You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

248 line
6.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISSEngine;
  7. public class CIGCommunityBuilding : CIGBuilding
  8. {
  9. protected override void OnDeserialized()
  10. {
  11. base.OnDeserialized();
  12. if (base.state == BuildingState.Normal)
  13. {
  14. this.HasRoad = (!this.checkForRoad || base.CheckForRoad());
  15. }
  16. }
  17. public override Currencies PurchasePrice
  18. {
  19. get
  20. {
  21. Currencies purchasePrice = base.PurchasePrice;
  22. if (purchasePrice.Contains("Cash"))
  23. {
  24. return purchasePrice * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.CommunityBuildingCostCashMultiplier;
  25. }
  26. return purchasePrice * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.CommunityBuildingCostGoldMultiplier;
  27. }
  28. }
  29. public override int Happiness
  30. {
  31. get
  32. {
  33. return base.Happiness;
  34. }
  35. protected set
  36. {
  37. int num = value - base.Happiness;
  38. base.Happiness = value;
  39. if (!this.HasRoad && num != 0)
  40. {
  41. base.IslandState.AddHappiness(-num);
  42. }
  43. }
  44. }
  45. public override bool HasRoad
  46. {
  47. get
  48. {
  49. return base.HasRoad || !this.checkForRoad;
  50. }
  51. protected set
  52. {
  53. bool hasRoad = base.HasRoad;
  54. base.HasRoad = value;
  55. if (hasRoad != value)
  56. {
  57. if (!this.HasRoad)
  58. {
  59. base.IslandState.AddHappiness(-this.Happiness);
  60. }
  61. else
  62. {
  63. base.IslandState.AddHappiness(this.Happiness);
  64. }
  65. }
  66. }
  67. }
  68. public override bool CanUpgrade
  69. {
  70. get
  71. {
  72. CIGExpansions.ExpansionBlock blockForIndex = this.expansions.reference.GetBlockForIndex(this.tile.index);
  73. return (blockForIndex == null || blockForIndex.Unlocked) && (!this.checkForRoad || this.HasRoad) && base.CanUpgrade;
  74. }
  75. }
  76. public override ILocalizedString ReasonWhyCantUpgrade(out ILocalizedString title)
  77. {
  78. CIGExpansions.ExpansionBlock blockForIndex = this.expansions.reference.GetBlockForIndex(this.tile.index);
  79. if (!blockForIndex.Unlocked)
  80. {
  81. title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building"));
  82. return Localization.Key("buy_expansion_first");
  83. }
  84. if (this.checkForRoad && !this.HasRoad)
  85. {
  86. title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building"));
  87. return Localization.Key("building_needs_road");
  88. }
  89. return base.ReasonWhyCantUpgrade(out title);
  90. }
  91. public override bool InfoRequiresFrequentRefresh
  92. {
  93. get
  94. {
  95. return (base.IsUpgrading || (this.activatable && !this.Activated) || base.state == BuildingState.Preview || base.state != BuildingState.Normal) && base.InfoRequiresFrequentRefresh;
  96. }
  97. }
  98. public override bool CanSpeedup
  99. {
  100. get
  101. {
  102. return (base.IsUpgrading || (this.activatable && !this.Activated) || base.state == BuildingState.Preview || base.state != BuildingState.Normal) && base.CanSpeedup;
  103. }
  104. }
  105. public override ILocalizedString InfoText()
  106. {
  107. if (base.IsUpgrading)
  108. {
  109. return base.InfoText();
  110. }
  111. if ((this.activatable && !this.Activated) || base.state == BuildingState.Preview)
  112. {
  113. return Localization.Concat(new ILocalizedString[]
  114. {
  115. base.InfoText(),
  116. Localization.LiteralNewLineString,
  117. Localization.Format(Localization.Key("happiness_points"), new ILocalizedString[]
  118. {
  119. Localization.Integer(this.baseHappinessValue)
  120. })
  121. });
  122. }
  123. if (base.state != BuildingState.Normal)
  124. {
  125. return base.InfoText();
  126. }
  127. if (this.checkForRoad && !base.CheckForRoad())
  128. {
  129. return Localization.Key("building_needs_road");
  130. }
  131. int num = (!this.activatable) ? 0 : -1;
  132. ILocalizedString result = Localization.Concat(new ILocalizedString[]
  133. {
  134. Localization.Format(Localization.Key("happiness_points"), new ILocalizedString[]
  135. {
  136. Localization.Integer(this.Happiness)
  137. }),
  138. Localization.LiteralNewLineString,
  139. Localization.Format(Localization.Key("building_current_upgrade_level"), new ILocalizedString[]
  140. {
  141. Localization.Integer(base.CurrentLevel + num),
  142. Localization.Integer(base.GetMaxLevel() + num)
  143. })
  144. });
  145. if (this.CanUpgrade)
  146. {
  147. result = Localization.Concat(new ILocalizedString[]
  148. {
  149. Localization.LiteralNewLineString,
  150. Localization.Format(Localization.Key("building_upgrade_option"), new ILocalizedString[]
  151. {
  152. Localization.Integer(base.CurrentLevel + 1 + num),
  153. this.UpgradeCost.LocalizedString()
  154. }),
  155. Localization.LiteralNewLineString,
  156. Localization.Format(Localization.Key("building_upgrade_option_happiness"), new ILocalizedString[]
  157. {
  158. Localization.Integer(this.UpgradeHappiness(base.CurrentLevel + 1))
  159. })
  160. });
  161. }
  162. return result;
  163. }
  164. public override List<BuildingProperty> ShownProperties
  165. {
  166. get
  167. {
  168. List<BuildingProperty> shownProperties = base.ShownProperties;
  169. shownProperties.Add(BuildingProperty.Happiness);
  170. return shownProperties;
  171. }
  172. }
  173. public override Currencies UpgradeCost
  174. {
  175. get
  176. {
  177. if (this.activatable && !this.Activated)
  178. {
  179. return base.UpgradeCost;
  180. }
  181. Currencies result;
  182. try
  183. {
  184. decimal num = this.baseUpgradeCost.GetValue("Cash");
  185. int num2 = (!this.activatable) ? 0 : -1;
  186. num *= this._upgradeCostFactor[base.CurrentLevel + 1 + num2] * 0.01m;
  187. result = new Currencies("Cash", Math.Ceiling(num));
  188. }
  189. catch (Exception ex)
  190. {
  191. throw new Exception(string.Format("[{0}|{2}]: {1}", base.name, ex.Message, this.stringReference), ex);
  192. }
  193. return result;
  194. }
  195. }
  196. public override int UpgradeHappiness(int toLevel)
  197. {
  198. if (!this.activatable)
  199. {
  200. return base.UpgradeHappiness(toLevel);
  201. }
  202. if (base.CurrentLevel == 0 && toLevel == 1)
  203. {
  204. return this.baseHappinessValue;
  205. }
  206. return base.UpgradeHappiness(toLevel - 1);
  207. }
  208. private MagicalReference<CIGExpansions> expansions = new MagicalReference<CIGExpansions>();
  209. private readonly int[] _upgradeCostFactor = new int[]
  210. {
  211. 100,
  212. 35,
  213. 44,
  214. 55,
  215. 69,
  216. 86,
  217. 108,
  218. 135,
  219. 169,
  220. 211,
  221. 264,
  222. 317,
  223. 380,
  224. 456,
  225. 547,
  226. 656,
  227. 787,
  228. 944,
  229. 1133,
  230. 1360,
  231. 1632
  232. };
  233. }