-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.java
209 lines (190 loc) · 6.21 KB
/
Item.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
import java.util.*;
/** Represents an item, either on the map or in a Unit's inventory */
public class Item {
Info info; //a reference to the info
String name;
String adj; //null if no adj (half of weapons have no adj)
int row;
int col;
Item(Info info, String n) {
this.info = info;
row = 0;
col = 0;
String[] s = n.split("[+]");
if(s.length == 2) {
adj = s[0];
name = s[1];
} else {
adj = null;
name = s[0];
}
}
Item(Info info, String tp, Vector<String> tags) { //chooses a random weapon from the available tags and of this type
this.info = info;
row = 0;
col = 0;
Vector<String> possible = info.listOf(tp);
Vector<String> goodones = new Vector<String>();
for(String key : possible) {
Vector<String> keytags = info.tags.get(key);
//make sure it has at least one similar tag and it has no tags that begin with -
boolean good = true;
boolean hasatag = false;
for(String tag : tags) {
if(tag.charAt(0) == '-') {
tag = tag.substring(1);
for(String othertag : keytags) {
if(tag.equals(othertag)) {
good = false;
break;
}
}
} else {
for(String othertag : keytags) {
if(tag.equals(othertag))
hasatag = true;
}
}
}
if(good && hasatag) {
goodones.add(key);
}
}
//Randomly select from goodones
name = goodones.get(Game.rand(0, goodones.size()));
//Choose an adjective randomly of ones that fit if random chance
adj = null;
if(tp.equals("weapon") && Game.rand(0, 5) == 0) {
possible = info.listOf("adj");
goodones = new Vector<String>();
for(String key : possible) { //for each adjective
Vector<String> keytags = info.tags.get(key); //get tags for the adjective
//make sure this weapon has at least one tag in common with the adjective and none of the -
boolean good = true;
boolean hasatag = false;
for(String tag : keytags) { //for each of the adjective tags
if(tag.charAt(0) == '-') { //if it starts with -
tag = tag.substring(1); //trim
for(String othertag : info.tags.get(name)) { //for each tag for this weapon
if(tag.equals(othertag)) { //if we find that tag
good = false; //this is a bad adjective and it should feel bad
break;
}
}
} else { //it didn't start with a -
for(String othertag : info.tags.get(name)) { //for each adjective in this weapon
if(tag.equals(othertag)) { //if they match
hasatag = true; //yay! we have something in common!
}
}
}
}
if(good && hasatag) {
goodones.add(key);
}
}
if(goodones.size() > 0) {
adj = goodones.get(Game.rand(0, goodones.size()));
}
}
}
public String toString() {
if(adj != null)
return adj + " " + name;
else
return name;
}
public String getSaveName() {
if(adj != null)
return adj + "+" + name;
else
return name;
}
public String getSlot() {
if(info.types.get(name).equals("armor"))
return info.stats.get(name).get("slot");
else
return "weapon";
}
public int getRow() {
return row;
}
public int getCol() {
return col;
}
public void setRow(int row) {
this.row = row;
}
public void setCol(int col) {
this.col = col;
}
public int getMass() {
int mass = 0;
if(info.stats.get(name).containsKey("mass"))
mass += Integer.parseInt(info.stats.get(name).get("mass"));
if(adj != null && info.stats.get(adj).containsKey("mass"))
mass += Integer.parseInt(info.stats.get(adj).get("mass"));
return mass;
}
public int getRange() {
int range = 0;
if(info.stats.get(name).containsKey("range"))
range += Integer.parseInt(info.stats.get(name).get("range"));
if(adj != null && info.stats.get(adj).containsKey("range"))
range += Integer.parseInt(info.stats.get(adj).get("range"));
return range;
}
public int getAttack() {
int attack = 0;
if(info.stats.get(name).containsKey("attack"))
attack += Integer.parseInt(info.stats.get(name).get("attack"));
if(adj != null && info.stats.get(adj).containsKey("attack"))
attack += Integer.parseInt(info.stats.get(adj).get("attack"));
return attack;
}
public int getASpeed() {
int aspeed = 0;
if(info.stats.get(name).containsKey("aspeed"))
aspeed += Integer.parseInt(info.stats.get(name).get("aspeed"));
if(adj != null && info.stats.get(adj).containsKey("aspeed"))
aspeed += Integer.parseInt(info.stats.get(adj).get("aspeed"));
return aspeed;
}
public int getDamage() {
int damage = 0;
if(info.stats.get(name).containsKey("damage"))
damage += Integer.parseInt(info.stats.get(name).get("damage"));
if(adj != null && info.stats.get(adj).containsKey("damage"))
damage += Integer.parseInt(info.stats.get(adj).get("damage"));
return damage;
}
public int getDefense() {
int defense = 0;
if(info.stats.get(name).containsKey("defense"))
defense += Integer.parseInt(info.stats.get(name).get("defense"));
if(adj != null && info.stats.get(adj).containsKey("defense"))
defense += Integer.parseInt(info.stats.get(adj).get("defense"));
return defense;
}
public int getSpeed() {
int speed = 0;
if(info.stats.get(name).containsKey("speed"))
speed += Integer.parseInt(info.stats.get(name).get("speed"));
if(adj != null && info.stats.get(adj).containsKey("speed"))
speed += Integer.parseInt(info.stats.get(adj).get("speed"));
return speed;
}
//Returns a random effect from possible effects, null if no effect happens this attack
public Effect getEffect() {
if(adj == null)
return null;
Vector<Effect> possible = new Vector<Effect>();
for(Effect e : info.effects.get(adj)) {
if(Game.rand(0, 100) < e.chance)
possible.add(e);
}
if(possible.size() == 0)
return null;
return possible.get(Game.rand(0, possible.size())).copy();
}
}