Core/GameObjects: Transport (type 11) improvements

Port From (https://github.com/TrinityCore/TrinityCore/commit/630b60eb0dcd3d9ce41582664ab822b049365431)
This commit is contained in:
hondacrx
2022-06-03 16:20:41 -04:00
parent e65ce31742
commit 40444525b2
30 changed files with 807 additions and 377 deletions
+4 -1
View File
@@ -103,7 +103,7 @@ namespace Game.Maps
{
// at this moment i_clientGUIDs have guids that not iterate at grid level checks
// but exist one case when this possible and object not out of range: transports
Transport transport = i_player.GetTransport();
Transport transport = i_player.GetTransport<Transport>();
if (transport)
{
foreach (var obj in transport.GetPassengers())
@@ -128,6 +128,9 @@ namespace Game.Maps
case TypeId.DynamicObject:
i_player.UpdateVisibilityOf(obj.ToDynamicObject(), i_data, i_visibleNow);
break;
case TypeId.AreaTrigger:
i_player.UpdateVisibilityOf(obj.ToAreaTrigger(), i_data, i_visibleNow);
break;
default:
break;
}
+6 -10
View File
@@ -1131,9 +1131,7 @@ namespace Game.Maps
else
{
go.Relocate(x, y, z, orientation);
go.UpdateModelPosition();
go.UpdatePositionData();
go.UpdateObjectVisibility(false);
go.AfterRelocation();
RemoveGameObjectFromMoveList(go);
}
@@ -1354,9 +1352,7 @@ namespace Game.Maps
{
// update pos
go.Relocate(go._newPosition);
go.UpdateModelPosition();
go.UpdatePositionData();
go.UpdateObjectVisibility(false);
go.AfterRelocation();
}
else
{
@@ -2247,7 +2243,7 @@ namespace Game.Maps
var data = new UpdateData(player.GetMapId());
// attach to player data current transport data
Transport transport = player.GetTransport();
Transport transport = player.GetTransport<Transport>();
if (transport != null)
{
transport.BuildCreateUpdateBlockForPlayer(data, player);
@@ -4168,8 +4164,8 @@ namespace Game.Maps
if (!summon.Create(GenerateLowGuid(HighGuid.Creature), this, entry, pos, null, vehId, true))
return null;
Transport transport = summoner != null ? summoner.GetTransport() : null;
if (transport)
ITransport transport = summoner != null ? summoner.GetTransport() : null;
if (transport != null)
{
pos.GetPosition(out float x, out float y, out float z, out float o);
transport.CalculatePassengerOffset(ref x, ref y, ref z, ref o);
@@ -4209,7 +4205,7 @@ namespace Game.Maps
if (!AddToMap(summon.ToCreature()))
{
// Returning false will cause the object to be deleted - remove from transport
if (transport)
if (transport != null)
transport.RemovePassenger(summon);
summon.Dispose();
+57 -20
View File
@@ -425,6 +425,18 @@ namespace Game.Maps
_transportAnimations[transportEntry] = animNode;
}
public void AddPathRotationToTransport(uint transportEntry, uint timeSeg, TransportRotationRecord node)
{
if (!_transportAnimations.ContainsKey(transportEntry))
_transportAnimations[transportEntry] = new();
TransportAnimation animNode = _transportAnimations[transportEntry];
animNode.Rotations[timeSeg] = node;
if (animNode.Path.Empty() && animNode.TotalTime < timeSeg)
animNode.TotalTime = timeSeg;
}
public Transport CreateTransport(uint entry, ulong guid = 0, Map map = null, PhaseUseFlagsValues phaseUseFlags = 0, uint phaseId = 0, uint phaseGroupId = 0)
{
// instance case, execute GetGameObjectEntry hook
@@ -530,14 +542,6 @@ namespace Game.Maps
{
return _transportSpawns.LookupByKey(spawnId);
}
public void AddPathRotationToTransport(uint transportEntry, uint timeSeg, TransportRotationRecord node)
{
if (!_transportAnimations.ContainsKey(transportEntry))
_transportAnimations[transportEntry] = new TransportAnimation();
_transportAnimations[transportEntry].Rotations[timeSeg] = node;
}
Dictionary<uint, TransportTemplate> _transportTemplates = new();
MultiMap<uint, uint> _instanceTransports = new();
@@ -557,8 +561,8 @@ namespace Game.Maps
mode = Spline.EvaluationMode.Catmullrom;
cyclic = false;
points = new Vector3[_points.Count];
for(var i = 0; i < _points.Count; ++i)
for (var i = 0; i < _points.Count; ++i)
points[i] = _points[i];
lo = 1;
@@ -627,26 +631,59 @@ namespace Game.Maps
public class TransportAnimation
{
TransportAnimationRecord GetAnimNode(uint time)
public Dictionary<uint, TransportAnimationRecord> Path = new();
public Dictionary<uint, TransportRotationRecord> Rotations = new();
public uint TotalTime;
public TransportAnimationRecord GetPrevAnimNode(uint time)
{
if (Path.Empty())
return null;
foreach (var pair in Path)
if (time >= pair.Key)
return pair.Value;
List<uint> lKeys = Path.Keys.ToList();
int reqIndex = lKeys.IndexOf(time) - 1;
return Path.First().Value;
if (reqIndex != -1)
return Path[lKeys[reqIndex]];
return Path.LastOrDefault().Value;
}
TransportRotationRecord GetAnimRotation(uint time)
public TransportRotationRecord GetPrevAnimRotation(uint time)
{
return Rotations.LookupByKey(time);
if (Rotations.Empty())
return null;
List<uint> lKeys = Rotations.Keys.ToList();
int reqIndex = lKeys.IndexOf(time) - 1;
if (reqIndex != -1)
return Rotations[lKeys[reqIndex]];
return Rotations.LastOrDefault().Value;
}
public Dictionary<uint, TransportAnimationRecord> Path = new();
public Dictionary<uint, TransportRotationRecord> Rotations = new();
public uint TotalTime;
public TransportAnimationRecord GetNextAnimNode(uint time)
{
if (Path.Empty())
return null;
if (Path.TryGetValue(time, out TransportAnimationRecord record))
return record;
return Path.FirstOrDefault().Value;
}
public TransportRotationRecord GetNextAnimRotation(uint time)
{
if (Rotations.Empty())
return null;
if (Rotations.TryGetValue(time, out TransportRotationRecord record))
return record;
return Rotations.FirstOrDefault().Value;
}
}
public class TransportSpawn