Guest User

BackstabFront.cpp

a guest
Dec 12th, 2024
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include "ScriptMgr.h"
  2. #include "SpellScript.h"
  3. #include "Unit.h"
  4.  
  5. class spell_backstab_front : public SpellScriptLoader
  6. {
  7. public:
  8.     spell_backstab_front() : SpellScriptLoader("spell_backstab_front") { }
  9.  
  10.     class spell_backstab_front_SpellScript : public SpellScript
  11.     {
  12.         PrepareSpellScript(spell_backstab_front_SpellScript);
  13.  
  14.         void HandleOnHit()
  15.         {
  16.             Unit* caster = GetCaster();
  17.             Unit* target = GetHitUnit();
  18.  
  19.             if (!caster || !target)
  20.                 return;
  21.  
  22.             // Check if the caster is behind the target
  23.             if (!target->isInBack(caster)) // Check if not behind
  24.             {
  25.                 // Only deal 80% of the damage if not behind the target
  26.                 SetHitDamage(int32(GetHitDamage() * 0.8f));
  27.             }
  28.         }
  29.  
  30.         void Register() override
  31.         {
  32.             OnHit += SpellHitFn(spell_backstab_front_SpellScript::HandleOnHit);
  33.         }
  34.     };
  35.  
  36.     SpellScript* GetSpellScript() const override
  37.     {
  38.         return new spell_backstab_front_SpellScript();
  39.     }
  40. };
  41.  
  42. void AddSC_spell_backstab_front()
  43. {
  44.     new spell_backstab_front();
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment