123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- 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<GiftType, string> TypeLabelDictionary = new Dictionary<GiftType, string>
- {
- {GiftType.金币,"g"},
- {GiftType.钻石,"d"},
- {GiftType.礼包,"p"},
- {GiftType.花朵,"f"},
- {GiftType.服装,"c"},
- {GiftType.开垦土地,"s"},
- {GiftType.精灵,"a"},
- };
- #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());
- int value = (int) jsonData["g"];
- if (value != 0)
- {
- Types.Add(GiftType.金币);
- Values.Add(new List<int> {value});
- }
- value = (int)jsonData["d"];
- if (value != 0)
- {
- Types.Add(GiftType.钻石);
- Values.Add(new List<int> { value });
- }
- string values = (string)jsonData["p"];
- if (values != "0")
- {
- Types.Add(GiftType.礼包);
- Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
- }
- values = (string)jsonData["f"];
- if (values != "0")
- {
- Types.Add(GiftType.花朵);
- Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
- }
- values = (string)jsonData["c"];
- if (values != "0")
- {
- Types.Add(GiftType.服装);
- Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
- }
- value = (int)jsonData["s"];
- if (value != 0)
- {
- Types.Add(GiftType.开垦土地);
- Values.Add(new List<int> { value });
- }
- values = (string)jsonData["a"];
- if (values != "0")
- {
- Types.Add(GiftType.精灵);
- Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
- }
- StartDate = DateTime.Parse(jsonData["starttime"].ToString());
- EndDate = DateTime.Parse(jsonData["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 (ManaServer.Time > EndDate)
- {
- //Debug.Log("has't start");
- return;
- }
- if (ManaServer.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 CloseRatio = 0.25f;
- private float AbilityRatio = 0.25f;
- private void GetGift(GiftType type, int value)
- {
- if (type == GiftType.开垦土地)
- {
- for (int i = 0; i < value; i++)
- {
- ManaGarden.UnlockSlot();
- int extraSlot = ManaData.GetPlayerInt(PlayerConfigLabel.ExtraSlot);
- ManaData.SavePlayerInt(PlayerConfigLabel.ExtraSlot, extraSlot + 1);
- //Debug.LogWarning($"{type}");
- }
- }
- else if (type == GiftType.服装)
- {
- CloseUnit closeUnit = ManaPlayer.CloseUnitDic[value];
- if (closeUnit.Bought)
- {
- /*ExchangeInfo info = */closeUnit.GetExchangeValue(CloseRatio, StaticsManager.ConsumeModule.Gift);
- //Debug.LogWarning($"{type} {info.Current} {info.Value}");
- }
- else
- {
- closeUnit.OnBuySucceed();
- //Debug.LogWarning($"{type} {value}");
- }
- }
- else if (type == GiftType.礼包)
- {
- (ManaCenter.SkillDic[SkillConfigLabel.Pack + value] as Pack).PurchaseResult(false);
- //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
- }
- else if (type == GiftType.精灵)
- {
- Ability ability = (Ability) ManaCenter.SkillDic[SkillConfigLabel.Ability + value];
- if (ability.ItemStatus == SkillStatus.Lock)
- {
- /*ExchangeInfo info = */ability.GetUnlockAheadExchangeValue(AbilityRatio, 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 = ManaGarden.FlowerInfoDic[value];
- if (!flowerInfo.Unlock)
- {
- flowerInfo.Unlock = true;
- //Debug.LogWarning($"{type} {flowerInfo.Name}");
- }
- else
- {
- flowerInfo.Amount++;
- //Debug.LogWarning($"{type} {flowerInfo.Name}");
- }
- }
- else if (type == GiftType.金币)
- {
- ManaCenter.AddCoin(value, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Gift);
- //Debug.LogWarning($"{type} {value}");
- }
- else if (type == GiftType.钻石)
- {
- ManaCenter.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 GetGiftList(JsonData jsonData)
- {
- //Debug.LogWarning("Inited");
- Inited = true;
- for (int i = 0; i < jsonData.Count; i++)
- {
- GiftDictionary.Add((int) jsonData[i]["packid"], new Gift(jsonData[i]));
- }
- }
- public static void GetGiftProcess(int packID)
- {
- if (!Inited)
- {
- ManaServer.GetThanksGiftInfo
- (
- jData =>
- {
- GetGiftList(jData);
- GetGift(packID);
- },
- () => Bubble.Show(null, Language.GetStr("UI", "获取充值返礼信息失败")
- )
- );
- }
- else
- {
- GetGift(packID);
- }
- }
- public static void GetGift(int packID)
- {
- if (GiftDictionary.ContainsKey(packID))
- {
- //Debug.Log("have gift");
- Gift gift = GiftDictionary[packID];
- gift.GetAllGift();
- }
- else
- {
- //Debug.Log("no gift");
- }
- }
- }
|