summaryrefslogtreecommitdiff
path: root/GameCode/AbyssalCountdown.cs
blob: 062e9208c2cbd4230659616691b3a29914bd4f5b (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
using System;
using Sonigon;
using UnityEngine;
using UnityEngine.UI.ProceduralImage;

public class AbyssalCountdown : MonoBehaviour
{
	public SoundEvent soundAbyssalChargeLoop;

	private bool soundChargeIsPlaying;

	private float soundCounterLast;

	private SoundParameterIntensity soundParameterIntensity = new SoundParameterIntensity(0f, UpdateMode.Continuous);

	[Range(0f, 1f)]
	public float counter;

	public float timeToFill = 10f;

	public float timeToEmpty = 3f;

	public float duration;

	public float hpMultiplier = 2f;

	public ProceduralImage outerRing;

	public ProceduralImage fill;

	public Transform rotator;

	public Transform still;

	private CharacterData data;

	public GameObject[] abyssalObjects;

	private float remainingDuration;

	private bool isAbyssalForm;

	private float startCounter;

	private void Start()
	{
		soundCounterLast = counter;
		data = GetComponentInParent<CharacterData>();
		HealthHandler healthHandler = data.healthHandler;
		healthHandler.reviveAction = (Action)Delegate.Combine(healthHandler.reviveAction, new Action(ResetStuff));
		GetComponentInParent<ChildRPC>().childRPCs.Add("Abyssal", RPCA_Activate);
	}

	private void OnDestroy()
	{
		HealthHandler healthHandler = data.healthHandler;
		healthHandler.reviveAction = (Action)Delegate.Combine(healthHandler.reviveAction, new Action(ResetStuff));
		GetComponentInParent<ChildRPC>().childRPCs.Remove("Abyssal");
		SoundStop();
	}

	private void OnDisable()
	{
		SoundStop();
	}

	private void SoundPlay()
	{
		if (!soundChargeIsPlaying)
		{
			soundChargeIsPlaying = true;
			SoundManager.Instance.Play(soundAbyssalChargeLoop, base.transform, soundParameterIntensity);
		}
	}

	private void SoundStop()
	{
		if (soundChargeIsPlaying)
		{
			soundChargeIsPlaying = false;
			SoundManager.Instance.Stop(soundAbyssalChargeLoop, base.transform);
		}
	}

	private void ResetStuff()
	{
		SoundStop();
		remainingDuration = 0f;
		counter = 0f;
		if (isAbyssalForm)
		{
			for (int i = 0; i < abyssalObjects.Length; i++)
			{
				abyssalObjects[i].gameObject.SetActive(value: false);
			}
			data.maxHealth /= hpMultiplier;
			data.health /= hpMultiplier;
			data.stats.ConfigureMassAndSize();
			isAbyssalForm = false;
			rotator.gameObject.SetActive(value: false);
			still.gameObject.SetActive(value: false);
		}
		SoundStop();
	}

	private void RPCA_Activate()
	{
		remainingDuration = duration;
	}

	private void Update()
	{
		if (soundCounterLast < counter)
		{
			SoundPlay();
		}
		else
		{
			SoundStop();
		}
		soundCounterLast = counter;
		soundParameterIntensity.intensity = counter;
		outerRing.fillAmount = counter;
		fill.fillAmount = counter;
		rotator.transform.localEulerAngles = new Vector3(0f, 0f, 0f - Mathf.Lerp(0f, 360f, counter));
		if (!data.playerVel.simulated)
		{
			startCounter = 1f;
			return;
		}
		startCounter -= TimeHandler.deltaTime;
		if (startCounter > 0f)
		{
			return;
		}
		if (remainingDuration > 0f)
		{
			if (!isAbyssalForm)
			{
				for (int i = 0; i < abyssalObjects.Length; i++)
				{
					abyssalObjects[i].gameObject.SetActive(value: true);
				}
				data.maxHealth *= hpMultiplier;
				data.health *= hpMultiplier;
				data.stats.ConfigureMassAndSize();
				isAbyssalForm = true;
			}
			remainingDuration -= TimeHandler.deltaTime;
			counter = remainingDuration / duration;
			return;
		}
		if (isAbyssalForm)
		{
			for (int j = 0; j < abyssalObjects.Length; j++)
			{
				abyssalObjects[j].gameObject.SetActive(value: false);
			}
			data.maxHealth /= hpMultiplier;
			data.health /= hpMultiplier;
			data.stats.ConfigureMassAndSize();
			isAbyssalForm = false;
		}
		if (data.input.direction == Vector3.zero || data.input.direction == Vector3.down)
		{
			counter += TimeHandler.deltaTime / timeToFill;
		}
		else
		{
			counter -= TimeHandler.deltaTime / timeToEmpty;
		}
		counter = Mathf.Clamp(counter, -0.1f / timeToFill, 1f);
		if (counter >= 1f && data.view.IsMine)
		{
			remainingDuration = duration;
			GetComponentInParent<ChildRPC>().CallFunction("Abyssal");
		}
		if (counter <= 0f)
		{
			rotator.gameObject.SetActive(value: false);
			still.gameObject.SetActive(value: false);
		}
		else
		{
			rotator.gameObject.SetActive(value: true);
			still.gameObject.SetActive(value: true);
		}
	}
}