Skip to content

Commit

Permalink
AI: Set ranged mode automatically for guards who have spell lists
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Aug 19, 2023
1 parent 27b85ce commit 5c1b290
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
9 changes: 0 additions & 9 deletions src/game/AI/BaseAI/GuardAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,3 @@ void GuardAI::MoveInLineOfSight(Unit* who)
}
}
}

void GuardAI::UpdateAI(const uint32 /*diff*/)
{
// update i_victimGuid if i_creature.GetVictim() !=0 and changed
if (!m_creature->SelectHostileTarget() || !m_creature->GetVictim())
return;

DoMeleeAttackIfReady();
}
1 change: 0 additions & 1 deletion src/game/AI/BaseAI/GuardAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class GuardAI : public CreatureAI

void MoveInLineOfSight(Unit* who) override;

void UpdateAI(const uint32 diff) override;
static int Permissible(const Creature* creature);
protected:
std::string GetAIName() override { return "GuardAI"; }
Expand Down
20 changes: 20 additions & 0 deletions src/game/AI/ScriptDevAI/base/guard_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ void guardAI::JustDied(Unit* killer)
m_creature->SendZoneUnderAttackMessage(pPlayer);
}

void guardAI::JustRespawned()
{
CombatAI::JustRespawned();
const auto& spellList = GetSpellList();
if (spellList.ChanceRangedAttack)
{
for (auto& spell : spellList.Spells)
{
if (spell.second.Flags & SPELL_LIST_FLAG_RANGED_ACTION)
{
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(spell.second.SpellId);
if (!spellInfo)
continue;
SetRangedMode(true, CalculateSpellRange(spellInfo) * 0.8f, TYPE_PROXIMITY);
break;
}
}
}
}

void guardAI::DoReplyToTextEmote(uint32 textEmote)
{
switch (textEmote)
Expand Down
1 change: 1 addition & 0 deletions src/game/AI/ScriptDevAI/base/guard_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ struct guardAI : public CombatAI
void Aggro(Unit* who) override;

void JustDied(Unit* /*killer*/) override;
void JustRespawned() override;

// Commonly used for guards in main cities
void DoReplyToTextEmote(uint32 textEmote);
Expand Down

0 comments on commit 5c1b290

Please sign in to comment.