feat: 로비 화면의 사용자 포션 아이템 갯수 매핑 로직 추가
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BackEnd;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
/// <summary>
|
||||
/// 뒤끝 서버 사용자 소모 아이템 데이터 관리 담당 클래스
|
||||
/// </summary>
|
||||
public class BackendItemDataManager
|
||||
{
|
||||
// 테이블 이름 상수
|
||||
private const string USER_ITEM_TABLE = "USER_ITEM_DATA";
|
||||
|
||||
public void LoadMyItemData(System.Action<UserItemData> onComplete)
|
||||
{
|
||||
UserItemData userItemData = new UserItemData();
|
||||
|
||||
Backend.PlayerData.GetMyData(USER_ITEM_TABLE, callback =>
|
||||
{
|
||||
if (callback.IsSuccess() == false)
|
||||
{
|
||||
Debug.Log("데이터 읽기 중에 문제가 발생했습니다 : " + callback.ToString());
|
||||
onComplete?.Invoke(userItemData); // 에러 상황에서 기본 객체 반환
|
||||
return;
|
||||
}
|
||||
|
||||
// 불러오기에는 성공했으나 데이터가 존재하지 않는 경우
|
||||
if (callback.IsSuccess() && callback.FlattenRows().Count <= 0)
|
||||
{
|
||||
Debug.Log("데이터가 존재하지 않습니다");
|
||||
InsertInitData(() =>
|
||||
{
|
||||
// 초기 데이터 삽입 후 다시 데이터를 불러옴
|
||||
LoadDataAfterInsert(onComplete);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 1개 이상 데이터를 불러온 경우
|
||||
if (callback.FlattenRows().Count > 0)
|
||||
{
|
||||
userItemData.hpPotion = int.Parse(callback.FlattenRows()[0]["hp_potion"].ToString());
|
||||
userItemData.mpPotion = int.Parse(callback.FlattenRows()[0]["mp_potion"].ToString());
|
||||
onComplete?.Invoke(userItemData); // 성공 시 데이터 반환
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 데이터 삽입 후 다시 불러오는 메소드
|
||||
private void LoadDataAfterInsert(System.Action<UserItemData> onComplete)
|
||||
{
|
||||
Backend.PlayerData.GetMyData(USER_ITEM_TABLE, callback =>
|
||||
{
|
||||
UserItemData userItemData = new UserItemData();
|
||||
|
||||
if (callback.IsSuccess() && callback.FlattenRows().Count > 0)
|
||||
{
|
||||
userItemData.hpPotion = int.Parse(callback.FlattenRows()[0]["hp_potion"].ToString());
|
||||
userItemData.mpPotion = int.Parse(callback.FlattenRows()[0]["mp_potion"].ToString());
|
||||
}
|
||||
|
||||
onComplete?.Invoke(userItemData);
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 캐릭터 초기 생성 시 row 삽입
|
||||
/// </summary>
|
||||
public void InsertInitData(System.Action onComplete = null)
|
||||
{
|
||||
Param param = new Param();
|
||||
param.Add("hp_potion", 5);
|
||||
param.Add("mp_potion", 5);
|
||||
|
||||
Backend.PlayerData.InsertData(USER_ITEM_TABLE, param, callback =>
|
||||
{
|
||||
if (callback.IsSuccess())
|
||||
{
|
||||
Debug.Log("초기 데이터 삽입 성공");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("초기 데이터 삽입 실패: " + callback.ToString());
|
||||
}
|
||||
|
||||
onComplete?.Invoke();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1502b07ba467a2408412ceb984db71c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -12,6 +12,7 @@ namespace TON
|
||||
public PlayerData player { get; private set; }
|
||||
public int goldAmount { get; private set; }
|
||||
public int fishAmount { get; private set; }
|
||||
public UserItemData userItem { get; private set; } = new UserItemData();
|
||||
|
||||
public int defensiveIntention { get; private set; } = 200; // 방어력 변수 (조정 가능)
|
||||
|
||||
@@ -19,13 +20,16 @@ namespace TON
|
||||
[SerializeField] private int attackGrowthFactor = 50; // 공격력 성장 변수 (조정 가능)
|
||||
|
||||
private BackendCashDataManager cashDataManager;
|
||||
private BackendItemDataManager itemDataManager;
|
||||
|
||||
public void Initalize()
|
||||
{
|
||||
cashDataManager = new BackendCashDataManager();
|
||||
itemDataManager = new BackendItemDataManager();
|
||||
|
||||
LoadPlayerData();
|
||||
LoadPlayerCashData();
|
||||
LoadPlayerItemData();
|
||||
}
|
||||
|
||||
private void LoadPlayerData()
|
||||
@@ -54,6 +58,16 @@ namespace TON
|
||||
});
|
||||
}
|
||||
|
||||
private void LoadPlayerItemData()
|
||||
{
|
||||
itemDataManager.LoadMyItemData(userItemData =>
|
||||
{
|
||||
userItem.hpPotion = userItemData.hpPotion;
|
||||
userItem.mpPotion = userItemData.mpPotion;
|
||||
Debug.Log($"로드된 hp포션: {userItemData.hpPotion}, mp포션: {userItemData.mpPotion}");
|
||||
});
|
||||
}
|
||||
|
||||
public void AddGold(int amount)
|
||||
{
|
||||
goldAmount += amount;
|
||||
@@ -104,18 +118,6 @@ namespace TON
|
||||
});
|
||||
}
|
||||
|
||||
// 플레이어가 사망했을때 호출
|
||||
public void PlayerDeadEvent()
|
||||
{
|
||||
Invoke(nameof(ShowGameEndUI), 0.5f);
|
||||
|
||||
}
|
||||
private void ShowGameEndUI()
|
||||
{
|
||||
UIManager.Show<GameWinUI>(UIList.GameWinUI);
|
||||
}
|
||||
|
||||
|
||||
// 공격력과 방어력 업데이트
|
||||
private void UpdateStats(int currentLevel)
|
||||
{
|
||||
@@ -176,5 +178,16 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
// 플레이어가 사망했을때 호출
|
||||
public void PlayerDeadEvent()
|
||||
{
|
||||
Invoke(nameof(ShowGameEndUI), 0.5f);
|
||||
|
||||
}
|
||||
private void ShowGameEndUI()
|
||||
{
|
||||
UIManager.Show<GameWinUI>(UIList.GameWinUI);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
19
Gameton-06/Assets/Gameton/Scripts/GameData/UserItemData.cs
Normal file
19
Gameton-06/Assets/Gameton/Scripts/GameData/UserItemData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
[System.Serializable]
|
||||
public class UserItemData
|
||||
{
|
||||
public int hpPotion;
|
||||
public int mpPotion;
|
||||
|
||||
public UserItemData()
|
||||
{
|
||||
hpPotion = 0;
|
||||
mpPotion = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb32053a6a7bb30498bb2155fcbffd1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
@@ -23,14 +24,20 @@ namespace TON
|
||||
[SerializeField] private TextMeshProUGUI playTime;
|
||||
[SerializeField] private TextMeshProUGUI score;
|
||||
|
||||
// 보유 포션 수량
|
||||
[SerializeField] private TextMeshProUGUI hpPotionCount;
|
||||
[SerializeField] private TextMeshProUGUI mpPotionCount;
|
||||
|
||||
public GameObject emptyHeartAlert;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
SetCharacterData();
|
||||
SetUserItemData();
|
||||
SetUserRankData();
|
||||
}
|
||||
|
||||
// 사용자 최고 기록 데이터 세팅
|
||||
private void SetUserRankData()
|
||||
{
|
||||
ClearData TOP_RECORD = StageManager.Singleton.TOP_RECORD;
|
||||
@@ -57,6 +64,7 @@ namespace TON
|
||||
}
|
||||
}
|
||||
|
||||
// 캐릭터 기본 스탯 표시
|
||||
private void SetCharacterData()
|
||||
{
|
||||
PlayerData player = PlayerDataManager.Singleton.player;
|
||||
@@ -73,6 +81,15 @@ namespace TON
|
||||
characterCritical.text = $"{player.critical}";
|
||||
}
|
||||
|
||||
// 사용자 보유 포션 수량 세팅
|
||||
private void SetUserItemData()
|
||||
{
|
||||
UserItemData userItem = PlayerDataManager.Singleton.userItem;
|
||||
|
||||
hpPotionCount.text = $"{userItem.hpPotion}";
|
||||
mpPotionCount.text = $"{userItem.mpPotion}";
|
||||
}
|
||||
|
||||
public void OnClickStagePlayButton()
|
||||
{
|
||||
PlayerPrefs.SetString("StageId", "STG004");
|
||||
|
||||
Reference in New Issue
Block a user