選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

1050 行
24 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using CIG;
  6. using CIG.Translation;
  7. using CIG3.ExtensionMethods;
  8. using CIGEnums;
  9. using SUISS.Core;
  10. using SUISS.Scheduling;
  11. using SUISS.Storage;
  12. using SUISSEngine;
  13. using UnityEngine;
  14. public class CIGGameState : GameState<CIGGameState>
  15. {
  16. protected override StorageLifecycle GetLifecycle()
  17. {
  18. return StorageLifecycle.Game;
  19. }
  20. protected override string GetStorageKey()
  21. {
  22. return this.storageKey;
  23. }
  24. protected override void Start()
  25. {
  26. base.Start();
  27. if (SingletonMonobehaviour<CIGSparkSocServices>.Instance != null)
  28. {
  29. SingletonMonobehaviour<CIGSparkSocServices>.Instance.StartLeaderboards();
  30. SingletonMonobehaviour<Scheduler>.Instance.StartRoutine(this._syncGameScoresRoutine = this.SyncGameScores());
  31. }
  32. this.CheckGlobalValues();
  33. this.GiveLevelUpReward();
  34. }
  35. private IEnumerator SyncGameScores()
  36. {
  37. for (;;)
  38. {
  39. CIGSparkSocServices sparksoc = SingletonMonobehaviour<CIGSparkSocServices>.Instance;
  40. if (sparksoc != null)
  41. {
  42. this.PostNewHighscores(sparksoc);
  43. }
  44. yield return Timing.time + 300.0;
  45. }
  46. yield break;
  47. }
  48. private void PostNewHighscores(CIGSparkSocServices sparksoc)
  49. {
  50. sparksoc.PostNewHighScores(this.Level, this.GlobalPopulation, this.GetIslandsUnlockedCount(), (int)Mathf.Round(this.LevelProgress * 100f));
  51. }
  52. protected override void OnNewGameState()
  53. {
  54. base.OnNewGameState();
  55. for (int i = 0; i < this.initialIslandUnlocks.Length; i++)
  56. {
  57. this.SetIslandUnlocked(this.initialIslandUnlocks[i]);
  58. }
  59. this.RecalculateRequiredXP(1);
  60. this.Level = 1;
  61. this.Balance = this.InitialBalance;
  62. this.GiftedBalance = Currencies.Zero;
  63. this.CurrenciesEarned = Currencies.Zero;
  64. this.CurrenciesSpent = Currencies.Zero;
  65. this.GlobalHappiness = this.BaseHappiness;
  66. this.GlobalPopulation = 0;
  67. this.GlobalHousing = 0;
  68. this.GlobalEmployees = 0;
  69. this.GlobalJobs = 0;
  70. this.UnprocessedChestGold = 0m;
  71. this.SpeedupWithCashEnabled = false;
  72. this.MaxBuildingLevel10 = true;
  73. }
  74. protected override void Awake()
  75. {
  76. base.Awake();
  77. for (int i = 0; i < this.Levels.Length; i++)
  78. {
  79. LevelDefinition levelDefinition = this.Levels[i];
  80. decimal value = 30000.0m + (i + 1) * 10000.0m;
  81. levelDefinition.Reward = new Currencies("Cash", value);
  82. }
  83. object[] array = this.GetValue<object[]>("RequiredXPValues", new object[0]);
  84. int num = -1;
  85. for (int j = 0; j < array.Length; j++)
  86. {
  87. this.Levels[j].XP = (int)array[j];
  88. if (j > 0 && this.Levels[j].XP < this.Levels[j - 1].XP)
  89. {
  90. if (num < 0)
  91. {
  92. num = this.Levels[j - 1].XP;
  93. }
  94. this.Levels[j].XP += num;
  95. }
  96. }
  97. if (array.Length != this.Levels.Length)
  98. {
  99. object[] array2 = new object[this.Levels.Length];
  100. int num2 = 0;
  101. while (num2 < array.Length && num2 < array2.Length)
  102. {
  103. array2[num2] = array[num2];
  104. num2++;
  105. }
  106. for (int k = array.Length; k < array2.Length; k++)
  107. {
  108. array2[k] = 0;
  109. }
  110. int level = this.Level;
  111. int num3 = array.Length;
  112. while (num3 <= level && num3 < array2.Length)
  113. {
  114. this.RecalculateRequiredXP(num3);
  115. array2[num3] = this.Levels[num3].XP;
  116. num3++;
  117. }
  118. array = array2;
  119. this.SetValue("RequiredXPValues", array);
  120. for (int l = 0; l < array.Length; l++)
  121. {
  122. this.Levels[l].XP = (int)array[l];
  123. }
  124. }
  125. if (!this.GetValue<bool>("CloudStorageMigrationCompleted", false) && InstallVersion.InstallVersionName != "?" && new Version(InstallVersion.InstallVersionName) < new Version(2, 3, 0))
  126. {
  127. if (StorageController.HasLoadedCloudSave)
  128. {
  129. Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Activated;
  130. }
  131. this.SetValue("CloudStorageMigrationCompleted", true);
  132. UnityEngine.Debug.Log("Performed cloud storage activation migration");
  133. }
  134. bool flag = false;
  135. if (this.UnprocessedChestGold > 0m)
  136. {
  137. this.Balance += new Currencies("Gold", this.UnprocessedChestGold);
  138. this.UnprocessedChestGold = 0m;
  139. flag = true;
  140. }
  141. object obj;
  142. if (Storage.Get(StorageLifecycle.Forever).Root.TryGetValue("UnprocessedPurchase", out obj))
  143. {
  144. if (obj is Currencies)
  145. {
  146. this.GiveCurrencies(obj as Currencies);
  147. this.CountBoughtGoldPackageIfApplicable(obj as Currencies);
  148. }
  149. Storage.Get(StorageLifecycle.Forever).Root.Remove("UnprocessedPurchase");
  150. flag = true;
  151. }
  152. if (this.Level <= this.Levels.Length)
  153. {
  154. Currencies earnedBalance = this.EarnedBalance;
  155. decimal value2 = earnedBalance.GetValue("XP");
  156. if (value2 < this.Levels[this.Level - 1].XP)
  157. {
  158. this.SetValue("EarnedBalance", earnedBalance.WithoutXPCurrency() + new Currencies("XP", this.Levels[this.Level - 1].XP));
  159. flag = true;
  160. }
  161. }
  162. if (flag)
  163. {
  164. StorageController.SaveAll();
  165. }
  166. }
  167. protected override void OnDestroy()
  168. {
  169. if (this._syncGameScoresRoutine != null && SingletonMonobehaviour<Scheduler>.IsAvailable)
  170. {
  171. SingletonMonobehaviour<Scheduler>.Instance.StopRoutine(this._syncGameScoresRoutine);
  172. this._syncGameScoresRoutine = null;
  173. }
  174. base.OnDestroy();
  175. }
  176. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  177. public event Action<int> LevelledUp;
  178. protected virtual void OnLevelledUp(int arg)
  179. {
  180. Action<int> levelledUp = this.LevelledUp;
  181. if (levelledUp != null)
  182. {
  183. levelledUp(arg);
  184. }
  185. }
  186. //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
  187. public event CIGGameState.BalanceChangedEventHandler BalanceChangedEvent;
  188. private void FireBalanceChangedEvent(Currencies oldBalance, Currencies newBalance, object earnSource)
  189. {
  190. if (this.BalanceChangedEvent != null)
  191. {
  192. this.BalanceChangedEvent(oldBalance, newBalance, earnSource);
  193. }
  194. }
  195. public int MaxLevel
  196. {
  197. get
  198. {
  199. return this.Levels.Length - 1;
  200. }
  201. }
  202. public int Level
  203. {
  204. get
  205. {
  206. return this.GetValue<int>("Level", 1);
  207. }
  208. private set
  209. {
  210. this.SetValue("Level", value);
  211. }
  212. }
  213. public bool ReachedMaxLevel
  214. {
  215. get
  216. {
  217. return this.Level >= this.MaxLevel;
  218. }
  219. }
  220. public float LevelProgress
  221. {
  222. get
  223. {
  224. float num = (float)this.Balance.GetValue("XP");
  225. float num4;
  226. if (this.Level >= this.Levels.Length)
  227. {
  228. float num2;
  229. if (this.Level == this.MaxLevel + 1)
  230. {
  231. num2 = (float)this.Levels[this.Level - 1].XP;
  232. }
  233. else
  234. {
  235. num2 = (float)this.XPNeededForGeneratedLevel(this.Level - 1);
  236. }
  237. float num3 = (float)this.XPNeededForGeneratedLevel(this.Level);
  238. num4 = (num - num2) / (num3 - num2);
  239. }
  240. else
  241. {
  242. float num5 = (float)this.Levels[this.Level - 1].XP;
  243. float num6 = (float)this.Levels[this.Level].XP;
  244. num4 = (num - num5) / (num6 - num5);
  245. }
  246. if (num4 < 0f)
  247. {
  248. num4 = 0f;
  249. }
  250. else if (num4 > 1f)
  251. {
  252. num4 = 1f;
  253. }
  254. return num4;
  255. }
  256. }
  257. public Currencies GiftedBalance
  258. {
  259. get
  260. {
  261. return this.GetValue<Currencies>("GiftedBalance", new Currencies());
  262. }
  263. private set
  264. {
  265. if (value.ContainsPositive("XP"))
  266. {
  267. this.EarnedBalance += new Currencies("XP", value.GetValue("XP"));
  268. }
  269. this.SetValue("GiftedBalance", value.WithoutXPCurrency());
  270. }
  271. }
  272. public Currencies EarnedBalance
  273. {
  274. get
  275. {
  276. return this.GetValue<Currencies>("EarnedBalance", new Currencies());
  277. }
  278. private set
  279. {
  280. decimal value2 = this.ProcessXPGain(value.GetValue("XP"));
  281. Currencies value3 = value.WithoutXPCurrency() + new Currencies("XP", value2);
  282. this.SetValue("EarnedBalance", value3);
  283. }
  284. }
  285. public Currencies Balance
  286. {
  287. get
  288. {
  289. return this.EarnedBalance + this.GiftedBalance;
  290. }
  291. private set
  292. {
  293. this.EarnedBalance = Currencies.NonNegative(value - this.GiftedBalance);
  294. this.GiftedBalance = this.GiftedBalance.Cap(value - this.EarnedBalance, true);
  295. }
  296. }
  297. public Currencies CurrenciesEarned
  298. {
  299. get
  300. {
  301. return this.GetValue<Currencies>("CurrenciesEarned", new Currencies());
  302. }
  303. private set
  304. {
  305. this.SetValue("CurrenciesEarned", value);
  306. }
  307. }
  308. public Currencies CurrenciesSpent
  309. {
  310. get
  311. {
  312. return this.GetValue<Currencies>("CurrenciesSpent", new Currencies());
  313. }
  314. private set
  315. {
  316. this.SetValue("CurrenciesSpent", value);
  317. }
  318. }
  319. public decimal UnprocessedChestGold
  320. {
  321. get
  322. {
  323. return this.GetValue<decimal>("UnprocessedChestGold", 0m);
  324. }
  325. set
  326. {
  327. this.SetValue("UnprocessedChestGold", (!(value > 0m)) ? 0m : value);
  328. }
  329. }
  330. public int GlobalHappiness
  331. {
  332. get
  333. {
  334. return this.GetValue<int>("GlobalHappiness", 0);
  335. }
  336. private set
  337. {
  338. this.SetValue("GlobalHappiness", value);
  339. }
  340. }
  341. public int GlobalPopulation
  342. {
  343. get
  344. {
  345. return this.GetValue<int>("GlobalPopulation", 0);
  346. }
  347. private set
  348. {
  349. this.SetValue("GlobalPopulation", value);
  350. }
  351. }
  352. public int GlobalHousing
  353. {
  354. get
  355. {
  356. return this.GetValue<int>("GlobalHousing", 0);
  357. }
  358. private set
  359. {
  360. this.SetValue("GlobalHousing", value);
  361. }
  362. }
  363. public int GlobalEmployees
  364. {
  365. get
  366. {
  367. return this.GetValue<int>("GlobalEmployees", 0);
  368. }
  369. private set
  370. {
  371. this.SetValue("GlobalEmployees", value);
  372. }
  373. }
  374. public int GlobalJobs
  375. {
  376. get
  377. {
  378. return this.GetValue<int>("GlobalJobs", 0);
  379. }
  380. private set
  381. {
  382. this.SetValue("GlobalJobs", value);
  383. }
  384. }
  385. public Currencies LevelUpReward
  386. {
  387. get
  388. {
  389. return this.GetValue<Currencies>("LevelUpReward", new Currencies());
  390. }
  391. private set
  392. {
  393. this.SetValue("LevelUpReward", value);
  394. }
  395. }
  396. public bool SpeedupWithCashEnabled
  397. {
  398. get
  399. {
  400. return this.GetValue<bool>("SpeedupWithCashEnabled", true);
  401. }
  402. private set
  403. {
  404. this.SetValue("SpeedupWithCashEnabled", value);
  405. }
  406. }
  407. public bool MaxBuildingLevel10
  408. {
  409. get
  410. {
  411. return this.GetValue<bool>("MaxBuildingLevel10", false);
  412. }
  413. private set
  414. {
  415. this.SetValue("MaxBuildingLevel10", value);
  416. }
  417. }
  418. public bool IsConnectionUnlocked(Island island1, Island island2)
  419. {
  420. if (island1.IsValid() && island2.IsValid())
  421. {
  422. return this.GetValue<string>("IslandConnections", string.Empty).Contains(this.GetConnectionString(island1, island2));
  423. }
  424. UnityEngine.Debug.LogWarning(string.Concat(new string[]
  425. {
  426. "Invalid islands (",
  427. island1.ToString(),
  428. ", ",
  429. island2.ToString(),
  430. ") passed to IsConnectionUnlocked()"
  431. }));
  432. return false;
  433. }
  434. public void SetConnectionUnlocked(Island island1, Island island2)
  435. {
  436. if (island1.IsValid() && island2.IsValid())
  437. {
  438. if (!this.IsConnectionUnlocked(island1, island2))
  439. {
  440. this.SetValue("IslandConnections", this.GetValue<string>("IslandConnections", string.Empty) + this.GetConnectionString(island1, island2));
  441. }
  442. }
  443. else
  444. {
  445. UnityEngine.Debug.LogWarning(string.Concat(new string[]
  446. {
  447. "Invalid islands (",
  448. island1.ToString(),
  449. ", ",
  450. island2.ToString(),
  451. ") passed to SetConnectionUnlocked()"
  452. }));
  453. }
  454. }
  455. public bool IsIslandUnlocked(Island island)
  456. {
  457. if (island.IsValid())
  458. {
  459. return this.GetValue<bool>("UnlockedIsland" + island.GetIndex().ToString(), false);
  460. }
  461. UnityEngine.Debug.LogWarning("Invalid island (" + island.ToString() + ") passed to IsIslandUnlocked()");
  462. return false;
  463. }
  464. public int GetIslandsUnlockedCount()
  465. {
  466. int num = 0;
  467. foreach (Island island in IslandExtensions.GetIslands())
  468. {
  469. if (island.IsValid() && this.IsIslandUnlocked(island))
  470. {
  471. num++;
  472. }
  473. }
  474. return num;
  475. }
  476. public void SetIslandUnlocked(Island island)
  477. {
  478. if (island.IsValid())
  479. {
  480. bool flag = this.IsIslandUnlocked(island);
  481. this.SetValue("UnlockedIsland" + island.GetIndex().ToString(), true);
  482. if (!flag)
  483. {
  484. this.stats.AddIslandUnlocked();
  485. }
  486. }
  487. else
  488. {
  489. UnityEngine.Debug.LogWarning("Invalid island (" + island.ToString() + ") passed to SetIslandUnlocked()");
  490. }
  491. }
  492. public decimal GetXpForLevelsUp(decimal levelsUp)
  493. {
  494. int i = this.Level - 1;
  495. int num = this.Level + (int)Math.Ceiling(levelsUp) + 1;
  496. while (i < num)
  497. {
  498. this.RecalculateRequiredXP(i);
  499. i++;
  500. }
  501. decimal d = Math.Min(1m - (decimal)this.LevelProgress, levelsUp);
  502. levelsUp -= d;
  503. int num2 = (int)Math.Floor(levelsUp);
  504. decimal d2 = levelsUp - num2;
  505. decimal d3 = (this.GetXpForLevel(this.Level) - this.GetXpForLevel(this.Level - 1)) * d;
  506. decimal d4 = this.GetXpForLevel(this.Level + num2) - this.GetXpForLevel(this.Level);
  507. decimal d5 = (this.GetXpForLevel(this.Level + num2 + 1) - this.GetXpForLevel(this.Level + num2)) * d2;
  508. return d3 + d4 + d5;
  509. }
  510. public void EarnCurrencies(Currencies c, object earnSource = null)
  511. {
  512. Currencies balance = this.Balance;
  513. this.Balance += c;
  514. this.CurrenciesEarned += c;
  515. this.FireBalanceChangedEvent(balance, this.Balance, earnSource);
  516. }
  517. public void GiveCurrencies(Currencies c)
  518. {
  519. Currencies balance = this.Balance;
  520. this.GiftedBalance += c;
  521. this.FireBalanceChangedEvent(balance, this.Balance, null);
  522. }
  523. public void CountBoughtGoldPackageIfApplicable(Currencies bought)
  524. {
  525. if (bought.Contains("Gold"))
  526. {
  527. this.stats.AddNumberOfGoldPackagesBought(1);
  528. }
  529. }
  530. public bool SpendCurrencies(Currencies c, bool enableGoldAsAlternativeForCash, Action<bool, Currencies> purchaseCallback)
  531. {
  532. Currencies currencies = this.Balance.MissingCurrencies(c);
  533. if (!currencies.IsEmpty())
  534. {
  535. SingletonMonobehaviour<PopupManager>.Instance.OpenYouNeedMore(c, enableGoldAsAlternativeForCash, purchaseCallback);
  536. return false;
  537. }
  538. ServiceLocator.Find<Messenger>().Invoke<InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>>(new InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>(CIGInterestingRatingTriggerEventType.SpendCurrencies));
  539. Currencies balance = this.Balance;
  540. this.Balance -= c;
  541. this.CurrenciesSpent += c;
  542. if (purchaseCallback != null)
  543. {
  544. purchaseCallback(true, c);
  545. }
  546. this.FireBalanceChangedEvent(balance, this.Balance, null);
  547. return true;
  548. }
  549. public void AddGlobalPopulation(int pop)
  550. {
  551. this.GlobalPopulation += pop;
  552. }
  553. public void AddGlobalHousing(int room)
  554. {
  555. this.GlobalHousing += room;
  556. }
  557. public void AddGlobalHappiness(int smiles)
  558. {
  559. this.GlobalHappiness += smiles;
  560. }
  561. public void AddGlobalEmployees(int emp)
  562. {
  563. this.GlobalEmployees += emp;
  564. }
  565. public void AddGlobalJobs(int jobs)
  566. {
  567. this.GlobalJobs += jobs;
  568. }
  569. public void GiveLevelUpReward()
  570. {
  571. Currencies levelUpReward = this.LevelUpReward;
  572. if (levelUpReward.IsEmpty())
  573. {
  574. return;
  575. }
  576. if (levelUpReward.ContainsPositive("Gold"))
  577. {
  578. }
  579. this.GiveCurrencies(levelUpReward);
  580. this.LevelUpReward = new Currencies();
  581. }
  582. public int XPNeededForGeneratedLevel(int level)
  583. {
  584. return this.Levels[this.MaxLevel].XP + (level - this.MaxLevel) * 50000;
  585. }
  586. protected void CheckGlobalValues()
  587. {
  588. int num = 0;
  589. int num2 = 0;
  590. int num3 = 0;
  591. int num4 = 0;
  592. int num5 = 0;
  593. IEnumerator enumerator = Enum.GetValues(typeof(Island)).GetEnumerator();
  594. try
  595. {
  596. while (enumerator.MoveNext())
  597. {
  598. object obj = enumerator.Current;
  599. Island island = (Island)obj;
  600. if (island.IsValid())
  601. {
  602. Dictionary<string, object> dictionary = CIGIslandState.GetDictionary(island);
  603. num += dictionary.GetInt("Happiness", 0);
  604. num2 += dictionary.GetInt("Housing", 0);
  605. num3 += dictionary.GetInt("Population", 0);
  606. num4 += dictionary.GetInt("Jobs", 0);
  607. num5 += dictionary.GetInt("Employees", 0);
  608. }
  609. }
  610. }
  611. finally
  612. {
  613. IDisposable disposable;
  614. if ((disposable = (enumerator as IDisposable)) != null)
  615. {
  616. disposable.Dispose();
  617. }
  618. }
  619. if (num != this.GlobalHappiness)
  620. {
  621. UnityEngine.Debug.LogWarning(string.Format("GlobalHappiness {0} does not match sum of (island) happiness {1}.", this.GlobalHappiness, num));
  622. this.GlobalHappiness = num;
  623. }
  624. if (num2 != this.GlobalHousing)
  625. {
  626. UnityEngine.Debug.LogWarning(string.Format("GlobalHousing {0} does not match sum of (island) housing {1}.", this.GlobalHousing, num2));
  627. this.GlobalHousing = num2;
  628. }
  629. if (num3 != this.GlobalPopulation)
  630. {
  631. UnityEngine.Debug.LogWarning(string.Format("GlobalPopulation {0} does not match sum of (island) population {1}.", this.GlobalPopulation, num3));
  632. this.GlobalPopulation = num3;
  633. }
  634. if (num4 != this.GlobalJobs)
  635. {
  636. UnityEngine.Debug.LogWarning(string.Format("GlobalJobs {0} does not match sum of (island) jobs {1}.", this.GlobalJobs, num4));
  637. this.GlobalJobs = num4;
  638. }
  639. if (num5 != this.GlobalEmployees)
  640. {
  641. UnityEngine.Debug.LogWarning(string.Format("GlobalEmployees {0} does not match sum of (island) employees {1}.", this.GlobalEmployees, num5));
  642. this.GlobalEmployees = num5;
  643. }
  644. }
  645. private decimal ProcessXPGain(decimal newXp)
  646. {
  647. if (!this.ReachedMaxLevel)
  648. {
  649. return this.ProcessXPGainManual(newXp);
  650. }
  651. return this.ProcessXPGainGenerated(newXp);
  652. }
  653. private decimal ProcessXPGainManual(decimal newXp)
  654. {
  655. if (this.Level >= this.Levels.Length)
  656. {
  657. UnityEngine.Debug.LogWarning("What is there to process? Player is max level already");
  658. return 0m;
  659. }
  660. decimal d = this.Levels[this.Level].XP;
  661. while (this.Level < this.Levels.Length && newXp >= d)
  662. {
  663. this.LevelUpManual();
  664. if (this.Level == this.Levels.Length)
  665. {
  666. return this.ProcessXPGainGenerated(newXp);
  667. }
  668. d = this.Levels[this.Level].XP;
  669. }
  670. return newXp;
  671. }
  672. private decimal ProcessXPGainGenerated(decimal newXp)
  673. {
  674. if (this.Level == 150)
  675. {
  676. UnityEngine.Debug.LogWarning("What is there to process? Player is max generated level already");
  677. return 0m;
  678. }
  679. int value = this.XPNeededForGeneratedLevel(this.Level);
  680. while (newXp >= value)
  681. {
  682. this.LevelUpGenerated();
  683. if (this.Level == 150)
  684. {
  685. return value;
  686. }
  687. value = this.XPNeededForGeneratedLevel(this.Level);
  688. }
  689. return newXp;
  690. }
  691. private void LevelUpManual()
  692. {
  693. if (this.Level >= this.Levels.Length)
  694. {
  695. UnityEngine.Debug.LogWarning("Can't level up because the maximum level has been reached already.");
  696. return;
  697. }
  698. this.RecalculateRequiredXP(this.Level + 1);
  699. this.IncreaseLevel();
  700. Currencies reward = this.Levels[this.Level - 1].Reward;
  701. this.LevelUpReward += reward;
  702. this.LevelledUpPopups(reward);
  703. this.OnLevelledUp(this.Level);
  704. }
  705. private void LevelUpGenerated()
  706. {
  707. this.IncreaseLevel();
  708. Currencies currencies = new Currencies("Gold", 2m);
  709. this.LevelUpReward += currencies;
  710. this.LevelledUpPopups(currencies);
  711. this.OnLevelledUp(this.Level);
  712. }
  713. private void IncreaseLevel()
  714. {
  715. int level = this.Level;
  716. this.Level++;
  717. int level2 = this.Level;
  718. int numberOfTimesPlayed = SingletonMonobehaviour<CIGGameStats>.Instance.NumberOfTimesPlayed;
  719. if (numberOfTimesPlayed != 1)
  720. {
  721. if (numberOfTimesPlayed == 2)
  722. {
  723. }
  724. }
  725. else
  726. {
  727. }
  728. }
  729. protected void LevelledUpPopups(Currencies reward)
  730. {
  731. ServiceLocator.Find<Messenger>().Invoke<InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>>(new InterestingRatingTriggerEvent<CIGInterestingRatingTriggerEventType>(CIGInterestingRatingTriggerEventType.LevelUp));
  732. SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Applause);
  733. int popupLevel = this.Level;
  734. PopupManager instance = SingletonMonobehaviour<PopupManager>.Instance;
  735. instance.RequestPopup<LevelUpPopupState>(delegate(State state)
  736. {
  737. SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed("level_up");
  738. ((LevelUpPopupState)state).UpdateElements(popupLevel, reward);
  739. });
  740. if (this.Level == Mathf.Max(this.MaxLevel, 150))
  741. {
  742. instance.RequestGenericPopup(UISpriteType.Star, Localization.Key("maxed_out_header"), Localization.Key("max_level_reached"), Localization.Key("ok"), null, null, null, null, true);
  743. }
  744. }
  745. private string GetConnectionString(Island island1, Island island2)
  746. {
  747. int num = island1.GetIndex();
  748. int num2 = island2.GetIndex();
  749. if (num > num2)
  750. {
  751. int num3 = num;
  752. num = num2;
  753. num2 = num3;
  754. }
  755. return string.Format(":{0}-{1}:", num, num2);
  756. }
  757. private void RecalculateRequiredXP(int level)
  758. {
  759. if (level < 0 || level >= this.Levels.Length)
  760. {
  761. return;
  762. }
  763. decimal num;
  764. if (level <= 0)
  765. {
  766. num = 0.0m;
  767. }
  768. else if (level == 1)
  769. {
  770. num = 200.0m;
  771. }
  772. else
  773. {
  774. if (level < CIGGameState.BASE_XP_PER_LEVEL.Length)
  775. {
  776. num = CIGGameState.BASE_XP_PER_LEVEL[level];
  777. }
  778. else
  779. {
  780. num = CIGGameState.BASE_XP_PER_LEVEL[CIGGameState.BASE_XP_PER_LEVEL.Length - 1];
  781. }
  782. if (level > 12 || (int)Math.Round(num) == 0)
  783. {
  784. decimal d = (decimal)(this.FactorMinutesPerLevel + (float)level * this.FactorMinutesPerLevelPerLevel);
  785. num += this.stats.GlobalProfitPerHour.GetValue("XP") / 60.0m * level * d;
  786. }
  787. }
  788. num *= (decimal)base.GetComponent<CIGVariables>().FactorForUpLevellingSpeed;
  789. int num2;
  790. if (level == 0)
  791. {
  792. num2 = (int)num;
  793. }
  794. else
  795. {
  796. num2 = this.Levels[level - 1].XP + (int)num;
  797. }
  798. this.Levels[level].XP = num2;
  799. object[] value = this.GetValue<object[]>("RequiredXPValues", new object[0]);
  800. if (value != null && level < value.Length)
  801. {
  802. value[level] = num2;
  803. }
  804. }
  805. private int GetXpForLevel(int level)
  806. {
  807. return (level <= this.MaxLevel) ? this.Levels[level].XP : this.XPNeededForGeneratedLevel(level);
  808. }
  809. public const string LevelKey = "Level";
  810. public const string EarnedBalanceKey = "EarnedBalance";
  811. public const string GiftedBalanceKey = "GiftedBalance";
  812. public const string CurrenciesEarnedKey = "CurrenciesEarned";
  813. public const string CurrenciesSpentKey = "CurrenciesSpent";
  814. public const string GlobalHappinessKey = "GlobalHappiness";
  815. public const string GlobalPopulationKey = "GlobalPopulation";
  816. public const string GlobalHousingKey = "GlobalHousing";
  817. public const string GlobalEmployeesKey = "GlobalEmployees";
  818. public const string GlobalJobsKey = "GlobalJobs";
  819. public const string RequiredXPValuesKey = "RequiredXPValues";
  820. public const string CashCurrency = "Cash";
  821. public const string GoldCurrency = "Gold";
  822. public const string XPCurrency = "XP";
  823. public const string LevelUpCurrency = "LevelUp";
  824. public const string UnprocessedPurchaseKey = "UnprocessedPurchase";
  825. public const string UnprocessedChestGoldKey = "UnprocessedChestGold";
  826. public const string IslandUnlockedKeyPrefix = "UnlockedIsland";
  827. public const string CraneCountKeyPrefix = "CraneCount";
  828. public const string IslandConnectionsKey = "IslandConnections";
  829. public const string LevelUpRewardKey = "LevelUpReward";
  830. public const int GeneratedLevelXPIncrements = 50000;
  831. public const int MaxGeneratedLevel = 150;
  832. private const string SpeedupWithCashEnabledKey = "SpeedupWithCashEnabled";
  833. private const string MaxBuildingLevel10Key = "MaxBuildingLevel10";
  834. private const string CloudStorageMigrationCompletedKey = "CloudStorageMigrationCompleted";
  835. public string storageKey = "GameState";
  836. [SelfReference]
  837. public GameObjectManager prefabManager;
  838. [SelfReference]
  839. public CIGGameStats stats;
  840. public Currencies InitialBalance = new Currencies();
  841. public LevelDefinition[] Levels = new LevelDefinition[0];
  842. public int BaseHappiness;
  843. public Island[] initialIslandUnlocks;
  844. [Tooltip("een level duurt zo lang als de waarde van het level maal dit getal, in minuten")]
  845. public float FactorMinutesPerLevel = 0.1f;
  846. [Tooltip("PER LEVEL gaat de factor hierboven omhoog")]
  847. public float FactorMinutesPerLevelPerLevel = 0.175f;
  848. private IEnumerator _syncGameScoresRoutine;
  849. private static readonly long[] BASE_XP_PER_LEVEL = new long[]
  850. {
  851. 132L,
  852. 212L,
  853. 292L,
  854. 372L,
  855. 452L,
  856. 532L,
  857. 612L,
  858. 692L,
  859. 772L,
  860. 935L,
  861. 965L,
  862. 1335L,
  863. 1705L,
  864. 2075L,
  865. 2445L,
  866. 2815L,
  867. 3185L,
  868. 3555L,
  869. 3925L,
  870. 4661L,
  871. 4990L,
  872. 5377L,
  873. 5764L,
  874. 6151L,
  875. 6538L,
  876. 6925L,
  877. 7312L,
  878. 7699L,
  879. 8086L,
  880. 8858L,
  881. 10108L,
  882. 10604L,
  883. 11100L,
  884. 11596L,
  885. 12092L,
  886. 12588L,
  887. 13084L,
  888. 13580L,
  889. 14076L,
  890. 15063L,
  891. 17595L,
  892. 17760L,
  893. 17925L,
  894. 18090L,
  895. 18255L,
  896. 18420L,
  897. 18585L,
  898. 18750L,
  899. 18915L,
  900. 19241L,
  901. 23644L,
  902. 23644L,
  903. 23644L,
  904. 23644L,
  905. 23644L,
  906. 23644L,
  907. 23644L,
  908. 23644L,
  909. 23644L,
  910. 23644L,
  911. 28165L,
  912. 28165L,
  913. 28165L,
  914. 28165L,
  915. 28165L,
  916. 28165L,
  917. 28165L,
  918. 28165L,
  919. 28165L,
  920. 28165L,
  921. 31986L,
  922. 31986L,
  923. 31986L,
  924. 31986L,
  925. 31986L,
  926. 31986L,
  927. 31986L,
  928. 31986L,
  929. 31986L,
  930. 31986L,
  931. 39723L,
  932. 39723L,
  933. 39723L,
  934. 39723L,
  935. 39723L,
  936. 39723L,
  937. 39723L,
  938. 39723L,
  939. 39723L,
  940. 39723L,
  941. 39723L,
  942. 39723L,
  943. 39723L,
  944. 39723L,
  945. 39723L,
  946. 39723L,
  947. 39723L,
  948. 39723L,
  949. 39723L,
  950. 39723L
  951. };
  952. public delegate void BalanceChangedEventHandler(Currencies oldBalance, Currencies newBalance, object earnSource);
  953. }