Scriptum/Assets/Scripts/REFACTORING/Story/WizardHouse/ResetPlayer.cs
2023-01-05 21:23:01 +01:00

69 lines
2.0 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Script to reset player stuf like
/// - missions list
/// - items
/// - equipment
/// - health
/// - exp
/// </summary>
public class ResetPlayer : MonoBehaviour
{
public bool isAfterReset = false;
void Update()
{
if (!isAfterReset)
ResetPlayerData();
}
void ResetPlayerData()
{
if (
EquipmentDataManager.Instance == null ||
SceneInventoryDataManager.Instance == null ||
SceneTaskDataManager.Instance == null
) return;
if (PlayerPrefs.GetString("gateway.sourceMapName") == "SampleScene")
{
isAfterReset = true;
// Clear panels data
EquipmentDataManager.Instance.ClearListOfElements();
SceneInventoryDataManager.Instance.ClearListOfElements();
SceneTaskDataManager.Instance.ClearListOfElements();
// Clear Account balance
AccountBalanceManager.Instance.SetAccountBalanceValue(0);
var saveController = GameObject.FindObjectOfType<SaveController>();
saveController.SavePlayerEquipmentItems();
saveController.SavePlayerInventory();
saveController.SavePlayerQuests();
saveController.SaveAccountBalance();
// Player reset lvl, exp & health
var playerAgent = GameObject.FindGameObjectWithTag("Player");
playerAgent.GetComponent<Player>().currentHealth = PlayerPrefs.GetFloat("maxHealth");
PlayerPrefs.SetFloat("health-S", PlayerPrefs.GetFloat("maxHealth"));
PlayerPrefs.SetFloat("health", PlayerPrefs.GetFloat("maxHealth"));
/*
playerAgent.GetComponent<Player>().exp = 0;
PlayerPrefs.SetFloat("exp-S", 0);
playerAgent.GetComponent<Player>().lvl = 1;
PlayerPrefs.SetInt("lvl-S", 1);
*/
playerAgent.GetComponent<Player>().SaveCheckpoint();
}
}
}