using System; using System.Collections; using System.Collections.Generic; using LitJson; using UnityEngine; public class Gift { private enum GiftType { 金币 = 0, 钻石 = 1, 礼包 = 2, 花朵 = 3, 服装 = 4, 开垦土地 = 5, 精灵 = 6, } private static Dictionary TypeLabelDictionary = new Dictionary { {GiftType.金币,"g"}, {GiftType.钻石,"d"}, {GiftType.礼包,"p"}, {GiftType.花朵,"f"}, {GiftType.服装,"c"}, {GiftType.开垦土地,"s"}, {GiftType.精灵,"a"}, }; #region Config private static int UnvalidValue = 0; private static string UnvalidValues = "0"; private static string StartTimeLabel = "starttime"; private static string EndTimeLabel = "endtime"; private List> Values = new List>(); private List Types = new List(); private DateTime StartDate; private DateTime EndDate; #endregion public Gift(JsonData jsonData) { //Debug.Log(jsonData.ToJson()); int value = (int) jsonData[TypeLabelDictionary[GiftType.金币]]; if (value != UnvalidValue) { Types.Add(GiftType.金币); Values.Add(new List {value}); } value = (int)jsonData[TypeLabelDictionary[GiftType.钻石]]; if (value != UnvalidValue) { Types.Add(GiftType.钻石); Values.Add(new List { value }); } string values = (string)jsonData[TypeLabelDictionary[GiftType.礼包]]; if (values != UnvalidValues) { Types.Add(GiftType.礼包); Values.Add(Auxiliary.StringToInts(' ', values, new List())); } values = (string)jsonData[TypeLabelDictionary[GiftType.花朵]]; if (values != UnvalidValues) { Types.Add(GiftType.花朵); Values.Add(Auxiliary.StringToInts(' ', values, new List())); } values = (string)jsonData[TypeLabelDictionary[GiftType.服装]]; if (values != UnvalidValues) { Types.Add(GiftType.服装); Values.Add(Auxiliary.StringToInts(' ', values, new List())); } value = (int)jsonData[TypeLabelDictionary[GiftType.开垦土地]]; if (value != UnvalidValue) { Types.Add(GiftType.开垦土地); Values.Add(new List { value }); } values = (string)jsonData[TypeLabelDictionary[GiftType.精灵]]; if (values != UnvalidValues) { Types.Add(GiftType.精灵); Values.Add(Auxiliary.StringToInts(' ', values, new List())); } StartDate = DateTime.Parse(jsonData[StartTimeLabel].ToString()); EndDate = DateTime.Parse(jsonData[EndTimeLabel].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.GetPlayerInt(PlayerConfigLabel.ExtraSlot); ConfigManager.SavePlayerInt(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 GiftDictionary = new Dictionary(); #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]["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("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"); } } }