forked from TomaQ/TextRPG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
307 lines (261 loc) · 11.6 KB
/
Player.java
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
//Need to make quests and have objects associated in here n such ya know
package textrpg;
import java.util.ArrayList;
import java.util.List;
import textrpg.equipment.*;
import textrpg.jobs.*;
import textrpg.weapons.*;
import textrpg.items.*;
public class Player extends Entity {
private Job job;
private Weapon weapon = new NoneW();
private Weapon offHand = new NoneW(); //shield or offhand goes here
private Equipment chest = new NoneE();
private Equipment legs = new NoneE();
private Equipment bracers = new NoneE();
private Equipment boots = new NoneE();
private Equipment gloves = new NoneE();
private Equipment ring = new NoneE();
private Equipment hat = new NoneE();
private Equipment goggles = new NoneE();//not sure if i want these...
private List<Item> inventory = new ArrayList<>();
private int level;
private int currentExp;
private int nextLevelExp = 27; //exp needed to reach the next level - Temporary number
private int gold = 0;
//sets the level to 1 and initializes the players job
public Player(String n, int j) {
level = 1;
super.setName(n);
new Job(this, j);
}
public String getJobName(){return job.getJobName();}
public Weapon getWeapon(){return weapon;}
public void setWeapon(Weapon e){weapon = e;initCurrentStats();}
public Weapon getOffHand(){return offHand;}
public void setOffHand(Weapon e){offHand = e;initCurrentStats();}
public Equipment getChest(){return chest;}
public void setChest(Equipment e){chest = e;initCurrentStats();}
public Equipment getLegs(){return legs;}
public void setLegs(Equipment e){legs = e;initCurrentStats();}
public Equipment getBracers(){return bracers;}
public void setBracers(Equipment e){bracers = e;initCurrentStats();}
public Equipment getBoots(){return boots;}
public void setBoots(Equipment e){boots = e;initCurrentStats();}
public Equipment getGloves(){return gloves;}
public void setGloves(Equipment e){gloves = e;initCurrentStats();}
public Equipment getRing(){return ring;}
public void setRing(Equipment e){ring = e;initCurrentStats();}
public Equipment getHat(){return hat;}
public void setHat(Equipment e){hat = e;initCurrentStats();}
public Equipment getGoggles(){return goggles;}
public void setGoggles(Equipment e){goggles = e;initCurrentStats();}
public Equipment[] getEquipment() {
Equipment[] temp = {weapon, offHand, chest, legs, bracers, boots, gloves, ring, hat, goggles};
return temp;
}
public List<Item> getInventory(){return inventory;}//used for removing and looping
public void addInventory(Item i){inventory.add(i);}
public Job getJob(){return job;}
public void setJob(Job j){job = j;} //if it is ever possible to switch jobs then need to do more than this
//Returns a 2d array of the item name and the quantity of each
public String[][] getCountedInventory() {
String[][] invenCount = new String[inventory.size()][2];
for (int i = 0; i < inventory.size(); i++) {
for (int j = 0; j - 1 < i; j++) {//i should use a map here instead lol
//short circuits here
if (invenCount[j][0] != null && invenCount[j][0].equals(inventory.get(i).getName())) {//if the names match
invenCount[j][1] = Integer.toString(Integer.valueOf(invenCount[j][1]) + 1);
break; //dont need to check rest of array if similar
}
else if (invenCount[j][0] == null) { //if it doesnt find the item then it adds it to the string
invenCount[j][0] = inventory.get(i).getName();
invenCount[j][1] = "1";
break; //dont need to check the rest of array if inserted
}
}
}
return invenCount;
}
//Returns the players inventory without duplicates
public Item[] getCountedInventoryItems() {
Item[] invenCount = new Item[inventory.size()];
for (int i = 0; i < inventory.size(); i++) {
for (int j = 0; j - 1 < i; j++) {
if (invenCount[j] != null && invenCount[j] == inventory.get(i)) {
invenCount[i] = inventory.get(j);
break;
}
else if (invenCount[j] == null) {
invenCount[j] = inventory.get(i);
}
}
}
return invenCount;
}
//Prints the players inventory in the format 'Item name(quantity)'
public void printInventory() {
Game.printBreak();
System.out.println("Your inventory:");
String inven = "Gold: " + this.getGold() + ", ";//the inventory string that gets printed out
String[][] invenCount = this.getCountedInventory();
for (int i = 0; i < invenCount.length; i++) { //prints the inventory and counter if > 1
if (invenCount[i][0] != null) {
if (Integer.valueOf(invenCount[i][1]) > 1) {
inven += invenCount[i][0] + "(" + invenCount[i][1] + "), ";
}
else {
inven += invenCount[i][0] + ", ";
}
}
}
if (inven.length() > 2) {//formatting
inven = inven.substring(0, inven.length() - 2);
}
System.out.println(inven);
}
public int getCurrentExp(){return currentExp;}
public void setCurrentExp(int i) {
if (nextLevelExp < (currentExp + i)) { //carrys over left over experience
currentExp = (currentExp + i) - nextLevelExp;
levelUp();
}
else {
currentExp = i;
}
}
public int getNextLevelExp(){return nextLevelExp;}
public void setNextLevelExp(int i){nextLevelExp = i;}
public int getLevel(){return level;}
public void levelUp(){
level += 1;
System.out.println("You reached level " + level + "!");
job.levelUp(this);
initCurrentStats(); //need to set currect stats since they changed
}
public int getGold(){return gold;}
public void setGold(int i){gold = i;}
public void printStatus() {
Game.printBreak();
System.out.println("Name: " + getName() + "\tJob: " + getJobName() + "\tLevel:" + getLevel());
System.out.println("Health:" + getCurrentHealth() + "\nMana:" + getCurrentMana() + "\nStrength:" + getCurrentStrength() + "\nMagic:" + getCurrentMagic() + "\nAgility:" + getCurrentAgility() + "\nDefense:" + getCurrentDefense() + "\nMagic Defense:" + getCurrentMagicDefense());
}
public void printEquipment() {
Game.printBreak();
System.out.println("Weapons: " + getWeapon().getName() + "/" + getOffHand().getName());
System.out.println("Chest: " + getChest().getName() + "\tLegs: " + getLegs().getName());
System.out.println("Bracers: " + getBracers().getName() + "\tBoots: " + getBoots().getName());
System.out.println("Gloves: " + getGloves().getName() + "\tRing: " + getRing().getName());
System.out.println("Helmet: " + getHat().getName() + "\tGoggles: " + getGoggles().getName());
}
@Override //sets the current stats by calculating the base and bonus from equipment
public void initCurrentStats() {
int[] temp = calculateBonusStats();
super.setCurrentHealth(super.getBaseHealth() + temp[0]);
super.setMaxHealth(super.getCurrentHealth());
super.setCurrentMana(super.getBaseMana() + temp[1]);
super.setMaxMana(super.getCurrentMana());
super.setCurrentStrength(super.getBaseStrength() + temp[2]);
super.setCurrentMagic(super.getBaseMagic() + temp[3]);
super.setCurrentAgility(super.getBaseAgility() + temp[4]);
super.setCurrentDefense(super.getBaseDefense() + temp[5]);
super.setCurrentMagicDefense(super.getBaseMagicDefense() + temp[6]);
}
//Calculates the bonus stats from equipment
private int[] calculateBonusStats() {
int[] temp = new int[7];
for (int i = 0; i < 7; i++) {
temp[i] = 0;
temp[i] += getWeapon().getEquipmentStats()[i]; //0 is the index of the hp modifier stat, look at docs
temp[i] += getOffHand().getEquipmentStats()[i];
temp[i] += getChest().getEquipmentStats()[i];
temp[i] += getLegs().getEquipmentStats()[i];
temp[i] += getBracers().getEquipmentStats()[i];
temp[i] += getBoots().getEquipmentStats()[i];
temp[i] += getGloves().getEquipmentStats()[i];
temp[i] += getRing().getEquipmentStats()[i];
temp[i] += getHat().getEquipmentStats()[i];
temp[i] += getGoggles().getEquipmentStats()[i];
}
return temp;
}
//Takes an array of stats from an item and adds it to the players
//Used for HP pots and MP pots and such (for now)
//Look at Item use documentation for order of array
public void useItem(int[] statsModified) {
if (statsModified[7] == 1) {//if it can increase max hp or mp, can probably make if-else better
super.setCurrentHealth(super.getCurrentHealth() + statsModified[0]);
}
else {
if (super.getCurrentHealth() + statsModified[0] > super.getMaxHealth()) {
super.setCurrentHealth(super.getMaxHealth());
}
else {
super.setCurrentHealth(super.getCurrentHealth() + statsModified[0]);
}
}
if (statsModified[7] == 1) {//if it can increase max hp or mp, can probably make if-else better
super.setCurrentMana(super.getCurrentMana() + statsModified[1]);
}
else {
if (super.getCurrentMana() + statsModified[1] > super.getMaxMana()) {
super.setCurrentMana(super.getMaxMana());
}
else {
super.setCurrentMana(super.getCurrentMana() + statsModified[1]);
}
}
super.setCurrentStrength(super.getCurrentStrength() + statsModified[2]);
super.setCurrentMagic(super.getCurrentMagic() + statsModified[3]);
super.setCurrentAgility(super.getCurrentAgility() + statsModified[4]);
super.setCurrentDefense(super.getCurrentDefense() + statsModified[5]);
super.setCurrentMagicDefense(super.getCurrentMagicDefense() + statsModified[6]);
}
//Sets the equipment based on it's type
//Look at docs for equipment type
//Calls this method when no type is specified
public void setEquipment(Equipment e) {
setEquipment(e, e.getEquipmentType());
}
//Sets the equipment based on the type passed
public void setEquipment(Equipment e, int type) {
switch (type) {
case 1:
Weapon tempW = new NoneW();
setWeapon(tempW);
break;
case 2:
setChest(e);
break;
case 3:
setLegs(e);
break;
case 4:
setBracers(e);
break;
case 5:
setBoots(e);
break;
case 6:
setGloves(e);
break;
case 7:
Weapon tempS = new NoneW();
setOffHand(tempS);
break;
case 8:
Weapon tempO = new NoneW();
setOffHand(tempO);
break;
case 9:
setRing(e);
break;
case 10:
setHat(e);
break;
case 11:
setGoggles(e);
break;
}
}
}