CreatureAI: Adjust AI behavior when a charm ends. OnCharmed will be invoked on the creature's base (non-charmed) AI, allowing the AI to react to the creature no longer being charmed.

This commit is contained in:
treeston authored and Aokromes committed 2016-05-12 09:16:31 +02:00
1 parent 73fd689c1e
commit 5671f50933
7 files changed
+27 -6

No files matched your search

+6
View File
@@ -58,6 +58,12 @@ void PossessedAI::KilledUnit(Unit* victim)
victim->RemoveFlag(UNIT_DYNAMIC_FLAGS, UNIT_DYNFLAG_LOOTABLE);
}
void PossessedAI::OnCharmed(bool /*apply*/)
{
me->NeedChangeAI = true;
me->IsAIEnabled = false;
}
void CritterAI::DamageTaken(Unit* /*done_by*/, uint32&)
{
if (!me->HasUnitState(UNIT_STATE_FLEEING))
+2
View File
@@ -46,6 +46,8 @@ class PossessedAI : public CreatureAI
void JustDied(Unit*) override;
void KilledUnit(Unit* victim) override;
void OnCharmed(bool /*apply*/) override;
static int Permissible(const Creature*) { return PERMIT_BASE_IDLE; }
};
+6
View File
@@ -588,6 +588,12 @@ void PetAI::ReceiveEmote(Player* player, uint32 emote)
}
}
void PetAI::OnCharmed(bool /*apply*/)
{
me->NeedChangeAI = true;
me->IsAIEnabled = false;
}
void PetAI::ClearCharmInfoFlags()
{
// Quick access to set all flags to FALSE
+2
View File
@@ -49,6 +49,8 @@ class PetAI : public CreatureAI
void MoveInLineOfSight_Safe(Unit* /*who*/) { } // CreatureAI interferes with returning pets
void EnterEvadeMode(EvadeReason /*why*/) override { } // For fleeing, pets don't use this type of Evade mechanic
void OnCharmed(bool /*apply*/) override;
private:
bool _isVisible(Unit*) const;
bool _needToStop(void);
+6 -4
View File
@@ -29,11 +29,13 @@
#include "Language.h"
//Disable CreatureAI when charmed
void CreatureAI::OnCharmed(bool /*apply*/)
void CreatureAI::OnCharmed(bool apply)
{
//me->IsAIEnabled = !apply;*/
me->NeedChangeAI = true;
me->IsAIEnabled = false;
if (apply)
{
me->NeedChangeAI = true;
me->IsAIEnabled = false;
}
}
AISpellInfoType* UnitAI::AISpellInfo;
+2 -2
View File
@@ -653,8 +653,8 @@ void SmartAI::OnCharmed(bool apply)
{
GetScript()->ProcessEventsFor(SMART_EVENT_CHARMED, NULL, 0, 0, apply);
if (!apply && !me->IsInEvadeMode() && me->GetCharmerGUID())
if (Unit* charmer = ObjectAccessor::GetUnit(*me, me->GetCharmerGUID()))
if (!apply && !me->IsInEvadeMode())
if (Unit* charmer = me->GetCharmer())
AttackStart(charmer);
}
+3
View File
@@ -12166,6 +12166,9 @@ void Unit::UpdateCharmAI()
delete i_AI;
i_AI = i_disabledAI;
i_disabledAI = nullptr;
if (GetTypeId() == TYPEID_UNIT)
ToCreature()->AI()->OnCharmed(false);
}
}
else