Skip to content

Commit

Permalink
fix: sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas committed Nov 10, 2024
1 parent beed45b commit 811626c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 29 deletions.
34 changes: 17 additions & 17 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ bool Spells::registerRuneLuaEvent(const std::shared_ptr<RuneSpell> &rune) {
"[{}] duplicate registered rune with id: {}, for script: {}",
__FUNCTION__,
id,
rune->getScriptInterface()->getLoadingScriptName()
rune->getRuneSpellScriptInterface()->getLoadingScriptName()
);
}
return inserted;
Expand Down Expand Up @@ -1311,31 +1311,31 @@ bool InstantSpell::canCast(const std::shared_ptr<Player> &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;
}

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> &player, const Position &toPos) {
Expand Down Expand Up @@ -1373,7 +1373,7 @@ bool RuneSpell::executeUse(const std::shared_ptr<Player> &player, const std::sha
}

// If script not loaded correctly, return
if (!isLoadedScriptId()) {
if (!isRuneSpellLoadedScriptId()) {
return false;
}

Expand Down Expand Up @@ -1437,7 +1437,7 @@ bool RuneSpell::castSpell(const std::shared_ptr<Creature> &creature, const std::

bool RuneSpell::internalCastSpell(const std::shared_ptr<Creature> &creature, const LuaVariant &var, bool isHotkey) const {
bool result;
if (isLoadedScriptId()) {
if (isRuneSpellLoadedScriptId()) {
result = executeCastSpell(creature, var, isHotkey);
} else {
result = false;
Expand All @@ -1455,11 +1455,11 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr<Creature> &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<Creature>(L, creature);
LuaScriptInterface::setCreatureMetatable(L, -1, creature);
Expand All @@ -1468,7 +1468,7 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr<Creature> &creature, cons

LuaScriptInterface::pushBoolean(L, isHotkey);

return getScriptInterface()->callFunction(3);
return getRuneSpellScriptInterface()->callFunction(3);
}

bool RuneSpell::isInstant() const {
Expand Down
22 changes: 12 additions & 10 deletions src/creatures/combat/spells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ class BaseSpell {
virtual bool castSpell(const std::shared_ptr<Creature> &creature) = 0;
virtual bool castSpell(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Creature> &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;
Expand Down Expand Up @@ -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> &player, const Position &toPos) override;
bool hasOwnErrorHandler() override;
Expand All @@ -341,6 +341,8 @@ class RuneSpell final : public Action, public Spell {
private:
bool internalCastSpell(const std::shared_ptr<Creature> &creature, const LuaVariant &var, bool isHotkey) const;

int32_t m_runeSpellScriptId = 0;

uint16_t runeId = 0;
uint32_t charges = 0;
bool hasCharges = false;
Expand Down
4 changes: 2 additions & 2 deletions src/lua/functions/creatures/combat/spell_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RuneSpell>(spell);
if (!rune->loadScriptId()) {
if (!rune->loadRuneSpellScriptId()) {
Lua::pushBoolean(L, false);
return 1;
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 811626c

Please sign in to comment.