fix: 캐릭터 최초 생성 시에 발생하는 exception 처리
This commit is contained in:
@@ -1,8 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"characterId": 0,
|
|
||||||
"currentHearts": 3,
|
|
||||||
"heartRechargeTime": 0,
|
|
||||||
"lastHeartTime": ""
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: e8666d47c97d4d347aa8687892718f69
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"id": 0,
|
|
||||||
"type": "w",
|
|
||||||
"name": "lulu",
|
|
||||||
"level": 3,
|
|
||||||
"experience": 0,
|
|
||||||
"hp": 1000,
|
|
||||||
"mp": 1000,
|
|
||||||
"attackPower": 50,
|
|
||||||
"defensivePower": 30,
|
|
||||||
"critical": 30
|
|
||||||
}
|
|
||||||
]
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: a4dee2e685350b1458b15992a0fdfc34
|
|
||||||
TextScriptImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
@@ -52,7 +52,7 @@ namespace TON
|
|||||||
public void SetCurrentUserHeart()
|
public void SetCurrentUserHeart()
|
||||||
{
|
{
|
||||||
characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
||||||
if (characterId > -1)
|
if (characterId > -1 && heartDatas.Count > 0)
|
||||||
{
|
{
|
||||||
currentHeartData = heartDatas[characterId];
|
currentHeartData = heartDatas[characterId];
|
||||||
if (currentHeartData != null)
|
if (currentHeartData != null)
|
||||||
@@ -85,9 +85,16 @@ namespace TON
|
|||||||
{
|
{
|
||||||
if (currentHeartData.currentHearts >= maxHearts) return;
|
if (currentHeartData.currentHearts >= maxHearts) return;
|
||||||
|
|
||||||
DateTime lastTime = DateTime.Parse(currentHeartData.lastHeartTime);
|
DateTime lastTime;
|
||||||
TimeSpan timePassed = DateTime.Now - lastTime;
|
bool hasValidTime = DateTime.TryParse(currentHeartData.lastHeartTime, out lastTime);
|
||||||
|
|
||||||
|
if (!hasValidTime)
|
||||||
|
{
|
||||||
|
lastTime = DateTime.Now; // 기본값 설정
|
||||||
|
currentHeartData.lastHeartTime = lastTime.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
TimeSpan timePassed = DateTime.Now - lastTime;
|
||||||
int heartsToRecover = (int)(timePassed.TotalSeconds / heartRechargeTime);
|
int heartsToRecover = (int)(timePassed.TotalSeconds / heartRechargeTime);
|
||||||
|
|
||||||
if (heartsToRecover > 0)
|
if (heartsToRecover > 0)
|
||||||
@@ -109,16 +116,23 @@ namespace TON
|
|||||||
if (currentHeartData.currentHearts > 0)
|
if (currentHeartData.currentHearts > 0)
|
||||||
{
|
{
|
||||||
currentHeartData.currentHearts--;
|
currentHeartData.currentHearts--;
|
||||||
|
// lastHeartTime이 비어있거나 잘못된 경우를 대비하여 기본값 설정
|
||||||
|
DateTime lastTime;
|
||||||
|
bool hasValidTime = DateTime.TryParse(currentHeartData.lastHeartTime, out lastTime);
|
||||||
|
|
||||||
|
if (!hasValidTime)
|
||||||
|
{
|
||||||
|
lastTime = DateTime.Now; // 기본값을 현재 시간으로 설정
|
||||||
|
currentHeartData.lastHeartTime = lastTime.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
// 재충전 중일 경우 lastHeartTime을 유지
|
|
||||||
DateTime lastTime = DateTime.Parse(currentHeartData.lastHeartTime);
|
|
||||||
TimeSpan timePassed = DateTime.Now - lastTime;
|
TimeSpan timePassed = DateTime.Now - lastTime;
|
||||||
|
|
||||||
|
// 재충전 시간이 지났거나, 처음 소모하여 재충전이 시작될 때만 lastHeartTime 갱신
|
||||||
if (timePassed.TotalSeconds >= heartRechargeTime || currentHeartData.currentHearts == maxHearts - 1)
|
if (timePassed.TotalSeconds >= heartRechargeTime || currentHeartData.currentHearts == maxHearts - 1)
|
||||||
{
|
{
|
||||||
currentHeartData.lastHeartTime = DateTime.Now.ToString();
|
currentHeartData.lastHeartTime = DateTime.Now.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveHeartData();
|
SaveHeartData();
|
||||||
FindObjectOfType<HeartSystem>().UpdateHeartUI(); // UI 업데이트
|
FindObjectOfType<HeartSystem>().UpdateHeartUI(); // UI 업데이트
|
||||||
}
|
}
|
||||||
@@ -129,7 +143,15 @@ namespace TON
|
|||||||
{
|
{
|
||||||
if (currentHeartData.currentHearts >= maxHearts) return 0;
|
if (currentHeartData.currentHearts >= maxHearts) return 0;
|
||||||
|
|
||||||
DateTime lastTime = DateTime.Parse(currentHeartData.lastHeartTime);
|
DateTime lastTime;
|
||||||
|
bool hasValidTime = DateTime.TryParse(currentHeartData.lastHeartTime, out lastTime);
|
||||||
|
|
||||||
|
if (!hasValidTime)
|
||||||
|
{
|
||||||
|
lastTime = DateTime.Now; // 기본값 설정
|
||||||
|
currentHeartData.lastHeartTime = lastTime.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
TimeSpan timePassed = DateTime.Now - lastTime;
|
TimeSpan timePassed = DateTime.Now - lastTime;
|
||||||
int timeLeft = heartRechargeTime - (int)timePassed.TotalSeconds;
|
int timeLeft = heartRechargeTime - (int)timePassed.TotalSeconds;
|
||||||
|
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ namespace TON
|
|||||||
public void Initalize()
|
public void Initalize()
|
||||||
{
|
{
|
||||||
LoadPlayerData();
|
LoadPlayerData();
|
||||||
// 현재 플레이어 1개만 사용하므로 0번째 인덱스의 플레이어 데이터를 사용
|
// PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
||||||
PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void LoadPlayerData()
|
private void LoadPlayerData()
|
||||||
@@ -88,12 +87,13 @@ namespace TON
|
|||||||
|
|
||||||
public void SetCurrentUserData()
|
public void SetCurrentUserData()
|
||||||
{
|
{
|
||||||
int characterId = PlayerPrefs.GetInt("SelectedPlayerIndex", -1);
|
if (playersData.Count > 0)
|
||||||
if (characterId > -1)
|
|
||||||
{
|
{
|
||||||
player = playersData[characterId];
|
// 현재 플레이어 1개만 사용하므로 0번째 인덱스의 플레이어 데이터를 사용
|
||||||
|
PlayerPrefs.SetInt("SelectedPlayerIndex", 0);
|
||||||
|
player = playersData[0];
|
||||||
// FIXME: 테스트를 위해 캐릭터 레벨 강제 적용함
|
// FIXME: 테스트를 위해 캐릭터 레벨 강제 적용함
|
||||||
player.level = 15;
|
// player.level = 15;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -121,7 +121,8 @@ namespace TON
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.LogError($"❌ Resources에서 JSON 파일을 찾을 s수 없음: {path}");
|
Debug.LogError($"❌ Resources에서 JSON 파일을 찾을 수 없음: {path}");
|
||||||
|
File.WriteAllText(persistentPath, "[]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,6 @@ namespace TON
|
|||||||
|
|
||||||
// TODO : GameDataModel.Singleton.Initalize();
|
// TODO : GameDataModel.Singleton.Initalize();
|
||||||
PlayerDataManager.Singleton.Initalize();
|
PlayerDataManager.Singleton.Initalize();
|
||||||
PlayerDataManager.Singleton.SetCurrentUserData();
|
|
||||||
|
|
||||||
StageManager.Singleton.Initialize();
|
|
||||||
SkillDataManager.Singleton.Initalize();
|
|
||||||
|
|
||||||
isIniaialized = true;
|
isIniaialized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ namespace TON
|
|||||||
public HeartData(int characterId)
|
public HeartData(int characterId)
|
||||||
{
|
{
|
||||||
this.characterId = characterId;
|
this.characterId = characterId;
|
||||||
// currentHearts = maxHearts;
|
currentHearts = 3;
|
||||||
|
lastHeartTime = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,12 @@ namespace TON
|
|||||||
yield return null;
|
yield return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerDataManager.Singleton.SetCurrentUserData();
|
||||||
|
|
||||||
|
StageManager.Singleton.Initialize();
|
||||||
|
SkillDataManager.Singleton.Initalize();
|
||||||
|
|
||||||
|
|
||||||
UIManager.Show<LobbyUI>(UIList.LobbyUI);
|
UIManager.Show<LobbyUI>(UIList.LobbyUI);
|
||||||
UIManager.Show<OptionUI>(UIList.OptionUI);
|
UIManager.Show<OptionUI>(UIList.OptionUI);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user