ItemUtil.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. int count = 0;
  105. if (item.Length > 1)
  106. {
  107. count = item[1];
  108. }
  109. else
  110. {
  111. count = 1;
  112. }
  113. ItemData itemData = createItemData(item[0], count * num);
  114. itemList.Add(itemData);
  115. }
  116. return itemList;
  117. }
  118. public static List<ItemData> CreateItemDataList(int itemId, int count)
  119. {
  120. List<ItemData> itemList = new List<ItemData>();
  121. ItemData itemData = createItemData(itemId, count);
  122. itemList.Add(itemData);
  123. return itemList;
  124. }
  125. public static ItemData createItemData(int[] bonus)
  126. {
  127. int itemID = bonus[0];
  128. int itemNum = 1;
  129. if (bonus.Length > 1)
  130. {
  131. itemNum = bonus[1];
  132. }
  133. return createItemData(itemID, itemNum);
  134. }
  135. public static ItemData createItemData(int itemId, int count)
  136. {
  137. ItemData itemData = ItemDataPool.GetItemData(itemId);
  138. itemData.num = count;
  139. return itemData;
  140. }
  141. public static Boolean CheckItemEnough(int itemId, int num)
  142. {
  143. int hasNum = ItemDataManager.GetItemNum(itemId);
  144. return hasNum >= num;
  145. }
  146. public static bool CheckMenuType1(int needItemId, int needSuitId, int typeId)
  147. {
  148. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(typeId);
  149. if (needItemId > 0)
  150. {
  151. int subType = ItemUtilCS.GetItemSubType(needItemId);
  152. if (subType == cfg1.type)
  153. {
  154. return true;
  155. }
  156. else if (cfg1.subMenusArr.Length > 0)
  157. {
  158. foreach (int id2 in cfg1.subMenusArr)
  159. {
  160. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
  161. if (cfg2.type == subType)
  162. {
  163. return true;
  164. }
  165. }
  166. }
  167. }
  168. else if (needSuitId > 0 && cfg1.type == ConstDressUpItemType.TAO_ZHUANG)
  169. {
  170. return true;
  171. }
  172. return false;
  173. }
  174. public static void SortItemIdsByOwned(int[] array)
  175. {
  176. Array.Sort(array, (int a, int b) =>
  177. {
  178. bool ownedA = ItemDataManager.GetItemNum(a) > 0;
  179. bool ownedB = ItemDataManager.GetItemNum(b) > 0;
  180. if (!ownedB && ownedA)
  181. {
  182. return 1;
  183. }
  184. else if (ownedB && !ownedA)
  185. {
  186. return -1;
  187. }
  188. return 0;
  189. });
  190. }
  191. public static string GetItemResExt(int itemType, int type)
  192. {
  193. if (itemType == ConstItemType.DRESS_UP && type == ConstDressUpItemType.BEI_JING)
  194. {
  195. return "jpg";
  196. }
  197. return "png";
  198. }
  199. }
  200. }