1 package cz.cuni.amis.pogamut.udk.communication.messages;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.Set;
6
7 import cz.cuni.amis.utils.maps.HashMapSet;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 public class ItemType implements Serializable {
27
28
29
30
31 public static final HashMapSet<Category, ItemType> CATEGORIES = new HashMapSet<Category, ItemType>();
32
33
34
35
36
37 public enum Category {
38
39 WEAPON("Weapon"),
40
41 AMMO("Ammo"),
42
43 HEALTH("Health"),
44
45 ARMOR("Armor"),
46
47 OTHER("Other");
48
49
50
51
52 public String name;
53
54
55
56
57
58
59
60
61
62 Category(String name) {
63 this.name = name;
64 }
65
66
67
68
69
70 public Set<ItemType> getTypes() {
71 return CATEGORIES.get(this);
72 }
73
74 }
75
76
77
78
79
80
81
82 public static final HashMapSet<Group, ItemType> GROUPS = new HashMapSet<Group, ItemType>();
83
84
85
86
87
88
89
90 public enum Group {
91
92 LINK_GUN("LinkGun"),
93
94 SHOCK_RIFLE("ShockRifle"),
95
96 ROCKET_LAUNCHER("RocketLauncher"),
97
98 PHYSICS_GUN("PhysicsGun"),
99
100
101 HEALTH("HealthKit"),
102
103 MINI_HEALTH("HealthVial"),
104
105
106 THIGH_PAD("Thighpad"),
107
108 BASE_ARMOR("BaseArmor"),
109
110 SHIELD_BELT("ShieldBelt"),
111
112
113 JUMP_BOOTS("JumpBoots"),
114
115 UDAMAGE("UDamage"),
116
117 OTHER("Unknown"),
118
119 NONE("None");
120
121
122
123
124 public String name;
125
126
127
128
129
130
131
132
133
134 Group(String name) {
135 this.name = name;
136 }
137
138 public Set<ItemType> getTypes() {
139 return GROUPS.get(this);
140 }
141 }
142
143
144
145
146
147
148 private static HashMap<String, ItemType> protos = new HashMap<String, ItemType>();
149
150
151
152
153 public static final ItemType SHOCK_RIFLE = MakePrototype(Category.WEAPON,
154 Group.SHOCK_RIFLE, new String[] { "ShockRifle.WeaponPickup" });
155
156 public static final ItemType SHOCK_RIFLE_AMMO = MakePrototype(
157 Category.AMMO, Group.SHOCK_RIFLE,
158 new String[] { "ShockRifleAmmo.AmmoPickup" });
159
160
161 public static final ItemType LINK_GUN = MakePrototype(Category.WEAPON,
162 Group.LINK_GUN, new String[] { "LinkGun.WeaponPickup" });
163
164 public static final ItemType LINK_GUN_AMMO = MakePrototype(Category.AMMO,
165 Group.LINK_GUN, new String[] { "LinkGunAmmo.AmmoPickup" });
166
167
168 public static final ItemType ROCKET_LAUNCHER = MakePrototype(
169 Category.WEAPON, Group.ROCKET_LAUNCHER, new String[] {
170 "RocketLauncher.WeaponPickup",
171 "RocketLauncher_Content.WeaponPickup" });
172
173 public static final ItemType ROCKET_LAUNCHER_AMMO = MakePrototype(
174 Category.AMMO, Group.ROCKET_LAUNCHER,
175 new String[] { "RocketLauncherAmmo.AmmoPickup",
176 "RocketLauncher_ContentAmmo.AmmoPickup" });
177
178
179 public static final ItemType HEALTH_PACK = MakePrototype(Category.HEALTH,
180 Group.HEALTH, new String[] { "HealthPack.HealthPickup" });
181
182 public static final ItemType HEALTH_VIAL = MakePrototype(
183 Category.HEALTH, Group.MINI_HEALTH,
184 new String[] { "HealthVial.HealthPickup" });
185
186
187 public static final ItemType THIGH_PAD = MakePrototype(Category.ARMOR,
188 Group.THIGH_PAD, new String[] { "Thighpad.ArmorPickup" });
189
190 public static final ItemType BASE_ARMOR = MakePrototype(
191 Category.ARMOR, Group.BASE_ARMOR,
192 new String[] { "BaseArmor.ArmorPickup" });
193
194 public static final ItemType SHIELD_BELT = MakePrototype(
195 Category.ARMOR, Group.SHIELD_BELT,
196 new String[] { "ShieldBelt.ArmorPickup" });
197
198
199 public static final ItemType UDAMAGE = MakePrototype(
200 Category.OTHER, Group.UDAMAGE, new String[] {
201 "UDamage.Pickup" });
202
203 public static final ItemType JUMP_BOOTS = MakePrototype(
204 Category.OTHER, Group.JUMP_BOOTS, new String[] {
205 "JumpBoots.Pickup" });
206
207
208 public static final ItemType WEAPON_LOCKER = MakePrototype(
209 Category.OTHER, Group.OTHER, new String[] {
210 "WeaponLocker.LockerPickup" });
211
212
213 public static final ItemType NONE = MakePrototype(Category.OTHER, Group.NONE,
214 new String[] { "None", "NONE", "none" });
215
216
217
218
219
220
221
222
223
224
225
226 private String name;
227
228 public String toString() {
229 return "ItemType[name = " + name + ", category = " + category + ", group = " + group + "]";
230 }
231
232
233
234
235
236
237 private Category category;
238
239
240
241
242 private Group group;
243
244
245
246
247
248
249 public Category getCategory() {
250
251 return (category == null) ? (category = getProto().category) : category;
252 }
253
254
255
256
257
258
259 public Group getGroup() {
260
261 return (group == null) ? (group = getProto().group) : group;
262 }
263
264
265
266
267
268
269 private ItemType proto;
270
271
272
273
274
275
276 private ItemType getProto() {
277
278 if (proto != null) return proto;
279 synchronized(protos) {
280 return proto = protos.get(name);
281 }
282 }
283
284
285
286
287
288
289
290
291
292
293 @Override
294 public boolean equals(Object obj) {
295
296 if (this == obj)
297 return true;
298
299
300 if (obj instanceof ItemType) {
301
302 if (getProto() == ((ItemType) obj).getProto())
303 return true;
304 }
305
306 return false;
307 }
308
309
310
311
312
313
314 @Override
315 public int hashCode() {
316
317 return getProto().name.hashCode();
318 }
319
320
321
322
323
324
325
326
327
328 public ItemType(String name) {
329 this.name = name;
330 this.category = Category.OTHER;
331 this.group = Group.OTHER;
332 this.proto = this;
333 }
334
335
336
337
338 private ItemType(String name, Category category, Group group) {
339 this.name = name;
340 this.category = category;
341 this.group = group;
342 this.proto = this;
343 }
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358 public static ItemType MakePrototype(Category category,
359 Group group, String[] utNames) {
360 ItemType type;
361 synchronized(protos) {
362
363 type = new ItemType(utNames[0], category, group);
364
365 for (String utName : utNames)
366 protos.put(utName, type);
367
368 if (category != null) {
369 CATEGORIES.get(category).add(type);
370 }
371 if (group != null) {
372 GROUPS.get(group).add(type);
373 }
374 }
375 return type;
376 }
377
378
379
380
381
382
383 public static ItemType getItemType(String utName) {
384 ItemType type;
385 synchronized(protos) {
386 type = protos.get(utName);
387 if (type != null) return type;
388
389 type = new ItemType(utName);
390 protos.put(utName, type);
391 }
392 return type;
393 }
394
395 public String getName() {
396 return name;
397 }
398
399 }