Files
3DBlobici-WorkingTitle/3D blobici/Assets/Scripts/Player/PlayerSkillTree.cs
2025-08-06 00:55:06 +02:00

117 lines
2.5 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using System.ComponentModel;
using UnityEditor.SceneManagement;
public class PlayerSkillTree
{
private static PlayerSkillTree _instance;
private Dictionary<PotionHandler.PotionType, PotionHandler> potionHandlers = new Dictionary<PotionHandler.PotionType, PotionHandler>();
private int health = 100;
private int maxHealth = 100;
public int MaxHealth { get => maxHealth; set => maxHealth = value; }
public static PlayerSkillTree Instance
{
get
{
if (_instance == null)
{
_instance = new PlayerSkillTree();
}
return _instance;
}
}
public enum Skills
{
Dash,
Reflection1,
Reflection2,
Shockwave,
Spin,
Potion,
Arrows1,
Arrows2
}
private List<Skills> playerSkills;
public PlayerSkillTree()
{
playerSkills = new List<Skills>();
}
public void RegisterPotionHandler(PotionHandler.PotionType type, PotionHandler handler)
{
if (!potionHandlers.ContainsKey(type))
{
potionHandlers.Add(type, handler);
}
else
{
potionHandlers[type] = handler;
}
}
public void UnlockSkill(Skills skill, PotionHandler.PotionType potionType)
{
if(skill == Skills.Potion){
if (potionHandlers.TryGetValue(potionType, out PotionHandler handler))
{
handler.AddPotion(potionType);
}
return;
}
if (playerSkills.Contains(skill)) return;
playerSkills.Add(skill);
}
public bool TryUsePotion(PotionHandler.PotionType potionType)
{
if (potionHandlers.TryGetValue(potionType, out PotionHandler handler))
{
if (handler.IsEmpty(potionType)) return false;
return handler.UsePotion(potionType);
}
return false;
}
public int GetHealth() { return health; }
public void SetHealth(int value)
{
if(value + health > maxHealth)
{
health = maxHealth;
return;
}
if(health + value < 0)
{
health = 0;
return;
}
health += value;
}
public bool IsSkillUnlocked(Skills skill)
{
return playerSkills.Contains(skill);
}
public List<Skills> GetPlayerSkills() { return playerSkills; }
}