|
- using System;
- using System.Collections.Generic;
- using CIG;
- using SUISS.Core;
- using UnityEngine;
-
- public class IAPPackManager
- {
- private IAPPackManager()
- {
- }
-
- public IList<string> AllPackNames
- {
- get
- {
- if (this._fileCache == null)
- {
- this.LoadPacksFromDisk();
- }
- return this._allPackNames.AsReadOnly();
- }
- }
-
- public static IAPPackManager Instance
- {
- get
- {
- if (IAPPackManager._instance == null)
- {
- IAPPackManager._instance = new IAPPackManager();
- }
- return IAPPackManager._instance;
- }
- }
-
- public static bool StoreHasIAPPack(string packName)
- {
- IAPPack pack = IAPPackManager.Instance.CreatePack(packName);
- return SingletonMonobehaviour<CIGStoreManager>.Instance.Store != null && SingletonMonobehaviour<CIGStoreManager>.Instance.Store.FindProduct((CIG3StoreProduct p) => p.GameProductName == pack.Name) != null;
- }
-
- public static int LevelsInPack(string packName)
- {
- int result = 5;
- if (SingletonMonobehaviour<CIGGameState>.Instance.Level == Mathf.Max(SingletonMonobehaviour<CIGGameState>.Instance.MaxLevel, 150))
- {
- return result;
- }
- IAPPack iappack = IAPPackManager.Instance.CreatePack(packName);
- LevelUpItem levelUpItem = iappack.FindPackItem<LevelUpItem>();
- if (levelUpItem != null)
- {
- result = levelUpItem.Levels;
- }
- else
- {
- UnityEngine.Debug.LogWarning("IAP level pack does not contain LevelUpItem, assuming 5 in the interface");
- }
- return result;
- }
-
- public IAPPack CreatePack(string packName)
- {
- return IAPPack.Create(packName, this.GetPackProperties(packName));
- }
-
- private Dictionary<string, object> GetPackProperties(string packName)
- {
- if (this._fileCache == null)
- {
- this.LoadPacksFromDisk();
- }
- if (!this._fileCache.ContainsKey("Packs"))
- {
- return new Dictionary<string, object>();
- }
- Dictionary<string, object> dictionary = this._fileCache["Packs"] as Dictionary<string, object>;
- if (!dictionary.ContainsKey(packName))
- {
- return new Dictionary<string, object>();
- }
- Dictionary<string, object> dictionary2 = dictionary[packName] as Dictionary<string, object>;
- if (dictionary2 == null)
- {
- return new Dictionary<string, object>();
- }
- return dictionary2;
- }
-
- private string[] GetAllPackNames()
- {
- string[] array = new string[this.AllPackNames.Count];
- this.AllPackNames.CopyTo(array, 0);
- return array;
- }
-
- private void LoadPacksFromDisk()
- {
- bool flag;
- this._fileCache = this.LoadJSONFile("iappacks.properties", out flag);
- this._allPackNames = new List<string>();
- if (!flag)
- {
- UnityEngine.Debug.LogError(string.Format("There was an error loading/parsing JSON file '{0}'.", "iappacks.properties"));
- return;
- }
- try
- {
- Dictionary<string, object> dictionary = this._fileCache["Packs"] as Dictionary<string, object>;
- foreach (KeyValuePair<string, object> keyValuePair in dictionary)
- {
- this._allPackNames.Add(keyValuePair.Key);
- }
- }
- catch (Exception exception)
- {
- UnityEngine.Debug.LogException(exception);
- }
- }
-
- private Dictionary<string, object> LoadJSONFile(string file, out bool success)
- {
- TextAsset textAsset = Resources.Load<TextAsset>(file);
- if (textAsset == null)
- {
- UnityEngine.Debug.LogError(string.Format("Can't load text asset '{0}'.", file));
- success = false;
- return new Dictionary<string, object>();
- }
- object obj = Json.Decode(textAsset.text);
- if (obj == null)
- {
- UnityEngine.Debug.LogError(string.Format("Can't load/parse JSON file '{0}'.", file));
- success = false;
- return new Dictionary<string, object>();
- }
- if (!(obj is Dictionary<string, object>))
- {
- UnityEngine.Debug.LogError(string.Format("I expected to find a Dictionary<string, object> as root while decoding JSON file '{0}', but I found a '{1}'.", file, obj.GetType()));
- success = false;
- return new Dictionary<string, object>();
- }
- Dictionary<string, object> dictionary = obj as Dictionary<string, object>;
- if (!dictionary.ContainsKey("Packs"))
- {
- UnityEngine.Debug.LogError(string.Format("Did not find an object with the key '{0}' while decoding JSON file '{1}'", "Packs", file));
- success = false;
- return new Dictionary<string, object>();
- }
- if (!(dictionary["Packs"] is Dictionary<string, object>))
- {
- UnityEngine.Debug.LogError(string.Format("Expected to find an object of type Dictionary<string, object> for the key '{0}', but I found a '{1}'.", "Packs", dictionary["Packs"].GetType()));
- success = false;
- return new Dictionary<string, object>();
- }
- success = true;
- return dictionary;
- }
-
- public const string File = "iappacks.properties";
-
- public const string PacksKey = "Packs";
-
- public const string Pack5Level = "pack_5_levels";
-
- public const string Pack4x = "pack_4x";
-
- public const string Pack2x = "pack_2x";
-
- public const string PackTimeboost12 = "pack_timeboost_12";
-
- public const string PackTimeboost24 = "pack_timeboost_24";
-
- private List<string> _allPackNames;
-
- private Dictionary<string, object> _fileCache;
-
- private static IAPPackManager _instance;
- }
|