Files
back_cantanBuilding/Assets/Scripts/Duel/UI/PvpStoreItem.cs
2026-05-26 16:15:54 +08:00

93 lines
3.0 KiB
C#

using asap.core;
using cfg;
using game;
using GameCore;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class PvpStoreItem : MonoBehaviour
{
[SerializeField]
protected Button btn_buy;
[SerializeField]
protected RewardItemNew rewardItem;
[SerializeField]
protected GameObject go_soldOut;
[SerializeField]
protected TMP_Text btn_buy_text;
protected PvpStore pvpStore;
protected ItemData itemData;
private void Reset()
{
btn_buy = transform.Find("position/btn_purchase/btn_green").GetComponent<Button>();
rewardItem = transform.Find("position/reward").GetComponent<RewardItemNew>();
go_soldOut = transform.Find("position/soldout").gameObject;
btn_buy_text = transform.Find("position/btn_purchase/btn_green/Ani_Container/p_text").GetComponent<TMP_Text>();
}
private void Start()
{
btn_buy.onClick.AddListener(OnBuy);
}
public void Init(PvpStore pvpStore, bool soldOut)
{
this.pvpStore = pvpStore;
itemData = new ItemData(pvpStore.ItemId, pvpStore.ItemNumber);
if (itemData.id == 1002)
{
itemData.count = GContext.container.Resolve<PlayerItemData>().GetExtraCoinMag(itemData.count);
}
rewardItem.SetData(itemData);
btn_buy_text.text = pvpStore.TokenNumber.ToString();
go_soldOut.SetActive(soldOut);
btn_buy.gameObject.SetActive(!soldOut);
Init();
}
protected virtual void Init()
{
}
void OnBuy()
{
FishingEventData fishingEventData = GContext.container.Resolve<FishingEventData>();
if (pvpStore.TokenNumber > fishingEventData.PVPToken)
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_87"));
//代币不足
return;
}
if (fishingEventData.BuyPVPItem(pvpStore.Id))
{
fishingEventData.AddPVPToken(-pvpStore.TokenNumber);
GContext.Publish(new ResAddEvent(pvpStore.TokenId));
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(itemData.id);
GContext.Publish(new ShowData(itemData));
GContext.container.Resolve<PlayerItemData>().AddItem(itemData);
GContext.Publish(new ShowData());
BuyEnd();
var duelData = fishingEventData.duelData;
#if AGG
using (var e = GEvent.GameEvent("pvp_store"))
{
e.AddContent("cost_token_id", 2052)
.AddContent("cost_token_count", pvpStore.TokenNumber)
.AddContent("change_type", pvpStore.Type)
.AddContent("item_id", itemData.id)
.AddContent("cost_token_count_sum", duelData == null ? 0 : duelData.rePVPToken)
.AddContent("available_token", fishingEventData.PVPToken)
.AddContent("change_count", itemData.count);
}
#endif
}
}
protected virtual void BuyEnd()
{
go_soldOut.SetActive(true);
btn_buy.gameObject.SetActive(false);
}
}