-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatchTurnPlayer.cs
More file actions
232 lines (195 loc) · 6.53 KB
/
MatchTurnPlayer.cs
File metadata and controls
232 lines (195 loc) · 6.53 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
// Unless denoted by a commented out link, TK wrote literally everything here
public class MatchTurnPlayer : MonoBehaviour
{
public MatchTurn turn;
public PlayerObject player;
public EnemyObject enemy;
public MoveSetScript moveset;
public BattleTextScript btext;
public Animations animate;
// Certain player buttons will be disabled if not player turn
// or player does not have that ability
public GameObject standardAbilButton;
public GameObject counterButton;
public GameObject jabButton;
public GameObject sundayButton;
public GameObject butterButton;
public bool prevGuard;
public void Start()
{
standardAbilButton.SetActive(false);
counterButton.SetActive(false);
sundayButton.SetActive(false);
butterButton.SetActive(false);
}
// ------------------------------------------------------------------------------------------------- //
public void doPlayerTurn()
{
// Debug.Log("You are inside Player's turn!");
// If player was defending last turn; turn it off
prevGuard = player.Guard;
player.Guard = false;
// If was in guarding stance, and not guarding again, return to idle stance animation
if (prevGuard)
{
animate.PlayerTurnOffGuard();
}
// If dazed, move is dazed and player doesn't get a turn
if (player.Dazed)
{
playerSelect(10);
player.Dazed = false;
}
else // Set up for player selection
{
// Start by enabling all regular buttons
standardAbilButton.SetActive(true);
// if counter, enable & select counter button; else select jab
if (enemy.prevMove == 9)
{
counterButton.SetActive(true);
counterButton.GetComponent<Button>().Select();
}
else
{
counterButton.SetActive(false);
jabButton.GetComponent<Button>().Select();
}
// if have 1st ability, enable sunday p
if (player.SundayPunch)
{
sundayButton.SetActive(true);
}
// if have 2nd ability, enable butterbee
if (player.ButterBee)
{
butterButton.SetActive(true);
}
}
}
// ------------------------------------------------------------------------------------------------- //
public void playerSelect(int moveNum)
{
bool PlayerMiss;
int attemptMove = moveNum;
// Reset error text on make selection
btext.updateErrorText(" ");
// Get miss chance, can't miss on Counter
if (enemy.prevMove == 9 && moveNum == 0)
{
PlayerMiss = false;
}
else if (moveNum == 1 || moveNum == 6 || moveNum == 7 || moveNum == 10 || moveNum == 11)
{
PlayerMiss = false;
}
else
{
// Get if player misses or not
PlayerMiss = (Random.Range(0.0f, 1.0f) < enemy.EVA) ? true : false;
}
if (PlayerMiss)
{
moveNum = 9; // Change move to miss
}
// Stop selection if player does not have enough SP
if (moveset.getMoveSetCost(moveNum) > player.SP)
{
Debug.Log("you cannot afford this move w/current SP!");
btext.updateErrorText("NOT ENOUGH SP!");
}
else // continue with player selection
{
// Deselect button
EventSystem.current.SetSelectedGameObject(null);
// Disable player Buttons
standardAbilButton.SetActive(false);
counterButton.SetActive(false);
sundayButton.SetActive(false);
butterButton.SetActive(false);
// DOES THE SELECTED ACTION WOO
moveset.doMove(moveNum);
// Hold the turn until the animations are over.
StartCoroutine(RunPlayerTurnAnimations(attemptMove, moveNum));
}
}
// ------------------------------------------------------------------------------------------------- //
IEnumerator RunPlayerTurnAnimations(int attemptMove, int moveNum)
{
float timeWait;
if (moveNum == 10)
{
timeWait = 1.5f;
}
else
{
timeWait = 1.0f;
}
// Run regular move animations
animate.PlayerSpriteAnimation(attemptMove, moveNum);
yield return new WaitForSeconds(timeWait);
if (moveNum == 8) // If ButterBee, chance for a second attack
{
bool bee = (Random.Range(0.0f, 1.0f) < (player.LCK*3.5f)) ? true : false;
if (bee)
{
playerSelect(0);
}
else
{
checkEndTurn();
}
}
else
{
checkEndTurn();
}
// EnemySpriteAnimation(int moveNum)
}
public void checkEndTurn()
{
if (player.HP <= 0)
{
// Run game over animatio
// set MatchEnd = true;
turn.MatchEnd = true;
turn.PlayerTurn = false;
turn.EnemyTurn = false;
turn.PlayerKO = true;
}
else if (enemy.HP <= 0)
{
// Run finisher animation for player
// set MatchEnd = true;
turn.MatchEnd = true;
turn.PlayerTurn = false;
turn.EnemyTurn = false;
turn.EnemyKO = true;
}
else
{
// Yield turn to enemy
yieldPlayerTurn();
}
}
// ------------------------------------------------------------------------------------------------- //
public void yieldPlayerTurn()
{
turn.PlayerTurn = false;
}
// ------------------------------------------------------------------------------------------------- //
// THESE ARE TEST FUNCTIONS;
public void setPlayerHP(int hp)
{
player.HP = hp;
}
public void setEnemyHP(int hp)
{
enemy.HP = hp;
}
}