ItemUtil.cs 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using ET;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class ItemUtil
  9. {
  10. /// <param name="showTips">是否弹购买成功飘字,默认是</param>
  11. /// <param name="openSource">是否打开来源界面。默认否</param>
  12. /// <param name="showTxtBuyTips">是否显示购买提示</param>
  13. public static void ExchangeItemById(int itemId, int num, bool showTips = true, Action onSuccess = null, bool openSource = false, int maxCount = 9990, bool showTxtBuyTips = false, string prefix = "")
  14. {
  15. if (itemId == ConstItemID.GOLD)
  16. {
  17. AddGold(num, onSuccess);
  18. }
  19. else if (itemId == ConstItemID.POWER)
  20. {
  21. AddPower();
  22. }
  23. else
  24. {
  25. BuyItemConteoller.Show(itemId, num, ConstBuyType.TYPE_ITEM, 0, onSuccess, showTips, openSource, maxCount);
  26. BuyItemConteoller.showTxtBuyTips = showTxtBuyTips;
  27. }
  28. }
  29. public static void AddPower(string prefix = "", Action onSuccess = null)
  30. {
  31. int maxLimit = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.POWER).maxLimit;
  32. int lastBuyCount = maxLimit - ItemDataManager.GetItemExchangeTimes(ConstItemID.POWER);
  33. string showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买{0}/{1}次", lastBuyCount, maxLimit);
  34. BuyConfirmController.Show(ConstItemID.POWER, 1, () =>
  35. {
  36. if (onSuccess != null)
  37. {
  38. onSuccess();
  39. }
  40. }, showTxt);
  41. }
  42. public static void AddGold(int value = 0, Action onSuccess = null)
  43. {
  44. BuyConfirmController.Show(ConstItemID.GOLD, 1, () =>
  45. {
  46. if (onSuccess != null)
  47. {
  48. onSuccess();
  49. }
  50. });
  51. }
  52. public static void AddDiamondPurple()
  53. {
  54. ViewManager.Show(ViewName.RECHARGE_STORE_VIEW);
  55. }
  56. //红钻(鲛绡)
  57. public static void AddDiamondRed(int value = 0, Action onSuccess = null)
  58. {
  59. ItemExchangeCfg currencyRatioCfg = ItemExchangeCfgArray.Instance.GetCfg(ConstItemID.DIAMOND_RED);// GetCurrencyRatioCfgById(ConstItemID.DIAMOND_RED);
  60. BuyItemConteoller.Show(currencyRatioCfg.id, value > 0 ? value : 1, ConstBuyType.TYPE_ITEM, 0, onSuccess, true, true);
  61. BuyItemConteoller.showTxtBuyTips = true;
  62. }
  63. public static string GetItemName(int itemId)
  64. {
  65. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  66. return itemCfg.name;
  67. }
  68. public static string GetSuitName(int suitId)
  69. {
  70. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  71. return suitCfg.name;
  72. }
  73. public static int GetItemRarity(int itemId)
  74. {
  75. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  76. return itemCfg.rarity;
  77. }
  78. public static List<ItemData> CreateItemDataList(List<ItemInfoProto> items)
  79. {
  80. List<ItemData> itemList = new List<ItemData>();
  81. for (int i = 0; i < items.Count; i++)
  82. {
  83. ItemData itemData = createItemData(items[i].ConfigId, items[i].Count);
  84. itemList.Add(itemData);
  85. }
  86. return itemList;
  87. }
  88. public static List<ItemData> CreateItemDataList(int[][] bonus, bool isOnceBonus = false)
  89. {
  90. List<ItemData> itemList = new List<ItemData>();
  91. foreach (int[] item in bonus)
  92. {
  93. ItemData itemData = createItemData(item);
  94. itemList.Add(itemData);
  95. itemData.isOnceBonus = isOnceBonus;
  96. }
  97. return itemList;
  98. }
  99. public static List<ItemData> CreateItemDataList(int[][] bonus, int num)
  100. {
  101. List<ItemData> itemList = new List<ItemData>();
  102. foreach (int[] item in bonus)
  103. {
  104. ItemData itemData = createItemData(item[0], item[1] * num);
  105. itemList.Add(itemData);
  106. }
  107. return itemList;
  108. }
  109. public static List<ItemData> CreateItemDataList(int itemId, int count)
  110. {
  111. List<ItemData> itemList = new List<ItemData>();
  112. ItemData itemData = createItemData(itemId, count);
  113. itemList.Add(itemData);
  114. return itemList;
  115. }
  116. public static ItemData createItemData(int[] bonus)
  117. {
  118. int itemID = bonus[0];
  119. int itemNum = 1;
  120. if (bonus.Length > 1)
  121. {
  122. itemNum = bonus[1];
  123. }
  124. return createItemData(itemID, itemNum);
  125. }
  126. public static ItemData createItemData(int itemId, int count)
  127. {
  128. ItemData itemData = ItemDataPool.GetItemData(itemId);
  129. itemData.num = count;
  130. return itemData;
  131. }
  132. public static Boolean CheckItemEnough(int itemId, int num)
  133. {
  134. int hasNum = ItemDataManager.GetItemNum(itemId);
  135. return hasNum >= num;
  136. }
  137. public static bool CheckMenuType1(int needItemId, int needSuitId, int typeId)
  138. {
  139. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(typeId);
  140. if (needItemId > 0)
  141. {
  142. int subType = ItemUtilCS.GetItemSubType(needItemId);
  143. if (subType == cfg1.type)
  144. {
  145. return true;
  146. }
  147. else if (cfg1.subMenusArr.Length > 0)
  148. {
  149. foreach (int id2 in cfg1.subMenusArr)
  150. {
  151. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
  152. if (cfg2.type == subType)
  153. {
  154. return true;
  155. }
  156. }
  157. }
  158. }
  159. else if (needSuitId > 0 && cfg1.type == ConstDressUpItemType.TAO_ZHUANG)
  160. {
  161. return true;
  162. }
  163. return false;
  164. }
  165. public static void SortItemIdsByOwned(int[] array)
  166. {
  167. Array.Sort(array, (int a, int b) =>
  168. {
  169. bool ownedA = ItemDataManager.GetItemNum(a) > 0;
  170. bool ownedB = ItemDataManager.GetItemNum(b) > 0;
  171. if (!ownedB && ownedA)
  172. {
  173. return 1;
  174. }
  175. else if (ownedB && !ownedA)
  176. {
  177. return -1;
  178. }
  179. return 0;
  180. });
  181. }
  182. public static string GetItemResExt(int itemType, int type)
  183. {
  184. if (itemType == ConstItemType.DRESS_UP && type == ConstDressUpItemType.BEI_JING)
  185. {
  186. return "jpg";
  187. }
  188. return "png";
  189. }
  190. }
  191. }