Misc cleanups/Fixes

This commit is contained in:
hondacrx
2020-12-07 10:07:26 -05:00
parent 5aa1c08ca1
commit 7e2df34250
39 changed files with 513 additions and 245 deletions
+1
View File
@@ -492,6 +492,7 @@ namespace Game.AI
protected EventMap _events = new EventMap();
protected TaskScheduler _scheduler = new TaskScheduler();
protected InstanceScript _instance;
}
public struct AISpellInfoType
+1 -1
View File
@@ -88,7 +88,7 @@ namespace Game.AI
public class NullCreatureAI : CreatureAI
{
public NullCreatureAI(Creature c) : base(c)
public NullCreatureAI(Creature creature) : base(creature)
{
me.SetReactState(ReactStates.Passive);
}
+16 -21
View File
@@ -132,7 +132,7 @@ namespace Game.AI
/// Select the best target (in <targetType> order) satisfying <predicate> from the threat list.
/// If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped.
/// </summary>
public Unit SelectTarget(SelectAggroTarget targetType, uint offset, ISelector selector)
public Unit SelectTarget(SelectAggroTarget targetType, uint offset, ICheck<Unit> selector)
{
ThreatManager mgr = GetThreatManager();
// shortcut: if we ignore the first <offset> elements, and there are at most <offset> elements, then we ignore ALL elements
@@ -170,7 +170,7 @@ namespace Game.AI
/// - Does not have aura with ID -<aura> (if aura < 0)
/// The resulting targets are stored in <targetList> (which is cleared first).
/// </summary>
public List<Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset, float dist, bool playerOnly, bool withTank, int aura = 0)
public List<Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset = 0, float dist = 0f, bool playerOnly = false, bool withTank = true, int aura = 0)
{
return SelectTargetList(num, targetType, offset, new DefaultTargetSelector(me, dist, playerOnly, withTank, aura));
}
@@ -179,7 +179,7 @@ namespace Game.AI
/// Select the best (up to) <num> targets (in <targetType> order) satisfying <predicate> from the threat list and stores them in <targetList> (which is cleared first).
/// If <offset> is nonzero, the first <offset> entries in <targetType> order (or MAXTHREAT order, if <targetType> is RANDOM) are skipped.
/// </summary>
public List<Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset, ISelector selector)
public List<Unit> SelectTargetList(uint num, SelectAggroTarget targetType, uint offset, ICheck<Unit> selector)
{
var targetList = new List<Unit>();
@@ -238,7 +238,7 @@ namespace Game.AI
}
// then finally filter by predicate
targetList.RemoveAll(target => { return !selector.Check(target); });
targetList.RemoveAll(unit => !selector.Invoke(unit));
if (targetList.Count <= num)
return targetList;
@@ -289,7 +289,7 @@ namespace Game.AI
DefaultTargetSelector targetSelector = new DefaultTargetSelector(me, range, playerOnly, true, -(int)spellId);
if (!spellInfo.HasAuraInterruptFlag(SpellAuraInterruptFlags.NotVictim)
&& targetSelector.Check(me.GetVictim()))
&& targetSelector.Invoke(me.GetVictim()))
target = me.GetVictim();
else
target = SelectTarget(SelectAggroTarget.Random, 0, targetSelector);
@@ -549,13 +549,8 @@ namespace Game.AI
MinDistance // prefer targets closer to us
}
public interface ISelector
{
bool Check(Unit target);
}
// default predicate function to select target based on distance, player and/or aura criteria
public class DefaultTargetSelector : ISelector
public class DefaultTargetSelector : ICheck<Unit>
{
Unit me;
float m_dist;
@@ -577,7 +572,7 @@ namespace Game.AI
m_aura = aura;
}
public bool Check(Unit target)
public bool Invoke(Unit target)
{
if (me == null)
return false;
@@ -611,13 +606,13 @@ namespace Game.AI
}
}
return true;
return false;
}
}
// Target selector for spell casts checking range, auras and attributes
// todo Add more checks from Spell.CheckCast
public class SpellTargetSelector : ISelector
public class SpellTargetSelector : ICheck<Unit>
{
public SpellTargetSelector(Unit caster, uint spellId)
{
@@ -627,7 +622,7 @@ namespace Game.AI
Cypher.Assert(_spellInfo != null);
}
public bool Check(Unit target)
public bool Invoke(Unit target)
{
if (target == null)
return false;
@@ -698,7 +693,7 @@ namespace Game.AI
// Very simple target selector, will just skip main target
// NOTE: When passing to UnitAI.SelectTarget remember to use 0 as position for random selection
// because tank will not be in the temporary list
public class NonTankTargetSelector : ISelector
public class NonTankTargetSelector : ICheck<Unit>
{
public NonTankTargetSelector(Unit source, bool playerOnly = true)
{
@@ -706,7 +701,7 @@ namespace Game.AI
_playerOnly = playerOnly;
}
public bool Check(Unit target)
public bool Invoke(Unit target)
{
if (target == null)
return false;
@@ -726,7 +721,7 @@ namespace Game.AI
}
// Simple selector for units using mana
class PowerUsersSelector : ISelector
class PowerUsersSelector : ICheck<Unit>
{
public PowerUsersSelector(Unit unit, PowerType power, float dist, bool playerOnly)
{
@@ -736,7 +731,7 @@ namespace Game.AI
_playerOnly = playerOnly;
}
public bool Check(Unit target)
public bool Invoke(Unit target)
{
if (_me == null || target == null)
return false;
@@ -762,7 +757,7 @@ namespace Game.AI
bool _playerOnly;
}
class FarthestTargetSelector : ISelector
class FarthestTargetSelector : ICheck<Unit>
{
public FarthestTargetSelector(Unit unit, float dist, bool playerOnly, bool inLos)
{
@@ -772,7 +767,7 @@ namespace Game.AI
_inLos = inLos;
}
public bool Check(Unit target)
public bool Invoke(Unit target)
{
if (_me == null || target == null)
return false;
+2 -2
View File
@@ -1366,7 +1366,7 @@ namespace Game.AI
bool _isFollowing;
}
struct ValidTargetSelectPredicate : ISelector
struct ValidTargetSelectPredicate : ICheck<Unit>
{
UnitAI _ai;
@@ -1375,7 +1375,7 @@ namespace Game.AI
_ai = ai;
}
public bool Check(Unit target)
public bool Invoke(Unit target)
{
return _ai.CanAIAttack(target);
}
+31 -6
View File
@@ -35,7 +35,7 @@ namespace Game.AI
_difficulty = me.GetMap().GetDifficultyID();
}
void AttackStartNoMove(Unit target)
public void AttackStartNoMove(Unit target)
{
if (target == null)
return;
@@ -150,7 +150,7 @@ namespace Game.AI
/// </summary>
/// <param name="victim"></param>
/// <param name="who"></param>
void ResetThreat(Unit victim, Unit who)
public void ResetThreat(Unit victim, Unit who)
{
if (!victim)
return;
@@ -189,7 +189,7 @@ namespace Game.AI
return who.GetThreatManager().GetThreat(victim);
}
//Spawns a creature relative to me
public Creature DoSpawnCreature(uint entry, float offsetX, float offsetY, float offsetZ, float angle, TempSummonType type, uint despawntime)
{
@@ -261,7 +261,7 @@ namespace Game.AI
return apSpell[RandomHelper.IRand(0, (int)(spellCount - 1))];
}
void DoTeleportTo(float x, float y, float z, uint time = 0)
public void DoTeleportTo(float x, float y, float z, uint time = 0)
{
me.Relocate(x, y, z);
float speed = me.GetDistance(x, y, z) / (time * 0.001f);
@@ -274,7 +274,7 @@ namespace Game.AI
}
//Teleports a player without dropping threat (only teleports to same map)
void DoTeleportPlayer(Unit unit, float x, float y, float z, float o)
public void DoTeleportPlayer(Unit unit, float x, float y, float z, float o)
{
if (unit == null)
return;
@@ -527,7 +527,7 @@ namespace Game.AI
ScheduleTasks();
}
void TeleportCheaters()
public void TeleportCheaters()
{
float x, y, z;
me.GetPosition(out x, out y, out z);
@@ -748,6 +748,11 @@ namespace Game.AI
public void Despawn(Creature summon) { Remove(summon.GetGUID()); }
public void DespawnIf(ICheck<ObjectGuid> predicate)
{
this.RemoveAll(predicate);
}
public void DespawnIf(Predicate<ObjectGuid> predicate)
{
RemoveAll(predicate);
@@ -762,6 +767,14 @@ namespace Game.AI
}
}
public void DoAction(int info, ICheck<ObjectGuid> predicate, ushort max = 0)
{
// We need to use a copy of SummonList here, otherwise original SummonList would be modified
List<ObjectGuid> listCopy = new List<ObjectGuid>(this);
listCopy.RandomResize(predicate.Invoke, max);
DoActionImpl(info, listCopy);
}
public void DoAction(int info, Predicate<ObjectGuid> predicate, ushort max = 0)
{
// We need to use a copy of SummonList here, otherwise original SummonList would be modified
@@ -794,4 +807,16 @@ namespace Game.AI
Creature me;
}
public class EntryCheckPredicate : ICheck<ObjectGuid>
{
public EntryCheckPredicate(uint entry)
{
_entry = entry;
}
public bool Invoke(ObjectGuid guid) { return guid.GetEntry() == _entry; }
uint _entry;
}
}
@@ -35,6 +35,8 @@ namespace Game.AI
_activeAttacker = true;
_despawnAtEnd = true;
_despawnAtFar = true;
_path = new WaypointPath();
}
public Player GetPlayerForEscort()
+1
View File
@@ -117,6 +117,7 @@ namespace Game.AI
return false;
}
_path = new WaypointPath();
_path.id = path.id;
_path.nodes = path.nodes;
foreach (WaypointNode waypoint in _path.nodes)