1 package cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric;
2
3 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
4 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType.Category;
5 import cz.cuni.amis.pogamut.unreal.communication.messages.UnrealId;
6 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbcommands.ChangeWeapon;
7 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.AddInventoryMsg;
8 import cz.cuni.amis.pogamut.ut2004.communication.translator.itemdescriptor.WeaponDescriptor;
9 import cz.cuni.amis.utils.exception.PogamutException;
10
11
12
13
14
15
16
17
18
19 public class Weapon {
20
21 protected ItemType weaponType = null;
22 protected int primaryAmmo = 0;
23 protected int secondaryAmmo = 0;
24 protected UnrealId inventoryId;
25 protected WeaponDescriptor descriptor = null;
26
27 protected Weapon(AddInventoryMsg weaponGained, int primaryAmmo, int secondaryAmmo) {
28 if (weaponGained.getPickupType().getCategory() != Category.WEAPON) {
29 throw new PogamutException("Could not create Weapon class out of inventory item that is not a weapon.", this);
30 }
31 this.weaponType = weaponGained.getPickupType();
32 this.inventoryId = weaponGained.getId();
33 this.descriptor = (WeaponDescriptor) weaponGained.getDescriptor();
34 this.primaryAmmo = primaryAmmo;
35 this.secondaryAmmo = secondaryAmmo;
36 }
37
38
39
40
41
42 public ItemType getType() {
43 return weaponType;
44 }
45
46
47
48
49
50 public ItemType.Group getGroup() {
51 return weaponType.getGroup();
52 }
53
54
55
56
57
58 public int getPrimaryAmmo() {
59 return primaryAmmo;
60 }
61
62
63
64
65
66 public int getSecondaryAmmo() {
67 return secondaryAmmo;
68 }
69
70
71
72
73
74
75
76
77
78 public UnrealId getInventoryId() {
79 return inventoryId;
80 }
81
82
83
84
85 public WeaponDescriptor getDescriptor() {
86 return descriptor;
87 }
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102 public boolean hasSecondaryAmmoType() {
103 return getDescriptor().getSecAmmoItemType() != null && getDescriptor().getPriAmmoItemType() != getDescriptor().getSecAmmoItemType();
104 }
105
106
107
108
109
110 public int getAmmo() {
111 return getPrimaryAmmo() + getSecondaryAmmo();
112 }
113
114 @Override
115 public String toString() {
116 if (getType() == null) {
117 return "Weapon[type=UNKNOWN, primary ammo=" + getPrimaryAmmo() + ", secondary ammo=" + getSecondaryAmmo() + "]";
118 } else
119 if (hasSecondaryAmmoType()) {
120 return "Weapon[type=" + getType().getName() + ", primary ammo=" + getPrimaryAmmo() + ", secondary ammo=" + getSecondaryAmmo() + "]";
121 } else {
122 return "Weapon[type=" + getType().getName() + ", ammo=" + getPrimaryAmmo() + "]";
123 }
124 }
125
126 }