-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItems.java
More file actions
296 lines (272 loc) · 10 KB
/
Items.java
File metadata and controls
296 lines (272 loc) · 10 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
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
package hod_game;
import java.util.Arrays;
public class Items<E>
{
public String name;
private int type; //type 1 = weapon, type 2 = armor, type 3 = consumable
private int ADD_hp, ADD_str, ADD_dex, ADD_con, ADD_int, ADD_wis, ADD_cha, SUB_hp, SUB_str, SUB_dex, SUB_con, SUB_int, SUB_wis, SUB_cha;
private int[] ADDstats = new int[]{ADD_hp, ADD_str, ADD_dex, ADD_con, ADD_int, ADD_wis, ADD_cha};
private int[] SUBstats = new int[]{SUB_hp, SUB_str, SUB_dex, SUB_con, SUB_int, SUB_wis, SUB_cha};
public Items(String Iname, int Ahp, int Astr, int Adex, int Acon, int Aint, int Awis, int Acha, int Shp, int Sstr, int Sdex, int Scon, int Sint, int Swis, int Scha , int Itype)
{
name = Iname;
type = Itype;
ADD_hp = Ahp;
ADD_str = Astr;
ADD_dex = Adex;
ADD_con = Acon;
ADD_int = Aint;
ADD_wis = Awis;
ADD_cha = Acha;
SUB_hp = Shp;
SUB_str = Sstr;
SUB_dex = Sdex;
SUB_con = Scon;
SUB_int = Sint;
SUB_wis = Swis;
SUB_cha = Scha;
}
public void getName()
{
System.out.println(name);
}
public void getType()
{
if(type == 1)
System.out.println("weapon");
if(type == 2)
System.out.println("ranged weapon");
if(type == 3)
System.out.println("armor");
if(type == 4)
System.out.println("consumable");
}
public void getStats(){
System.out.println("\tHP: +" + this.ADD_hp + " and -" + this.SUB_hp + "\n\t Strength: +" + this.ADD_str + " and -" + this.SUB_str + "\n\t Dexterity: +" + this.ADD_dex + " and -" + this.SUB_dex + "\n\t Constitution: +" + this.ADD_con + " and -" + this.SUB_con + "\n\t Intelligence: +" + this.ADD_int + " and -" + this.SUB_int + "\n\t Wisdom: +" + this.ADD_wis + " and -" + this.SUB_wis + "\n\t Charisma: +" + this.ADD_cha + " and -" + this.SUB_cha);
}
public int[] ADDstats(int[] stats)
{
if(type == 1 || type == 2)
{
int[] new_stats = new int[]{stats[0], stats[1]+ADD_str-SUB_str, stats[2]+ADD_dex-SUB_dex, stats[3]+ADD_con-SUB_con, stats[4]+ADD_int-SUB_int, stats[5]+ADD_wis-SUB_wis, stats[6]+ADD_cha-SUB_cha};
return new_stats;
}
else
{
int[] new_stats = new int[]{stats[0]+ADD_hp-SUB_hp, stats[1]+ADD_str-SUB_str, stats[2]+ADD_dex-SUB_dex, stats[3]+ADD_con-SUB_con, stats[4]+ADD_int-SUB_int, stats[5]+ADD_wis-SUB_wis, stats[6]+ADD_cha-SUB_cha};
if(new_stats[0] > 100){
new_stats[0] = 100;
}
return new_stats;
}
}
public int[] SUBstats(int[] stats)
{
if(type == 1 || type == 2)
{
int[] new_stats = new int[]{stats[0], stats[1]-ADD_str+SUB_str, stats[2]-ADD_dex+SUB_dex, stats[3]-ADD_con+SUB_con, stats[4]-ADD_int+SUB_int, stats[5]-ADD_wis+SUB_wis, stats[6]-ADD_cha+SUB_cha};
return new_stats;
}
else
{
int[] new_stats = new int[]{stats[0]-ADD_hp+SUB_hp, stats[1]-ADD_str+SUB_str, stats[2]-ADD_dex+SUB_dex, stats[3]-ADD_con+SUB_con, stats[4]-ADD_int+SUB_int, stats[5]-ADD_wis+SUB_wis, stats[6]-ADD_cha+SUB_cha};
if(new_stats[0] <= 0){
new_stats[0] = 1;
}
return new_stats;
}
}
public Items[] ADDequipment(Items[] equipment) //
{
int full_slots = 0;
Items[] new_equipment = (Items[]) new Items[equipment.length]; //create new object array to replace old (passed)
System.arraycopy(equipment, 0, new_equipment, 0, new_equipment.length); //make new array copy of old (passed) array (return passed array if array not null)
for(int y = 0; y < new_equipment.length; y++) //loop checks to see if equipment is already "full"
{
if(new_equipment[y]!=null)
full_slots++;
}
if(full_slots == new_equipment.length)
{
System.out.println("\n\tYour equipment is full! cannot equip any more items!");
return equipment;
}
for(int z = 0; z<new_equipment.length; z++)
{
if(new_equipment[z] == null)
{
new_equipment[z] = (Items) this;
break;
}
}
//System.out.println(Arrays.toString(new_equipment));
return new_equipment;
}
public Items[] ADDinventory(Items[] inventory)//
{
int full_slots = 0;
Items[] new_inventory = (Items[]) new Items[inventory.length]; //create new object array to replace old (passed)
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length); //make new array copy of old (passed) array (return passed array if array not null)
for(int y = 0; y<new_inventory.length; y++) //loop checks to see if inventory is already "full"
{
if(new_inventory[y]!=null)
full_slots++;
}
if(full_slots==new_inventory.length)
{
System.out.println("\n\tYour inventory is full! You cannot carry any more items!");
return inventory;
}
for(int z = 0; z<new_inventory.length; z++)
{
if(new_inventory[z] == null)
{
new_inventory[z] = (Items) this;
break;
}
}
//System.out.println(Arrays.toString(new_inventory));
return new_inventory;
}
public Items[] swapInventory(Items[] inventory, Items item) //command
{
Items[] new_inventory = (Items[]) new Items[inventory.length]; //create new object array to replace old (passed)
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length);
int temp = 0;
for(int i = 0; i < new_inventory.length; i++)
{
if(new_inventory[i].equals(item))
{
new_inventory[i] = (Items) this;
break;
}
}
return new_inventory;
}
public Items[] dropInventory(Items[] inventory) //command "drop"
{
Items[] new_inventory = (Items[]) new Items[inventory.length]; //create new object array to replace old (passed)
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length);
for(int i = 0; i < new_inventory.length; i++)
{
if(new_inventory[i] != null){
if(new_inventory[i].equals(this))
{
new_inventory[i] = null;
break;
}
}
}
return new_inventory;
}
public Items[] dropEquipment(Items[] equipment) //command "drop"
{
Items[] new_equipment = (Items[]) new Items[equipment.length]; //create new object array to replace old (passed)
System.arraycopy(equipment, 0, new_equipment, 0, new_equipment.length);
for(int i = 0; i < new_equipment.length; i++)
{
if(new_equipment[i] != null){
if(new_equipment[i].equals(this))
{
new_equipment[i] = null;
break;
}
}
}
return new_equipment;
}
public Items[][] equip(Items[] inventory, Items[] equipment) //command "equip (item name)"
{
int temp = 0;
Items[] new_inventory = (Items[]) new Items[inventory.length];
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length);
Items[] new_equipment = (Items[]) new Items[equipment.length];
System.arraycopy(equipment, 0, new_equipment, 0, new_equipment.length);
for(int i = 0; i < new_inventory.length; i++){
if(new_inventory[i] != null){
if(new_inventory[i].equals(this)) {
temp++;
break;
}
}
}
if(temp > 0){
new_inventory = this.dropInventory(inventory);
new_equipment = this.ADDequipment(equipment);
return new Items[][]{new_inventory, new_equipment};
}
else{
return new Items[][]{inventory, equipment};
}
}
public Items[][] unequip(Items[] inventory, Items[] equipment) //command "unequip (item name)"
{
int temp = 0;
Items[] new_inventory = (Items[]) new Items[inventory.length];
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length);
Items[] new_equipment = (Items[]) new Items[equipment.length];
System.arraycopy(equipment, 0, new_equipment, 0, new_equipment.length);
for(int i = 0; i < new_equipment.length; i++){
if(new_equipment[i] != null){
if(new_equipment[i].equals(this)) {
temp++;
break;
}
}
}
if(temp > 0){
new_equipment = this.dropEquipment(equipment);
new_inventory = this.ADDinventory(inventory);
return new Items[][]{new_inventory, new_equipment};
}
else{
return new Items[][]{inventory, equipment};
}
}
public boolean containedIn(Items[] array) //
{
for(int i = 0; i < array.length; i++){
if(array[i].equals(this)) {
return true;
}
}
return false;
}
public boolean isFull(Items[] array){
int full_slots = 0;
for(int y = 0; y < array.length; y++) //loop checks to see if inventory is already "full"
{
if(array[y]!=null)
full_slots++;
}
if(full_slots == array.length)
return true;
else
return false;
}
@Override
public boolean equals(Object object)
{
if(object instanceof Items) {
Items i = (Items) object;
return this.name.equals(i.name);
}
return false;
}
@Override
public String toString()
{
if (this != null)
return (this.name);
else
return "Empty";
}
public boolean typeCheckRanged()
{
return this.type == 2;
}
public boolean typeCheckConsumable()
{
return this.type == 4;
}
}