From b18f6637b6c58db20353cd3e77584b646ab36b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Beltr=C3=A1n?= Date: Mon, 21 Aug 2017 10:46:41 +0200 Subject: Fully implemented leashes (#3798) --- src/Entities/Entity.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/Entities/Entity.cpp') diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index a38a6552d..56f7b33a3 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -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); +} -- cgit v1.2.3