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