1 package cz.cuni.amis.pogamut.ut2004.communication.messages; 2 3 import java.io.Serializable; 4 import java.util.HashMap; 5 import java.util.Set; 6 7 import static cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType.CATEGORIES; 8 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Group; 9 import cz.cuni.amis.utils.maps.HashMapSet; 10 11 /** 12 * Abastract Type of the item. 13 * 14 * <p> 15 * Note: Items of the same type might have different names in UT engine. 16 * <b>Always use {@link #equals(Object)} to safely compare two ItemTypes.</b> 17 * 18 * <p> 19 * Use {@link #getCategory()} to obtain basic categorization of items. 20 * 21 * <p> 22 * Use {@link #getGroup()} to obtain detailed group info of items. 23 * 24 * <p> 25 * {@link Comparable} according to {@link ItemType#getName()}. 26 * 27 * @author Juraj 'Loque' Simlovic 28 * @author Jimmy 29 */ 30 public abstract class ItemType implements Serializable, Comparable<ItemType> { 31 public abstract interface Group { 32 public Set<ItemType> getTypes(); 33 /** 34 * @return human readable representation of name. 35 */ 36 public String getName(); 37 38 /** 39 * @return enum representation of name 40 */ 41 public String name(); 42 } 43 44 /** 45 * Contains item types that belongs to their categories. 46 */ 47 public static final HashMapSet<Category, ItemType> CATEGORIES = new HashMapSet<Category, ItemType>(); 48 49 public enum Category { 50 /** Weapons of all sorts. */ 51 WEAPON("Weapon"), 52 /** Ammunition for weapons of all sorts. */ 53 AMMO("Ammo"), 54 /** Projectiles for weapons of all sorts */ 55 PROJECTILE("Projectile"), 56 /** Health packs and other health restorers. */ 57 HEALTH("Health"), 58 /** Armor packs and other armor restorers. */ 59 ARMOR("Armor"), 60 /** Shield packs and other shield restorers. */ 61 SHIELD("Shield"), 62 /** Adrenaline */ 63 ADRENALINE("Adrenaline"), 64 /** Deployable weapons like slowfields, minefields, etc. */ 65 DEPLOYABLE("Deployable"), 66 /** UDamage, Keys + user defined items */ 67 OTHER("Other"), 68 /** No category */ 69 NONE("No category"); 70 71 /* =================================================================== */ 72 73 /** Human-readable name of the category. */ 74 public final String name; 75 76 /* =================================================================== */ 77 78 /** 79 * Constructor. 80 * 81 * @param name 82 * Human-readable name of the category. 83 */ 84 Category(String name) { 85 this.name = name; 86 } 87 88 /** 89 * Return all item types of a certain category. 90 * 91 * @return 92 */ 93 public Set<ItemType> getTypes() { 94 return CATEGORIES.get(this); 95 } 96 } 97 98 99 100 public abstract String toString(); 101 102 /** 103 * Retrieves category of the item type. 104 * 105 * @return String representing the category of the item. 106 */ 107 public abstract Category getCategory(); 108 109 /** 110 * Retrieves group of the item type. 111 * 112 * @return String representing the group of the item. 113 */ 114 public abstract Group getGroup(); 115 116 /** 117 * Indicates whether some other ItemType is "equal to" this one. 118 * 119 * @param obj 120 * Object to be compared with. 121 * @return True, if the objects are equal. 122 */ 123 public abstract boolean equals(Object obj); 124 125 /** 126 * Returns a hash code value for the object. 127 * 128 * @return A hash code value for this object. 129 */ 130 public abstract int hashCode(); 131 132 public abstract String getName(); 133 134 135 136 }