ItemUtil.cs 6.6 KB

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