ThanksGift.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using LitJson;
  5. using UnityEngine;
  6. public class Gift
  7. {
  8. private enum GiftType
  9. {
  10. 金币 = 0,
  11. 钻石 = 1,
  12. 礼包 = 2,
  13. 花朵 = 3,
  14. 服装 = 4,
  15. 开垦土地 = 5,
  16. 精灵 = 6,
  17. }
  18. private static Dictionary<GiftType, string> TypeLabelDictionary = new Dictionary<GiftType, string>
  19. {
  20. {GiftType.金币,"g"},
  21. {GiftType.钻石,"d"},
  22. {GiftType.礼包,"p"},
  23. {GiftType.花朵,"f"},
  24. {GiftType.服装,"c"},
  25. {GiftType.开垦土地,"s"},
  26. {GiftType.精灵,"a"},
  27. };
  28. #region Config
  29. private List<List<int>> Values = new List<List<int>>();
  30. private List<GiftType> Types = new List<GiftType>();
  31. private DateTime StartDate;
  32. private DateTime EndDate;
  33. #endregion
  34. public Gift(JsonData jsonData)
  35. {
  36. //Debug.Log(jsonData.ToJson());
  37. int value = (int) jsonData["g"];
  38. if (value != 0)
  39. {
  40. Types.Add(GiftType.金币);
  41. Values.Add(new List<int> {value});
  42. }
  43. value = (int)jsonData["d"];
  44. if (value != 0)
  45. {
  46. Types.Add(GiftType.钻石);
  47. Values.Add(new List<int> { value });
  48. }
  49. string values = (string)jsonData["p"];
  50. if (values != "0")
  51. {
  52. Types.Add(GiftType.礼包);
  53. Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
  54. }
  55. values = (string)jsonData["f"];
  56. if (values != "0")
  57. {
  58. Types.Add(GiftType.花朵);
  59. Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
  60. }
  61. values = (string)jsonData["c"];
  62. if (values != "0")
  63. {
  64. Types.Add(GiftType.服装);
  65. Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
  66. }
  67. value = (int)jsonData["s"];
  68. if (value != 0)
  69. {
  70. Types.Add(GiftType.开垦土地);
  71. Values.Add(new List<int> { value });
  72. }
  73. values = (string)jsonData["a"];
  74. if (values != "0")
  75. {
  76. Types.Add(GiftType.精灵);
  77. Values.Add(Auxiliary.IntListParse(' ', values, new List<int>()));
  78. }
  79. StartDate = DateTime.Parse(jsonData["starttime"].ToString());
  80. EndDate = DateTime.Parse(jsonData["endtime"].ToString());
  81. //for (int i = 0; i < Types.Count; i++)
  82. //{
  83. // Debug.LogWarning(Types[i]);
  84. // for (int j = 0; j < Values[i].Count; j++)
  85. // {
  86. // Debug.Log(Values[i][j]);
  87. // }
  88. //}
  89. //Debug.LogWarning(StartDate);
  90. //Debug.LogWarning(EndDate);
  91. }
  92. public void GetAllGift()
  93. {
  94. if (ManaServer.Time > EndDate)
  95. {
  96. //Debug.Log("has't start");
  97. return;
  98. }
  99. if (ManaServer.Time < StartDate)
  100. {
  101. //Debug.Log("over");
  102. return;
  103. }
  104. for (int i = 0; i < Types.Count; i++)
  105. {
  106. for (int j = 0; j < Values[i].Count; j++)
  107. {
  108. GetGift(Types[i], Values[i][j]);
  109. }
  110. }
  111. }
  112. private float CloseRatio = 0.25f;
  113. private float AbilityRatio = 0.25f;
  114. private void GetGift(GiftType type, int value)
  115. {
  116. if (type == GiftType.开垦土地)
  117. {
  118. for (int i = 0; i < value; i++)
  119. {
  120. ManaGarden.UnlockSlot();
  121. int extraSlot = ManaData.GetPlayerInt(PlayerConfigLabel.ExtraSlot);
  122. ManaData.SavePlayerInt(PlayerConfigLabel.ExtraSlot, extraSlot + 1);
  123. //Debug.LogWarning($"{type}");
  124. }
  125. }
  126. else if (type == GiftType.服装)
  127. {
  128. CloseUnit closeUnit = ManaPlayer.CloseUnitDic[value];
  129. if (closeUnit.Bought)
  130. {
  131. /*ExchangeInfo info = */closeUnit.GetExchangeValue(CloseRatio, StaticsManager.ConsumeModule.Gift);
  132. //Debug.LogWarning($"{type} {info.Current} {info.Value}");
  133. }
  134. else
  135. {
  136. closeUnit.OnBuySucceed();
  137. //Debug.LogWarning($"{type} {value}");
  138. }
  139. }
  140. else if (type == GiftType.礼包)
  141. {
  142. (ManaCenter.SkillDic[SkillConfigLabel.Pack + value] as Pack).PurchaseResult(false);
  143. //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
  144. }
  145. else if (type == GiftType.精灵)
  146. {
  147. Ability ability = (Ability) ManaCenter.SkillDic[SkillConfigLabel.Ability + value];
  148. if (ability.ItemStatus == SkillStatus.Lock)
  149. {
  150. /*ExchangeInfo info = */ability.GetUnlockAheadExchangeValue(AbilityRatio, StaticsManager.ConsumeModule.Gift);
  151. //Debug.LogWarning($"{type} {info.Current} {info.Value}");
  152. }
  153. else if (ability.ItemStatus == SkillStatus.UnLock)
  154. {
  155. ability.UnlockSucceed();
  156. //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
  157. }
  158. else if (ability.ItemStatus == SkillStatus.Upgrade)
  159. {
  160. ability.UpgradeSucceed();
  161. //Debug.LogWarning($"{type} {SkillConfigLabel.Pack + value}");
  162. }
  163. }
  164. else if (type == GiftType.花朵)
  165. {
  166. FlowerInfo flowerInfo = ManaGarden.FlowerInfoDic[value];
  167. if (!flowerInfo.Unlock)
  168. {
  169. flowerInfo.Unlock = true;
  170. //Debug.LogWarning($"{type} {flowerInfo.Name}");
  171. }
  172. else
  173. {
  174. flowerInfo.Amount++;
  175. //Debug.LogWarning($"{type} {flowerInfo.Name}");
  176. }
  177. }
  178. else if (type == GiftType.金币)
  179. {
  180. ManaCenter.AddCoin(value, StaticsManager.ItemID.获得金币, StaticsManager.ConsumeModule.Gift);
  181. //Debug.LogWarning($"{type} {value}");
  182. }
  183. else if (type == GiftType.钻石)
  184. {
  185. ManaCenter.AddDiamond(value, StaticsManager.ItemID.获得钻石, StaticsManager.ConsumeModule.Gift);
  186. //Debug.LogWarning($"{type} {value}");
  187. }
  188. }
  189. }
  190. public class ThanksGift
  191. {
  192. #region Config
  193. private static bool Inited;
  194. private static Dictionary<int, Gift> GiftDictionary = new Dictionary<int, Gift>();
  195. #endregion
  196. public static void GetGiftList(JsonData jsonData)
  197. {
  198. //Debug.LogWarning("Inited");
  199. Inited = true;
  200. for (int i = 0; i < jsonData.Count; i++)
  201. {
  202. GiftDictionary.Add((int) jsonData[i]["packid"], new Gift(jsonData[i]));
  203. }
  204. }
  205. public static void GetGiftProcess(int packID)
  206. {
  207. if (!Inited)
  208. {
  209. ManaServer.GetThanksGiftInfo
  210. (
  211. jData =>
  212. {
  213. GetGiftList(jData);
  214. GetGift(packID);
  215. },
  216. () => Bubble.Show(null, Language.GetStr("UI", "获取充值返礼信息失败")
  217. )
  218. );
  219. }
  220. else
  221. {
  222. GetGift(packID);
  223. }
  224. }
  225. public static void GetGift(int packID)
  226. {
  227. if (GiftDictionary.ContainsKey(packID))
  228. {
  229. //Debug.Log("have gift");
  230. Gift gift = GiftDictionary[packID];
  231. gift.GetAllGift();
  232. }
  233. else
  234. {
  235. //Debug.Log("no gift");
  236. }
  237. }
  238. }