diff options
Diffstat (limited to 'Thronefall_v1.0/Decompile/UnitRespawnerForBuildings.cs')
-rw-r--r-- | Thronefall_v1.0/Decompile/UnitRespawnerForBuildings.cs | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/Thronefall_v1.0/Decompile/UnitRespawnerForBuildings.cs b/Thronefall_v1.0/Decompile/UnitRespawnerForBuildings.cs new file mode 100644 index 0000000..a405fb5 --- /dev/null +++ b/Thronefall_v1.0/Decompile/UnitRespawnerForBuildings.cs @@ -0,0 +1,113 @@ +using System.Collections.Generic; +using UnityEngine; + +public class UnitRespawnerForBuildings : MonoBehaviour +{ + public Hp hp; + + public List<Hp> units; + + public List<float> timeToRespawnAUnitDependingOnLevel = new List<float>(); + + private float timeTillNextRespawn; + + public BuildSlot myBuildSlot; + + public TaggedObject taggedObject; + + public ProductionBar productionBar; + + [Header("Quick arrange units:")] + public Transform copyUnitPositionsFrom; + + private bool gladiatorSchool; + + private bool elliteWarriors; + + private float gladiatorSchoolSpeed; + + private float elliteWarriorSpeed; + + private float totalTrainingSpeed = 1f; + + [SerializeField] + private Equippable gladiatorSchoolPerk; + + [SerializeField] + private Equippable elliteWarriorsPerk; + + private bool godOfDeathActive; + + private float ResetCooldownTime => timeToRespawnAUnitDependingOnLevel[Mathf.Clamp(myBuildSlot.Level, 0, timeToRespawnAUnitDependingOnLevel.Count - 1)]; + + private void Start() + { + godOfDeathActive = PerkManager.instance.GodOfDeathActive; + timeTillNextRespawn = ResetCooldownTime; + productionBar.UpdateVisual(0f); + gladiatorSchool = PerkManager.IsEquipped(gladiatorSchoolPerk); + elliteWarriors = PerkManager.IsEquipped(elliteWarriorsPerk); + gladiatorSchoolSpeed = PerkManager.instance.gladiatorSchool_TrainingSpeedMultiplyer; + elliteWarriorSpeed = PerkManager.instance.elliteWarriors_TrainingSpeedMultiplyer; + totalTrainingSpeed = 1f * (gladiatorSchool ? gladiatorSchoolSpeed : 1f) * (elliteWarriors ? elliteWarriorSpeed : 1f); + } + + private void Update() + { + if (godOfDeathActive) + { + return; + } + if (hp.KnockedOut) + { + productionBar.UpdateVisual(0f); + } + else if (AtLeastOneUnitIsKnockedOut()) + { + timeTillNextRespawn -= Time.deltaTime; + productionBar.UpdateVisual(1f - timeTillNextRespawn / ResetCooldownTime * totalTrainingSpeed); + if (timeTillNextRespawn <= 0f) + { + timeTillNextRespawn += ResetCooldownTime; + timeTillNextRespawn /= totalTrainingSpeed; + RespawnAKnockedOutUnit(); + } + } + else + { + timeTillNextRespawn = ResetCooldownTime; + timeTillNextRespawn /= totalTrainingSpeed; + productionBar.UpdateVisual(0f); + } + } + + private bool AtLeastOneUnitIsKnockedOut() + { + for (int i = 0; i < units.Count; i++) + { + Hp hp = units[i]; + if (hp.gameObject.activeInHierarchy && hp.KnockedOut) + { + return true; + } + } + return false; + } + + private void RespawnAKnockedOutUnit() + { + for (int i = 0; i < units.Count; i++) + { + Hp hp = units[i]; + if (hp.gameObject.activeInHierarchy && hp.KnockedOut) + { + hp.Revive(); + PathfindMovementPlayerunit component = hp.GetComponent<PathfindMovementPlayerunit>(); + Vector3 position = taggedObject.colliderForBigOjectsToMeasureDistance.ClosestPoint(component.HopePositionOriginal); + hp.transform.position = position; + component.SnapToNavmesh(); + break; + } + } + } +} |