feat: 플레이 중 포션 사용 로직 적용
This commit is contained in:
@@ -89,5 +89,27 @@ namespace TON
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateHpData(int count)
|
||||
{
|
||||
Param param = new Param();
|
||||
param.Add("hp_potion", count);
|
||||
|
||||
Backend.PlayerData.UpdateMyLatestData(USER_ITEM_TABLE, param, callback =>
|
||||
{
|
||||
UserItemData updatedData = new UserItemData { hpPotion = count };
|
||||
});
|
||||
}
|
||||
|
||||
public void UpdateMpData(int count)
|
||||
{
|
||||
Param param = new Param();
|
||||
param.Add("mp_potion", count);
|
||||
|
||||
Backend.PlayerData.UpdateMyLatestData(USER_ITEM_TABLE, param, callback =>
|
||||
{
|
||||
UserItemData updatedData = new UserItemData { mpPotion = count };
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,6 +206,27 @@ namespace TON
|
||||
isRecovering = false;
|
||||
}
|
||||
|
||||
public void UsePotion(string type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "HP":
|
||||
if (currentHP < maxHP) // currentHP가 maxHP보다 작을 때만 실행
|
||||
{
|
||||
currentHP = Mathf.Min(currentHP + (maxHP * 0.2f), maxHP); // maxHP를 초과하지 않도록 보정
|
||||
OnHPChanged?.Invoke(currentHP, maxHP);
|
||||
}
|
||||
break;
|
||||
case "MP":
|
||||
if (currentSP < maxSP) // currentSP가 maxSP보다 작을 때만 실행
|
||||
{
|
||||
currentSP = Mathf.Min(currentSP + (maxSP * 0.2f), maxSP); // maxSP를를 초과하지 않도록 보정
|
||||
OnSPChanged?.Invoke(currentSP, maxSP);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void SkillAttack(string skillId)
|
||||
{
|
||||
SkillBase skillBase = SkillDataManager.Singleton.GetSkillInstance(skillId);
|
||||
|
||||
@@ -68,6 +68,21 @@ namespace TON
|
||||
});
|
||||
}
|
||||
|
||||
public void UsePotion(string type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "HP":
|
||||
userItem.hpPotion -= 1;
|
||||
itemDataManager.UpdateHpData(userItem.hpPotion);
|
||||
break;
|
||||
case "MP":
|
||||
userItem.mpPotion -= 1;
|
||||
itemDataManager.UpdateMpData(userItem.mpPotion);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddGold(int amount)
|
||||
{
|
||||
goldAmount += amount;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -20,12 +21,24 @@ namespace TON
|
||||
public ControllerUI_SkillButton skillButtonPrefab;
|
||||
private List<ControllerUI_SkillButton> createdSkillButtons = new List<ControllerUI_SkillButton>();
|
||||
|
||||
public UserItemData userItem { get; private set; } = new UserItemData();
|
||||
// 보유 포션 수량
|
||||
[SerializeField] private TextMeshProUGUI hpPotionCount;
|
||||
[SerializeField] private TextMeshProUGUI mpPotionCount;
|
||||
|
||||
public List<ControllerUI_ItemButton> itemButtons = new List<ControllerUI_ItemButton>();
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
skillButtonPrefab.gameObject.SetActive(false);
|
||||
Initalize();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
InitalizeItemData();
|
||||
}
|
||||
|
||||
public void Initalize()
|
||||
{
|
||||
// 이미 기존에 UI가 생성되어 있다면 삭제
|
||||
@@ -59,6 +72,36 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
private void InitalizeItemData()
|
||||
{
|
||||
userItem = PlayerDataManager.Singleton.userItem;
|
||||
|
||||
hpPotionCount.text = $"{userItem.hpPotion}";
|
||||
mpPotionCount.text = $"{userItem.mpPotion}";
|
||||
}
|
||||
|
||||
public void OnClickHpPotionButton()
|
||||
{
|
||||
if (userItem.hpPotion <= 0)
|
||||
return;
|
||||
|
||||
PlayerDataManager.Singleton.UsePotion("HP");
|
||||
|
||||
itemButtons[0].SetCurrentCoolDown();
|
||||
linkedCharactor.UsePotion("HP");
|
||||
}
|
||||
|
||||
public void OnClickMpPotionButton()
|
||||
{
|
||||
if (userItem.mpPotion <= 0)
|
||||
return;
|
||||
|
||||
PlayerDataManager.Singleton.UsePotion("MP");
|
||||
|
||||
itemButtons[1].SetCurrentCoolDown();
|
||||
linkedCharactor.UsePotion("MP");
|
||||
}
|
||||
|
||||
public void OnClickJumpButton()
|
||||
{
|
||||
linkedCharactor.Jump();
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class ControllerUI_ItemButton : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI coolTimeText;
|
||||
[SerializeField] private Image coolTimeDimd;
|
||||
|
||||
private float currentCoolDown = 0f;
|
||||
private float potionCoolDown = 5f;
|
||||
|
||||
public void SetCurrentCoolDown()
|
||||
{
|
||||
currentCoolDown = potionCoolDown; // 쿨타임 시작
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (currentCoolDown == 0f)
|
||||
return;
|
||||
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
private void UpdateCooldownUI()
|
||||
{
|
||||
if (coolTimeText == null || coolTimeDimd == null)
|
||||
{
|
||||
return; // UI가 삭제되었으면 업데이트 중단
|
||||
}
|
||||
|
||||
currentCoolDown -= Time.deltaTime;
|
||||
currentCoolDown = Mathf.Max(0, currentCoolDown);
|
||||
|
||||
coolTimeText.gameObject.SetActive(currentCoolDown > 0); // 남은 쿨타임이 있을 때만 표시
|
||||
|
||||
if (coolTimeText.IsActive())
|
||||
{
|
||||
coolTimeText.text = $"{currentCoolDown: 0}s"; // 정수 초단위 표시
|
||||
coolTimeDimd.fillAmount = currentCoolDown / potionCoolDown; // 1 → 0 으로 감소
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e890b5f706c997b4396fb3fc11938954
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user