/
PlayerStats.cs
238 lines (209 loc) · 6.73 KB
/
PlayerStats.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
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
233
234
235
236
237
238
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class PlayerStats
{
/* This class has a WHOLE lot going on. It has static variables to update the private variables as well as the saving and reloading for the playerstats
*
*
*/
#region static helper variables
public static string classInfo;
public static string playerName;
public static int maxHealth;
public static int currHealth;
public static int maxMP;
public static int currMP;
public static WeaponData weapon;
public static int attackPwr;
public static int level;
public static int magicPwr;
public static string gps;
public static string weaponNameSTA;
public static List<QuestData> missionList;
public static int exp;
public static int gold;
#endregion
#region serialized variables
[SerializeField]
private string name;
[SerializeField]
private string currClass;
[SerializeField]
private int currMaxHealth;
[SerializeField]
private int currHP;
[SerializeField]
private int currMaxMP;
[SerializeField]
private int currMagP;
[SerializeField]
private WeaponData currWeapon;
[SerializeField]
private int currAtkPwr;
[SerializeField]
private int currMagicPwer;
[SerializeField]
private int currLevel;
[SerializeField]
private string location;
[SerializeField]
private List<QuestData> questList;
[SerializeField]
private int currExp;
[SerializeField]
private int currGold;
#endregion
/* This constructor calls the static variables to re-update the private variables to be serialized
*/
public PlayerStats() {
currClass = classInfo;
name = playerName;
currMaxHealth = maxHealth;
currHP = currHealth;
currMaxMP = maxMP;
currMagP = currMP;
currWeapon = weapon;
currAtkPwr = attackPwr;
currMagicPwer = magicPwr;
currLevel = level;
location = gps;
questList = missionList;
currExp = exp;
currGold = gold;
}
//this function adds values to the static variables initially
public void Creation(string job, string incomingName, int startHealth, int strength, int magic, Weapons starterWeapon)
{
classInfo = job;
playerName = incomingName;
maxHealth = startHealth;
attackPwr = strength;
magicPwr = magic;
weapon = new WeaponData(starterWeapon.weapon.GetWeaponName(), starterWeapon.weapon.GetWeaponPwr(), starterWeapon.weapon.GetWeaponDescrpt());
currHealth = startHealth;
exp = 0;
maxMP = 20;
currMP = 20;
level = 1;
missionList = new List<QuestData>();
gps = "Overword";
}
#region getters
public int GetLevel() {
return currLevel;
}
public string GetClass() {
return currClass;
}
public string GetName() {
return name;
}
public int GetCurrHealth() {
return currHP;
}
public int GetCurrMP() {
return currMagP;
}
public int GetMaxHealth() {
return currMaxHealth;
}
public int GetMaxMP() {
return currMaxMP;
}
public int GetStr() {
return currAtkPwr;
}
public int GetInt() {
return currMagicPwer;
}
public WeaponData GetEquippedWeapon() {
return currWeapon;
}
public string GetLocation() {
return location;
}
public List<QuestData> GetQuestList() {
return questList;
}
public int GetExp(){
return currExp;
}
public int GetGold() {
return currGold;
}
#endregion
#region setters
public void SetLevel(int newLevel) {
currLevel = newLevel;
}
public void SetClass(string newClass) {
currClass = newClass;
}
public void SetName(string newName) {
name = newName;
}
public void EquipWeapon(WeaponData newWeapon) {
currWeapon = newWeapon;
}
public void SetLocation(string newPlace) {
location = newPlace;
}
public void GainExp(int expGain) {
exp += expGain;
}
public void GainGold(int goldGain) {
gold += goldGain;
}
#endregion
public void SavePlayer()
{
Debug.Log("We savin bois");
SaveSystem.SavePlayer(this);
}
public void LoadPlayer()
{
PlayerStats loadedPlayer = SaveSystem.LoadPlayer();
#region private variable setters
currClass = loadedPlayer.GetClass();
name = loadedPlayer.GetName();
currMaxHealth = loadedPlayer.GetMaxHealth();
currMaxMP = loadedPlayer.GetMaxMP();
currHP = loadedPlayer.GetCurrHealth();
currMP = loadedPlayer.GetCurrMP();
currAtkPwr = loadedPlayer.GetStr();
currMagicPwer = loadedPlayer.GetInt();
currLevel = loadedPlayer.GetLevel();
location = loadedPlayer.GetLocation();
currWeapon = loadedPlayer.GetEquippedWeapon();
currGold = loadedPlayer.GetGold();
currExp = loadedPlayer.GetExp();
//questList = loadedPlayer.GetQuestList();
currExp = loadedPlayer.GetExp();
Debug.Log("We loaded verything");
Debug.Log("Character info: " + loadedPlayer.GetName() + " " + loadedPlayer.GetClass() + " " + loadedPlayer.GetLevel());
Debug.Log("Weapon info: " + loadedPlayer.GetEquippedWeapon().GetWeaponName() + " " + loadedPlayer.GetEquippedWeapon().GetWeaponDescrpt() + " " + loadedPlayer.GetEquippedWeapon().GetWeaponPwr());
#endregion
#region static variable resetters
classInfo = loadedPlayer.GetClass();
playerName = loadedPlayer.GetName();
maxHealth = loadedPlayer.GetMaxHealth();
currHealth = loadedPlayer.GetCurrHealth();
maxMP = loadedPlayer.GetMaxMP();
currMP = loadedPlayer.GetCurrMP();
attackPwr = loadedPlayer.GetStr();
level = loadedPlayer.GetLevel();
magicPwr = loadedPlayer.GetInt();
gps = loadedPlayer.GetLocation();
weapon = loadedPlayer.GetEquippedWeapon();
missionList = loadedPlayer.GetQuestList();
exp = loadedPlayer.GetExp();
gold = loadedPlayer.GetGold();
for (int i = 0; i < missionList.Count; i++) {
if(missionList[i].GetQuestObjective().goalType == GoalType.ReportTo)
missionList[i].GetQuestObjective().reporter = GameObject.Find(missionList[i].GetQuestObjective().reporterName);
}
#endregion
}
}