Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System;
- public class PlayerSkills
- {
- public event EventHandler OnSkillPointsChanged;
- public event EventHandler<OnSkillUnlockedEventArgs> OnSkillUnlocked;
- public class OnSkillUnlockedEventArgs : EventArgs
- {
- public SkillType skillType;
- }
- public enum SkillType
- {
- None,
- Punch,
- PunchC,
- PunchNC,
- Fireball,
- FireballC,
- FireballNc,
- Stun,
- StunC,
- StunNC,
- Def,
- DefC,
- DefNC,
- Pleh,
- PlehUp,
- }
- public List<SkillType> unlockedSkillTypeList;
- public int skillPoints;
- public PlayerSkills()
- {
- unlockedSkillTypeList = new List<SkillType>();
- }
- public void AddSkillPoints()
- {
- skillPoints++;
- OnSkillPointsChanged?.Invoke(this, EventArgs.Empty);
- }
- public int GetSkillPoints()
- {
- return skillPoints;
- }
- public void UnlockSkill(SkillType skillType)
- {
- if (!IsSkillUnlocked(skillType))
- {
- unlockedSkillTypeList.Add(skillType);
- OnSkillUnlocked?.Invoke(this, new OnSkillUnlockedEventArgs { skillType = skillType });
- }
- }
- public bool IsSkillUnlocked(SkillType skillType)
- {
- return unlockedSkillTypeList.Contains(skillType);
- }
- public SkillType GetSkillRequeriment (SkillType skillType)
- {
- switch (skillType) {
- case SkillType.PunchC: return SkillType.Punch;
- case SkillType.PunchNC: return SkillType.Punch;
- case SkillType.FireballC: return SkillType.Fireball;
- case SkillType.FireballNc: return SkillType.Fireball;
- case SkillType.StunC: return SkillType.Stun;
- case SkillType.StunNC: return SkillType.Stun;
- case SkillType.DefC: return SkillType.Def;
- case SkillType.DefNC: return SkillType.Def;
- case SkillType.PlehUp: return SkillType.Pleh;
- }
- return SkillType.None;
- }
- public bool CanUnlock(SkillType skillType)
- {
- SkillType skillRequiremente = GetSkillRequeriment(skillType);
- if (skillRequiremente != SkillType.None)
- {
- if (IsSkillUnlocked(skillRequiremente))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return true;
- }
- }
- public bool TryUnlockSkill(SkillType skillType)
- {
- if (CanUnlock(skillType))
- {
- if (skillPoints > 0)
- {
- skillPoints--;
- OnSkillPointsChanged?.Invoke(this, EventArgs.Empty);
- UnlockSkill(skillType);
- return true;
- }
- else
- {
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement