-
Notifications
You must be signed in to change notification settings - Fork 1
/
Skill.cs
121 lines (97 loc) · 3.49 KB
/
Skill.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class Skill : ScriptableObject {
public string skillName;
public bool moveWhileCasting;
public float moveSpeedPenalty;
public bool rotateWhileCasting;
public float castTime;
public float exitTime;
public bool fireBeforeCast;
public int cooldown;
public string target; // Target de la skill
protected GameObject actionBar;
public SkillEffect[] effects;
public AudioClip shootSound;
// Dispara la skill
public abstract void Fire(GameObject emitter);
public virtual IEnumerator Initiate(GameObject emitter, GameObject actionBar)
{
this.actionBar = actionBar;
if (fireBeforeCast){
Fire(emitter);
yield return Cast(emitter);
yield return ExitCast(emitter);
yield return Cooldown();
} else
{
yield return Cast(emitter);
Fire(emitter);
yield return ExitCast(emitter);
yield return Cooldown();
}
}
protected virtual IEnumerator Cast(GameObject emitter)
{
if (!this.moveWhileCasting)
{
emitter.GetComponentInParent<PlayerController>().move = false;
}
else
{
emitter.GetComponentInParent<Stats>().DecreaseSpeedMultiplier(moveSpeedPenalty);
}
if (this.rotateWhileCasting)
{
emitter.GetComponentInParent<PlayerController>().rotate = true;
}
emitter.GetComponentInParent<Animator>().Play(this.skillName);
yield return new WaitForSeconds(this.castTime); // Tiempo de activacion
emitter.GetComponentInParent<AudioSource>().PlayOneShot(shootSound);
}
protected virtual IEnumerator ExitCast(GameObject emitter)
{
yield return new WaitForSeconds(this.exitTime);
if (!this.moveWhileCasting)
{
emitter.GetComponentInParent<PlayerController>().move = true;
}
else
{
emitter.GetComponentInParent<Stats>().IncreaseSpeedMultiplier(moveSpeedPenalty);
}
if (this.rotateWhileCasting)
{
emitter.GetComponentInParent<PlayerController>().rotate = false;
}
actionBar.GetComponent<ActionBar>().castingSkill = null;
}
protected virtual IEnumerator Cooldown()
{
int[] indexCD = new int[2];
indexCD[0] = actionBar.GetComponent<ActionBar>().GetIndex(this); // Se añade a skills activas (en enfriamiento)
indexCD[1] = this.cooldown + 1;
actionBar.GetComponent<ActionBar>().AddActiveSkill(this.GetHashCode(), indexCD);
while (actionBar.GetComponent<ActionBar>().DecreaseCooldown(this.GetHashCode()) > -1) // Cooldown
{
yield return new WaitForSeconds(1);
}
actionBar.GetComponent<ActionBar>().RemoveActiveSkill(this.GetHashCode());
Debug.Log("Lista de nuevo");
}
public void ApplyEffects(GameObject launcher, GameObject target) {
if (target != launcher && launcher.tag == "Player")
{
launcher.GetComponent<State>().ActivateTarget(target);
}
if(this.target == "Enemy")
{
target.GetComponent<EnemyAI>().Fight(launcher.transform);
}
foreach ( SkillEffect effect in effects)
{
effect.Apply(launcher, target);
}
}
}