Skip to content

Commit

Permalink
PetAI: Enable more extensive scripting for pets
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed Jan 2, 2025
1 parent 40ad272 commit fb6c253
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
24 changes: 22 additions & 2 deletions src/game/AI/BaseAI/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ int PetAI::Permissible(const Creature* creature)
return PERMIT_BASE_NO;
}

PetAI::PetAI(Creature* creature) : CreatureAI(creature), inCombat(false)
PetAI::PetAI(Creature* creature) : PetAI(creature, 0)
{

}

PetAI::PetAI(Creature* creature, uint32 combatActions) : CreatureAI(creature, combatActions), inCombat(false)
{
m_followAngle = M_PI_F / 2;
m_followDist = 1.5f;
Expand Down Expand Up @@ -134,12 +139,19 @@ void PetAI::EnterEvadeMode()

void PetAI::UpdateAI(const uint32 diff)
{
Unit* owner = m_unit->GetMaster();

if (CanHandleCharm() && !owner)
{
CreatureAI::UpdateAI(diff);
return;
}

UpdateTimers(diff, m_creature->IsInCombat());

Creature* creature = (m_unit->GetTypeId() == TYPEID_UNIT) ? static_cast<Creature*>(m_unit) : nullptr;
Pet* pet = (creature && creature->IsPet()) ? static_cast<Pet*>(m_unit) : nullptr;

Unit* owner = m_unit->GetMaster();
if (!owner)
return;

Expand Down Expand Up @@ -182,6 +194,8 @@ void PetAI::UpdateAI(const uint32 diff)
charminfo->SetIsRetreating();
}

ExecuteActions();

// Stop here if casting spell (No melee and no movement)
if (m_unit->IsNonMeleeSpellCasted(false))
return;
Expand Down Expand Up @@ -439,6 +453,12 @@ void PetAI::JustDied(Unit* killer)
void PetAI::AttackedBy(Unit* attacker)
{
CharmInfo* charminfo = m_unit->GetCharmInfo();
if (CanHandleCharm() && !charminfo)
{
CreatureAI::AttackedBy(attacker);
return;
}

MANGOS_ASSERT(charminfo);

// when attacked, fight back if no victim unless we have a charm state set to passive
Expand Down
1 change: 1 addition & 0 deletions src/game/AI/BaseAI/PetAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PetAI : public CreatureAI
public:

explicit PetAI(Creature* creature);
explicit PetAI(Creature* creature, uint32 combatActions);

void MoveInLineOfSight(Unit* who) override;
void AttackStart(Unit* who) override;
Expand Down
2 changes: 1 addition & 1 deletion src/game/AI/BaseAI/UnitAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ class UnitAI : public CombatActions
virtual void JustStunnedTarget(SpellEntry const* spellInfo, Unit* victim) { JustStoppedMovementOfTarget(spellInfo, victim); }

// AI selection - works in connection with IsPossessCharmType
virtual bool CanHandleCharm() { return false; }
virtual bool CanHandleCharm() const { return false; }
virtual void JustGotCharmed(Unit* charmer) {}

// Movement generator responses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ struct npc_chess_piece_genericAI : public Scripted_NoMovementAI
void MoveInLineOfSight(Unit* /*pWho*/) override { }
void AttackStart(Unit* /*pWho*/) override { }
void EnterEvadeMode() override { }
bool CanHandleCharm() override { return true; }
bool CanHandleCharm() const override { return true; }

void JustDied(Unit* /*pKiller*/) override
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ struct npc_fel_cannon : public Scripted_NoMovementAI
m_creature->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNINTERACTIBLE);
}

bool CanHandleCharm() override { return true; }
bool CanHandleCharm() const override { return true; }

void SpellHit(Unit* /*pCaster*/, const SpellEntry* pSpell) override
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2362,7 +2362,7 @@ struct npc_razorthorn_ravager : public CombatAI

}

bool CanHandleCharm() override { return true; }
bool CanHandleCharm() const override { return true; }

void JustGotCharmed(Unit* /*charmer*/) override
{
Expand Down
2 changes: 1 addition & 1 deletion src/game/AI/ScriptDevAI/scripts/outland/netherstorm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2766,7 +2766,7 @@ struct npc_scrap_reaverAI : ScriptedPetAI

}

bool CanHandleCharm() override { return true; }
bool CanHandleCharm() const override { return true; }

void JustRespawned() override
{
Expand Down

0 comments on commit fb6c253

Please sign in to comment.