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.
 
 
 

96 line
2.6 KiB

  1. using System;
  2. using CIG;
  3. using SUISS.Core;
  4. using SUISSEngine;
  5. using UnityEngine;
  6. public class BuyExpansionPopupState : PopupBaseState
  7. {
  8. public CIGExpansions.ExpansionBlock Block
  9. {
  10. get
  11. {
  12. return this._block;
  13. }
  14. set
  15. {
  16. this._block = value;
  17. if (value != null)
  18. {
  19. this._price = value.Price;
  20. ((BuyExpansionPopupView)this.View).SetPrice(this._price);
  21. }
  22. else
  23. {
  24. UnityEngine.Debug.LogWarning("ExpansionBlock is null");
  25. }
  26. }
  27. }
  28. private Currencies Price
  29. {
  30. get
  31. {
  32. return this._price;
  33. }
  34. }
  35. public override void Init()
  36. {
  37. base.Init();
  38. }
  39. public override void Enter(State oldState)
  40. {
  41. base.Enter(oldState);
  42. this.expansions = CityIsland.Current.GetComponent<CIGExpansions>();
  43. }
  44. public void BuyWith(string currency)
  45. {
  46. string str = ", buying will be cancelled";
  47. if (this.Block == null)
  48. {
  49. UnityEngine.Debug.LogWarning("Buying unknown block" + str);
  50. }
  51. IsometricIsland current = IsometricIsland.Current;
  52. if (current == null)
  53. {
  54. UnityEngine.Debug.LogError("Cannot find island object" + str);
  55. }
  56. CIGGameState state = SingletonMonobehaviour<CIGGameState>.Instance;
  57. if (state == null)
  58. {
  59. UnityEngine.Debug.LogError("Game state is not known" + str);
  60. }
  61. decimal value = this.Price.GetValue(currency);
  62. Currencies toSpend = new Currencies(currency, value);
  63. base.ClosePopup(delegate ()
  64. {
  65. state.SpendCurrencies(toSpend, false, delegate (bool succes, Currencies spent)
  66. {
  67. if (succes)
  68. {
  69. this.expansions.UnlockBlock(this.Block, toSpend);
  70. CIGGameStats instance = SingletonMonobehaviour<CIGGameStats>.Instance;
  71. if (instance != null)
  72. {
  73. bool flag = spent.GetValue("Gold") > 0m;
  74. instance.AddExpansionPurchased(flag);
  75. if (flag)
  76. {
  77. instance.AddVirtualCurrencySpent();
  78. }
  79. }
  80. }
  81. });
  82. });
  83. }
  84. private CIGExpansions.ExpansionBlock _block;
  85. private Currencies _price;
  86. private CIGExpansions expansions;
  87. }