using System; using System.Collections.Generic; using CIG.Translation; using CIGEnums; using SUISS.Core; using SUISSEngine; public class CIGCommunityBuilding : CIGBuilding { protected override void OnDeserialized() { base.OnDeserialized(); if (base.state == BuildingState.Normal) { this.HasRoad = (!this.checkForRoad || base.CheckForRoad()); } } public override Currencies PurchasePrice { get { Currencies purchasePrice = base.PurchasePrice; if (purchasePrice.Contains("Cash")) { return purchasePrice * SingletonMonobehaviour.Instance.Multipliers.CommunityBuildingCostCashMultiplier; } return purchasePrice * SingletonMonobehaviour.Instance.Multipliers.CommunityBuildingCostGoldMultiplier; } } public override int Happiness { get { return base.Happiness; } protected set { int num = value - base.Happiness; base.Happiness = value; if (!this.HasRoad && num != 0) { base.IslandState.AddHappiness(-num); } } } public override bool HasRoad { get { return base.HasRoad || !this.checkForRoad; } protected set { bool hasRoad = base.HasRoad; base.HasRoad = value; if (hasRoad != value) { if (!this.HasRoad) { base.IslandState.AddHappiness(-this.Happiness); } else { base.IslandState.AddHappiness(this.Happiness); } } } } public override bool CanUpgrade { get { CIGExpansions.ExpansionBlock blockForIndex = this.expansions.reference.GetBlockForIndex(this.tile.index); return (blockForIndex == null || blockForIndex.Unlocked) && (!this.checkForRoad || this.HasRoad) && base.CanUpgrade; } } public override ILocalizedString ReasonWhyCantUpgrade(out ILocalizedString title) { CIGExpansions.ExpansionBlock blockForIndex = this.expansions.reference.GetBlockForIndex(this.tile.index); if (!blockForIndex.Unlocked) { title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building")); return Localization.Key("buy_expansion_first"); } if (this.checkForRoad && !this.HasRoad) { title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building")); return Localization.Key("building_needs_road"); } return base.ReasonWhyCantUpgrade(out title); } public override bool InfoRequiresFrequentRefresh { get { return (base.IsUpgrading || (this.activatable && !this.Activated) || base.state == BuildingState.Preview || base.state != BuildingState.Normal) && base.InfoRequiresFrequentRefresh; } } public override bool CanSpeedup { get { return (base.IsUpgrading || (this.activatable && !this.Activated) || base.state == BuildingState.Preview || base.state != BuildingState.Normal) && base.CanSpeedup; } } public override ILocalizedString InfoText() { if (base.IsUpgrading) { return base.InfoText(); } if ((this.activatable && !this.Activated) || base.state == BuildingState.Preview) { return Localization.Concat(new ILocalizedString[] { base.InfoText(), Localization.LiteralNewLineString, Localization.Format(Localization.Key("happiness_points"), new ILocalizedString[] { Localization.Integer(this.baseHappinessValue) }) }); } if (base.state != BuildingState.Normal) { return base.InfoText(); } if (this.checkForRoad && !base.CheckForRoad()) { return Localization.Key("building_needs_road"); } int num = (!this.activatable) ? 0 : -1; ILocalizedString result = Localization.Concat(new ILocalizedString[] { Localization.Format(Localization.Key("happiness_points"), new ILocalizedString[] { Localization.Integer(this.Happiness) }), Localization.LiteralNewLineString, Localization.Format(Localization.Key("building_current_upgrade_level"), new ILocalizedString[] { Localization.Integer(base.CurrentLevel + num), Localization.Integer(base.GetMaxLevel() + num) }) }); if (this.CanUpgrade) { result = Localization.Concat(new ILocalizedString[] { Localization.LiteralNewLineString, Localization.Format(Localization.Key("building_upgrade_option"), new ILocalizedString[] { Localization.Integer(base.CurrentLevel + 1 + num), this.UpgradeCost.LocalizedString() }), Localization.LiteralNewLineString, Localization.Format(Localization.Key("building_upgrade_option_happiness"), new ILocalizedString[] { Localization.Integer(this.UpgradeHappiness(base.CurrentLevel + 1)) }) }); } return result; } public override List ShownProperties { get { List shownProperties = base.ShownProperties; shownProperties.Add(BuildingProperty.Happiness); return shownProperties; } } public override Currencies UpgradeCost { get { if (this.activatable && !this.Activated) { return base.UpgradeCost; } 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 int UpgradeHappiness(int toLevel) { if (!this.activatable) { return base.UpgradeHappiness(toLevel); } if (base.CurrentLevel == 0 && toLevel == 1) { return this.baseHappinessValue; } return base.UpgradeHappiness(toLevel - 1); } private MagicalReference expansions = new MagicalReference(); private readonly int[] _upgradeCostFactor = new int[] { 100, 35, 44, 55, 69, 86, 108, 135, 169, 211, 264, 317, 380, 456, 547, 656, 787, 944, 1133, 1360, 1632 }; }