From 5667591635c65a51e44984ef0a362df468288b9b Mon Sep 17 00:00:00 2001 From: dinomking33 <38479763+TAHuntling@users.noreply.github.com> Date: Sat, 25 May 2024 01:25:56 -0500 Subject: [PATCH 1/6] Testing Scripts Testing splitting AgSpaceStuff into AgSpaceStuff and AgShipShake --- dScripts/ai/AG/AgShipShake.cpp | 105 +++++++++++++++++++++++++++++++++ dScripts/ai/AG/AgShipShake.h | 17 ++++++ dScripts/ai/AG/AgSpaceStuff.h | 9 --- 3 files changed, 122 insertions(+), 9 deletions(-) create mode 100644 dScripts/ai/AG/AgShipShake.cpp create mode 100644 dScripts/ai/AG/AgShipShake.h diff --git a/dScripts/ai/AG/AgShipShake.cpp b/dScripts/ai/AG/AgShipShake.cpp new file mode 100644 index 000000000..0b65de518 --- /dev/null +++ b/dScripts/ai/AG/AgShipShake.cpp @@ -0,0 +1,105 @@ +#include "AgShipShake.h" +#include "EntityInfo.h" +#include "GeneralUtils.h" +#include "GameMessages.h" +#include "EntityManager.h" +#include "RenderComponent.h" +#include "Entity.h" + +void AgShipShake::OnStartup(Entity* self) { + EntityInfo info{}; + + info.pos = { -418, 585, -30 }; + info.lot = 33; + info.spawnerID = self->GetObjectID(); + + auto* ref = Game::entityManager->CreateEntity(info); + + Game::entityManager->ConstructEntity(ref); + + self->SetVar(u"ShakeObject", ref->GetObjectID()); + + self->AddTimer("ShipShakeIdle", 2.0f); + self->SetVar(u"RandomTime", 10); +} + +void AgShipShake::OnTimerDone(Entity* self, std::string timerName) { + if (timerName == "FloaterScale") { + int scaleType = GeneralUtils::GenerateRandomNumber(1, 5); + + RenderComponent::PlayAnimation(self, u"scale_0" + GeneralUtils::to_u16string(scaleType)); + self->AddTimer("FloaterPath", 0.4); + } else if (timerName == "FloaterPath") { + int pathType = GeneralUtils::GenerateRandomNumber(1, 4); + int randTime = GeneralUtils::GenerateRandomNumber(20, 25); + + RenderComponent::PlayAnimation(self, u"path_0" + (GeneralUtils::to_u16string(pathType))); + self->AddTimer("FloaterScale", randTime); + } else if (timerName == "ShipShakeExplode") { + DoShake(self, true); + } else if (timerName == "ShipShakeIdle") { + DoShake(self, false); + } +} + +void AgShipShake::DoShake(Entity* self, bool explodeIdle) { + + if (!explodeIdle) { + auto* ref = Game::entityManager->GetEntity(self->GetVar(u"ShakeObject")); + + const auto randomTime = self->GetVar(u"RandomTime"); + auto time = GeneralUtils::GenerateRandomNumber(0, randomTime + 1); + + if (time < randomTime / 2) { + time += randomTime / 2; + } + + self->AddTimer("ShipShakeIdle", static_cast(time)); + + if (ref) + GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(ref, FXName, ref->GetObjectID(), 500.0f); + + auto* debrisObject = GetEntityInGroup(DebrisFX); + + if (debrisObject) + GameMessages::SendPlayFXEffect(debrisObject, -1, u"DebrisFall", "Debris", LWOOBJID_EMPTY, 1.0f, 1.0f, true); + + const auto randomFx = GeneralUtils::GenerateRandomNumber(0, 3); + + auto* shipFxObject = GetEntityInGroup(ShipFX); + if (shipFxObject) { + std::string effectType = "shipboom" + std::to_string(randomFx); + GameMessages::SendPlayFXEffect(shipFxObject, 559, GeneralUtils::ASCIIToUTF16(effectType), "FX", LWOOBJID_EMPTY, 1.0f, 1.0f, true); + } + + self->AddTimer("ShipShakeExplode", 5.0f); + + auto* shipFxObject2 = GetEntityInGroup(ShipFX2); + if (shipFxObject2) + RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); + } else { + auto* shipFxObject = GetEntityInGroup(ShipFX); + auto* shipFxObject2 = GetEntityInGroup(ShipFX2); + + if (shipFxObject) + RenderComponent::PlayAnimation(shipFxObject, u"idle"); + + if (shipFxObject2) + RenderComponent::PlayAnimation(shipFxObject2, u"idle"); + } +} + +Entity* AgShipShake::GetEntityInGroup(const std::string& group) { + auto entities = Game::entityManager->GetEntitiesInGroup(group); + Entity* en = nullptr; + + for (auto entity : entities) { + if (entity) { + en = entity; + break; + } + } + + return en; +} + diff --git a/dScripts/ai/AG/AgShipShake.h b/dScripts/ai/AG/AgShipShake.h new file mode 100644 index 000000000..10c6d3625 --- /dev/null +++ b/dScripts/ai/AG/AgShipShake.h @@ -0,0 +1,17 @@ +#pragma once +#include "CppScripts.h" + +class AgShipShake : public CppScripts::Script { +public: + void OnStartup(Entity* self) override; + void OnTimerDone(Entity* self, std::string timerName) override; + void DoShake(Entity* self, bool explodeIdle); + + std::string DebrisFX = "DebrisFX"; + std::string ShipFX = "ShipFX"; + std::string ShipFX2 = "ShipFX2"; + std::u16string FXName = u"camshake-bridge"; + +private: + Entity* GetEntityInGroup(const std::string& group); +}; diff --git a/dScripts/ai/AG/AgSpaceStuff.h b/dScripts/ai/AG/AgSpaceStuff.h index 8d8166912..568f2baf7 100644 --- a/dScripts/ai/AG/AgSpaceStuff.h +++ b/dScripts/ai/AG/AgSpaceStuff.h @@ -5,14 +5,5 @@ class AgSpaceStuff : public CppScripts::Script { public: void OnStartup(Entity* self); void OnTimerDone(Entity* self, std::string timerName); - void DoShake(Entity* self, bool explodeIdle); - - std::string DebrisFX = "DebrisFX"; - std::string ShipFX = "ShipFX"; - std::string ShipFX2 = "ShipFX2"; - std::u16string FXName = u"camshake-bridge"; - -private: - Entity* GetEntityInGroup(const std::string& group); }; From a77a4db9f4da9072db845aa2928b02108f3c1a80 Mon Sep 17 00:00:00 2001 From: dinomking33 <38479763+TAHuntling@users.noreply.github.com> Date: Sat, 25 May 2024 21:42:55 -0500 Subject: [PATCH 2/6] fixed inclusions --- dScripts/CppScripts.cpp | 2 + dScripts/ai/AG/AgSpaceStuff.cpp | 80 --------------------------------- dScripts/ai/AG/CMakeLists.txt | 1 + 3 files changed, 3 insertions(+), 80 deletions(-) diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index 784edbdb0..3d0e83c68 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -14,6 +14,7 @@ #include "AgShipPlayerDeathTrigger.h" #include "AgShipPlayerShockServer.h" #include "AgSpaceStuff.h" +#include "AgShipShake.h" #include "AgImagSmashable.h" #include "NpcNpSpacemanBob.h" #include "StoryBoxInteractServer.h" @@ -341,6 +342,7 @@ namespace { { "scripts\\ai\\AG\\L_AG_SHIP_PLAYER_DEATH_TRIGGER.lua", []() { return new AgShipPlayerDeathTrigger(); } }, {"scripts\\ai\\NP\\L_NPC_NP_SPACEMAN_BOB.lua", []() { return new NpcNpSpacemanBob(); } }, {"scripts\\ai\\AG\\L_AG_SPACE_STUFF.lua", []() { return new AgSpaceStuff();} }, + {"scripts\\ai\\AG\\L_AG_SHIP_SHAKE.lua", []() { return new AgShipShake();}}, {"scripts\\ai\\AG\\L_AG_SHIP_PLAYER_SHOCK_SERVER.lua", []() { return new AgShipPlayerShockServer();} }, {"scripts\\ai\\AG\\L_AG_IMAG_SMASHABLE.lua", []() { return new AgImagSmashable();} }, {"scripts\\02_server\\Map\\General\\L_STORY_BOX_INTERACT_SERVER.lua", []() { return new StoryBoxInteractServer();} }, diff --git a/dScripts/ai/AG/AgSpaceStuff.cpp b/dScripts/ai/AG/AgSpaceStuff.cpp index 130d43540..dedbd08cd 100644 --- a/dScripts/ai/AG/AgSpaceStuff.cpp +++ b/dScripts/ai/AG/AgSpaceStuff.cpp @@ -8,21 +8,6 @@ void AgSpaceStuff::OnStartup(Entity* self) { self->AddTimer("FloaterScale", 5.0f); - - EntityInfo info{}; - - info.pos = { -418, 585, -30 }; - info.lot = 33; - info.spawnerID = self->GetObjectID(); - - auto* ref = Game::entityManager->CreateEntity(info); - - Game::entityManager->ConstructEntity(ref); - - self->SetVar(u"ShakeObject", ref->GetObjectID()); - - self->AddTimer("ShipShakeIdle", 2.0f); - self->SetVar(u"RandomTime", 10); } void AgSpaceStuff::OnTimerDone(Entity* self, std::string timerName) { @@ -37,70 +22,5 @@ void AgSpaceStuff::OnTimerDone(Entity* self, std::string timerName) { RenderComponent::PlayAnimation(self, u"path_0" + (GeneralUtils::to_u16string(pathType))); self->AddTimer("FloaterScale", randTime); - } else if (timerName == "ShipShakeExplode") { - DoShake(self, true); - } else if (timerName == "ShipShakeIdle") { - DoShake(self, false); } } - -void AgSpaceStuff::DoShake(Entity* self, bool explodeIdle) { - - if (!explodeIdle) { - auto* ref = Game::entityManager->GetEntity(self->GetVar(u"ShakeObject")); - - const auto randomTime = self->GetVar(u"RandomTime"); - auto time = GeneralUtils::GenerateRandomNumber(0, randomTime + 1); - - if (time < randomTime / 2) { - time += randomTime / 2; - } - - self->AddTimer("ShipShakeIdle", static_cast(time)); - - if (ref) - GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(ref, FXName, ref->GetObjectID(), 500.0f); - - auto* debrisObject = GetEntityInGroup(DebrisFX); - - if (debrisObject) - GameMessages::SendPlayFXEffect(debrisObject, -1, u"DebrisFall", "Debris", LWOOBJID_EMPTY, 1.0f, 1.0f, true); - - const auto randomFx = GeneralUtils::GenerateRandomNumber(0, 3); - - auto* shipFxObject = GetEntityInGroup(ShipFX); - if (shipFxObject) { - std::string effectType = "shipboom" + std::to_string(randomFx); - GameMessages::SendPlayFXEffect(shipFxObject, 559, GeneralUtils::ASCIIToUTF16(effectType), "FX", LWOOBJID_EMPTY, 1.0f, 1.0f, true); - } - - self->AddTimer("ShipShakeExplode", 5.0f); - - auto* shipFxObject2 = GetEntityInGroup(ShipFX2); - if (shipFxObject2) - RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); - } else { - auto* shipFxObject = GetEntityInGroup(ShipFX); - auto* shipFxObject2 = GetEntityInGroup(ShipFX2); - - if (shipFxObject) - RenderComponent::PlayAnimation(shipFxObject, u"idle"); - - if (shipFxObject2) - RenderComponent::PlayAnimation(shipFxObject2, u"idle"); - } -} - -Entity* AgSpaceStuff::GetEntityInGroup(const std::string& group) { - auto entities = Game::entityManager->GetEntitiesInGroup(group); - Entity* en = nullptr; - - for (auto entity : entities) { - if (entity) { - en = entity; - break; - } - } - - return en; -} diff --git a/dScripts/ai/AG/CMakeLists.txt b/dScripts/ai/AG/CMakeLists.txt index e74aac789..101f86fd5 100644 --- a/dScripts/ai/AG/CMakeLists.txt +++ b/dScripts/ai/AG/CMakeLists.txt @@ -1,6 +1,7 @@ set(DSCRIPTS_SOURCES_AI_AG "AgShipPlayerDeathTrigger.cpp" "AgSpaceStuff.cpp" + "AgShipShake.cpp" "AgShipPlayerShockServer.cpp" "AgImagSmashable.cpp" "ActSharkPlayerDeathTrigger.cpp" From f9edb26a3c376908e2f7aa728e60f03599bf84e8 Mon Sep 17 00:00:00 2001 From: dinomking33 <38479763+TAHuntling@users.noreply.github.com> Date: Sat, 25 May 2024 23:03:57 -0500 Subject: [PATCH 3/6] Removed DoShake --- dScripts/ai/AG/AgShipShake.cpp | 30 ++++-------------------------- 1 file changed, 4 insertions(+), 26 deletions(-) diff --git a/dScripts/ai/AG/AgShipShake.cpp b/dScripts/ai/AG/AgShipShake.cpp index 0b65de518..356987a47 100644 --- a/dScripts/ai/AG/AgShipShake.cpp +++ b/dScripts/ai/AG/AgShipShake.cpp @@ -24,27 +24,7 @@ void AgShipShake::OnStartup(Entity* self) { } void AgShipShake::OnTimerDone(Entity* self, std::string timerName) { - if (timerName == "FloaterScale") { - int scaleType = GeneralUtils::GenerateRandomNumber(1, 5); - - RenderComponent::PlayAnimation(self, u"scale_0" + GeneralUtils::to_u16string(scaleType)); - self->AddTimer("FloaterPath", 0.4); - } else if (timerName == "FloaterPath") { - int pathType = GeneralUtils::GenerateRandomNumber(1, 4); - int randTime = GeneralUtils::GenerateRandomNumber(20, 25); - - RenderComponent::PlayAnimation(self, u"path_0" + (GeneralUtils::to_u16string(pathType))); - self->AddTimer("FloaterScale", randTime); - } else if (timerName == "ShipShakeExplode") { - DoShake(self, true); - } else if (timerName == "ShipShakeIdle") { - DoShake(self, false); - } -} - -void AgShipShake::DoShake(Entity* self, bool explodeIdle) { - - if (!explodeIdle) { + if (timerName == "ShipShakeIdle") { auto* ref = Game::entityManager->GetEntity(self->GetVar(u"ShakeObject")); const auto randomTime = self->GetVar(u"RandomTime"); @@ -77,15 +57,13 @@ void AgShipShake::DoShake(Entity* self, bool explodeIdle) { auto* shipFxObject2 = GetEntityInGroup(ShipFX2); if (shipFxObject2) RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); - } else { + } else if (timerName == "ShipShakeExplode") { auto* shipFxObject = GetEntityInGroup(ShipFX); auto* shipFxObject2 = GetEntityInGroup(ShipFX2); - if (shipFxObject) - RenderComponent::PlayAnimation(shipFxObject, u"idle"); + if (shipFxObject) { RenderComponent::PlayAnimation(shipFxObject, u"idle"); } - if (shipFxObject2) - RenderComponent::PlayAnimation(shipFxObject2, u"idle"); + if (shipFxObject2) { RenderComponent::PlayAnimation(shipFxObject2, u"idle"); } } } From 635059e92481fa37937803104a21096ea6aaa183 Mon Sep 17 00:00:00 2001 From: dinomking33 <38479763+TAHuntling@users.noreply.github.com> Date: Sat, 25 May 2024 23:10:10 -0500 Subject: [PATCH 4/6] cleaning up --- dScripts/ai/AG/AgShipShake.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/dScripts/ai/AG/AgShipShake.cpp b/dScripts/ai/AG/AgShipShake.cpp index 356987a47..e8234e56d 100644 --- a/dScripts/ai/AG/AgShipShake.cpp +++ b/dScripts/ai/AG/AgShipShake.cpp @@ -24,6 +24,9 @@ void AgShipShake::OnStartup(Entity* self) { } void AgShipShake::OnTimerDone(Entity* self, std::string timerName) { + auto* shipFxObject = GetEntityInGroup(ShipFX); + auto* shipFxObject2 = GetEntityInGroup(ShipFX2); + auto* debrisObject = GetEntityInGroup(DebrisFX); if (timerName == "ShipShakeIdle") { auto* ref = Game::entityManager->GetEntity(self->GetVar(u"ShakeObject")); @@ -39,14 +42,12 @@ void AgShipShake::OnTimerDone(Entity* self, std::string timerName) { if (ref) GameMessages::SendPlayEmbeddedEffectOnAllClientsNearObject(ref, FXName, ref->GetObjectID(), 500.0f); - auto* debrisObject = GetEntityInGroup(DebrisFX); if (debrisObject) GameMessages::SendPlayFXEffect(debrisObject, -1, u"DebrisFall", "Debris", LWOOBJID_EMPTY, 1.0f, 1.0f, true); const auto randomFx = GeneralUtils::GenerateRandomNumber(0, 3); - auto* shipFxObject = GetEntityInGroup(ShipFX); if (shipFxObject) { std::string effectType = "shipboom" + std::to_string(randomFx); GameMessages::SendPlayFXEffect(shipFxObject, 559, GeneralUtils::ASCIIToUTF16(effectType), "FX", LWOOBJID_EMPTY, 1.0f, 1.0f, true); @@ -54,15 +55,9 @@ void AgShipShake::OnTimerDone(Entity* self, std::string timerName) { self->AddTimer("ShipShakeExplode", 5.0f); - auto* shipFxObject2 = GetEntityInGroup(ShipFX2); - if (shipFxObject2) - RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); + if (shipFxObject2) { RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); } } else if (timerName == "ShipShakeExplode") { - auto* shipFxObject = GetEntityInGroup(ShipFX); - auto* shipFxObject2 = GetEntityInGroup(ShipFX2); - if (shipFxObject) { RenderComponent::PlayAnimation(shipFxObject, u"idle"); } - if (shipFxObject2) { RenderComponent::PlayAnimation(shipFxObject2, u"idle"); } } } From 9e150076f29984855c494a312ee20f482802d84a Mon Sep 17 00:00:00 2001 From: dinomking33 <38479763+TAHuntling@users.noreply.github.com> Date: Sat, 25 May 2024 23:14:25 -0500 Subject: [PATCH 5/6] consistent if statements --- dScripts/ai/AG/AgShipShake.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/dScripts/ai/AG/AgShipShake.cpp b/dScripts/ai/AG/AgShipShake.cpp index e8234e56d..7dd2323a7 100644 --- a/dScripts/ai/AG/AgShipShake.cpp +++ b/dScripts/ai/AG/AgShipShake.cpp @@ -55,10 +55,13 @@ void AgShipShake::OnTimerDone(Entity* self, std::string timerName) { self->AddTimer("ShipShakeExplode", 5.0f); - if (shipFxObject2) { RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); } + if (shipFxObject2) + RenderComponent::PlayAnimation(shipFxObject2, u"explosion"); } else if (timerName == "ShipShakeExplode") { - if (shipFxObject) { RenderComponent::PlayAnimation(shipFxObject, u"idle"); } - if (shipFxObject2) { RenderComponent::PlayAnimation(shipFxObject2, u"idle"); } + if (shipFxObject) + RenderComponent::PlayAnimation(shipFxObject, u"idle"); + if (shipFxObject2) + RenderComponent::PlayAnimation(shipFxObject2, u"idle"); } } From dae41f9f43d1c713521cf5256f625d1ecc91ef7e Mon Sep 17 00:00:00 2001 From: TAHuntling <38479763+TAHuntling@users.noreply.github.com> Date: Sun, 26 May 2024 14:17:44 -0500 Subject: [PATCH 6/6] Update dScripts/ai/AG/AgShipShake.h Co-authored-by: David Markowitz <39972741+EmosewaMC@users.noreply.github.com> --- dScripts/ai/AG/AgShipShake.h | 1 - 1 file changed, 1 deletion(-) diff --git a/dScripts/ai/AG/AgShipShake.h b/dScripts/ai/AG/AgShipShake.h index 10c6d3625..4cc26f960 100644 --- a/dScripts/ai/AG/AgShipShake.h +++ b/dScripts/ai/AG/AgShipShake.h @@ -5,7 +5,6 @@ class AgShipShake : public CppScripts::Script { public: void OnStartup(Entity* self) override; void OnTimerDone(Entity* self, std::string timerName) override; - void DoShake(Entity* self, bool explodeIdle); std::string DebrisFX = "DebrisFX"; std::string ShipFX = "ShipFX";