-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerMovement.cs
160 lines (119 loc) · 4.49 KB
/
PlayerMovement.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using UnityEngine;
using RPG.CameraUI; //TODO considerar reescrever
using System.Collections;
namespace RPG.Personagem
{
public class PlayerMovement : MonoBehaviour
{
SpecialAbilities abilities;
Character myCharacter;
DialogueSystem talkTo;
WeaponSystem weaponSystem;
void Start()
{
myCharacter = GetComponent<Character>();
abilities = GetComponent<SpecialAbilities>();
RegisterforMouseEvent();
weaponSystem = GetComponent<WeaponSystem>();
}
void RegisterforMouseEvent()
{
var cameraRaycaster = FindObjectOfType<CameraRaycaster>();
cameraRaycaster.onMouseOverEnemy += OnMouseOverEnemy;
cameraRaycaster.onMouseOverNPC += OnMouseOverNPC;
cameraRaycaster.onMouseOverPotentiallyWalkable += OnMouseOverPotentiallyWalkable;
}
void Update()
{
ScanForAbilityKeyDown();
}
void ScanForAbilityKeyDown()
{
for (int keyIndex = 1; keyIndex <= abilities.GetNumbersOfAbilities(); keyIndex++)
{
if (Input.GetKeyDown(keyIndex.ToString()))
abilities.AttemptSpecialAbility(keyIndex);
}
}
void OnMouseOverPotentiallyWalkable(Vector3 destination)
{
if (Input.GetMouseButton(0))
{
weaponSystem.StopAttacking();
myCharacter.SetDestination(destination);
}
}
bool IsTargetInRange(GameObject target)
{
float distanceToTarget = (target.transform.position - transform.position).magnitude;
return distanceToTarget <= weaponSystem.GetCurrentWeapon().GetMaxAttackRange();
}
void OnMouseOverNPC (NpcAI npc)
{
if (Input.GetMouseButton(0) && IsTargetInRange(npc.gameObject))
{
talkTo = npc.GetComponent<DialogueSystem>();
talkTo.Talk(npc.gameObject);
}
if (Input.GetMouseButton(0)&& !IsTargetInRange(npc.gameObject))
{
StartCoroutine(MoveAndTalk(npc));
}
}
void OnMouseOverEnemy(EnemyAI enemy)
{
{
if (Input.GetMouseButton(0) && IsTargetInRange(enemy.gameObject))
{
weaponSystem.AttackTarget(enemy.gameObject);
}
else if (Input.GetMouseButton(0) && !IsTargetInRange(enemy.gameObject))
{
StartCoroutine(MoveAnAttack(enemy));
//atacar
}
else if (Input.GetMouseButtonDown(1) && IsTargetInRange(enemy.gameObject))
{
abilities.AttemptSpecialAbility(0, enemy.gameObject);
}
else if (Input.GetMouseButtonDown(1) && !IsTargetInRange(enemy.gameObject))
{
StartCoroutine(MoveAnSmite(enemy));
}
}
}
IEnumerator MoveToTarget(GameObject target)
{
myCharacter.SetDestination(target.transform.position);
while (!IsTargetInRange(target))
{
yield return new WaitForEndOfFrame();
}
yield return new WaitForEndOfFrame();
}
IEnumerator MoveToTalk(NpcAI npc)
{
myCharacter.SetDestination(npc.transform.position);
while (!IsTargetInRange(npc.gameObject))
{
yield return new WaitForEndOfFrame();
}
yield return new WaitForEndOfFrame();
}
IEnumerator MoveAndTalk(NpcAI npc)
{
yield return StartCoroutine(MoveToTalk(npc));
}
IEnumerator MoveAnAttack(EnemyAI enemy)
{
yield return StartCoroutine(MoveToTarget(enemy.gameObject));
weaponSystem.AttackTarget(enemy.gameObject);
}
IEnumerator MoveAnSmite(EnemyAI enemy)
{
yield return StartCoroutine(MoveToTarget(enemy.gameObject));
abilities.AttemptSpecialAbility(0, enemy.gameObject);
}
}
}