ItemUtil.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. /// <summary>
  64. /// 添加物品,会消耗物品
  65. /// </summary>
  66. /// <param name="addId"></param>
  67. /// <param name="addNum"></param>
  68. /// <param name="costId"></param>
  69. /// <param name="costNum"></param>
  70. public static void AddItemUseCost(int addId, int addNum, int costId, int costNum)
  71. {
  72. ItemDataManager.Add(addId, addNum);
  73. ItemDataManager.Remove(costId, costNum);
  74. GetSuitItemController.TryShow(0);
  75. }
  76. public static string GetItemName(int itemId)
  77. {
  78. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  79. return itemCfg.name;
  80. }
  81. public static string GetSuitName(int suitId)
  82. {
  83. SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
  84. return suitCfg.name;
  85. }
  86. public static int GetItemRarity(int itemId)
  87. {
  88. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
  89. return itemCfg.rarity;
  90. }
  91. public static List<ItemData> CreateItemDataList(int[][] bonus, bool isOnceBonus = false)
  92. {
  93. List<ItemData> itemList = new List<ItemData>();
  94. foreach (int[] item in bonus)
  95. {
  96. ItemData itemData = createItemData(item);
  97. itemList.Add(itemData);
  98. itemData.isOnceBonus = isOnceBonus;
  99. }
  100. return itemList;
  101. }
  102. public static ItemData createItemData(int[] bonus)
  103. {
  104. int itemID = bonus[0];
  105. int itemNum = 1;
  106. if (bonus.Length > 1)
  107. {
  108. itemNum = bonus[1];
  109. }
  110. return createItemData(itemID, itemNum);
  111. }
  112. public static ItemData createItemData(int itemId, int count)
  113. {
  114. ItemData itemData = ItemDataPool.GetItemData(itemId);
  115. itemData.num = count;
  116. return itemData;
  117. }
  118. public static Boolean CheckItemEnough(int itemId, int num)
  119. {
  120. int hasNum = ItemDataManager.GetItemNum(itemId);
  121. return hasNum >= num;
  122. }
  123. public static bool CheckMenuType1(int needItemId, int needSuitId, int typeId)
  124. {
  125. DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(typeId);
  126. if (needItemId > 0)
  127. {
  128. int subType = ItemUtilCS.GetItemSubType(needItemId);
  129. if (subType == cfg1.type)
  130. {
  131. return true;
  132. }
  133. else if (cfg1.subMenusArr.Length > 0)
  134. {
  135. foreach (int id2 in cfg1.subMenusArr)
  136. {
  137. DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
  138. if (cfg2.type == subType)
  139. {
  140. return true;
  141. }
  142. }
  143. }
  144. }
  145. else if (needSuitId > 0 && cfg1.type == ConstDressUpItemType.TAO_ZHUANG)
  146. {
  147. return true;
  148. }
  149. return false;
  150. }
  151. public static void SortItemIdsByOwned(int[] array)
  152. {
  153. Array.Sort(array, (int a, int b) =>
  154. {
  155. bool ownedA = ItemDataManager.GetItemNum(a) > 0;
  156. bool ownedB = ItemDataManager.GetItemNum(b) > 0;
  157. if (!ownedB && ownedA)
  158. {
  159. return 1;
  160. }
  161. else if (ownedB && !ownedA)
  162. {
  163. return -1;
  164. }
  165. return 0;
  166. });
  167. }
  168. public static string GetItemResExt(int itemType, int type)
  169. {
  170. if (itemType == ConstItemType.DRESS_UP && type == ConstDressUpItemType.BEI_JING)
  171. {
  172. return "jpg";
  173. }
  174. return "png";
  175. }
  176. }
  177. }