1
0

Fully implemented leashes (#3798)

This commit is contained in:
Pablo Beltrán
2017-08-21 10:46:41 +02:00
committed by Mattes D
parent f81e6f6b6d
commit b18f6637b6
42 changed files with 1022 additions and 21 deletions

View File

@@ -159,6 +159,15 @@ bool cEntity::Initialize(OwnedEntity a_Self, cWorld & a_EntityWorld)
// Spawn the entity on the clients:
a_EntityWorld.BroadcastSpawnEntity(*this);
// If has any mob leashed broadcast every leashed entity to this
if (HasAnyMobLeashed())
{
for (auto LeashedMob : m_LeashedMobs)
{
m_World->BroadcastLeashEntity(*LeashedMob, *this);
}
}
return true;
}
@@ -218,6 +227,12 @@ void cEntity::Destroy(bool a_ShouldBroadcast)
ASSERT(GetParentChunk() != nullptr);
SetIsTicking(false);
// Unleash leashed mobs
while (!m_LeashedMobs.empty())
{
m_LeashedMobs.front()->Unleash(true, true);
}
if (a_ShouldBroadcast)
{
m_World->BroadcastDestroyEntity(*this);
@@ -2195,3 +2210,24 @@ void cEntity::SetPosition(const Vector3d & a_Position)
void cEntity::AddLeashedMob(cMonster * a_Monster)
{
// Not there already
ASSERT(std::find(m_LeashedMobs.begin(), m_LeashedMobs.end(), a_Monster) == m_LeashedMobs.end());
m_LeashedMobs.push_back(a_Monster);
}
void cEntity::RemoveLeashedMob(cMonster * a_Monster)
{
ASSERT(a_Monster->GetLeashedTo() == this);
// Must exists
ASSERT(std::find(m_LeashedMobs.begin(), m_LeashedMobs.end(), a_Monster) != m_LeashedMobs.end());
m_LeashedMobs.remove(a_Monster);
}