/
DeployableObject.cs
210 lines (187 loc) · 5.46 KB
/
DeployableObject.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
using Facepunch.MeshBatch;
using RustProto;
using RustProto.Helpers;
using System;
using UnityEngine;
[NGCAutoAddScript]
public class DeployableObject : IDMain, IDeployedObjectMain, IServerSaveable, IServerSaveNotify, ICarriableTrans
{
public TransCarrier _carrier;
private EnvDecay _EnvDecay;
public bool cantPlaceOn;
public GameObject clientDeathEffect;
public GameObject corpseObject;
public ulong creatorID;
public bool decayProtector;
public bool doEdgeCheck;
public bool handleDeathHere;
[NonSerialized]
private HealthDimmer healthDimmer;
public float maxEdgeDifferential;
public float maxSlope;
public ulong ownerID;
public string ownerName;
public DeployableObject() : this(IDFlags.Unknown)
{
}
protected DeployableObject(IDFlags flags) : base(flags)
{
this.maxEdgeDifferential = 1f;
this.maxSlope = 30f;
this.ownerName = string.Empty;
}
public void Awake()
{
}
public bool BelongsTo(Controllable controllable)
{
if (controllable == null)
{
return false;
}
PlayerClient playerClient = controllable.playerClient;
if (playerClient == null)
{
return false;
}
return (playerClient.userID == this.ownerID);
}
public void CacheCreator()
{
}
[RPC]
public void Client_OnKilled()
{
if (this.clientDeathEffect != null)
{
GameObject obj2 = UnityEngine.Object.Instantiate(this.clientDeathEffect, base.transform.position, base.transform.rotation) as GameObject;
UnityEngine.Object.Destroy(obj2, 5f);
}
}
[RPC]
public void ClientHealthUpdate(float newHealth)
{
this.healthDimmer.UpdateHealthAmount(this, newHealth, false);
}
public TransCarrier GetCarrier()
{
return this._carrier;
}
[RPC]
public void GetOwnerInfo(ulong creator, ulong owner)
{
this.creatorID = creator;
this.ownerID = owner;
}
public void GrabCarrier()
{
RaycastHit hit;
bool flag;
MeshBatchInstance instance;
Ray ray = new Ray(base.transform.position + ((Vector3) (Vector3.up * 0.01f)), Vector3.down);
if (Facepunch.MeshBatch.MeshBatchPhysics.Raycast(ray, out hit, 5f, out flag, out instance))
{
IDMain main = !flag ? IDBase.GetMain(hit.collider) : instance.idMain;
if (main != null)
{
TransCarrier local = main.GetLocal<TransCarrier>();
if (local != null)
{
local.AddObject(this);
}
}
}
}
void IServerSaveNotify.PostLoad()
{
}
public static bool IsValidLocation(Vector3 location, Vector3 surfaceNormal, UnityEngine.Quaternion rotation, DeployableObject prefab)
{
if (prefab.doEdgeCheck)
{
return false;
}
return (Vector3.Angle(surfaceNormal, Vector3.up) <= prefab.maxSlope);
}
public void OnAddedToCarrier(TransCarrier carrier)
{
this._carrier = carrier;
}
public void OnDestroy()
{
if (this._carrier != null)
{
this._carrier.RemoveObject(this);
this._carrier = null;
}
base.OnDestroy();
}
public void OnDroppedFromCarrier(TransCarrier carrier)
{
this._carrier = null;
}
protected void OnPoolAlive()
{
this.ownerID = 0L;
this.ownerName = string.Empty;
this.creatorID = 0L;
}
protected void OnPoolRetire()
{
this.healthDimmer.Reset();
}
public void ReadObjectSave(ref SavedObject saveobj)
{
if (saveobj.HasDeployable)
{
this.creatorID = saveobj.Deployable.CreatorID;
this.ownerID = saveobj.Deployable.OwnerID;
}
}
public void Touched()
{
TransCarrier carrier = this.GetCarrier();
if (carrier != null)
{
IDMain idMain = carrier.idMain;
if ((idMain != null) && (idMain is StructureComponent))
{
((StructureComponent) idMain).Touched();
}
}
}
public void WriteObjectSave(ref SavedObject.Builder saveobj)
{
using (Recycler<objectDeployable, objectDeployable.Builder> recycler = objectDeployable.Recycler())
{
objectDeployable.Builder builderForValue = recycler.OpenBuilder();
builderForValue.SetCreatorID(this.creatorID);
builderForValue.SetOwnerID(this.ownerID);
saveobj.SetDeployable(builderForValue);
}
using (Recycler<objectICarriableTrans, objectICarriableTrans.Builder> recycler2 = objectICarriableTrans.Recycler())
{
NetEntityID yid;
objectICarriableTrans.Builder builder2 = recycler2.OpenBuilder();
if ((this._carrier != null) && (((int) NetEntityID.Of((MonoBehaviour) this._carrier, out yid)) != 0))
{
builder2.SetTransCarrierID(yid.id);
}
else
{
builder2.ClearTransCarrierID();
}
saveobj.SetCarriableTrans(builder2);
}
}
DeployedObjectInfo IDeployedObjectMain.DeployedObjectInfo
{
get
{
DeployedObjectInfo info;
info.userID = this.ownerID;
info.valid = this.ownerID != 0L;
return info;
}
}
}