add child loading (#1706)

Tested that the NT combat challenge, am skullkin towers and qa wall in avant gardens all function as before.
This commit is contained in:
David Markowitz
2024-12-31 22:46:00 -08:00
committed by GitHub
parent 0b261e934f
commit 021db0ecd1
10 changed files with 54 additions and 33 deletions

View File

@@ -64,21 +64,22 @@ void AmSkullkinTower::SpawnLegs(Entity* self, const std::string& loc) {
info.rot = NiQuaternion::LookAt(info.pos, self->GetPosition());
auto* entity = Game::entityManager->CreateEntity(info);
auto* entity = Game::entityManager->CreateEntity(info, nullptr, self);
Game::entityManager->ConstructEntity(entity);
OnChildLoaded(self, entity);
}
void AmSkullkinTower::OnChildLoaded(Entity* self, Entity* child) {
auto legTable = self->GetVar<std::vector<LWOOBJID>>(u"legTable");
void AmSkullkinTower::OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) {
auto legTable = self.GetVar<std::vector<LWOOBJID>>(u"legTable");
legTable.push_back(child->GetObjectID());
legTable.push_back(childLoaded.childID);
self->SetVar(u"legTable", legTable);
self.SetVar(u"legTable", legTable);
const auto selfID = self->GetObjectID();
const auto selfID = self.GetObjectID();
auto* const child = Game::entityManager->GetEntity(childLoaded.childID);
if (!child) return;
child->AddDieCallback([this, selfID, child]() {
auto* self = Game::entityManager->GetEntity(selfID);

View File

@@ -8,7 +8,7 @@ public:
void SpawnLegs(Entity* self, const std::string& loc);
void OnChildLoaded(Entity* self, Entity* child);
void OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) override;
void NotifyDie(Entity* self, Entity* other, Entity* killer);

View File

@@ -77,8 +77,6 @@ void QbSpawner::OnTimerDone(Entity* self, std::string timerName) {
auto* child = Game::entityManager->CreateEntity(info, nullptr, self);
Game::entityManager->ConstructEntity(child);
OnChildLoaded(self, child);
} else {
auto* mob = Game::entityManager->GetEntity(mobTable[i]);
AggroTargetObject(self, mob);
@@ -88,16 +86,19 @@ void QbSpawner::OnTimerDone(Entity* self, std::string timerName) {
}
}
void QbSpawner::OnChildLoaded(Entity* self, Entity* child) {
auto mobTable = self->GetVar<std::vector<LWOOBJID>>(u"mobTable");
void QbSpawner::OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) {
auto* const child = Game::entityManager->GetEntity(childLoaded.childID);
if (!child) return;
auto mobTable = self.GetVar<std::vector<LWOOBJID>>(u"mobTable");
auto tableLoc = child->GetVar<int>(u"mobTableLoc");
mobTable[tableLoc] = child->GetObjectID();
self->SetVar<std::vector<LWOOBJID>>(u"mobTable", mobTable);
self.SetVar<std::vector<LWOOBJID>>(u"mobTable", mobTable);
AggroTargetObject(self, child);
AggroTargetObject(&self, child);
const auto selfID = self->GetObjectID();
const auto selfID = self.GetObjectID();
child->AddDieCallback([this, selfID, child]() {
auto* self = Game::entityManager->GetEntity(selfID);

View File

@@ -6,7 +6,7 @@ public:
void OnStartup(Entity* self) override;
void OnFireEventServerSide(Entity* self, Entity* sender, std::string args, int32_t param1, int32_t param2, int32_t param3) override;
void OnTimerDone(Entity* self, std::string timerName) override;
void OnChildLoaded(Entity* self, Entity* child);
void OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) override;
void OnChildRemoved(Entity* self, Entity* child);
void AggroTargetObject(Entity* self, Entity* enemy);
private:

View File

@@ -91,7 +91,7 @@ void NtCombatChallengeServer::SpawnTargetDummy(Entity* self) {
info.rot = self->GetRotation();
info.settings = { new LDFData<std::string>(u"custom_script_server", "scripts\\02_server\\Map\\NT\\L_NT_COMBAT_CHALLENGE_DUMMY.lua") };
auto* dummy = Game::entityManager->CreateEntity(info);
auto* dummy = Game::entityManager->CreateEntity(info, nullptr, self);
dummy->SetVar(u"challengeObjectID", self->GetObjectID());
@@ -104,26 +104,18 @@ void NtCombatChallengeServer::SetAttackImmunity(LWOOBJID objID, bool bTurnOn) {
}
void NtCombatChallengeServer::OnChildLoaded(Entity* self, Entity* child) {
auto targetNumber = self->GetVar<int32_t>(u"TargetNumber");
if (targetNumber == 0) targetNumber = 1;
self->SetVar(u"TargetNumber", targetNumber + 1);
void NtCombatChallengeServer::OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) {
auto* const child = Game::entityManager->GetEntity(childLoaded.childID);
const auto playerID = self->GetVar<LWOOBJID>(u"playerID");
auto* player = Game::entityManager->GetEntity(playerID);
if (player == nullptr) {
return;
if (child) {
child->SetRotation(NiQuaternion::FromEulerAngles(child->GetRotation().GetEulerAngles() += NiPoint3(0, PI, 0))); // rotate 180 degrees
}
child->SetRotation(NiQuaternion::LookAt(child->GetPosition(), player->GetPosition()));
self->SetVar(u"currentTargetID", child->GetObjectID());
self.SetVar(u"currentTargetID", child->GetObjectID());
Game::entityManager->SerializeEntity(child);
child->GetGroups().push_back("targets_" + std::to_string(self->GetObjectID()));
child->GetGroups().push_back("targets_" + std::to_string(self.GetObjectID()));
}
void NtCombatChallengeServer::ResetGame(Entity* self) {

View File

@@ -12,7 +12,7 @@ public:
void OnMessageBoxResponse(Entity* self, Entity* sender, int32_t button, const std::u16string& identifier, const std::u16string& userData) override;
void SpawnTargetDummy(Entity* self);
void SetAttackImmunity(LWOOBJID objID, bool bTurnOn);
void OnChildLoaded(Entity* self, Entity* child);
void OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) override;
void ResetGame(Entity* self);
void OnActivityTimerUpdate(Entity* self, float timeRemaining);
void OnTimerDone(Entity* self, std::string timerName) override;

View File

@@ -373,6 +373,14 @@ namespace CppScripts {
* @param fire The firing data
*/
virtual void OnShootingGalleryFire(Entity& self, GameMessages::ShootingGalleryFire& fire) {};
/**
* @brief Handles when a child is loaded
*
* @param self
* @param fire The child info
*/
virtual void OnChildLoaded(Entity& self, GameMessages::ChildLoaded& childLoaded) {};
};
Script* const GetScript(Entity* parent, const std::string& scriptName);