-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbilityManager.cs
More file actions
77 lines (67 loc) · 2.28 KB
/
AbilityManager.cs
File metadata and controls
77 lines (67 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AbilityManager : MonoBehaviour
{
private CharacterSkills characterSkills;
[SerializeField]
private EquipmentSO equipment;
[SerializeField]
private Ability basicAttack;
[SerializeField]
private Ability onePunch;
[SerializeField]
private bool cheatAbility = false;
private void Start()
{
characterSkills = GlobalControl.instance.characterSkills;
RefreshAbilities();
}
public void RefreshAbilities()
{
ClearAbilities();
Weapon weapon;
if (weapon = equipment.currentEquipment[(int)EquipmentSlot.Weapon] as Weapon)
UnlockWeaponAbilities(weapon);
if (weapon = equipment.currentEquipment[(int)EquipmentSlot.Shield] as Weapon)
UnlockWeaponAbilities(weapon);
if (cheatAbility)
GlobalControl.instance.abilities.Add(onePunch);
}
private void UnlockWeaponAbilities(Weapon weapon)
{
if (!weapon) return;
var weaponSkill = FindWeaponSkill(weapon);
if (weaponSkill is null) return;
var playerAbilities = GlobalControl.instance.abilities;
foreach (var ability in weapon.DefaultAbilities)
{
if (weaponSkill.Level >= ability.RequiredLevel && !playerAbilities.Contains(ability))
playerAbilities.Add(ability);
}
foreach (var ability in weapon.uniqueAbilities)
{
if (weaponSkill.Level >= ability.RequiredLevel && !playerAbilities.Contains(ability))
playerAbilities.Add(ability);
}
}
private Skill FindWeaponSkill(Weapon weapon)
{
if (weapon is Sword)
return characterSkills.swordSkill;
else if (weapon is Staff)
return characterSkills.staffSkill;
else if (weapon is Shield)
return characterSkills.shieldSkill;
else if (weapon is Dagger)
return characterSkills.daggerSkill;
else
return null;
}
private void ClearAbilities()
{
var abilities = GlobalControl.instance.abilities;
abilities.Clear();
abilities.Add(basicAttack);
}
}