상점 포션 구매 UniRx(MVP 패턴)를 활용하여 수정중
This commit is contained in:
70
Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs
Normal file
70
Gameton-06/Assets/Gameton/Scripts/UI/ShopPresenter.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
// 포션 구매 메서드
|
||||
private void BuyPotion(int price, string potionType, int quantity)
|
||||
{
|
||||
if (playerDataManager.goldAmount >= price)
|
||||
{
|
||||
playerDataManager.UseGold(price, (isSuccess) =>
|
||||
{
|
||||
if (isSuccess)
|
||||
{
|
||||
if (potionType == "hp")
|
||||
{
|
||||
playerDataManager.AddPotion("HP", quantity);
|
||||
}
|
||||
else if (potionType == "mp")
|
||||
{
|
||||
playerDataManager.AddPotion("MP", quantity);
|
||||
}
|
||||
|
||||
UIManager.Singleton.UpdateCashData();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user