Core/Movement: Smooth movement
This commit is contained in:
@@ -22,7 +22,7 @@ using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class RandomMovementGenerator<T> : MovementGeneratorMedium<T> where T : Creature
|
||||
public class RandomMovementGenerator : MovementGeneratorMedium<Creature>
|
||||
{
|
||||
public RandomMovementGenerator(float spawn_dist = 0.0f)
|
||||
{
|
||||
@@ -38,7 +38,7 @@ namespace Game.Movement
|
||||
return MovementGeneratorType.Random;
|
||||
}
|
||||
|
||||
public override void DoInitialize(T creature)
|
||||
public override void DoInitialize(Creature creature)
|
||||
{
|
||||
if (!creature.IsAlive())
|
||||
return;
|
||||
@@ -53,17 +53,17 @@ namespace Game.Movement
|
||||
_setRandomLocation(creature);
|
||||
|
||||
}
|
||||
public override void DoFinalize(T creature)
|
||||
public override void DoFinalize(Creature creature)
|
||||
{
|
||||
creature.ClearUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
creature.SetWalk(false);
|
||||
}
|
||||
public override void DoReset(T creature)
|
||||
public override void DoReset(Creature creature)
|
||||
{
|
||||
DoInitialize(creature);
|
||||
}
|
||||
|
||||
public override bool DoUpdate(T creature, uint diff)
|
||||
public override bool DoUpdate(Creature creature, uint diff)
|
||||
{
|
||||
if (!creature || !creature.IsAlive())
|
||||
return false;
|
||||
@@ -84,7 +84,7 @@ namespace Game.Movement
|
||||
return true;
|
||||
}
|
||||
|
||||
public void _setRandomLocation(T creature)
|
||||
public void _setRandomLocation(Creature creature)
|
||||
{
|
||||
if (creature.IsMovementPreventedByCasting())
|
||||
{
|
||||
|
||||
@@ -26,10 +26,11 @@ using System.Linq;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class WaypointMovementGenerator<T> : MovementGeneratorMedium<T> where T : Creature
|
||||
public class WaypointMovementGenerator : MovementGeneratorMedium<Creature>
|
||||
{
|
||||
const int FLIGHT_TRAVEL_UPDATE = 100;
|
||||
const int TIMEDIFF_NEXT_WP = 250;
|
||||
|
||||
public WaypointMovementGenerator(uint pathid = 0, bool _repeating = true)
|
||||
{
|
||||
nextMoveTime = new TimeTrackerSmall(0);
|
||||
@@ -37,52 +38,100 @@ namespace Game.Movement
|
||||
pathId = pathid;
|
||||
repeating = _repeating;
|
||||
}
|
||||
public override void DoReset(T owner)
|
||||
|
||||
public WaypointMovementGenerator(WaypointPath _path, bool _repeating = true)
|
||||
{
|
||||
owner.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
StartMoveNow(owner);
|
||||
nextMoveTime = new TimeTrackerSmall(0);
|
||||
isArrivalDone = false;
|
||||
pathId = 0;
|
||||
repeating = _repeating;
|
||||
loadedFromDB = false;
|
||||
path = _path;
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
public override void DoReset(Creature creature)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
owner.SetWalk(false);
|
||||
if (!Stopped())
|
||||
StartMoveNow(creature);
|
||||
}
|
||||
public override void DoInitialize(T owner)
|
||||
|
||||
public override void DoFinalize(Creature creature)
|
||||
{
|
||||
LoadPath(owner);
|
||||
owner.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
creature.ClearUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
creature.SetWalk(false);
|
||||
}
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
|
||||
public override void DoInitialize(Creature creature)
|
||||
{
|
||||
LoadPath(creature);
|
||||
}
|
||||
|
||||
public override bool DoUpdate(Creature creature, uint time_diff)
|
||||
{
|
||||
if (!creature || !creature.IsAlive())
|
||||
return false;
|
||||
|
||||
// Waypoint movement can be switched on/off
|
||||
// This is quite handy for escort quests and other stuff
|
||||
if (owner.HasUnitState(UnitState.NotMove))
|
||||
if (creature.HasUnitState(UnitState.NotMove))
|
||||
{
|
||||
owner.ClearUnitState(UnitState.RoamingMove);
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent a crash at empty waypoint path.
|
||||
if (path == null || path.Empty())
|
||||
if (path == null || path.nodes.Empty())
|
||||
return false;
|
||||
|
||||
if (Stopped())
|
||||
{
|
||||
if (CanMove((int)time_diff))
|
||||
return StartMove(owner);
|
||||
return StartMoveNow(creature);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (owner.IsStopped())
|
||||
Stop(WorldConfig.GetIntValue(WorldCfg.CreatureStopForPlayer));
|
||||
else if (owner.moveSpline.Finalized())
|
||||
if (creature.IsStopped())
|
||||
Stop(loadedFromDB ? WorldConfig.GetIntValue(WorldCfg.CreatureStopForPlayer) : 2 * Time.Hour * Time.InMilliseconds);
|
||||
else if (creature.moveSpline.Finalized())
|
||||
{
|
||||
OnArrived(owner);
|
||||
return StartMove(owner);
|
||||
OnArrived(creature);
|
||||
|
||||
isArrivalDone = true;
|
||||
|
||||
if (!Stopped())
|
||||
{
|
||||
if (creature.IsStopped())
|
||||
Stop(loadedFromDB ? WorldConfig.GetIntValue(WorldCfg.CreatureStopForPlayer) : 2 * Time.Hour * Time.InMilliseconds);
|
||||
else
|
||||
return StartMove(creature);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// speed changed during path execution, calculate remaining path and launch it once more
|
||||
if (recalculateSpeed)
|
||||
{
|
||||
recalculateSpeed = false;
|
||||
|
||||
if (!Stopped())
|
||||
return StartMove(creature);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint pointId = (uint)creature.moveSpline.currentPathIdx();
|
||||
if (pointId > currentNode)
|
||||
{
|
||||
OnArrived(creature);
|
||||
currentNode = pointId;
|
||||
FormationMove(creature);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void MovementInform(Creature creature)
|
||||
{
|
||||
if (creature.IsAIEnabled)
|
||||
@@ -93,38 +142,44 @@ namespace Game.Movement
|
||||
{
|
||||
nextMoveTime.Reset(time);
|
||||
}
|
||||
|
||||
bool Stopped()
|
||||
{
|
||||
return !nextMoveTime.Passed();
|
||||
}
|
||||
|
||||
bool CanMove(int diff)
|
||||
{
|
||||
nextMoveTime.Update(diff);
|
||||
return nextMoveTime.Passed();
|
||||
}
|
||||
void StartMoveNow(Creature creature)
|
||||
|
||||
bool StartMoveNow(Creature creature)
|
||||
{
|
||||
nextMoveTime.Reset(0);
|
||||
StartMove(creature);
|
||||
return StartMove(creature);
|
||||
}
|
||||
|
||||
bool StartMove(Creature creature)
|
||||
{
|
||||
if (path == null || path.Empty())
|
||||
if (!creature || !creature.IsAlive())
|
||||
return false;
|
||||
|
||||
if (Stopped())
|
||||
return true;
|
||||
if (path == null || path.nodes.Empty())
|
||||
return false;
|
||||
|
||||
bool transportPath = creature.GetTransport() != null;
|
||||
|
||||
if (isArrivalDone)
|
||||
{
|
||||
if ((currentNode == path.Count - 1) && !repeating) // If that's our last waypoint
|
||||
if ((currentNode == path.nodes.Count - 1) && !repeating) // If that's our last waypoint
|
||||
{
|
||||
float x = path[(int)currentNode].x;
|
||||
float y = path[(int)currentNode].y;
|
||||
float z = path[(int)currentNode].z;
|
||||
float o = path[(int)currentNode].orientation;
|
||||
WaypointNode waypoint = path.nodes.LookupByIndex((int)currentNode);
|
||||
|
||||
float x = waypoint.x;
|
||||
float y = waypoint.y;
|
||||
float z = waypoint.z;
|
||||
float o = creature.GetOrientation();
|
||||
|
||||
if (!transportPath)
|
||||
creature.SetHomePosition(x, y, z, o);
|
||||
@@ -143,21 +198,43 @@ namespace Game.Movement
|
||||
// else if (vehicle) - this should never happen, vehicle offsets are const
|
||||
}
|
||||
|
||||
creature.GetMotionMaster().Initialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
currentNode = (uint)((currentNode + 1) % path.Count);
|
||||
currentNode = (uint)((currentNode + 1) % path.nodes.Count);
|
||||
}
|
||||
|
||||
WaypointData node = path.LookupByIndex((int)currentNode);
|
||||
float finalOrient = 0.0f;
|
||||
WaypointMoveType finalMove = WaypointMoveType.Walk;
|
||||
|
||||
List<Vector3> pathing = new List<Vector3>();
|
||||
|
||||
pathing.Add(new Vector3(creature.GetPositionX(), creature.GetPositionY(), creature.GetPositionZ()));
|
||||
for (int i = (int)currentNode; i < path.nodes.Count(); ++i)
|
||||
{
|
||||
WaypointNode waypoint = path.nodes.LookupByIndex(i);
|
||||
|
||||
pathing.Add(new Vector3(waypoint.x, waypoint.y, waypoint.z));
|
||||
|
||||
finalOrient = waypoint.orientation;
|
||||
finalMove = waypoint.moveType;
|
||||
|
||||
if (waypoint.delay != 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// if we have only 1 point, only current position, we shall return
|
||||
if (pathing.Count < 2)
|
||||
return false;
|
||||
|
||||
isArrivalDone = false;
|
||||
recalculateSpeed = false;
|
||||
|
||||
creature.AddUnitState(UnitState.RoamingMove);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(creature);
|
||||
Position formationDest = new Position(node.x, node.y, node.z);
|
||||
var node = path.nodes.LookupByIndex((int)currentNode);
|
||||
Position formationDest = new Position(node.x, node.y, node.z, 0.0f);
|
||||
|
||||
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
|
||||
if (transportPath)
|
||||
@@ -168,13 +245,8 @@ namespace Game.Movement
|
||||
trans.CalculatePassengerPosition(ref formationDest.posX, ref formationDest.posY, ref formationDest.posZ, ref formationDest.Orientation);
|
||||
}
|
||||
|
||||
init.MoveTo(formationDest.posX, formationDest.posY, formationDest.posZ);
|
||||
|
||||
//! Accepts angles such as 0.00001 and -0.00001, 0 must be ignored, default value in waypoint table
|
||||
if (node.orientation != 0 && node.delay != 0)
|
||||
init.SetFacing(formationDest.Orientation);
|
||||
|
||||
switch (node.movetype)
|
||||
init.MovebyPath(pathing.ToArray(), (int)currentNode);
|
||||
switch (finalMove)
|
||||
{
|
||||
case WaypointMoveType.Land:
|
||||
init.SetAnimation(AnimType.ToGround);
|
||||
@@ -190,23 +262,26 @@ namespace Game.Movement
|
||||
break;
|
||||
}
|
||||
|
||||
if (finalOrient != 0.0f)
|
||||
init.SetFacing(finalOrient);
|
||||
|
||||
init.Launch();
|
||||
|
||||
//Call for creature group update
|
||||
if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
|
||||
{
|
||||
creature.SetWalk(node.movetype != WaypointMoveType.Run);
|
||||
creature.GetFormation().LeaderMoveTo(formationDest.posX, formationDest.posY, formationDest.posZ);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
void LoadPath(Creature creature)
|
||||
{
|
||||
if (pathId == 0)
|
||||
pathId = creature.GetWaypointPath();
|
||||
if (loadedFromDB)
|
||||
{
|
||||
if (pathId == 0)
|
||||
pathId = creature.GetWaypointPath();
|
||||
|
||||
path = Global.WaypointMgr.GetPath(pathId);
|
||||
path = Global.WaypointMgr.GetPath(pathId);
|
||||
}
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
@@ -215,35 +290,54 @@ namespace Game.Movement
|
||||
return;
|
||||
}
|
||||
|
||||
StartMoveNow(creature);
|
||||
if (!Stopped())
|
||||
StartMoveNow(creature);
|
||||
}
|
||||
void OnArrived(Creature creature)
|
||||
{
|
||||
if (path == null || path.Empty())
|
||||
if (path == null || path.nodes.Empty())
|
||||
return;
|
||||
|
||||
if (isArrivalDone)
|
||||
return;
|
||||
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
isArrivalDone = true;
|
||||
|
||||
var wpData = path.LookupByIndex((int)currentNode);
|
||||
if (wpData.event_id != 0 && RandomHelper.IRand(0, 99) < wpData.event_chance)
|
||||
WaypointNode waypoint = path.nodes.LookupByIndex((int)currentNode);
|
||||
if (waypoint.delay != 0)
|
||||
{
|
||||
Log.outDebug(LogFilter.Unit, "Creature movement start script {0} at point {1} for {2}.", wpData.event_id, currentNode, creature.GetGUID());
|
||||
creature.GetMap().ScriptsStart(ScriptsType.Waypoint, wpData.event_id, creature, null);
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
Stop((int)waypoint.delay);
|
||||
}
|
||||
|
||||
if (waypoint.eventId != 0 && RandomHelper.URand(0, 99) < waypoint.eventChance)
|
||||
{
|
||||
Log.outDebug(LogFilter.Unit, "Creature movement start script {0} at point {1} for {2}.", waypoint.eventId, currentNode, creature.GetGUID());
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
creature.GetMap().ScriptsStart(ScriptsType.Waypoint, waypoint.eventId, creature, null);
|
||||
}
|
||||
|
||||
// Inform script
|
||||
MovementInform(creature);
|
||||
creature.UpdateWaypointID(currentNode);
|
||||
|
||||
if (wpData.delay != 0)
|
||||
creature.SetWalk(waypoint.moveType != WaypointMoveType.Run);
|
||||
}
|
||||
|
||||
void FormationMove(Creature creature)
|
||||
{
|
||||
bool transportPath = creature.GetTransport() != null;
|
||||
|
||||
WaypointNode waypoint = path.nodes.LookupByIndex((int)currentNode);
|
||||
|
||||
Position formationDest = new Position(waypoint.x, waypoint.y, waypoint.z, 0.0f);
|
||||
|
||||
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
|
||||
if (transportPath)
|
||||
{
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
Stop((int)wpData.delay);
|
||||
ITransport trans = creature.GetDirectTransport();
|
||||
if (trans != null)
|
||||
trans.CalculatePassengerPosition(ref formationDest.posX, ref formationDest.posY, ref formationDest.posZ, ref formationDest.Orientation);
|
||||
}
|
||||
|
||||
// Call for creature group update
|
||||
if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
|
||||
creature.GetFormation().LeaderMoveTo(formationDest.posX, formationDest.posY, formationDest.posZ);
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
@@ -251,11 +345,20 @@ namespace Game.Movement
|
||||
return MovementGeneratorType.Waypoint;
|
||||
}
|
||||
|
||||
public TimeTrackerSmall GetTrackerTimer() { return nextMoveTime; }
|
||||
|
||||
public void UnitSpeedChanged() { recalculateSpeed = true; }
|
||||
|
||||
public uint GetCurrentNode() { return currentNode; }
|
||||
|
||||
TimeTrackerSmall nextMoveTime;
|
||||
bool recalculateSpeed;
|
||||
|
||||
bool isArrivalDone;
|
||||
uint pathId;
|
||||
bool repeating;
|
||||
List<WaypointData> path;
|
||||
bool loadedFromDB;
|
||||
WaypointPath path;
|
||||
uint currentNode;
|
||||
}
|
||||
|
||||
|
||||
@@ -35,22 +35,17 @@ namespace Game.Movement
|
||||
public MotionMaster(Unit me)
|
||||
{
|
||||
_owner = me;
|
||||
_expList = null;
|
||||
_expireList = null;
|
||||
_top = -1;
|
||||
_cleanFlag = MMCleanFlag.None;
|
||||
|
||||
for (byte i = 0; i < (int)MovementSlot.Max; ++i)
|
||||
{
|
||||
Impl[i] = null;
|
||||
_needInit[i] = true;
|
||||
_slot[i] = null;
|
||||
_initialize[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool isStatic(IMovementGenerator mv)
|
||||
{
|
||||
return (mv == staticIdleMovement);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
while (!empty())
|
||||
@@ -94,19 +89,19 @@ namespace Game.Movement
|
||||
else
|
||||
_cleanFlag &= ~MMCleanFlag.Update;
|
||||
|
||||
if (_expList != null)
|
||||
if (_expireList != null)
|
||||
{
|
||||
for (int i = 0; i < _expList.Count; ++i)
|
||||
for (int i = 0; i < _expireList.Count; ++i)
|
||||
{
|
||||
IMovementGenerator mg = _expList[i];
|
||||
IMovementGenerator mg = _expireList[i];
|
||||
DirectDelete(mg);
|
||||
}
|
||||
|
||||
_expList = null;
|
||||
_expireList = null;
|
||||
|
||||
if (empty())
|
||||
Initialize();
|
||||
else if (needInitTop())
|
||||
else if (NeedInitTop())
|
||||
InitTop();
|
||||
else if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Reset))
|
||||
top().Reset(_owner);
|
||||
@@ -117,81 +112,86 @@ namespace Game.Movement
|
||||
_owner.UpdateUnderwaterState(_owner.GetMap(), _owner.GetPositionX(), _owner.GetPositionY(), _owner.GetPositionZ());
|
||||
}
|
||||
|
||||
void DirectClean(bool reset)
|
||||
public void Clear(bool reset = true)
|
||||
{
|
||||
while (size() > 1)
|
||||
if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Update))
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
if (curr != null)
|
||||
DirectDelete(curr);
|
||||
if (reset)
|
||||
_cleanFlag |= MMCleanFlag.Reset;
|
||||
else
|
||||
_cleanFlag &= ~MMCleanFlag.Reset;
|
||||
DelayedClean();
|
||||
}
|
||||
else
|
||||
DirectClean(reset);
|
||||
}
|
||||
|
||||
public void MovementExpired(bool reset = true)
|
||||
{
|
||||
if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Update))
|
||||
{
|
||||
if (reset)
|
||||
_cleanFlag |= MMCleanFlag.Reset;
|
||||
else
|
||||
_cleanFlag &= ~MMCleanFlag.Reset;
|
||||
DelayedExpire();
|
||||
}
|
||||
else
|
||||
DirectExpire(reset);
|
||||
}
|
||||
|
||||
public MovementGeneratorType GetCurrentMovementGeneratorType()
|
||||
{
|
||||
if (empty())
|
||||
return;
|
||||
return MovementGeneratorType.Idle;
|
||||
|
||||
if (needInitTop())
|
||||
InitTop();
|
||||
else if (reset)
|
||||
top().Reset(_owner);
|
||||
return top().GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
void DelayedClean()
|
||||
public MovementGeneratorType GetMotionSlotType(MovementSlot slot)
|
||||
{
|
||||
while (size() > 1)
|
||||
if (_slot[(int)slot] == null)
|
||||
return MovementGeneratorType.Null;
|
||||
else
|
||||
return _slot[(int)slot].GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
public IMovementGenerator GetMotionSlot(int slot)
|
||||
{
|
||||
Contract.Assert(slot >= 0);
|
||||
return _slot[slot];
|
||||
}
|
||||
|
||||
public void propagateSpeedChange()
|
||||
{
|
||||
for (int i = 0; i <= _top; ++i)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
if (curr != null)
|
||||
DelayedDelete(curr);
|
||||
if (_slot[i] != null)
|
||||
_slot[i].unitSpeedChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void DirectExpire(bool reset)
|
||||
public bool GetDestination(out float x, out float y, out float z)
|
||||
{
|
||||
if (size() > 1)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
DirectDelete(curr);
|
||||
}
|
||||
x = 0f;
|
||||
y = 0f;
|
||||
z = 0f;
|
||||
if (_owner.moveSpline.Finalized())
|
||||
return false;
|
||||
|
||||
while (!empty() && top() == null)//not sure this will work
|
||||
--_top;
|
||||
|
||||
if (empty())
|
||||
Initialize();
|
||||
else if (needInitTop())
|
||||
InitTop();
|
||||
else if (reset)
|
||||
top().Reset(_owner);
|
||||
}
|
||||
|
||||
void DelayedExpire()
|
||||
{
|
||||
if (size() > 1)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
DelayedDelete(curr);
|
||||
}
|
||||
|
||||
while (!empty() && top() == null)
|
||||
--_top;
|
||||
Vector3 dest = _owner.moveSpline.FinalDestination();
|
||||
x = dest.X;
|
||||
y = dest.Y;
|
||||
z = dest.Z;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void MoveIdle()
|
||||
{
|
||||
if (empty() || !isStatic(top()))
|
||||
if (empty() || !IsStatic(top()))
|
||||
StartMovement(staticIdleMovement, MovementSlot.Idle);
|
||||
}
|
||||
|
||||
public void MoveRandom(float spawndist = 0.0f)
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Unit))
|
||||
StartMovement(new RandomMovementGenerator<Creature>(spawndist), MovementSlot.Idle);
|
||||
}
|
||||
|
||||
public void MoveTargetedHome()
|
||||
{
|
||||
Clear(false);
|
||||
@@ -208,12 +208,22 @@ namespace Game.Movement
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveConfused()
|
||||
public void MoveRandom(float spawndist = 0.0f)
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Unit))
|
||||
StartMovement(new RandomMovementGenerator(spawndist), MovementSlot.Idle);
|
||||
}
|
||||
|
||||
public void MoveFollow(Unit target, float dist = 0.0f, float angle = 0.0f, MovementSlot slot = MovementSlot.Idle)
|
||||
{
|
||||
// ignore movement request if target not exist
|
||||
if (!target || target == _owner)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new ConfusedGenerator<Player>(), MovementSlot.Controlled);
|
||||
StartMovement(new FollowMovementGenerator<Player>(target, dist, angle), slot);
|
||||
else
|
||||
StartMovement(new ConfusedGenerator<Creature>(), MovementSlot.Controlled);
|
||||
StartMovement(new FollowMovementGenerator<Creature>(target, dist, angle), slot);
|
||||
}
|
||||
|
||||
public void MoveChase(Unit target, float dist = 0.0f, float angle = 0.0f)
|
||||
@@ -227,15 +237,33 @@ namespace Game.Movement
|
||||
StartMovement(new ChaseMovementGenerator<Creature>(target, dist, angle), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MoveFollow(Unit target, float dist = 0.0f, float angle = 0.0f, MovementSlot slot = MovementSlot.Idle)
|
||||
public void MoveConfused()
|
||||
{
|
||||
if (!target || target == _owner)
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new ConfusedGenerator<Player>(), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new ConfusedGenerator<Creature>(), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
public void MoveFleeing(Unit enemy, uint time)
|
||||
{
|
||||
if (!enemy)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new FollowMovementGenerator<Player>(target, dist, angle), slot);
|
||||
StartMovement(new FleeingGenerator<Player>(enemy.GetGUID()), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new FollowMovementGenerator<Creature>(target, dist, angle), slot);
|
||||
{
|
||||
if (time != 0)
|
||||
StartMovement(new TimedFleeingGenerator(enemy.GetGUID(), time), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new FleeingGenerator<Creature>(enemy.GetGUID()), MovementSlot.Controlled);
|
||||
}
|
||||
}
|
||||
|
||||
public void MovePoint(uint id, Position pos, bool generatePath = true)
|
||||
{
|
||||
MovePoint(id, pos.posX, pos.posY, pos.posZ, generatePath);
|
||||
}
|
||||
|
||||
public void MovePoint(ulong id, float x, float y, float z, bool generatePath = true)
|
||||
@@ -246,9 +274,25 @@ namespace Game.Movement
|
||||
StartMovement(new PointMovementGenerator<Creature>(id, x, y, z, generatePath), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MovePoint(uint id, Position pos, bool generatePath = true)
|
||||
void MoveCloserAndStop(uint id, Unit target, float distance)
|
||||
{
|
||||
MovePoint(id, pos.posX, pos.posY, pos.posZ, generatePath);
|
||||
float distanceToTravel = _owner.GetExactDist2d(target) - distance;
|
||||
if (distanceToTravel > 0.0f)
|
||||
{
|
||||
float angle = _owner.GetAngle(target);
|
||||
float destx = _owner.GetPositionX() + distanceToTravel * (float)Math.Cos(angle);
|
||||
float desty = _owner.GetPositionY() + distanceToTravel * (float)Math.Sin(angle);
|
||||
MovePoint(id, destx, desty, target.GetPositionZ());
|
||||
}
|
||||
else
|
||||
{
|
||||
// we are already close enough. We just need to turn toward the target without changing position.
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MoveTo(_owner.GetPositionX(), _owner.GetPositionY(), _owner.GetPositionZMinusOffset());
|
||||
init.SetFacing(target);
|
||||
init.Launch();
|
||||
StartMovement(new EffectMovementGenerator(id), MovementSlot.Active);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveLand(uint id, Position pos)
|
||||
@@ -275,6 +319,34 @@ namespace Game.Movement
|
||||
StartMovement(new EffectMovementGenerator(id), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint id = EventId.Charge, bool generatePath = false, Unit target = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
if (_slot[(int)MovementSlot.Controlled] != null && _slot[(int)MovementSlot.Controlled].GetMovementGeneratorType() != MovementGeneratorType.Distract)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new PointMovementGenerator<Player>(id, x, y, z, generatePath, speed, target, spellEffectExtraData), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new PointMovementGenerator<Creature>(id, x, y, z, generatePath, speed, target, spellEffectExtraData), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
public void MoveCharge(PathGenerator path, float speed = SPEED_CHARGE, Unit target = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
Vector3 dest = path.GetActualEndPosition();
|
||||
|
||||
MoveCharge(dest.X, dest.Y, dest.Z, SPEED_CHARGE, EventId.ChargePrepath);
|
||||
|
||||
// Charge movement is not started when using EVENT_CHARGE_PREPATH
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MovebyPath(path.GetPath());
|
||||
init.SetVelocity(speed);
|
||||
if (target != null)
|
||||
init.SetFacing(target);
|
||||
if (spellEffectExtraData != null)
|
||||
init.SetSpellEffectExtraData(spellEffectExtraData);
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
public void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
//this function may make players fall below map
|
||||
@@ -464,34 +536,6 @@ namespace Game.Movement
|
||||
StartMovement(new EffectMovementGenerator(id), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
public void MoveCharge(float x, float y, float z, float speed = SPEED_CHARGE, uint id = EventId.Charge, bool generatePath = false, Unit target = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
if (Impl[(int)MovementSlot.Controlled] != null && Impl[(int)MovementSlot.Controlled].GetMovementGeneratorType() != MovementGeneratorType.Distract)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new PointMovementGenerator<Player>(id, x, y, z, generatePath, speed, target, spellEffectExtraData), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new PointMovementGenerator<Creature>(id, x, y, z, generatePath, speed, target, spellEffectExtraData), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
public void MoveCharge(PathGenerator path, float speed = SPEED_CHARGE, Unit target = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
Vector3 dest = path.GetActualEndPosition();
|
||||
|
||||
MoveCharge(dest.X, dest.Y, dest.Z, SPEED_CHARGE, EventId.ChargePrepath);
|
||||
|
||||
// Charge movement is not started when using EVENT_CHARGE_PREPATH
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MovebyPath(path.GetPath());
|
||||
init.SetVelocity(speed);
|
||||
if (target != null)
|
||||
init.SetFacing(target);
|
||||
if (spellEffectExtraData != null)
|
||||
init.SetSpellEffectExtraData(spellEffectExtraData);
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
public void MoveSeekAssistance(float x, float y, float z)
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
@@ -513,22 +557,6 @@ namespace Game.Movement
|
||||
StartMovement(new AssistanceDistractMovementGenerator(time), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MoveFleeing(Unit enemy, uint time)
|
||||
{
|
||||
if (!enemy)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new FleeingGenerator<Player>(enemy.GetGUID()), MovementSlot.Controlled);
|
||||
else
|
||||
{
|
||||
if (time != 0)
|
||||
StartMovement(new TimedFleeingGenerator(enemy.GetGUID(), time), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new FleeingGenerator<Creature>(enemy.GetGUID()), MovementSlot.Controlled);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTaxiFlight(uint path, uint pathnode)
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
@@ -555,45 +583,23 @@ namespace Game.Movement
|
||||
|
||||
public void MoveDistract(uint timer)
|
||||
{
|
||||
if (Impl[(int)MovementSlot.Controlled] != null)
|
||||
if (_slot[(int)MovementSlot.Controlled] != null)
|
||||
return;
|
||||
|
||||
StartMovement(new DistractMovementGenerator(timer), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
void StartMovement(IMovementGenerator m, MovementSlot slot)
|
||||
{
|
||||
int _slot = (int)slot;
|
||||
IMovementGenerator curr = Impl[_slot];
|
||||
if (curr != null)
|
||||
{
|
||||
Impl[_slot] = null; // in case a new one is generated in this slot during directdelete
|
||||
if (_top == _slot && Convert.ToBoolean(_cleanFlag & MMCleanFlag.Update))
|
||||
DelayedDelete(curr);
|
||||
else
|
||||
DirectDelete(curr);
|
||||
}
|
||||
else if (_top < _slot)
|
||||
{
|
||||
_top = _slot;
|
||||
}
|
||||
|
||||
Impl[_slot] = m;
|
||||
if (_top > _slot)
|
||||
_needInit[_slot] = true;
|
||||
else
|
||||
{
|
||||
_needInit[_slot] = false;
|
||||
m.Initialize(_owner);
|
||||
}
|
||||
}
|
||||
|
||||
public void MovePath(uint path_id, bool repeatable)
|
||||
{
|
||||
if (path_id == 0)
|
||||
return;
|
||||
|
||||
StartMovement(new WaypointMovementGenerator<Creature>(path_id, repeatable), MovementSlot.Idle);
|
||||
StartMovement(new WaypointMovementGenerator(path_id, repeatable), MovementSlot.Idle);
|
||||
}
|
||||
|
||||
public void MovePath(WaypointPath path, bool repeatable)
|
||||
{
|
||||
StartMovement(new WaypointMovementGenerator(path, repeatable), MovementSlot.Idle);
|
||||
}
|
||||
|
||||
void MoveRotate(uint time, RotateDirection direction)
|
||||
@@ -604,90 +610,133 @@ namespace Game.Movement
|
||||
StartMovement(new RotateMovementGenerator(time, direction), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void propagateSpeedChange()
|
||||
{
|
||||
for (int i = 0; i <= _top; ++i)
|
||||
{
|
||||
if (Impl[i] != null)
|
||||
Impl[i].unitSpeedChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public MovementGeneratorType GetCurrentMovementGeneratorType()
|
||||
void pop()
|
||||
{
|
||||
if (empty())
|
||||
return MovementGeneratorType.Idle;
|
||||
return;
|
||||
|
||||
return top().GetMovementGeneratorType();
|
||||
_slot[_top] = null;
|
||||
while (!empty() && top() == null)
|
||||
--_top;
|
||||
}
|
||||
|
||||
public MovementGeneratorType GetMotionSlotType(MovementSlot slot)
|
||||
bool NeedInitTop()
|
||||
{
|
||||
if (Impl[(int)slot] == null)
|
||||
return MovementGeneratorType.Null;
|
||||
else
|
||||
return Impl[(int)slot].GetMovementGeneratorType();
|
||||
if (empty())
|
||||
return false;
|
||||
|
||||
return _initialize[_top];
|
||||
}
|
||||
|
||||
void InitTop()
|
||||
{
|
||||
top().Initialize(_owner);
|
||||
_needInit[_top] = false;
|
||||
_initialize[_top] = false;
|
||||
}
|
||||
|
||||
void StartMovement(IMovementGenerator m, MovementSlot slot)
|
||||
{
|
||||
IMovementGenerator curr = _slot[(int)slot];
|
||||
if (curr != null)
|
||||
{
|
||||
_slot[(int)slot] = null; // in case a new one is generated in this slot during directdelete
|
||||
if (_top == (int)slot && Convert.ToBoolean(_cleanFlag & MMCleanFlag.Update))
|
||||
DelayedDelete(curr);
|
||||
else
|
||||
DirectDelete(curr);
|
||||
}
|
||||
else if (_top < (int)slot)
|
||||
{
|
||||
_top = (int)slot;
|
||||
}
|
||||
|
||||
_slot[(int)slot] = m;
|
||||
if (_top > (int)slot)
|
||||
_initialize[(int)slot] = true;
|
||||
else
|
||||
{
|
||||
_initialize[(int)slot] = false;
|
||||
m.Initialize(_owner);
|
||||
}
|
||||
}
|
||||
|
||||
void DirectClean(bool reset)
|
||||
{
|
||||
while (size() > 1)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
if (curr != null)
|
||||
DirectDelete(curr);
|
||||
}
|
||||
|
||||
if (empty())
|
||||
return;
|
||||
|
||||
if (NeedInitTop())
|
||||
InitTop();
|
||||
else if (reset)
|
||||
top().Reset(_owner);
|
||||
}
|
||||
|
||||
void DelayedClean()
|
||||
{
|
||||
while (size() > 1)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
if (curr != null)
|
||||
DelayedDelete(curr);
|
||||
}
|
||||
}
|
||||
|
||||
void DirectExpire(bool reset)
|
||||
{
|
||||
if (size() > 1)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
DirectDelete(curr);
|
||||
}
|
||||
|
||||
while (!empty() && top() == null)//not sure this will work
|
||||
--_top;
|
||||
|
||||
if (empty())
|
||||
Initialize();
|
||||
else if (NeedInitTop())
|
||||
InitTop();
|
||||
else if (reset)
|
||||
top().Reset(_owner);
|
||||
}
|
||||
|
||||
void DelayedExpire()
|
||||
{
|
||||
if (size() > 1)
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
DelayedDelete(curr);
|
||||
}
|
||||
|
||||
while (!empty() && top() == null)
|
||||
--_top;
|
||||
}
|
||||
|
||||
void DirectDelete(IMovementGenerator curr)
|
||||
{
|
||||
if (isStatic(curr))
|
||||
if (IsStatic(curr))
|
||||
return;
|
||||
curr.Finalize(_owner);
|
||||
}
|
||||
|
||||
void DelayedDelete(IMovementGenerator curr)
|
||||
{
|
||||
if (isStatic(curr))
|
||||
if (IsStatic(curr))
|
||||
return;
|
||||
if (_expList == null)
|
||||
_expList = new List<IMovementGenerator>();
|
||||
_expList.Add(curr);
|
||||
}
|
||||
|
||||
public bool GetDestination(out float x, out float y, out float z)
|
||||
{
|
||||
x = 0f;
|
||||
y = 0f;
|
||||
z = 0f;
|
||||
if (_owner.moveSpline.Finalized())
|
||||
return false;
|
||||
|
||||
Vector3 dest = _owner.moveSpline.FinalDestination();
|
||||
x = dest.X;
|
||||
y = dest.Y;
|
||||
z = dest.Z;
|
||||
return true;
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
if (empty())
|
||||
return;
|
||||
|
||||
Impl[_top] = null;
|
||||
while (!empty() && top() == null)
|
||||
--_top;
|
||||
}
|
||||
|
||||
void push(IMovementGenerator _Val)
|
||||
{
|
||||
++_top;
|
||||
Impl[_top] = _Val;
|
||||
}
|
||||
|
||||
bool needInitTop()
|
||||
{
|
||||
if (empty())
|
||||
return false;
|
||||
|
||||
return _needInit[_top];
|
||||
if (_expireList == null)
|
||||
_expireList = new List<IMovementGenerator>();
|
||||
_expireList.Add(curr);
|
||||
}
|
||||
|
||||
public bool empty() { return (_top < 0); }
|
||||
@@ -697,41 +746,7 @@ namespace Game.Movement
|
||||
public IMovementGenerator top()
|
||||
{
|
||||
Contract.Assert(!empty());
|
||||
return Impl[_top];
|
||||
}
|
||||
|
||||
public IMovementGenerator GetMotionSlot(int slot)
|
||||
{
|
||||
Contract.Assert(slot >= 0);
|
||||
return Impl[slot];
|
||||
}
|
||||
|
||||
public void Clear(bool reset = true)
|
||||
{
|
||||
if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Update))
|
||||
{
|
||||
if (reset)
|
||||
_cleanFlag |= MMCleanFlag.Reset;
|
||||
else
|
||||
_cleanFlag &= ~MMCleanFlag.Reset;
|
||||
DelayedClean();
|
||||
}
|
||||
else
|
||||
DirectClean(reset);
|
||||
}
|
||||
|
||||
public void MovementExpired(bool reset = true)
|
||||
{
|
||||
if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Update))
|
||||
{
|
||||
if (reset)
|
||||
_cleanFlag |= MMCleanFlag.Reset;
|
||||
else
|
||||
_cleanFlag &= ~MMCleanFlag.Reset;
|
||||
DelayedExpire();
|
||||
}
|
||||
else
|
||||
DirectExpire(reset);
|
||||
return _slot[_top];
|
||||
}
|
||||
|
||||
public static uint SplineId
|
||||
@@ -739,14 +754,19 @@ namespace Game.Movement
|
||||
get { return splineId++; }
|
||||
}
|
||||
|
||||
bool IsStatic(IMovementGenerator movement)
|
||||
{
|
||||
return (movement == staticIdleMovement);
|
||||
}
|
||||
|
||||
static uint splineId = 0;
|
||||
|
||||
public Unit _owner { get; private set; }
|
||||
protected IMovementGenerator[] Impl = new IMovementGenerator[(int)MovementSlot.Max];
|
||||
protected IMovementGenerator[] _slot = new IMovementGenerator[(int)MovementSlot.Max];
|
||||
MMCleanFlag _cleanFlag;
|
||||
bool[] _needInit = new bool[(int)MovementSlot.Max];
|
||||
bool[] _initialize = new bool[(int)MovementSlot.Max];
|
||||
int _top;
|
||||
List<IMovementGenerator> _expList = new List<IMovementGenerator>();
|
||||
List<IMovementGenerator> _expireList = new List<IMovementGenerator>();
|
||||
}
|
||||
|
||||
public class JumpArrivalCastArgs
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Game
|
||||
{
|
||||
WaypointManager()
|
||||
{
|
||||
_waypointStore = new MultiMap<uint, WaypointData>();
|
||||
_waypointStore = new Dictionary<uint, WaypointPath>();
|
||||
}
|
||||
|
||||
public void Load()
|
||||
@@ -45,8 +45,6 @@ namespace Game
|
||||
|
||||
do
|
||||
{
|
||||
WaypointData wp = new WaypointData();
|
||||
|
||||
uint pathId = result.Read<uint>(0);
|
||||
|
||||
float x = result.Read<float>(2);
|
||||
@@ -57,23 +55,28 @@ namespace Game
|
||||
GridDefines.NormalizeMapCoord(ref x);
|
||||
GridDefines.NormalizeMapCoord(ref y);
|
||||
|
||||
WaypointNode wp = new WaypointNode();
|
||||
wp.id = result.Read<uint>(1);
|
||||
wp.x = x;
|
||||
wp.y = y;
|
||||
wp.z = z;
|
||||
wp.orientation = o;
|
||||
wp.movetype = (WaypointMoveType)result.Read<uint>(6);
|
||||
if (wp.movetype >= WaypointMoveType.Max)
|
||||
wp.moveType = (WaypointMoveType)result.Read<uint>(6);
|
||||
|
||||
if (wp.moveType >= WaypointMoveType.Max)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Waypoint {0} in waypoint_data has invalid move_type, ignoring", wp.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
wp.delay = result.Read<uint>(7);
|
||||
wp.event_id = result.Read<uint>(8);
|
||||
wp.event_chance = result.Read<byte>(9);
|
||||
wp.eventId = result.Read<uint>(8);
|
||||
wp.eventChance = result.Read<byte>(9);
|
||||
|
||||
_waypointStore.Add(pathId, wp);
|
||||
if (!_waypointStore.ContainsKey(pathId))
|
||||
_waypointStore[pathId] = new WaypointPath();
|
||||
|
||||
_waypointStore[pathId].nodes.Add(wp);
|
||||
++count;
|
||||
} while (result.NextRow());
|
||||
|
||||
@@ -82,8 +85,7 @@ namespace Game
|
||||
|
||||
public void ReloadPath(uint id)
|
||||
{
|
||||
if (_waypointStore.ContainsKey(id))
|
||||
_waypointStore.Remove(id);
|
||||
_waypointStore.Remove(id);
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_ID);
|
||||
stmt.AddValue(0, id);
|
||||
@@ -94,8 +96,6 @@ namespace Game
|
||||
|
||||
do
|
||||
{
|
||||
WaypointData wp = new WaypointData();
|
||||
|
||||
float x = result.Read<float>(1);
|
||||
float y = result.Read<float>(2);
|
||||
float z = result.Read<float>(3);
|
||||
@@ -104,45 +104,79 @@ namespace Game
|
||||
GridDefines.NormalizeMapCoord(ref x);
|
||||
GridDefines.NormalizeMapCoord(ref y);
|
||||
|
||||
WaypointNode wp = new WaypointNode();
|
||||
wp.id = result.Read<uint>(0);
|
||||
wp.x = x;
|
||||
wp.y = y;
|
||||
wp.z = z;
|
||||
wp.orientation = o;
|
||||
wp.movetype = (WaypointMoveType)result.Read<uint>(5);
|
||||
wp.moveType = (WaypointMoveType)result.Read<uint>(5);
|
||||
|
||||
if (wp.movetype >= WaypointMoveType.Max)
|
||||
if (wp.moveType >= WaypointMoveType.Max)
|
||||
{
|
||||
Log.outError(LogFilter.Sql, "Waypoint {0} in waypoint_data has invalid move_type, ignoring", wp.id);
|
||||
continue;
|
||||
}
|
||||
|
||||
wp.delay = result.Read<uint>(6);
|
||||
wp.event_id = result.Read<uint>(7);
|
||||
wp.event_chance = result.Read<byte>(8);
|
||||
wp.eventId = result.Read<uint>(7);
|
||||
wp.eventChance = result.Read<byte>(8);
|
||||
|
||||
_waypointStore.Add(id, wp);
|
||||
if (!_waypointStore.ContainsKey(id))
|
||||
_waypointStore[id] = new WaypointPath();
|
||||
|
||||
_waypointStore[id].nodes.Add(wp);
|
||||
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
public List<WaypointData> GetPath(uint id)
|
||||
public WaypointPath GetPath(uint id)
|
||||
{
|
||||
return _waypointStore.LookupByKey(id);
|
||||
}
|
||||
|
||||
MultiMap<uint, WaypointData> _waypointStore;
|
||||
Dictionary<uint, WaypointPath> _waypointStore;
|
||||
}
|
||||
|
||||
public struct WaypointData
|
||||
public class WaypointNode
|
||||
{
|
||||
public WaypointNode() { moveType = WaypointMoveType.Run; }
|
||||
public WaypointNode(uint _id, float _x, float _y, float _z, float _orientation = 0.0f, uint _delay = 0)
|
||||
{
|
||||
id = _id;
|
||||
x = _x;
|
||||
y = _y;
|
||||
z = _z;
|
||||
orientation = _orientation;
|
||||
delay = _delay;
|
||||
eventId = 0;
|
||||
moveType = WaypointMoveType.Walk;
|
||||
eventChance = 100;
|
||||
}
|
||||
|
||||
public uint id;
|
||||
public float x, y, z, orientation;
|
||||
public uint delay;
|
||||
public uint event_id;
|
||||
public WaypointMoveType movetype;
|
||||
public byte event_chance;
|
||||
public uint eventId;
|
||||
public WaypointMoveType moveType;
|
||||
public byte eventChance;
|
||||
}
|
||||
|
||||
public class WaypointPath
|
||||
{
|
||||
public WaypointPath()
|
||||
{
|
||||
nodes = new List<WaypointNode>();
|
||||
}
|
||||
public WaypointPath(uint _id, List<WaypointNode> _nodes)
|
||||
{
|
||||
id = _id;
|
||||
nodes = _nodes;
|
||||
}
|
||||
|
||||
public List<WaypointNode> nodes;
|
||||
public uint id;
|
||||
}
|
||||
|
||||
public enum WaypointMoveType
|
||||
|
||||
Reference in New Issue
Block a user