using System.Collections.Generic; using Core.Language; using Excel2Json; using Fort23.Core; using Fort23.UTool; using GameLogic.Bag; using UnityEngine; namespace Fort23.Mono { [UIBinding(prefab = "DivineSenceRestoredWidget")] public partial class DivineSenceRestoredWidget : UIComponent { private ShopItemConfig ShopItemConfig; private AccountFileInfo.ShopItem shopItem; private ItemConfig itemConfig; private int openType; private void Init() { } public override void AddEvent() { } public override void DelEvent() { } public override void AddButtonEvent() { Btn_Use.onClick.AddListener(async () => { //购买并使用道具 if (openType == 1) { if (ShopItemConfig.buyCount != -1 && shopItem.buyCount >= ShopItemConfig.buyCount) { TipMessagePanel.OpenTipMessagePanel(811, Vector2.zero); return; } List itemInfos = await ShopManger.Instance.BuyItem(ShopItemConfig.ID, 1); if (itemInfos != null) { //使用道具 foreach (var itemInfo in itemInfos) { if (itemInfo.config.itemTag == 8) { AccountFileInfo.Instance.playerData.divineSensePoint += itemInfo.config.associateVlaue[0]; PlayerManager.Instance.BagController.DeductItem(itemInfo.config.ID, 1); } } CustomInit(ShopItemConfig.ID); } else { TipMessagePanel.OpenTipMessagePanel(833, Vector2.zero); } } //世界使用道具 else { if (PlayerManager.Instance.BagController.IsEnough(itemConfig.ID, 1)) { AccountFileInfo.Instance.playerData.divineSensePoint += itemConfig.associateVlaue[0]; PlayerManager.Instance.BagController.DeductItem(itemConfig.ID, 1); CustomInit(itemConfig.ID); } else { TipMessagePanel.OpenTipMessagePanel(10324, Vector2.zero); } } EventManager.Instance.Dispatch(CustomEventType.DivineSensePointChange, null); }); } public void CustomInit(int shopitemId) { openType = 1; ShopItemConfig = ConfigComponent.Instance.Get(shopitemId); shopItem = ShopManger.Instance.GetShopItem(shopitemId); itemConfig = ConfigComponent.Instance.Get(ShopItemConfig.itemId[0]); if (ShopItemConfig.costItemId == 0) { Group_Price.SetActive(false); Text_Free.gameObject.SetActive(true); Text_Free.text = LanguageManager.Instance.Text(10328); } else { ItemConfig costItemConfig = ConfigComponent.Instance.Get(ShopItemConfig.costItemId); Group_Price.SetActive(true); Text_Free.gameObject.SetActive(false); Icon_PriceItem.icon_name = costItemConfig.icon; Text_Price.text = ShopItemConfig.price.ToString(); } Text_Count.text = $"x{itemConfig.associateVlaue[0]}"; Text_Tip.text = LanguageManager.Instance.Text(10327, ShopItemConfig.buyCount - shopItem.buyCount); } public void CustomInit1(int itemId) { openType = 2; itemConfig = ConfigComponent.Instance.Get(itemId); Text_Count.text = $"x{itemConfig.associateVlaue[0]}"; Text_Tip.text = LanguageManager.Instance.Text(10327, PlayerManager.Instance.BagController.GetItemCount(itemId)); Group_Price.SetActive(false); Text_Free.gameObject.SetActive(true); Text_Free.text = LanguageManager.Instance.Text(10329); } } }