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.
 
 
 

145 lines
3.3 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIGEnums;
  4. using SUISSEngine;
  5. using UnityEngine;
  6. namespace CIG
  7. {
  8. public class CIG3StoreProduct : StoreProduct, IComparable<CIG3StoreProduct>
  9. {
  10. public CIG3StoreProduct(StoreProduct product) : base(product)
  11. {
  12. this.Init();
  13. }
  14. public CIG3StoreProduct(Dictionary<string, object> properties) : base(properties)
  15. {
  16. this.Init();
  17. }
  18. public override void Update(Dictionary<string, object> props)
  19. {
  20. base.Update(props);
  21. this.Init();
  22. }
  23. public StoreProductCategory Category { get; private set; }
  24. public string GameProductName { get; private set; }
  25. public int From { get; private set; }
  26. public int To { get; private set; }
  27. public Currencies Currencies { get; private set; }
  28. public bool IsSale
  29. {
  30. get
  31. {
  32. return this.Category == StoreProductCategory.ShopSale;
  33. }
  34. }
  35. private void Init()
  36. {
  37. this.Currencies = new Currencies();
  38. string text;
  39. long value;
  40. if (base.CustomProperties.TryGetValue("gold_value", out text) && long.TryParse(text, out value))
  41. {
  42. this.Currencies += new Currencies("Gold", value);
  43. }
  44. if (base.CustomProperties.TryGetValue("cash_value", out text) && long.TryParse(text, out value))
  45. {
  46. this.Currencies += new Currencies("Cash", value);
  47. }
  48. if (base.CustomProperties.TryGetValue("category", out text))
  49. {
  50. StoreProductCategory category;
  51. if (CIG3StoreProduct.GameCategoryMapping.TryGetValue(text, out category))
  52. {
  53. this.Category = category;
  54. }
  55. else
  56. {
  57. this.Category = StoreProductCategory.Unknown;
  58. UnityEngine.Debug.LogErrorFormat("Missing mapping of GameCategory '{0}' for StoreProduct '{1}'", new object[]
  59. {
  60. text,
  61. base.Identifier
  62. });
  63. }
  64. }
  65. else
  66. {
  67. this.Category = StoreProductCategory.Unknown;
  68. }
  69. if (base.CustomProperties.TryGetValue("game_product_name", out text))
  70. {
  71. this.GameProductName = text;
  72. }
  73. else
  74. {
  75. this.GameProductName = string.Empty;
  76. }
  77. int num;
  78. if (base.CustomProperties.TryGetValue("from", out text) && int.TryParse(text, out num))
  79. {
  80. this.From = num;
  81. }
  82. else
  83. {
  84. this.From = 0;
  85. }
  86. if (base.CustomProperties.TryGetValue("to", out text) && int.TryParse(text, out num))
  87. {
  88. this.To = num;
  89. }
  90. else
  91. {
  92. this.To = 0;
  93. }
  94. }
  95. public int CompareTo(CIG3StoreProduct other)
  96. {
  97. int num = base.CompareTo(other);
  98. return (num != 0) ? num : this.Currencies.ContainsApproximate("Gold").CompareTo(other.Currencies.ContainsApproximate("Gold"));
  99. }
  100. private const string GoldValueKey = "gold_value";
  101. private const string CashValueKey = "cash_value";
  102. private const string GameCategoryKey = "category";
  103. private const string FromKey = "from";
  104. private const string ToKey = "to";
  105. private const string GameProductNameKey = "game_product_name";
  106. private static readonly Dictionary<string, StoreProductCategory> GameCategoryMapping = new Dictionary<string, StoreProductCategory>
  107. {
  108. {
  109. "shop",
  110. StoreProductCategory.Shop
  111. },
  112. {
  113. "shopSale",
  114. StoreProductCategory.ShopSale
  115. },
  116. {
  117. "pack",
  118. StoreProductCategory.Packs
  119. },
  120. {
  121. "crane",
  122. StoreProductCategory.Cranes
  123. }
  124. };
  125. }
  126. }