1
1
using System . Text ;
2
2
using Google . ProtocolBuffers ;
3
3
using MHServerEmu . Core . Extensions ;
4
+ using MHServerEmu . Core . Serialization ;
4
5
using MHServerEmu . Core . VectorMath ;
5
6
using MHServerEmu . Games . Common ;
6
7
using MHServerEmu . Games . GameData ;
10
11
11
12
namespace MHServerEmu . Games . Entities
12
13
{
13
- public class Destination
14
+ public class Destination : ISerialize
14
15
{
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 ; }
28
44
29
45
public Destination ( )
30
46
{
31
- Position = Vector3 . Zero ;
32
- Name = "" ;
47
+ _position = Vector3 . Zero ;
48
+ _name = string . Empty ;
33
49
}
34
50
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 )
36
95
{
37
- Type = ( RegionTransitionType ) stream . ReadRawInt32 ( ) ;
96
+ _type = ( RegionTransitionType ) stream . ReadRawInt32 ( ) ;
38
97
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 > ( ) ;
44
103
45
- Unk2 = stream . ReadRawInt32 ( ) ;
104
+ _unk2 = stream . ReadRawInt32 ( ) ;
46
105
47
- Name = stream . ReadRawString ( ) ;
48
- NameId = ( LocaleStringId ) stream . ReadRawVarint64 ( ) ;
106
+ _name = stream . ReadRawString ( ) ;
107
+ _nameId = ( LocaleStringId ) stream . ReadRawVarint64 ( ) ;
49
108
50
- RegionId = stream . ReadRawVarint64 ( ) ;
109
+ _regionId = stream . ReadRawVarint64 ( ) ;
51
110
52
111
float x = stream . ReadRawFloat ( ) ;
53
112
float y = stream . ReadRawFloat ( ) ;
54
113
float z = stream . ReadRawFloat ( ) ;
55
- Position = new Vector3 ( x , y , z ) ;
114
+ _position = new Vector3 ( x , y , z ) ;
56
115
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 ( ) ;
78
118
}
79
119
80
120
public void Encode ( CodedOutputStream stream )
81
121
{
82
- stream . WriteRawInt32 ( ( int ) Type ) ;
122
+ stream . WriteRawInt32 ( ( int ) _type ) ;
83
123
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 ) ;
89
129
90
- stream . WriteRawInt32 ( Unk2 ) ;
130
+ stream . WriteRawInt32 ( _unk2 ) ;
91
131
92
- stream . WriteRawString ( Name ) ;
93
- stream . WriteRawVarint64 ( ( ulong ) NameId ) ;
132
+ stream . WriteRawString ( _name ) ;
133
+ stream . WriteRawVarint64 ( ( ulong ) _nameId ) ;
94
134
95
- stream . WriteRawVarint64 ( RegionId ) ;
135
+ stream . WriteRawVarint64 ( _regionId ) ;
96
136
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 ) ;
100
140
101
- stream . WriteRawVarint64 ( EntityId ) ;
102
- stream . WriteRawVarint64 ( UnkId2 ) ;
141
+ stream . WriteRawVarint64 ( _entityId ) ;
142
+ stream . WriteRawVarint64 ( _unkId2 ) ;
103
143
}
104
144
public override string ToString ( )
105
145
{
106
146
StringBuilder sb = new ( ) ;
107
147
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 } ") ;
121
161
122
162
return sb . ToString ( ) ;
123
163
}
@@ -142,21 +182,22 @@ public static Destination DestinationFromTarget(PrototypeId targetRef, Region re
142
182
var cellPrototypeId = cellAssetId != AssetId . Invalid ? GameDatabase . GetDataRefByAsset ( cellAssetId ) : PrototypeId . Invalid ;
143
183
144
184
var targetRegionRef = regionConnectionTarget . Region ;
145
-
146
-
147
185
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 ;
149
189
150
190
Destination destination = new ( )
151
191
{
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
159
199
} ;
200
+
160
201
return destination ;
161
202
}
162
203
}
0 commit comments