123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using UnityEngine;
- using System.Collections;
- public class Finances : MonoBehaviour {
- #region PowerUps
- private static int _magn;
- /// <summary>
- /// Current magnetism level
- /// </summary>
- public static int MagnetismLevel
- {
- get
- {
- return _magn;
- }
- set
- {
- if (value < 0)
- {
- return;
- }
- if (_magn != value)
- {
- _magn = value;
- PlayerPrefs.SetInt("Magnetism", _magn);
- PlayerPrefs.Save();
- }
- }
- }
- private static int _rage;
- /// <summary>
- /// Current Rage level
- /// </summary>
- public static int RageLevel
- {
- get
- {
- return _rage;
- }
- set
- {
- if (value < 0)
- {
- return;
- }
- if (_rage != value)
- {
- _rage = value;
- PlayerPrefs.SetInt("Rage", _rage);
- PlayerPrefs.Save();
- }
- }
- }
- public static int GetUpgradePrice(PowerupsMainControllerCS.PowerUps powerUp)
- {
- switch (powerUp)
- {
- case PowerupsMainControllerCS.PowerUps.Magnetism:
- switch (MagnetismLevel)
- {
- case 1: return 5000;
- case 2: return 10000;
- case 3: return 15000;
- case 4: return 20000;
- }
- break;
- case PowerupsMainControllerCS.PowerUps.Rage:
- switch (RageLevel)
- {
- case 1: return 5000;
- case 2: return 10000;
- case 3: return 15000;
- case 4: return 20000;
- }
- break;
- case PowerupsMainControllerCS.PowerUps.SuperSledge:
- switch (MagnetismLevel)
- {
- case 1: return 5000;
- case 2: return 10000;
- case 3: return 15000;
- case 4: return 20000;
- }
- break;
- }
- return 0;
- }
- public static void Upgrade(PowerupsMainControllerCS.PowerUps powerUp)
- {
- var price = GetUpgradePrice(powerUp);
- if (Coins < price)
- {
- return;
- }
- if (GetUpgradeLevel(powerUp) >= 5)
- {
- return;
- }
- Coins -= price;
- switch (powerUp)
- {
- case PowerupsMainControllerCS.PowerUps.SuperSledge:
- MagnetismLevel++;
- break;
- case PowerupsMainControllerCS.PowerUps.Magnetism:
- MagnetismLevel++;
- break;
- case PowerupsMainControllerCS.PowerUps.Rage:
- RageLevel++;
- break;
- }
- }
- public static int GetUpgradeLevel(PowerupsMainControllerCS.PowerUps powerUp)
- {
- switch (powerUp)
- {
- case PowerupsMainControllerCS.PowerUps.Magnetism:
- return MagnetismLevel;
- case PowerupsMainControllerCS.PowerUps.Rage:
- return RageLevel;
- case PowerupsMainControllerCS.PowerUps.SuperSledge:
- return MagnetismLevel;
- }
- return 0;
- }
- #endregion
- #region currency
- public enum Lots
- {
- ut_kr_iap_001,
- ut_kr_iap_002,
- ut_kr_iap_003
- }
- public static string CurrencySymbol { get; private set; }
- private static int _coins;
- /// <summary>
- /// Current player amount of coins
- /// </summary>
- public static int Coins
- {
- get
- {
- return _coins;
- }
- set
- {
- if (value < 0)
- {
- return;
- }
- if (_coins != value)
- {
- _coins = value;
- PlayerPrefs.SetInt("Coins", _coins);
- PlayerPrefs.Save();
- }
- }
- }
- private static int _bestScore;
- /// <summary>
- /// Current player amount of coins
- /// </summary>
- public static int BestScore
- {
- get
- {
- return _bestScore;
- }
- set
- {
- if (value < 0)
- {
- return;
- }
- if (_bestScore != value)
- {
- _bestScore = value;
- PlayerPrefs.SetInt("BestScore", _bestScore);
- PlayerPrefs.Save();
- UILeaderBoard.SummitScore(_bestScore);
- }
- }
- }
- private static readonly Dictionary<Lots, string> Prices = new Dictionary<Lots, string>();
- public static string GetLotID(Lots lot)
- {
- return string.Format("{0}",lot);
- }
- public static Lots GetLotID(string lot)
- {
- return (Lots)Enum.Parse(typeof(Lots), lot);
- }
- public static string GetPrice(Lots lot)
- {
- return (Prices.ContainsKey(lot) ? Prices[lot] : "");
- }
- public static int GetReward(Lots lot)
- {
- switch (lot)
- {
- case Lots.ut_kr_iap_001: return 5000;
- case Lots.ut_kr_iap_002: return 10000;
- case Lots.ut_kr_iap_003: return 20000;
- }
- return 0;
- }
- public NGUIMenuScript hNGUIMenuScript;
- #endregion
- /// <summary>
- ///
- /// </summary>
- public enum Costumes
- {
- Knight,
- Underpants
- }
- void Start ()
- {
- _coins = PlayerPrefs.GetInt("Coins",1000);
- _magn = PlayerPrefs.GetInt("Magnetism", 1);
- _rage = PlayerPrefs.GetInt("Rage", 1);
- _bestScore = PlayerPrefs.GetInt("BestScore", 0);
- if (_magn == 0)
- {
- _magn = 1;
- }
- if (_rage == 0)
- {
- _rage = 1;
- }
- PlayerPrefs.SetInt(Costumes.Knight.ToString(), 1);
- PlayerPrefs.Save();
- #if UNITY_IOS
- /*StoreKitBinding.requestProductData(Enum.GetNames(typeof(Lots)));
- StoreKitManager.productListReceivedEvent += onReceive;
- StoreKitManager.purchaseSuccessfulEvent += onPurchaseDone;
- StoreKitManager.purchaseFailedEvent += onPurchaseFail;*/
- #endif
- foreach (Costumes costume in Enum.GetValues(typeof(Costumes)))
- {
- if (!CostumesInfo.ContainsKey(costume))
- {
- CostumesInfo.Add(costume, PlayerPrefs.GetInt(costume.ToString(), 0) == 1);
- }
- }
- }
- private void Reset()
- {
- #if UNITY_EDITOR
- if (Application.isEditor)
- {
- PlayerPrefs.SetInt("FirstPlay", 1);
- PlayerPrefs.SetInt("FirstTimeInfoShown", 0);
- Coins = 1000;
- MagnetismLevel = 0;
- RageLevel = 0;
- BestScore = 0;
- foreach (Costumes costume in Enum.GetValues(typeof(Costumes)))
- {
- PlayerPrefs.SetInt(costume.ToString(), 0);
- }
- PlayerPrefs.SetInt(Costumes.Knight.ToString(), 1);
- UIEnergy.Instance.Restore();
- PlayerPrefs.Save();
- UnityEditor.EditorApplication.isPlaying = false;
- }
- #endif
- }
- void Update()
- {
- if (hNGUIMenuScript)
- {
- var menu = hNGUIMenuScript.getCurrentMenu();
- if (menu == NGUIMenuScript.NGUIMenus.ShopHome || menu == NGUIMenuScript.NGUIMenus.ShopCostumes
- || menu == NGUIMenuScript.NGUIMenus.ShopIAPs || menu == NGUIMenuScript.NGUIMenus.ShopPowerups
- || menu == NGUIMenuScript.NGUIMenus.ShopUtilities)
- hNGUIMenuScript.updateCurrencyOnHeader(hNGUIMenuScript.getCurrentMenu());
- }
- if (Input.GetKeyDown(KeyCode.Return))
- {
- Reset();
- }
- }
- #region PurchaseCallbacks
- #if UNITY_IOS
- private void onPurchaseFail(string message)
- {
- Debug.LogError("onPurchaseFail with message: "+ message);
- }
- /* private void onPurchaseDone(StoreKitTransaction product)
- {
- Coins += GetReward(GetLotID(product.productIdentifier));
- Debug.Log("onPurchaseDone " + product.productIdentifier);
- }*/
- /*private void onReceive(List<StoreKitProduct> products)
- {
- foreach (var product in products)
- {
- try
- {
- var id = GetLotID(product.productIdentifier);
- if (!Prices.ContainsKey(id))
- {
- Prices.Add(id,product.price);
- }
- }
- catch (Exception) { }
- }
- }*/
- #endif
- #endregion
- public static int GetCostumeCost(Costumes costume)
- {
- switch (costume)
- {
- case Costumes.Knight: return 0;
- case Costumes.Underpants: return 20000;
- }
- return 0;
- }
- private static readonly Dictionary<Costumes,bool> CostumesInfo = new Dictionary<Costumes, bool>();
- public static bool HasCostume(Costumes costume)
- {
- return CostumesInfo[costume];
- }
- public static void BuyCostume(Costumes costume)
- {
- if (HasCostume(costume))
- {
- return;
- }
- if (Coins >= GetCostumeCost(costume))
- {
- PlayerPrefs.SetInt(costume.ToString(),1);
- PlayerPrefs.Save();
- Coins -= GetCostumeCost(costume);
- CostumesInfo[costume] = true;
- }
- }
- }
|