From fb18225f463100c885113a6f6edf5d99ac5c8aa9 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Wed, 15 Dec 2021 13:23:49 -0600 Subject: [PATCH] Implemented die roll animations for the Lego Dice item --- dScripts/CppScripts.cpp | 3 +++ dScripts/LegoDieRoll.cpp | 41 ++++++++++++++++++++++++++++++++++++++++ dScripts/LegoDieRoll.h | 11 +++++++++++ utils | 1 + 4 files changed, 56 insertions(+) create mode 100644 dScripts/LegoDieRoll.cpp create mode 100644 dScripts/LegoDieRoll.h create mode 160000 utils diff --git a/dScripts/CppScripts.cpp b/dScripts/CppScripts.cpp index ed59c5ba..0513ddbf 100644 --- a/dScripts/CppScripts.cpp +++ b/dScripts/CppScripts.cpp @@ -261,6 +261,7 @@ #include "PersonalFortress.h" #include "PropertyDevice.h" #include "ImaginationBackpackHealServer.h" +#include "LegoDieRoll.h" // Survival scripts #include "AgSurvivalStromling.h" @@ -774,6 +775,8 @@ CppScripts::Script* CppScripts::GetScript(Entity* parent, const std::string& scr script = new PropertyDevice(); else if (scriptName == "scripts\\02_server\\Map\\General\\L_IMAG_BACKPACK_HEALS_SERVER.lua") script = new ImaginationBackpackHealServer(); + else if (scriptName == "scripts\\ai\\GENERAL\\L_LEGO_DIE_ROLL.lua") + script = new LegoDieRoll(); //Ignore these scripts: else if (scriptName == "scripts\\02_server\\Enemy\\General\\L_SUSPEND_LUA_AI.lua") diff --git a/dScripts/LegoDieRoll.cpp b/dScripts/LegoDieRoll.cpp new file mode 100644 index 00000000..940a842c --- /dev/null +++ b/dScripts/LegoDieRoll.cpp @@ -0,0 +1,41 @@ +#include "LegoDieRoll.h" +#include "Entity.h" +#include "GameMessages.h" + +void LegoDieRoll::OnStartup(Entity* self) { + self->AddTimer("DoneRolling", 10.0f); + self->AddTimer("ThrowDice", LegoDieRoll::animTime); +} + +void LegoDieRoll::OnTimerDone(Entity* self, std::string timerName) { + if (timerName == "DoneRolling") { + self->Smash(self->GetObjectID(), SILENT); + } + else if (timerName == "ThrowDice") { + int dieRoll = GeneralUtils::GenerateRandomNumber(1, 6); + + switch (dieRoll) + { + case 1: + GameMessages::SendPlayAnimation(self, u"roll-die-1"); + break; + case 2: + GameMessages::SendPlayAnimation(self, u"roll-die-2"); + break; + case 3: + GameMessages::SendPlayAnimation(self, u"roll-die-3"); + break; + case 4: + GameMessages::SendPlayAnimation(self, u"roll-die-4"); + break; + case 5: + GameMessages::SendPlayAnimation(self, u"roll-die-5"); + break; + case 6: + GameMessages::SendPlayAnimation(self, u"roll-die-6"); + break; + default: + break; + } + } +} \ No newline at end of file diff --git a/dScripts/LegoDieRoll.h b/dScripts/LegoDieRoll.h new file mode 100644 index 00000000..3b28d529 --- /dev/null +++ b/dScripts/LegoDieRoll.h @@ -0,0 +1,11 @@ +#pragma once +#include "CppScripts.h" + +class LegoDieRoll : public CppScripts::Script { +public: + void OnStartup(Entity* self); + void OnTimerDone(Entity* self, std::string timerName); +private: + constexpr static const float animTime = 2.0f; +}; + diff --git a/utils b/utils new file mode 160000 index 00000000..74508f87 --- /dev/null +++ b/utils @@ -0,0 +1 @@ +Subproject commit 74508f879a17910ae7273ee62c7b3252d166b8ee