Ported .Net Core commits:
hondacrx: - Initial commit: Switch to .Net Core 2.0 - Fix build and removed not needed files Fabi: - Updated solution platforms. - Changed folder structure. - Change library target framework to netstandard2.0. - Updated solution platforms again... - Removed windows specific kernel32 function usage (Ctrl-C handler).
This commit is contained in:
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class ConfusedGenerator<T> : MovementGeneratorMedium<T> where T : Unit
|
||||
{
|
||||
public ConfusedGenerator()
|
||||
{
|
||||
i_nextMoveTime = new TimeTracker();
|
||||
}
|
||||
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
owner.AddUnitState(UnitState.Confused);
|
||||
owner.SetFlag(UnitFields.Flags, UnitFlags.Confused);
|
||||
owner.GetPosition(out i_x, out i_y, out i_z);
|
||||
|
||||
if (!owner.IsAlive() || owner.IsStopped())
|
||||
return;
|
||||
|
||||
owner.StopMoving();
|
||||
owner.AddUnitState(UnitState.ConfusedMove);
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
if (owner.IsTypeId(TypeId.Player))
|
||||
{
|
||||
owner.RemoveFlag(UnitFields.Flags, UnitFlags.Confused);
|
||||
owner.ClearUnitState(UnitState.Confused | UnitState.ConfusedMove);
|
||||
owner.StopMoving();
|
||||
}
|
||||
else if (owner.IsTypeId(TypeId.Unit))
|
||||
{
|
||||
owner.RemoveFlag(UnitFields.Flags, UnitFlags.Confused);
|
||||
owner.ClearUnitState(UnitState.Confused | UnitState.ConfusedMove);
|
||||
if (owner.GetVictim())
|
||||
owner.SetTarget(owner.GetVictim().GetGUID());
|
||||
}
|
||||
}
|
||||
|
||||
public override void DoReset(T owner)
|
||||
{
|
||||
i_nextMoveTime.Reset(0);
|
||||
|
||||
if (!owner.IsAlive() || owner.IsStopped())
|
||||
return;
|
||||
|
||||
owner.StopMoving();
|
||||
owner.AddUnitState(UnitState.Confused | UnitState.ConfusedMove);
|
||||
}
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
{
|
||||
if (owner.HasUnitState(UnitState.Root | UnitState.Stunned | UnitState.Distracted))
|
||||
return true;
|
||||
|
||||
if (i_nextMoveTime.Passed())
|
||||
{
|
||||
// currently moving, update location
|
||||
owner.AddUnitState(UnitState.ConfusedMove);
|
||||
|
||||
if (owner.moveSpline.Finalized())
|
||||
i_nextMoveTime.Reset(RandomHelper.IRand(800, 1500));
|
||||
}
|
||||
else
|
||||
{
|
||||
// waiting for next move
|
||||
i_nextMoveTime.Update(time_diff);
|
||||
if (i_nextMoveTime.Passed())
|
||||
{
|
||||
// start moving
|
||||
owner.AddUnitState(UnitState.ConfusedMove);
|
||||
|
||||
float dest = (float)(4.0f * RandomHelper.NextDouble() - 2.0f);
|
||||
|
||||
Position pos = new Position(i_x, i_y, i_z);
|
||||
owner.MovePositionToFirstCollision(ref pos, dest, 0.0f);
|
||||
|
||||
PathGenerator path = new PathGenerator(owner);
|
||||
path.SetPathLengthLimit(30.0f);
|
||||
bool result = path.CalculatePath(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ());
|
||||
if (!result || path.GetPathType().HasAnyFlag(PathType.NoPath))
|
||||
{
|
||||
i_nextMoveTime.Reset(100);
|
||||
return true;
|
||||
}
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
init.MovebyPath(path.GetPath());
|
||||
init.SetWalk(true);
|
||||
init.Launch();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Confused;
|
||||
}
|
||||
|
||||
TimeTracker i_nextMoveTime;
|
||||
float i_x, i_y, i_z;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class FleeingGenerator<T> : MovementGeneratorMedium<T> where T : Unit
|
||||
{
|
||||
public const float MIN_QUIET_DISTANCE = 28.0f;
|
||||
public const float MAX_QUIET_DISTANCE = 43.0f;
|
||||
|
||||
public FleeingGenerator(ObjectGuid fright)
|
||||
{
|
||||
i_frightGUID = fright;
|
||||
i_nextCheckTime = new TimeTracker();
|
||||
}
|
||||
|
||||
void _setTargetLocation(T owner)
|
||||
{
|
||||
if (owner == null)
|
||||
return;
|
||||
|
||||
if (owner.HasUnitState(UnitState.Root | UnitState.Stunned))
|
||||
return;
|
||||
|
||||
if (owner.HasUnitState(UnitState.Casting) && !owner.CanMoveDuringChannel())
|
||||
{
|
||||
owner.CastStop();
|
||||
return;
|
||||
}
|
||||
|
||||
owner.AddUnitState(UnitState.FleeingMove);
|
||||
|
||||
float x, y, z;
|
||||
_getPoint(owner, out x, out y, out z);
|
||||
|
||||
Position mypos = owner.GetPosition();
|
||||
bool isInLOS = Global.VMapMgr.isInLineOfSight(owner.GetMapId(), mypos.posX, mypos.posY, mypos.posZ + 2.0f, x, y, z + 2.0f);
|
||||
|
||||
if (!isInLOS)
|
||||
{
|
||||
i_nextCheckTime.Reset(200);
|
||||
return;
|
||||
}
|
||||
|
||||
PathGenerator path = new PathGenerator(owner);
|
||||
path.SetPathLengthLimit(30.0f);
|
||||
bool result = path.CalculatePath(x, y, z);
|
||||
if (!result || path.GetPathType().HasAnyFlag(PathType.NoPath))
|
||||
{
|
||||
i_nextCheckTime.Reset(100);
|
||||
return;
|
||||
}
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
init.MovebyPath(path.GetPath());
|
||||
init.SetWalk(false);
|
||||
int traveltime = init.Launch();
|
||||
i_nextCheckTime.Reset(traveltime + RandomHelper.URand(800, 1500));
|
||||
}
|
||||
|
||||
void _getPoint(T owner, out float x, out float y, out float z)
|
||||
{
|
||||
float dist_from_caster, angle_to_caster;
|
||||
Unit fright = Global.ObjAccessor.GetUnit(owner, i_frightGUID);
|
||||
if (fright != null)
|
||||
{
|
||||
dist_from_caster = fright.GetDistance(owner);
|
||||
if (dist_from_caster > 0.2f)
|
||||
angle_to_caster = fright.GetAngle(owner);
|
||||
else
|
||||
angle_to_caster = RandomHelper.FRand(0, 2 * MathFunctions.PI);
|
||||
}
|
||||
else
|
||||
{
|
||||
dist_from_caster = 0.0f;
|
||||
angle_to_caster = RandomHelper.FRand(0, 2 * MathFunctions.PI);
|
||||
}
|
||||
|
||||
float dist, angle;
|
||||
if (dist_from_caster < MIN_QUIET_DISTANCE)
|
||||
{
|
||||
dist = RandomHelper.FRand(0.4f, 1.3f) * (MIN_QUIET_DISTANCE - dist_from_caster);
|
||||
angle = angle_to_caster + RandomHelper.FRand(-MathFunctions.PI / 8, MathFunctions.PI / 8);
|
||||
}
|
||||
else if (dist_from_caster > MAX_QUIET_DISTANCE)
|
||||
{
|
||||
dist = RandomHelper.FRand(0.4f, 1.0f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
|
||||
angle = -angle_to_caster + RandomHelper.FRand(-MathFunctions.PI / 4, MathFunctions.PI / 4);
|
||||
}
|
||||
else // we are inside quiet range
|
||||
{
|
||||
dist = RandomHelper.FRand(0.6f, 1.2f) * (MAX_QUIET_DISTANCE - MIN_QUIET_DISTANCE);
|
||||
angle = RandomHelper.FRand(0, 2 * MathFunctions.PI);
|
||||
}
|
||||
|
||||
Position pos = owner.GetFirstCollisionPosition(dist, angle);
|
||||
x = pos.posX;
|
||||
y = pos.posY;
|
||||
z = pos.posZ;
|
||||
}
|
||||
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
if (owner == null)
|
||||
return;
|
||||
|
||||
owner.SetFlag(UnitFields.Flags, UnitFlags.Fleeing);
|
||||
owner.AddUnitState(UnitState.Fleeing | UnitState.FleeingMove);
|
||||
_setTargetLocation(owner);
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
if (owner.IsTypeId(TypeId.Player))
|
||||
{
|
||||
owner.RemoveFlag(UnitFields.Flags, UnitFlags.Fleeing);
|
||||
owner.ClearUnitState(UnitState.Fleeing | UnitState.FleeingMove);
|
||||
owner.StopMoving();
|
||||
}
|
||||
else
|
||||
{
|
||||
owner.RemoveFlag(UnitFields.Flags, UnitFlags.Fleeing);
|
||||
owner.ClearUnitState(UnitState.Fleeing | UnitState.FleeingMove);
|
||||
if (owner.GetVictim() != null)
|
||||
owner.SetTarget(owner.GetVictim().GetGUID());
|
||||
}
|
||||
}
|
||||
|
||||
public override void DoReset(T owner)
|
||||
{
|
||||
DoInitialize(owner);
|
||||
}
|
||||
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
{
|
||||
if (owner == null || !owner.IsAlive())
|
||||
return false;
|
||||
|
||||
if (owner.HasUnitState(UnitState.Root | UnitState.Stunned))
|
||||
{
|
||||
owner.ClearUnitState(UnitState.FleeingMove);
|
||||
return true;
|
||||
}
|
||||
|
||||
i_nextCheckTime.Update(time_diff);
|
||||
if (i_nextCheckTime.Passed() && owner.moveSpline.Finalized())
|
||||
_setTargetLocation(owner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Fleeing;
|
||||
}
|
||||
|
||||
ObjectGuid i_frightGUID;
|
||||
TimeTracker i_nextCheckTime;
|
||||
}
|
||||
|
||||
public class TimedFleeingGenerator : FleeingGenerator<Creature>
|
||||
{
|
||||
public TimedFleeingGenerator(ObjectGuid fright, uint time) : base(fright)
|
||||
{
|
||||
i_totalFleeTime = new TimeTracker(time);
|
||||
}
|
||||
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
owner.RemoveFlag(UnitFields.Flags, UnitFlags.Fleeing);
|
||||
owner.ClearUnitState(UnitState.Fleeing | UnitState.FleeingMove);
|
||||
Unit victim = owner.GetVictim();
|
||||
if (victim != null)
|
||||
{
|
||||
if (owner.IsAlive())
|
||||
{
|
||||
owner.AttackStop();
|
||||
owner.ToCreature().GetAI().AttackStart(victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Update(Unit owner, uint time_diff)
|
||||
{
|
||||
if (!owner.IsAlive())
|
||||
return false;
|
||||
|
||||
if (owner.HasUnitState(UnitState.Root | UnitState.Stunned))
|
||||
{
|
||||
owner.ClearUnitState(UnitState.FleeingMove);
|
||||
return true;
|
||||
}
|
||||
|
||||
i_totalFleeTime.Update(time_diff);
|
||||
if (i_totalFleeTime.Passed())
|
||||
return false;
|
||||
|
||||
// This calls grant-parent Update method hiden by FleeingMovementGenerator.Update(Creature &, uint32) version
|
||||
// This is done instead of casting Unit& to Creature& and call parent method, then we can use Unit directly
|
||||
return base.Update(owner, time_diff);
|
||||
}
|
||||
|
||||
TimeTracker i_totalFleeTime;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using Game.Movement;
|
||||
|
||||
namespace Game.AI
|
||||
{
|
||||
public class HomeMovementGenerator<T> : MovementGeneratorMedium<T> where T : Creature
|
||||
{
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
SetTargetLocation(owner);
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
if (arrived)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Evade);
|
||||
owner.SetWalk(true);
|
||||
owner.LoadCreaturesAddon();
|
||||
owner.GetAI().JustReachedHome();
|
||||
owner.SetSpawnHealth();
|
||||
}
|
||||
}
|
||||
|
||||
public override void DoReset(T owner) { }
|
||||
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
{
|
||||
arrived = skipToHome || owner.moveSpline.Finalized();
|
||||
return !arrived;
|
||||
}
|
||||
|
||||
void SetTargetLocation(T owner)
|
||||
{
|
||||
if (owner.HasUnitState(UnitState.Root | UnitState.Stunned | UnitState.Distracted))
|
||||
{ // if we are ROOT/STUNNED/DISTRACTED even after aura clear, finalize on next update - otherwise we would get stuck in evade
|
||||
skipToHome = true;
|
||||
return;
|
||||
}
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
float x, y, z, o;
|
||||
// at apply we can select more nice return points base at current movegen
|
||||
if (owner.GetMotionMaster().empty() || !owner.GetMotionMaster().top().GetResetPosition(owner, out x, out y, out z))
|
||||
{
|
||||
owner.GetHomePosition(out x, out y, out z, out o);
|
||||
init.SetFacing(o);
|
||||
}
|
||||
init.MoveTo(x, y, z);
|
||||
init.SetWalk(false);
|
||||
init.Launch();
|
||||
|
||||
skipToHome = false;
|
||||
arrived = false;
|
||||
|
||||
owner.ClearUnitState(UnitState.AllState & ~(UnitState.Evade | UnitState.IgnorePathfinding));
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Home;
|
||||
}
|
||||
|
||||
bool arrived;
|
||||
bool skipToHome;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class IdleMovementGenerator : IMovementGenerator
|
||||
{
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Idle;
|
||||
}
|
||||
|
||||
public bool isActive { get; set; }
|
||||
|
||||
public override void Reset(Unit owner)
|
||||
{
|
||||
if (!owner.isStopped())
|
||||
owner.StopMoving();
|
||||
}
|
||||
public override void Initialize(Unit owner)
|
||||
{
|
||||
Reset(owner);
|
||||
}
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
}
|
||||
public override bool Update(Unit owner, uint time_diff)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class RotateMovementGenerator : IMovementGenerator
|
||||
{
|
||||
public RotateMovementGenerator(uint time, RotateDirection direction)
|
||||
{
|
||||
m_duration = time;
|
||||
m_maxDuration = time;
|
||||
m_direction = direction;
|
||||
}
|
||||
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Rotating);
|
||||
if (owner.IsTypeId(TypeId.Unit))
|
||||
owner.ToCreature().GetAI().MovementInform(MovementGeneratorType.Rotate, 0);
|
||||
}
|
||||
|
||||
public override void Initialize(Unit owner)
|
||||
{
|
||||
if (!owner.IsStopped())
|
||||
owner.StopMoving();
|
||||
|
||||
if (owner.GetVictim())
|
||||
owner.SetInFront(owner.GetVictim());
|
||||
|
||||
owner.AddUnitState(UnitState.Rotating);
|
||||
owner.AttackStop();
|
||||
}
|
||||
|
||||
public override bool Update(Unit owner, uint time_diff)
|
||||
{
|
||||
float angle = owner.GetOrientation();
|
||||
angle += time_diff * MathFunctions.TwoPi / m_maxDuration * (m_direction == RotateDirection.Left ? 1.0f : -1.0f);
|
||||
angle = MathFunctions.wrap(angle, 0.0f, MathFunctions.TwoPi);
|
||||
|
||||
owner.SetOrientation(angle); // UpdateSplinePosition does not set orientation with UNIT_STATE_ROTATING
|
||||
owner.SetFacingTo(angle); // Send spline movement to clients
|
||||
|
||||
if (m_duration > time_diff)
|
||||
m_duration -= time_diff;
|
||||
else
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Reset(Unit owner) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Rotate; }
|
||||
|
||||
uint m_duration, m_maxDuration;
|
||||
RotateDirection m_direction;
|
||||
}
|
||||
|
||||
public class DistractMovementGenerator : IMovementGenerator
|
||||
{
|
||||
public DistractMovementGenerator(uint timer)
|
||||
{
|
||||
m_timer = timer;
|
||||
}
|
||||
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Distracted);
|
||||
|
||||
// If this is a creature, then return orientation to original position (for idle movement creatures)
|
||||
if (owner.IsTypeId(TypeId.Unit))
|
||||
{
|
||||
float angle = owner.ToCreature().GetHomePosition().GetOrientation();
|
||||
owner.SetFacingTo(angle);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize(Unit owner)
|
||||
{
|
||||
// Distracted creatures stand up if not standing
|
||||
if (!owner.IsStandState())
|
||||
owner.SetStandState(UnitStandStateType.Stand);
|
||||
|
||||
owner.AddUnitState(UnitState.Distracted);
|
||||
}
|
||||
|
||||
public override bool Update(Unit owner, uint time_diff)
|
||||
{
|
||||
if (time_diff > m_timer)
|
||||
return false;
|
||||
|
||||
m_timer -= time_diff;
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void Reset(Unit owner) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Distract; }
|
||||
|
||||
uint m_timer;
|
||||
}
|
||||
|
||||
public class AssistanceDistractMovementGenerator : DistractMovementGenerator
|
||||
{
|
||||
public AssistanceDistractMovementGenerator(uint timer) : base(timer) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.AssistanceDistract; }
|
||||
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Distracted);
|
||||
owner.ToCreature().SetReactState(ReactStates.Aggressive);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Dynamic;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public abstract class IMovementGenerator
|
||||
{
|
||||
public abstract void Finalize(Unit owner);
|
||||
|
||||
public abstract void Initialize(Unit owner);
|
||||
|
||||
public abstract void Reset(Unit owner);
|
||||
|
||||
public abstract bool Update(Unit owner, uint time_diff);
|
||||
|
||||
public abstract MovementGeneratorType GetMovementGeneratorType();
|
||||
|
||||
public virtual void unitSpeedChanged() { }
|
||||
|
||||
// used by Evade code for select point to evade with expected restart default movement
|
||||
public virtual bool GetResetPosition(Unit u, out float x, out float y, out float z)
|
||||
{
|
||||
x = y = z = 0.0f;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class MovementGeneratorMedium<T> : IMovementGenerator where T : Unit
|
||||
{
|
||||
public override void Initialize(Unit owner)
|
||||
{
|
||||
DoInitialize((T)owner);
|
||||
isActive = true;
|
||||
}
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
DoFinalize((T)owner);
|
||||
}
|
||||
public override void Reset(Unit owner)
|
||||
{
|
||||
DoReset((T)owner);
|
||||
}
|
||||
public override bool Update(Unit owner, uint time_diff)
|
||||
{
|
||||
return DoUpdate((T)owner, time_diff);
|
||||
}
|
||||
|
||||
public bool isActive { get; set; }
|
||||
|
||||
public abstract void DoInitialize(T owner);
|
||||
public abstract void DoFinalize(T owner);
|
||||
public abstract void DoReset(T owner);
|
||||
public abstract bool DoUpdate(T owner, uint time_diff);
|
||||
}
|
||||
|
||||
public class FollowerReference : Reference<Unit, TargetedMovementGeneratorBase>
|
||||
{
|
||||
public override void targetObjectBuildLink()
|
||||
{
|
||||
getTarget().addFollower(this);
|
||||
}
|
||||
|
||||
public override void targetObjectDestroyLink()
|
||||
{
|
||||
getTarget().removeFollower(this);
|
||||
}
|
||||
|
||||
public override void sourceObjectDestroyLink()
|
||||
{
|
||||
GetSource().stopFollowing();
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class PointMovementGenerator<T> : MovementGeneratorMedium<T> where T : Unit
|
||||
{
|
||||
public PointMovementGenerator(ulong _id, float _x, float _y, float _z, bool _generatePath, float _speed = 0.0f, Unit faceTarget = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
id = _id;
|
||||
i_x = _x;
|
||||
i_y = _y;
|
||||
i_z = _z;
|
||||
speed = _speed;
|
||||
i_faceTarget = faceTarget;
|
||||
i_spellEffectExtra = spellEffectExtraData;
|
||||
m_generatePath = _generatePath;
|
||||
i_recalculateSpeed = false;
|
||||
}
|
||||
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
if (!owner.IsStopped())
|
||||
owner.StopMoving();
|
||||
|
||||
owner.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
|
||||
if (id == EventId.ChargePrepath)
|
||||
return;
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
init.MoveTo(i_x, i_y, i_z, m_generatePath);
|
||||
if (speed > 0.0f)
|
||||
init.SetVelocity(speed);
|
||||
|
||||
if (i_faceTarget)
|
||||
init.SetFacing(i_faceTarget);
|
||||
|
||||
if (i_spellEffectExtra != null)
|
||||
init.SetSpellEffectExtraData(i_spellEffectExtra);
|
||||
|
||||
init.Launch();
|
||||
|
||||
// Call for creature group update
|
||||
Creature creature = owner.ToCreature();
|
||||
if (creature != null)
|
||||
if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
|
||||
creature.GetFormation().LeaderMoveTo(i_x, i_y, i_z);
|
||||
}
|
||||
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
{
|
||||
if (owner == null)
|
||||
return false;
|
||||
|
||||
if (owner.HasUnitState(UnitState.Root | UnitState.Stunned))
|
||||
{
|
||||
owner.ClearUnitState(UnitState.RoamingMove);
|
||||
return true;
|
||||
}
|
||||
|
||||
owner.AddUnitState(UnitState.RoamingMove);
|
||||
|
||||
if (id != EventId.ChargePrepath && i_recalculateSpeed && !owner.moveSpline.Finalized())
|
||||
{
|
||||
i_recalculateSpeed = false;
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
init.MoveTo(i_x, i_y, i_z, m_generatePath);
|
||||
if (speed > 0.0f) // Default value for point motion type is 0.0, if 0.0 spline will use GetSpeed on unit
|
||||
init.SetVelocity(speed);
|
||||
init.Launch();
|
||||
|
||||
// Call for creature group update
|
||||
Creature creature = owner.ToCreature();
|
||||
if (creature != null)
|
||||
if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
|
||||
creature.GetFormation().LeaderMoveTo(i_x, i_y, i_z);
|
||||
}
|
||||
|
||||
return !owner.moveSpline.Finalized();
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
if (owner.HasUnitState(UnitState.Charging))
|
||||
owner.ClearUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
|
||||
if (owner.moveSpline.Finalized())
|
||||
MovementInform(owner);
|
||||
}
|
||||
|
||||
public override void DoReset(T owner)
|
||||
{
|
||||
if (!owner.IsStopped())
|
||||
owner.StopMoving();
|
||||
|
||||
owner.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
}
|
||||
|
||||
public void MovementInform(T unit)
|
||||
{
|
||||
if (!unit.IsTypeId(TypeId.Unit))
|
||||
return;
|
||||
|
||||
if (unit.ToCreature().GetAI() != null)
|
||||
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Point, (uint)id);
|
||||
}
|
||||
|
||||
public override void unitSpeedChanged()
|
||||
{
|
||||
i_recalculateSpeed = true;
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Point;
|
||||
}
|
||||
|
||||
ulong id;
|
||||
float i_x, i_y, i_z;
|
||||
float speed;
|
||||
Unit i_faceTarget;
|
||||
SpellEffectExtraData i_spellEffectExtra;
|
||||
bool m_generatePath;
|
||||
bool i_recalculateSpeed;
|
||||
}
|
||||
|
||||
public class AssistanceMovementGenerator : PointMovementGenerator<Creature>
|
||||
{
|
||||
public AssistanceMovementGenerator(float _x, float _y, float _z) : base(0, _x, _y, _z, true) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Assistance; }
|
||||
|
||||
public override void Finalize(Unit owner)
|
||||
{
|
||||
owner.ToCreature().SetNoCallAssistance(false);
|
||||
owner.ToCreature().CallAssistance();
|
||||
if (owner.IsAlive())
|
||||
owner.GetMotionMaster().MoveSeekAssistanceDistract(WorldConfig.GetUIntValue(WorldCfg.CreatureFamilyAssistanceDelay));
|
||||
}
|
||||
}
|
||||
|
||||
// Does almost nothing - just doesn't allows previous movegen interrupt current effect.
|
||||
public class EffectMovementGenerator : IMovementGenerator
|
||||
{
|
||||
public EffectMovementGenerator(uint Id, uint arrivalSpellId = 0, ObjectGuid arrivalSpellTargetGuid = default(ObjectGuid))
|
||||
{
|
||||
_Id = Id;
|
||||
_arrivalSpellId = arrivalSpellId;
|
||||
_arrivalSpellTargetGuid = arrivalSpellTargetGuid;
|
||||
}
|
||||
|
||||
public override void Finalize(Unit unit)
|
||||
{
|
||||
if (_arrivalSpellId != 0)
|
||||
unit.CastSpell(Global.ObjAccessor.GetUnit(unit, _arrivalSpellTargetGuid), _arrivalSpellId, true);
|
||||
|
||||
if (!unit.IsTypeId(TypeId.Unit))
|
||||
return;
|
||||
|
||||
// Need restore previous movement since we have no proper states system
|
||||
if (unit.IsAlive() && !unit.HasUnitState(UnitState.Confused | UnitState.Fleeing))
|
||||
{
|
||||
Unit victim = unit.GetVictim();
|
||||
if (victim != null)
|
||||
unit.GetMotionMaster().MoveChase(victim);
|
||||
else
|
||||
unit.GetMotionMaster().Initialize();
|
||||
}
|
||||
|
||||
if (unit.ToCreature().GetAI() != null)
|
||||
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Effect, _Id);
|
||||
}
|
||||
|
||||
public override bool Update(Unit owner, uint time_diff)
|
||||
{
|
||||
return !owner.moveSpline.Finalized();
|
||||
}
|
||||
|
||||
public override void Initialize(Unit owner) { }
|
||||
|
||||
public override void Reset(Unit owner) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Effect; }
|
||||
|
||||
uint _Id;
|
||||
uint _arrivalSpellId;
|
||||
ObjectGuid _arrivalSpellTargetGuid;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class RandomMovementGenerator<T> : MovementGeneratorMedium<T> where T : Creature
|
||||
{
|
||||
public RandomMovementGenerator(float spawn_dist = 0.0f)
|
||||
{
|
||||
i_nextMoveTime = new TimeTrackerSmall();
|
||||
wander_distance = spawn_dist;
|
||||
}
|
||||
|
||||
TimeTrackerSmall i_nextMoveTime;
|
||||
float wander_distance;
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Random;
|
||||
}
|
||||
|
||||
public override void DoInitialize(T creature)
|
||||
{
|
||||
if (!creature.IsAlive())
|
||||
return;
|
||||
|
||||
if (wander_distance == 0)
|
||||
wander_distance = creature.GetRespawnRadius();
|
||||
|
||||
if (wander_distance == 0)//Temp fix
|
||||
wander_distance = 50.0f;
|
||||
|
||||
creature.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
_setRandomLocation(creature);
|
||||
|
||||
}
|
||||
public override void DoFinalize(T creature)
|
||||
{
|
||||
creature.ClearUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
creature.SetWalk(false);
|
||||
}
|
||||
public override void DoReset(T creature)
|
||||
{
|
||||
DoInitialize(creature);
|
||||
}
|
||||
|
||||
public override bool DoUpdate(T creature, uint diff)
|
||||
{
|
||||
if (!creature || !creature.IsAlive())
|
||||
return false;
|
||||
|
||||
if (creature.HasUnitState(UnitState.Root | UnitState.Stunned | UnitState.Distracted))
|
||||
{
|
||||
i_nextMoveTime.Reset(0); // Expire the timer
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (creature.moveSpline.Finalized())
|
||||
{
|
||||
i_nextMoveTime.Update((int)diff);
|
||||
if (i_nextMoveTime.Passed())
|
||||
_setRandomLocation(creature);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void _setRandomLocation(T creature)
|
||||
{
|
||||
if (creature.HasUnitState(UnitState.Casting) && !creature.CanMoveDuringChannel())
|
||||
{
|
||||
creature.CastStop();
|
||||
return;
|
||||
}
|
||||
|
||||
float respX, respY, respZ, respO, destX, destY, destZ, travelDistZ;
|
||||
creature.GetHomePosition(out respX, out respY, out respZ, out respO);
|
||||
Map map = creature.GetMap();
|
||||
|
||||
bool is_air_ok = creature.CanFly();
|
||||
|
||||
float angle = (float)(RandomHelper.NextDouble() * MathFunctions.TwoPi);
|
||||
float range = (float)(RandomHelper.NextDouble() * wander_distance);
|
||||
float distanceX = (float)(range * Math.Cos(angle));
|
||||
float distanceY = (float)(range * Math.Sin(angle));
|
||||
|
||||
destX = respX + distanceX;
|
||||
destY = respY + distanceY;
|
||||
|
||||
// prevent invalid coordinates generation
|
||||
GridDefines.NormalizeMapCoord(ref destX);
|
||||
GridDefines.NormalizeMapCoord(ref destY);
|
||||
|
||||
travelDistZ = range; // sin^2+cos^2=1, so travelDistZ=range^2; no need for sqrt below
|
||||
|
||||
if (is_air_ok) // 3D system above ground and above water (flying mode)
|
||||
{
|
||||
// Limit height change
|
||||
float distanceZ = (float)(RandomHelper.NextDouble() * travelDistZ / 2.0f);
|
||||
destZ = respZ + distanceZ;
|
||||
float levelZ = map.GetWaterOrGroundLevel(creature.GetPhases(), destX, destY, destZ - 2.5f);
|
||||
|
||||
// Problem here, we must fly above the ground and water, not under. Let's try on next tick
|
||||
if (levelZ >= destZ)
|
||||
return;
|
||||
}
|
||||
else // 2D only
|
||||
{
|
||||
// 10.0 is the max that vmap high can check (MAX_CAN_FALL_DISTANCE)
|
||||
travelDistZ = travelDistZ >= 10.0f ? 10.0f : travelDistZ;
|
||||
|
||||
// The fastest way to get an accurate result 90% of the time.
|
||||
// Better result can be obtained like 99% accuracy with a ray light, but the cost is too high and the code is too long.
|
||||
destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ + travelDistZ - 2.0f, false);
|
||||
|
||||
if (Math.Abs(destZ - respZ) > travelDistZ) // Map check
|
||||
{
|
||||
// Vmap Horizontal or above
|
||||
destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ - 2.0f, true);
|
||||
|
||||
if (Math.Abs(destZ - respZ) > travelDistZ)
|
||||
{
|
||||
// Vmap Higher
|
||||
destZ = map.GetHeight(creature.GetPhases(), destX, destY, respZ + travelDistZ - 2.0f, true);
|
||||
|
||||
// let's forget this bad coords where a z cannot be find and retry at next tick
|
||||
if (Math.Abs(destZ - respZ) > travelDistZ)
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_air_ok)
|
||||
i_nextMoveTime.Reset(0);
|
||||
else
|
||||
{
|
||||
if (RandomHelper.randChance(50))
|
||||
i_nextMoveTime.Reset(RandomHelper.IRand(5000, 10000));
|
||||
else
|
||||
i_nextMoveTime.Reset(RandomHelper.IRand(50, 400));
|
||||
}
|
||||
|
||||
creature.AddUnitState(UnitState.RoamingMove);
|
||||
if (destZ < 25f)
|
||||
{
|
||||
|
||||
}
|
||||
MoveSplineInit init = new MoveSplineInit(creature);
|
||||
init.MoveTo(destX, destY, destZ);
|
||||
init.SetWalk(true);
|
||||
init.Launch();
|
||||
|
||||
//Call for creature group update
|
||||
if (creature.GetFormation() != null && creature.GetFormation().getLeader() == creature)
|
||||
creature.GetFormation().LeaderMoveTo(destX, destY, destZ);
|
||||
}
|
||||
|
||||
public virtual bool GetResetPosition(Creature creature, float x, float y, float z) { return false; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class SplineChainMovementGenerator : IMovementGenerator
|
||||
{
|
||||
public SplineChainMovementGenerator(uint id, List<SplineChainLink> chain, bool walk = false)
|
||||
{
|
||||
_id = id;
|
||||
_chain = chain;
|
||||
_chainSize = (byte)chain.Count;
|
||||
_walk = walk;
|
||||
}
|
||||
public SplineChainMovementGenerator(SplineChainResumeInfo info)
|
||||
{
|
||||
_id = info.PointID;
|
||||
_chain = info.Chain;
|
||||
_chainSize = (byte)info.Chain.Count;
|
||||
_walk = info.IsWalkMode;
|
||||
finished = info.SplineIndex >= info.Chain.Count;
|
||||
_nextIndex = info.SplineIndex;
|
||||
_nextFirstWP = info.PointIndex;
|
||||
_msToNext = info.TimeToNext;
|
||||
}
|
||||
|
||||
uint SendPathSpline(Unit me, List<Vector3> wp)
|
||||
{
|
||||
int numWp = wp.Count;
|
||||
Contract.Assert(numWp > 1, "Every path must have source & destination");
|
||||
MoveSplineInit init = new MoveSplineInit(me);
|
||||
if (numWp > 2)
|
||||
init.MovebyPath(wp.ToArray());
|
||||
else
|
||||
init.MoveTo(wp[1], false, true);
|
||||
init.SetWalk(_walk);
|
||||
return (uint)init.Launch();
|
||||
}
|
||||
|
||||
void SendSplineFor(Unit me, int index, uint toNext)
|
||||
{
|
||||
Contract.Assert(index < _chainSize);
|
||||
Log.outDebug(LogFilter.Movement, "{0}: Sending spline for {1}.", me.GetGUID().ToString(), index);
|
||||
|
||||
SplineChainLink thisLink = _chain[index];
|
||||
uint actualDuration = SendPathSpline(me, thisLink.Points);
|
||||
if (actualDuration != thisLink.ExpectedDuration)
|
||||
{
|
||||
Log.outDebug(LogFilter.Movement, "{0}: Sent spline for {1}, duration is {2} ms. Expected was {3} ms (delta {4} ms). Adjusting.", me.GetGUID().ToString(), index, actualDuration, thisLink.ExpectedDuration, actualDuration - thisLink.ExpectedDuration);
|
||||
toNext = (uint)(actualDuration / thisLink.ExpectedDuration * toNext);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outDebug(LogFilter.Movement, "{0}: Sent spline for {1}, duration is {2} ms.", me.GetGUID().ToString(), index, actualDuration);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Initialize(Unit me)
|
||||
{
|
||||
if (_chainSize != 0)
|
||||
{
|
||||
if (_nextFirstWP != 0) // this is a resumed movegen that has to start with a partial spline
|
||||
{
|
||||
if (finished)
|
||||
return;
|
||||
SplineChainLink thisLink = _chain[_nextIndex];
|
||||
if (_nextFirstWP >= thisLink.Points.Count)
|
||||
{
|
||||
Log.outError(LogFilter.Movement, "{0}: Attempted to resume spline chain from invalid resume state ({1}, {2}).", me.GetGUID().ToString(), _nextIndex, _nextFirstWP);
|
||||
_nextFirstWP = (byte)(thisLink.Points.Count - 1);
|
||||
}
|
||||
List<Vector3> partial = new List<Vector3>();
|
||||
partial.AddRange(thisLink.Points.Skip(_nextFirstWP - 1).ToArray());
|
||||
SendPathSpline(me, partial);
|
||||
Log.outDebug(LogFilter.Movement, "{0}: Resumed spline chain generator from resume state.", me.GetGUID().ToString());
|
||||
++_nextIndex;
|
||||
if (_msToNext == 0)
|
||||
_msToNext = 1;
|
||||
_nextFirstWP = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
_msToNext = Math.Max(_chain[_nextIndex].TimeToNext, 1u);
|
||||
SendSplineFor(me, _nextIndex, _msToNext);
|
||||
++_nextIndex;
|
||||
if (_nextIndex >= _chainSize)
|
||||
_msToNext = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outError(LogFilter.Movement, "SplineChainMovementGenerator.Initialize - empty spline chain passed for {0}.", me.GetGUID().ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public override void Finalize(Unit me)
|
||||
{
|
||||
if (!finished)
|
||||
return;
|
||||
|
||||
Creature cMe = me.ToCreature();
|
||||
if (cMe && cMe.IsAIEnabled)
|
||||
cMe.GetAI().MovementInform(MovementGeneratorType.SplineChain, _id);
|
||||
}
|
||||
|
||||
public override bool Update(Unit me, uint diff)
|
||||
{
|
||||
if (finished)
|
||||
return false;
|
||||
|
||||
// _msToNext being zero here means we're on the final spline
|
||||
if (_msToNext == 0)
|
||||
{
|
||||
finished = me.moveSpline.Finalized();
|
||||
return !finished;
|
||||
}
|
||||
|
||||
if (_msToNext <= diff)
|
||||
{
|
||||
// Send next spline
|
||||
Log.outDebug(LogFilter.Movement, "{0}: Should send spline {1} ({2} ms late).", me.GetGUID().ToString(), _nextIndex, diff - _msToNext);
|
||||
_msToNext = Math.Max(_chain[_nextIndex].TimeToNext, 1u);
|
||||
SendSplineFor(me, _nextIndex, _msToNext);
|
||||
++_nextIndex;
|
||||
if (_nextIndex >= _chainSize)
|
||||
{
|
||||
// We have reached the final spline, once it finalizes we should also finalize the movegen (start checking on next update)
|
||||
_msToNext = 0;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
_msToNext -= diff;
|
||||
return true;
|
||||
}
|
||||
|
||||
SplineChainResumeInfo GetResumeInfo(Unit me)
|
||||
{
|
||||
if (_nextIndex == 0)
|
||||
return new SplineChainResumeInfo(_id, _chain, _walk, 0, 0, _msToNext);
|
||||
if (me.moveSpline.Finalized())
|
||||
{
|
||||
if (_nextIndex < _chainSize)
|
||||
return new SplineChainResumeInfo(_id, _chain, _walk, _nextIndex, 0, 1u);
|
||||
else
|
||||
return new SplineChainResumeInfo();
|
||||
}
|
||||
return new SplineChainResumeInfo(_id, _chain, _walk, (byte)(_nextIndex - 1), (byte)(me.moveSpline._currentSplineIdx()), _msToNext);
|
||||
}
|
||||
|
||||
public override void Reset(Unit owner) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.SplineChain; }
|
||||
|
||||
uint _id;
|
||||
List<SplineChainLink> _chain = new List<SplineChainLink>();
|
||||
byte _chainSize;
|
||||
bool _walk;
|
||||
bool finished;
|
||||
byte _nextIndex;
|
||||
byte _nextFirstWP; // only used for resuming
|
||||
uint _msToNext;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,401 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public interface TargetedMovementGeneratorBase
|
||||
{
|
||||
FollowerReference reftarget { get; set; }
|
||||
void stopFollowing();
|
||||
}
|
||||
|
||||
public abstract class TargetedMovementGeneratorMedium<T, D> : MovementGeneratorMedium<T>, TargetedMovementGeneratorBase where T : Unit
|
||||
{
|
||||
public FollowerReference reftarget { get; set; }
|
||||
public Unit target
|
||||
{
|
||||
get { return reftarget.getTarget(); }
|
||||
}
|
||||
|
||||
public void stopFollowing() { }
|
||||
|
||||
public TargetedMovementGeneratorMedium(Unit _target, float _offset = 0, float _angle = 0)
|
||||
{
|
||||
reftarget = new FollowerReference();
|
||||
reftarget.link(_target, this);
|
||||
recheckDistance = new TimeTrackerSmall();
|
||||
offset = _offset;
|
||||
angle = _angle;
|
||||
recalculateTravel = false;
|
||||
targetReached = false;
|
||||
}
|
||||
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
{
|
||||
if (!reftarget.isValid() || !target.IsInWorld)
|
||||
return false;
|
||||
|
||||
if (owner == null || !owner.IsAlive())
|
||||
return false;
|
||||
|
||||
if (owner.HasUnitState(UnitState.NotMove))
|
||||
{
|
||||
_clearUnitStateMove(owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent movement while casting spells with cast time or channel time
|
||||
if (owner.HasUnitState(UnitState.Casting) && !owner.CanMoveDuringChannel())
|
||||
{
|
||||
if (!owner.isStopped())
|
||||
owner.StopMoving();
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent crash after creature killed pet
|
||||
if (_lostTarget(owner))
|
||||
{
|
||||
_clearUnitStateMove(owner);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool targetMoved = false;
|
||||
recheckDistance.Update((int)time_diff);
|
||||
if (recheckDistance.Passed())
|
||||
{
|
||||
recheckDistance.Reset(100);
|
||||
//More distance let have better performance, less distance let have more sensitive reaction at target move.
|
||||
float allowed_dist = 0.0f;// owner.GetCombatReach() + WorldConfig.GetFloatValue(WorldCfg.RateTargetPosRecalculationRange);
|
||||
|
||||
if (owner.IsPet() && (owner.GetCharmerOrOwnerGUID() == target.GetGUID()))
|
||||
allowed_dist = 1.0f; // pet following owner
|
||||
else
|
||||
allowed_dist = owner.GetCombatReach() + WorldConfig.GetFloatValue(WorldCfg.RateTargetPosRecalculationRange);
|
||||
|
||||
Vector3 dest = owner.moveSpline.FinalDestination();
|
||||
if (owner.moveSpline.onTransport)
|
||||
{
|
||||
float o = 0;
|
||||
ITransport transport = owner.GetDirectTransport();
|
||||
if (transport != null)
|
||||
transport.CalculatePassengerPosition(ref dest.X, ref dest.Y, ref dest.Z, ref o);
|
||||
}
|
||||
|
||||
// First check distance
|
||||
if (owner.IsTypeId(TypeId.Unit) && (owner.ToCreature().CanFly() || owner.ToCreature().CanSwim()))
|
||||
targetMoved = !target.IsWithinDist3d(dest.X, dest.Y, dest.Z, allowed_dist);
|
||||
else
|
||||
targetMoved = !target.IsWithinDist2d(dest.X, dest.Y, allowed_dist);
|
||||
|
||||
|
||||
// then, if the target is in range, check also Line of Sight.
|
||||
if (!targetMoved)
|
||||
targetMoved = !target.IsWithinLOSInMap(owner);
|
||||
}
|
||||
|
||||
if (recalculateTravel || targetMoved)
|
||||
_setTargetLocation(owner, targetMoved);
|
||||
|
||||
if (owner.moveSpline.Finalized())
|
||||
{
|
||||
MovementInform(owner);
|
||||
if (angle == 0.0f && !owner.HasInArc(0.01f, target))
|
||||
owner.SetInFront(target);
|
||||
|
||||
if (!targetReached)
|
||||
{
|
||||
targetReached = true;
|
||||
_reachTarget(owner);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void unitSpeedChanged()
|
||||
{
|
||||
recalculateTravel = true;
|
||||
}
|
||||
|
||||
public void _setTargetLocation(T owner, bool updateDestination)
|
||||
{
|
||||
if (!reftarget.isValid() || !target.IsInWorld)
|
||||
return;
|
||||
|
||||
if (owner.HasUnitState(UnitState.NotMove))
|
||||
return;
|
||||
|
||||
if (owner.HasUnitState(UnitState.Casting) && !owner.CanMoveDuringChannel())
|
||||
return;
|
||||
|
||||
if (owner.IsTypeId(TypeId.Unit) && !target.isInAccessiblePlaceFor(owner.ToCreature()))
|
||||
{
|
||||
owner.ToCreature().SetCannotReachTarget(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (owner.IsTypeId(TypeId.Unit) && owner.ToCreature().IsFocusing(null, true))
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
if (updateDestination || i_path == null)
|
||||
{
|
||||
if (offset == 0)
|
||||
{
|
||||
if (target.IsWithinDistInMap(owner, SharedConst.ContactDistance))
|
||||
return;
|
||||
|
||||
// to nearest contact position
|
||||
target.GetContactPoint(owner, out x, out y, out z);
|
||||
}
|
||||
else
|
||||
{
|
||||
float dist = 0;
|
||||
float size = 0;
|
||||
|
||||
// Pets need special handling.
|
||||
// We need to subtract GetObjectSize() because it gets added back further down the chain
|
||||
// and that makes pets too far away. Subtracting it allows pets to properly
|
||||
// be (GetCombatReach() + i_offset) away.
|
||||
// Only applies when i_target is pet's owner otherwise pets and mobs end up
|
||||
// doing a "dance" while fighting
|
||||
if (owner.IsPet() && target.IsTypeId(TypeId.Player))
|
||||
{
|
||||
dist = 1.0f;// target.GetCombatReach();
|
||||
size = 1.0f;// target.GetCombatReach() - target.GetObjectSize();
|
||||
}
|
||||
else
|
||||
{
|
||||
dist = offset + 1.0f;
|
||||
size = owner.GetObjectSize();
|
||||
}
|
||||
|
||||
if (target.IsWithinDistInMap(owner, dist))
|
||||
return;
|
||||
|
||||
// to at i_offset distance from target and i_angle from target facing
|
||||
target.GetClosePoint(out x, out y, out z, size, offset, angle);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// the destination has not changed, we just need to refresh the path (usually speed change)
|
||||
var end = i_path.GetEndPosition();
|
||||
x = end.X;
|
||||
y = end.Y;
|
||||
z = end.Z;
|
||||
}
|
||||
|
||||
if (i_path == null)
|
||||
i_path = new PathGenerator(owner);
|
||||
|
||||
// allow pets to use shortcut if no path found when following their master
|
||||
bool forceDest = (owner.IsTypeId(TypeId.Unit) && owner.IsPet()
|
||||
&& owner.HasUnitState(UnitState.Follow));
|
||||
|
||||
bool result = i_path.CalculatePath(x, y, z, forceDest);
|
||||
if (!result && Convert.ToBoolean(i_path.GetPathType() & PathType.NoPath))
|
||||
{
|
||||
// Can't reach target
|
||||
recalculateTravel = true;
|
||||
if (owner.IsTypeId(TypeId.Unit))
|
||||
owner.ToCreature().SetCannotReachTarget(true);
|
||||
return;
|
||||
}
|
||||
|
||||
_addUnitStateMove(owner);
|
||||
targetReached = false;
|
||||
recalculateTravel = false;
|
||||
owner.AddUnitState(UnitState.Chase);
|
||||
if (owner.IsTypeId(TypeId.Unit))
|
||||
owner.ToCreature().SetCannotReachTarget(false);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
init.MovebyPath(i_path.GetPath());
|
||||
init.SetWalk(EnableWalking());
|
||||
// Using the same condition for facing target as the one that is used for SetInFront on movement end
|
||||
// - applies to ChaseMovementGenerator mostly
|
||||
if (angle == 0.0f)
|
||||
init.SetFacing(target);
|
||||
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
public void UpdateFinalDistance(float fDistance)
|
||||
{
|
||||
if (typeof(T) == typeof(Player))
|
||||
return;
|
||||
offset = fDistance;
|
||||
recalculateTravel = true;
|
||||
}
|
||||
|
||||
bool IsReachable() { return (i_path != null) ? Convert.ToBoolean(i_path.GetPathType() & PathType.Normal) : true; }
|
||||
|
||||
public abstract void MovementInform(T unit);
|
||||
public abstract bool _lostTarget(T u);
|
||||
public abstract void _clearUnitStateMove(T u);
|
||||
public abstract void _addUnitStateMove(T u);
|
||||
public abstract void _reachTarget(T owner);
|
||||
public abstract bool EnableWalking();
|
||||
public abstract void _updateSpeed(T u);
|
||||
|
||||
#region Fields
|
||||
PathGenerator i_path;
|
||||
TimeTrackerSmall recheckDistance;
|
||||
float offset;
|
||||
float angle;
|
||||
public bool recalculateTravel;
|
||||
bool targetReached;
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class ChaseMovementGenerator<T> : TargetedMovementGeneratorMedium<T, ChaseMovementGenerator<T>> where T : Unit
|
||||
{
|
||||
public ChaseMovementGenerator(Unit target)
|
||||
: base(target)
|
||||
{
|
||||
}
|
||||
public ChaseMovementGenerator(Unit target, float offset, float angle)
|
||||
: base(target, offset, angle)
|
||||
{
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Chase; }
|
||||
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
if (owner.IsTypeId(TypeId.Unit))
|
||||
owner.SetWalk(false);
|
||||
|
||||
owner.AddUnitState(UnitState.Chase | UnitState.ChaseMove);
|
||||
_setTargetLocation(owner, true);
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Chase | UnitState.ChaseMove);
|
||||
}
|
||||
|
||||
public override void DoReset(T owner)
|
||||
{
|
||||
DoInitialize(owner);
|
||||
}
|
||||
|
||||
public override bool _lostTarget(T u)
|
||||
{
|
||||
return u.GetVictim() != target;
|
||||
}
|
||||
public override void _clearUnitStateMove(T u)
|
||||
{
|
||||
u.ClearUnitState(UnitState.ChaseMove);
|
||||
}
|
||||
public override void _addUnitStateMove(T u)
|
||||
{
|
||||
u.AddUnitState(UnitState.ChaseMove);
|
||||
}
|
||||
|
||||
public override bool EnableWalking() { return false; }
|
||||
public override void _updateSpeed(T u) { }
|
||||
public override void _reachTarget(T owner)
|
||||
{
|
||||
_clearUnitStateMove(owner);
|
||||
if (owner.IsWithinMeleeRange(target))
|
||||
owner.Attack(target, true);
|
||||
if (owner.IsTypeId(TypeId.Unit))
|
||||
owner.ToCreature().SetCannotReachTarget(false);
|
||||
}
|
||||
public override void MovementInform(T unit)
|
||||
{
|
||||
if (unit.IsTypeId(TypeId.Unit))
|
||||
{
|
||||
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
|
||||
if (unit.ToCreature().GetAI() != null)
|
||||
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Chase, (uint)target.GetGUID().GetCounter());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FollowMovementGenerator<T> : TargetedMovementGeneratorMedium<T, FollowMovementGenerator<T>> where T : Unit
|
||||
{
|
||||
public FollowMovementGenerator(Unit target) : base(target) { }
|
||||
public FollowMovementGenerator(Unit target, float offset, float angle) : base(target, offset, angle) { }
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Follow;
|
||||
}
|
||||
public override void _clearUnitStateMove(T u)
|
||||
{
|
||||
u.ClearUnitState(UnitState.FollowMove);
|
||||
}
|
||||
public override void _addUnitStateMove(T u)
|
||||
{
|
||||
u.AddUnitState(UnitState.FollowMove);
|
||||
}
|
||||
public override void DoReset(T owner)
|
||||
{
|
||||
DoInitialize(owner);
|
||||
}
|
||||
public override bool _lostTarget(T u) { return false; }
|
||||
public override void _reachTarget(T u) { }
|
||||
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
owner.AddUnitState(UnitState.Follow | UnitState.FollowMove);
|
||||
_updateSpeed(owner);
|
||||
_setTargetLocation(owner, true);
|
||||
}
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Follow | UnitState.FollowMove);
|
||||
_updateSpeed(owner);
|
||||
}
|
||||
public override void MovementInform(T unit)
|
||||
{
|
||||
if (unit.IsTypeId(TypeId.Player))
|
||||
return;
|
||||
|
||||
// Pass back the GUIDLow of the target. If it is pet's owner then PetAI will handle
|
||||
if (unit.ToCreature().GetAI() != null)
|
||||
unit.ToCreature().GetAI().MovementInform(MovementGeneratorType.Follow, (uint)target.GetGUID().GetCounter());
|
||||
}
|
||||
public override bool EnableWalking()
|
||||
{
|
||||
if (typeof(T) == typeof(Player))
|
||||
return false;
|
||||
else
|
||||
return reftarget.isValid() && target.IsWalking();
|
||||
}
|
||||
public override void _updateSpeed(T owner)
|
||||
{
|
||||
if (owner.IsTypeId(TypeId.Player))
|
||||
return;
|
||||
|
||||
if (!owner.IsPet() || !owner.IsInWorld || !reftarget.isValid() && target.GetGUID() != owner.GetOwnerGUID())
|
||||
return;
|
||||
|
||||
owner.UpdateSpeed(UnitMoveType.Run);
|
||||
owner.UpdateSpeed(UnitMoveType.Walk);
|
||||
owner.UpdateSpeed(UnitMoveType.Swim);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,503 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class WaypointMovementGenerator<T> : MovementGeneratorMedium<T> where T : 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);
|
||||
isArrivalDone = false;
|
||||
pathId = pathid;
|
||||
repeating = _repeating;
|
||||
}
|
||||
public override void DoReset(T owner)
|
||||
{
|
||||
owner.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
StartMoveNow(owner);
|
||||
}
|
||||
|
||||
public override void DoFinalize(T owner)
|
||||
{
|
||||
owner.ClearUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
owner.SetWalk(false);
|
||||
}
|
||||
public override void DoInitialize(T owner)
|
||||
{
|
||||
LoadPath(owner);
|
||||
owner.AddUnitState(UnitState.Roaming | UnitState.RoamingMove);
|
||||
}
|
||||
public override bool DoUpdate(T owner, uint time_diff)
|
||||
{
|
||||
// Waypoint movement can be switched on/off
|
||||
// This is quite handy for escort quests and other stuff
|
||||
if (owner.HasUnitState(UnitState.NotMove))
|
||||
{
|
||||
owner.ClearUnitState(UnitState.RoamingMove);
|
||||
return true;
|
||||
}
|
||||
// prevent a crash at empty waypoint path.
|
||||
if (path == null || path.Empty())
|
||||
return false;
|
||||
|
||||
if (Stopped())
|
||||
{
|
||||
if (CanMove((int)time_diff))
|
||||
return StartMove(owner);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (owner.IsStopped())
|
||||
Stop(WorldConfig.GetIntValue(WorldCfg.CreatureStopForPlayer));
|
||||
else if (owner.moveSpline.Finalized())
|
||||
{
|
||||
OnArrived(owner);
|
||||
return StartMove(owner);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void MovementInform(Creature creature)
|
||||
{
|
||||
if (creature.IsAIEnabled)
|
||||
creature.GetAI().MovementInform(MovementGeneratorType.Waypoint, currentNode);
|
||||
}
|
||||
|
||||
void Stop(int time)
|
||||
{
|
||||
nextMoveTime.Reset(time);
|
||||
}
|
||||
bool Stopped()
|
||||
{
|
||||
return !nextMoveTime.Passed();
|
||||
}
|
||||
bool CanMove(int diff)
|
||||
{
|
||||
nextMoveTime.Update(diff);
|
||||
return nextMoveTime.Passed();
|
||||
}
|
||||
void StartMoveNow(Creature creature)
|
||||
{
|
||||
nextMoveTime.Reset(0);
|
||||
StartMove(creature);
|
||||
}
|
||||
bool StartMove(Creature creature)
|
||||
{
|
||||
if (path == null || path.Empty())
|
||||
return false;
|
||||
|
||||
if (Stopped())
|
||||
return true;
|
||||
|
||||
bool transportPath = creature.GetTransport() != null;
|
||||
|
||||
if (isArrivalDone)
|
||||
{
|
||||
if ((currentNode == path.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;
|
||||
|
||||
if (!transportPath)
|
||||
creature.SetHomePosition(x, y, z, o);
|
||||
else
|
||||
{
|
||||
Transport trans = creature.GetTransport();
|
||||
if (trans)
|
||||
{
|
||||
o -= trans.GetOrientation();
|
||||
creature.SetTransportHomePosition(x, y, z, o);
|
||||
trans.CalculatePassengerPosition(ref x, ref y, ref z, ref o);
|
||||
creature.SetHomePosition(x, y, z, o);
|
||||
}
|
||||
else
|
||||
transportPath = false;
|
||||
// else if (vehicle) - this should never happen, vehicle offsets are const
|
||||
}
|
||||
|
||||
creature.GetMotionMaster().Initialize();
|
||||
return false;
|
||||
}
|
||||
|
||||
currentNode = (uint)((currentNode + 1) % path.Count);
|
||||
}
|
||||
|
||||
WaypointData node = path.LookupByIndex((int)currentNode);
|
||||
|
||||
isArrivalDone = false;
|
||||
|
||||
creature.AddUnitState(UnitState.RoamingMove);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(creature);
|
||||
Position formationDest = new Position(node.x, node.y, node.z);
|
||||
|
||||
//! If creature is on transport, we assume waypoints set in DB are already transport offsets
|
||||
if (transportPath)
|
||||
{
|
||||
init.DisableTransportPathTransformations();
|
||||
ITransport trans = creature.GetDirectTransport();
|
||||
if (trans != null)
|
||||
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)
|
||||
{
|
||||
case WaypointMoveType.Land:
|
||||
init.SetAnimation(AnimType.ToGround);
|
||||
break;
|
||||
case WaypointMoveType.Takeoff:
|
||||
init.SetAnimation(AnimType.ToFly);
|
||||
break;
|
||||
case WaypointMoveType.Run:
|
||||
init.SetWalk(false);
|
||||
break;
|
||||
case WaypointMoveType.Walk:
|
||||
init.SetWalk(true);
|
||||
break;
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
path = Global.WaypointMgr.GetPath(pathId);
|
||||
|
||||
if (path == null)
|
||||
{
|
||||
// No movement found for entry
|
||||
Log.outError(LogFilter.ScriptsAi, "WaypointMovementGenerator.LoadPath: creature {0} (Entry: {1} GUID: {2}) doesn't have waypoint path id: {3}", creature.GetName(), creature.GetEntry(), creature.GetGUID().ToString(), pathId);
|
||||
return;
|
||||
}
|
||||
|
||||
StartMoveNow(creature);
|
||||
}
|
||||
void OnArrived(Creature creature)
|
||||
{
|
||||
if (path == null || path.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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
// Inform script
|
||||
MovementInform(creature);
|
||||
creature.UpdateWaypointID(currentNode);
|
||||
|
||||
if (wpData.delay != 0)
|
||||
{
|
||||
creature.ClearUnitState(UnitState.RoamingMove);
|
||||
Stop((int)wpData.delay);
|
||||
}
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType()
|
||||
{
|
||||
return MovementGeneratorType.Waypoint;
|
||||
}
|
||||
|
||||
TimeTrackerSmall nextMoveTime;
|
||||
bool isArrivalDone;
|
||||
uint pathId;
|
||||
bool repeating;
|
||||
List<WaypointData> path;
|
||||
uint currentNode;
|
||||
}
|
||||
|
||||
public class FlightPathMovementGenerator : MovementGeneratorMedium<Player>
|
||||
{
|
||||
public FlightPathMovementGenerator() { }
|
||||
|
||||
public void LoadPath(Player player, uint startNode = 0)
|
||||
{
|
||||
i_path.Clear();
|
||||
i_currentNode = (int)startNode;
|
||||
_pointsForPathSwitch.Clear();
|
||||
var taxi = player.m_taxi.GetPath();
|
||||
for (int src = 0, dst = 1; dst < taxi.Count; src = dst++)
|
||||
{
|
||||
uint path, cost;
|
||||
Global.ObjectMgr.GetTaxiPath(taxi[src], taxi[dst], out path, out cost);
|
||||
if (path > CliDB.TaxiPathNodesByPath.Keys.Max())
|
||||
return;
|
||||
|
||||
var nodes = CliDB.TaxiPathNodesByPath[path];
|
||||
if (!nodes.Empty())
|
||||
{
|
||||
TaxiPathNodeRecord start = nodes[0];
|
||||
TaxiPathNodeRecord end = nodes[nodes.Length - 1];
|
||||
bool passedPreviousSegmentProximityCheck = false;
|
||||
for (uint i = 0; i < nodes.Length; ++i)
|
||||
{
|
||||
if (passedPreviousSegmentProximityCheck || src == 0 || i_path.Empty() || IsNodeIncludedInShortenedPath(i_path.Last(), nodes[i]))
|
||||
{
|
||||
if ((src == 0 || (IsNodeIncludedInShortenedPath(start, nodes[i]) && i >= 2)) &&
|
||||
(dst == taxi.Count - 1 || (IsNodeIncludedInShortenedPath(end, nodes[i]) && i < nodes.Length - 1)))
|
||||
{
|
||||
passedPreviousSegmentProximityCheck = true;
|
||||
i_path.Add(nodes[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i_path.RemoveAt(i_path.Count - 1);
|
||||
_pointsForPathSwitch[_pointsForPathSwitch.Count - 1].PathIndex -= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_pointsForPathSwitch.Add(new TaxiNodeChangeInfo((uint)(i_path.Count - 1), (int)cost));
|
||||
}
|
||||
}
|
||||
|
||||
public override void DoInitialize(Player owner)
|
||||
{
|
||||
Reset(owner);
|
||||
InitEndGridInfo();
|
||||
}
|
||||
|
||||
public override void DoFinalize(Player owner)
|
||||
{
|
||||
// remove flag to prevent send object build movement packets for flight state and crash (movement generator already not at top of stack)
|
||||
owner.ClearUnitState(UnitState.InFlight);
|
||||
|
||||
owner.Dismount();
|
||||
owner.RemoveFlag(UnitFields.Flags, UnitFlags.RemoveClientControl | UnitFlags.TaxiFlight);
|
||||
|
||||
if (owner.m_taxi.empty())
|
||||
{
|
||||
owner.getHostileRefManager().setOnlineOfflineState(true);
|
||||
// update z position to ground and orientation for landing point
|
||||
// this prevent cheating with landing point at lags
|
||||
// when client side flight end early in comparison server side
|
||||
owner.StopMoving();
|
||||
}
|
||||
|
||||
owner.RemoveFlag(PlayerFields.Flags, PlayerFlags.TaxiBenchmark);
|
||||
}
|
||||
|
||||
public override void DoReset(Player owner)
|
||||
{
|
||||
owner.getHostileRefManager().setOnlineOfflineState(false);
|
||||
owner.AddUnitState(UnitState.InFlight);
|
||||
owner.SetFlag(UnitFields.Flags, UnitFlags.RemoveClientControl | UnitFlags.TaxiFlight);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(owner);
|
||||
uint end = GetPathAtMapEnd();
|
||||
init.args.path = new Vector3[end];
|
||||
for (int i = i_currentNode; i != end; ++i)
|
||||
{
|
||||
Vector3 vertice = new Vector3(i_path[i].Loc.X, i_path[i].Loc.Y, i_path[i].Loc.Z);
|
||||
init.args.path[i] = vertice;
|
||||
}
|
||||
init.SetFirstPointId(i_currentNode);
|
||||
init.SetFly();
|
||||
init.SetSmooth();
|
||||
init.SetUncompressed();
|
||||
init.SetWalk(true);
|
||||
init.SetVelocity(30.0f);
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
public override bool DoUpdate(Player player, uint time_diff)
|
||||
{
|
||||
uint pointId = (uint)player.moveSpline.currentPathIdx();
|
||||
if (pointId > i_currentNode)
|
||||
{
|
||||
bool departureEvent = true;
|
||||
do
|
||||
{
|
||||
DoEventIfAny(player, i_path[i_currentNode], departureEvent);
|
||||
while (!_pointsForPathSwitch.Empty() && _pointsForPathSwitch[0].PathIndex <= i_currentNode)
|
||||
{
|
||||
_pointsForPathSwitch.RemoveAt(0);
|
||||
player.m_taxi.NextTaxiDestination();
|
||||
if (!_pointsForPathSwitch.Empty())
|
||||
{
|
||||
player.UpdateCriteria(CriteriaTypes.GoldSpentForTravelling, (uint)_pointsForPathSwitch[0].Cost);
|
||||
player.ModifyMoney(-_pointsForPathSwitch[0].Cost);
|
||||
}
|
||||
}
|
||||
|
||||
if (pointId == i_currentNode)
|
||||
break;
|
||||
|
||||
if (i_currentNode == _preloadTargetNode)
|
||||
PreloadEndGrid();
|
||||
i_currentNode += (departureEvent ? 1 : 0);
|
||||
departureEvent = !departureEvent;
|
||||
}
|
||||
while (true);
|
||||
}
|
||||
|
||||
return i_currentNode < (i_path.Count - 1);
|
||||
}
|
||||
|
||||
public void SetCurrentNodeAfterTeleport()
|
||||
{
|
||||
if (i_path.Empty() || i_currentNode >= i_path.Count)
|
||||
return;
|
||||
|
||||
uint map0 = i_path[i_currentNode].MapID;
|
||||
for (int i = i_currentNode + 1; i < i_path.Count; ++i)
|
||||
{
|
||||
if (i_path[i].MapID != map0)
|
||||
{
|
||||
i_currentNode = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DoEventIfAny(Player player, TaxiPathNodeRecord node, bool departure)
|
||||
{
|
||||
uint eventid = departure ? node.DepartureEventID : node.ArrivalEventID;
|
||||
if (eventid != 0)
|
||||
{
|
||||
Log.outDebug(LogFilter.Scripts, "Taxi {0} event {1} of node {2} of path {3} for player {4}", departure ? "departure" : "arrival", eventid, node.NodeIndex, node.PathID, player.GetName());
|
||||
player.GetMap().ScriptsStart(ScriptsType.Event, eventid, player, player);
|
||||
}
|
||||
}
|
||||
|
||||
bool GetResetPos(Player player, out float x, out float y, out float z)
|
||||
{
|
||||
TaxiPathNodeRecord node = i_path[i_currentNode];
|
||||
x = node.Loc.X;
|
||||
y = node.Loc.Y;
|
||||
z = node.Loc.Z;
|
||||
return true;
|
||||
}
|
||||
|
||||
void InitEndGridInfo()
|
||||
{
|
||||
int nodeCount = i_path.Count; //! Number of nodes in path.
|
||||
_endMapId = i_path[nodeCount - 1].MapID; //! MapId of last node
|
||||
_preloadTargetNode = (uint)nodeCount - 3;
|
||||
_endGridX = i_path[nodeCount - 1].Loc.X;
|
||||
_endGridY = i_path[nodeCount - 1].Loc.Y;
|
||||
}
|
||||
|
||||
void PreloadEndGrid()
|
||||
{
|
||||
// used to preload the final grid where the flightmaster is
|
||||
Map endMap = Global.MapMgr.FindBaseNonInstanceMap(_endMapId);
|
||||
|
||||
// Load the grid
|
||||
if (endMap != null)
|
||||
{
|
||||
Log.outInfo(LogFilter.Server, "Preloading grid ({0}, {1}) for map {2} at node index {3}/{4}", _endGridX, _endGridY, _endMapId, _preloadTargetNode, i_path.Count - 1);
|
||||
endMap.LoadGrid(_endGridX, _endGridY);
|
||||
}
|
||||
else
|
||||
Log.outInfo(LogFilter.Server, "Unable to determine map to preload flightmaster grid");
|
||||
}
|
||||
|
||||
uint GetPathAtMapEnd()
|
||||
{
|
||||
if (i_currentNode >= i_path.Count)
|
||||
return (uint)i_path.Count;
|
||||
|
||||
uint curMapId = i_path[i_currentNode].MapID;
|
||||
for (int i = i_currentNode; i < i_path.Count; ++i)
|
||||
{
|
||||
if (i_path[i].MapID != curMapId)
|
||||
return (uint)i;
|
||||
}
|
||||
|
||||
return (uint)i_path.Count;
|
||||
}
|
||||
|
||||
bool IsNodeIncludedInShortenedPath(TaxiPathNodeRecord p1, TaxiPathNodeRecord p2)
|
||||
{
|
||||
return p1.MapID != p2.MapID || Math.Pow(p1.Loc.X - p2.Loc.X, 2) + Math.Pow(p1.Loc.Y - p2.Loc.Y, 2) > (40.0f * 40.0f);
|
||||
}
|
||||
|
||||
public override MovementGeneratorType GetMovementGeneratorType() { return MovementGeneratorType.Flight; }
|
||||
|
||||
public List<TaxiPathNodeRecord> GetPath() { return i_path; }
|
||||
|
||||
bool HasArrived() { return (i_currentNode >= i_path.Count); }
|
||||
|
||||
public void SkipCurrentNode() { ++i_currentNode; }
|
||||
|
||||
public uint GetCurrentNode() { return (uint)i_currentNode; }
|
||||
|
||||
|
||||
float _endGridX; //! X coord of last node location
|
||||
float _endGridY; //! Y coord of last node location
|
||||
uint _endMapId; //! map Id of last node location
|
||||
uint _preloadTargetNode; //! node index where preloading starts
|
||||
|
||||
int i_currentNode;
|
||||
List<TaxiPathNodeRecord> i_path = new List<TaxiPathNodeRecord>();
|
||||
List<TaxiNodeChangeInfo> _pointsForPathSwitch = new List<TaxiNodeChangeInfo>(); //! node indexes and costs where TaxiPath changes
|
||||
|
||||
class TaxiNodeChangeInfo
|
||||
{
|
||||
public TaxiNodeChangeInfo(uint pathIndex, int cost)
|
||||
{
|
||||
PathIndex = pathIndex;
|
||||
Cost = cost;
|
||||
}
|
||||
|
||||
public uint PathIndex;
|
||||
public int Cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,764 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using Game.AI;
|
||||
using Game.DataStorage;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class MotionMaster
|
||||
{
|
||||
public const double gravity = 19.29110527038574;
|
||||
public const float SPEED_CHARGE = 42.0f;
|
||||
IdleMovementGenerator staticIdleMovement = new IdleMovementGenerator();
|
||||
|
||||
public MotionMaster(Unit me)
|
||||
{
|
||||
_owner = me;
|
||||
_expList = null;
|
||||
_top = -1;
|
||||
_cleanFlag = MMCleanFlag.None;
|
||||
|
||||
for (byte i = 0; i < (int)MovementSlot.Max; ++i)
|
||||
{
|
||||
Impl[i] = null;
|
||||
_needInit[i] = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool isStatic(IMovementGenerator mv)
|
||||
{
|
||||
return (mv == staticIdleMovement);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
while (!empty())
|
||||
{
|
||||
IMovementGenerator curr = top();
|
||||
pop();
|
||||
if (curr != null)
|
||||
DirectDelete(curr);
|
||||
}
|
||||
|
||||
InitDefault();
|
||||
}
|
||||
|
||||
public void InitDefault()
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Unit))
|
||||
{
|
||||
IMovementGenerator movement = AISelector.SelectMovementAI(_owner.ToCreature());
|
||||
StartMovement(movement ?? staticIdleMovement, MovementSlot.Idle);
|
||||
}
|
||||
else
|
||||
StartMovement(staticIdleMovement, MovementSlot.Idle);
|
||||
}
|
||||
|
||||
public virtual void UpdateMotion(uint diff)
|
||||
{
|
||||
if (!_owner)
|
||||
return;
|
||||
|
||||
if (_owner.HasUnitState(UnitState.Root | UnitState.Stunned))
|
||||
return;
|
||||
|
||||
Contract.Assert(!empty());
|
||||
|
||||
_cleanFlag |= MMCleanFlag.Update;
|
||||
if (!top().Update(_owner, diff))
|
||||
{
|
||||
_cleanFlag &= ~MMCleanFlag.Update;
|
||||
MovementExpired();
|
||||
}
|
||||
else
|
||||
_cleanFlag &= ~MMCleanFlag.Update;
|
||||
|
||||
if (_expList != null)
|
||||
{
|
||||
for (int i = 0; i < _expList.Count; ++i)
|
||||
{
|
||||
IMovementGenerator mg = _expList[i];
|
||||
DirectDelete(mg);
|
||||
}
|
||||
|
||||
_expList = null;
|
||||
|
||||
if (empty())
|
||||
Initialize();
|
||||
else if (needInitTop())
|
||||
InitTop();
|
||||
else if (Convert.ToBoolean(_cleanFlag & MMCleanFlag.Reset))
|
||||
top().Reset(_owner);
|
||||
|
||||
_cleanFlag &= ~MMCleanFlag.Reset;
|
||||
}
|
||||
|
||||
_owner.UpdateUnderwaterState(_owner.GetMap(), _owner.GetPositionX(), _owner.GetPositionY(), _owner.GetPositionZ());
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public void MoveIdle()
|
||||
{
|
||||
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);
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Unit) && _owner.ToCreature().GetCharmerOrOwnerGUID().IsEmpty())
|
||||
{
|
||||
StartMovement(new HomeMovementGenerator<Creature>(), MovementSlot.Active);
|
||||
}
|
||||
else if (_owner.IsTypeId(TypeId.Unit) && !_owner.ToCreature().GetCharmerOrOwnerGUID().IsEmpty())
|
||||
{
|
||||
Unit target = _owner.ToCreature().GetCharmerOrOwner();
|
||||
if (target)
|
||||
StartMovement(new FollowMovementGenerator<Creature>(target, SharedConst.PetFollowDist, SharedConst.PetFollowAngle), MovementSlot.Active);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveConfused()
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new ConfusedGenerator<Player>(), MovementSlot.Controlled);
|
||||
else
|
||||
StartMovement(new ConfusedGenerator<Creature>(), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
public void MoveChase(Unit target, float dist = 0.0f, float angle = 0.0f)
|
||||
{
|
||||
if (!target || target == _owner)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new ChaseMovementGenerator<Player>(target, dist, angle), MovementSlot.Active);
|
||||
else
|
||||
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)
|
||||
{
|
||||
if (!target || target == _owner)
|
||||
return;
|
||||
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new FollowMovementGenerator<Player>(target, dist, angle), slot);
|
||||
else
|
||||
StartMovement(new FollowMovementGenerator<Creature>(target, dist, angle), slot);
|
||||
}
|
||||
|
||||
public void MovePoint(ulong id, float x, float y, float z, bool generatePath = true)
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
StartMovement(new PointMovementGenerator<Player>(id, x, y, z, generatePath), MovementSlot.Active);
|
||||
else
|
||||
StartMovement(new PointMovementGenerator<Creature>(id, x, y, z, generatePath), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MovePoint(uint id, Position pos, bool generatePath = true)
|
||||
{
|
||||
MovePoint(id, pos.posX, pos.posY, pos.posZ, generatePath);
|
||||
}
|
||||
|
||||
public void MoveLand(uint id, Position pos)
|
||||
{
|
||||
float x, y, z;
|
||||
pos.GetPosition(out x, out y, out z);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MoveTo(x, y, z);
|
||||
init.SetAnimation(AnimType.ToGround);
|
||||
init.Launch();
|
||||
StartMovement(new EffectMovementGenerator(id), MovementSlot.Active);
|
||||
}
|
||||
|
||||
void MoveTakeoff(uint id, Position pos)
|
||||
{
|
||||
float x, y, z;
|
||||
pos.GetPosition(out x, out y, out z);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MoveTo(x, y, z);
|
||||
init.SetAnimation(AnimType.ToFly);
|
||||
init.Launch();
|
||||
StartMovement(new EffectMovementGenerator(id), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MoveKnockbackFrom(float srcX, float srcY, float speedXY, float speedZ, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
//this function may make players fall below map
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
float moveTimeHalf = (float)(speedZ / gravity);
|
||||
float dist = 2 * moveTimeHalf * speedXY;
|
||||
float max_height = -MoveSpline.computeFallElevation(moveTimeHalf, false, -speedZ);
|
||||
|
||||
_owner.GetNearPoint(_owner, out x, out y, out z, _owner.GetObjectSize(), dist, _owner.GetAngle(srcX, srcY) + MathFunctions.PI);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MoveTo(x, y, z);
|
||||
init.SetParabolic(max_height, 0);
|
||||
init.SetOrientationFixed(true);
|
||||
init.SetVelocity(speedXY);
|
||||
if (spellEffectExtraData != null)
|
||||
init.SetSpellEffectExtraData(spellEffectExtraData);
|
||||
|
||||
init.Launch();
|
||||
StartMovement(new EffectMovementGenerator(0), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
public void MoveJumpTo(float angle, float speedXY, float speedZ)
|
||||
{
|
||||
//this function may make players fall below map
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
return;
|
||||
|
||||
float x, y, z;
|
||||
|
||||
float moveTimeHalf = (float)(speedZ / gravity);
|
||||
float dist = 2 * moveTimeHalf * speedXY;
|
||||
_owner.GetClosePoint(out x, out y, out z, _owner.GetObjectSize(), dist, angle);
|
||||
MoveJump(x, y, z, 0.0f, speedXY, speedZ);
|
||||
}
|
||||
|
||||
public void MoveJump(Position pos, float speedXY, float speedZ, uint id = EventId.Jump, bool hasOrientation = false, JumpArrivalCastArgs arrivalCast = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
MoveJump(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ(), pos.GetOrientation(), speedXY, speedZ, id, hasOrientation, arrivalCast, spellEffectExtraData);
|
||||
}
|
||||
|
||||
public void MoveJump(float x, float y, float z, float o, float speedXY, float speedZ, uint id = EventId.Jump, bool hasOrientation = false,
|
||||
JumpArrivalCastArgs arrivalCast = null, SpellEffectExtraData spellEffectExtraData = null)
|
||||
{
|
||||
Log.outDebug(LogFilter.Server, "Unit ({0}) jump to point (X: {1} Y: {2} Z: {3})", _owner.GetGUID().ToString(), x, y, z);
|
||||
|
||||
float moveTimeHalf = (float)(speedZ / gravity);
|
||||
float max_height = -MoveSpline.computeFallElevation(moveTimeHalf, false, -speedZ);
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MoveTo(x, y, z, false);
|
||||
init.SetParabolic(max_height, 0);
|
||||
init.SetVelocity(speedXY);
|
||||
if (hasOrientation)
|
||||
init.SetFacing(o);
|
||||
if (spellEffectExtraData != null)
|
||||
init.SetSpellEffectExtraData(spellEffectExtraData);
|
||||
init.Launch();
|
||||
|
||||
uint arrivalSpellId = 0;
|
||||
ObjectGuid arrivalSpellTargetGuid = ObjectGuid.Empty;
|
||||
if (arrivalCast != null)
|
||||
{
|
||||
arrivalSpellId = arrivalCast.SpellId;
|
||||
arrivalSpellTargetGuid = arrivalCast.Target;
|
||||
}
|
||||
|
||||
StartMovement(new EffectMovementGenerator(id, arrivalSpellId, arrivalSpellTargetGuid), MovementSlot.Controlled);
|
||||
}
|
||||
|
||||
void MoveCirclePath(float x, float y, float z, float radius, bool clockwise, byte stepCount)
|
||||
{
|
||||
float step = 2 * MathFunctions.PI / stepCount * (clockwise ? -1.0f : 1.0f);
|
||||
Position pos = new Position(x, y, z, 0.0f);
|
||||
float angle = pos.GetAngle(_owner.GetPositionX(), _owner.GetPositionY());
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.args.path = new Vector3[stepCount];
|
||||
for (byte i = 0; i < stepCount; angle += step, ++i)
|
||||
{
|
||||
Vector3 point = new Vector3();
|
||||
point.X = (float)(x + radius * Math.Cos(angle));
|
||||
point.Y = (float)(y + radius * Math.Sin(angle));
|
||||
|
||||
if (_owner.IsFlying())
|
||||
point.Z = z;
|
||||
else
|
||||
point.Z = _owner.GetMap().GetHeight(_owner.GetPhases(), point.X, point.Y, z);
|
||||
|
||||
init.args.path[i] = point;
|
||||
}
|
||||
|
||||
if (_owner.IsFlying())
|
||||
{
|
||||
init.SetFly();
|
||||
init.SetCyclic();
|
||||
init.SetAnimation(AnimType.ToFly);
|
||||
}
|
||||
else
|
||||
{
|
||||
init.SetWalk(true);
|
||||
init.SetCyclic();
|
||||
}
|
||||
|
||||
init.Launch();
|
||||
}
|
||||
|
||||
void MoveSmoothPath(uint pointId, Vector3[] pathPoints, int pathSize, bool walk = false, bool fly = false)
|
||||
{
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
if (fly)
|
||||
{
|
||||
init.SetFly();
|
||||
init.SetUncompressed();
|
||||
init.SetSmooth();
|
||||
}
|
||||
|
||||
init.MovebyPath(pathPoints);
|
||||
init.SetWalk(walk);
|
||||
init.Launch();
|
||||
|
||||
// This code is not correct
|
||||
// EffectMovementGenerator does not affect UNIT_STATE_ROAMING | UNIT_STATE_ROAMING_MOVE
|
||||
// need to call PointMovementGenerator with various pointIds
|
||||
StartMovement(new EffectMovementGenerator(pointId), MovementSlot.Active);
|
||||
//Position pos(pathPoints[pathSize - 1].x, pathPoints[pathSize - 1].y, pathPoints[pathSize - 1].z);
|
||||
//MovePoint(EVENT_CHARGE_PREPATH, pos, false);
|
||||
}
|
||||
|
||||
void MoveAlongSplineChain(uint pointId, uint dbChainId, bool walk)
|
||||
{
|
||||
Creature owner = _owner.ToCreature();
|
||||
if (!owner)
|
||||
{
|
||||
Log.outError(LogFilter.Misc, "MotionMaster.MoveAlongSplineChain: non-creature {0} tried to walk along DB spline chain. Ignoring.", _owner.GetGUID().ToString());
|
||||
return;
|
||||
}
|
||||
List<SplineChainLink> chain = Global.ScriptMgr.GetSplineChain(owner, (byte)dbChainId);
|
||||
if (chain.Empty())
|
||||
{
|
||||
Log.outError(LogFilter.Misc, "MotionMaster.MoveAlongSplineChain: creature with entry {0} tried to walk along non-existing spline chain with DB id {1}.", owner.GetEntry(), dbChainId);
|
||||
return;
|
||||
}
|
||||
MoveAlongSplineChain(pointId, chain, walk);
|
||||
}
|
||||
|
||||
void MoveAlongSplineChain(uint pointId, List<SplineChainLink> chain, bool walk)
|
||||
{
|
||||
StartMovement(new SplineChainMovementGenerator(pointId, chain, walk), MovementSlot.Active);
|
||||
}
|
||||
|
||||
void ResumeSplineChain(SplineChainResumeInfo info)
|
||||
{
|
||||
if (info.Empty())
|
||||
{
|
||||
Log.outError(LogFilter.Movement, "MotionMaster.ResumeSplineChain: unit with entry {0} tried to resume a spline chain from empty info.", _owner.GetEntry());
|
||||
return;
|
||||
}
|
||||
|
||||
StartMovement(new SplineChainMovementGenerator(info), MovementSlot.Active);
|
||||
}
|
||||
|
||||
public void MoveFall(uint id = 0)
|
||||
{
|
||||
// use larger distance for vmap height search than in most other cases
|
||||
float tz = _owner.GetMap().GetHeight(_owner.GetPhases(), _owner.GetPositionX(), _owner.GetPositionY(), _owner.GetPositionZ(), true, MapConst.MaxFallDistance);
|
||||
if (tz <= MapConst.InvalidHeight)
|
||||
return;
|
||||
|
||||
// Abort too if the ground is very near
|
||||
if (Math.Abs(_owner.GetPositionZ() - tz) < 0.1f)
|
||||
return;
|
||||
|
||||
_owner.SetFall(true);
|
||||
|
||||
// don't run spline movement for players
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
return;
|
||||
|
||||
MoveSplineInit init = new MoveSplineInit(_owner);
|
||||
init.MoveTo(_owner.GetPositionX(), _owner.GetPositionY(), tz, false);
|
||||
init.SetFall();
|
||||
init.Launch();
|
||||
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))
|
||||
Log.outError(LogFilter.Server, "Player {0} attempt to seek assistance", _owner.GetGUID().ToString());
|
||||
else
|
||||
{
|
||||
_owner.AttackStop();
|
||||
_owner.CastStop();
|
||||
_owner.ToCreature().SetReactState(ReactStates.Passive);
|
||||
StartMovement(new AssistanceMovementGenerator(x, y, z), MovementSlot.Active);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveSeekAssistanceDistract(uint time)
|
||||
{
|
||||
if (_owner.IsTypeId(TypeId.Player))
|
||||
Log.outError(LogFilter.Server, "Player {0} attempt to call distract after assistance", _owner.GetGUID().ToString());
|
||||
else
|
||||
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))
|
||||
{
|
||||
if (path < CliDB.TaxiPathNodesByPath.Count)
|
||||
{
|
||||
Log.outDebug(LogFilter.Server, "{0} taxi to (Path {1} node {2})", _owner.GetName(), path, pathnode);
|
||||
FlightPathMovementGenerator mgen = new FlightPathMovementGenerator();
|
||||
mgen.LoadPath(_owner.ToPlayer());
|
||||
StartMovement(mgen, MovementSlot.Controlled);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outDebug(LogFilter.Server, "{0} attempt taxi to (not existed Path {1} node {2})",
|
||||
_owner.GetName(), path, pathnode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.outDebug(LogFilter.Server, "Creature (Entry: {0} GUID: {1}) attempt taxi to (Path {2} node {3})",
|
||||
_owner.GetEntry(), _owner.GetGUID().ToString(), path, pathnode);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveDistract(uint timer)
|
||||
{
|
||||
if (Impl[(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);
|
||||
}
|
||||
|
||||
void MoveRotate(uint time, RotateDirection direction)
|
||||
{
|
||||
if (time == 0)
|
||||
return;
|
||||
|
||||
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()
|
||||
{
|
||||
if (empty())
|
||||
return MovementGeneratorType.Idle;
|
||||
|
||||
return top().GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
public MovementGeneratorType GetMotionSlotType(MovementSlot slot)
|
||||
{
|
||||
if (Impl[(int)slot] == null)
|
||||
return MovementGeneratorType.Null;
|
||||
else
|
||||
return Impl[(int)slot].GetMovementGeneratorType();
|
||||
}
|
||||
|
||||
void InitTop()
|
||||
{
|
||||
top().Initialize(_owner);
|
||||
_needInit[_top] = false;
|
||||
}
|
||||
|
||||
void DirectDelete(IMovementGenerator curr)
|
||||
{
|
||||
if (isStatic(curr))
|
||||
return;
|
||||
curr.Finalize(_owner);
|
||||
}
|
||||
|
||||
void DelayedDelete(IMovementGenerator 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];
|
||||
}
|
||||
|
||||
public bool empty() { return (_top < 0); }
|
||||
|
||||
int size() { return _top + 1; }
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
public static uint SplineId
|
||||
{
|
||||
get { return splineId++; }
|
||||
}
|
||||
|
||||
static uint splineId = 0;
|
||||
|
||||
public Unit _owner { get; private set; }
|
||||
protected IMovementGenerator[] Impl = new IMovementGenerator[(int)MovementSlot.Max];
|
||||
MMCleanFlag _cleanFlag;
|
||||
bool[] _needInit = new bool[(int)MovementSlot.Max];
|
||||
int _top;
|
||||
List<IMovementGenerator> _expList = new List<IMovementGenerator>();
|
||||
}
|
||||
|
||||
public class JumpArrivalCastArgs
|
||||
{
|
||||
public uint SpellId;
|
||||
public ObjectGuid Target;
|
||||
}
|
||||
|
||||
enum MMCleanFlag
|
||||
{
|
||||
None = 0,
|
||||
Update = 1, // Clear or Expire called from update
|
||||
Reset = 2 // Flag if need top().Reset()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,421 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.Dynamic;
|
||||
using Framework.GameMath;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class MoveSpline
|
||||
{
|
||||
public MoveSpline()
|
||||
{
|
||||
m_Id = 0;
|
||||
time_passed = 0;
|
||||
vertical_acceleration = 0.0f;
|
||||
initialOrientation = 0.0f;
|
||||
effect_start_time = 0;
|
||||
point_Idx = 0;
|
||||
point_Idx_offset = 0;
|
||||
onTransport = false;
|
||||
splineIsFacingOnly = false;
|
||||
splineflags.Flags = SplineFlag.Done;
|
||||
}
|
||||
|
||||
public void Initialize(MoveSplineInitArgs args)
|
||||
{
|
||||
splineflags = args.flags;
|
||||
facing = args.facing;
|
||||
m_Id = args.splineId;
|
||||
point_Idx_offset = args.path_Idx_offset;
|
||||
initialOrientation = args.initialOrientation;
|
||||
|
||||
time_passed = 0;
|
||||
vertical_acceleration = 0.0f;
|
||||
effect_start_time = 0;
|
||||
spell_effect_extra = args.spellEffectExtra;
|
||||
splineIsFacingOnly = args.path.Length == 2 && args.facing.type != MonsterMoveType.Normal && ((args.path[1] - args.path[0]).GetLength() < 0.1f);
|
||||
|
||||
// Check if its a stop spline
|
||||
if (args.flags.hasFlag(SplineFlag.Done))
|
||||
{
|
||||
spline.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
init_spline(args);
|
||||
|
||||
// init parabolic / animation
|
||||
// spline initialized, duration known and i able to compute parabolic acceleration
|
||||
if (args.flags.hasFlag(SplineFlag.Parabolic | SplineFlag.Animation | SplineFlag.FadeObject))
|
||||
{
|
||||
effect_start_time = (int)(Duration() * args.time_perc);
|
||||
if (args.flags.hasFlag(SplineFlag.Parabolic) && effect_start_time < Duration())
|
||||
{
|
||||
float f_duration = (float)TimeSpan.FromMilliseconds(Duration() - effect_start_time).TotalSeconds;
|
||||
vertical_acceleration = args.parabolic_amplitude * 8.0f / (f_duration * f_duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void init_spline(MoveSplineInitArgs args)
|
||||
{
|
||||
Spline.EvaluationMode[] modes = new Spline.EvaluationMode[2] { Spline.EvaluationMode.Linear, Spline.EvaluationMode.Catmullrom };
|
||||
if (args.flags.hasFlag(SplineFlag.Cyclic))
|
||||
{
|
||||
spline.init_cyclic_spline(args.path, args.path.Length, modes[Convert.ToInt32(args.flags.isSmooth())], 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
spline.Init_Spline(args.path, args.path.Length, modes[Convert.ToInt32(args.flags.isSmooth())]);
|
||||
}
|
||||
|
||||
// init spline timestamps
|
||||
if (splineflags.hasFlag(SplineFlag.Falling))
|
||||
{
|
||||
FallInitializer init = new FallInitializer(spline.getPoint(spline.first()).Z);
|
||||
spline.initLengths(init);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommonInitializer init = new CommonInitializer(args.velocity);
|
||||
spline.initLengths(init);
|
||||
}
|
||||
|
||||
// TODO: what to do in such cases? problem is in input data (all points are at same coords)
|
||||
if (spline.length() < 1)
|
||||
{
|
||||
Log.outError(LogFilter.Unit, "MoveSpline.init_spline: zero length spline, wrong input data?");
|
||||
spline.set_length(spline.last(), spline.isCyclic() ? 1000 : 1);
|
||||
}
|
||||
point_Idx = spline.first();
|
||||
}
|
||||
|
||||
public int currentPathIdx()
|
||||
{
|
||||
int point = point_Idx_offset + point_Idx - spline.first() + (Finalized() ? 1 : 0);
|
||||
if (isCyclic())
|
||||
point = point % (spline.last() - spline.first());
|
||||
return point;
|
||||
}
|
||||
|
||||
public Vector3[] getPath() { return spline.getPoints(); }
|
||||
public int timePassed() { return time_passed; }
|
||||
|
||||
public int Duration() { return spline.length(); }
|
||||
public int _currentSplineIdx() { return point_Idx; }
|
||||
public uint GetId() { return m_Id; }
|
||||
public bool Finalized() { return splineflags.hasFlag(SplineFlag.Done); }
|
||||
void _Finalize()
|
||||
{
|
||||
splineflags.SetUnsetFlag(SplineFlag.Done);
|
||||
point_Idx = spline.last() - 1;
|
||||
time_passed = Duration();
|
||||
}
|
||||
public Vector4 computePosition(int time_point, int point_index)
|
||||
{
|
||||
float u = 1.0f;
|
||||
int seg_time = spline.length(point_index, point_index + 1);
|
||||
if (seg_time > 0)
|
||||
u = (time_point - spline.length(point_index)) / (float)seg_time;
|
||||
|
||||
Vector3 c;
|
||||
float orientation = initialOrientation;
|
||||
spline.Evaluate_Percent(point_index, u, out c);
|
||||
|
||||
if (splineflags.hasFlag(SplineFlag.Parabolic))
|
||||
computeParabolicElevation(time_point, ref c.Z);
|
||||
else if (splineflags.hasFlag(SplineFlag.Falling))
|
||||
computeFallElevation(time_point, ref c.Z);
|
||||
|
||||
if (splineflags.hasFlag(SplineFlag.Done) && facing.type != MonsterMoveType.Normal)
|
||||
{
|
||||
if (facing.type == MonsterMoveType.FacingAngle)
|
||||
orientation = facing.angle;
|
||||
else if (facing.type == MonsterMoveType.FacingSpot)
|
||||
orientation = (float)Math.Atan2(facing.f.Y - c.Y, facing.f.X - c.X);
|
||||
//nothing to do for MoveSplineFlag.Final_Target flag
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!splineflags.hasFlag(SplineFlag.OrientationFixed | SplineFlag.Falling | SplineFlag.Unknown0))
|
||||
{
|
||||
Vector3 hermite;
|
||||
spline.Evaluate_Derivative(point_Idx, u, out hermite);
|
||||
orientation = (float)Math.Atan2(hermite.Y, hermite.X);
|
||||
}
|
||||
|
||||
if (splineflags.hasFlag(SplineFlag.Backward))
|
||||
orientation = orientation - (float)Math.PI;
|
||||
}
|
||||
|
||||
return new Vector4(c.X, c.Y, c.Z, orientation);
|
||||
}
|
||||
public Vector4 ComputePosition()
|
||||
{
|
||||
return computePosition(time_passed, point_Idx);
|
||||
}
|
||||
public Vector4 ComputePosition(int time_offset)
|
||||
{
|
||||
int time_point = time_passed + time_offset;
|
||||
if (time_point >= Duration())
|
||||
return computePosition(Duration(), spline.last() - 1);
|
||||
if (time_point <= 0)
|
||||
return computePosition(0, spline.first());
|
||||
|
||||
// find point_index where spline.length(point_index) < time_point < spline.length(point_index + 1)
|
||||
int point_index = point_Idx;
|
||||
while (time_point >= spline.length(point_index + 1))
|
||||
++point_index;
|
||||
|
||||
while (time_point < spline.length(point_index))
|
||||
--point_index;
|
||||
|
||||
return computePosition(time_point, point_index);
|
||||
}
|
||||
public void computeParabolicElevation(int time_point, ref float el)
|
||||
{
|
||||
if (time_point > effect_start_time)
|
||||
{
|
||||
float t_passedf = MSToSec((uint)(time_point - effect_start_time));
|
||||
float t_durationf = MSToSec((uint)(Duration() - effect_start_time)); //client use not modified duration here
|
||||
if (spell_effect_extra.HasValue && spell_effect_extra.Value.ParabolicCurveId != 0)
|
||||
t_passedf *= Global.DB2Mgr.GetCurveValueAt(spell_effect_extra.Value.ParabolicCurveId, time_point / Duration());
|
||||
|
||||
el += (t_durationf - t_passedf) * 0.5f * vertical_acceleration * t_passedf;
|
||||
}
|
||||
}
|
||||
public void computeFallElevation(int time_point, ref float el)
|
||||
{
|
||||
float z_now = spline.getPoint(spline.first()).Z - computeFallElevation(MSToSec((uint)time_point), false);
|
||||
float final_z = FinalDestination().Z;
|
||||
el = Math.Max(z_now, final_z);
|
||||
}
|
||||
public static float computeFallElevation(float t_passed, bool isSafeFall, float start_velocity = 0.0f)
|
||||
{
|
||||
float termVel;
|
||||
float result;
|
||||
|
||||
if (isSafeFall)
|
||||
termVel = SharedConst.terminalSafefallVelocity;
|
||||
else
|
||||
termVel = SharedConst.terminalVelocity;
|
||||
|
||||
if (start_velocity > termVel)
|
||||
start_velocity = termVel;
|
||||
|
||||
float terminal_time = (float)((isSafeFall ? SharedConst.terminal_safeFall_fallTime : SharedConst.terminal_fallTime) - start_velocity / SharedConst.gravity); // the time that needed to reach terminalVelocity
|
||||
|
||||
if (t_passed > terminal_time)
|
||||
{
|
||||
result = termVel * (t_passed - terminal_time) +
|
||||
start_velocity * terminal_time +
|
||||
(float)SharedConst.gravity * terminal_time * terminal_time * 0.5f;
|
||||
}
|
||||
else
|
||||
result = t_passed * (float)(start_velocity + t_passed * SharedConst.gravity * 0.5f);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
float MSToSec(uint ms)
|
||||
{
|
||||
return ms / 1000.0f;
|
||||
}
|
||||
|
||||
public void Interrupt() { splineflags.SetUnsetFlag(SplineFlag.Done); }
|
||||
public void updateState(int difftime)
|
||||
{
|
||||
do
|
||||
{
|
||||
_updateState(ref difftime);
|
||||
} while (difftime > 0);
|
||||
}
|
||||
UpdateResult _updateState(ref int ms_time_diff)
|
||||
{
|
||||
if (Finalized())
|
||||
{
|
||||
ms_time_diff = 0;
|
||||
return UpdateResult.Arrived;
|
||||
}
|
||||
|
||||
UpdateResult result = UpdateResult.None;
|
||||
int minimal_diff = Math.Min(ms_time_diff, segment_time_elapsed());
|
||||
time_passed += minimal_diff;
|
||||
ms_time_diff -= minimal_diff;
|
||||
|
||||
if (time_passed >= next_timestamp())
|
||||
{
|
||||
++point_Idx;
|
||||
if (point_Idx < spline.last())
|
||||
{
|
||||
result = UpdateResult.NextSegment;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (spline.isCyclic())
|
||||
{
|
||||
point_Idx = spline.first();
|
||||
time_passed = time_passed % Duration();
|
||||
result = UpdateResult.NextCycle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_Finalize();
|
||||
ms_time_diff = 0;
|
||||
result = UpdateResult.Arrived;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
int next_timestamp() { return spline.length(point_Idx + 1); }
|
||||
int segment_time_elapsed() { return next_timestamp() - time_passed; }
|
||||
public bool isCyclic() { return splineflags.hasFlag(SplineFlag.Cyclic); }
|
||||
public bool isFalling() { return splineflags.hasFlag(SplineFlag.Falling); }
|
||||
public bool Initialized() { return !spline.empty(); }
|
||||
public Vector3 FinalDestination() { return Initialized() ? spline.getPoint(spline.last()) : new Vector3(); }
|
||||
|
||||
#region Fields
|
||||
public MoveSplineInitArgs InitArgs;
|
||||
public Spline spline = new Spline();
|
||||
public FacingInfo facing;
|
||||
public MoveSplineFlag splineflags = new MoveSplineFlag();
|
||||
public bool onTransport;
|
||||
public bool splineIsFacingOnly;
|
||||
public uint m_Id;
|
||||
public int time_passed;
|
||||
public float vertical_acceleration;
|
||||
public float initialOrientation;
|
||||
public int effect_start_time;
|
||||
public int point_Idx;
|
||||
public int point_Idx_offset;
|
||||
public Optional<SpellEffectExtraData> spell_effect_extra;
|
||||
#endregion
|
||||
|
||||
public class CommonInitializer : Initializer
|
||||
{
|
||||
public CommonInitializer(float _velocity)
|
||||
{
|
||||
velocityInv = 1000f / _velocity;
|
||||
time = 1;
|
||||
}
|
||||
public float velocityInv;
|
||||
public int time;
|
||||
public int SetGetTime(Spline s, int i)
|
||||
{
|
||||
time += (int)(s.SegLength(i) * velocityInv);
|
||||
return time;
|
||||
}
|
||||
}
|
||||
public class FallInitializer : Initializer
|
||||
{
|
||||
public FallInitializer(float startelevation)
|
||||
{
|
||||
startElevation = startelevation;
|
||||
}
|
||||
float startElevation;
|
||||
public int SetGetTime(Spline s, int i)
|
||||
{
|
||||
return (int)(computeFallTime(startElevation - s.getPoint(i + 1).Z, false) * 1000.0f);
|
||||
}
|
||||
|
||||
float computeFallTime(float path_length, bool isSafeFall)
|
||||
{
|
||||
if (path_length < 0.0f)
|
||||
return 0.0f;
|
||||
|
||||
float time;
|
||||
if (isSafeFall)
|
||||
{
|
||||
if (path_length >= SharedConst.terminal_safeFall_length)
|
||||
time = (path_length - SharedConst.terminal_safeFall_length) / SharedConst.terminalSafefallVelocity + SharedConst.terminal_safeFall_fallTime;
|
||||
else
|
||||
time = (float)Math.Sqrt(2.0f * path_length / SharedConst.gravity);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (path_length >= SharedConst.terminal_length)
|
||||
time = (path_length - SharedConst.terminal_length) / SharedConst.terminalVelocity + SharedConst.terminal_fallTime;
|
||||
else
|
||||
time = (float)Math.Sqrt(2.0f * path_length / SharedConst.gravity);
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
}
|
||||
public enum UpdateResult
|
||||
{
|
||||
None = 0x01,
|
||||
Arrived = 0x02,
|
||||
NextCycle = 0x04,
|
||||
NextSegment = 0x08
|
||||
}
|
||||
}
|
||||
public interface Initializer
|
||||
{
|
||||
int SetGetTime(Spline s, int i);
|
||||
}
|
||||
|
||||
public class SplineChainLink
|
||||
{
|
||||
public SplineChainLink(Vector3[] points, uint expectedDuration, uint msToNext)
|
||||
{
|
||||
Points.AddRange(points);
|
||||
ExpectedDuration = expectedDuration;
|
||||
TimeToNext = msToNext;
|
||||
}
|
||||
|
||||
public SplineChainLink(uint expectedDuration, uint msToNext)
|
||||
{
|
||||
ExpectedDuration = expectedDuration;
|
||||
TimeToNext = msToNext;
|
||||
}
|
||||
|
||||
public List<Vector3> Points = new List<Vector3>();
|
||||
public uint ExpectedDuration;
|
||||
public uint TimeToNext;
|
||||
}
|
||||
|
||||
public class SplineChainResumeInfo
|
||||
{
|
||||
public SplineChainResumeInfo() { }
|
||||
public SplineChainResumeInfo(uint id, List<SplineChainLink> chain, bool walk, byte splineIndex, byte wpIndex, uint msToNext)
|
||||
{
|
||||
PointID = id;
|
||||
Chain = chain;
|
||||
IsWalkMode = walk;
|
||||
SplineIndex = splineIndex;
|
||||
PointIndex = wpIndex;
|
||||
TimeToNext = msToNext;
|
||||
}
|
||||
|
||||
public bool Empty() { return Chain.Empty(); }
|
||||
public void Clear() { Chain.Clear(); }
|
||||
|
||||
public uint PointID;
|
||||
public List<SplineChainLink> Chain = new List<SplineChainLink>();
|
||||
public bool IsWalkMode;
|
||||
public byte SplineIndex;
|
||||
public byte PointIndex;
|
||||
public uint TimeToNext;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class MoveSplineFlag
|
||||
{
|
||||
public MoveSplineFlag() { }
|
||||
public MoveSplineFlag(SplineFlag f) { Flags = f; }
|
||||
public MoveSplineFlag(MoveSplineFlag f) { Flags = f.Flags; }
|
||||
|
||||
public bool isSmooth() { return Flags.HasAnyFlag(SplineFlag.Catmullrom); }
|
||||
public bool isLinear() { return !isSmooth(); }
|
||||
|
||||
public byte getAnimationId() { return animId; }
|
||||
public bool hasAllFlags(SplineFlag f) { return (Flags & f) == f; }
|
||||
public bool hasFlag(SplineFlag f) { return (Flags & f) != 0; }
|
||||
|
||||
public void SetUnsetFlag(SplineFlag f, bool Set = true)
|
||||
{
|
||||
if (Set)
|
||||
Flags |= f;
|
||||
else
|
||||
Flags &= ~f;
|
||||
}
|
||||
|
||||
public void EnableAnimation(uint anim) { Flags = (Flags & ~(SplineFlag.MaskAnimations | SplineFlag.Falling | SplineFlag.Parabolic | SplineFlag.FallingSlow | SplineFlag.FadeObject)) | SplineFlag.Animation | ((SplineFlag)anim & SplineFlag.MaskAnimations); }
|
||||
public void EnableParabolic() { Flags = (Flags & ~(SplineFlag.MaskAnimations | SplineFlag.Falling | SplineFlag.Animation | SplineFlag.FallingSlow | SplineFlag.FadeObject)) | SplineFlag.Parabolic; }
|
||||
public void EnableFlying() { Flags = (Flags & ~SplineFlag.Falling) | SplineFlag.Flying; }
|
||||
public void EnableFalling() { Flags = (Flags & ~(SplineFlag.MaskAnimations | SplineFlag.Parabolic | SplineFlag.Animation | SplineFlag.Flying)) | SplineFlag.Falling; }
|
||||
public void EnableCatmullRom() { Flags = (Flags & ~SplineFlag.SmoothGroundPath) | SplineFlag.Catmullrom; }
|
||||
public void EnableTransportEnter() { Flags = (Flags & ~SplineFlag.TransportExit) | SplineFlag.TransportEnter; }
|
||||
public void EnableTransportExit() { Flags = (Flags & ~SplineFlag.TransportEnter) | SplineFlag.TransportExit; }
|
||||
|
||||
public SplineFlag Flags;
|
||||
public byte animId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using Game.Entities;
|
||||
using Game.Network.Packets;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class MoveSplineInit
|
||||
{
|
||||
public MoveSplineInit(Unit m)
|
||||
{
|
||||
unit = m;
|
||||
args.splineId = MotionMaster.SplineId;
|
||||
|
||||
// Elevators also use MOVEMENTFLAG_ONTRANSPORT but we do not keep track of their position changes
|
||||
args.TransformForTransport = !unit.GetTransGUID().IsEmpty();
|
||||
// mix existing state into new
|
||||
args.flags.SetUnsetFlag(SplineFlag.CanSwim, unit.CanSwim());
|
||||
args.walk = unit.HasUnitMovementFlag(MovementFlag.Walking);
|
||||
args.flags.SetUnsetFlag(SplineFlag.Flying, unit.HasUnitMovementFlag(MovementFlag.CanFly | MovementFlag.DisableGravity));
|
||||
args.flags.SetUnsetFlag(SplineFlag.SmoothGroundPath, true); // enabled by default, CatmullRom mode or client config "pathSmoothing" will disable this
|
||||
args.flags.SetUnsetFlag(SplineFlag.Steering, unit.HasFlag64(UnitFields.NpcFlags, NPCFlags.Steering));
|
||||
}
|
||||
|
||||
UnitMoveType SelectSpeedType(MovementFlag moveFlags)
|
||||
{
|
||||
if (Convert.ToBoolean(moveFlags & (MovementFlag.Flying | MovementFlag.CanFly | MovementFlag.DisableGravity)))
|
||||
{
|
||||
if (Convert.ToBoolean(moveFlags & MovementFlag.Backward))
|
||||
return UnitMoveType.FlightBack;
|
||||
else
|
||||
return UnitMoveType.Flight;
|
||||
}
|
||||
else if (Convert.ToBoolean(moveFlags & MovementFlag.Swimming))
|
||||
{
|
||||
if (Convert.ToBoolean(moveFlags & MovementFlag.Backward))
|
||||
return UnitMoveType.SwimBack;
|
||||
else
|
||||
return UnitMoveType.Swim;
|
||||
}
|
||||
else if (Convert.ToBoolean(moveFlags & MovementFlag.Walking))
|
||||
{
|
||||
return UnitMoveType.Walk;
|
||||
}
|
||||
else if (Convert.ToBoolean(moveFlags & MovementFlag.Backward))
|
||||
return UnitMoveType.RunBack;
|
||||
|
||||
// Flying creatures use MOVEMENTFLAG_CAN_FLY or MOVEMENTFLAG_DISABLE_GRAVITY
|
||||
// Run speed is their default flight speed.
|
||||
return UnitMoveType.Run;
|
||||
}
|
||||
|
||||
public int Launch()
|
||||
{
|
||||
MoveSpline move_spline = unit.moveSpline;
|
||||
|
||||
bool transport = !unit.GetTransGUID().IsEmpty();
|
||||
Vector4 real_position = new Vector4();
|
||||
// there is a big chance that current position is unknown if current state is not finalized, need compute it
|
||||
// this also allows calculate spline position and update map position in much greater intervals
|
||||
// Don't compute for transport movement if the unit is in a motion between two transports
|
||||
if (!move_spline.Finalized() && move_spline.onTransport == transport)
|
||||
real_position = move_spline.ComputePosition();
|
||||
else
|
||||
{
|
||||
Position pos;
|
||||
if (!transport)
|
||||
pos = unit;
|
||||
else
|
||||
pos = unit.m_movementInfo.transport.pos;
|
||||
|
||||
real_position.X = pos.GetPositionX();
|
||||
real_position.Y = pos.GetPositionY();
|
||||
real_position.Z = pos.GetPositionZ();
|
||||
real_position.W = unit.GetOrientation();
|
||||
}
|
||||
|
||||
// should i do the things that user should do? - no.
|
||||
if (args.path.Length == 0)
|
||||
return 0;
|
||||
|
||||
// correct first vertex
|
||||
args.path[0] = new Vector3(real_position.X, real_position.Y, real_position.Z);
|
||||
args.initialOrientation = real_position.W;
|
||||
move_spline.onTransport = !unit.GetTransGUID().IsEmpty();
|
||||
|
||||
MovementFlag moveFlags = unit.m_movementInfo.GetMovementFlags();
|
||||
if (!args.flags.hasFlag(SplineFlag.Backward))
|
||||
moveFlags = (moveFlags & ~MovementFlag.Backward) | MovementFlag.Forward;
|
||||
else
|
||||
moveFlags = (moveFlags & ~MovementFlag.Forward) | MovementFlag.Backward;
|
||||
|
||||
if (Convert.ToBoolean(moveFlags & MovementFlag.Root))
|
||||
moveFlags &= ~MovementFlag.MaskMoving;
|
||||
|
||||
if (!args.HasVelocity)
|
||||
{
|
||||
// If spline is initialized with SetWalk method it only means we need to select
|
||||
// walk move speed for it but not add walk flag to unit
|
||||
var moveFlagsForSpeed = moveFlags;
|
||||
if (args.walk)
|
||||
moveFlagsForSpeed |= MovementFlag.Walking;
|
||||
else
|
||||
moveFlagsForSpeed &= ~MovementFlag.Walking;
|
||||
|
||||
args.velocity = unit.GetSpeed(SelectSpeedType(moveFlagsForSpeed));
|
||||
}
|
||||
|
||||
if (!args.Validate(unit))
|
||||
return 0;
|
||||
|
||||
unit.m_movementInfo.SetMovementFlags(moveFlags);
|
||||
move_spline.Initialize(args);
|
||||
|
||||
MonsterMove packet = new MonsterMove();
|
||||
packet.MoverGUID = unit.GetGUID();
|
||||
packet.Pos = new Vector3(real_position.X, real_position.Y, real_position.Z);
|
||||
packet.InitializeSplineData(move_spline);
|
||||
if (transport)
|
||||
{
|
||||
packet.SplineData.Move.TransportGUID = unit.GetTransGUID();
|
||||
packet.SplineData.Move.VehicleSeat = unit.GetTransSeat();
|
||||
}
|
||||
unit.SendMessageToSet(packet, true);
|
||||
|
||||
return move_spline.Duration();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
MoveSpline move_spline = unit.moveSpline;
|
||||
|
||||
// No need to stop if we are not moving
|
||||
if (move_spline.Finalized())
|
||||
return;
|
||||
|
||||
bool transport = !unit.GetTransGUID().IsEmpty();
|
||||
Vector4 loc = new Vector4();
|
||||
if (move_spline.onTransport == transport)
|
||||
loc = move_spline.ComputePosition();
|
||||
else
|
||||
{
|
||||
Position pos;
|
||||
if (!transport)
|
||||
pos = unit;
|
||||
else
|
||||
pos = unit.m_movementInfo.transport.pos;
|
||||
|
||||
loc.X = pos.GetPositionX();
|
||||
loc.Y = pos.GetPositionY();
|
||||
loc.Z = pos.GetPositionZ();
|
||||
loc.W = unit.GetOrientation();
|
||||
}
|
||||
|
||||
args.flags.Flags = SplineFlag.Done;
|
||||
unit.m_movementInfo.RemoveMovementFlag(MovementFlag.Forward);
|
||||
move_spline.onTransport = transport;
|
||||
move_spline.Initialize(args);
|
||||
|
||||
MonsterMove packet = new MonsterMove();
|
||||
packet.MoverGUID = unit.GetGUID();
|
||||
packet.Pos = new Vector3(loc.X, loc.Y, loc.Z);
|
||||
packet.SplineData.StopDistanceTolerance = 2;
|
||||
packet.SplineData.ID = move_spline.GetId();
|
||||
|
||||
if (transport)
|
||||
{
|
||||
packet.SplineData.Move.TransportGUID = unit.GetTransGUID();
|
||||
packet.SplineData.Move.VehicleSeat = unit.GetTransSeat();
|
||||
}
|
||||
|
||||
unit.SendMessageToSet(packet, true);
|
||||
}
|
||||
|
||||
public void SetFacing(Unit target)
|
||||
{
|
||||
args.facing.angle = unit.GetAngle(target);
|
||||
args.facing.target = target.GetGUID();
|
||||
args.facing.type = MonsterMoveType.FacingTarget;
|
||||
}
|
||||
|
||||
public void SetFacing(float angle)
|
||||
{
|
||||
if (args.TransformForTransport)
|
||||
{
|
||||
Unit vehicle = unit.GetVehicleBase();
|
||||
Transport transport = unit.GetTransport();
|
||||
if (vehicle != null)
|
||||
angle -= vehicle.Orientation;
|
||||
else if (transport != null)
|
||||
angle -= transport.Orientation;
|
||||
}
|
||||
|
||||
args.facing.angle = MathFunctions.wrap(angle, 0.0f, MathFunctions.TwoPi);
|
||||
args.facing.type = MonsterMoveType.FacingAngle;
|
||||
}
|
||||
|
||||
public void MoveTo(Vector3 dest, bool generatePath = true, bool forceDestination = false)
|
||||
{
|
||||
if (generatePath)
|
||||
{
|
||||
PathGenerator path = new PathGenerator(unit);
|
||||
bool result = path.CalculatePath(dest.X, dest.Y, dest.Z, forceDestination);
|
||||
if (result && !Convert.ToBoolean(path.GetPathType() & PathType.NoPath))
|
||||
{
|
||||
MovebyPath(path.GetPath());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
args.path_Idx_offset = 0;
|
||||
args.path = new Vector3[2];
|
||||
TransportPathTransform transform = new TransportPathTransform(unit, args.TransformForTransport);
|
||||
args.path[1] = transform.Calc(dest);
|
||||
}
|
||||
|
||||
public void SetFall()
|
||||
{
|
||||
args.flags.EnableFalling();
|
||||
args.flags.SetUnsetFlag(SplineFlag.FallingSlow, unit.HasUnitMovementFlag(MovementFlag.FallingSlow));
|
||||
}
|
||||
|
||||
public void SetFirstPointId(int pointId) { args.path_Idx_offset = pointId; }
|
||||
|
||||
public void SetFly() { args.flags.EnableFlying(); }
|
||||
|
||||
public void SetWalk(bool enable) { args.walk = enable; }
|
||||
|
||||
public void SetSmooth() { args.flags.EnableCatmullRom(); }
|
||||
|
||||
public void SetUncompressed() { args.flags.SetUnsetFlag(SplineFlag.UncompressedPath); }
|
||||
|
||||
public void SetCyclic() { args.flags.SetUnsetFlag(SplineFlag.Cyclic); }
|
||||
|
||||
public void SetVelocity(float vel) { args.velocity = vel; args.HasVelocity = true; }
|
||||
|
||||
void SetBackward() { args.flags.SetUnsetFlag(SplineFlag.Backward); }
|
||||
|
||||
public void SetTransportEnter() { args.flags.EnableTransportEnter(); }
|
||||
|
||||
public void SetTransportExit() { args.flags.EnableTransportExit(); }
|
||||
|
||||
public void SetOrientationFixed(bool enable) { args.flags.SetUnsetFlag(SplineFlag.OrientationFixed, enable); }
|
||||
|
||||
public void MovebyPath(Vector3[] controls, int path_offset = 0)
|
||||
{
|
||||
args.path_Idx_offset = path_offset;
|
||||
args.path = new Vector3[controls.Length];
|
||||
TransportPathTransform transform = new TransportPathTransform(unit, args.TransformForTransport);
|
||||
for (var i = 0; i < controls.Length; i++)
|
||||
args.path[i] = transform.Calc(controls[i]);
|
||||
|
||||
}
|
||||
|
||||
public void MoveTo(float x, float y, float z, bool generatePath = true, bool forceDest = false)
|
||||
{
|
||||
MoveTo(new Vector3(x, y, z), generatePath, forceDest);
|
||||
}
|
||||
|
||||
public void SetParabolic(float amplitude, float time_shift)
|
||||
{
|
||||
args.time_perc = time_shift;
|
||||
args.parabolic_amplitude = amplitude;
|
||||
args.flags.EnableParabolic();
|
||||
}
|
||||
|
||||
public void SetAnimation(AnimType anim)
|
||||
{
|
||||
args.time_perc = 0.0f;
|
||||
args.flags.EnableAnimation((byte)anim);
|
||||
}
|
||||
|
||||
public void SetFacing(Vector3 spot)
|
||||
{
|
||||
TransportPathTransform transform = new TransportPathTransform(unit, args.TransformForTransport);
|
||||
Vector3 finalSpot = transform.Calc(spot);
|
||||
args.facing.f = new Vector3(finalSpot.X, finalSpot.Y, finalSpot.Z);
|
||||
args.facing.type = MonsterMoveType.FacingSpot;
|
||||
}
|
||||
|
||||
public void DisableTransportPathTransformations() { args.TransformForTransport = false; }
|
||||
|
||||
public void SetSpellEffectExtraData(SpellEffectExtraData spellEffectExtraData)
|
||||
{
|
||||
args.spellEffectExtra.Set(spellEffectExtraData);
|
||||
}
|
||||
|
||||
public Vector3[] Path() { return args.path; }
|
||||
|
||||
public MoveSplineInitArgs args = new MoveSplineInitArgs();
|
||||
Unit unit;
|
||||
}
|
||||
|
||||
// Transforms coordinates from global to transport offsets
|
||||
public class TransportPathTransform
|
||||
{
|
||||
public TransportPathTransform(Unit owner, bool transformForTransport)
|
||||
{
|
||||
_owner = owner;
|
||||
_transformForTransport = transformForTransport;
|
||||
}
|
||||
public Vector3 Calc(Vector3 input)
|
||||
{
|
||||
float x = input.X;
|
||||
float y = input.Y;
|
||||
float z = input.Z;
|
||||
if (_transformForTransport)
|
||||
{
|
||||
ITransport transport = _owner.GetDirectTransport();
|
||||
if (transport != null)
|
||||
{
|
||||
float unused = 0.0f; // need reference
|
||||
|
||||
transport.CalculatePassengerOffset(ref x, ref y, ref z, ref unused);
|
||||
}
|
||||
}
|
||||
return new Vector3(x, y, z);
|
||||
}
|
||||
|
||||
Unit _owner;
|
||||
bool _transformForTransport;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Dynamic;
|
||||
using Framework.GameMath;
|
||||
using Game.Entities;
|
||||
using System;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class MoveSplineInitArgs
|
||||
{
|
||||
public MoveSplineInitArgs(int path_capacity = 16)
|
||||
{
|
||||
path_Idx_offset = 0;
|
||||
velocity = 0.0f;
|
||||
parabolic_amplitude = 0.0f;
|
||||
time_perc = 0.0f;
|
||||
splineId = 0;
|
||||
initialOrientation = 0.0f;
|
||||
HasVelocity = false;
|
||||
TransformForTransport = true;
|
||||
path = new Vector3[path_capacity];
|
||||
}
|
||||
|
||||
public Vector3[] path;
|
||||
public FacingInfo facing = new FacingInfo();
|
||||
public MoveSplineFlag flags = new MoveSplineFlag();
|
||||
public int path_Idx_offset;
|
||||
public float velocity;
|
||||
public float parabolic_amplitude;
|
||||
public float time_perc;
|
||||
public uint splineId;
|
||||
public float initialOrientation;
|
||||
public Optional<SpellEffectExtraData> spellEffectExtra;
|
||||
public bool walk;
|
||||
public bool HasVelocity;
|
||||
public bool TransformForTransport;
|
||||
|
||||
// Returns true to show that the arguments were configured correctly and MoveSpline initialization will succeed.
|
||||
public bool Validate(Unit unit)
|
||||
{
|
||||
Func<bool, bool> CHECK = new Func<bool, bool>(exp =>
|
||||
{
|
||||
if (!(exp))
|
||||
{
|
||||
Log.outError(LogFilter.Misc, "MoveSplineInitArgs::Validate: expression '{0}' failed for {1} Entry: {2}", exp.ToString(), unit.GetGUID().ToString(), unit.GetEntry());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (!CHECK(path.Length > 1))
|
||||
return false;
|
||||
if (!CHECK(velocity > 0.01f))
|
||||
return false;
|
||||
if (!CHECK(time_perc >= 0.0f && time_perc <= 1.0f))
|
||||
return false;
|
||||
if (!CHECK(_checkPathLengths()))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool _checkPathLengths()
|
||||
{
|
||||
if (path.Length > 2 || facing.type == Framework.Constants.MonsterMoveType.Normal)
|
||||
for (uint i = 0; i < path.Length - 1; ++i)
|
||||
if ((path[i + 1] - path[i]).GetLength() < 0.1f)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class SpellEffectExtraData
|
||||
{
|
||||
public ObjectGuid Target;
|
||||
public uint SpellVisualId;
|
||||
public uint ProgressCurveId;
|
||||
public uint ParabolicCurveId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,378 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Constants;
|
||||
using Framework.GameMath;
|
||||
using Game.Entities;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Movement
|
||||
{
|
||||
public class Spline
|
||||
{
|
||||
public int getPointCount() { return points.Length; }
|
||||
public Vector3 getPoint(int i) { return points[i]; }
|
||||
public Vector3[] getPoints() { return points; }
|
||||
|
||||
public void clear()
|
||||
{
|
||||
Array.Clear(points, 0, points.Length);
|
||||
}
|
||||
public int first() { return index_lo; }
|
||||
public int last() { return index_hi; }
|
||||
|
||||
public bool isCyclic() { return cyclic;}
|
||||
|
||||
#region Evaluate
|
||||
public void Evaluate_Percent(int Idx, float u, out Vector3 c)
|
||||
{
|
||||
switch (m_mode)
|
||||
{
|
||||
case EvaluationMode.Linear:
|
||||
EvaluateLinear(Idx, u, out c);
|
||||
break;
|
||||
case EvaluationMode.Catmullrom:
|
||||
EvaluateCatmullRom(Idx, u, out c);
|
||||
break;
|
||||
case EvaluationMode.Bezier3_Unused:
|
||||
EvaluateBezier3(Idx, u, out c);
|
||||
break;
|
||||
default:
|
||||
c = new Vector3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
void EvaluateLinear(int index, float u, out Vector3 result)
|
||||
{
|
||||
result = points[index] + (points[index + 1] - points[index]) * u;
|
||||
}
|
||||
void EvaluateCatmullRom(int index, float t, out Vector3 result)
|
||||
{
|
||||
C_Evaluate(points.Skip(index - 1).ToArray(), t, s_catmullRomCoeffs, out result);
|
||||
}
|
||||
void EvaluateBezier3(int index, float t, out Vector3 result)
|
||||
{
|
||||
index *= (int)3u;
|
||||
C_Evaluate(points.Skip(index).ToArray(), t, s_Bezier3Coeffs, out result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Init
|
||||
public void init_spline_custom(SplineRawInitializer initializer)
|
||||
{
|
||||
initializer.Initialize(ref m_mode, ref cyclic, ref points, ref index_lo, ref index_hi);
|
||||
}
|
||||
public void init_cyclic_spline(Vector3[] controls, int count, EvaluationMode m, int cyclic_point)
|
||||
{
|
||||
m_mode = m;
|
||||
cyclic = true;
|
||||
|
||||
Init_Spline(controls, count, m);
|
||||
}
|
||||
public void Init_Spline(Vector3[] controls, int count, EvaluationMode m)
|
||||
{
|
||||
m_mode = m;
|
||||
cyclic = false;
|
||||
|
||||
switch (m_mode)
|
||||
{
|
||||
case EvaluationMode.Linear:
|
||||
case EvaluationMode.Catmullrom:
|
||||
InitCatmullRom(controls, count, cyclic, 0);
|
||||
break;
|
||||
case EvaluationMode.Bezier3_Unused:
|
||||
InitBezier3(controls, count, cyclic, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void InitLinear(Vector3[] controls, int count, bool cyclic, int cyclic_point)
|
||||
{
|
||||
int real_size = count + 1;
|
||||
|
||||
Array.Resize(ref points, real_size);
|
||||
Array.Copy(controls, points, count);
|
||||
|
||||
// first and last two indexes are space for special 'virtual points'
|
||||
// these points are required for proper C_Evaluate and C_Evaluate_Derivative methtod work
|
||||
if (cyclic)
|
||||
points[count] = controls[cyclic_point];
|
||||
else
|
||||
points[count] = controls[count - 1];
|
||||
|
||||
index_lo = 0;
|
||||
index_hi = cyclic ? count : (count - 1);
|
||||
}
|
||||
void InitCatmullRom(Vector3[] controls, int count, bool cyclic, int cyclic_point)
|
||||
{
|
||||
int real_size = count + (cyclic ? (1 + 2) : (1 + 1));
|
||||
|
||||
points = new Vector3[real_size];
|
||||
|
||||
int lo_index = 1;
|
||||
int high_index = lo_index + count - 1;
|
||||
|
||||
Array.Copy(controls, 0, points, lo_index, count);
|
||||
|
||||
// first and last two indexes are space for special 'virtual points'
|
||||
// these points are required for proper C_Evaluate and C_Evaluate_Derivative methtod work
|
||||
if (cyclic)
|
||||
{
|
||||
if (cyclic_point == 0)
|
||||
points[0] = controls[count - 1];
|
||||
else
|
||||
points[0] = controls[0].lerp(controls[1], -1);
|
||||
|
||||
points[high_index + 1] = controls[cyclic_point];
|
||||
points[high_index + 2] = controls[cyclic_point + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
points[0] = controls[0].lerp(controls[1], -1);
|
||||
points[high_index + 1] = controls[count - 1];
|
||||
}
|
||||
|
||||
index_lo = lo_index;
|
||||
index_hi = high_index + (cyclic ? 1 : 0);
|
||||
}
|
||||
void InitBezier3(Vector3[] controls, int count, bool cyclic, int cyclic_point)
|
||||
{
|
||||
int c = (int)(count / 3u * 3u);
|
||||
int t = (int)(c / 3u);
|
||||
|
||||
Array.Resize(ref points, c);
|
||||
Array.Copy(controls, points, c);
|
||||
|
||||
index_lo = 0;
|
||||
index_hi = t - 1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region EvaluateDerivative
|
||||
public void Evaluate_Derivative(int Idx, float u, out Vector3 hermite)
|
||||
{
|
||||
switch (m_mode)
|
||||
{
|
||||
case EvaluationMode.Linear:
|
||||
EvaluateDerivativeLinear(Idx, u, out hermite);
|
||||
break;
|
||||
case EvaluationMode.Catmullrom:
|
||||
EvaluateDerivativeCatmullRom(Idx, u, out hermite);
|
||||
break;
|
||||
case EvaluationMode.Bezier3_Unused:
|
||||
EvaluateDerivativeBezier3(Idx, u, out hermite);
|
||||
break;
|
||||
default:
|
||||
hermite = new Vector3();
|
||||
break;
|
||||
}
|
||||
}
|
||||
void EvaluateDerivativeLinear(int index, float t, out Vector3 result)
|
||||
{
|
||||
result = points[index + 1] - points[index];
|
||||
}
|
||||
void EvaluateDerivativeCatmullRom(int index, float t, out Vector3 result)
|
||||
{
|
||||
C_Evaluate_Derivative(points.Skip(index - 1).ToArray(), t, s_catmullRomCoeffs, out result);
|
||||
}
|
||||
void EvaluateDerivativeBezier3(int index, float t, out Vector3 result)
|
||||
{
|
||||
index *= (int)3u;
|
||||
C_Evaluate_Derivative(points.Skip(index).ToArray(), t, s_Bezier3Coeffs, out result);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region SegLength
|
||||
public float SegLength(int i)
|
||||
{
|
||||
switch (m_mode)
|
||||
{
|
||||
case EvaluationMode.Linear:
|
||||
return SegLengthLinear(i);
|
||||
case EvaluationMode.Catmullrom:
|
||||
return SegLengthCatmullRom(i);
|
||||
case EvaluationMode.Bezier3_Unused:
|
||||
return SegLengthBezier3(i);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
float SegLengthLinear(int index)
|
||||
{
|
||||
return (points[index] - points[index + 1]).GetLength();
|
||||
}
|
||||
float SegLengthCatmullRom(int index)
|
||||
{
|
||||
Vector3 curPos, nextPos;
|
||||
var p = points.Skip(index - 1).ToArray();
|
||||
curPos = nextPos = p[1];
|
||||
|
||||
int i = 1;
|
||||
double length = 0;
|
||||
while (i <= 3)
|
||||
{
|
||||
C_Evaluate(p, i / (float)3, s_catmullRomCoeffs, out nextPos);
|
||||
length += (nextPos - curPos).GetLength();
|
||||
curPos = nextPos;
|
||||
++i;
|
||||
}
|
||||
return (float)length;
|
||||
}
|
||||
float SegLengthBezier3(int index)
|
||||
{
|
||||
index *= (int)3u;
|
||||
|
||||
Vector3 curPos, nextPos;
|
||||
var p = points.Skip(index).ToArray();
|
||||
|
||||
C_Evaluate(p, 0.0f, s_Bezier3Coeffs, out nextPos);
|
||||
curPos = nextPos;
|
||||
|
||||
int i = 1;
|
||||
double length = 0;
|
||||
while (i <= 3)
|
||||
{
|
||||
C_Evaluate(p, i / (float)3, s_Bezier3Coeffs, out nextPos);
|
||||
length += (nextPos - curPos).GetLength();
|
||||
curPos = nextPos;
|
||||
++i;
|
||||
}
|
||||
return (float)length;
|
||||
}
|
||||
#endregion
|
||||
|
||||
public void computeIndex(float t, ref int index, ref float u)
|
||||
{
|
||||
//ASSERT(t >= 0.f && t <= 1.f);
|
||||
int length_ = (int)(t * length());
|
||||
index = computeIndexInBounds(length_);
|
||||
//ASSERT(index < index_hi);
|
||||
u = (length_ - length(index)) / (float)length(index, index + 1);
|
||||
}
|
||||
|
||||
int computeIndexInBounds(int length_)
|
||||
{
|
||||
// Temporary disabled: causes infinite loop with t = 1.f
|
||||
/*
|
||||
index_type hi = index_hi;
|
||||
index_type lo = index_lo;
|
||||
|
||||
index_type i = lo + (float)(hi - lo) * t;
|
||||
|
||||
while ((lengths[i] > length) || (lengths[i + 1] <= length))
|
||||
{
|
||||
if (lengths[i] > length)
|
||||
hi = i - 1; // too big
|
||||
else if (lengths[i + 1] <= length)
|
||||
lo = i + 1; // too small
|
||||
|
||||
i = (hi + lo) / 2;
|
||||
}*/
|
||||
|
||||
int i = index_lo;
|
||||
int N = index_hi;
|
||||
while (i + 1 < N && lengths[i + 1] < length_)
|
||||
++i;
|
||||
|
||||
return i;
|
||||
}
|
||||
private static readonly Matrix4 s_catmullRomCoeffs = new Matrix4(-0.5f, 1.5f, -1.5f, 0.5f, 1.0f, -2.5f, 2.0f, -0.5f, -0.5f, 0.0f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
private static readonly Matrix4 s_Bezier3Coeffs = new Matrix4(-1.0f, 3.0f, -3.0f, 1.0f, 3.0f, -6.0f, 3.0f, 0.0f, -3.0f, 3.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
void C_Evaluate(Vector3[] vertice, float t, Matrix4 matr, out Vector3 result)
|
||||
{
|
||||
Vector4 tvec = new Vector4(t * t * t, t * t, t, 1.0f);
|
||||
Vector4 weights = (tvec * matr);
|
||||
|
||||
result = vertice[0] * weights[0] + vertice[1] * weights[1]
|
||||
+ vertice[2] * weights[2] + vertice[3] * weights[3];
|
||||
}
|
||||
void C_Evaluate_Derivative(Vector3[] vertice, float t, Matrix4 matr, out Vector3 result)
|
||||
{
|
||||
Vector4 tvec = new Vector4(3.0f * t * t, 2.0f * t, 1.0f, 0.0f);
|
||||
Vector4 weights = (tvec * matr);
|
||||
|
||||
result = vertice[0] * weights[0] + vertice[1] * weights[1]
|
||||
+ vertice[2] * weights[2] + vertice[3] * weights[3];
|
||||
}
|
||||
|
||||
public int length() { return lengths[index_hi];}
|
||||
|
||||
public int length(int first, int last) { return lengths[last] - lengths[first]; }
|
||||
|
||||
public int length(int Idx) { return lengths[Idx]; }
|
||||
|
||||
public void set_length(int i, int length) { lengths[i] = length; }
|
||||
|
||||
public void initLengths(Initializer cacher)
|
||||
{
|
||||
int i = index_lo;
|
||||
Array.Resize(ref lengths, index_hi+1);
|
||||
int prev_length = 0, new_length = 0;
|
||||
while (i < index_hi)
|
||||
{
|
||||
new_length = cacher.SetGetTime(this, i);
|
||||
if (new_length < 0)
|
||||
new_length = int.MaxValue;
|
||||
lengths[++i] = new_length;
|
||||
|
||||
prev_length = new_length;
|
||||
}
|
||||
}
|
||||
|
||||
public void initLengths()
|
||||
{
|
||||
int i = index_lo;
|
||||
int length = 0;
|
||||
Array.Resize(ref lengths, index_hi + 1);
|
||||
while (i < index_hi)
|
||||
{
|
||||
length += (int)SegLength(i);
|
||||
lengths[++i] = length;
|
||||
}
|
||||
}
|
||||
|
||||
public bool empty() { return index_lo == index_hi;}
|
||||
|
||||
int[] lengths = new int[0];
|
||||
Vector3[] points = new Vector3[0];
|
||||
public EvaluationMode m_mode;
|
||||
bool cyclic;
|
||||
int index_lo;
|
||||
int index_hi;
|
||||
public enum EvaluationMode
|
||||
{
|
||||
Linear,
|
||||
Catmullrom,
|
||||
Bezier3_Unused,
|
||||
UninitializedMode,
|
||||
ModesEnd
|
||||
}
|
||||
}
|
||||
|
||||
public class FacingInfo
|
||||
{
|
||||
public Vector3 f;
|
||||
public ObjectGuid target;
|
||||
public float angle;
|
||||
public MonsterMoveType type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2017 CypherCore <http://github.com/CypherCore>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
using Framework.Database;
|
||||
using Game.Maps;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game
|
||||
{
|
||||
public sealed class WaypointManager : Singleton<WaypointManager>
|
||||
{
|
||||
WaypointManager()
|
||||
{
|
||||
_waypointStore = new MultiMap<uint, WaypointData>();
|
||||
}
|
||||
|
||||
public void Load()
|
||||
{
|
||||
var oldMSTime = Time.GetMSTime();
|
||||
|
||||
// 0 1 2 3 4 5 6 7 8 9
|
||||
SQLResult result = DB.World.Query("SELECT id, point, position_x, position_y, position_z, orientation, move_type, delay, action, action_chance FROM waypoint_data ORDER BY id, point");
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outError(LogFilter.ServerLoading, "Loaded 0 waypoints. DB table `waypoint_data` is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
uint count = 0;
|
||||
|
||||
do
|
||||
{
|
||||
WaypointData wp = new WaypointData();
|
||||
|
||||
uint pathId = result.Read<uint>(0);
|
||||
|
||||
float x = result.Read<float>(2);
|
||||
float y = result.Read<float>(3);
|
||||
float z = result.Read<float>(4);
|
||||
float o = result.Read<float>(5);
|
||||
|
||||
GridDefines.NormalizeMapCoord(ref x);
|
||||
GridDefines.NormalizeMapCoord(ref y);
|
||||
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
_waypointStore.Add(pathId, wp);
|
||||
++count;
|
||||
} while (result.NextRow());
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} waypoints in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
public void ReloadPath(uint id)
|
||||
{
|
||||
if (_waypointStore.ContainsKey(id))
|
||||
_waypointStore.Remove(id);
|
||||
|
||||
PreparedStatement stmt = DB.World.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_ID);
|
||||
stmt.AddValue(0, id);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
WaypointData wp = new WaypointData();
|
||||
|
||||
float x = result.Read<float>(1);
|
||||
float y = result.Read<float>(2);
|
||||
float z = result.Read<float>(3);
|
||||
float o = result.Read<float>(4);
|
||||
|
||||
GridDefines.NormalizeMapCoord(ref x);
|
||||
GridDefines.NormalizeMapCoord(ref y);
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
_waypointStore.Add(id, wp);
|
||||
|
||||
}
|
||||
while (result.NextRow());
|
||||
}
|
||||
|
||||
public List<WaypointData> GetPath(uint id)
|
||||
{
|
||||
return _waypointStore.LookupByKey(id);
|
||||
}
|
||||
|
||||
MultiMap<uint, WaypointData> _waypointStore;
|
||||
}
|
||||
|
||||
public struct WaypointData
|
||||
{
|
||||
public uint id;
|
||||
public float x, y, z, orientation;
|
||||
public uint delay;
|
||||
public uint event_id;
|
||||
public WaypointMoveType movetype;
|
||||
public byte event_chance;
|
||||
}
|
||||
|
||||
public enum WaypointMoveType
|
||||
{
|
||||
Walk,
|
||||
Run,
|
||||
Land,
|
||||
Takeoff,
|
||||
|
||||
Max
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user