Advertisement
04vini

Untitled

Jul 8th, 2020
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.22 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using System;
  5.  
  6.  
  7.  
  8. public class PlayerSkills
  9. {
  10.     public event EventHandler OnSkillPointsChanged;
  11.     public event EventHandler<OnSkillUnlockedEventArgs> OnSkillUnlocked;
  12.     public class OnSkillUnlockedEventArgs : EventArgs
  13.     {
  14.         public SkillType skillType;
  15.     }
  16.  
  17.     public enum SkillType
  18.     {
  19.         None,
  20.         Punch,
  21.         PunchC,
  22.         PunchNC,
  23.         Fireball,
  24.         FireballC,
  25.         FireballNc,
  26.         Stun,
  27.         StunC,
  28.         StunNC,
  29.         Def,
  30.         DefC,
  31.         DefNC,
  32.         Pleh,
  33.         PlehUp,
  34.     }
  35.  
  36.    
  37.     public List<SkillType> unlockedSkillTypeList;
  38.     public int skillPoints;
  39.    
  40.        
  41.    
  42.     public PlayerSkills()
  43.     {      
  44.  
  45.         unlockedSkillTypeList = new List<SkillType>();
  46.        
  47.     }
  48.  
  49.     public void AddSkillPoints()
  50.     {
  51.         skillPoints++;
  52.         OnSkillPointsChanged?.Invoke(this, EventArgs.Empty);
  53.     }
  54.  
  55.     public int GetSkillPoints()
  56.     {
  57.         return skillPoints;
  58.     }
  59.     public void UnlockSkill(SkillType skillType)
  60.     {
  61.         if (!IsSkillUnlocked(skillType))
  62.         {
  63.             unlockedSkillTypeList.Add(skillType);
  64.             OnSkillUnlocked?.Invoke(this, new OnSkillUnlockedEventArgs { skillType = skillType });          
  65.         }
  66.      
  67.     }
  68.  
  69.  
  70.     public bool IsSkillUnlocked(SkillType skillType)
  71.     {
  72.         return unlockedSkillTypeList.Contains(skillType);      
  73.     }
  74.     public SkillType GetSkillRequeriment (SkillType skillType)
  75.     {
  76.         switch (skillType) {
  77.             case SkillType.PunchC: return SkillType.Punch;
  78.             case SkillType.PunchNC: return SkillType.Punch;              
  79.             case SkillType.FireballC: return SkillType.Fireball;    
  80.             case SkillType.FireballNc: return SkillType.Fireball;
  81.             case SkillType.StunC: return SkillType.Stun;
  82.             case SkillType.StunNC: return SkillType.Stun;
  83.             case SkillType.DefC: return SkillType.Def;
  84.             case SkillType.DefNC: return SkillType.Def;
  85.             case SkillType.PlehUp: return SkillType.Pleh;
  86.            
  87.         }
  88.         return SkillType.None;
  89.        
  90.     }
  91.     public bool CanUnlock(SkillType skillType)
  92.     {
  93.         SkillType skillRequiremente = GetSkillRequeriment(skillType);
  94.  
  95.         if (skillRequiremente != SkillType.None)
  96.         {
  97.             if (IsSkillUnlocked(skillRequiremente))
  98.             {          
  99.                 return true;
  100.             }
  101.             else
  102.             {
  103.                 return false;
  104.             }
  105.         }
  106.         else
  107.         {
  108.             return true;
  109.         }
  110.     }
  111.  
  112.    
  113.     public bool TryUnlockSkill(SkillType skillType)
  114.     {
  115.         if (CanUnlock(skillType))
  116.         {
  117.             if (skillPoints > 0)
  118.             {
  119.                 skillPoints--;
  120.                 OnSkillPointsChanged?.Invoke(this, EventArgs.Empty);
  121.                 UnlockSkill(skillType);
  122.                 return true;
  123.             }
  124.             else
  125.             {
  126.                 return false;
  127.             }
  128.            
  129.            
  130.         }
  131.         else
  132.         {
  133.             return false;
  134.         }
  135.        
  136.     }
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement