123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- using ET;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- namespace GFGGame
- {
- public class ItemUtil
- {
-
- /// <param name="showTips">是否弹购买成功飘字,默认是</param>
- /// <param name="openSource">是否打开来源界面。默认否</param>
- /// <param name="showTxtBuyTips">是否显示购买提示</param>
- 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 = "")
- {
- CurrencyRatioCfg currencyRatioCfg = GetCurrencyRatioCfgById(itemId);
- if (itemId == ConstItemID.GOLD)
- {
- AddGold(num, onSuccess);
- }
- else if (itemId == ConstItemID.POWER)
- {
- AddPower();
- }
- else
- {
- BuyItemConteoller.Show(itemId, currencyRatioCfg.costId, currencyRatioCfg.num, currencyRatioCfg.costNum, num, onSuccess, showTips, openSource, maxCount);
- BuyItemConteoller.showTxtBuyTips = showTxtBuyTips;
- }
- }
- public static CurrencyRatioCfg GetCurrencyRatioCfgById(int itemId)
- {
- CurrencyRatioCfg[] currencyRatioCfgs = CurrencyRatioCfgArray.Instance.GetCfgs(itemId);
- if (currencyRatioCfgs.Length == 0)
- {
- UnityEngine.Debug.LogWarning(itemId + "在h货币换算.xlsx中没有配置");
- return null;
- }
- CurrencyRatioCfg currencyRatioCfg;
- if (itemId == ConstItemID.POWER)
- {
- int powerBuyTimes = GameGlobal.myNumericComponent.GetAsInt(NumericType.PowerBuyTimes);
- //体力购买次数不同,对应消耗配置不同
- if (powerBuyTimes < currencyRatioCfgs.Length)
- {
- currencyRatioCfg = currencyRatioCfgs[powerBuyTimes];
- }
- else
- {
- currencyRatioCfg = currencyRatioCfgs[currencyRatioCfgs.Length - 1];
- }
- }
- else
- {
- currencyRatioCfg = currencyRatioCfgs[currencyRatioCfgs.Length - 1];
- }
- return currencyRatioCfg;
- }
- public static void AddPower(string prefix = "", Action onSuccess = null)
- {
- CurrencyRatioCfg currencyRatioCfg = GetCurrencyRatioCfgById(ConstItemID.POWER);
- int count = GetCostItemCount(ConstItemID.POWER, currencyRatioCfg.num);
- int powerBuyTimes = GameGlobal.myNumericComponent.GetAsInt(NumericType.PowerBuyTimes);
- int lastBuyCount = currencyRatioCfg.maxLimit - powerBuyTimes;
- string showTxt = string.Format("每5分钟回复1点体力\n今日剩余购买{0}/{1}次", lastBuyCount, currencyRatioCfg.maxLimit);
- BuyConfirmController.Show(ConstItemID.POWER, currencyRatioCfg.num, currencyRatioCfg.costId, currencyRatioCfg.costNum, () =>
- {
- NumericHelper.RequestAddAttributePoint(GameGlobal.zoneScene , NumericType.PowerBuyTimes).Coroutine();
- if (onSuccess != null)
- {
- onSuccess();
- }
- }, lastBuyCount, powerBuyTimes, showTxt);
- }
- public static void AddGold(int value = 0, Action onSuccess = null)
- {
- CurrencyRatioCfg currencyRatioCfg = GetCurrencyRatioCfgById(ConstItemID.GOLD);
- int count = value > 0 ? value : currencyRatioCfg.num;
- int costCount = GetCostItemCount(ConstItemID.GOLD, count);
- int lastBuyCount = currencyRatioCfg.maxLimit - GameGlobal.myNumericComponent.GetAsInt(NumericType.GoldBuyTimes);
- BuyConfirmController.Show(ConstItemID.GOLD, count, currencyRatioCfg.costId, costCount, () =>
- {
- NumericHelper.RequestAddAttributePoint(GameGlobal.zoneScene, NumericType.GoldBuyTimes).Coroutine();
- if (onSuccess != null)
- {
- onSuccess();
- }
- }, lastBuyCount, currencyRatioCfg.maxLimit);
- }
- public static void AddDiamondPurple()
- {
- ViewManager.Show(ViewName.RECHARGE_STORE_VIEW);
- }
- public static void AddDiamondPurple(int value, int costNum)
- {
- if (!AntiAddictionController.CheckAntiAddictionRecharge(costNum))
- {
- RoleDataManager.diaP += value;
- GameProxy.ReqUpdateRecharge(costNum);
- PromptController.Instance.ShowFloatTextPrompt("虚拟充值成功", MessageType.SUCCESS);
- }
- }
- //红钻(鲛绡)
- public static void AddDiamondRed(int value = 0, Action onSuccess = null)
- {
- CurrencyRatioCfg currencyRatioCfg = GetCurrencyRatioCfgById(ConstItemID.DIAMOND_RED);
- BuyItemConteoller.Show(currencyRatioCfg.id, currencyRatioCfg.costId, currencyRatioCfg.num, currencyRatioCfg.costNum, value > 0 ? value : currencyRatioCfg.num, onSuccess, true, true, GameConst.MAX_COUNT_TO_BUY_DIAMOND_RED);
- BuyItemConteoller.showTxtBuyTips = true;
- }
- /// <summary>
- /// 根据物品id和需求量获取兑换消耗品的消耗量
- /// </summary>
- public static int GetCostItemCount(int itemId, int count)
- {
- CurrencyRatioCfg currencyRatioCfg = GetCurrencyRatioCfgById(itemId);
- if (currencyRatioCfg != null)
- {
- return (int)Math.Ceiling((decimal)count / currencyRatioCfg.num * currencyRatioCfg.costNum);
- }
- else
- {
- return 0;
- }
- }
- /// <summary>
- /// 根据物品id和兑换消耗品的消耗量获取物品兑换量
- /// </summary>
- public static int GetItemExChangeCount(int itemId, int costCount)
- {
- CurrencyRatioCfg currencyRatioCfg = GetCurrencyRatioCfgById(itemId);
- if (currencyRatioCfg != null)
- {
- return (int)Math.Floor((decimal)costCount / currencyRatioCfg.costNum * currencyRatioCfg.num);
- }
- else
- {
- return 0;
- }
- }
- /// <summary>
- /// 添加物品,会消耗物品
- /// </summary>
- /// <param name="addId"></param>
- /// <param name="addNum"></param>
- /// <param name="costId"></param>
- /// <param name="costNum"></param>
- public static void AddItemUseCost(int addId, int addNum, int costId, int costNum)
- {
- ItemDataManager.Add(addId, addNum);
- ItemDataManager.Remove(costId, costNum);
- GetSuitItemController.TryShow(0);
- }
- public static string GetItemName(int itemId)
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
- return itemCfg.name;
- }
- public static string GetSuitName(int suitId)
- {
- SuitCfg suitCfg = SuitCfgArray.Instance.GetCfg(suitId);
- return suitCfg.name;
- }
- public static int GetItemRarity(int itemId)
- {
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId);
- return itemCfg.rarity;
- }
- public static List<ItemData> CreateItemDataList(string bonus, bool isOnceBonus = false)
- {
- List<ItemData> itemList = new List<ItemData>();
- string[] bonusList = bonus.Split(';');
- foreach (string i in bonusList)
- {
- if (i.Length > 0)
- {
- ItemData itemData = createItemData(i);
- itemList.Add(itemData);
- itemData.isOnceBonus = isOnceBonus;
- }
- }
- return itemList;
- }
- public static List<ItemData> CreateItemDataList(int[][] bonus, bool isOnceBonus = false)
- {
- List<ItemData> itemList = new List<ItemData>();
- foreach (int[] item in bonus)
- {
- ItemData itemData = createItemData(item);
- itemList.Add(itemData);
- itemData.isOnceBonus = isOnceBonus;
- }
- return itemList;
- }
- public static ItemData createItemData(string bonus)
- {
- string[] arr = bonus.Split('*');
- int itemID = int.Parse(arr[0]);
- int itemNum = 1;
- if (arr.Length > 1)
- {
- itemNum = int.Parse(arr[1]);
- }
- ItemData itemData = ItemDataPool.GetItemData(itemID);
- itemData.num = itemNum;
- return itemData;
- }
- public static ItemData createItemData(int[] bonus)
- {
- int itemID = bonus[0];
- int itemNum = 1;
- if (bonus.Length > 1)
- {
- itemNum = bonus[1];
- }
- ItemData itemData = ItemDataPool.GetItemData(itemID);
- itemData.num = itemNum;
- return itemData;
- }
- public static Boolean CheckItemEnough(int itemId, int num)
- {
- int hasNum = ItemDataManager.GetItemNum(itemId);
- return hasNum >= num;
- }
- public static bool CheckMenuType1(int needItemId, int needSuitId, int typeId)
- {
- DressUpMenuItemCfg1 cfg1 = DressUpMenuItemCfg1Array.Instance.GetCfg(typeId);
- if (needItemId > 0)
- {
- int subType = ItemUtilCS.GetItemSubType(needItemId);
- if (subType == cfg1.type)
- {
- return true;
- }
- else if (cfg1.subMenusArr.Length > 0)
- {
- foreach (int id2 in cfg1.subMenusArr)
- {
- DressUpMenuItemCfg2 cfg2 = DressUpMenuItemCfg2Array.Instance.GetCfg(id2);
- if (cfg2.type == subType)
- {
- return true;
- }
- }
- }
- }
- else if (needSuitId > 0 && cfg1.type == ConstDressUpItemType.TAO_ZHUANG)
- {
- return true;
- }
- return false;
- }
- public static void SortItemIdsByOwned(int[] array)
- {
- Array.Sort(array, (int a, int b) =>
- {
- bool ownedA = ItemDataManager.GetItemNum(a) > 0;
- bool ownedB = ItemDataManager.GetItemNum(b) > 0;
- if (!ownedB && ownedA)
- {
- return 1;
- }
- else if (ownedB && !ownedA)
- {
- return -1;
- }
- return 0;
- });
- }
- public static string GetItemResExt(int itemType, int type)
- {
- if (itemType == ConstItemType.DRESS_UP && type == ConstDressUpItemType.BEI_JING)
- {
- return "jpg";
- }
- return "png";
- }
- }
- }
|