mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-21 17:54:48 +01:00
Core/Game: implement combat args in the new SetAggresiveStateEvent
This commit is contained in:
@@ -490,11 +490,18 @@ void ScriptedAI::SetCombatMovement(bool allowMovement)
|
||||
_isCombatMovementAllowed = allowMovement;
|
||||
}
|
||||
|
||||
void ScriptedAI::SetAggressiveStateAfter(Milliseconds timer, Creature* who/* = nullptr*/, bool startCombat/* = true*/, Creature* summoner/* = nullptr*/)
|
||||
void ScriptedAI::SetAggressiveStateAfter(Milliseconds timer, Creature* who/* = nullptr*/, bool startCombat/* = true*/, Creature* summoner/* = nullptr*/, StartCombatArgs const& combatArgs/* = { }*/)
|
||||
{
|
||||
if (!who)
|
||||
who = me;
|
||||
who->m_Events.AddEvent(new Trinity::Helpers::Events::SetAggresiveStateEvent(who, startCombat, summoner->GetGUID()), who->m_Events.CalculateTime(timer));
|
||||
who->m_Events.AddEvent(new Trinity::Helpers::Events::SetAggresiveStateEvent(who, startCombat, summoner->GetGUID(), combatArgs), who->m_Events.CalculateTime(timer));
|
||||
}
|
||||
|
||||
void ScriptedAI::DoAddEvent(Milliseconds timer, BasicEvent* event, WorldObject* who/* = nullptr*/)
|
||||
{
|
||||
if (!who)
|
||||
who = me;
|
||||
who->m_Events.AddEvent(event, who->m_Events.CalculateTime(timer));
|
||||
}
|
||||
|
||||
// BossAI - for instanced bosses
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#ifndef TRINITY_SCRIPTEDCREATURE_H
|
||||
#define TRINITY_SCRIPTEDCREATURE_H
|
||||
|
||||
#include "CommonHelpers.h"
|
||||
#include "Creature.h" // convenience include for scripts, all uses of ScriptedCreature also need Creature (except ScriptedCreature itself doesn't need Creature)
|
||||
#include "CreatureAI.h"
|
||||
#include "DBCEnums.h"
|
||||
@@ -246,7 +247,9 @@ struct TC_GAME_API ScriptedAI : public CreatureAI
|
||||
// return true for 25 man or 25 man heroic mode
|
||||
bool Is25ManRaid() const { return _difficulty & RAID_DIFFICULTY_MASK_25MAN; }
|
||||
|
||||
void SetAggressiveStateAfter(Milliseconds timer, Creature* who = nullptr, bool startCombat = true, Creature* summoner = nullptr);
|
||||
void SetAggressiveStateAfter(Milliseconds timer, Creature* who = nullptr, bool startCombat = true, Creature* summoner = nullptr, StartCombatArgs const& combatArgs = { });
|
||||
|
||||
void DoAddEvent(Milliseconds timer, BasicEvent* event, WorldObject* who = nullptr);
|
||||
|
||||
template <class T>
|
||||
inline T const& DUNGEON_MODE(T const& normal5, T const& heroic10) const
|
||||
|
||||
@@ -327,7 +327,7 @@ bool Trinity::Helpers::Entity::IsPlayerRangedAttacker(Player const* who)
|
||||
}
|
||||
}
|
||||
|
||||
Trinity::Helpers::Events::SetAggresiveStateEvent::SetAggresiveStateEvent(Creature* owner, bool startCombat/* = true*/, ObjectGuid summonerGUID/* = ObjectGuid::Empty*/) : _owner(owner), _startCombat(startCombat), _summonerGUID(summonerGUID)
|
||||
Trinity::Helpers::Events::SetAggresiveStateEvent::SetAggresiveStateEvent(Creature* owner, bool startCombat/* = true*/, ObjectGuid summonerGUID/* = ObjectGuid::Empty*/, StartCombatArgs const& combatArgs/* = { }*/) : _owner(owner), _startCombat(startCombat), _summonerGUID(summonerGUID), _combatArgs(combatArgs)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -336,16 +336,26 @@ bool Trinity::Helpers::Events::SetAggresiveStateEvent::Execute(uint64 /*time*/,
|
||||
_owner->SetReactState(REACT_AGGRESSIVE);
|
||||
if (_startCombat)
|
||||
{
|
||||
if (Unit* currentVictim = _owner->SelectVictim())
|
||||
if (!_summonerGUID.IsEmpty())
|
||||
{
|
||||
if (Creature* summoner = ObjectAccessor::GetCreature(*_owner, _summonerGUID))
|
||||
if (summoner->IsEngaged() && summoner->IsAIEnabled() && _owner->IsAIEnabled())
|
||||
if (_combatArgs.AvoidTargetVictim)
|
||||
{
|
||||
if (Unit* target = summoner->AI()->SelectTarget(SelectTargetMethod::Random, 0, NonTankTargetSelector(summoner, _combatArgs.TargetPlayers)))
|
||||
_owner->AI()->AttackStart(target);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Unit* target = summoner->AI()->SelectTarget(SelectTargetMethod::Random, 0, _combatArgs.Distance, _combatArgs.TargetPlayers))
|
||||
_owner->AI()->AttackStart(target);
|
||||
}
|
||||
}
|
||||
else if (Unit* currentVictim = _owner->SelectVictim())
|
||||
{
|
||||
if (_owner->IsAIEnabled())
|
||||
_owner->AI()->AttackStart(currentVictim);
|
||||
}
|
||||
else if (!_summonerGUID.IsEmpty())
|
||||
if (Creature* summoner = ObjectAccessor::GetCreature(*_owner, _summonerGUID))
|
||||
if (summoner->IsEngaged() && summoner->IsAIEnabled() && _owner->IsAIEnabled())
|
||||
if (Unit* target = summoner->AI()->SelectTarget(SelectTargetMethod::Random, 0, 0.0f, true))
|
||||
_owner->AI()->AttackStart(target);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,18 @@
|
||||
class Creature;
|
||||
class Player;
|
||||
|
||||
struct TC_GAME_API StartCombatArgs
|
||||
{
|
||||
StartCombatArgs() {}
|
||||
StartCombatArgs& SetAvoidTargetVictim(bool value) { AvoidTargetVictim = value; return *this; }
|
||||
StartCombatArgs& SetTargetPlayers(bool value) { TargetPlayers = value; return *this; }
|
||||
StartCombatArgs& SetDistance(float value) { Distance = value; return *this; }
|
||||
|
||||
bool AvoidTargetVictim = false;
|
||||
bool TargetPlayers = true;
|
||||
float Distance = 0.f;
|
||||
};
|
||||
|
||||
namespace Trinity
|
||||
{
|
||||
namespace Helpers
|
||||
@@ -38,10 +50,10 @@ namespace Trinity
|
||||
}
|
||||
namespace Events
|
||||
{
|
||||
class SetAggresiveStateEvent : public BasicEvent
|
||||
class TC_GAME_API SetAggresiveStateEvent : public BasicEvent
|
||||
{
|
||||
public:
|
||||
SetAggresiveStateEvent(Creature* owner, bool startCombat = true, ObjectGuid summonerGUID = ObjectGuid::Empty);
|
||||
SetAggresiveStateEvent(Creature* owner, bool startCombat = true, ObjectGuid summonerGUID = ObjectGuid::Empty, StartCombatArgs const& combatArgs = { });
|
||||
|
||||
bool Execute(uint64 /*time*/, uint32 /*diff*/) override;
|
||||
|
||||
@@ -49,6 +61,7 @@ namespace Trinity
|
||||
Creature* _owner;
|
||||
bool const _startCombat;
|
||||
ObjectGuid const _summonerGUID;
|
||||
StartCombatArgs const _combatArgs;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user