Skip to content

fix(Core/Scripting): UnitScript::DealDamage always returns the original damage value #22206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/game/Scripting/ScriptDefines/UnitScript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ uint32 ScriptMgr::DealDamage(Unit* AttackerUnit, Unit* pVictim, uint32 damage, D
auto const& dmg = script->DealDamage(AttackerUnit, pVictim, damage, damagetype);
if (dmg != damage)
{
return damage;
return dmg;
}
}
Copy link
Member

@sogladev sogladev May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
auto const& dmg = script->DealDamage(AttackerUnit, pVictim, damage, damagetype);
if (dmg != damage)
{
return damage;
return dmg;
}
}
damage = script->DealDamage(AttackerUnit, pVictim, damage, damagetype);
}

Looking through the git history the above looks like the intended behavior

original function:

uint32 ScriptMgr::DealDamage(Unit* AttackerUnit, Unit *pVictim, uint32 damage, DamageEffectType damagetype)

with macro expansion

uint32 ScriptMgr::DealDamage(Unit* AttackerUnit, Unit *pVictim, uint32 damage, DamageEffectType damagetype)
{
  if (ScriptRegistry<UnitScript>::ScriptPointerList.empty())
    return damage;
  for (ScriptRegistry<UnitScript>::ScriptMapIterator itr =
           ScriptRegistry<UnitScript>::ScriptPointerList.begin();
       itr != ScriptRegistry<UnitScript>::ScriptPointerList.end(); ++itr)
    damage = itr->second->DealDamage(AttackerUnit, pVictim, damage, damagetype);
  return damage;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea good catch, as it was written only the first script was actually ever being ran (alongside returning the wrong value -- this was really wrong!). I will adjust the code


Expand Down