Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
Core/AI: use default PetAI only for class pets and allow using custom…
Browse files Browse the repository at this point in the history
… PetAI for non-class pets

* restore the attack ai hook calls for summons
* fixed Fungal Growth when the treants spawned by Force of Nature die
  • Loading branch information
Ovahlord committed Oct 20, 2023
1 parent bf3d12b commit 90bee2c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
6 changes: 2 additions & 4 deletions src/server/game/AI/CreatureAISelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
#include "Creature.h"
#include "CreatureAISelector.h"
#include "CreatureAIFactory.h"

#include "MovementGenerator.h"

#include "GameObject.h"
#include "GameObjectAIFactory.h"

#include "Log.h"
#include "ScriptMgr.h"
#include "NewPet.h"

namespace FactorySelector
{
Expand Down Expand Up @@ -81,7 +79,7 @@ namespace FactorySelector
CreatureAI* SelectAI(Creature* creature)
{
// special pet case, if a tamed creature uses AIName (example SmartAI) we need to override it
if (creature->IsPet())
if (creature->IsPet() && creature->ToNewPet()->IsClassPet())
return ASSERT_NOTNULL(sCreatureAIRegistry->GetRegistryItem("PetAI"))->Create(creature);

// scriptname in db
Expand Down
22 changes: 20 additions & 2 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,9 +755,18 @@ bool Unit::HasBreakableByDamageCrowdControlAura(Unit* excludeCasterChannel) cons
// Hook for OnDamage Event
sScriptMgr->OnDamage(attacker, victim, damage);

if (victim->GetTypeId() == TYPEID_PLAYER)
if (victim->IsPlayer())
{
// Signal to pets that their owner was attacked - except when dealing damage via DOT
if (attacker != victim && damagetype != DOT)
for (ObjectGuid const& summonGuid : victim->GetSummonGUIDs())
if (NewTemporarySummon* summon = victim->GetSummonByGUID(summonGuid))
if (CreatureAI* ai = summon->AI())
ai->OwnerAttackedBy(attacker);

if (victim->ToPlayer()->GetCommandStatus(CHEAT_GOD))
return 0;
}

if (damagetype != NODAMAGE)
{
Expand Down Expand Up @@ -5376,10 +5385,19 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
if (haveOffhandWeapon() && GetTypeId() != TYPEID_PLAYER)
setAttackTimer(OFF_ATTACK, std::max(getAttackTimer(OFF_ATTACK), getAttackTimer(BASE_ATTACK) + uint32(CalculatePct(GetFloatValue(UNIT_FIELD_BASEATTACKTIME), 50))));


if (meleeAttack)
SendMeleeAttackStart(victim);

// Let the pet know we've started attacking someting. Handles melee attacks only
// Spells such as auto-shot and others handled in WorldSession::HandleCastSpellOpcode
if (IsPlayer())
{
for (ObjectGuid const& summonGuid : GetSummonGUIDs())
if (NewTemporarySummon* summon = GetSummonByGUID(summonGuid))
if (CreatureAI* ai = summon->AI())
ai->OwnerAttacked(victim);
}

return true;
}

Expand Down
12 changes: 12 additions & 0 deletions src/server/game/Spells/Spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3539,6 +3539,18 @@ void Spell::_cast(bool skipCheck)
// now that we've done the basic check, now run the scripts
// should be done before the spell is actually executed
sScriptMgr->OnPlayerSpellCast(playerCaster, this, skipCheck);

// As of 3.0.2 pets begin attacking their owner's target immediately
// Let any pets know we've attacked something. Check DmgClass for harmful spells only
// This prevents spells such as Hunter's Mark from triggering pet attack
if (GetSpellInfo()->DmgClass != SPELL_DAMAGE_CLASS_NONE)
{
if (Unit* unitTarget = m_targets.GetUnitTarget())
for (ObjectGuid const& summonGuid : playerCaster->GetSummonGUIDs())
if (NewTemporarySummon* summon = playerCaster->GetSummonByGUID(summonGuid))
if (CreatureAI* ai =summon->AI())
ai->OwnerAttacked(unitTarget);
}
}

SetExecutedCurrently(true);
Expand Down
36 changes: 13 additions & 23 deletions src/server/scripts/World/npcs_special.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "SpellAuras.h"
#include "SpellHistory.h"
#include "SpellMgr.h"
#include "NewTemporarySummon.h"
#include "Vehicle.h"
#include "World.h"

Expand Down Expand Up @@ -2907,34 +2908,23 @@ enum DruidTreant
SPELL_FUNGAL_GROWTH_SUMMON_R2 = 81283
};

class npc_druid_treant : public CreatureScript
struct npc_druid_treant : public PetAI
{
public:
npc_druid_treant() : CreatureScript("npc_druid_treant") { }
npc_druid_treant(Creature* creature) : PetAI(creature) { }

struct npc_druid_treantAI : public PetAI
void JustDied(Unit* /*killer*/) override
{
if (NewTemporarySummon const* summon = me->ToTemporarySummon())
{
npc_druid_treantAI(Creature* creature) : PetAI(creature) { }

void JustDied(Unit* /*killer*/) override
if (Unit* summoner = summon->GetInternalSummoner())
{
if (TempSummon* summon = me->ToTempSummon())
{
if (Unit* summoner = summon->GetSummoner())
{
if (summoner->HasAura(SPELL_FUNGAL_GROWTH_R1))
summoner->CastSpell(me, SPELL_FUNGAL_GROWTH_SUMMON_R1, true);
else if (summoner->HasAura(SPELL_FUNGAL_GROWTH_R2))
summoner->CastSpell(me, SPELL_FUNGAL_GROWTH_SUMMON_R2, true);
}
}
if (summoner->HasAura(SPELL_FUNGAL_GROWTH_R1))
summoner->CastSpell(me, SPELL_FUNGAL_GROWTH_SUMMON_R1, true);
else if (summoner->HasAura(SPELL_FUNGAL_GROWTH_R2))
summoner->CastSpell(me, SPELL_FUNGAL_GROWTH_SUMMON_R2, true);
}
};

CreatureAI* GetAI(Creature* creature) const override
{
return new npc_druid_treantAI(creature);
}
}
};

enum WildMushroom
Expand Down Expand Up @@ -3091,7 +3081,7 @@ void AddSC_npcs_special()
new npc_argent_squire_gruntling();
new npc_bountiful_table();
RegisterCreatureAI(npc_mage_orb);
new npc_druid_treant();
RegisterCreatureAI(npc_druid_treant);
RegisterCreatureAI(npc_druid_wild_mushroom);
RegisterCreatureAI(npc_darkmoon_island_gnoll);
}

0 comments on commit 90bee2c

Please sign in to comment.