using ET; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; namespace GFGGame { public class ItemUtil { /// 是否弹购买成功飘字,默认是 /// 是否打开来源界面。默认否 /// 是否显示购买提示 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; } /// /// 根据物品id和需求量获取兑换消耗品的消耗量 /// 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; } } /// /// 根据物品id和兑换消耗品的消耗量获取物品兑换量 /// 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; } } /// /// 添加物品,会消耗物品 /// /// /// /// /// 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 CreateItemDataList(int[][] bonus, bool isOnceBonus = false) { List itemList = new List(); foreach (int[] item in bonus) { ItemData itemData = createItemData(item); itemList.Add(itemData); itemData.isOnceBonus = isOnceBonus; } return itemList; } public static ItemData createItemData(int[] bonus) { int itemID = bonus[0]; int itemNum = 1; if (bonus.Length > 1) { itemNum = bonus[1]; } return createItemData(itemID, itemNum); } public static ItemData createItemData(int itemId, int count) { ItemData itemData = ItemDataPool.GetItemData(itemId); itemData.num = count; 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"; } } }