using System; using System.Collections.Generic; using CIGEnums; using SUISSEngine; using UnityEngine; namespace CIG { public class CIG3StoreProduct : StoreProduct, IComparable { public CIG3StoreProduct(StoreProduct product) : base(product) { this.Init(); } public CIG3StoreProduct(Dictionary properties) : base(properties) { this.Init(); } public override void Update(Dictionary props) { base.Update(props); this.Init(); } public StoreProductCategory Category { get; private set; } public string GameProductName { get; private set; } public int From { get; private set; } public int To { get; private set; } public Currencies Currencies { get; private set; } public bool IsSale { get { return this.Category == StoreProductCategory.ShopSale; } } private void Init() { this.Currencies = new Currencies(); string text; long value; if (base.CustomProperties.TryGetValue("gold_value", out text) && long.TryParse(text, out value)) { this.Currencies += new Currencies("Gold", value); } if (base.CustomProperties.TryGetValue("cash_value", out text) && long.TryParse(text, out value)) { this.Currencies += new Currencies("Cash", value); } if (base.CustomProperties.TryGetValue("category", out text)) { StoreProductCategory category; if (CIG3StoreProduct.GameCategoryMapping.TryGetValue(text, out category)) { this.Category = category; } else { this.Category = StoreProductCategory.Unknown; UnityEngine.Debug.LogErrorFormat("Missing mapping of GameCategory '{0}' for StoreProduct '{1}'", new object[] { text, base.Identifier }); } } else { this.Category = StoreProductCategory.Unknown; } if (base.CustomProperties.TryGetValue("game_product_name", out text)) { this.GameProductName = text; } else { this.GameProductName = string.Empty; } int num; if (base.CustomProperties.TryGetValue("from", out text) && int.TryParse(text, out num)) { this.From = num; } else { this.From = 0; } if (base.CustomProperties.TryGetValue("to", out text) && int.TryParse(text, out num)) { this.To = num; } else { this.To = 0; } } public int CompareTo(CIG3StoreProduct other) { int num = base.CompareTo(other); return (num != 0) ? num : this.Currencies.ContainsApproximate("Gold").CompareTo(other.Currencies.ContainsApproximate("Gold")); } private const string GoldValueKey = "gold_value"; private const string CashValueKey = "cash_value"; private const string GameCategoryKey = "category"; private const string FromKey = "from"; private const string ToKey = "to"; private const string GameProductNameKey = "game_product_name"; private static readonly Dictionary GameCategoryMapping = new Dictionary { { "shop", StoreProductCategory.Shop }, { "shopSale", StoreProductCategory.ShopSale }, { "pack", StoreProductCategory.Packs }, { "crane", StoreProductCategory.Cranes } }; } }