-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathActionBar.cs
127 lines (115 loc) · 3.89 KB
/
ActionBar.cs
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ActionBar : MonoBehaviour {
[HideInInspector] public Skill[] slots;
public IEnumerator castingSkill;
[HideInInspector] public Dictionary<int, int[]> activeSkills;
public Skill skillPrueba;
public GameObject player;
public GameObject actionEmitter;
// Use this for initialization
void Start () {
slots = new Skill[5];
activeSkills = new Dictionary<int, int[]>(); // KEY = skillHashCode, Value[0] = index, Value[1] = CD
castingSkill = null;
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown("1"))
{
if ((slots[0] != null) && (castingSkill == null) && (!activeSkills.ContainsKey(slots[0].GetHashCode())))
{
castingSkill = slots[0].Initiate(this.actionEmitter, this.gameObject);
if(castingSkill != null)
StartCoroutine(castingSkill);
}
else
{
Debug.Log("COOLDOWN ESPERAAAA");
}
}
else if (Input.GetButtonDown("2"))
{
if ((slots[1] != null) && (castingSkill == null) && (!activeSkills.ContainsKey(slots[1].GetHashCode())))
{
castingSkill = slots[1].Initiate(this.actionEmitter, this.gameObject);
StartCoroutine(castingSkill);
}
}
else if (Input.GetButtonDown("3"))
{
StartCoroutine(this.skillPrueba.Initiate(this.actionEmitter, this.gameObject));
}
}
// Si la skill existe en la barra de accion, se borra
public void RemoveRepeated(int skillHashCode, int ignoreIndex)
{
for (int i = 0; i < slots.Length; i++)
{
if (i == ignoreIndex) continue;
if(slots[i] != null && slots[i].GetHashCode() == skillHashCode)
{
Debug.Log("ignore index = " + ignoreIndex);
Debug.Log("repeated = " + i);
slots[i] = null;
player.GetComponent<PlayerGuiManager>().RemoveSlot(i);
}
}
}
public int DecreaseCooldown(int skillHashCode)
{
int cd = --activeSkills[skillHashCode][1];
if (activeSkills[skillHashCode][0] > -1)
{
player.GetComponent<PlayerGuiManager>().SetCooldown(activeSkills[skillHashCode][0], cd);
}
return cd;
}
public void AddSkill(Skill skill, int index)
{
slots[index] = skill;
if (activeSkills.ContainsKey(skill.GetHashCode()))
{
activeSkills[skill.GetHashCode()][0] = index;
player.GetComponent<PlayerGuiManager>().ActivateCooldown(index, activeSkills[skill.GetHashCode()][1]);
}
}
public void RemoveSkill(int index)
{
Debug.Log("Borrando Skill");
if (activeSkills.ContainsKey(slots[index].GetHashCode()))
{
activeSkills[slots[index].GetHashCode()][0] = -1;
slots[index] = null;
player.GetComponent<PlayerGuiManager>().DeactivateCooldown(index);
}
else
{
slots[index] = null;
}
}
public void AddActiveSkill(int skillHashCode, int[] indexCD)
{
activeSkills.Add(skillHashCode, indexCD);
player.GetComponent<PlayerGuiManager>().ActivateCooldown(indexCD[0], indexCD[1]);
}
public void RemoveActiveSkill(int skillHashCode)
{
if (activeSkills[skillHashCode][0] > -1)
{
player.GetComponent<PlayerGuiManager>().DeactivateCooldown(activeSkills[skillHashCode][0]);
}
activeSkills.Remove(skillHashCode);
}
public int GetIndex(Skill skill)
{
int index = -1;
for(int i = 0; i < slots.Length; i++)
{
if (slots[i] == skill)
index = i;
}
return index;
}
}