Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

943 wiersze
30 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using CIG.Translation;
  5. using CIGEnums;
  6. using SUISS.Core;
  7. using SUISS.Scheduling;
  8. using SUISSEngine;
  9. using UnityEngine;
  10. public class CIGCommercialBuilding : CIGBuilding
  11. {
  12. public Currencies Profit
  13. {
  14. get
  15. {
  16. if (this.currentMaxEmployees == 0)
  17. {
  18. return new Currencies();
  19. }
  20. return this.currentEmployees * this.currentProfit / this.currentMaxEmployees * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.CommercialBuildingProfitMultiplier;
  21. }
  22. }
  23. public Currencies ProfitPerHour
  24. {
  25. get
  26. {
  27. if (this.profitTime == 0)
  28. {
  29. return Currencies.Zero;
  30. }
  31. return 3600m * this.currentProfit / this.profitTime;
  32. }
  33. }
  34. public int MaxEmployees
  35. {
  36. get
  37. {
  38. return this.currentMaxEmployees;
  39. }
  40. protected set
  41. {
  42. int num = value - this.currentMaxEmployees;
  43. this.currentMaxEmployees = value;
  44. if (num != 0)
  45. {
  46. base.IslandState.AddJobs(num);
  47. }
  48. }
  49. }
  50. public int Employees
  51. {
  52. get
  53. {
  54. return this.currentEmployees;
  55. }
  56. protected set
  57. {
  58. int num = value - this.currentEmployees;
  59. this.currentEmployees = value;
  60. if (num != 0)
  61. {
  62. base.IslandState.AddEmployees(num);
  63. this.OnEmployeesChanged();
  64. }
  65. }
  66. }
  67. public int ProfitTimeLeft
  68. {
  69. get
  70. {
  71. if (this._waitForProfitRoutine != null)
  72. {
  73. return (int)(Scheduler.TimeLeft(this._waitForProfitRoutine) + 0.5);
  74. }
  75. return 0;
  76. }
  77. }
  78. protected override void OnDestroy()
  79. {
  80. if (SingletonMonobehaviour<Scheduler>.IsAvailable)
  81. {
  82. this.StopRoutines();
  83. if (this._delayedPlingEnumerator != null)
  84. {
  85. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._delayedPlingEnumerator);
  86. this._delayedPlingEnumerator = null;
  87. }
  88. }
  89. base.OnDestroy();
  90. }
  91. public override bool CanUpgrade
  92. {
  93. get
  94. {
  95. if (this.activatable && !this.Activated)
  96. {
  97. CIGExpansions.ExpansionBlock blockForIndex = this._expansions.reference.GetBlockForIndex(this.tile.index);
  98. if (blockForIndex != null && !blockForIndex.Unlocked)
  99. {
  100. return false;
  101. }
  102. }
  103. return base.CanUpgrade;
  104. }
  105. }
  106. public void ShowCommercialTimerProgress()
  107. {
  108. base.SetProgressBar((double)this.ProfitTimeLeft, (double)this.profitTime);
  109. }
  110. public void HideCommercialTimerProgress()
  111. {
  112. if (this._showingCommercialProgressTimer)
  113. {
  114. this._showingCommercialProgressTimer = false;
  115. base.HideProgressBar();
  116. }
  117. }
  118. protected override void ProgressTimeChanged()
  119. {
  120. this._showingCommercialProgressTimer = false;
  121. }
  122. public override ILocalizedString ReasonWhyCantUpgrade(out ILocalizedString title)
  123. {
  124. if (this.activatable && !this.Activated)
  125. {
  126. CIGExpansions reference = this._expansions.reference;
  127. if (reference != null)
  128. {
  129. CIGExpansions.ExpansionBlock blockForIndex = reference.GetBlockForIndex(this.tile.index);
  130. if (blockForIndex != null && !blockForIndex.Unlocked)
  131. {
  132. title = ((!this.Activated) ? Localization.Key("steps_to_complete_to_activate_this_building") : Localization.Key("steps_to_complete_to_be_able_to_upgrade_this_building"));
  133. return Localization.Key("buy_expansion_first");
  134. }
  135. }
  136. }
  137. return base.ReasonWhyCantUpgrade(out title);
  138. }
  139. public override bool InfoRequiresFrequentRefresh
  140. {
  141. get
  142. {
  143. if (base.state == BuildingState.Preview || base.state != BuildingState.Normal || base.IsUpgrading || (this.activatable && !this.Activated))
  144. {
  145. return base.InfoRequiresFrequentRefresh;
  146. }
  147. return (!this.checkForRoad || base.CheckForRoad()) && this.HasTimeLeft;
  148. }
  149. }
  150. public override bool CanSpeedup
  151. {
  152. get
  153. {
  154. return (base.state == BuildingState.Preview || base.state != BuildingState.Normal || base.IsUpgrading || (this.activatable && !this.Activated)) && base.CanSpeedup;
  155. }
  156. }
  157. public override ILocalizedString InfoText()
  158. {
  159. ILocalizedString localizedString;
  160. if (base.state == BuildingState.Preview)
  161. {
  162. localizedString = Localization.Concat(new ILocalizedString[]
  163. {
  164. base.InfoText(),
  165. Localization.LiteralNewLineString,
  166. Localization.Format(Localization.Key("profit_within"), new ILocalizedString[]
  167. {
  168. this.baseProfitCurrencies.WithoutXPCurrency().LocalizedString(),
  169. Localization.TimeSpan(TimeSpan.FromSeconds((double)this.profitTime), false)
  170. }),
  171. Localization.LiteralNewLineString,
  172. Localization.Key("jobs"),
  173. Localization.LiteralSemiColonSpaceString,
  174. Localization.Integer(this.maxEmployeesBaseValue),
  175. Localization.LiteralNewLineString,
  176. Localization.Key("construction_time"),
  177. Localization.LiteralSemiColonSpaceString,
  178. Localization.TimeSpan(TimeSpan.FromSeconds((double)this.constructionTime), false)
  179. });
  180. if (this.maxFacilities > 0)
  181. {
  182. int num = SingletonMonobehaviour<CIGGameStats>.Instance.NumberOf(base.CachedName);
  183. if (this.PurchasePrice.Contains("Cash"))
  184. {
  185. localizedString = Localization.Concat(new ILocalizedString[]
  186. {
  187. localizedString,
  188. Localization.LiteralNewLineString,
  189. Localization.Format(Localization.Key("building_max_facilities"), new ILocalizedString[]
  190. {
  191. Localization.Integer(this.maxFacilities)
  192. })
  193. });
  194. }
  195. else if (num > 0)
  196. {
  197. localizedString = Localization.Concat(new ILocalizedString[]
  198. {
  199. localizedString,
  200. Localization.LiteralNewLineString,
  201. Localization.Format(Localization.Key("building_costs_gold_max_facilities"), new ILocalizedString[]
  202. {
  203. Localization.Integer(num)
  204. })
  205. });
  206. }
  207. }
  208. return localizedString;
  209. }
  210. if (base.state != BuildingState.Normal || base.IsUpgrading)
  211. {
  212. return base.InfoText();
  213. }
  214. if (this.activatable && !this.Activated)
  215. {
  216. return Localization.Concat(new ILocalizedString[]
  217. {
  218. base.InfoText(),
  219. Localization.LiteralNewLineString,
  220. Localization.Key("profit"),
  221. Localization.LiteralSemiColonSpaceString,
  222. this.baseProfitCurrencies.WithoutXPCurrency().LocalizedString(),
  223. Localization.LiteralNewLineString,
  224. Localization.Key("jobs"),
  225. Localization.LiteralSemiColonSpaceString,
  226. Localization.Integer(this.maxEmployeesBaseValue)
  227. });
  228. }
  229. if (this.checkForRoad && !base.CheckForRoad())
  230. {
  231. return Localization.Key("building_needs_road");
  232. }
  233. int p = 0;
  234. if (this.MaxEmployees > 0)
  235. {
  236. p = 100 * this.Employees / this.MaxEmployees;
  237. }
  238. int num2 = (!this.activatable) ? 0 : -1;
  239. localizedString = Localization.Concat(new ILocalizedString[]
  240. {
  241. Localization.Format(Localization.Key("current_profit"), new ILocalizedString[]
  242. {
  243. this.Profit.WithoutXPCurrency().LocalizedString(),
  244. Localization.Percentage(p)
  245. }),
  246. Localization.LiteralNewLineString,
  247. Localization.Format(Localization.Key("current_employees"), new ILocalizedString[]
  248. {
  249. Localization.Integer(this.Employees),
  250. Localization.Integer(this.MaxEmployees)
  251. }),
  252. Localization.LiteralNewLineString,
  253. Localization.Format(Localization.Key("time_until_profit"), new ILocalizedString[]
  254. {
  255. this.TimeLeftString()
  256. }),
  257. Localization.LiteralNewLineString,
  258. Localization.Format(Localization.Key("building_current_upgrade_level"), new ILocalizedString[]
  259. {
  260. Localization.Integer(base.CurrentLevel + num2),
  261. Localization.Integer(base.GetMaxLevel() + num2)
  262. })
  263. });
  264. if (this.CanUpgrade)
  265. {
  266. localizedString = Localization.Concat(new ILocalizedString[]
  267. {
  268. localizedString,
  269. Localization.LiteralNewLineString,
  270. Localization.Format(Localization.Key("building_upgrade_option"), new ILocalizedString[]
  271. {
  272. Localization.Integer(base.CurrentLevel + 1 + num2),
  273. this.UpgradeCost.LocalizedString()
  274. }),
  275. Localization.LiteralNewLineString,
  276. Localization.Format(Localization.Key("building_upgrade_option_commercial"), new ILocalizedString[]
  277. {
  278. Localization.Integer(this.UpgradeJobs(base.CurrentLevel + 1)),
  279. this.UpgradeProfit(base.CurrentLevel + 1).LocalizedString()
  280. })
  281. });
  282. }
  283. return localizedString;
  284. }
  285. public override List<BuildingProperty> ShownProperties
  286. {
  287. get
  288. {
  289. List<BuildingProperty> shownProperties = base.ShownProperties;
  290. shownProperties.Add(BuildingProperty.Profit);
  291. shownProperties.Add(BuildingProperty.Employees);
  292. shownProperties.Add(BuildingProperty.TimeUntilProfit);
  293. return shownProperties;
  294. }
  295. }
  296. public override Currencies PurchasePrice
  297. {
  298. get
  299. {
  300. Currencies purchasePrice = base.PurchasePrice;
  301. if (purchasePrice.Contains("Cash"))
  302. {
  303. return purchasePrice * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.CommercialBuildingCostCashMultiplier;
  304. }
  305. return purchasePrice * SingletonMonobehaviour<CIGWebService>.Instance.Multipliers.CommercialBuildingCostGoldMultiplier;
  306. }
  307. }
  308. public override Currencies UpgradeCost
  309. {
  310. get
  311. {
  312. if (this.activatable && !this.Activated)
  313. {
  314. return base.UpgradeCost;
  315. }
  316. Currencies result;
  317. try
  318. {
  319. decimal num = this.baseUpgradeCost.GetValue("Cash");
  320. int num2 = (!this.activatable) ? 0 : -1;
  321. num *= this._upgradeCostFactor[base.CurrentLevel + 1 + num2] * 0.01m;
  322. result = new Currencies("Cash", Math.Ceiling(num));
  323. }
  324. catch (Exception ex)
  325. {
  326. throw new Exception(string.Format("[{0}|{2}]: {1}", base.name, ex.Message, this.stringReference), ex);
  327. }
  328. return result;
  329. }
  330. }
  331. protected virtual bool HasTimeLeft
  332. {
  333. get
  334. {
  335. return this._waitForProfitRoutine != null;
  336. }
  337. }
  338. public virtual ILocalizedString TimeLeftString()
  339. {
  340. if (this._waitForProfitRoutine == null)
  341. {
  342. return Localization.TimeSpan(TimeSpan.Zero, false);
  343. }
  344. return Localization.TimeSpan(TimeSpan.FromSeconds(Scheduler.TimeLeft(this._waitForProfitRoutine)), false);
  345. }
  346. private bool UpdateEmployees()
  347. {
  348. int globalEmployees = base.GameState.GlobalEmployees;
  349. int num = this.Employees;
  350. if (this.checkForRoad && !base.CheckForRoad())
  351. {
  352. num--;
  353. }
  354. else if (base.IslandState.AvailablePopulation < globalEmployees)
  355. {
  356. num--;
  357. }
  358. else if (base.IslandState.AvailablePopulation > globalEmployees)
  359. {
  360. num++;
  361. }
  362. num = Math.Max(0, Math.Min(num, this.MaxEmployees));
  363. if (num != this.Employees)
  364. {
  365. this.Employees = num;
  366. this.serializing.Serialize();
  367. return true;
  368. }
  369. return false;
  370. }
  371. protected virtual void CollectProfit(Currencies profit, bool maxed)
  372. {
  373. profit = profit.Round();
  374. base.GameState.EarnCurrencies(profit, this._currencyAnimationObject);
  375. base.GameStats.AddCashCollected(profit);
  376. if (SingletonMonobehaviour<CIGLocalNotificationManager>.Instance != null && SingletonMonobehaviour<CIGLocalNotificationManager>.Instance.AreNotificationsAllowed)
  377. {
  378. SingletonMonobehaviour<CIGLocalNotificationManager>.Instance.RequestPermissions();
  379. }
  380. Bounds bounds = this._renderer.bounds;
  381. bounds.center = new Vector3(bounds.center.x, this._renderer.bounds.max.y, bounds.center.z);
  382. decimal value;
  383. PlingType plingType;
  384. if (profit.ContainsPositive("Gold"))
  385. {
  386. value = profit.GetValue("Gold");
  387. plingType = PlingType.Gold;
  388. }
  389. else if (maxed)
  390. {
  391. value = profit.GetValue("Cash");
  392. plingType = PlingType.Cash_Green;
  393. }
  394. else
  395. {
  396. value = profit.GetValue("Cash");
  397. plingType = PlingType.Cash_Red;
  398. }
  399. Pling pling = this._plingManager.Show(plingType, Vector3.zero, Clip.Ping);
  400. if (plingType == PlingType.Cash_Green || plingType == PlingType.Cash_Red)
  401. {
  402. pling.ShowWithParticles(Localization.Integer(value), ParticleType.CashFountain);
  403. }
  404. else
  405. {
  406. pling.Show(Localization.Integer(value));
  407. }
  408. decimal xpValue = profit.GetValue("XP");
  409. if (xpValue > 0m && !SingletonMonobehaviour<CIGGameState>.Instance.ReachedMaxLevel)
  410. {
  411. XPBoostReward xpboostReward = Singleton<OngoingRewardManager>.Instance.FindActiveReward((IOngoingReward reward) => reward is XPBoostReward) as XPBoostReward;
  412. if (xpboostReward != null)
  413. {
  414. decimal additionalValue = (decimal)xpboostReward.BoostPercentage * 0.01m * xpValue;
  415. base.GameState.EarnCurrencies(new Currencies("XP", additionalValue), this._currencyAnimationObject);
  416. this._delayedPlingEnumerator = SingletonMonobehaviour<Scheduler>.Instance.ExecuteDelayed(delegate
  417. {
  418. Pling pling2 = this._plingManager.Show(PlingType.XP, 0.9f * Vector3.down * 50f);
  419. pling2.Show(Localization.Integer(additionalValue));
  420. this._delayedPlingEnumerator = null;
  421. }, 0.06f);
  422. }
  423. else
  424. {
  425. this._delayedPlingEnumerator = SingletonMonobehaviour<Scheduler>.Instance.ExecuteDelayed(delegate
  426. {
  427. Pling pling2 = this._plingManager.Show(PlingType.XP, 0.9f * Vector3.down * 50f);
  428. pling2.Show(Localization.Integer(xpValue));
  429. this._delayedPlingEnumerator = null;
  430. }, 0.06f);
  431. }
  432. }
  433. }
  434. protected virtual IEnumerator WaitForProfit()
  435. {
  436. if (this.storedProfitTimeLeft < 0.0)
  437. {
  438. yield return Timing.time + (double)this.profitTime;
  439. }
  440. else
  441. {
  442. double t = Timing.time + this.storedProfitTimeLeft;
  443. this.storedProfitTimeLeft = -1.0;
  444. yield return t;
  445. }
  446. yield break;
  447. }
  448. private IEnumerator WaitForClick()
  449. {
  450. for (; ; )
  451. {
  452. yield return Timing.time + 60.0;
  453. }
  454. yield break;
  455. }
  456. private IEnumerator ProfitLoopBehaviour()
  457. {
  458. if (this.profitTime <= 0)
  459. {
  460. UnityEngine.Debug.LogWarning(string.Format("{1}: profitTime({0}) should not be <= 0", this.profitTime, base.name));
  461. yield break;
  462. }
  463. for (; ; )
  464. {
  465. yield return this._waitForProfitRoutine = this.WaitForProfit();
  466. this._waitForProfitRoutine = null;
  467. Currencies profit = this.Profit;
  468. bool maxed = profit.MissingCurrencies(this.currentProfit).IsEmpty();
  469. if (!profit.IsEmpty())
  470. {
  471. this.ShowProfitIcon(maxed);
  472. yield return this._clickRoutine = this.WaitForClick();
  473. this._clickRoutine = null;
  474. this.HideProfitIcon();
  475. this.CollectProfit(profit, maxed);
  476. this.serializing.Serialize();
  477. }
  478. }
  479. yield break;
  480. }
  481. private IEnumerator ProfitBehaviour()
  482. {
  483. yield return this._profitLoopRoutine = this.ProfitLoopBehaviour();
  484. this._profitLoopRoutine = null;
  485. this.HideProfitIcon();
  486. yield break;
  487. }
  488. private IEnumerator EmployeesBehaviour()
  489. {
  490. bool changed = true;
  491. for (; ; )
  492. {
  493. yield return Timing.time + ((!changed) ? this.EmployeeUnchangedUpdateWaitTime : this.EmployeeChangedUpdateWaitTime);
  494. changed = this.UpdateEmployees();
  495. }
  496. yield break;
  497. }
  498. protected virtual void OnEmployeesChanged()
  499. {
  500. this.UpdateNoEmployeesIcon();
  501. }
  502. protected void ClickProfitIcon(GameObject target)
  503. {
  504. if (this._clickRoutine != null)
  505. {
  506. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._clickRoutine);
  507. this._clickRoutine = null;
  508. }
  509. }
  510. protected override void OnConstructionCompleted()
  511. {
  512. base.OnConstructionCompleted();
  513. if (!this.activatable)
  514. {
  515. this.MaxEmployees = this.maxEmployeesBaseValue;
  516. this.currentProfit = this.baseProfitCurrencies;
  517. this.StartRoutines();
  518. this.UpdateNoEmployeesIcon();
  519. SingletonMonobehaviour<CIGGameStats>.Instance.AddGlobalProfitPerHour(this.ProfitPerHour);
  520. }
  521. }
  522. protected override void OnSerialize(Dictionary<string, object> values)
  523. {
  524. base.OnSerialize(values);
  525. values["maxEmployees"] = this.currentMaxEmployees;
  526. values["employees"] = this.currentEmployees;
  527. values["profit"] = this.currentProfit;
  528. if (this._maxEmployeesWhenDemolishStarted != 0)
  529. {
  530. values["maxEmployeesWhenDemolishStarted"] = this._maxEmployeesWhenDemolishStarted;
  531. }
  532. if (this._clickRoutine != null)
  533. {
  534. values["profitTimestamp"] = Timing.UtcNow;
  535. }
  536. else if (this._waitForProfitRoutine != null)
  537. {
  538. values["profitTimestamp"] = Timing.UtcNow + Scheduler.TimeLeft(this._waitForProfitRoutine);
  539. }
  540. else if (base.IsUpgrading)
  541. {
  542. values["profitTimestamp"] = Timing.UtcNow + base.UpgradeTimeLeft + 1.0 + (double)this.profitTime;
  543. }
  544. else if (base.state == BuildingState.Normal)
  545. {
  546. values["profitTimestamp"] = Timing.UtcNow + (double)this.profitTime;
  547. }
  548. else if (values.ContainsKey("profitTimestamp"))
  549. {
  550. values.Remove("profitTimestamp");
  551. }
  552. }
  553. protected override void OnDeserialize(Dictionary<string, object> values)
  554. {
  555. base.OnDeserialize(values);
  556. if (values.ContainsKey("maxEmployees"))
  557. {
  558. this.currentMaxEmployees = (int)values["maxEmployees"];
  559. }
  560. if (values.ContainsKey("maxEmployeesWhenDemolishStarted"))
  561. {
  562. this._maxEmployeesWhenDemolishStarted = (int)values["maxEmployeesWhenDemolishStarted"];
  563. }
  564. if (values.ContainsKey("employees"))
  565. {
  566. this.currentEmployees = (int)values["employees"];
  567. }
  568. if (values.ContainsKey("profit"))
  569. {
  570. this.currentProfit = (Currencies)values["profit"];
  571. }
  572. if (values.ContainsKey("profitTimestamp"))
  573. {
  574. this.storedProfitTimeLeft = Math.Max(0.0, (double)values["profitTimestamp"] - Timing.UtcNow);
  575. }
  576. else
  577. {
  578. this.storedProfitTimeLeft = -1.0;
  579. }
  580. }
  581. protected override void OnDeserialized()
  582. {
  583. base.OnDeserialized();
  584. if (base.state == BuildingState.Normal)
  585. {
  586. this.UpdateNoEmployeesIcon();
  587. if (base.IsUpgrading)
  588. {
  589. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._employeesRoutine = this.EmployeesBehaviour(), base.gameObject);
  590. }
  591. else
  592. {
  593. this.StartRoutines();
  594. }
  595. }
  596. }
  597. protected override void OnUpgradeStarted()
  598. {
  599. base.OnUpgradeStarted();
  600. if (this._profitRoutine != null)
  601. {
  602. this.StopProfitRoutine();
  603. this.HideProfitIcon();
  604. }
  605. }
  606. protected override void OnUpgradeCompleted(double upgradedTime)
  607. {
  608. base.OnUpgradeCompleted(upgradedTime);
  609. if (this.activatable && base.CurrentLevel == 1)
  610. {
  611. this.MaxEmployees = this.maxEmployeesBaseValue;
  612. this.currentProfit = this.baseProfitCurrencies;
  613. this.StartRoutines();
  614. this.UpdateNoEmployeesIcon();
  615. SingletonMonobehaviour<CIGGameStats>.Instance.AddGlobalProfitPerHour(this.ProfitPerHour);
  616. }
  617. else
  618. {
  619. this.MaxEmployees += this.UpgradeJobs(base.CurrentLevel);
  620. Currencies currencies = this.UpgradeProfit(base.CurrentLevel);
  621. this.currentProfit += currencies;
  622. SingletonMonobehaviour<CIGGameStats>.Instance.AddGlobalProfitPerHour(3600m * currencies / this.profitTime);
  623. if (this._profitLoopRoutine != null)
  624. {
  625. UnityEngine.Debug.LogWarning(string.Format("{0}: profitLoopRoutine is not null OnUpgradeCompleted", base.name));
  626. }
  627. this.storedProfitTimeLeft = Math.Max(0.0, (double)this.profitTime - (Timing.time - upgradedTime));
  628. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._profitRoutine = this.ProfitBehaviour(), base.gameObject);
  629. }
  630. }
  631. protected override void OnDemolishStarted()
  632. {
  633. base.OnDemolishStarted();
  634. SingletonMonobehaviour<CIGGameStats>.Instance.AddGlobalProfitPerHour(-this.ProfitPerHour);
  635. this.StopRoutines();
  636. this.Employees = 0;
  637. this._maxEmployeesWhenDemolishStarted = this.MaxEmployees;
  638. this.MaxEmployees = 0;
  639. }
  640. protected override void OnDemolishCancelled()
  641. {
  642. base.OnDemolishCancelled();
  643. SingletonMonobehaviour<CIGGameStats>.Instance.AddGlobalProfitPerHour(this.ProfitPerHour);
  644. this.MaxEmployees = this._maxEmployeesWhenDemolishStarted;
  645. this._maxEmployeesWhenDemolishStarted = 0;
  646. this.StartRoutines();
  647. }
  648. protected override void ClickHandler(GameObject target)
  649. {
  650. if (this._clickRoutine != null)
  651. {
  652. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._clickRoutine);
  653. this._clickRoutine = null;
  654. }
  655. else
  656. {
  657. base.ClickHandler(target);
  658. }
  659. }
  660. private void StartRoutines()
  661. {
  662. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._profitRoutine = this.ProfitBehaviour(), base.gameObject);
  663. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._employeesRoutine = this.EmployeesBehaviour(), base.gameObject);
  664. }
  665. private void StopRoutines()
  666. {
  667. this.StopProfitRoutine();
  668. if (this._employeesRoutine != null)
  669. {
  670. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._employeesRoutine);
  671. this._employeesRoutine = null;
  672. }
  673. }
  674. private void StopProfitRoutine()
  675. {
  676. if (this._profitRoutine != null)
  677. {
  678. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._profitRoutine);
  679. this._profitRoutine = null;
  680. this._profitLoopRoutine = null;
  681. this._waitForProfitRoutine = null;
  682. this._clickRoutine = null;
  683. }
  684. }
  685. private double EmployeeUnchangedUpdateWaitTime
  686. {
  687. get
  688. {
  689. return (double)UnityEngine.Random.Range(2f, 30f);
  690. }
  691. }
  692. private double EmployeeChangedUpdateWaitTime
  693. {
  694. get
  695. {
  696. return (double)UnityEngine.Random.Range(1f, 3f);
  697. }
  698. }
  699. protected virtual void ShowProfitIcon(bool maxed)
  700. {
  701. GridTileIconType icon = (!maxed) ? GridTileIconType.LowProfit : GridTileIconType.Profit;
  702. ButtonGridTileIcon buttonGridTileIcon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(icon);
  703. buttonGridTileIcon.Init(delegate
  704. {
  705. this.ClickProfitIcon(base.gameObject);
  706. });
  707. }
  708. protected void HideProfitIcon()
  709. {
  710. this._gridTileIconManager.RemoveIcon(GridTileIconType.Profit);
  711. this._gridTileIconManager.RemoveIcon(GridTileIconType.LowProfit);
  712. this._gridTileIconManager.RemoveIcon(GridTileIconType.GoldProfit);
  713. }
  714. public int UpgradeJobs(int toLevel)
  715. {
  716. if (this.activatable && base.CurrentLevel == 0 && toLevel == 1)
  717. {
  718. return this.maxEmployeesBaseValue;
  719. }
  720. if (base.GetMaxLevel() != 0)
  721. {
  722. int val = Math.Max(0, toLevel - base.CurrentLevel);
  723. return Math.Max(val, this.maxEmployeesBaseValue + toLevel * this.maxEmployeesBaseValue / 10 - this.currentMaxEmployees);
  724. }
  725. return 0;
  726. }
  727. public override int UpgradeTime
  728. {
  729. get
  730. {
  731. if (this.activatable && !this.Activated)
  732. {
  733. return base.UpgradeTime;
  734. }
  735. int num = this.constructionTime;
  736. if (this.activatable)
  737. {
  738. num = this.activationTime;
  739. }
  740. return this._upgradeTimeFactor[base.CurrentLevel + 1 + ((!this.activatable) ? 0 : -1)] * num / 100;
  741. }
  742. }
  743. public Currencies UpgradeProfit(int toLevel)
  744. {
  745. if (this.activatable && base.CurrentLevel == 0 && toLevel == 1)
  746. {
  747. return this.baseProfitCurrencies;
  748. }
  749. if (this.activatable)
  750. {
  751. toLevel--;
  752. }
  753. if (base.GetMaxLevel() != 0 && toLevel >= 0 && toLevel < this._upgradeProfitFactor.Length)
  754. {
  755. return this.baseProfitCurrencies.WithoutXPCurrency() + (this._upgradeProfitFactor[toLevel] * this.baseProfitCurrencies.WithoutXPCurrency() / 100m).Round(Currencies.RoundingMethod.Floor) - this.currentProfit.WithoutXPCurrency();
  756. }
  757. return new Currencies();
  758. }
  759. public void FixProfit()
  760. {
  761. Currencies currencies = this.UpgradeProfit(base.CurrentLevel);
  762. if (currencies.ContainsPositive("Cash"))
  763. {
  764. this.currentProfit += currencies;
  765. if (this.serializing != null)
  766. {
  767. this.serializing.Serialize();
  768. }
  769. }
  770. }
  771. private void UpdateNoEmployeesIcon()
  772. {
  773. if (this.Employees == 0)
  774. {
  775. ButtonGridTileIcon buttonGridTileIcon = this._gridTileIconManager.SetIcon<ButtonGridTileIcon>(GridTileIconType.NoEmployees);
  776. buttonGridTileIcon.Init(delegate
  777. {
  778. this.ClickHandler(base.gameObject);
  779. });
  780. }
  781. else
  782. {
  783. this._gridTileIconManager.RemoveIcon(GridTileIconType.NoEmployees);
  784. }
  785. }
  786. public int profitTime;
  787. public Currencies baseProfitCurrencies;
  788. public int maxEmployeesBaseValue;
  789. private int currentEmployees;
  790. private int currentMaxEmployees;
  791. private int _maxEmployeesWhenDemolishStarted;
  792. private Currencies currentProfit = new Currencies();
  793. private double storedProfitTimeLeft = -1.0;
  794. private MagicalReference<CIGExpansions> _expansions = new MagicalReference<CIGExpansions>();
  795. private bool _showingCommercialProgressTimer;
  796. private IEnumerator _delayedPlingEnumerator;
  797. private readonly int[] _upgradeCostFactor = new int[]
  798. {
  799. 100,
  800. 30,
  801. 38,
  802. 48,
  803. 60,
  804. 75,
  805. 94,
  806. 118,
  807. 148,
  808. 185,
  809. 231,
  810. 277,
  811. 346,
  812. 433,
  813. 541,
  814. 676,
  815. 845,
  816. 1056,
  817. 1320,
  818. 1650,
  819. 2063
  820. };
  821. private IEnumerator _waitForProfitRoutine;
  822. private IEnumerator _clickRoutine;
  823. private IEnumerator _profitLoopRoutine;
  824. private IEnumerator _profitRoutine;
  825. private IEnumerator _employeesRoutine;
  826. private readonly int[] _upgradeTimeFactor = new int[]
  827. {
  828. 100,
  829. 25,
  830. 33,
  831. 43,
  832. 56,
  833. 73,
  834. 95,
  835. 124,
  836. 161,
  837. 209,
  838. 272,
  839. 354,
  840. 460,
  841. 598,
  842. 777,
  843. 1010,
  844. 1313,
  845. 1707,
  846. 2219,
  847. 2885,
  848. 3751
  849. };
  850. private readonly int[] _upgradeProfitFactor = new int[]
  851. {
  852. 0,
  853. 10,
  854. 21,
  855. 33,
  856. 46,
  857. 61,
  858. 77,
  859. 95,
  860. 115,
  861. 137,
  862. 161,
  863. 187,
  864. 216,
  865. 248,
  866. 283,
  867. 321,
  868. 363,
  869. 409,
  870. 460,
  871. 516,
  872. 578
  873. };
  874. }