Core/Movement: Store adv flying speeds instead of hardcoding them in SMSG_UPDATE_OBJECT and enable packets modifying them

Port From (https://github.com/TrinityCore/TrinityCore/commit/43c7965d6b97a919ddd7e97a1f6e3f5750553f09)
This commit is contained in:
Hondacrx
2024-11-10 18:24:49 -05:00
parent bb76867477
commit be74f514a1
7 changed files with 226 additions and 23 deletions
+17 -17
View File
@@ -355,23 +355,23 @@ namespace Game.Entities
data.WriteFloat(1.0f); // MovementForcesModMagnitude
}
data.WriteFloat(2.0f); // advFlyingAirFriction
data.WriteFloat(65.0f); // advFlyingMaxVel
data.WriteFloat(1.0f); // advFlyingLiftCoefficient
data.WriteFloat(3.0f); // advFlyingDoubleJumpVelMod
data.WriteFloat(10.0f); // advFlyingGlideStartMinHeight
data.WriteFloat(100.0f); // advFlyingAddImpulseMaxSpeed
data.WriteFloat(90.0f); // advFlyingMinBankingRate
data.WriteFloat(140.0f); // advFlyingMaxBankingRate
data.WriteFloat(180.0f); // advFlyingMinPitchingRateDown
data.WriteFloat(360.0f); // advFlyingMaxPitchingRateDown
data.WriteFloat(90.0f); // advFlyingMinPitchingRateUp
data.WriteFloat(270.0f); // advFlyingMaxPitchingRateUp
data.WriteFloat(30.0f); // advFlyingMinTurnVelocityThreshold
data.WriteFloat(80.0f); // advFlyingMaxTurnVelocityThreshold
data.WriteFloat(2.75f); // advFlyingSurfaceFriction
data.WriteFloat(7.0f); // advFlyingOverMaxDeceleration
data.WriteFloat(0.4f); // advFlyingLaunchSpeedCoefficient
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.AirFriction));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.MaxVel));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.LiftCoefficient));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.DoubleJumpVelMod));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.GlideStartMinHeight));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.AddImpulseMaxSpeed));
data.WriteFloat(unit.GetAdvFlyingSpeedMin(AdvFlyingRateTypeRange.BankingRate));
data.WriteFloat(unit.GetAdvFlyingSpeedMax(AdvFlyingRateTypeRange.BankingRate));
data.WriteFloat(unit.GetAdvFlyingSpeedMin(AdvFlyingRateTypeRange.PitchingRateDown));
data.WriteFloat(unit.GetAdvFlyingSpeedMax(AdvFlyingRateTypeRange.PitchingRateDown));
data.WriteFloat(unit.GetAdvFlyingSpeedMin(AdvFlyingRateTypeRange.PitchingRateUp));
data.WriteFloat(unit.GetAdvFlyingSpeedMax(AdvFlyingRateTypeRange.PitchingRateUp));
data.WriteFloat(unit.GetAdvFlyingSpeedMin(AdvFlyingRateTypeRange.TurnVelocityThreshold));
data.WriteFloat(unit.GetAdvFlyingSpeedMax(AdvFlyingRateTypeRange.TurnVelocityThreshold));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.SurfaceFriction));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.OverMaxDeceleration));
data.WriteFloat(unit.GetAdvFlyingSpeed(AdvFlyingRateTypeSingle.LaunchSpeedCoefficient));
data.WriteBit(HasSpline);
data.FlushBits();
+1
View File
@@ -23,6 +23,7 @@ namespace Game.Entities
//Movement
protected float[] m_speed_rate = new float[(int)UnitMoveType.Max];
float[] m_advFlyingSpeed = new float[(int)AdvFlyingRateTypeSingle.Max];
List<AbstractFollower> m_followingMe = new();
public MoveSpline MoveSpline { get; set; }
MotionMaster i_motionMaster;
+106 -1
View File
@@ -154,6 +154,111 @@ namespace Game.Entities
public float GetSpeedRate(UnitMoveType mtype) { return m_speed_rate[(int)mtype]; }
void SetFlightCapabilityID(int flightCapabilityId, bool clientUpdate)
{
if (flightCapabilityId != 0 && !CliDB.FlightCapabilityStorage.HasRecord((uint)flightCapabilityId))
return;
SetUpdateFieldValue(m_values.ModifyValue(m_unitData).ModifyValue(m_unitData.FlightCapabilityID), flightCapabilityId);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.AirFriction, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.MaxVel, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.LiftCoefficient, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.DoubleJumpVelMod, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.GlideStartMinHeight, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.AddImpulseMaxSpeed, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeRange.BankingRate, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeRange.PitchingRateDown, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeRange.PitchingRateUp, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeRange.TurnVelocityThreshold, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.SurfaceFriction, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.OverMaxDeceleration, clientUpdate);
UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle.LaunchSpeedCoefficient, clientUpdate);
}
void UpdateAdvFlyingSpeed(AdvFlyingRateTypeSingle speedType, bool clientUpdate)
{
FlightCapabilityRecord flightCapabilityEntry = CliDB.FlightCapabilityStorage.LookupByKey(GetFlightCapabilityID());
if (flightCapabilityEntry == null)
flightCapabilityEntry = CliDB.FlightCapabilityStorage.LookupByKey(1);
(ServerOpcodes opcode, float newValue) = speedType switch
{
AdvFlyingRateTypeSingle.AirFriction => (ServerOpcodes.MoveSetAdvFlyingAirFriction, flightCapabilityEntry.AirFriction),
AdvFlyingRateTypeSingle.MaxVel => (ServerOpcodes.MoveSetAdvFlyingMaxVel, flightCapabilityEntry.MaxVel),
AdvFlyingRateTypeSingle.LiftCoefficient => (ServerOpcodes.MoveSetAdvFlyingLiftCoefficient, flightCapabilityEntry.LiftCoefficient),
AdvFlyingRateTypeSingle.DoubleJumpVelMod => (ServerOpcodes.MoveSetAdvFlyingDoubleJumpVelMod, flightCapabilityEntry.DoubleJumpVelMod),
AdvFlyingRateTypeSingle.GlideStartMinHeight => (ServerOpcodes.MoveSetAdvFlyingGlideStartMinHeight, flightCapabilityEntry.GlideStartMinHeight),
AdvFlyingRateTypeSingle.AddImpulseMaxSpeed => (ServerOpcodes.MoveSetAdvFlyingAddImpulseMaxSpeed, flightCapabilityEntry.AddImpulseMaxSpeed),
AdvFlyingRateTypeSingle.SurfaceFriction => (ServerOpcodes.MoveSetAdvFlyingSurfaceFriction, flightCapabilityEntry.SurfaceFriction),
AdvFlyingRateTypeSingle.OverMaxDeceleration => (ServerOpcodes.MoveSetAdvFlyingOverMaxDeceleration, flightCapabilityEntry.OverMaxDeceleration),
AdvFlyingRateTypeSingle.LaunchSpeedCoefficient => (ServerOpcodes.MoveSetAdvFlyingLaunchSpeedCoefficient, flightCapabilityEntry.LaunchSpeedCoefficient),
_ => (ServerOpcodes.Max, 0)
};
if (m_advFlyingSpeed[(int)speedType] == newValue)
return;
m_advFlyingSpeed[(int)speedType] = newValue;
if (!clientUpdate)
return;
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
if (playerMover != null)
{
SetAdvFlyingSpeed selfpacket = new(opcode);
selfpacket.MoverGUID = GetGUID();
selfpacket.SequenceIndex = m_movementCounter++;
selfpacket.Speed = newValue;
playerMover.GetSession().SendPacket(selfpacket);
}
}
void UpdateAdvFlyingSpeed(AdvFlyingRateTypeRange speedType, bool clientUpdate)
{
FlightCapabilityRecord flightCapabilityEntry = CliDB.FlightCapabilityStorage.LookupByKey(GetFlightCapabilityID());
if (flightCapabilityEntry == null)
flightCapabilityEntry = CliDB.FlightCapabilityStorage.LookupByKey(1);
(ServerOpcodes opcode, float min, float max) = speedType switch
{
AdvFlyingRateTypeRange.BankingRate => (ServerOpcodes.MoveSetAdvFlyingBankingRate, flightCapabilityEntry.BankingRateMin, flightCapabilityEntry.BankingRateMax),
AdvFlyingRateTypeRange.PitchingRateDown => (ServerOpcodes.MoveSetAdvFlyingPitchingRateDown, flightCapabilityEntry.PitchingRateDownMin, flightCapabilityEntry.PitchingRateDownMax),
AdvFlyingRateTypeRange.PitchingRateUp => (ServerOpcodes.MoveSetAdvFlyingPitchingRateUp, flightCapabilityEntry.PitchingRateUpMin, flightCapabilityEntry.PitchingRateUpMax),
AdvFlyingRateTypeRange.TurnVelocityThreshold => (ServerOpcodes.MoveSetAdvFlyingTurnVelocityThreshold, flightCapabilityEntry.TurnVelocityThresholdMin, flightCapabilityEntry.TurnVelocityThresholdMax),
_ => (ServerOpcodes.Max, 0, 0)
};
if (m_advFlyingSpeed[(int)speedType] == min && m_advFlyingSpeed[(int)speedType + 1] == max)
return;
m_advFlyingSpeed[(int)speedType] = min;
m_advFlyingSpeed[(int)speedType + 1] = max;
if (!clientUpdate)
return;
Player playerMover = GetUnitBeingMoved()?.ToPlayer();
if (playerMover != null)
{
SetAdvFlyingSpeedRange selfpacket = new(opcode);
selfpacket.MoverGUID = GetGUID();
selfpacket.SequenceIndex = m_movementCounter++;
selfpacket.SpeedMin = min;
selfpacket.SpeedMax = max;
playerMover.GetSession().SendPacket(selfpacket);
}
}
int GetFlightCapabilityID() { return m_unitData.FlightCapabilityID; }
public float GetAdvFlyingSpeed(AdvFlyingRateTypeSingle speedType) { return m_advFlyingSpeed[(int)speedType]; }
public float GetAdvFlyingSpeedMin(AdvFlyingRateTypeRange speedType) { return m_advFlyingSpeed[(int)speedType]; }
public float GetAdvFlyingSpeedMax(AdvFlyingRateTypeRange speedType) { return m_advFlyingSpeed[(int)speedType + 1]; }
public virtual MovementGeneratorType GetDefaultMovementType()
{
return MovementGeneratorType.Idle;
@@ -254,7 +359,7 @@ namespace Game.Entities
init.DisableTransportPathTransformations(); // It makes no sense to target global orientation
init.SetFacing(point.GetPositionX(), point.GetPositionY(), point.GetPositionZ());
//GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_PRIORITY_HIGHEST);
//GetMotionMaster().LaunchMoveSpline(std::move(init), EVENT_FACE, MOTION_PRIORITY_HIGHEST);
UpdateSplineMovement((uint)init.Launch());
Creature creature = ToCreature();
if (creature != null)
+2
View File
@@ -68,6 +68,8 @@ namespace Game.Entities
for (byte i = 0; i < (int)UnitMoveType.Max; ++i)
m_speed_rate[i] = 1.0f;
SetFlightCapabilityID(0, false);
m_serverSideVisibility.SetValue(ServerSideVisibilityType.Ghost, GhostVisibilityType.Alive);
m_unitData = new UnitData();