-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRankUpScript.cs
More file actions
229 lines (192 loc) · 6.52 KB
/
RankUpScript.cs
File metadata and controls
229 lines (192 loc) · 6.52 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
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 RankUpScript : MonoBehaviour
{
public SavePrefs prefs;
public GameObject rankCheer;
public GameObject rankText;
public GameObject expText;
public SceneChanger sceneChanger;
public Button exitButton;
[System.NonSerialized]
public bool Sparring = false;
public int PlayerRank = 3;
public int PlayerEXP = 0;
public int MaxEXP = 0;
public int TotalEXP = 0;
public int GiveThisMuchEXP = 0;
public int updateCount = 0;
public bool startCount = false;
public bool exitNow = false;
public int SparringR2EXP;
public int SparringR1EXP;
public int MatchR2EXP;
public int MatchR1EXP;
public int MaxEXPR2;
public int MaxEXPR1;
public bool MaxedOut = false;
// -----------------------------------------------------------------------//
// Start is called before the first frame update
void Start()
{
// Set correct values
SparringR2EXP = 250;
SparringR1EXP = 500;
MatchR2EXP = 3000;
MatchR1EXP = 6000;
MaxEXPR2 = 3000;
MaxEXPR1 = 6000;
exitButton.enabled = false;
exitButton.GetComponent<Image>().enabled = false;
PlayerRank = PlayerPrefs.GetInt("PlayerRank");
rankText.GetComponent<Text>().text = "" + PlayerRank;
Sparring = prefs.getAbilityTF("SparringMatch");
PlayerEXP = PlayerPrefs.GetInt("PlayerEXP");
TotalEXP = PlayerPrefs.GetInt("TotalEXP");
MaxedOut = checkMaxed();
if (Sparring)
{
if (MaxedOut)
{
GiveThisMuchEXP = 0;
expText.GetComponent<Text>().text = "+" + GiveThisMuchEXP + "\n" + PlayerEXP;
}
else
{
// Do sparing-only code
SparringMatchSetup();
// Turn Sparring off in player prefs
prefs.SavePrefBool("SparringMatch", false);
}
}
else
{
// Real Match set-up
TrueMatchSetup();
}
}
// -----------------------------------------------------------------------//
public bool checkMaxed()
{
// this function checks if they have maxed earnable exp for that rank
if (PlayerRank > 1 && TotalEXP >= MaxEXPR2)
{
return true;
}
else if (PlayerRank <= 1 && TotalEXP >= MaxEXPR1)
{
return true;
}
else
{
return false;
}
}
// -----------------------------------------------------------------------//
void SparringMatchSetup()
{
// Get rank & display in text box
PlayerRank = PlayerPrefs.GetInt("PlayerRank");
rankText.GetComponent<Text>().text = "" + PlayerRank;
if (PlayerRank >= 2) // player rank >=2
{
GiveThisMuchEXP = SparringR2EXP;
prefs.GainEXP(GiveThisMuchEXP);
/* Kept for posterity
// Add current exp + granted exp
newEXP = PlayerEXP + GiveThisMuchEXP;
// Update playerprefs
// PlayerPrefs.SetInt("PlayerEXP", newEXP);
prefs.SavePref("PlayerEXP", newEXP);
// Update player's total earned EXP
TotalEXP += GiveThisMuchEXP;
prefs.SavePref("TotalEXP", TotalEXP);
*/
}
if (PlayerRank == 1)
{
GiveThisMuchEXP = SparringR1EXP;
prefs.GainEXP(GiveThisMuchEXP);
}
expText.GetComponent<Text>().text = "+" + GiveThisMuchEXP + "\n" + PlayerEXP;
}
// -----------------------------------------------------------------------//
void TrueMatchSetup()
{
if ((PlayerRank - 1) > 0) // New Player Rank will be > 0 (ie. hasn't won game yet.)
{
// Decrease rank as player wins
PlayerRank--;
// Save rank across scenes
// PlayerPrefs.SetInt("PlayerRank", PlayerRank);
prefs.SavePref("PlayerRank", PlayerRank);
if (PlayerRank == 2) // player goes 3->2
{
GiveThisMuchEXP = MatchR2EXP;
prefs.GainEXP(MatchR2EXP);
}
if (PlayerRank == 1)
{
GiveThisMuchEXP = MatchR1EXP;
prefs.GainEXP(MatchR1EXP);
}
expText.GetComponent<Text>().text = "+" + GiveThisMuchEXP + "\n" + PlayerEXP;
}
else if (PlayerRank > 3)
{
Debug.Log("PLAYER RANK IS TOO HIGH; SOMETHING BROKEN");
}
else // New Player rank 0 ie <1
{
rankText.GetComponent<Text>().text = "";
expText.GetComponent<Text>().text = "";
// Player Beat Game!
prefs.SavePrefBool("BeatGame", true);
// PlayerPrefs.SetInt("BeatGame", 1);
// Load Beat Game Scene (no delay)
sceneChanger.GoSceneNumber(2);
}
}
// -----------------------------------------------------------------------//
void Update()
{
if (startCount)
{
updateCount++;
if (GiveThisMuchEXP > 0)
{
GiveThisMuchEXP -= 25;
PlayerEXP += 25;
expText.GetComponent<Text>().text = "+" + GiveThisMuchEXP + "\n" + PlayerEXP;
if (updateCount > 30 && Input.anyKey)
{
PlayerEXP += GiveThisMuchEXP;
GiveThisMuchEXP -= GiveThisMuchEXP;
}
}
else
{
expText.GetComponent<Text>().text = "\n" + PlayerEXP;
exitButton.enabled = true;
exitButton.GetComponent<Image>().enabled = true;
exitButton.Select();
}
}
else
{
if (Input.anyKey)
{
startCount = true;
rankText.GetComponent<Text>().text = "" + PlayerRank;
if (!Sparring)
{
rankCheer.GetComponent<Text>().text = "Rank Up!";
}
}
}
}
}