Files
ft/Client/Assets/Scripts/Duel/UI/PvpStoreItem.cs
2026-06-29 21:18:33 +08:00

102 lines
3.6 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;
int TokenNumber;
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;
TokenNumber = pvpStore.TokenNumber;
itemData = new ItemData(pvpStore.ItemId, pvpStore.ItemNumber);
if (itemData.id == 1002)
{
itemData.count = GContext.container.Resolve<PlayerItemData>().GetExtraCoinMag(itemData.count);
}
else if (itemData.id == 1001)
{
GContext.container.Resolve<PlayerItemData>().ItemInflation(itemData, null);
float inflation = GContext.container.Resolve<FishingEventData>().duelData.inflation;
TokenNumber = GContext.container.Resolve<PlayerItemData>().IntInflation(TokenNumber, inflation);
}
rewardItem.SetData(itemData);
btn_buy_text.text = 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 (TokenNumber > fishingEventData.PVPToken)
{
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_87"));
//代币不足
return;
}
if (fishingEventData.BuyPVPItem(pvpStore.Id))
{
fishingEventData.AddPVPToken(-TokenNumber);
GContext.Publish(new ResAddEvent(pvpStore.TokenId));
itemData.curCount = (ulong)GContext.container.Resolve<PlayerItemData>().GetItemCount(itemData.id);
GContext.Publish(new ShowData(itemData));
ChangeSource changeSource = new ChangeSource(GContext.container.Resolve<FishingDuelManager>().duelData.eventID, "Event_Duel", "Event_Duel", "StoreReward");
GContext.container.Resolve<PlayerItemData>().AddItem(itemData, changeSource);
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", 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);
}
}