diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/AbyssalCountdown.cs |
+ init
Diffstat (limited to 'GameCode/AbyssalCountdown.cs')
-rw-r--r-- | GameCode/AbyssalCountdown.cs | 189 |
1 files changed, 189 insertions, 0 deletions
diff --git a/GameCode/AbyssalCountdown.cs b/GameCode/AbyssalCountdown.cs new file mode 100644 index 0000000..062e920 --- /dev/null +++ b/GameCode/AbyssalCountdown.cs @@ -0,0 +1,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); + } + } +} |