Core/Movement: Fixed creature hover

Port From (https://github.com/TrinityCore/TrinityCore/commit/2e2b29861878fda2d27156c71a1d8ed7dbe0b4fe)
This commit is contained in:
hondacrx
2021-08-24 11:10:59 -04:00
parent 1c5bb258d5
commit 89058fec83
9 changed files with 59 additions and 90 deletions
+4 -7
View File
@@ -201,6 +201,7 @@ namespace Game.Entities
transport.CalculatePassengerPosition(ref x, ref y, ref z, ref o);
}
UpdateAllowedPositionZ(x, y, ref z);
SetHomePosition(x, y, z, o);
GetMap().CreatureRelocation(this, x, y, z, o);
}
@@ -897,11 +898,7 @@ namespace Game.Entities
LoadCreaturesAddon();
//! Need to be called after LoadCreaturesAddon - MOVEMENTFLAG_HOVER is set there
if (HasUnitMovementFlag(MovementFlag.Hover))
{
//! Relocate again with updated Z coord
posZ += m_unitData.HoverHeight;
}
posZ += GetHoverOffset();
LastUsedScriptID = GetScriptId();
@@ -2825,7 +2822,7 @@ namespace Game.Entities
// Set the movement flags if the creature is in that mode. (Only fly if actually in air, only swim if in water, etc)
float ground = GetFloorZ();
bool isInAir = (MathFunctions.fuzzyGt(GetPositionZMinusOffset(), ground + MapConst.GroundHeightTolerance) || MathFunctions.fuzzyLt(GetPositionZMinusOffset(), ground - MapConst.GroundHeightTolerance)); // Can be underground too, prevent the falling
bool isInAir = (MathFunctions.fuzzyGt(GetPositionZ(), ground + MapConst.GroundHeightTolerance) || MathFunctions.fuzzyLt(GetPositionZ(), ground - MapConst.GroundHeightTolerance)); // Can be underground too, prevent the falling
if (GetCreatureTemplate().InhabitType.HasAnyFlag(InhabitType.Air) && isInAir && !IsFalling())
{
@@ -3138,7 +3135,7 @@ namespace Game.Entities
return false;
//We should set first home position, because then AI calls home movement
SetHomePosition(data.spawnPoint);
SetHomePosition(this);
m_deathState = DeathState.Alive;
+32 -51
View File
@@ -2095,7 +2095,9 @@ namespace Game.Entities
public void UpdateGroundPositionZ(float x, float y, ref float z)
{
z = GetMapHeight(x, y, z);
float newZ = GetMapHeight(x, y, z);
if (newZ > MapConst.InvalidHeight)
z = newZ + (IsUnit() ? ToUnit().GetHoverOffset() : 0.0f);
}
public void UpdateAllowedPositionZ(float x, float y, ref float z)
@@ -2104,66 +2106,45 @@ namespace Game.Entities
if (GetTransport())
return;
switch (GetTypeId())
Unit unit = ToUnit();
if (unit != null)
{
case TypeId.Unit:
if (!unit.CanFly())
{
// non fly unit don't must be in air
// non swim unit must be at ground (mostly speedup, because it don't must be in water and water level check less fast
if (!ToCreature().CanFly())
{
bool canSwim = ToCreature().CanSwim();
float ground_z = z;
float max_z = canSwim
? GetMapWaterOrGroundLevel(x, y, z, ref ground_z)
: (ground_z = GetMapHeight(x, y, z));
if (max_z > MapConst.InvalidHeight)
{
if (z > max_z)
z = max_z;
else if (z < ground_z)
z = ground_z;
}
}
bool canSwim = unit.CanSwim();
float groundZ = z;
float max_z;
if (canSwim)
max_z = GetMapWaterOrGroundLevel(x, y, z, ref groundZ);
else
max_z = groundZ = GetMapHeight(x, y, z);
if (max_z > MapConst.InvalidHeight)
{
float ground_z = GetMapHeight(x, y, z);
if (MathF.Abs(z - ground_z) < GetCollisionHeight())
z = ground_z;
// hovering units cannot go below their hover height
float hoverOffset = unit.GetHoverOffset();
max_z += hoverOffset;
groundZ += hoverOffset;
if (z > max_z)
z = max_z;
else if (z < groundZ)
z = groundZ;
}
break;
}
case TypeId.Player:
else
{
// for server controlled moves playr work same as creature (but it can always swim)
if (!ToPlayer().CanFly())
{
float ground_z = z;
float max_z = GetMapWaterOrGroundLevel(x, y, z, ref ground_z);
if (max_z > MapConst.InvalidHeight)
{
if (z > max_z)
z = max_z;
else if (z < ground_z)
z = ground_z;
}
}
else
{
float ground_z = GetMapHeight(x, y, z);
if (MathF.Abs(z - ground_z) < GetCollisionHeight())
z = ground_z;
}
break;
}
default:
{
float ground_z = GetMapHeight(x, y, z);
if (ground_z > MapConst.InvalidHeight)
float ground_z = GetMapHeight(x, y, z) + unit.GetHoverOffset();
if (z < ground_z)
z = ground_z;
break;
}
}
else
{
float ground_z = GetMapHeight(x, y, z);
if (ground_z > MapConst.InvalidHeight)
z = ground_z;
}
}
public void GetNearPoint2D(out float x, out float y, float distance2d, float absAngle)
+1 -1
View File
@@ -1531,7 +1531,7 @@ namespace Game.Entities
float dx = GetPositionX() - obj.GetPositionX();
float dy = GetPositionY() - obj.GetPositionY();
float dz = GetPositionZMinusOffset() - obj.GetPositionZMinusOffset();
float dz = GetPositionZ() - obj.GetPositionZ();
float distsq = (dx * dx) + (dy * dy) + (dz * dz);
float maxdist = GetMeleeRange(obj) + GetTotalAuraModifier(AuraType.ModAutoAttackRange);
+6 -10
View File
@@ -198,7 +198,7 @@ namespace Game.Entities
return;
MoveSplineInit init = new(this);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZMinusOffset(), false);
init.MoveTo(GetPositionX(), GetPositionY(), GetPositionZ(), false);
init.SetFacing(ori);
init.Launch();
}
@@ -616,6 +616,11 @@ namespace Game.Entities
GetVehicleKit().RelocatePassengers();
}
public float GetHoverOffset()
{
return HasUnitMovementFlag(MovementFlag.Hover) ? m_unitData.HoverHeight : 0.0f;
}
public bool IsWithinBoundaryRadius(Unit obj)
{
if (!obj || !IsInMap(obj) || !IsInPhase(obj))
@@ -1577,15 +1582,6 @@ namespace Game.Entities
SendMessageToSet(data, true);
}
public float GetPositionZMinusOffset()
{
float offset = 0.0f;
if (HasUnitMovementFlag(MovementFlag.Hover))
offset = m_unitData.HoverHeight;
return GetPositionZ() - offset;
}
public Unit GetUnitBeingMoved()
{
Player player = ToPlayer();