mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-17 21:50:50 -04:00
Core/AI: logs, codestyle & cosmetics standarization
This commit is contained in:
@@ -16,13 +16,6 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/* ScriptData
|
||||
SDName: FollowerAI
|
||||
SD%Complete: 50
|
||||
SDComment: This AI is under development
|
||||
SDCategory: Npc
|
||||
EndScriptData */
|
||||
|
||||
#include "ScriptedFollowerAI.h"
|
||||
#include "Creature.h"
|
||||
#include "Group.h"
|
||||
@@ -32,18 +25,14 @@ EndScriptData */
|
||||
#include "ObjectAccessor.h"
|
||||
#include "Player.h"
|
||||
|
||||
const float MAX_PLAYER_DISTANCE = 100.0f;
|
||||
float constexpr MAX_PLAYER_DISTANCE = 100.0f;
|
||||
|
||||
enum Points
|
||||
{
|
||||
POINT_COMBAT_START = 0xFFFFFF
|
||||
POINT_COMBAT_START = 0xFFFFFF
|
||||
};
|
||||
|
||||
FollowerAI::FollowerAI(Creature* creature) : ScriptedAI(creature),
|
||||
_updateFollowTimer(2500),
|
||||
_followState(STATE_FOLLOW_NONE),
|
||||
_questForFollow(nullptr)
|
||||
{ }
|
||||
FollowerAI::FollowerAI(Creature* creature) : ScriptedAI(creature), _updateFollowTimer(2500), _followState(STATE_FOLLOW_NONE), _questForFollow(nullptr) { }
|
||||
|
||||
void FollowerAI::AttackStart(Unit* who)
|
||||
{
|
||||
@@ -62,27 +51,27 @@ void FollowerAI::AttackStart(Unit* who)
|
||||
}
|
||||
}
|
||||
|
||||
//This part provides assistance to a player that are attacked by who, even if out of normal aggro range
|
||||
//It will cause me to attack who that are attacking _any_ player (which has been confirmed may happen also on offi)
|
||||
//The flag (type_flag) is unconfirmed, but used here for further research and is a good candidate.
|
||||
// This part provides assistance to a player that are attacked by who, even if out of normal aggro range
|
||||
// It will cause me to attack who that are attacking _any_ player (which has been confirmed may happen also on offi)
|
||||
// The flag (type_flag) is unconfirmed, but used here for further research and is a good candidate.
|
||||
bool FollowerAI::AssistPlayerInCombatAgainst(Unit* who)
|
||||
{
|
||||
if (!who || !who->GetVictim())
|
||||
return false;
|
||||
|
||||
//experimental (unknown) flag not present
|
||||
// experimental (unknown) flag not present
|
||||
if (!(me->GetCreatureTemplate()->type_flags & CREATURE_TYPE_FLAG_CAN_ASSIST))
|
||||
return false;
|
||||
|
||||
//not a player
|
||||
// not a player
|
||||
if (!who->EnsureVictim()->GetCharmerOrOwnerPlayerOrPlayerItself())
|
||||
return false;
|
||||
|
||||
//never attack friendly
|
||||
// never attack friendly
|
||||
if (me->IsFriendlyTo(who))
|
||||
return false;
|
||||
|
||||
//too far away and no free sight?
|
||||
// too far away and no free sight?
|
||||
if (me->IsWithinDistInMap(who, MAX_PLAYER_DISTANCE) && me->IsWithinLOSInMap(who))
|
||||
{
|
||||
me->EngageWithTarget(who);
|
||||
@@ -167,14 +156,10 @@ void FollowerAI::EnterEvadeMode(EvadeReason /*why*/)
|
||||
|
||||
if (HasFollowState(STATE_FOLLOW_INPROGRESS))
|
||||
{
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI left combat, returning to CombatStartPosition.");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::EnterEvadeMode: left combat, returning to CombatStartPosition. (%s)", me->GetGUID().ToString().c_str());
|
||||
|
||||
if (me->GetMotionMaster()->GetCurrentMovementGeneratorType() == CHASE_MOTION_TYPE)
|
||||
{
|
||||
float fPosX, fPosY, fPosZ;
|
||||
me->GetPosition(fPosX, fPosY, fPosZ);
|
||||
me->GetMotionMaster()->MovePoint(POINT_COMBAT_START, fPosX, fPosY, fPosZ);
|
||||
}
|
||||
me->GetMotionMaster()->MovePoint(POINT_COMBAT_START, me->GetPosition());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -187,24 +172,24 @@ void FollowerAI::EnterEvadeMode(EvadeReason /*why*/)
|
||||
|
||||
void FollowerAI::UpdateAI(uint32 uiDiff)
|
||||
{
|
||||
if (HasFollowState(STATE_FOLLOW_INPROGRESS) && !me->GetVictim())
|
||||
if (HasFollowState(STATE_FOLLOW_INPROGRESS) && !me->IsEngaged())
|
||||
{
|
||||
if (_updateFollowTimer <= uiDiff)
|
||||
{
|
||||
if (HasFollowState(STATE_FOLLOW_COMPLETE) && !HasFollowState(STATE_FOLLOW_POSTEVENT))
|
||||
{
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI is set completed, despawns.");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::UpdateAI: is set completed, despawns. (%s)", me->GetGUID().ToString().c_str());
|
||||
me->DespawnOrUnsummon();
|
||||
return;
|
||||
}
|
||||
|
||||
bool bIsMaxRangeExceeded = true;
|
||||
bool maxRangeExceeded = true;
|
||||
|
||||
if (Player* player = GetLeaderForFollower())
|
||||
{
|
||||
if (HasFollowState(STATE_FOLLOW_RETURNING))
|
||||
{
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI is returning to leader.");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::UpdateAI: is returning to leader. (%s)", me->GetGUID().ToString().c_str());
|
||||
|
||||
RemoveFollowState(STATE_FOLLOW_RETURNING);
|
||||
me->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
|
||||
@@ -218,7 +203,7 @@ void FollowerAI::UpdateAI(uint32 uiDiff)
|
||||
Player* member = groupRef->GetSource();
|
||||
if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE))
|
||||
{
|
||||
bIsMaxRangeExceeded = false;
|
||||
maxRangeExceeded = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -226,13 +211,13 @@ void FollowerAI::UpdateAI(uint32 uiDiff)
|
||||
else
|
||||
{
|
||||
if (me->IsWithinDistInMap(player, MAX_PLAYER_DISTANCE))
|
||||
bIsMaxRangeExceeded = false;
|
||||
maxRangeExceeded = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (bIsMaxRangeExceeded)
|
||||
if (maxRangeExceeded)
|
||||
{
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI failed because player/group was to far away or not found");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::UpdateAI: failed because player/group was to far away or not found (%s)", me->GetGUID().ToString().c_str());
|
||||
me->DespawnOrUnsummon();
|
||||
return;
|
||||
}
|
||||
@@ -254,12 +239,12 @@ void FollowerAI::UpdateFollowerAI(uint32 /*uiDiff*/)
|
||||
DoMeleeAttackIfReady();
|
||||
}
|
||||
|
||||
void FollowerAI::MovementInform(uint32 motionType, uint32 pointId)
|
||||
void FollowerAI::MovementInform(uint32 type, uint32 id)
|
||||
{
|
||||
if (motionType != POINT_MOTION_TYPE || !HasFollowState(STATE_FOLLOW_INPROGRESS))
|
||||
if (type != POINT_MOTION_TYPE || !HasFollowState(STATE_FOLLOW_INPROGRESS))
|
||||
return;
|
||||
|
||||
if (pointId == POINT_COMBAT_START)
|
||||
if (id == POINT_COMBAT_START)
|
||||
{
|
||||
if (GetLeaderForFollower())
|
||||
{
|
||||
@@ -273,19 +258,19 @@ void FollowerAI::MovementInform(uint32 motionType, uint32 pointId)
|
||||
|
||||
void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, Quest const* quest)
|
||||
{
|
||||
if (me->GetVictim())
|
||||
if (me->IsEngaged())
|
||||
{
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI attempt to StartFollow while in combat.");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::StartFollow: attempt to StartFollow while in combat. (%s)", me->GetGUID().ToString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasFollowState(STATE_FOLLOW_INPROGRESS))
|
||||
{
|
||||
TC_LOG_ERROR("scripts", "FollowerAI attempt to StartFollow while already following.");
|
||||
TC_LOG_ERROR("scripts.ai.followerai", "FollowerAI::StartFollow: attempt to StartFollow while already following. (%s)", me->GetGUID().ToString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
//set variables
|
||||
// set variables
|
||||
_leaderGUID = player->GetGUID();
|
||||
|
||||
if (factionForFollower)
|
||||
@@ -297,7 +282,6 @@ void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, Quest co
|
||||
{
|
||||
me->GetMotionMaster()->Clear();
|
||||
me->GetMotionMaster()->MoveIdle();
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI start with WAYPOINT_MOTION_TYPE, set to MoveIdle.");
|
||||
}
|
||||
|
||||
me->SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
|
||||
@@ -306,7 +290,7 @@ void FollowerAI::StartFollow(Player* player, uint32 factionForFollower, Quest co
|
||||
|
||||
me->GetMotionMaster()->MoveFollow(player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
|
||||
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI start follow %s (%s)", player->GetName().c_str(), _leaderGUID.ToString().c_str());
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::StartFollow: start follow %s - %s (%s)", player->GetName().c_str(), _leaderGUID.ToString().c_str(), me->GetGUID().ToString().c_str());
|
||||
}
|
||||
|
||||
Player* FollowerAI::GetLeaderForFollower()
|
||||
@@ -324,7 +308,7 @@ Player* FollowerAI::GetLeaderForFollower()
|
||||
Player* member = groupRef->GetSource();
|
||||
if (member && me->IsWithinDistInMap(member, MAX_PLAYER_DISTANCE) && member->IsAlive())
|
||||
{
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI GetLeader changed and returned new leader.");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::GetLeaderForFollower: GetLeader changed and returned new leader. (%s)", me->GetGUID().ToString().c_str());
|
||||
_leaderGUID = member->GetGUID();
|
||||
return member;
|
||||
}
|
||||
@@ -333,11 +317,11 @@ Player* FollowerAI::GetLeaderForFollower()
|
||||
}
|
||||
}
|
||||
|
||||
TC_LOG_DEBUG("scripts", "FollowerAI GetLeader can not find suitable leader.");
|
||||
TC_LOG_DEBUG("scripts.ai.followerai", "FollowerAI::GetLeaderForFollower: GetLeader can not find suitable leader. (%s)", me->GetGUID().ToString().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void FollowerAI::SetFollowComplete(bool bWithEndEvent)
|
||||
void FollowerAI::SetFollowComplete(bool withEndEvent)
|
||||
{
|
||||
if (me->HasUnitState(UNIT_STATE_FOLLOW))
|
||||
{
|
||||
@@ -348,7 +332,7 @@ void FollowerAI::SetFollowComplete(bool bWithEndEvent)
|
||||
me->GetMotionMaster()->MoveIdle();
|
||||
}
|
||||
|
||||
if (bWithEndEvent)
|
||||
if (withEndEvent)
|
||||
AddFollowState(STATE_FOLLOW_POSTEVENT);
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user