[7668] Cleanup In CreatureAI function descriptions and AttackStart/AttackedBy use. Author: VladimirMangos
* Use AI::AttackStart calls only in case explicit request creature attack from core or AI code "attack it if can".
Like taunt, pet handler attack command.
* Use AI::AttackedBy for reaction at hostile action "do something at hostile action"
Like non-dot damage, swing, negative spell landing, or fade fear/etc.
And provided by default call AttackStart if no current target.
This fix some problems, like:
* Civilian will react propertly at attack by another creature (not pet or player).
* Will not cases (at least triggred by core) when attack target start run to attacker before any real hostile action apply.
*Note: AttackBy is still disabled until proved useful to TC.
--HG--
branch : trunk
This commit is contained in:
+34
-8
@@ -73,7 +73,7 @@ enum SelectAggroTarget
|
||||
class TRINITY_DLL_SPEC UnitAI
|
||||
{
|
||||
protected:
|
||||
Unit *me;
|
||||
Unit* const me;
|
||||
public:
|
||||
explicit UnitAI(Unit *u) : me(u) {}
|
||||
virtual void AttackStart(Unit *);
|
||||
@@ -95,7 +95,7 @@ class TRINITY_DLL_SPEC UnitAI
|
||||
class TRINITY_DLL_SPEC PlayerAI : public UnitAI
|
||||
{
|
||||
protected:
|
||||
Player *me;
|
||||
Player* const me;
|
||||
public:
|
||||
explicit PlayerAI(Player *p) : UnitAI((Unit*)p), me(p) {}
|
||||
|
||||
@@ -111,8 +111,8 @@ class TRINITY_DLL_SPEC SimpleCharmedAI : public PlayerAI
|
||||
class TRINITY_DLL_SPEC CreatureAI : public UnitAI
|
||||
{
|
||||
protected:
|
||||
Creature *me;
|
||||
Creature *m_creature;
|
||||
Creature* const me;
|
||||
Creature* const m_creature;
|
||||
|
||||
bool UpdateVictim();
|
||||
public:
|
||||
@@ -120,13 +120,17 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
|
||||
|
||||
virtual ~CreatureAI() {}
|
||||
|
||||
// Called if IsVisible(Unit *who) is true at each *who move
|
||||
///== Reactions At =================================
|
||||
|
||||
// Called if IsVisible(Unit *who) is true at each *who move, reaction at visibility zone enter
|
||||
virtual void MoveInLineOfSight(Unit *);
|
||||
|
||||
// Called at stopping attack by any attacker
|
||||
// Called for reaction at stopping attack at no attackers or targets
|
||||
virtual void EnterEvadeMode();
|
||||
|
||||
// Called at any Damage from any attacker (before damage apply)
|
||||
// Note: it for recalculation damage or special reaction at damage
|
||||
// for attack reaction use AttackedBy called for not DOT damage in Unit::DealDamage also
|
||||
virtual void DamageTaken(Unit *done_by, uint32 & /*damage*/) {}
|
||||
|
||||
// Called when the creature is killed
|
||||
@@ -146,8 +150,8 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
|
||||
// Called when spell hits a target
|
||||
virtual void SpellHitTarget(Unit* target, const SpellEntry*) {}
|
||||
|
||||
// Called when vitim entered water and creature can not enter water
|
||||
virtual bool canReachByRangeAttack(Unit*) { return false; }
|
||||
// Called when the creature is target of hostile action: swing, hostile spell landed, fear/etc)
|
||||
//virtual void AttackedBy(Unit* attacker);
|
||||
|
||||
// Called when creature is spawned or respawned (for reseting variables)
|
||||
virtual void JustRespawned() {}
|
||||
@@ -161,6 +165,28 @@ class TRINITY_DLL_SPEC CreatureAI : public UnitAI
|
||||
virtual void JustReachedHome() {}
|
||||
|
||||
void DoZoneInCombat(Unit* pUnit = NULL);
|
||||
|
||||
///== Triggered Actions Requested ==================
|
||||
|
||||
// Called when creature attack expected (if creature can and no have current victim)
|
||||
// Note: for reaction at hostile action must be called AttackedBy function.
|
||||
virtual void AttackStart(Unit *) {}
|
||||
|
||||
// Called at World update tick
|
||||
virtual void UpdateAI(const uint32 diff ) {}
|
||||
|
||||
///== State checks =================================
|
||||
|
||||
// Is unit visible for MoveInLineOfSight
|
||||
//virtual bool IsVisible(Unit *) const { return false; }
|
||||
|
||||
// Called when victim entered water and creature can not enter water
|
||||
virtual bool canReachByRangeAttack(Unit*) { return false; }
|
||||
|
||||
///== Fields =======================================
|
||||
|
||||
// Pointer to controlled by AI creature
|
||||
//Creature* const m_creature;
|
||||
};
|
||||
|
||||
struct SelectableAI : public FactoryHolder<CreatureAI>, public Permissible<Creature>
|
||||
|
||||
Reference in New Issue
Block a user