/// <summary> /// Tries to damage the building if unlucky. /// </summary> private void CheckForDisaster() { //Creates a list of potential disasters List <BuildingDistaster> disasters = new List <BuildingDistaster>(); disasters.AddRange(thisBuilding.potentialDisasters); disasters.AddRange(tile.properties.environmentalDisaster); foreach (BuildingDistaster disaster in disasters) { // If the building isn't already broken and the risk returns true a disaster occurs. if (durability > 0 && SoulTycoon.AttemptRisk(disaster.risk)) { //Gameplay implications int damageDealt = (int)SoulTycoon.VariableValue(disaster.damageBase, disaster.damageVariance); durability = Mathf.Max(durability - damageDealt, 0); //Play particle effects SmokeParticles.Emit(15); if (durability <= 0) { SmokeParticles.Play(); } //Create a notifiaction about the disaster. GameObject go = Instantiate(Resources.Load <GameObject>("Disaster"), transform.position - new Vector3(0, 0, 1), Quaternion.identity); TMPro.TextMeshPro textMesh = go.GetComponent <TMPro.TextMeshPro>(); textMesh.SetText(string.Format(durability > 0 ? "{0}!\nIntegrity {2}%" : "{0}\nRepairs needed!", disaster.name, damageDealt, Mathf.Max((float)durability / thisBuilding.durability * 100, 0).ToString("N1"))); textMesh.color = new Color(1f, 0.7f, 0.7f); //Only one disaster can occur per hour so we stop running through the foreach loop here. break; } } }
/// <summary> /// Will add currency to the building's storage. Cannot store past the buildings limit. /// </summary> private void YieldCurrency() { heldCurrency = (uint)Mathf.Min(thisBuilding.maxCurrency, heldCurrency + SoulTycoon.VariableValue(thisBuilding.yieldBase, thisBuilding.yieldVariance)); var emission = GoldParticles.emission; emission.rateOverTime = new ParticleSystem.MinMaxCurve(Mathf.Log(heldCurrency, 1.3f) + 3); }