-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewInvManagement
More file actions
239 lines (217 loc) · 7.66 KB
/
NewInvManagement
File metadata and controls
239 lines (217 loc) · 7.66 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
package chests;
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("armor");
if(type == 3)
System.out.println("consumable");
}
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};
return new_stats;
}
}
public E[] ADDequipment(E[] equipment)
{
int full_slots = 0;
E[] new_equipment = (E[]) new Object[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-1)
{
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] = (E) this;
break;
}
}
//System.out.println(Arrays.toString(new_equipment));
return new_equipment;
}
public E[] ADDinventory(E[] inventory){
int full_slots = 0;
E[] new_inventory = (E[]) 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-1)
{
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] = (E) this;
break;
}
}
//System.out.println(Arrays.toString(new_inventory));
return new_inventory;
}
public E[] swapInventory(E[] inventory, Items item){
if(!item.containedIn(inventory))
return inventory;
E[] new_inventory = (E[]) 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] = (E) this;
break;
}
}
return new_inventory;
}
public E[] dropInventory(E[] inventory){
if(!this.containedIn(inventory))
return inventory;
E[] new_inventory = (E[]) 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].equals(this))
{
new_inventory[i] = null;
break;
}
}
return new_inventory;
}
public E[] dropEquipment(E[] equipment){
if(!this.containedIn(equipment))
return equipment;
E[] new_equipment = (E[]) 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].equals(this))
{
new_equipment[i] = null;
break;
}
}
return new_equipment;
}
public Object[][] equip(E[] inventory, E[] equipment){
int temp = 0;
E[] new_inventory = (E[]) new Items[inventory.length];
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length);
E[] new_equipment = (E[]) new Object[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].equals(this)) {
temp++;
break;
}
}
if(temp > 0){
new_inventory = this.dropInventory(inventory);
new_equipment = this.ADDequipment(equipment);
return new Object[][]{new_inventory, new_equipment};
}
else{
return new Object[][]{inventory, equipment};
}
}
public Object[][] uneuqip(E[] inventory, E[] equipment){
int temp = 0;
E[] new_inventory = (E[]) new Items[inventory.length];
System.arraycopy(inventory, 0, new_inventory, 0, new_inventory.length);
E[] new_equipment = (E[]) new Object[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].equals(this)) {
temp++;
break;
}
}
if(temp > 0){
new_equipment = this.dropEquipment(equipment);
new_inventory = this.ADDinventory(inventory);
return new Object[][]{new_inventory, new_equipment};
}
else{
return new Object[][]{inventory, equipment};
}
}
public boolean containedIn(E[] array){
for(int i = 0; i < array.length; i++){
if(array[i].equals(this)) {
return true;
}
}
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";
}
}