|
@@ -1,43 +1,254 @@
|
|
|
-using System.Collections;
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
using System.Collections.Generic;
|
|
|
using LitJson;
|
|
|
using UnityEngine;
|
|
|
|
|
|
-public enum GiftType
|
|
|
+public class Gift
|
|
|
{
|
|
|
- 金币=0,
|
|
|
- 钻石 = 1,
|
|
|
- 礼包 = 2,
|
|
|
- 花朵 = 3,
|
|
|
- 服装 = 4,
|
|
|
- 开垦土地=5,
|
|
|
+ private enum GiftType
|
|
|
+ {
|
|
|
+ 金币 = 0,
|
|
|
+ 钻石 = 1,
|
|
|
+ 礼包 = 2,
|
|
|
+ 花朵 = 3,
|
|
|
+ 服装 = 4,
|
|
|
+ 开垦土地 = 5,
|
|
|
+ 精灵 = 6,
|
|
|
+ }
|
|
|
+
|
|
|
+ //private static Dictionary<char, GiftType> TypeDictionary = new Dictionary<char, GiftType>
|
|
|
+ //{
|
|
|
+ // {'g', GiftType.金币},
|
|
|
+ // {'d', GiftType.钻石},
|
|
|
+ // {'p', GiftType.礼包},
|
|
|
+ // {'f', GiftType.花朵},
|
|
|
+ // {'c', GiftType.服装},
|
|
|
+ // {'s', GiftType.开垦土地},
|
|
|
+ // {'a', GiftType.精灵},
|
|
|
+ //};
|
|
|
+
|
|
|
+ #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 Dictionary<int, List<KV<GiftType, int>>> GiftDictionary = new Dictionary<int, List<KV<GiftType, int>>>();
|
|
|
- private static Dictionary<char, GiftType> TypeDictionary = new Dictionary<char, GiftType>
|
|
|
- {
|
|
|
- {'g', GiftType.金币},
|
|
|
- {'d', GiftType.钻石},
|
|
|
- {'p', GiftType.礼包},
|
|
|
- {'f', GiftType.花朵},
|
|
|
- {'c', GiftType.服装},
|
|
|
- {'s', GiftType.开垦土地},
|
|
|
- };
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private static float CloseRatio = 0.25f;
|
|
|
- public static void Test(int 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");
|
|
|
+ }
|
|
|
}
|
|
|
}
|