123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine;
- public class ThanksGiftJson
- {
- public static string PackID = "packid";
- public static string StartTime = "starttime";
- public static string EndTime = "endtime";
- public static int UnvalidValue = 0;
- public static string UnvalidValues = "0";
- public static Dictionary<Gift.GiftType, string> TypeDictionary = new Dictionary<Gift.GiftType, string>
- {
- {Gift.GiftType.金币,"g"},
- {Gift.GiftType.钻石,"d"},
- {Gift.GiftType.礼包,"p"},
- {Gift.GiftType.花朵,"f"},
- {Gift.GiftType.服装,"c"},
- {Gift.GiftType.开垦土地,"s"},
- {Gift.GiftType.精灵,"a"},
- };
- }
- public class Gift
- {
- public enum GiftType
- {
- 金币 = 0,
- 钻石 = 1,
- 礼包 = 2,
- 花朵 = 3,
- 服装 = 4,
- 开垦土地 = 5,
- 精灵 = 6,
- }
- #region Config
- private List<List<int>> Values = new List<List<int>>();
- private List<GiftType> Types = new List<GiftType>();
- private DateTime StartDate;
- private DateTime EndDate;
- #endregion
- public Gift(JsonData jsonData)
- {
- //Debug.Log(jsonData.ToJson());
- string label = ThanksGiftJson.TypeDictionary[GiftType.金币];
- int value = (int) jsonData[label];
- if (value != ThanksGiftJson.UnvalidValue)
- {
- Types.Add(GiftType.金币);
- Values.Add(new List<int> {value});
- }
- label = ThanksGiftJson.TypeDictionary[GiftType.钻石];
- value = (int)jsonData[label];
- if (value != ThanksGiftJson.UnvalidValue)
- {
- Types.Add(GiftType.钻石);
- Values.Add(new List<int> { value });
- }
- label = ThanksGiftJson.TypeDictionary[GiftType.礼包];
- string values = (string)jsonData[label];
- if (values != ThanksGiftJson.UnvalidValues)
- {
- Types.Add(GiftType.礼包);
- Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
- }
- label = ThanksGiftJson.TypeDictionary[GiftType.花朵];
- values = (string)jsonData[label];
- if (values != ThanksGiftJson.UnvalidValues)
- {
- Types.Add(GiftType.花朵);
- Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
- }
- label = ThanksGiftJson.TypeDictionary[GiftType.服装];
- values = (string)jsonData[label];
- if (values != ThanksGiftJson.UnvalidValues)
- {
- Types.Add(GiftType.服装);
- Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
- }
- label = ThanksGiftJson.TypeDictionary[GiftType.开垦土地];
- value = (int)jsonData[label];
- if (value != ThanksGiftJson.UnvalidValue)
- {
- Types.Add(GiftType.开垦土地);
- Values.Add(new List<int> { value });
- }
- label = ThanksGiftJson.TypeDictionary[GiftType.精灵];
- values = (string)jsonData[label];
- if (values != ThanksGiftJson.UnvalidValues)
- {
- Types.Add(GiftType.精灵);
- Values.Add(Auxiliary.StringToInts(' ', values, new List<int>()));
- }
- StartDate = DateTime.Parse(jsonData[ThanksGiftJson.StartTime].ToString());
- EndDate = DateTime.Parse(jsonData[ThanksGiftJson.EndTime].ToString());
- //for (int i = 0; i < Types.Count; i++)
- //{
- // Debug.LogWarning(Types[i]);
- // for (int j = 0; j < Values[i].Count; j++)
- // {
- // Debug.Log(Values[i][j]);
- // }
- //}
- //Debug.LogWarning(StartDate);
- //Debug.LogWarning(EndDate);
- }
- public void GetAllGift()
- {
- if (HttpManager.Time > EndDate)
- {
- //Debug.Log("has't start");
- return;
- }
- if (HttpManager.Time < StartDate)
- {
- //Debug.Log("over");
- return;
- }
- for (int i = 0; i < Types.Count; i++)
- {
- for (int j = 0; j < Values[i].Count; j++)
- {
- GetGift(Types[i], Values[i][j]);
- }
- }
- }
- private float CloseExchangeRatio = 0.25f;
- private float AbilityExchangeRatio = 0.25f;
- private void GetGift(GiftType type, int value)
- {
- if (type == GiftType.开垦土地)
- {
- for (int i = 0; i < value; i++)
- {
- GardenManager.UnlockSlot();
- int extraSlot = ConfigManager.GetIntFormConfig(PlayerConfigLabel.ExtraSlot);
- ConfigManager.SaveIntToConfig(PlayerConfigLabel.ExtraSlot, extraSlot + 1);
- //Debug.LogWarning($"{type}");
- }
- }
- else if (type == GiftType.服装)
- {
- CloseItem closeItem = PlayerManager.CloseItemDic[value];
- if (closeItem.Possess)
- {
- /*ExchangeInfo info = */closeItem.GetExchangeValue(CloseExchangeRatio, StaticsManager.ConsumeModule.Gift);
- //Debug.LogWarning($"{type} {info.Current} {info.Value}");
- }
- else
- {
- closeItem.OnBuySucceed();
- //Debug.LogWarning($"{type} {value}");
- }
- }
- else if (type == GiftType.礼包)
- {
- string packID = SkillConfigLabel.GetFullID(SkillType.Pack, value);
- (Manager.SkillDic[packID] as Pack).OnBuySucceed(false);
- //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
- }
- else if (type == GiftType.精灵)
- {
- string abilityID = SkillConfigLabel.GetFullID(SkillType.Ability, value);
- Ability ability = Manager.SkillDic[abilityID] as Ability;
- if (ability.ItemStatus == SkillStatus.Lock)
- {
- /*ExchangeInfo info = */ability.GetUnlockAheadExchangeValue(AbilityExchangeRatio, StaticsManager.ConsumeModule.Gift);
- //Debug.LogWarning($"{type} {info.Current} {info.Value}");
- }
- else if (ability.ItemStatus == SkillStatus.UnLock)
- {
- ability.UnlockSucceed();
- //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
- }
- else if (ability.ItemStatus == SkillStatus.Upgrade)
- {
- ability.UpgradeSucceed();
- //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
- }
- }
- else if (type == GiftType.花朵)
- {
- FlowerInfo flowerInfo = GardenManager.FlowerInfoDic[value];
- flowerInfo.Add();
- //if (!flowerInfo.Unlock)
- //{
- // flowerInfo.Unlock = true;
- // //Debug.LogWarning($"{type} {flowerInfo.Name}");
- //}
- //else
- //{
- // flowerInfo.Amount++;
- // //Debug.LogWarning($"{type} {flowerInfo.Name}");
- //}
- }
- else if (type == GiftType.金币)
- {
- Manager.AddCoin(value, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Gift);
- //Debug.LogWarning($"{type} {value}");
- }
- else if (type == GiftType.钻石)
- {
- Manager.AddDiamond(value, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Gift);
- //Debug.LogWarning($"{type} {value}");
- }
- }
- }
- public class ThanksGift
- {
- #region Config
- private static bool Inited;
- private static Dictionary<int, Gift> GiftDictionary = new Dictionary<int, Gift>();
- #endregion
- public static void Init(JsonData jsonData)
- {
- //Debug.LogWarning("Inited");
- Inited = true;
- for (int i = 0; i < jsonData.Count; i++)
- {
- int packID = (int) jsonData[i][ThanksGiftJson.PackID];
- Gift gift = new Gift(jsonData[i]);
- GiftDictionary.Add(packID, gift);
- }
- }
- public static void GetAllGift(int packID)
- {
- if (!Inited)
- {
- HttpManager.GetThanksGiftInfo
- (
- jData =>
- {
- Init(jData);
- getGift(packID);
- },
- () => Bubble.Show(null, Language.GetStr(LanguageLabel.UI__GetThanksGiftInfoFailed)
- )
- );
- }
- else
- {
- getGift(packID);
- }
- }
- private static void getGift(int packID)
- {
- if (GiftDictionary.ContainsKey(packID))
- {
- //Debug.Log("have gift");
- Gift gift = GiftDictionary[packID];
- gift.GetAllGift();
- }
- else
- {
- //Debug.Log("no gift");
- }
- }
- }
|