More refactoring of code.
This commit is contained in:
@@ -184,17 +184,17 @@ namespace Game.AI
|
||||
//Drops all threat to 0%. Does not remove players from the threat list
|
||||
public void DoResetThreat()
|
||||
{
|
||||
if (!me.CanHaveThreatList() || me.GetThreatManager().isThreatListEmpty())
|
||||
if (!me.CanHaveThreatList() || me.GetThreatManager().IsThreatListEmpty())
|
||||
{
|
||||
Log.outError(LogFilter.Scripts, "DoResetThreat called for creature that either cannot have threat list or has empty threat list (me entry = {0})", me.GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
var threatlist = me.GetThreatManager().getThreatList();
|
||||
var threatlist = me.GetThreatManager().GetThreatList();
|
||||
|
||||
foreach (var refe in threatlist)
|
||||
{
|
||||
Unit unit = Global.ObjAccessor.GetUnit(me, refe.getUnitGuid());
|
||||
Unit unit = Global.ObjAccessor.GetUnit(me, refe.GetUnitGuid());
|
||||
if (unit != null && DoGetThreat(unit) != 0)
|
||||
DoModifyThreatPercent(unit, -100);
|
||||
}
|
||||
@@ -204,14 +204,14 @@ namespace Game.AI
|
||||
{
|
||||
if (unit == null)
|
||||
return 0.0f;
|
||||
return me.GetThreatManager().getThreat(unit);
|
||||
return me.GetThreatManager().GetThreat(unit);
|
||||
}
|
||||
|
||||
public void DoModifyThreatPercent(Unit unit, int pct)
|
||||
{
|
||||
if (unit == null)
|
||||
return;
|
||||
me.GetThreatManager().modifyThreatPercent(unit, pct);
|
||||
me.GetThreatManager().ModifyThreatPercent(unit, pct);
|
||||
}
|
||||
|
||||
void DoTeleportTo(float x, float y, float z, uint time = 0)
|
||||
@@ -485,10 +485,10 @@ namespace Game.AI
|
||||
float x, y, z;
|
||||
me.GetPosition(out x, out y, out z);
|
||||
|
||||
var threatList = me.GetThreatManager().getThreatList();
|
||||
var threatList = me.GetThreatManager().GetThreatList();
|
||||
foreach (var refe in threatList)
|
||||
{
|
||||
Unit target = refe.getTarget();
|
||||
Unit target = refe.GetTarget();
|
||||
if (target)
|
||||
if (target.IsTypeId(TypeId.Player) && !CheckBoundary(target))
|
||||
target.NearTeleportTo(x, y, z, 0);
|
||||
|
||||
@@ -24,14 +24,14 @@ using System.Linq;
|
||||
|
||||
namespace Game.AI
|
||||
{
|
||||
public class npc_escortAI : ScriptedAI
|
||||
public class NpcEscortAI : ScriptedAI
|
||||
{
|
||||
public npc_escortAI(Creature creature) : base(creature)
|
||||
public NpcEscortAI(Creature creature) : base(creature)
|
||||
{
|
||||
m_uiPlayerGUID = ObjectGuid.Empty;
|
||||
m_uiWPWaitTimer = 2500;
|
||||
m_uiPlayerCheckTimer = 1000;
|
||||
m_uiEscortState = eEscortState.None;
|
||||
m_uiEscortState = EscortState.None;
|
||||
MaxPlayerDistance = 50;
|
||||
m_pQuestForEscort = null;
|
||||
m_bIsActiveAttacker = true;
|
||||
@@ -101,7 +101,7 @@ namespace Game.AI
|
||||
{
|
||||
if (me.HasReactState(ReactStates.Aggressive) && !me.HasUnitState(UnitState.Stunned) && who.IsTargetableForAttack() && who.IsInAccessiblePlaceFor(me))
|
||||
{
|
||||
if (HasEscortState(eEscortState.Escorting) && AssistPlayerInCombatAgainst(who))
|
||||
if (HasEscortState(EscortState.Escorting) && AssistPlayerInCombatAgainst(who))
|
||||
return;
|
||||
|
||||
if (!me.CanFly() && me.GetDistanceZ(who) > SharedConst.CreatureAttackRangeZ)
|
||||
@@ -135,7 +135,7 @@ namespace Game.AI
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
{
|
||||
if (!HasEscortState(eEscortState.Escorting) || m_uiPlayerGUID.IsEmpty() || m_pQuestForEscort == null)
|
||||
if (!HasEscortState(EscortState.Escorting) || m_uiPlayerGUID.IsEmpty() || m_pQuestForEscort == null)
|
||||
return;
|
||||
|
||||
Player player = GetPlayerForEscort();
|
||||
@@ -144,7 +144,7 @@ namespace Game.AI
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
{
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.next())
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.Next())
|
||||
{
|
||||
Player member = groupRef.GetSource();
|
||||
if (member)
|
||||
@@ -159,7 +159,7 @@ namespace Game.AI
|
||||
|
||||
public override void JustRespawned()
|
||||
{
|
||||
m_uiEscortState = eEscortState.None;
|
||||
m_uiEscortState = EscortState.None;
|
||||
|
||||
if (!IsCombatMovementAllowed())
|
||||
SetCombatMovement(true);
|
||||
@@ -185,9 +185,9 @@ namespace Game.AI
|
||||
me.CombatStop(true);
|
||||
me.SetLootRecipient(null);
|
||||
|
||||
if (HasEscortState(eEscortState.Escorting))
|
||||
if (HasEscortState(EscortState.Escorting))
|
||||
{
|
||||
AddEscortState(eEscortState.Returning);
|
||||
AddEscortState(EscortState.Returning);
|
||||
ReturnToLastPoint();
|
||||
Log.outDebug(LogFilter.Scripts, "EscortAI has left combat and is now returning to last point");
|
||||
}
|
||||
@@ -208,7 +208,7 @@ namespace Game.AI
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
{
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.next())
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.Next())
|
||||
{
|
||||
Player member = groupRef.GetSource();
|
||||
if (member)
|
||||
@@ -226,7 +226,7 @@ namespace Game.AI
|
||||
public override void UpdateAI(uint diff)
|
||||
{
|
||||
//Waypoint Updating
|
||||
if (HasEscortState(eEscortState.Escorting) && !me.GetVictim() && m_uiWPWaitTimer != 0 && !HasEscortState(eEscortState.Returning))
|
||||
if (HasEscortState(EscortState.Escorting) && !me.GetVictim() && m_uiWPWaitTimer != 0 && !HasEscortState(EscortState.Returning))
|
||||
{
|
||||
if (m_uiWPWaitTimer <= diff)
|
||||
{
|
||||
@@ -270,7 +270,7 @@ namespace Game.AI
|
||||
|
||||
}
|
||||
|
||||
if (!HasEscortState(eEscortState.Paused))
|
||||
if (!HasEscortState(EscortState.Paused))
|
||||
{
|
||||
var currentWp = WaypointList[CurrentWPIndex];
|
||||
me.GetMotionMaster().MovePoint(currentWp.Id, currentWp.X, currentWp.Y, currentWp.Z);
|
||||
@@ -284,7 +284,7 @@ namespace Game.AI
|
||||
}
|
||||
|
||||
//Check if player or any member of his group is within range
|
||||
if (HasEscortState(eEscortState.Escorting) && !m_uiPlayerGUID.IsEmpty() && !me.GetVictim() && !HasEscortState(eEscortState.Returning))
|
||||
if (HasEscortState(EscortState.Escorting) && !m_uiPlayerGUID.IsEmpty() && !me.GetVictim() && !HasEscortState(EscortState.Returning))
|
||||
{
|
||||
if (m_uiPlayerCheckTimer <= diff)
|
||||
{
|
||||
@@ -322,7 +322,7 @@ namespace Game.AI
|
||||
|
||||
public override void MovementInform(MovementGeneratorType moveType, uint pointId)
|
||||
{
|
||||
if (moveType != MovementGeneratorType.Point || !HasEscortState(eEscortState.Escorting))
|
||||
if (moveType != MovementGeneratorType.Point || !HasEscortState(EscortState.Escorting))
|
||||
return;
|
||||
|
||||
//Combat start position reached, continue waypoint movement
|
||||
@@ -331,7 +331,7 @@ namespace Game.AI
|
||||
Log.outDebug(LogFilter.Scripts, "EscortAI has returned to original position before combat");
|
||||
|
||||
me.SetWalk(!m_bIsRunning);
|
||||
RemoveEscortState(eEscortState.Returning);
|
||||
RemoveEscortState(EscortState.Returning);
|
||||
|
||||
if (m_uiWPWaitTimer == 0)
|
||||
m_uiWPWaitTimer = 1;
|
||||
@@ -415,7 +415,7 @@ namespace Game.AI
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasEscortState(eEscortState.Escorting))
|
||||
if (HasEscortState(EscortState.Escorting))
|
||||
{
|
||||
Log.outError(LogFilter.Scripts, "EscortAI (script: {0}, creature entry: {1}) attempts to Start while already escorting", me.GetScriptName(), me.GetEntry());
|
||||
return;
|
||||
@@ -474,18 +474,18 @@ namespace Game.AI
|
||||
else
|
||||
me.SetWalk(true);
|
||||
|
||||
AddEscortState(eEscortState.Escorting);
|
||||
AddEscortState(EscortState.Escorting);
|
||||
}
|
||||
|
||||
public void SetEscortPaused(bool on)
|
||||
{
|
||||
if (!HasEscortState(eEscortState.Escorting))
|
||||
if (!HasEscortState(EscortState.Escorting))
|
||||
return;
|
||||
|
||||
if (on)
|
||||
AddEscortState(eEscortState.Paused);
|
||||
AddEscortState(EscortState.Paused);
|
||||
else
|
||||
RemoveEscortState(eEscortState.Paused);
|
||||
RemoveEscortState(EscortState.Paused);
|
||||
}
|
||||
|
||||
bool SetNextWaypoint(uint pointId, float x, float y, float z, float orientation)
|
||||
@@ -557,8 +557,8 @@ namespace Game.AI
|
||||
public virtual void WaypointReached(uint pointId) { }
|
||||
public virtual void WaypointStart(uint pointId) { }
|
||||
|
||||
public bool HasEscortState(eEscortState escortState) { return m_uiEscortState.HasAnyFlag(escortState); }
|
||||
public override bool IsEscorted() { return m_uiEscortState.HasAnyFlag(eEscortState.Escorting); }
|
||||
public bool HasEscortState(EscortState escortState) { return m_uiEscortState.HasAnyFlag(escortState); }
|
||||
public override bool IsEscorted() { return m_uiEscortState.HasAnyFlag(EscortState.Escorting); }
|
||||
|
||||
public void SetMaxPlayerDistance(float newMax) { MaxPlayerDistance = newMax; }
|
||||
public float GetMaxPlayerDistance() { return MaxPlayerDistance; }
|
||||
@@ -571,13 +571,13 @@ namespace Game.AI
|
||||
|
||||
public Player GetPlayerForEscort() { return Global.ObjAccessor.GetPlayer(me, m_uiPlayerGUID); }
|
||||
|
||||
void AddEscortState(eEscortState escortState) { m_uiEscortState |= escortState; }
|
||||
void RemoveEscortState(eEscortState escortState) { m_uiEscortState &= ~escortState; }
|
||||
void AddEscortState(EscortState escortState) { m_uiEscortState |= escortState; }
|
||||
void RemoveEscortState(EscortState escortState) { m_uiEscortState &= ~escortState; }
|
||||
|
||||
ObjectGuid m_uiPlayerGUID;
|
||||
uint m_uiWPWaitTimer;
|
||||
uint m_uiPlayerCheckTimer;
|
||||
eEscortState m_uiEscortState;
|
||||
EscortState m_uiEscortState;
|
||||
float MaxPlayerDistance;
|
||||
|
||||
Quest m_pQuestForEscort; //generally passed in Start() when regular escort script.
|
||||
@@ -595,7 +595,7 @@ namespace Game.AI
|
||||
bool HasImmuneToNPCFlags;
|
||||
}
|
||||
|
||||
public enum eEscortState
|
||||
public enum EscortState
|
||||
{
|
||||
None = 0x000, //nothing in progress
|
||||
Escorting = 0x001, //escort are in progress
|
||||
|
||||
@@ -22,7 +22,7 @@ using System;
|
||||
|
||||
namespace Game.AI
|
||||
{
|
||||
enum eFollowState
|
||||
enum FollowState
|
||||
{
|
||||
None = 0x000,
|
||||
Inprogress = 0x001, //must always have this state for any follow
|
||||
@@ -38,7 +38,7 @@ namespace Game.AI
|
||||
public FollowerAI(Creature creature) : base(creature)
|
||||
{
|
||||
m_uiUpdateFollowTimer = 2500;
|
||||
m_uiFollowState = eFollowState.None;
|
||||
m_uiFollowState = FollowState.None;
|
||||
m_pQuestForFollow = null;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace Game.AI
|
||||
{
|
||||
if (me.HasReactState(ReactStates.Aggressive) && !me.HasUnitState(UnitState.Stunned) && who.IsTargetableForAttack() && who.IsInAccessiblePlaceFor(me))
|
||||
{
|
||||
if (HasFollowState(eFollowState.Inprogress) && AssistPlayerInCombatAgainst(who))
|
||||
if (HasFollowState(FollowState.Inprogress) && AssistPlayerInCombatAgainst(who))
|
||||
return;
|
||||
|
||||
if (!me.CanFly() && me.GetDistanceZ(who) > SharedConst.CreatureAttackRangeZ)
|
||||
@@ -139,7 +139,7 @@ namespace Game.AI
|
||||
|
||||
public override void JustDied(Unit killer)
|
||||
{
|
||||
if (!HasFollowState(eFollowState.Inprogress) || m_uiLeaderGUID.IsEmpty() || m_pQuestForFollow == null)
|
||||
if (!HasFollowState(FollowState.Inprogress) || m_uiLeaderGUID.IsEmpty() || m_pQuestForFollow == null)
|
||||
return;
|
||||
|
||||
// @todo need a better check for quests with time limit.
|
||||
@@ -149,7 +149,7 @@ namespace Game.AI
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
{
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.next())
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.Next())
|
||||
{
|
||||
Player member = groupRef.GetSource();
|
||||
if (member)
|
||||
@@ -164,7 +164,7 @@ namespace Game.AI
|
||||
|
||||
public override void JustRespawned()
|
||||
{
|
||||
m_uiFollowState = eFollowState.None;
|
||||
m_uiFollowState = FollowState.None;
|
||||
|
||||
if (!IsCombatMovementAllowed())
|
||||
SetCombatMovement(true);
|
||||
@@ -182,7 +182,7 @@ namespace Game.AI
|
||||
me.CombatStop(true);
|
||||
me.SetLootRecipient(null);
|
||||
|
||||
if (HasFollowState(eFollowState.Inprogress))
|
||||
if (HasFollowState(FollowState.Inprogress))
|
||||
{
|
||||
Log.outDebug(LogFilter.Scripts, "FollowerAI left combat, returning to CombatStartPosition.");
|
||||
|
||||
@@ -204,11 +204,11 @@ namespace Game.AI
|
||||
|
||||
public override void UpdateAI(uint uiDiff)
|
||||
{
|
||||
if (HasFollowState(eFollowState.Inprogress) && !me.GetVictim())
|
||||
if (HasFollowState(FollowState.Inprogress) && !me.GetVictim())
|
||||
{
|
||||
if (m_uiUpdateFollowTimer <= uiDiff)
|
||||
{
|
||||
if (HasFollowState(eFollowState.Complete) && !HasFollowState(eFollowState.PostEvent))
|
||||
if (HasFollowState(FollowState.Complete) && !HasFollowState(FollowState.PostEvent))
|
||||
{
|
||||
Log.outDebug(LogFilter.Scripts, "FollowerAI is set completed, despawns.");
|
||||
me.DespawnOrUnsummon();
|
||||
@@ -220,11 +220,11 @@ namespace Game.AI
|
||||
Player player = GetLeaderForFollower();
|
||||
if (player)
|
||||
{
|
||||
if (HasFollowState(eFollowState.Returning))
|
||||
if (HasFollowState(FollowState.Returning))
|
||||
{
|
||||
Log.outDebug(LogFilter.Scripts, "FollowerAI is returning to leader.");
|
||||
|
||||
RemoveFollowState(eFollowState.Returning);
|
||||
RemoveFollowState(FollowState.Returning);
|
||||
me.GetMotionMaster().MoveFollow(player, SharedConst.PetFollowDist, SharedConst.PetFollowAngle);
|
||||
return;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ namespace Game.AI
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
{
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.next())
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.Next())
|
||||
{
|
||||
Player member = groupRef.GetSource();
|
||||
if (member && me.IsWithinDistInMap(member, 100.0f))
|
||||
@@ -275,15 +275,15 @@ namespace Game.AI
|
||||
|
||||
public override void MovementInform(MovementGeneratorType motionType, uint pointId)
|
||||
{
|
||||
if (motionType != MovementGeneratorType.Point || !HasFollowState(eFollowState.Inprogress))
|
||||
if (motionType != MovementGeneratorType.Point || !HasFollowState(FollowState.Inprogress))
|
||||
return;
|
||||
|
||||
if (pointId == 0xFFFFFF)
|
||||
{
|
||||
if (GetLeaderForFollower())
|
||||
{
|
||||
if (!HasFollowState(eFollowState.Paused))
|
||||
AddFollowState(eFollowState.Returning);
|
||||
if (!HasFollowState(FollowState.Paused))
|
||||
AddFollowState(FollowState.Returning);
|
||||
}
|
||||
else
|
||||
me.DespawnOrUnsummon();
|
||||
@@ -298,7 +298,7 @@ namespace Game.AI
|
||||
return;
|
||||
}
|
||||
|
||||
if (HasFollowState(eFollowState.Inprogress))
|
||||
if (HasFollowState(FollowState.Inprogress))
|
||||
{
|
||||
Log.outError(LogFilter.Scenario, "FollowerAI attempt to StartFollow while already following.");
|
||||
return;
|
||||
@@ -322,7 +322,7 @@ namespace Game.AI
|
||||
me.SetNpcFlags(NPCFlags.None);
|
||||
me.SetNpcFlags2(NPCFlags2.None);
|
||||
|
||||
AddFollowState(eFollowState.Inprogress);
|
||||
AddFollowState(FollowState.Inprogress);
|
||||
|
||||
me.GetMotionMaster().MoveFollow(player, SharedConst.PetFollowDist, SharedConst.PetFollowAngle);
|
||||
|
||||
@@ -341,7 +341,7 @@ namespace Game.AI
|
||||
Group group = player.GetGroup();
|
||||
if (group)
|
||||
{
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.next())
|
||||
for (GroupReference groupRef = group.GetFirstMember(); groupRef != null; groupRef = groupRef.Next())
|
||||
{
|
||||
Player member = groupRef.GetSource();
|
||||
if (member && me.IsWithinDistInMap(member, 100.0f) && member.IsAlive())
|
||||
@@ -371,24 +371,24 @@ namespace Game.AI
|
||||
}
|
||||
|
||||
if (bWithEndEvent)
|
||||
AddFollowState(eFollowState.PostEvent);
|
||||
AddFollowState(FollowState.PostEvent);
|
||||
else
|
||||
{
|
||||
if (HasFollowState(eFollowState.PostEvent))
|
||||
RemoveFollowState(eFollowState.PostEvent);
|
||||
if (HasFollowState(FollowState.PostEvent))
|
||||
RemoveFollowState(FollowState.PostEvent);
|
||||
}
|
||||
|
||||
AddFollowState(eFollowState.Complete);
|
||||
AddFollowState(FollowState.Complete);
|
||||
}
|
||||
|
||||
bool HasFollowState(eFollowState uiFollowState) { return (m_uiFollowState & uiFollowState) != 0; }
|
||||
bool HasFollowState(FollowState uiFollowState) { return (m_uiFollowState & uiFollowState) != 0; }
|
||||
|
||||
void AddFollowState(eFollowState uiFollowState) { m_uiFollowState |= uiFollowState; }
|
||||
void RemoveFollowState(eFollowState uiFollowState) { m_uiFollowState &= ~uiFollowState; }
|
||||
void AddFollowState(FollowState uiFollowState) { m_uiFollowState |= uiFollowState; }
|
||||
void RemoveFollowState(FollowState uiFollowState) { m_uiFollowState &= ~uiFollowState; }
|
||||
|
||||
ObjectGuid m_uiLeaderGUID;
|
||||
uint m_uiUpdateFollowTimer;
|
||||
eFollowState m_uiFollowState;
|
||||
FollowState m_uiFollowState;
|
||||
|
||||
Quest m_pQuestForFollow; //normally we have a quest
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user