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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
|
using System;
using System.Collections;
using System.Collections.Generic;
using Photon.Pun;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Events;
public class ProjectileHit : RayHit
{
[HideInInspector]
public bool canPushBox = true;
public float force;
public float damage;
public float stun;
public float percentageDamage;
public float movementSlow;
public float shake;
public ObjectsToSpawn[] objectsToSpawn;
public PlayerSkin team;
[HideInInspector]
public Player ownPlayer;
[HideInInspector]
public GameObject ownWeapon;
public AnimationCurve effectOverTimeCurve;
[HideInInspector]
public List<RayHitEffect> effects;
private List<HealthHandler> playersHit = new List<HealthHandler>();
public Color projectileColor = Color.black;
private Action hitAction;
private Action<HitInfo> hitActionWithData;
[HideInInspector]
public bool unblockable;
[HideInInspector]
public bool fullSelfDamage;
[FoldoutGroup("Special", 0)]
public UnityEvent deathEvent;
[FoldoutGroup("Special", 0)]
public bool destroyOnBlock;
[FoldoutGroup("Special", 0)]
public float holdPlayerFor = 0.5f;
[FoldoutGroup("Special", 0)]
public string bulletImmunity = "";
private SpawnedAttack spawnedAttack;
[HideInInspector]
public float sinceReflect = 10f;
[HideInInspector]
public float dealDamageMultiplierr = 1f;
internal bool hasControl;
[HideInInspector]
public PhotonView view;
private MoveTransform move;
[HideInInspector]
public bool bulletCanDealDeamage = true;
[HideInInspector]
public bool isAllowedToSpawnObjects = true;
public bool sendCollisions = true;
public Dictionary<string, Action> customActions = new Dictionary<string, Action>();
public Dictionary<string, Action<Vector2, Vector2>> customActionsV2V2 = new Dictionary<string, Action<Vector2, Vector2>>();
private void Start()
{
move = GetComponent<MoveTransform>();
view = GetComponent<PhotonView>();
effects.AddRange(GetComponentsInChildren<RayHitEffect>());
effects.Sort((RayHitEffect p1, RayHitEffect p2) => p2.priority.CompareTo(p1.priority));
spawnedAttack = GetComponent<SpawnedAttack>();
if ((bool)spawnedAttack && !ownPlayer)
{
ownPlayer = spawnedAttack.spawner;
}
if ((bool)ownPlayer && !fullSelfDamage)
{
StartCoroutine(HoldPlayer(ownPlayer.GetComponent<HealthHandler>()));
}
damage *= base.transform.localScale.x;
force *= Mathf.Pow(damage / 55f, 2f);
}
public void ResortHitEffects()
{
effects.Sort((RayHitEffect p1, RayHitEffect p2) => p2.priority.CompareTo(p1.priority));
}
private IEnumerator HoldPlayer(HealthHandler player)
{
if ((bool)player)
{
playersHit.Add(player);
}
yield return new WaitForSeconds(holdPlayerFor);
if (playersHit.Contains(player))
{
playersHit.Remove(player);
}
}
private void Update()
{
sinceReflect += TimeHandler.deltaTime;
}
public void AddPlayerToHeld(HealthHandler health)
{
StartCoroutine(HoldPlayer(health));
}
public void RemoveOwnPlayerFromPlayersHit()
{
if ((bool)ownPlayer && playersHit.Contains(ownPlayer.GetComponent<HealthHandler>()))
{
playersHit.Remove(ownPlayer.GetComponent<HealthHandler>());
}
}
public override void Hit(HitInfo hit, bool forceCall = false)
{
int num = -1;
if ((bool)hit.transform)
{
PhotonView component = hit.transform.root.GetComponent<PhotonView>();
if ((bool)component)
{
num = component.ViewID;
}
}
int num2 = -1;
if (num == -1)
{
Collider2D[] componentsInChildren = MapManager.instance.currentMap.Map.GetComponentsInChildren<Collider2D>();
for (int i = 0; i < componentsInChildren.Length; i++)
{
if (componentsInChildren[i] == hit.collider)
{
num2 = i;
}
}
}
HealthHandler healthHandler = null;
if ((bool)hit.transform)
{
healthHandler = hit.transform.GetComponent<HealthHandler>();
}
bool flag = false;
if ((bool)healthHandler)
{
if (playersHit.Contains(healthHandler))
{
return;
}
if (view.IsMine && healthHandler.GetComponent<Block>().IsBlocking())
{
flag = true;
}
StartCoroutine(HoldPlayer(healthHandler));
}
if (view.IsMine || forceCall)
{
if (sendCollisions)
{
view.RPC("RPCA_DoHit", RpcTarget.All, hit.point, hit.normal, (Vector2)move.velocity, num, num2, flag);
}
else
{
RPCA_DoHit(hit.point, hit.normal, move.velocity, num, num2, flag);
}
}
}
[PunRPC]
public void RPCA_DoHit(Vector2 hitPoint, Vector2 hitNormal, Vector2 vel, int viewID = -1, int colliderID = -1, bool wasBlocked = false)
{
HitInfo hitInfo = new HitInfo();
if ((bool)move)
{
move.velocity = vel;
}
hitInfo.point = hitPoint;
hitInfo.normal = hitNormal;
hitInfo.collider = null;
if (viewID != -1)
{
PhotonView photonView = PhotonNetwork.GetPhotonView(viewID);
hitInfo.collider = photonView.GetComponentInChildren<Collider2D>();
hitInfo.transform = photonView.transform;
}
else if (colliderID != -1)
{
hitInfo.collider = MapManager.instance.currentMap.Map.GetComponentsInChildren<Collider2D>()[colliderID];
hitInfo.transform = hitInfo.collider.transform;
}
HealthHandler healthHandler = null;
if ((bool)hitInfo.transform)
{
healthHandler = hitInfo.transform.GetComponent<HealthHandler>();
}
if (isAllowedToSpawnObjects)
{
base.transform.position = hitInfo.point;
}
if ((bool)hitInfo.collider)
{
ProjectileHitSurface component = hitInfo.collider.GetComponent<ProjectileHitSurface>();
if ((bool)component && component.HitSurface(hitInfo, base.gameObject) == ProjectileHitSurface.HasToStop.HasToStop)
{
return;
}
}
if ((bool)healthHandler)
{
Block component2 = healthHandler.GetComponent<Block>();
if (wasBlocked)
{
component2.DoBlock(base.gameObject, base.transform.forward, hitInfo.point);
if (destroyOnBlock)
{
DestroyMe();
}
sinceReflect = 0f;
return;
}
CharacterStatModifiers component3 = healthHandler.GetComponent<CharacterStatModifiers>();
if (movementSlow != 0f && !wasBlocked)
{
component3.RPCA_AddSlow(movementSlow);
}
}
float num = 1f;
PlayerVelocity playerVelocity = null;
if ((bool)hitInfo.transform)
{
playerVelocity = hitInfo.transform.GetComponentInParent<PlayerVelocity>();
}
if ((bool)hitInfo.collider)
{
Damagable componentInParent = hitInfo.collider.GetComponentInParent<Damagable>();
if ((bool)componentInParent)
{
if ((bool)healthHandler && percentageDamage != 0f)
{
damage += healthHandler.GetComponent<CharacterData>().maxHealth * percentageDamage;
}
if (hasControl)
{
if (bulletImmunity != "" && (bool)healthHandler)
{
healthHandler.GetComponent<PlayerImmunity>().IsImune(0.1f, (bulletCanDealDeamage ? damage : 1f) * dealDamageMultiplierr, bulletImmunity);
}
if ((bool)componentInParent.GetComponent<DamagableEvent>())
{
componentInParent.CallTakeDamage(base.transform.forward * damage * dealDamageMultiplierr, hitInfo.point, ownWeapon, ownPlayer);
}
else
{
componentInParent.CallTakeDamage(base.transform.forward * (bulletCanDealDeamage ? damage : 1f) * dealDamageMultiplierr, hitInfo.point, ownWeapon, ownPlayer);
}
}
}
}
if ((bool)playerVelocity)
{
float num2 = 1f;
float num3 = Mathf.Clamp(playerVelocity.mass / 100f * num2, 0f, 1f) * num2;
float num4 = 1f;
playerVelocity.AddForce(-playerVelocity.velocity * 0.1f * playerVelocity.mass, ForceMode2D.Impulse);
if ((bool)healthHandler)
{
num *= 3f;
if (hasControl)
{
healthHandler.CallTakeForce(base.transform.forward * num4 * num3 * force);
}
}
}
if (isAllowedToSpawnObjects && !wasBlocked)
{
GamefeelManager.GameFeel(base.transform.forward * num * shake);
DynamicParticles.instance.PlayBulletHit(damage, base.transform, hitInfo, projectileColor);
for (int i = 0; i < objectsToSpawn.Length; i++)
{
ObjectsToSpawn.SpawnObject(base.transform, hitInfo, objectsToSpawn[i], healthHandler, team, damage, spawnedAttack, wasBlocked);
}
base.transform.position = hitInfo.point + hitInfo.normal * 0.01f;
}
if ((bool)hitInfo.transform)
{
NetworkPhysicsObject component4 = hitInfo.transform.GetComponent<NetworkPhysicsObject>();
if ((bool)component4 && canPushBox)
{
component4.BulletPush(base.transform.forward * (force * 0.5f + damage * 100f), hitInfo.transform.InverseTransformPoint(hitInfo.point), spawnedAttack.spawner.data);
}
}
bool flag = false;
if (effects != null && effects.Count != 0)
{
for (int j = 0; j < effects.Count; j++)
{
HasToReturn num5 = effects[j].DoHitEffect(hitInfo);
if (num5 == HasToReturn.hasToReturn)
{
flag = true;
}
if (num5 == HasToReturn.hasToReturnNow)
{
return;
}
}
}
if (!flag)
{
if (hitAction != null)
{
hitAction();
}
if (hitActionWithData != null)
{
hitActionWithData(hitInfo);
}
deathEvent.Invoke();
DestroyMe();
}
}
private void DestroyMe()
{
if ((bool)view)
{
if (view.IsMine)
{
PhotonNetwork.Destroy(base.gameObject);
}
}
else
{
UnityEngine.Object.Destroy(base.gameObject);
}
}
[PunRPC]
public void RPCA_CallCustomAction(string actionKey)
{
customActions[actionKey]();
}
[PunRPC]
public void RPCA_CallCustomActionV2V2(string actionKey, Vector2 v1, Vector2 v2)
{
customActionsV2V2[actionKey](v1, v2);
}
public void AddHitAction(Action action)
{
hitAction = (Action)Delegate.Combine(hitAction, action);
}
public void AddHitActionWithData(Action<HitInfo> action)
{
hitActionWithData = (Action<HitInfo>)Delegate.Combine(hitActionWithData, action);
}
}
|