From 2fb16420f34ee2b441beaf7f082fdc3cff056953 Mon Sep 17 00:00:00 2001 From: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> Date: Sat, 15 Nov 2025 13:30:02 -0800 Subject: [PATCH] fix: ape anchor not respawning (#1927) * fix: ape anchor not respawning * add return Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- dGame/Entity.cpp | 10 ++++++++++ dGame/Entity.h | 1 + dGame/dGameMessages/GameMessages.h | 6 ++++++ dScripts/02_server/Enemy/General/BaseEnemyApe.cpp | 8 +++++++- dScripts/02_server/Enemy/General/BaseEnemyApe.h | 1 + dScripts/CppScripts.h | 2 ++ 6 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 7d8046e0..35e2cfdc 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -189,6 +189,10 @@ Entity::~Entity() { } if (m_ParentEntity) { + GameMessages::ChildRemoved removedMsg{}; + removedMsg.childID = m_ObjectID; + removedMsg.target = m_ParentEntity->GetObjectID(); + removedMsg.Send(); m_ParentEntity->RemoveChild(this); } } @@ -198,6 +202,7 @@ void Entity::Initialize() { RegisterMsg(this, &Entity::MsgDropClientLoot); RegisterMsg(this, &Entity::MsgGetFactionTokenType); RegisterMsg(this, &Entity::MsgPickupItem); + RegisterMsg(this, &Entity::MsgChildRemoved); /** * Setup trigger */ @@ -2352,3 +2357,8 @@ bool Entity::MsgPickupItem(GameMessages::GameMsg& msg) { return true; } + +bool Entity::MsgChildRemoved(GameMessages::GameMsg& msg) { + GetScript()->OnChildRemoved(*this, static_cast(msg)); + return true; +} diff --git a/dGame/Entity.h b/dGame/Entity.h index 6d50efa7..5310cd0f 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -180,6 +180,7 @@ public: bool MsgGetFlag(GameMessages::GameMsg& msg); bool MsgGetFactionTokenType(GameMessages::GameMsg& msg); bool MsgPickupItem(GameMessages::GameMsg& msg); + bool MsgChildRemoved(GameMessages::GameMsg& msg); // This is expceted to never return nullptr, an assert checks this. CppScripts::Script* const GetScript() const; diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index 65349852..9daae4b5 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -937,5 +937,11 @@ namespace GameMessages { LWOOBJID lootID{}; LWOOBJID lootOwnerID{}; }; + + struct ChildRemoved : public GameMsg { + ChildRemoved() : GameMsg(MessageType::Game::CHILD_REMOVED) {} + + LWOOBJID childID{}; + }; }; #endif // GAMEMESSAGES_H diff --git a/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp b/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp index db6754f3..9c71c284 100644 --- a/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp +++ b/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp @@ -92,7 +92,7 @@ void BaseEnemyApe::OnTimerDone(Entity* self, std::string timerName) { new LDFData(u"ape", self->GetObjectID()) }; - auto* anchor = Game::entityManager->CreateEntity(entityInfo); + auto* anchor = Game::entityManager->CreateEntity(entityInfo, nullptr, self); Game::entityManager->ConstructEntity(anchor); self->SetVar(u"QB", anchor->GetObjectID()); @@ -140,3 +140,9 @@ void BaseEnemyApe::StunApe(Entity* self, bool stunState) { self->SetBoolean(u"knockedOut", stunState); } } + +void BaseEnemyApe::OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) { + if (self.GetVar(u"QB") == childRemoved.childID) { + self.SetVar(u"QB", LWOOBJID_EMPTY); + } +} diff --git a/dScripts/02_server/Enemy/General/BaseEnemyApe.h b/dScripts/02_server/Enemy/General/BaseEnemyApe.h index 54a734bb..a31f1612 100644 --- a/dScripts/02_server/Enemy/General/BaseEnemyApe.h +++ b/dScripts/02_server/Enemy/General/BaseEnemyApe.h @@ -10,6 +10,7 @@ public: void OnTimerDone(Entity* self, std::string timerName) override; void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override; + void OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) override; private: static void StunApe(Entity* self, bool stunState); }; diff --git a/dScripts/CppScripts.h b/dScripts/CppScripts.h index eb483a11..5ba4cee2 100644 --- a/dScripts/CppScripts.h +++ b/dScripts/CppScripts.h @@ -383,6 +383,8 @@ namespace CppScripts { * @param fire The child info */ virtual void OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) {}; + + virtual void OnChildRemoved(Entity& self, GameMessages::ChildRemoved& childRemoved) {}; }; Script* const GetScript(Entity* parent, const std::string& scriptName);