-
Notifications
You must be signed in to change notification settings - Fork 0
/
BaseWeaponModDataBlock.cs
305 lines (264 loc) · 8.74 KB
/
BaseWeaponModDataBlock.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
using System;
using uLink;
using UnityEngine;
public class BaseWeaponModDataBlock : ItemModDataBlock
{
public GameObject attachObjectRep;
public GameObject attachObjectVM;
public string attachSocketName;
public bool isMesh;
public bool modifyZoomOffset;
public float punchScalar;
public string socketOverrideName;
public float zoomOffsetZ;
public BaseWeaponModDataBlock() : this(typeof(WeaponModRep))
{
}
protected BaseWeaponModDataBlock(System.Type minimumItemModRepresentationType) : base(minimumItemModRepresentationType)
{
this.attachSocketName = "muzzle";
this.socketOverrideName = string.Empty;
this.punchScalar = 1f;
if (!typeof(WeaponModRep).IsAssignableFrom(minimumItemModRepresentationType))
{
throw new ArgumentOutOfRangeException("minimumItemModRepresentationType", minimumItemModRepresentationType, "!typeof(WeaponModRep).IsAssignableFrom(minimumItemModRepresentationType)");
}
}
protected override IInventoryItem ConstructItem()
{
return new ITEM_TYPE(this);
}
public Socket GetSocketByName(Socket.Mapped vm, string name)
{
Socket.Slot slot = vm.socketMap[name];
return slot.socket;
}
protected override void InstallToItemModRepresentation(ItemModRepresentation modRep)
{
base.InstallToItemModRepresentation(modRep);
if (this.attachObjectRep != null)
{
GameObject attached = modRep.itemRep.muzzle.InstantiateAsChild(this.attachObjectRep, false);
attached.name = this.attachObjectRep.name;
((WeaponModRep) modRep).SetAttached(attached, false);
}
}
protected override bool InstallToViewModel(ref ModViewModelAddArgs a)
{
if (this.isMesh && !a.isMesh)
{
return base.InstallToViewModel(ref a);
}
if (!this.isMesh && a.isMesh)
{
return base.InstallToViewModel(ref a);
}
if (a.vm == null)
{
Debug.Log("Viewmodel null for item attachment...");
}
if (this.attachObjectVM != null)
{
GameObject obj2;
WeaponModRep modRep = (WeaponModRep) a.modRep;
if (a.isMesh)
{
Socket socketByName = this.GetSocketByName(a.vm, this.attachSocketName);
obj2 = UnityEngine.Object.Instantiate(this.attachObjectVM, socketByName.offset, Quaternion.Euler(socketByName.eulerRotate)) as GameObject;
obj2.transform.parent = socketByName.parent;
obj2.transform.localPosition = socketByName.offset;
obj2.transform.localEulerAngles = socketByName.eulerRotate;
}
else
{
obj2 = this.GetSocketByName(a.vm, this.attachSocketName).InstantiateAsChild(this.attachObjectVM, true);
}
obj2.name = this.attachObjectVM.name;
modRep.SetAttached(obj2, true);
ViewModelAttachment component = obj2.GetComponent<ViewModelAttachment>();
if (component != null)
{
if ((this.socketOverrideName != string.Empty) && (component is VMAttachmentSocketOverride))
{
VMAttachmentSocketOverride @override = (VMAttachmentSocketOverride) component;
this.SetSocketByname(a.vm, this.socketOverrideName, @override.socketOverride);
if (this.modifyZoomOffset)
{
a.vm.punchScalar = this.punchScalar;
a.vm.zoomOffset.z = this.zoomOffsetZ;
}
}
component.viewModel = a.vm;
}
}
return true;
}
protected override void SecureWriteMemberValues(uLink.BitStream stream)
{
base.SecureWriteMemberValues(stream);
stream.Write<string>(this.socketOverrideName, new object[0]);
stream.Write<float>(this.zoomOffsetZ, new object[0]);
stream.Write<bool>(this.isMesh, new object[0]);
stream.Write<float>(this.punchScalar, new object[0]);
stream.Write<bool>(this.modifyZoomOffset, new object[0]);
}
public void SetSocketByname(Socket.Mapped vm, string name, Socket newSocket)
{
vm.socketMap.ReplaceSocket(name, newSocket);
}
protected override void UninstallFromItemModRepresentation(ItemModRepresentation rep)
{
WeaponModRep rep2 = (WeaponModRep) rep;
GameObject attached = rep2.attached;
if (attached != null)
{
rep2.SetAttached(null, false);
UnityEngine.Object.Destroy(attached);
}
base.UninstallFromItemModRepresentation(rep);
}
protected override void UninstallFromViewModel(ref ModViewModelRemoveArgs a)
{
if (this.attachObjectVM != null)
{
WeaponModRep modRep = (WeaponModRep) a.modRep;
GameObject attached = modRep.attached;
ViewModelAttachment component = attached.GetComponent<ViewModelAttachment>();
if (component != null)
{
component.viewModel = null;
}
Socket socketByName = this.GetSocketByName(a.vm, this.attachSocketName);
if (socketByName.attachParent == null)
{
Transform parent = socketByName.parent;
}
if (attached != null)
{
modRep.SetAttached(null, true);
UnityEngine.Object.Destroy(attached.gameObject);
}
}
}
private sealed class ITEM_TYPE : ItemModItem<BaseWeaponModDataBlock>, IInventoryItem, IItemModItem
{
public ITEM_TYPE(BaseWeaponModDataBlock BLOCK) : base(BLOCK)
{
}
int IInventoryItem.AddUses(int count)
{
return base.AddUses(count);
}
bool IInventoryItem.Consume(ref int count)
{
return base.Consume(ref count);
}
void IInventoryItem.Deserialize(uLink.BitStream stream)
{
base.Deserialize(stream);
}
bool IInventoryItem.get_active()
{
return base.active;
}
Character IInventoryItem.get_character()
{
return base.character;
}
float IInventoryItem.get_condition()
{
return base.condition;
}
Controllable IInventoryItem.get_controllable()
{
return base.controllable;
}
Controller IInventoryItem.get_controller()
{
return base.controller;
}
bool IInventoryItem.get_dirty()
{
return base.dirty;
}
bool IInventoryItem.get_doNotSave()
{
return base.doNotSave;
}
IDMain IInventoryItem.get_idMain()
{
return base.idMain;
}
Inventory IInventoryItem.get_inventory()
{
return base.inventory;
}
bool IInventoryItem.get_isInLocalInventory()
{
return base.isInLocalInventory;
}
float IInventoryItem.get_lastUseTime()
{
return base.lastUseTime;
}
float IInventoryItem.get_maxcondition()
{
return base.maxcondition;
}
int IInventoryItem.get_slot()
{
return base.slot;
}
int IInventoryItem.get_uses()
{
return base.uses;
}
float IInventoryItem.GetConditionPercent()
{
return base.GetConditionPercent();
}
bool IInventoryItem.IsBroken()
{
return base.IsBroken();
}
bool IInventoryItem.IsDamaged()
{
return base.IsDamaged();
}
bool IInventoryItem.MarkDirty()
{
return base.MarkDirty();
}
void IInventoryItem.Serialize(uLink.BitStream stream)
{
base.Serialize(stream);
}
void IInventoryItem.set_lastUseTime(float value)
{
base.lastUseTime = value;
}
void IInventoryItem.SetCondition(float condition)
{
base.SetCondition(condition);
}
void IInventoryItem.SetMaxCondition(float condition)
{
base.SetMaxCondition(condition);
}
void IInventoryItem.SetUses(int count)
{
base.SetUses(count);
}
bool IInventoryItem.TryConditionLoss(float probability, float percentLoss)
{
return base.TryConditionLoss(probability, percentLoss);
}
ItemDataBlock IInventoryItem.datablock
{
get
{
return base.datablock;
}
}
}
}