Scriptum/Assets/Scripts/REFACTORING/Story/WizardHouse/ResetPlayer.cs
2022-12-13 02:28:49 +01:00

63 lines
1.8 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();
var saveController = GameObject.FindObjectOfType<SaveController>();
saveController.SavePlayerEquipmentItems();
saveController.SavePlayerInventory();
saveController.SavePlayerQuests();
// 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();
}
}
}