Core/SmartAI: Various fixes and extensions for smart scripts:
Port From (https://github.com/TrinityCore/TrinityCore/commit/a32d5cfa1762ae1158ee2f40b4c9b36e5b41913a)
This commit is contained in:
@@ -316,34 +316,35 @@ namespace Game.AI
|
||||
|
||||
void CheckConditions(uint diff)
|
||||
{
|
||||
if (m_ConditionsTimer < diff)
|
||||
if (!m_HasConditions)
|
||||
return;
|
||||
|
||||
if (m_ConditionsTimer <= diff)
|
||||
{
|
||||
if (m_HasConditions)
|
||||
Vehicle vehicleKit = me.GetVehicleKit();
|
||||
if (vehicleKit)
|
||||
{
|
||||
Vehicle vehicleKit = me.GetVehicleKit();
|
||||
if (vehicleKit)
|
||||
foreach (var pair in vehicleKit.Seats)
|
||||
{
|
||||
foreach (var pair in vehicleKit.Seats)
|
||||
Unit passenger = Global.ObjAccessor.GetUnit(me, pair.Value.Passenger.Guid);
|
||||
if (passenger)
|
||||
{
|
||||
Unit passenger = Global.ObjAccessor.GetUnit(me, pair.Value.Passenger.Guid);
|
||||
if (passenger)
|
||||
Player player = passenger.ToPlayer();
|
||||
if (player)
|
||||
{
|
||||
Player player = passenger.ToPlayer();
|
||||
if (player)
|
||||
if (!Global.ConditionMgr.IsObjectMeetingNotGroupedConditions(ConditionSourceType.CreatureTemplateVehicle, me.GetEntry(), player, me))
|
||||
{
|
||||
if (!Global.ConditionMgr.IsObjectMeetingNotGroupedConditions(ConditionSourceType.CreatureTemplateVehicle, me.GetEntry(), player, me))
|
||||
{
|
||||
player.ExitVehicle();
|
||||
return;//check other pessanger in next tick
|
||||
}
|
||||
player.ExitVehicle();
|
||||
return;//check other pessanger in next tick
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_ConditionsTimer = VEHICLE_CONDITION_CHECK_TIME;
|
||||
}
|
||||
else
|
||||
else
|
||||
m_ConditionsTimer -= diff;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
|
||||
using Framework.Dynamic;
|
||||
using Game.Entities;
|
||||
using Game.Spells;
|
||||
|
||||
namespace Game.AI
|
||||
{
|
||||
@@ -40,7 +41,7 @@ namespace Game.AI
|
||||
public virtual void SetGUID(ulong guid, int id = 0) { }
|
||||
public virtual ulong GetGUID(int id = 0) { return 0; }
|
||||
|
||||
public virtual bool GossipHello(Player player, bool isUse) { return false; }
|
||||
public virtual bool GossipHello(Player player, bool reportUse) { return false; }
|
||||
public virtual bool GossipSelect(Player player, uint sender, uint action) { return false; }
|
||||
public virtual bool GossipSelectCode(Player player, uint sender, uint action, string code) { return false; }
|
||||
public virtual bool QuestAccept(Player player, Quest quest) { return false; }
|
||||
@@ -55,6 +56,7 @@ namespace Game.AI
|
||||
public virtual void OnGameEvent(bool start, ushort eventId) { }
|
||||
public virtual void OnStateChanged(uint state, Unit unit) { }
|
||||
public virtual void EventInform(uint eventId) { }
|
||||
public virtual void SpellHit(Unit unit, SpellInfo spellInfo) { }
|
||||
|
||||
protected TaskScheduler _scheduler;
|
||||
protected EventMap _events;
|
||||
|
||||
@@ -571,4 +571,74 @@ namespace Game.AI
|
||||
Unit _source;
|
||||
bool _playerOnly;
|
||||
}
|
||||
|
||||
// Simple selector for units using mana
|
||||
class PowerUsersSelector : ISelector
|
||||
{
|
||||
public PowerUsersSelector(Unit unit, PowerType power, float dist, bool playerOnly)
|
||||
{
|
||||
_me = unit;
|
||||
_power = power;
|
||||
_dist = dist;
|
||||
_playerOnly = playerOnly;
|
||||
}
|
||||
|
||||
public bool Check(Unit target)
|
||||
{
|
||||
if (_me == null || target == null)
|
||||
return false;
|
||||
|
||||
if (target.GetPowerType() != _power)
|
||||
return false;
|
||||
|
||||
if (_playerOnly && target.GetTypeId() != TypeId.Player)
|
||||
return false;
|
||||
|
||||
if (_dist > 0.0f && !_me.IsWithinCombatRange(target, _dist))
|
||||
return false;
|
||||
|
||||
if (_dist < 0.0f && _me.IsWithinCombatRange(target, -_dist))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Unit _me;
|
||||
PowerType _power;
|
||||
float _dist;
|
||||
bool _playerOnly;
|
||||
}
|
||||
|
||||
class FarthestTargetSelector : ISelector
|
||||
{
|
||||
public FarthestTargetSelector(Unit unit, float dist, bool playerOnly, bool inLos)
|
||||
{
|
||||
_me = unit;
|
||||
_dist = dist;
|
||||
_playerOnly = playerOnly;
|
||||
_inLos = inLos;
|
||||
}
|
||||
|
||||
public bool Check(Unit target)
|
||||
{
|
||||
if (_me == null || target == null)
|
||||
return false;
|
||||
|
||||
if (_playerOnly && target.GetTypeId() != TypeId.Player)
|
||||
return false;
|
||||
|
||||
if (_dist > 0.0f && !_me.IsWithinCombatRange(target, _dist))
|
||||
return false;
|
||||
|
||||
if (_inLos && !_me.IsWithinLOSInMap(target))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Unit _me;
|
||||
float _dist;
|
||||
bool _playerOnly;
|
||||
bool _inLos;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user