Files
M-Gameton-06/Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs
2025-06-08 23:07:23 +09:00

71 lines
2.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UniRx;
using UnityEngine;
namespace TON
{
public class ShopPresenter
{
private int hpPotionPrice1 = 200; // HP 포션 가격
private int hpPotionPrice5 = 1000; // HP 포션 가격
private int hpPotionPrice20 = 3600; // HP 포션 가격
private int mpPotionPrice1 = 400; // MP 포션 가격
private int mpPotionPrice5 = 2000; // MP 포션 가격
private int mpPotionPrice20 = 7600; // MP 포션 가격
private PlayerDataManager playerDataManager;
private List<ShopItemModel> shopItemModels = new();
public ReactiveCollection<ShopItemPresenter> ShopItems { get; } = new();
public ShopPresenter()
{
// 싱글톤으로 PlayerDataManager 접근
playerDataManager = PlayerDataManager.Singleton;
if (playerDataManager == null)
{
Debug.LogError("PlayerDataManager가 초기화되지 않았습니다.");
}
shopItemModels.Add(new ShopItemModel(hpPotionPrice1, "hp", 1));
shopItemModels.Add(new ShopItemModel(hpPotionPrice5, "hp", 5));
shopItemModels.Add(new ShopItemModel(hpPotionPrice20, "hp", 20));
shopItemModels.Add(new ShopItemModel(mpPotionPrice1, "mp", 1));
shopItemModels.Add(new ShopItemModel(mpPotionPrice5, "mp", 5));
shopItemModels.Add(new ShopItemModel(mpPotionPrice20, "mp", 20));
foreach (var item in shopItemModels)
{
ShopItems.Add(new ShopItemPresenter(this, item));
}
}
// 포션 구매 메서드
public void BuyPotion(ShopItemPresenter shopItem)
{
if (playerDataManager.goldAmount >= shopItem.Price.Value)
{
playerDataManager.UseGold(shopItem.Price.Value, (isSuccess) =>
{
if (isSuccess)
{
if (shopItem.PotionType.Value == "hp")
{
playerDataManager.AddPotion("HP", shopItem.Quantity.Value);
}
else if (shopItem.PotionType.Value == "mp")
{
playerDataManager.AddPotion("MP", shopItem.Quantity.Value);
}
UIManager.Singleton.UpdateCashData();
}
});
}
}
}
}