Files
beyond/Assets/Scripts/Skills/SkillsManager.cs
2024-11-20 15:21:28 +01:00

166 lines
5.6 KiB
C#

using RootMotion;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
namespace Beyond
{
public class SkillsManager : Singleton<SkillsManager>
{
[SerializeField] private List<CompleteSkillInfo> completeSkillInfos; //skills info +current level info, combines scriptable object part and saveable part for easy use in game
[SerializeField] private SkillsDataContainer skillDataContainer; //scriptable object, storing info about skill image, name, description etc.
//checkers, if skill unlocked
private float bPGainOnLvlUp = 5f;
[Button]
internal void SetSkillsData(List<SkillCurrentData> skillsCurrentData = null)
{
completeSkillInfos.Clear();
foreach (var skill in skillDataContainer.skills)
{
CompleteSkillInfo completeSkillInfo;
if (skillsCurrentData != null)
{
SkillCurrentData skillCurrentData = skillsCurrentData.Find(skill2 => skill2.skillType == skill.skillType);
completeSkillInfo = new CompleteSkillInfo(skill, skillCurrentData == null ? 0 : skillCurrentData.currentLevel);
}
else
{
completeSkillInfo = new CompleteSkillInfo(skill, 0);
}
completeSkillInfos.Add(completeSkillInfo);
}
}
public int GetSkillLevelOf(Skills queredSkill)
{
CompleteSkillInfo skillInfo = completeSkillInfos.Find(skill => skill.skillInfo.skillType == queredSkill);
return skillInfo.currentLevel;
//if 0 then its simply not unlocked,
}
public string GetStringNameOf(Skills queredSkill)
{
SkillInfo skillInfo = skillDataContainer.skills.Find(skill => skill.skillType == queredSkill);
return skillInfo.descriptioryName;
}
public List<SkillCurrentData> GetSkillCurrentData()
{
List<SkillCurrentData> skillsCurrentData = new List<SkillCurrentData>();
completeSkillInfos.ForEach(skill =>
{
SkillCurrentData skillCurrentData = new SkillCurrentData(skill.skillInfo.skillType, skill.currentLevel);
skillsCurrentData.Add(skillCurrentData);
});
return skillsCurrentData;
}
public List<CompleteSkillInfo> GetAllUnlockedSkills()
{
List<CompleteSkillInfo> unlockedSkills = completeSkillInfos.FindAll(skill => skill.currentLevel > 0);
return unlockedSkills;
}
[Button]
public void LevelUpSkill(Skills queredSkill)
{
CompleteSkillInfo skillToLevel = completeSkillInfos.Find(skill => skill.skillInfo.skillType == queredSkill);
skillToLevel.currentLevel++;
if (skillToLevel.currentLevel > skillToLevel.skillInfo.maxLevel)
{
skillToLevel.currentLevel--;
}
else
{
Player.Instance.SetBrightness(Player.Instance.GetBrightness() + bPGainOnLvlUp);
}
}
public void LevelUpSkill(string queredSkill)
{
Skills skill;
if (!Enum.TryParse<Skills>(queredSkill, out skill))
{
return;
}
LevelUpSkill(skill);
}
[Button]
public void SetSkillLevel(Skills queredSkill, int levelToSet)
{
CompleteSkillInfo skillToLevel = completeSkillInfos.Find(skill => skill.skillInfo.skillType == queredSkill);
skillToLevel.currentLevel = levelToSet;
if (skillToLevel.currentLevel > skillToLevel.skillInfo.maxLevel)
{
skillToLevel.currentLevel = skillToLevel.skillInfo.maxLevel;
}
if (skillToLevel.currentLevel < 0)
{
skillToLevel.currentLevel = 0;
}
}
}
public enum Skills
{ SilentSense, BreathOfLife, WaveWalker, FlameWalker, WalkingOnAir, UnderstandingBlueprints, CreativeLight, TransformingLight, SongOfWhispers, CycleOfLife, RecognizingShadows, DeepHealing, CombatUpgrades, CraftingAndHunting, UnderstaingPortals, MasterOfScrolls }
[System.Serializable]
public class SkillInfo
{
public Skills skillType;
public string descriptioryName;
public string imagePath, quantaImagePath, quantaBackgroundImagePath;
// public Sprite image;
// public Sprite quantaImage;
// public Sprite quantaBackgroundImage;
[TextArea]
public string description;
public int maxLevel;
}
[System.Serializable]
public class SkillCurrentData
{
public Skills skillType;
public int currentLevel;
public SkillCurrentData(Skills skillType, int currentLevel)
{
this.skillType = skillType;
this.currentLevel = currentLevel;
}
}
[System.Serializable]
public class SkillsCurrentDataContainer
{
public List<SkillCurrentData> skillsCurrentData = new List<SkillCurrentData>();
}
[Serializable]
public class CompleteSkillInfo
{
[ReadOnly]
public SkillInfo skillInfo;
[ReadOnly]
public int currentLevel;
public CompleteSkillInfo(SkillInfo skillInfo, int currentLevel)
{
this.skillInfo = skillInfo;
this.currentLevel = currentLevel;
}
}
}