fix(Scripts/SSC): Fix being able to damage Leo's minions if you are n… (#17786)

* fix(Scripts/SSC): Fix being able to damage Leo's minions if you are not the target player

* implement helper

* Update Creature.cpp

* Update Creature.h
This commit is contained in:
Andrew
2023-11-19 08:38:47 -03:00
committed by GitHub
parent 4bf20ffde4
commit bf40479db6
3 changed files with 40 additions and 13 deletions

View File

@@ -3736,6 +3736,15 @@ bool Creature::CanCastSpell(uint32 spellID) const
return true;
}
ObjectGuid Creature::GetSummonerGUID() const
{
if (TempSummon const* temp = ToTempSummon())
return temp->GetSummonerGUID();
LOG_DEBUG("entities.unit", "Creature::GetSummonerGUID() called by creature that is not a summon. Creature: {} ({})", GetEntry(), GetName());
return ObjectGuid::Empty;
}
std::string Creature::GetDebugInfo() const
{
std::stringstream sstr;

View File

@@ -407,6 +407,12 @@ public:
* */
bool CanCastSpell(uint32 spellID) const;
/**
* @brief Helper to get the creature's summoner GUID, if it is a summon
*
* */
[[nodiscard]] ObjectGuid GetSummonerGUID() const;
std::string GetDebugInfo() const override;
protected:

View File

@@ -238,13 +238,6 @@ struct npc_inner_demon : public ScriptedAI
if (!summoner)
return;
//summoner is always the affected player
_affectedPlayerGUID = summoner->GetGUID();
if (Unit* affectedPlayer = summoner->ToUnit())
{
me->Attack(affectedPlayer, true);
}
scheduler.CancelAll();
scheduler.Schedule(4s, [this](TaskContext context)
{
@@ -255,15 +248,36 @@ struct npc_inner_demon : public ScriptedAI
void JustDied(Unit* /*killer*/) override
{
if (Unit* affectedPlayer = ObjectAccessor::GetUnit(*me, _affectedPlayerGUID))
if (Unit* affectedPlayer = ObjectAccessor::GetUnit(*me, me->GetSummonerGUID()))
{
affectedPlayer->RemoveAurasDueToSpell(SPELL_INSIDIOUS_WHISPER);
}
}
void DamageTaken(Unit* who, uint32& damage, DamageEffectType, SpellSchoolMask) override
bool CanReceiveDamage(Unit* attacker)
{
if (!who || who->GetGUID() != _affectedPlayerGUID)
return attacker && attacker->GetGUID() == me->GetSummonerGUID();
}
void OnCalculateMeleeDamageReceived(uint32& damage, Unit* attacker) override
{
if (!CanReceiveDamage(attacker))
{
damage = 0;
}
}
void OnCalculateSpellDamageReceived(int32& damage, Unit* attacker) override
{
if (!CanReceiveDamage(attacker))
{
damage = 0;
}
}
void OnCalculatePeriodicTickReceived(uint32& damage, Unit* attacker) override
{
if (!CanReceiveDamage(attacker))
{
damage = 0;
}
@@ -271,7 +285,7 @@ struct npc_inner_demon : public ScriptedAI
bool CanAIAttack(Unit const* who) const override
{
return who->GetGUID() == _affectedPlayerGUID;
return who->GetGUID() == me->GetSummonerGUID();
}
void UpdateAI(uint32 diff) override
@@ -285,8 +299,6 @@ struct npc_inner_demon : public ScriptedAI
DoMeleeAttackIfReady();
}
private:
ObjectGuid _affectedPlayerGUID;
};
class spell_leotheras_whirlwind : public SpellScript