Skip to content

Commit 4a51095

Browse files
committed
Update Destination implementation
1 parent 8ba3d39 commit 4a51095

File tree

6 files changed

+148
-104
lines changed

6 files changed

+148
-104
lines changed

src/MHServerEmu.Games/Dialog/InteractionManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ public bool GetEntityContextInvolvement(WorldEntity entity, EntityTrackingContex
523523
if (entity is Transition transition)
524524
foreach (var destination in transition.Destinations)
525525
{
526-
var regionRef = destination.Region;
526+
var regionRef = destination.RegionRef;
527527
if (regionRef != PrototypeId.Invalid)
528528
{
529529
map.Insert(regionRef, EntityTrackingFlag.TransitionRegion);

src/MHServerEmu.Games/Dialog/MissionOptions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public override EntityTrackingFlag InterestedInEntity(EntityTrackingContextMap m
152152
{
153153
List<Destination> destinations = transition.Destinations;
154154
foreach (var destination in destinations)
155-
if (destination.Region != PrototypeId.Invalid && InterestRegions.Contains(destination.Region))
155+
if (destination.RegionRef != PrototypeId.Invalid && InterestRegions.Contains(destination.RegionRef))
156156
{
157157
map.Insert(MissionProto.DataRef, EntityTrackingFlags);
158158
return EntityTrackingFlags;
@@ -229,7 +229,7 @@ public override EntityTrackingFlag InterestedInEntity(EntityTrackingContextMap m
229229
var targetRef = Proto.ConnectionTarget;
230230
List<Destination> destinations = transition.Destinations;
231231
foreach (var destination in destinations)
232-
if (destination.Target == targetRef)
232+
if (destination.TargetRef == targetRef)
233233
{
234234
map.Insert(targetRef, EntityTrackingFlag.Appearance);
235235
return EntityTrackingFlag.Appearance;

src/MHServerEmu.Games/Entities/Destination.cs

+128-87
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text;
22
using Google.ProtocolBuffers;
33
using MHServerEmu.Core.Extensions;
4+
using MHServerEmu.Core.Serialization;
45
using MHServerEmu.Core.VectorMath;
56
using MHServerEmu.Games.Common;
67
using MHServerEmu.Games.GameData;
@@ -10,114 +11,153 @@
1011

1112
namespace MHServerEmu.Games.Entities
1213
{
13-
public class Destination
14+
public class Destination : ISerialize
1415
{
15-
public RegionTransitionType Type { get; set; }
16-
public PrototypeId Region { get; set; }
17-
public PrototypeId Area { get; set; }
18-
public PrototypeId Cell { get; set; }
19-
public PrototypeId Entity { get; set; }
20-
public PrototypeId Target { get; set; }
21-
public int Unk2 { get; set; }
22-
public string Name { get; set; }
23-
public LocaleStringId NameId { get; set; }
24-
public ulong RegionId { get; set; }
25-
public Vector3 Position { get; set; }
26-
public ulong EntityId { get; set; }
27-
public ulong UnkId2 { get; set; }
16+
private RegionTransitionType _type;
17+
private PrototypeId _regionRef;
18+
private PrototypeId _areaRef;
19+
private PrototypeId _cellRef;
20+
private PrototypeId _entityRef;
21+
private PrototypeId _targetRef;
22+
private int _unk2;
23+
private string _name;
24+
private LocaleStringId _nameId;
25+
private ulong _regionId;
26+
private Vector3 _position;
27+
private ulong _entityId;
28+
private ulong _unkId2;
29+
30+
// TODO: Remove unnecessary accessors
31+
public RegionTransitionType Type { get => _type; set => _type = value; }
32+
public PrototypeId RegionRef { get => _regionRef; set => _regionRef = value; }
33+
public PrototypeId AreaRef { get => _areaRef; set => _areaRef = value; }
34+
public PrototypeId CellRef { get => _cellRef; set => _cellRef = value; }
35+
public PrototypeId EntityRef { get => _entityRef; set => _entityRef = value; }
36+
public PrototypeId TargetRef { get => _targetRef; set => _targetRef = value; }
37+
public int Unk2 { get => _unk2; set => _unk2 = value; }
38+
public string Name { get => _name; set => _name = value; }
39+
public LocaleStringId NameId { get => _nameId; set => _nameId = value; }
40+
public ulong RegionId { get => _regionId; set => _regionId = value; }
41+
public Vector3 Position { get => _position; set => _position = value; }
42+
public ulong EntityId { get => _entityId; set => _entityId = value; }
43+
public ulong UnkId2 { get => _unkId2; set => _unkId2 = value; }
2844

2945
public Destination()
3046
{
31-
Position = Vector3.Zero;
32-
Name = "";
47+
_position = Vector3.Zero;
48+
_name = string.Empty;
3349
}
3450

35-
public Destination(CodedInputStream stream)
51+
public Destination(RegionTransitionType type, PrototypeId regionRef, PrototypeId areaRef, PrototypeId cellRef, PrototypeId entityRef, PrototypeId targetRef,
52+
int unk2, string name, LocaleStringId nameId, ulong regionId,
53+
Vector3 position, ulong entityId, ulong unkId2)
54+
{
55+
_type = type;
56+
_regionRef = regionRef;
57+
_areaRef = areaRef;
58+
_cellRef = cellRef;
59+
_entityRef = entityRef;
60+
_targetRef = targetRef;
61+
_unk2 = unk2;
62+
_name = name;
63+
_nameId = nameId;
64+
_regionId = regionId;
65+
_position = position;
66+
_entityId = entityId;
67+
_unkId2 = unkId2;
68+
}
69+
70+
public bool Serialize(Archive archive)
71+
{
72+
bool success = true;
73+
74+
int type = (int)_type;
75+
success &= Serializer.Transfer(archive, ref type);
76+
_type = (RegionTransitionType)type;
77+
78+
success &= Serializer.Transfer(archive, ref _regionRef);
79+
success &= Serializer.Transfer(archive, ref _areaRef);
80+
success &= Serializer.Transfer(archive, ref _cellRef);
81+
success &= Serializer.Transfer(archive, ref _entityRef);
82+
success &= Serializer.Transfer(archive, ref _targetRef);
83+
success &= Serializer.Transfer(archive, ref _unk2);
84+
success &= Serializer.Transfer(archive, ref _name);
85+
success &= Serializer.Transfer(archive, ref _nameId);
86+
success &= Serializer.Transfer(archive, ref _regionId);
87+
success &= Serializer.Transfer(archive, ref _position);
88+
success &= Serializer.Transfer(archive, ref _entityId);
89+
success &= Serializer.Transfer(archive, ref _unkId2);
90+
91+
return success;
92+
}
93+
94+
public void Decode(CodedInputStream stream)
3695
{
37-
Type = (RegionTransitionType)stream.ReadRawInt32();
96+
_type = (RegionTransitionType)stream.ReadRawInt32();
3897

39-
Region = stream.ReadPrototypeRef<Prototype>();
40-
Area = stream.ReadPrototypeRef<Prototype>();
41-
Cell = stream.ReadPrototypeRef<Prototype>();
42-
Entity = stream.ReadPrototypeRef<Prototype>();
43-
Target = stream.ReadPrototypeRef<Prototype>();
98+
_regionRef = stream.ReadPrototypeRef<Prototype>();
99+
_areaRef = stream.ReadPrototypeRef<Prototype>();
100+
_cellRef = stream.ReadPrototypeRef<Prototype>();
101+
_entityRef = stream.ReadPrototypeRef<Prototype>();
102+
_targetRef = stream.ReadPrototypeRef<Prototype>();
44103

45-
Unk2 = stream.ReadRawInt32();
104+
_unk2 = stream.ReadRawInt32();
46105

47-
Name = stream.ReadRawString();
48-
NameId = (LocaleStringId)stream.ReadRawVarint64();
106+
_name = stream.ReadRawString();
107+
_nameId = (LocaleStringId)stream.ReadRawVarint64();
49108

50-
RegionId = stream.ReadRawVarint64();
109+
_regionId = stream.ReadRawVarint64();
51110

52111
float x = stream.ReadRawFloat();
53112
float y = stream.ReadRawFloat();
54113
float z = stream.ReadRawFloat();
55-
Position = new Vector3(x, y, z);
114+
_position = new Vector3(x, y, z);
56115

57-
EntityId = stream.ReadRawVarint64();
58-
UnkId2 = stream.ReadRawVarint64();
59-
}
60-
61-
public Destination(RegionTransitionType type, PrototypeId region, PrototypeId area, PrototypeId cell, PrototypeId entity, PrototypeId target,
62-
int unk2, string name, LocaleStringId nameId, ulong regionId,
63-
Vector3 position, ulong entityId, ulong unkId2)
64-
{
65-
Type = type;
66-
Region = region;
67-
Area = area;
68-
Cell = cell;
69-
Entity = entity;
70-
Target = target;
71-
Unk2 = unk2;
72-
Name = name;
73-
NameId = nameId;
74-
RegionId = regionId;
75-
Position = position;
76-
EntityId = entityId;
77-
UnkId2 = unkId2;
116+
_entityId = stream.ReadRawVarint64();
117+
_unkId2 = stream.ReadRawVarint64();
78118
}
79119

80120
public void Encode(CodedOutputStream stream)
81121
{
82-
stream.WriteRawInt32((int)Type);
122+
stream.WriteRawInt32((int)_type);
83123

84-
stream.WritePrototypeRef<Prototype>(Region);
85-
stream.WritePrototypeRef<Prototype>(Area);
86-
stream.WritePrototypeRef<Prototype>(Cell);
87-
stream.WritePrototypeRef<Prototype>(Entity);
88-
stream.WritePrototypeRef<Prototype>(Target);
124+
stream.WritePrototypeRef<Prototype>(_regionRef);
125+
stream.WritePrototypeRef<Prototype>(_areaRef);
126+
stream.WritePrototypeRef<Prototype>(_cellRef);
127+
stream.WritePrototypeRef<Prototype>(_entityRef);
128+
stream.WritePrototypeRef<Prototype>(_targetRef);
89129

90-
stream.WriteRawInt32(Unk2);
130+
stream.WriteRawInt32(_unk2);
91131

92-
stream.WriteRawString(Name);
93-
stream.WriteRawVarint64((ulong)NameId);
132+
stream.WriteRawString(_name);
133+
stream.WriteRawVarint64((ulong)_nameId);
94134

95-
stream.WriteRawVarint64(RegionId);
135+
stream.WriteRawVarint64(_regionId);
96136

97-
stream.WriteRawFloat(Position.X);
98-
stream.WriteRawFloat(Position.Y);
99-
stream.WriteRawFloat(Position.Z);
137+
stream.WriteRawFloat(_position.X);
138+
stream.WriteRawFloat(_position.Y);
139+
stream.WriteRawFloat(_position.Z);
100140

101-
stream.WriteRawVarint64(EntityId);
102-
stream.WriteRawVarint64(UnkId2);
141+
stream.WriteRawVarint64(_entityId);
142+
stream.WriteRawVarint64(_unkId2);
103143
}
104144
public override string ToString()
105145
{
106146
StringBuilder sb = new();
107147

108-
sb.AppendLine($"Type: {Type}");
109-
sb.AppendLine($"Region: {GameDatabase.GetPrototypeName(Region)}");
110-
sb.AppendLine($"Area: {GameDatabase.GetPrototypeName(Area)}");
111-
sb.AppendLine($"Cell: {GameDatabase.GetPrototypeName(Cell)}");
112-
sb.AppendLine($"Entity: {GameDatabase.GetPrototypeName(Entity)}");
113-
sb.AppendLine($"Target: {GameDatabase.GetPrototypeName(Target)}");
114-
sb.AppendLine($"Unk2: {Unk2}");
115-
sb.AppendLine($"Name: {Name}");
116-
sb.AppendLine($"NameId: {NameId}");
117-
sb.AppendLine($"RegionId: {RegionId}");
118-
sb.AppendLine($"Position: {Position}");
119-
sb.AppendLine($"UnkId1: {EntityId}");
120-
sb.AppendLine($"UnkId2: {UnkId2}");
148+
sb.AppendLine($"{nameof(_type)}: {_type}");
149+
sb.AppendLine($"{nameof(_regionRef)}: {GameDatabase.GetPrototypeName(_regionRef)}");
150+
sb.AppendLine($"{nameof(_areaRef)}: {GameDatabase.GetPrototypeName(_areaRef)}");
151+
sb.AppendLine($"{nameof(_cellRef)}: {GameDatabase.GetPrototypeName(_cellRef)}");
152+
sb.AppendLine($"{nameof(_entityRef)}: {GameDatabase.GetPrototypeName(_entityRef)}");
153+
sb.AppendLine($"{nameof(_targetRef)}: {GameDatabase.GetPrototypeName(_targetRef)}");
154+
sb.AppendLine($"{nameof(_unk2)}: {_unk2}");
155+
sb.AppendLine($"{nameof(_name)}: {_name}");
156+
sb.AppendLine($"{nameof(_nameId)}: {_nameId}");
157+
sb.AppendLine($"{nameof(_regionId)}: {_regionId}");
158+
sb.AppendLine($"{nameof(_position)}: {_position}");
159+
sb.AppendLine($"{nameof(_entityId)}: {_entityId}");
160+
sb.AppendLine($"{nameof(_unkId2)}: {_unkId2}");
121161

122162
return sb.ToString();
123163
}
@@ -142,21 +182,22 @@ public static Destination DestinationFromTarget(PrototypeId targetRef, Region re
142182
var cellPrototypeId = cellAssetId != AssetId.Invalid ? GameDatabase.GetDataRefByAsset(cellAssetId) : PrototypeId.Invalid;
143183

144184
var targetRegionRef = regionConnectionTarget.Region;
145-
146-
147185
var targetRegion = GameDatabase.GetPrototype<RegionPrototype>(targetRegionRef);
148-
if (RegionPrototype.Equivalent(targetRegion, region.RegionPrototype)) targetRegionRef = (PrototypeId)region.PrototypeId;
186+
187+
if (RegionPrototype.Equivalent(targetRegion, region.RegionPrototype))
188+
targetRegionRef = (PrototypeId)region.PrototypeId;
149189

150190
Destination destination = new()
151191
{
152-
Type = transitionProto.Type,
153-
Region = targetRegionRef,
154-
Area = regionConnectionTarget.Area,
155-
Cell = cellPrototypeId,
156-
Entity = regionConnectionTarget.Entity,
157-
NameId = regionConnectionTarget.Name,
158-
Target = targetRef
192+
_type = transitionProto.Type,
193+
_regionRef = targetRegionRef,
194+
_areaRef = regionConnectionTarget.Area,
195+
_cellRef = cellPrototypeId,
196+
_entityRef = regionConnectionTarget.Entity,
197+
_nameId = regionConnectionTarget.Name,
198+
_targetRef = targetRef
159199
};
200+
160201
return destination;
161202
}
162203
}

src/MHServerEmu.Games/Entities/EntityManager.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ public T GetEntity<T>(ulong entityId) where T : Entity
180180

181181
public Transition GetTransitionInRegion(Destination destination, ulong regionId)
182182
{
183-
PrototypeId areaRef = destination.Area;
184-
PrototypeId cellRef = destination.Cell;
185-
PrototypeId entityRef = destination.Entity;
183+
PrototypeId areaRef = destination.AreaRef;
184+
PrototypeId cellRef = destination.CellRef;
185+
PrototypeId entityRef = destination.EntityRef;
186186
foreach (var entity in _entityDict.Values)
187187
if (entity.RegionId == regionId)
188188
{
@@ -318,8 +318,8 @@ public void HardcodedEntities(Region region)
318318
if (teleportProto.VisibleByDefault == false) // To fix
319319
{
320320
// Logger.Debug($"[{teleport.Location.GetPosition()}][InvT]{GameDatabase.GetFormattedPrototypeName(teleport.Destinations[0].Target)} = {teleport.Destinations[0].Target},");
321-
if (LockedTargets.Contains((InvTarget)teleport.Destinations[0].Target) == false) continue;
322-
if ((InvTarget)teleport.Destinations[0].Target == InvTarget.NPEAvengersTowerHubEntry && region.PrototypeId == RegionPrototypeId.NPERaftRegion) continue;
321+
if (LockedTargets.Contains((InvTarget)teleport.Destinations[0].TargetRef) == false) continue;
322+
if ((InvTarget)teleport.Destinations[0].TargetRef == InvTarget.NPEAvengersTowerHubEntry && region.PrototypeId == RegionPrototypeId.NPERaftRegion) continue;
323323
PrototypeId visibleParent = GetVisibleParentRef(teleportProto.ParentDataRef);
324324
entity.BaseData.PrototypeId = visibleParent;
325325
continue;

src/MHServerEmu.Games/Entities/Transition.cs

+10-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
using Google.ProtocolBuffers;
33
using MHServerEmu.Core.Extensions;
44
using MHServerEmu.Core.Logging;
5-
using MHServerEmu.Core.VectorMath;
65
using MHServerEmu.Games.Common;
76
using MHServerEmu.Games.Entities.PowerCollections;
87
using MHServerEmu.Games.GameData;
98
using MHServerEmu.Games.GameData.Prototypes;
10-
using MHServerEmu.Games.Generators.Regions;
119
using MHServerEmu.Games.Network;
1210
using MHServerEmu.Games.Properties;
1311
using MHServerEmu.Games.Regions;
@@ -91,7 +89,12 @@ protected override void Decode(CodedInputStream stream)
9189
Destinations = new();
9290
int destinationsCount = (int)stream.ReadRawVarint64();
9391
for (int i = 0; i < destinationsCount; i++)
94-
Destinations.Add(new(stream));
92+
{
93+
Destination destination = new();
94+
destination.Decode(stream);
95+
Destinations.Add(destination);
96+
}
97+
9598
}
9699

97100
public override void Encode(CodedOutputStream stream)
@@ -124,19 +127,19 @@ public void ConfigureTowerGen(Transition transition)
124127
destination = Destinations[0];
125128
}
126129
destination.EntityId = transition.Id;
127-
destination.Entity = transition.BaseData.PrototypeId;
130+
destination.EntityRef = transition.BaseData.PrototypeId;
128131
destination.Type = TransitionPrototype.Type;
129132
}
130133

131134
public void TeleportClient(PlayerConnection connection)
132135
{
133-
Logger.Trace($"Destination region {GameDatabase.GetFormattedPrototypeName(Destinations[0].Region)} [{GameDatabase.GetFormattedPrototypeName(Destinations[0].Entity)}]");
134-
connection.Game.MovePlayerToRegion(connection, Destinations[0].Region, Destinations[0].Target);
136+
Logger.Trace($"Destination region {GameDatabase.GetFormattedPrototypeName(Destinations[0].RegionRef)} [{GameDatabase.GetFormattedPrototypeName(Destinations[0].EntityRef)}]");
137+
connection.Game.MovePlayerToRegion(connection, Destinations[0].RegionRef, Destinations[0].TargetRef);
135138
}
136139

137140
public void TeleportToEntity(PlayerConnection connection, ulong entityId)
138141
{
139-
Logger.Trace($"Destination EntityId [{entityId}] [{GameDatabase.GetFormattedPrototypeName(Destinations[0].Entity)}]");
142+
Logger.Trace($"Destination EntityId [{entityId}] [{GameDatabase.GetFormattedPrototypeName(Destinations[0].EntityRef)}]");
140143
connection.Game.MovePlayerToEntity(connection, Destinations[0].EntityId);
141144
}
142145

src/MHServerEmu.Games/Network/PlayerConnection.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ private bool OnUseInteractableObject(MailboxMessage message)
367367
return true;
368368
}
369369
if (teleport.Destinations.Count == 0 || teleport.Destinations[0].Type == RegionTransitionType.Waypoint) return true;
370-
Logger.Trace($"Destination entity {teleport.Destinations[0].Entity}");
370+
Logger.Trace($"Destination entity {teleport.Destinations[0].EntityRef}");
371371

372372
if (teleport.Destinations[0].Type == RegionTransitionType.TowerUp ||
373373
teleport.Destinations[0].Type == RegionTransitionType.TowerDown)
@@ -376,7 +376,7 @@ private bool OnUseInteractableObject(MailboxMessage message)
376376
return true;
377377
}
378378

379-
if (RegionDataRef != teleport.Destinations[0].Region)
379+
if (RegionDataRef != teleport.Destinations[0].RegionRef)
380380
{
381381
teleport.TeleportClient(this);
382382
return true;

0 commit comments

Comments
 (0)