From 729e79eadbff2fd9bb73d0573573526face9c73a Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Tue, 17 May 2022 19:12:43 -0500 Subject: [PATCH] resolves #556 --- dScripts/ActMine.cpp | 53 +++++++++++++++++++++++++++++++++++++++++ dScripts/ActMine.h | 18 ++++++++++++++ dScripts/CppScripts.cpp | 3 +++ 3 files changed, 74 insertions(+) create mode 100644 dScripts/ActMine.cpp create mode 100644 dScripts/ActMine.h diff --git a/dScripts/ActMine.cpp b/dScripts/ActMine.cpp new file mode 100644 index 00000000..9cc116b1 --- /dev/null +++ b/dScripts/ActMine.cpp @@ -0,0 +1,53 @@ +#include "ActMine.h" +#include "SkillComponent.h" +#include "DestroyableComponent.h" +#include "RebuildComponent.h" + +void ActMine::OnStartup(Entity* self) { + self->SetVar(u"RebuildComplete", false); + self->SetProximityRadius(MINE_RADIUS, "mineRadius"); +} + +void ActMine::OnRebuildNotifyState(Entity* self, eRebuildState state) +{ + if (state == eRebuildState::REBUILD_COMPLETED) { + auto* rebuild = self->GetComponent(); + if (rebuild) { + auto* builder = rebuild->GetBuilder(); + self->SetVar(u"Builder", builder->GetObjectID()); + } + + self->SetVar(u"RebuildComplete", true); + self->SetVar(u"NumWarnings", 0); + self->AddToGroup("reset"); + } + +} + +void ActMine::OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status) { + auto* detroyable = self->GetComponent(); + if (!detroyable) return; + if (status == "ENTER" && self->GetVar(u"RebuildComplete") == true && detroyable->IsEnemy(entering)) { + GameMessages::SendPlayFXEffect(self->GetObjectID(), 242, u"orange", "sirenlight_B"); + self->AddTimer("Tick", TICK_TIME); + } +} + +void ActMine::OnTimerDone(Entity* self, std::string timerName) { + if (timerName == "Tick") { + if (self->GetVar(u"NumWarnings") >= MAX_WARNINGS){ + auto* skill = self->GetComponent(); + if (!skill) return; + skill->CalculateBehavior(SKILL_ID, BEHAVIOR_ID, LWOOBJID_EMPTY); + self->AddTimer("BlowedUp", BLOWED_UP_TIME); + } else { + GameMessages::SendPlayFXEffect(self->GetObjectID(), 242, u"orange", "sirenlight_B"); + self->AddTimer("Tick", TICK_TIME); + self->SetVar(u"NumWarnings", self->GetVar(u"NumWarnings") + 1); + } + } + + if (timerName == "BlowedUp") { + self->Kill(self); + } +} \ No newline at end of file diff --git a/dScripts/ActMine.h b/dScripts/ActMine.h new file mode 100644 index 00000000..85efadcc --- /dev/null +++ b/dScripts/ActMine.h @@ -0,0 +1,18 @@ +#pragma once +#include "CppScripts.h" + +class ActMine : public CppScripts::Script { + public: + void OnStartup(Entity* self); + void OnRebuildNotifyState(Entity* self, eRebuildState state) override; + void OnProximityUpdate(Entity* self, Entity* entering, std::string name, std::string status); + void OnTimerDone(Entity* self, std::string timerName); + private: + int MAX_WARNINGS = 3; + float MINE_RADIUS = 10.0; + float TICK_TIME = 0.25; + float BLOWED_UP_TIME = 0.1; + uint32_t SKILL_ID = 317; + uint32_t BEHAVIOR_ID = 3719; +}; + diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 4381823a..9e402a21 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -164,6 +164,7 @@ #include "BaseFootRaceManager.h" #include "PropertyPlatform.h" #include "MailBoxServer.h" +#include "ActMine.h" // Racing Scripts #include "RaceImagineCrateServer.h" @@ -591,6 +592,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr return new VeBricksampleServer(); else if (scriptName == "scripts\\02_server\\Map\\General\\L_MAIL_BOX_SERVER.lua") script = new MailBoxServer(); + else if (scriptName == "scripts\\ai\\ACT\\L_ACT_MINE.lua") + script = new ActMine(); //Racing: else if (scriptName == "scripts\\ai\\RACING\\OBJECTS\\RACE_IMAGINE_CRATE_SERVER.lua")