diff options
Diffstat (limited to 'Thronefall_v1.0/Decompile/DayNightCycle.cs')
-rw-r--r-- | Thronefall_v1.0/Decompile/DayNightCycle.cs | 202 |
1 files changed, 202 insertions, 0 deletions
diff --git a/Thronefall_v1.0/Decompile/DayNightCycle.cs b/Thronefall_v1.0/Decompile/DayNightCycle.cs new file mode 100644 index 0000000..348a641 --- /dev/null +++ b/Thronefall_v1.0/Decompile/DayNightCycle.cs @@ -0,0 +1,202 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class DayNightCycle : MonoBehaviour +{ + public interface IDaytimeSensitive + { + void OnDusk(); + + void OnDawn_AfterSunrise(); + + void OnDawn_BeforeSunrise(); + } + + public enum Timestate + { + Day, + Night + } + + private static DayNightCycle instance; + + public float sunriseTime = 2.5f; + + private Timestate currentTimestate; + + private float currentNightLength; + + private List<IDaytimeSensitive> daytimeSensitiveObjects = new List<IDaytimeSensitive>(); + + private bool afterSunrise = true; + + public static DayNightCycle Instance => instance; + + public Timestate CurrentTimestate => currentTimestate; + + public float CurrentNightLength => currentNightLength; + + public bool AfterSunrise => afterSunrise; + + public int CoinCountToBeHarvested + { + get + { + int num = 0; + foreach (BuildingInteractor playerBuildingInteractor in TagManager.instance.playerBuildingInteractors) + { + if ((bool)playerBuildingInteractor.coinSpawner) + { + num += playerBuildingInteractor.coinSpawner.CoinsLeft; + } + if (playerBuildingInteractor.canBeHarvested) + { + num += playerBuildingInteractor.GoldIncome; + } + } + return num; + } + } + + private void Awake() + { + if (instance != null) + { + Object.Destroy(this); + } + else + { + instance = this; + } + } + + private void Update() + { + if (LocalGamestate.Instance.CurrentState == LocalGamestate.State.InMatch) + { + if (currentTimestate == Timestate.Night) + { + currentNightLength += Time.deltaTime; + } + if (currentTimestate == Timestate.Night && (bool)TagManager.instance && (bool)EnemySpawner.instance && !EnemySpawner.instance.SpawningInProgress && TagManager.instance.CountAllTaggedObjectsWithTag(TagManager.ETag.EnemyOwned) < 1 && base.gameObject.activeInHierarchy) + { + StartCoroutine(SwitchToDayCoroutine()); + } + } + } + + private void DawnCallAfterSunrise() + { + afterSunrise = true; + Hp.ReviveAllKnockedOutPlayerUnitsAndBuildings(); + for (int num = daytimeSensitiveObjects.Count - 1; num >= 0; num--) + { + if (daytimeSensitiveObjects[num] != null) + { + daytimeSensitiveObjects[num].OnDawn_AfterSunrise(); + } + else + { + daytimeSensitiveObjects.RemoveAt(num); + } + } + ThronefallAudioManager.Oneshot(ThronefallAudioManager.AudioOneShot.BuildingRepair); + LevelData levelDataForActiveScene = LevelProgressManager.instance.GetLevelDataForActiveScene(); + int networth = PlayerInteraction.instance.Networth; + networth += TagManager.instance.freeCoins.Count; + networth += CoinCountToBeHarvested; + levelDataForActiveScene.dayToDayNetworth.Add(networth); + PlayerInteraction component = TagManager.instance.Players[0].GetComponent<PlayerInteraction>(); + foreach (Coin freeCoin in TagManager.instance.freeCoins) + { + if (freeCoin.IsFree) + { + freeCoin.SetTarget(component); + } + } + } + + private void DawnCallBeforeSunrise() + { + afterSunrise = false; + for (int num = daytimeSensitiveObjects.Count - 1; num >= 0; num--) + { + if (daytimeSensitiveObjects[num] != null) + { + daytimeSensitiveObjects[num].OnDawn_BeforeSunrise(); + } + else + { + daytimeSensitiveObjects.RemoveAt(num); + } + } + ThronefallAudioManager.Oneshot(ThronefallAudioManager.AudioOneShot.NightSurvived); + } + + private void DuskCall() + { + afterSunrise = false; + currentNightLength = 0f; + for (int num = daytimeSensitiveObjects.Count - 1; num >= 0; num--) + { + if (daytimeSensitiveObjects[num] != null) + { + daytimeSensitiveObjects[num].OnDusk(); + } + else + { + daytimeSensitiveObjects.RemoveAt(num); + } + } + } + + public void ToggleDaytime() + { + if (currentTimestate == Timestate.Day) + { + currentTimestate = Timestate.Night; + DuskCall(); + } + else + { + currentTimestate = Timestate.Day; + DawnCallBeforeSunrise(); + DawnCallAfterSunrise(); + } + } + + private IEnumerator SwitchToDayCoroutine() + { + if (currentTimestate == Timestate.Night) + { + currentTimestate = Timestate.Day; + DawnCallBeforeSunrise(); + yield return new WaitForSeconds(sunriseTime); + DawnCallAfterSunrise(); + if (EnemySpawner.instance.Wavenumber >= EnemySpawner.instance.waves.Count - 1) + { + LocalGamestate.Instance.SetState(LocalGamestate.State.AfterMatchVictory); + } + } + } + + public void SwitchToNight() + { + if (currentTimestate != Timestate.Night) + { + currentTimestate = Timestate.Night; + DuskCall(); + } + } + + public void RegisterDaytimeSensitiveObject(IDaytimeSensitive obj) + { + daytimeSensitiveObjects.Add(obj); + } + + public void UnregisterDaytimeSensitiveObject(IDaytimeSensitive obj) + { + daytimeSensitiveObjects.Remove(obj); + } +} |