|
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISS.Scheduling;
- using SUISSEngine;
- using UnityEngine;
-
- public class CIGResidentialBuilding : CIGBuilding
- {
- public int MaxPeople
- {
- get
- {
- return this.currentMaxPeople;
- }
- protected set
- {
- int num = value - this.currentMaxPeople;
- this.currentMaxPeople = value;
- if (num != 0)
- {
- base.IslandState.AddHousing(num);
- }
- }
- }
-
- public int People
- {
- get
- {
- return this.currentPeople;
- }
- protected set
- {
- int num = value - this.currentPeople;
- this.currentPeople = value;
- if (num != 0)
- {
- base.IslandState.AddPopulation(num);
- }
- }
- }
-
- private IEnumerator ResidentialBehaviour()
- {
- bool changed = true;
- for (;;)
- {
- yield return Timing.time + ((!changed) ? this.UnchangedWaitTime : this.ChangedWaitTime);
- changed = this.UpdatePeople();
- }
- yield break;
- }
-
- protected override void OnDestroy()
- {
- if (SingletonMonobehaviour<Scheduler>.IsAvailable)
- {
- this.StopResidentialBehavior();
- }
- base.OnDestroy();
- }
-
- protected virtual double UnchangedWaitTime
- {
- get
- {
- return (double)UnityEngine.Random.Range(2f, 30f);
- }
- }
-
- protected virtual double ChangedWaitTime
- {
- get
- {
- return (double)UnityEngine.Random.Range(1f, 3f);
- }
- }
-
- protected bool UpdatePeople()
- {
- int num = this.People;
- if (this.checkForRoad && !base.CheckForRoad())
- {
- num--;
- }
- else if (base.IslandState.Population > base.IslandState.AvailableHappiness)
- {
- num--;
- }
- else if (base.IslandState.Population < base.IslandState.AvailableHappiness)
- {
- num++;
- }
- num = Math.Max(Math.Min(num, this.MaxPeople), 0);
- if (num != this.People)
- {
- this.People = num;
- this.serializing.Serialize();
- return true;
- }
- return false;
- }
-
- public override bool InfoRequiresFrequentRefresh
- {
- get
- {
- return (base.state != BuildingState.Preview && base.state == BuildingState.Normal && !base.IsUpgrading) || base.InfoRequiresFrequentRefresh;
- }
- }
-
- public override bool CanSpeedup
- {
- get
- {
- return (base.state == BuildingState.Preview || base.state != BuildingState.Normal || base.IsUpgrading) && base.CanSpeedup;
- }
- }
-
- public override ILocalizedString InfoText()
- {
- ILocalizedString localizedString;
- if (base.state == BuildingState.Preview)
- {
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- base.InfoText(),
- Localization.LiteralNewLineString,
- Localization.Key("people"),
- Localization.LiteralSemiColonSpaceString,
- Localization.Integer(this.maxPeopleBaseValue),
- Localization.LiteralNewLineString,
- Localization.Key("construction_time"),
- Localization.LiteralSemiColonSpaceString,
- Localization.TimeSpan(TimeSpan.FromSeconds((double)this.constructionTime), false)
- });
- if (this.maxFacilities > 0)
- {
- int num = SingletonMonobehaviour<CIGGameStats>.Instance.NumberOf(base.CachedName);
- if (this.PurchasePrice.Contains("Cash"))
- {
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- localizedString,
- Localization.LiteralNewLineString,
- Localization.Format(Localization.Key("building_max_facilities"), new ILocalizedString[]
- {
- Localization.Integer(this.maxFacilities)
- })
- });
- }
- else if (num > 0)
- {
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- localizedString,
- Localization.LiteralNewLineString,
- Localization.Format(Localization.Key("building_costs_gold_max_facilities"), new ILocalizedString[]
- {
- Localization.Integer(num)
- })
- });
- }
- }
- return localizedString;
- }
- if (base.state != BuildingState.Normal || base.IsUpgrading)
- {
- return base.InfoText();
- }
- if (this.checkForRoad && !base.CheckForRoad())
- {
- return Localization.Key("building_needs_road");
- }
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- Localization.Format(Localization.Key("residential_people"), new ILocalizedString[]
- {
- Localization.Integer(this.People),
- Localization.Integer(this.MaxPeople)
- }),
- Localization.LiteralNewLineString,
- Localization.Format(Localization.Key("building_current_upgrade_level"), new ILocalizedString[]
- {
- Localization.Integer(base.CurrentLevel),
- Localization.Integer(base.GetMaxLevel())
- })
- });
- if (this.CanUpgrade)
- {
- localizedString = Localization.Concat(new ILocalizedString[]
- {
- localizedString,
- Localization.LiteralNewLineString,
- Localization.Format(Localization.Key("building_upgrade_option"), new ILocalizedString[]
- {
- Localization.Integer(base.CurrentLevel + 1),
- this.UpgradeCost.LocalizedString()
- }),
- Localization.LiteralNewLineString,
- Localization.Format(Localization.Key("building_upgrade_option_residential"), new ILocalizedString[]
- {
- Localization.Integer(this.UpgradePeople(base.CurrentLevel + 1))
- })
- });
- }
- return localizedString;
- }
-
- public override List<BuildingProperty> ShownProperties
- {
- get
- {
- List<BuildingProperty> shownProperties = base.ShownProperties;
- shownProperties.Add(BuildingProperty.People);
- return shownProperties;
- }
- }
-
- public override Currencies UpgradeCost
- {
- get
- {
- Currencies result;
- try
- {
- decimal num = this.baseUpgradeCost.GetValue("Cash");
- int num2 = (!this.activatable) ? 0 : -1;
- num *= this._upgradeCostFactor[base.CurrentLevel + 1 + num2] * 0.01m;
- result = new Currencies("Cash", Math.Ceiling(num));
- }
- catch (Exception ex)
- {
- throw new Exception(string.Format("[{0}|{2}]: {1}", base.name, ex.Message, this.stringReference), ex);
- }
- return result;
- }
- }
-
- public override Currencies PurchasePrice
- {
- get
- {
- Currencies purchasePrice = base.PurchasePrice;
- if (purchasePrice.Contains("Cash"))
- {
- return purchasePrice * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.ResidentialBuildingCostCashMultiplier;
- }
- return purchasePrice * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.ResidentialBuildingCostGoldMultiplier;
- }
- }
-
- public int UpgradePeople(int toLevel)
- {
- if (base.GetMaxLevel() != 0)
- {
- int val = Math.Max(0, toLevel - base.CurrentLevel);
- return Math.Max(val, this.maxPeopleBaseValue + toLevel * this.maxPeopleBaseValue / 5 - this.currentMaxPeople);
- }
- return 0;
- }
-
- private void StartResidentialBehavior()
- {
- SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._behaviourRoutine = this.ResidentialBehaviour(), base.gameObject);
- }
-
- private void StopResidentialBehavior()
- {
- if (this._behaviourRoutine != null)
- {
- SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._behaviourRoutine);
- this._behaviourRoutine = null;
- }
- }
-
- protected override void OnSerialize(Dictionary<string, object> values)
- {
- base.OnSerialize(values);
- values["people"] = this.People;
- values["maxPeople"] = this.MaxPeople;
- if (this._maxPeopleWhenDemolishStarted != 0)
- {
- values["maxPeopleWhenDemolishStarted"] = this._maxPeopleWhenDemolishStarted;
- }
- }
-
- protected override void OnDeserialize(Dictionary<string, object> values)
- {
- base.OnDeserialize(values);
- if (values.ContainsKey("people"))
- {
- this.currentPeople = (int)values["people"];
- }
- if (values.ContainsKey("maxPeople"))
- {
- this.currentMaxPeople = (int)values["maxPeople"];
- }
- if (values.ContainsKey("maxPeopleWhenDemolishStarted"))
- {
- this._maxPeopleWhenDemolishStarted = (int)values["maxPeopleWhenDemolishStarted"];
- }
- }
-
- protected override void OnDeserialized()
- {
- base.OnDeserialized();
- if (base.state == BuildingState.Normal)
- {
- this.StartResidentialBehavior();
- }
- }
-
- protected override void OnConstructionCompleted()
- {
- base.OnConstructionCompleted();
- this.MaxPeople = this.maxPeopleBaseValue;
- this.StartResidentialBehavior();
- }
-
- protected override void OnDemolishStarted()
- {
- base.OnDemolishStarted();
- this.StopResidentialBehavior();
- this._maxPeopleWhenDemolishStarted = this.MaxPeople;
- int num = 0;
- this.People = num;
- this.MaxPeople = num;
- }
-
- protected override void OnDemolishCancelled()
- {
- base.OnDemolishCancelled();
- this.MaxPeople = this._maxPeopleWhenDemolishStarted;
- this._maxPeopleWhenDemolishStarted = 0;
- this.StartResidentialBehavior();
- }
-
- protected override void OnUpgradeCompleted(double upgradedTime)
- {
- base.OnUpgradeCompleted(upgradedTime);
- this.MaxPeople += this.UpgradePeople(base.CurrentLevel);
- }
-
- public int maxPeopleBaseValue;
-
- private int currentMaxPeople;
-
- private int currentPeople;
-
- private int _maxPeopleWhenDemolishStarted;
-
- private IEnumerator _behaviourRoutine;
-
- private readonly int[] _upgradeCostFactor = new int[]
- {
- 100,
- 20,
- 28,
- 39,
- 55,
- 77,
- 108,
- 151,
- 211,
- 295,
- 413,
- 496,
- 595,
- 714,
- 857,
- 1028,
- 1234,
- 1481,
- 1777,
- 2132,
- 2558
- };
- }
|