diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 8701df2b98d..47ae56c7dd6 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -157,7 +157,7 @@ bool Spells::registerRuneLuaEvent(const std::shared_ptr &rune) { "[{}] duplicate registered rune with id: {}, for script: {}", __FUNCTION__, id, - rune->getScriptInterface()->getLoadingScriptName() + rune->getRuneSpellScriptInterface()->getLoadingScriptName() ); } return inserted; @@ -1311,14 +1311,14 @@ bool InstantSpell::canCast(const std::shared_ptr &player) const { return false; } -LuaScriptInterface* RuneSpell::getScriptInterface() const { +LuaScriptInterface* RuneSpell::getRuneSpellScriptInterface() const { return &g_scripts().getScriptInterface(); } -bool RuneSpell::loadScriptId() { +bool RuneSpell::loadRuneSpellScriptId() { LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); - m_spellScriptId = luaInterface.getEvent(); - if (m_spellScriptId == -1) { + m_runeSpellScriptId = luaInterface.getEvent(); + if (m_runeSpellScriptId == -1) { g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); return false; } @@ -1326,16 +1326,16 @@ bool RuneSpell::loadScriptId() { return true; } -int32_t RuneSpell::getScriptId() const { - return m_spellScriptId; +int32_t RuneSpell::getRuneSpellScriptId() const { + return m_runeSpellScriptId; } -void RuneSpell::setScriptId(int32_t newScriptId) { - m_spellScriptId = newScriptId; +void RuneSpell::setRuneSpellScriptId(int32_t newScriptId) { + m_runeSpellScriptId = newScriptId; } -bool RuneSpell::isLoadedScriptId() const { - return m_spellScriptId != 0; +bool RuneSpell::isRuneSpellLoadedScriptId() const { + return m_runeSpellScriptId != 0; } ReturnValue RuneSpell::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { @@ -1373,7 +1373,7 @@ bool RuneSpell::executeUse(const std::shared_ptr &player, const std::sha } // If script not loaded correctly, return - if (!isLoadedScriptId()) { + if (!isRuneSpellLoadedScriptId()) { return false; } @@ -1437,7 +1437,7 @@ bool RuneSpell::castSpell(const std::shared_ptr &creature, const std:: bool RuneSpell::internalCastSpell(const std::shared_ptr &creature, const LuaVariant &var, bool isHotkey) const { bool result; - if (isLoadedScriptId()) { + if (isRuneSpellLoadedScriptId()) { result = executeCastSpell(creature, var, isHotkey); } else { result = false; @@ -1455,11 +1455,11 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr &creature, cons } ScriptEnvironment* env = LuaEnvironment::getScriptEnv(); - env->setScriptId(getScriptId(), getScriptInterface()); + env->setScriptId(getRuneSpellScriptId(), getRuneSpellScriptInterface()); - lua_State* L = getScriptInterface()->getLuaState(); + lua_State* L = getRuneSpellScriptInterface()->getLuaState(); - getScriptInterface()->pushFunction(getScriptId()); + getRuneSpellScriptInterface()->pushFunction(getRuneSpellScriptId()); LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); @@ -1468,7 +1468,7 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr &creature, cons LuaScriptInterface::pushBoolean(L, isHotkey); - return getScriptInterface()->callFunction(3); + return getRuneSpellScriptInterface()->callFunction(3); } bool RuneSpell::isInstant() const { diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index 09908810000..5d9edb70dd6 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -82,11 +82,11 @@ class BaseSpell { virtual bool castSpell(const std::shared_ptr &creature) = 0; virtual bool castSpell(const std::shared_ptr &creature, const std::shared_ptr &target) = 0; - virtual LuaScriptInterface* getScriptInterface() const; - virtual bool loadScriptId(); - virtual int32_t getScriptId() const; - virtual void setScriptId(int32_t newScriptId); - virtual bool isLoadedScriptId() const; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; SoundEffect_t soundImpactEffect = SoundEffect_t::SILENCE; SoundEffect_t soundCastEffect = SoundEffect_t::SPELL_OR_RUNE; @@ -314,11 +314,11 @@ class RuneSpell final : public Action, public Spell { public: using Action::Action; - LuaScriptInterface* getScriptInterface() const override; - bool loadScriptId() override; - int32_t getScriptId() const override; - void setScriptId(int32_t newScriptId) override; - bool isLoadedScriptId() const override; + LuaScriptInterface* getRuneSpellScriptInterface() const; + bool loadRuneSpellScriptId(); + int32_t getRuneSpellScriptId() const; + void setRuneSpellScriptId(int32_t newScriptId); + bool isRuneSpellLoadedScriptId() const; ReturnValue canExecuteAction(const std::shared_ptr &player, const Position &toPos) override; bool hasOwnErrorHandler() override; @@ -341,6 +341,8 @@ class RuneSpell final : public Action, public Spell { private: bool internalCastSpell(const std::shared_ptr &creature, const LuaVariant &var, bool isHotkey) const; + int32_t m_runeSpellScriptId = 0; + uint16_t runeId = 0; uint32_t charges = 0; bool hasCharges = false; diff --git a/src/lua/functions/creatures/combat/spell_functions.cpp b/src/lua/functions/creatures/combat/spell_functions.cpp index b7130fc9912..0d2d4a955ef 100644 --- a/src/lua/functions/creatures/combat/spell_functions.cpp +++ b/src/lua/functions/creatures/combat/spell_functions.cpp @@ -146,7 +146,7 @@ int SpellFunctions::luaSpellOnCastSpell(lua_State* L) { Lua::pushBoolean(L, true); } else if (spell->spellType == SPELL_RUNE) { const auto &rune = std::static_pointer_cast(spell); - if (!rune->loadScriptId()) { + if (!rune->loadRuneSpellScriptId()) { Lua::pushBoolean(L, false); return 1; } @@ -189,7 +189,7 @@ int SpellFunctions::luaSpellRegister(lua_State* L) { iType.runeLevel = rune->getLevel(); iType.charges = rune->getCharges(); } - if (!rune->isLoadedScriptId()) { + if (!rune->isRuneSpellLoadedScriptId()) { Lua::pushBoolean(L, false); return 1; }