Skip to content

Commit

Permalink
Don't destroy monster when last target type is a player (cuberite#3721)
Browse files Browse the repository at this point in the history
In current Cuberite version if you are pursued by monsters you just have to disconnect and connect again to get rid of them. If no other player is in your chunk monsters will get destroyed.
  • Loading branch information
spekdrum authored and madmaxoft committed May 21, 2017
1 parent 4b5a11e commit 2359611
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Mobs/Monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ cMonster::cMonster(const AString & a_ConfigName, eMonsterType a_MobType, const A
, m_RelativeWalkSpeed(1)
, m_Age(1)
, m_AgingTimer(20 * 60 * 20) // about 20 minutes
, m_WasLastTargetAPlayer(false)
, m_Target(nullptr)
{
if (!a_ConfigName.empty())
Expand Down Expand Up @@ -945,6 +946,7 @@ void cMonster::SetTarget (cPawn * a_NewTarget)
ASSERT(a_NewTarget->IsTicking());
// Notify the new target that we are now targeting it.
m_Target->TargetingMe(this);
m_WasLastTargetAPlayer = m_Target->IsPlayer();
}

}
Expand Down
5 changes: 5 additions & 0 deletions src/Mobs/Monster.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ class cMonster :
*/
static cMonster * NewMonsterFromType(eMonsterType a_MobType);

/** Returns if this mob last target was a player to avoid destruction on player quit */
bool WasLastTargetAPlayer() const { return m_WasLastTargetAPlayer; }

protected:

/** The pathfinder instance handles pathfinding for this monster. */
Expand Down Expand Up @@ -251,6 +254,8 @@ class cMonster :
int m_Age;
int m_AgingTimer;

bool m_WasLastTargetAPlayer;

/** Adds a random number of a_Item between a_Min and a_Max to itemdrops a_Drops */
void AddRandomDropItem(cItems & a_Drops, unsigned int a_Min, unsigned int a_Max, short a_Item, short a_ItemHealth = 0);

Expand Down
4 changes: 2 additions & 2 deletions src/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,8 @@ void cWorld::TickMobs(std::chrono::milliseconds a_Dt)
{
Monster->Tick(m_Dt, *(a_Entity->GetParentChunk()));
}
// Destroy far hostile mobs
else if ((Monster->GetMobFamily() == cMonster::eFamily::mfHostile))
// Destroy far hostile mobs except if last target was a player
else if ((Monster->GetMobFamily() == cMonster::eFamily::mfHostile) && !Monster->WasLastTargetAPlayer())
{
if (Monster->GetMobType() != eMonsterType::mtWolf)
{
Expand Down

0 comments on commit 2359611

Please sign in to comment.