From 22fbfd83607431ec80f2d248cbf155e66e833e06 Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Sun, 4 Aug 2024 17:18:56 -0400 Subject: [PATCH] Core/Movement: Allow overriding speed for taxi movement generator Port From (https://github.com/TrinityCore/TrinityCore/commit/038f995ad6ce6a26f71367cae3eb7ae107527a18) --- Source/Game/Entities/Player/Player.cs | 29 ++++++++++++------- Source/Game/Handlers/TaxiHandler.cs | 12 -------- .../Generators/FlightPathMovementGenerator.cs | 24 ++++++++------- Source/Game/Movement/MotionMaster.cs | 4 +-- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/Source/Game/Entities/Player/Player.cs b/Source/Game/Entities/Player/Player.cs index dc9728cd2..a21511f3f 100644 --- a/Source/Game/Entities/Player/Player.cs +++ b/Source/Game/Entities/Player/Player.cs @@ -26,7 +26,6 @@ using Game.Spells; using System; using System.Collections.Generic; using System.Linq; - using static Global; namespace Game.Entities @@ -6907,6 +6906,7 @@ namespace Game.Entities SendMessageToSet(data, true); } + public static DrunkenState GetDrunkenstateByValue(byte value) { if (value >= 90) @@ -6919,7 +6919,8 @@ namespace Game.Entities } public uint GetDeathTimer() { return m_deathTimer; } - public bool ActivateTaxiPathTo(List nodes, Creature npc = null, uint spellid = 0, uint preferredMountDisplay = 0) + + public bool ActivateTaxiPathTo(List nodes, Creature npc = null, uint spellid = 0, uint preferredMountDisplay = 0, float? speed = null) { if (nodes.Count < 2) { @@ -7096,23 +7097,18 @@ namespace Game.Entities ModifyMoney(-firstcost); UpdateCriteria(CriteriaType.MoneySpentOnTaxis, firstcost); GetSession().SendActivateTaxiReply(); - GetSession().SendDoFlight(mount_display_id, sourcepath); + StartTaxiMovement(mount_display_id, sourcepath, 0, speed); } return true; } - public bool ActivateTaxiPathTo(uint taxi_path_id, uint spellid = 0) + public bool ActivateTaxiPathTo(uint taxi_path_id, uint spellid = 0, float? speed = null) { var entry = CliDB.TaxiPathStorage.LookupByKey(taxi_path_id); if (entry == null) return false; - List nodes = new(); - - nodes.Add(entry.FromTaxiNode); - nodes.Add(entry.ToTaxiNode); - - return ActivateTaxiPathTo(nodes, null, spellid); + return ActivateTaxiPathTo([entry.FromTaxiNode, entry.ToTaxiNode], null, spellid, 0, speed); } public void FinishTaxiFlight() @@ -7178,7 +7174,18 @@ namespace Game.Entities } } - GetSession().SendDoFlight(mountDisplayId, path, startNode); + StartTaxiMovement(mountDisplayId, path, startNode, null); + } + + void StartTaxiMovement(uint mountDisplayId, uint path, uint pathNode, float? speed) + { + // remove fake death + RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags.Interacting); + + if (mountDisplayId != 0) + Mount(mountDisplayId); + + GetMotionMaster().MoveTaxiFlight(path, pathNode, speed); } public bool GetsRecruitAFriendBonus(bool forXP) diff --git a/Source/Game/Handlers/TaxiHandler.cs b/Source/Game/Handlers/TaxiHandler.cs index 300675839..4e4582d33 100644 --- a/Source/Game/Handlers/TaxiHandler.cs +++ b/Source/Game/Handlers/TaxiHandler.cs @@ -112,18 +112,6 @@ namespace Game GetPlayer().SetTaxiCheater(lastTaxiCheaterState); } - public void SendDoFlight(uint mountDisplayId, uint path, uint pathNode = 0) - { - // remove fake death - if (GetPlayer().HasUnitState(UnitState.Died)) - GetPlayer().RemoveAurasByType(AuraType.FeignDeath); - - if (mountDisplayId != 0) - GetPlayer().Mount(mountDisplayId); - - GetPlayer().GetMotionMaster().MoveTaxiFlight(path, pathNode); - } - public bool SendLearnNewTaxiNode(Creature unit) { // find current node diff --git a/Source/Game/Movement/Generators/FlightPathMovementGenerator.cs b/Source/Game/Movement/Generators/FlightPathMovementGenerator.cs index 7cbc725c4..bf5068cb2 100644 --- a/Source/Game/Movement/Generators/FlightPathMovementGenerator.cs +++ b/Source/Game/Movement/Generators/FlightPathMovementGenerator.cs @@ -14,8 +14,19 @@ namespace Game.Movement { public class FlightPathMovementGenerator : MovementGeneratorMedium { - public FlightPathMovementGenerator() + float? _speed; + 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 + + List _path = new(); + int _currentNode; + List _pointsForPathSwitch = new(); //! node indexes and costs where TaxiPath changes + + public FlightPathMovementGenerator(float? speed) { + _speed = speed; Mode = MovementGeneratorMode.Default; Priority = MovementGeneratorPriority.Highest; Flags = MovementGeneratorFlags.InitializationPending; @@ -61,7 +72,7 @@ namespace Game.Movement init.SetSmooth(); init.SetUncompressed(); init.SetWalk(true); - init.SetVelocity(30.0f); + init.SetVelocity(_speed.GetValueOrDefault(30.0f)); init.Launch(); } @@ -312,15 +323,6 @@ namespace Game.Movement public uint GetCurrentNode() { return (uint)_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 - - List _path = new(); - int _currentNode; - List _pointsForPathSwitch = new(); //! node indexes and costs where TaxiPath changes - class TaxiNodeChangeInfo { public TaxiNodeChangeInfo(uint pathIndex, long cost) diff --git a/Source/Game/Movement/MotionMaster.cs b/Source/Game/Movement/MotionMaster.cs index cd4bd5813..701c0d79e 100644 --- a/Source/Game/Movement/MotionMaster.cs +++ b/Source/Game/Movement/MotionMaster.cs @@ -994,7 +994,7 @@ namespace Game.Movement Log.outError(LogFilter.Server, $"MotionMaster::MoveSeekAssistanceDistract: {_owner.GetGUID()} attempted to call distract after assistance"); } - public void MoveTaxiFlight(uint path, uint pathnode) + public void MoveTaxiFlight(uint path, uint pathnode, float? speed = null) { if (_owner.IsTypeId(TypeId.Player)) { @@ -1006,7 +1006,7 @@ namespace Game.Movement bool hasExisting = HasMovementGenerator(gen => gen.GetMovementGeneratorType() == MovementGeneratorType.Flight); Cypher.Assert(!hasExisting, "Duplicate flight path movement generator"); - FlightPathMovementGenerator movement = new(); + FlightPathMovementGenerator movement = new(speed); movement.LoadPath(_owner.ToPlayer()); Add(movement); }