-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectileLogic.cs
181 lines (175 loc) · 7.16 KB
/
ProjectileLogic.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Fusion;
public class ProjectileLogic : NetworkBehaviour
{
public bool isExplosive = false;
public bool isChain = false;
public bool isDOT = false;
public bool isAOEDOT = false;
public bool isTargeted = false;
public bool isRolltimed = false;
public GameObject targetedObject = null;
public float radius;
public float aoeMod = 1f;
public string targetType;
public string friendly;
public float damage;
public int punchThrough;
public float range;
private float timer;
private TickTimer life;
public NetworkPrefabRef hitEffect;
public UnitStats stats;
public Dictionary<string, int> onHits;
private void OnTriggerEnter(Collider other)
{
//Debug.Log("HIT!");
if (Object != null)
if (!Runner.IsServer)
return;
if (isTargeted)
{
if (other.gameObject == targetedObject)
{
other.gameObject.GetComponent<UnitStats>().TakeDamage(damage, stats, onHits);
Runner.Spawn(hitEffect, transform.position, transform.rotation);
Runner.Despawn(Object);
}
}
else if (isRolltimed)
{
return;
}
else if (isAOEDOT)
{
if (LayerMask.LayerToName(other.gameObject.layer) != friendly)
{
Collider[] hitTargets = Physics.OverlapSphere(transform.position, radius, LayerMask.GetMask(targetType));
void AdjustExplosion(NetworkRunner runner, NetworkObject obj)
{ obj.gameObject.GetComponent<NetworkScale>().scale *= radius; }
if (hitEffect != null)
{
NetworkObject ex = Runner.Spawn(hitEffect, transform.position, transform.rotation *
Quaternion.Euler(-90, 0, 0),
inputAuthority: null, AdjustExplosion, predictionKey: null);
}
foreach (Collider c in hitTargets)
{
//Debug.Log("Hit a player collider");
c.GetComponent<UnitStats>().TakeTotalDot(damage);
}
Runner.Despawn(Object);
}
}
else if (isExplosive)
{
//Debug.Log("in explosive");
//! Explosive logic
if (LayerMask.LayerToName(other.gameObject.layer) != friendly)
{
Collider[] hitTargets = Physics.OverlapSphere(transform.position, radius, LayerMask.GetMask(targetType));
void AdjustExplosion(NetworkRunner runner, NetworkObject obj)
{ obj.gameObject.GetComponent<NetworkScale>().scale *= radius; }
if (hitEffect != null)
{
NetworkObject ex = Runner.Spawn(hitEffect, transform.position, transform.rotation *
Quaternion.Euler(-90, 0, 0),
inputAuthority: null, AdjustExplosion, predictionKey: null);
}
foreach (Collider c in hitTargets)
{
//Debug.Log("Hit a player collider");
if (c.gameObject == other.gameObject)
c.gameObject.GetComponent<UnitStats>().TakeDamage((damage * aoeMod) + damage, stats, onHits);
else
c.gameObject.GetComponent<UnitStats>().TakeDamage(damage * aoeMod, stats, onHits);
}
Runner.Despawn(Object);
}
}
else if (isChain)
{
//! Chain logic
if (LayerMask.LayerToName(other.gameObject.layer) == targetType)
{
//Debug.Log("HIT!");
other.gameObject.GetComponent<UnitStats>().TakeDamage(damage, stats, onHits);
Runner.Spawn(hitEffect, transform.position, transform.rotation);
punchThrough--;
if (punchThrough <= 0)
Runner.Despawn(Object);
}
}
else if (isDOT)
{
//! DOT logic
if (LayerMask.LayerToName(other.gameObject.layer) == targetType)
{
//Debug.Log("HIT!");
other.gameObject.GetComponent<UnitStats>().TakeTotalDot(damage);
other.gameObject.GetComponent<UnitStats>().TakeDamage(damage, stats, onHits);
Runner.Spawn(hitEffect, transform.position, transform.rotation);
Runner.Despawn(Object);
}
}
else
{
//! Basic logic
if (LayerMask.LayerToName(other.gameObject.layer) == targetType)
{
//Debug.Log("HIT!");
other.gameObject.GetComponent<UnitStats>().TakeDamage(damage, stats, onHits);
Runner.Spawn(hitEffect, transform.position, transform.rotation);
Runner.Despawn(Object);
}
}
}
public override void FixedUpdateNetwork()
{
base.FixedUpdateNetwork();
if (life.Expired(Runner))
{
if (isRolltimed)
{
Collider[] hitTargets = Physics.OverlapSphere(transform.position, radius, LayerMask.GetMask(targetType));
void AdjustExplosion(NetworkRunner runner, NetworkObject obj)
{ obj.gameObject.GetComponent<NetworkScale>().scale *= radius; }
if (hitEffect != null)
{
NetworkObject ex = Runner.Spawn(hitEffect, transform.position, transform.rotation *
Quaternion.Euler(-90, 0, 0),
inputAuthority: null, AdjustExplosion, predictionKey: null);
}
foreach (Collider c in hitTargets)
{
//Debug.Log("Hit a player collider");
c.GetComponent<UnitStats>().TakeDamage(damage, stats, onHits);
}
}
Runner.Despawn(Object);
}
}
public void SetUp(bool isExplosive, float radius, float aoeMod, string target, string friendly,
float damage, float range, int punchThrough)
{
this.isExplosive = isExplosive;
this.radius = radius;
this.aoeMod = aoeMod;
this.friendly = friendly;
this.targetType = target;
this.damage = damage;
this.range = range;
this.punchThrough = punchThrough;
life = TickTimer.CreateFromSeconds(Runner, this.range / 10f);
}
public void SetUp(string target, float damage, float range, int punchThrough)
{
this.targetType = target;
this.damage = damage;
this.range = range;
this.punchThrough = punchThrough;
life = TickTimer.CreateFromSeconds(Runner, this.range / 10f);
}
}