summaryrefslogtreecommitdiff
path: root/GameCode/CharacterStatModifiers.cs
blob: 9122d66bc990fc9b24e72e43c1a490743deb2ff3 (plain)
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
using System;
using System.Collections.Generic;
using Photon.Pun;
using Sonigon;
using UnityEngine;

public class CharacterStatModifiers : MonoBehaviour
{
	[Header("Sounds")]
	public SoundEvent soundCharacterSlowFreeze;

	private float soundSlowTime;

	private float soundSlowSpeedSec = 0.3f;

	[Header("Settings")]
	public GameObject AddObjectToPlayer;

	[HideInInspector]
	public List<GameObject> objectsAddedToPlayer;

	[Header("Multiply")]
	public float sizeMultiplier = 1f;

	public float health = 1f;

	public float movementSpeed = 1f;

	public float jump = 1f;

	public float gravity = 1f;

	public float slow;

	public float slowSlow;

	public float fastSlow;

	[Header("Add")]
	public float secondsToTakeDamageOver;

	public int numberOfJumps;

	public float regen;

	public float lifeSteal;

	public bool refreshOnDamage;

	public bool automaticReload = true;

	public int respawns;

	[HideInInspector]
	public int remainingRespawns;

	[HideInInspector]
	public float tasteOfBloodSpeed = 1f;

	[HideInInspector]
	public float rageSpeed = 1f;

	public float attackSpeedMultiplier = 1f;

	private WasDealtDamageEffect[] wasDealtDamageEffects;

	private DealtDamageEffect[] dealtDamageEffects;

	private CharacterData data;

	public ParticleSystem slowPart;

	private float soundBigThreshold = 1.5f;

	public Action<Vector2, bool> DealtDamageAction;

	public Action<Vector2, bool> WasDealtDamageAction;

	public Action<int> OnReloadDoneAction;

	public Action<int> OutOfAmmpAction;

	internal float sinceDealtDamage;

	public bool SoundTransformScaleThresholdReached()
	{
		if (base.transform.localScale.x > soundBigThreshold)
		{
			return true;
		}
		return false;
	}

	private void Start()
	{
		data = GetComponent<CharacterData>();
	}

	public float GetSlow()
	{
		return Mathf.Clamp(slow, 0f, 0.9f);
	}

	private void Update()
	{
		attackSpeedMultiplier = tasteOfBloodSpeed * rageSpeed;
		sinceDealtDamage += TimeHandler.deltaTime;
		if ((bool)data && !data.isPlaying)
		{
			sinceDealtDamage = 100f;
		}
		slow = slowSlow;
		if (fastSlow > slowSlow)
		{
			slow = fastSlow;
		}
		if (slowSlow > 0f)
		{
			slowSlow = Mathf.Clamp(slowSlow - TimeHandler.deltaTime * 0.3f, 0f, 10f);
		}
		if (fastSlow > 0f)
		{
			fastSlow = Mathf.Clamp(fastSlow - TimeHandler.deltaTime * 2f, 0f, 1f);
		}
	}

	public void DealtDamage(Vector2 damage, bool selfDamage, Player damagedPlayer = null)
	{
		if (lifeSteal != 0f && !selfDamage)
		{
			GetComponent<HealthHandler>().Heal(damage.magnitude * lifeSteal);
		}
		if (refreshOnDamage)
		{
			GetComponent<Holding>().holdable.GetComponent<Weapon>().sinceAttack = float.PositiveInfinity;
		}
		if (DealtDamageAction != null)
		{
			DealtDamageAction(damage, selfDamage);
		}
		if ((bool)damagedPlayer)
		{
			data.lastDamagedPlayer = damagedPlayer;
		}
		if (!selfDamage)
		{
			sinceDealtDamage = 0f;
		}
		if (dealtDamageEffects != null)
		{
			for (int i = 0; i < dealtDamageEffects.Length; i++)
			{
				dealtDamageEffects[i].DealtDamage(damage, selfDamage, damagedPlayer);
			}
		}
	}

	internal void ResetStats()
	{
		for (int i = 0; i < objectsAddedToPlayer.Count; i++)
		{
			UnityEngine.Object.Destroy(objectsAddedToPlayer[i]);
		}
		objectsAddedToPlayer.Clear();
		data.health = 100f;
		data.maxHealth = 100f;
		sizeMultiplier = 1f;
		health = 1f;
		movementSpeed = 1f;
		jump = 1f;
		gravity = 1f;
		slow = 0f;
		slowSlow = 0f;
		fastSlow = 0f;
		secondsToTakeDamageOver = 0f;
		numberOfJumps = 0;
		regen = 0f;
		lifeSteal = 0f;
		respawns = 0;
		refreshOnDamage = false;
		automaticReload = true;
		tasteOfBloodSpeed = 1f;
		rageSpeed = 1f;
		attackSpeedMultiplier = 1f;
		WasUpdated();
		ConfigureMassAndSize();
	}

	public void WasDealtDamage(Vector2 damage, bool selfDamage)
	{
		if (WasDealtDamageAction != null)
		{
			WasDealtDamageAction(damage, selfDamage);
		}
		if (wasDealtDamageEffects != null)
		{
			for (int i = 0; i < wasDealtDamageEffects.Length; i++)
			{
				wasDealtDamageEffects[i].WasDealtDamage(damage, selfDamage);
			}
		}
	}

	public void WasUpdated()
	{
		GetComponent<ForceMultiplier>().multiplier = 1f / base.transform.root.localScale.x;
		wasDealtDamageEffects = GetComponentsInChildren<WasDealtDamageEffect>();
		dealtDamageEffects = GetComponentsInChildren<DealtDamageEffect>();
	}

	public void AddSlowAddative(float slowToAdd, float maxValue = 1f, bool isFastSlow = false)
	{
		if (data.block.IsBlocking())
		{
			return;
		}
		DoSlowDown(slowToAdd);
		if (isFastSlow)
		{
			if (fastSlow < maxValue)
			{
				fastSlow += slowToAdd;
				fastSlow = Mathf.Clamp(slow, 0f, maxValue);
			}
		}
		else if (slowSlow < maxValue)
		{
			slowSlow += slowToAdd;
			slowSlow = Mathf.Clamp(slowSlow, 0f, maxValue);
		}
	}

	[PunRPC]
	public void RPCA_AddSlow(float slowToAdd, bool isFastSlow = false)
	{
		DoSlowDown(slowToAdd);
		if (isFastSlow)
		{
			fastSlow = Mathf.Clamp(fastSlow, slowToAdd, 1f);
		}
		else
		{
			slowSlow = Mathf.Clamp(slowSlow, slowToAdd, 10f);
		}
	}

	private void DoSlowDown(float newSlow)
	{
		if (soundSlowTime + soundSlowSpeedSec < Time.time)
		{
			soundSlowTime = Time.time;
			SoundManager.Instance.Play(soundCharacterSlowFreeze, base.transform);
		}
		float num = Mathf.Clamp(newSlow - slow, 0f, 1f);
		slowPart.Emit((int)Mathf.Clamp((newSlow * 0.1f + num * 0.7f) * 50f, 1f, 50f));
		data.playerVel.velocity *= 1f - num * 1f;
		data.sinceGrounded *= 1f - num * 1f;
	}

	internal void ConfigureMassAndSize()
	{
		base.transform.localScale = Vector3.one * 1.2f * Mathf.Pow(data.maxHealth / 100f * 1.2f, 0.2f) * sizeMultiplier;
		data.playerVel.mass = 100f * Mathf.Pow(data.maxHealth / 100f * 1.2f, 0.8f) * sizeMultiplier;
	}

	internal void OnReload(int bulletsReloaded)
	{
		if (OnReloadDoneAction != null)
		{
			OnReloadDoneAction(bulletsReloaded);
		}
	}

	internal void OnOutOfAmmp(int maxAmmo)
	{
		if (OutOfAmmpAction != null)
		{
			OutOfAmmpAction(maxAmmo);
		}
	}
}