1 package nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon;
2
3 import nl.tudelft.pogamut.ut2004.agent.module.shooting.AbstractWeaponShooting;
4 import nl.tudelft.pogamut.ut2004.agent.module.shooting.util.FacingUtil;
5 import cz.cuni.amis.pogamut.base3d.worldview.object.ILocated;
6 import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
7 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
8 import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
9 import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
10 import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
11 import cz.cuni.amis.pogamut.ut2004.communication.messages.ItemType;
12 import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
13
14 public class AssaultRifleShooting extends AbstractWeaponShooting {
15
16 protected static final WeaponPref ASSAULT_RIFLE_PRIMARY = new WeaponPref(ItemType.ASSAULT_RIFLE, true);
17 protected static final double ASSAULT_RIFLE_SEC_SPLASH_RADIUS = 200;
18 private static final int ASSAULT_RIFLE_SEC_SPLASH_DAMAGE = 60;
19
20 public AssaultRifleShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry) {
21 super(agent, info, shoot, weaponry);
22 }
23
24 @Override
25 protected void shoot() {
26
27
28 if (!isWeaponReady()) {
29 return;
30 }
31
32
33 if (!hasTarget() && weaponPref.isSecondary()) {
34 chargeSecondary();
35 return;
36 }
37
38 else if (!hasTarget()) {
39 shoot.stopShooting();
40 return;
41 }
42
43 boolean facing = FacingUtil.isFacing2D(info, target, FACING_ANGLE);
44 boolean close = info.getLocation().getDistance(target.getLocation()) < ASSAULT_RIFLE_SEC_SPLASH_RADIUS;
45 boolean healthy = info.getHealth() > ASSAULT_RIFLE_SEC_SPLASH_DAMAGE;
46 boolean primary = weaponPref.isPrimary();
47 boolean safe = !close || healthy || primary;
48
49 if (!(target instanceof Player)) {
50 shootTarget(target, facing, safe);
51 return;
52 }
53
54 Player player = (Player) target;
55
56 if (weaponPref.isPrimary()) {
57 shootPrimary(player, facing, safe);
58 } else {
59 shootSecondary(player, facing, safe);
60 }
61 }
62
63
64
65
66
67
68
69
70 protected void shootTarget(ILocated target, boolean facing, boolean safe) {
71 if (facing && safe) {
72 shoot.shootPrimary(target);
73 } else if (!info.isSecondaryShooting()) {
74 shoot.stopShooting();
75 }
76 }
77
78
79
80
81 protected void chargeSecondary() {
82 shoot.shootSecondary();
83 }
84
85
86
87
88
89
90
91
92 protected void shootSecondary(Player player, boolean facing, boolean safe) {
93
94
95 if (player.isVisible() && facing && safe) {
96 shoot.shootSecondaryCharged(player, 0);
97 } else {
98 chargeSecondary();
99 }
100 }
101
102
103
104
105
106
107
108
109 protected void shootPrimary(Player player, boolean facing, boolean safe) {
110 if (player.isVisible() && facing && safe) {
111 shoot.shootPrimary(target);
112 } else if (!info.isSecondaryShooting()) {
113 shoot.stopShooting();
114 }
115 }
116
117 @Override
118 protected WeaponPref getDefaultWeaponPref() {
119 return ASSAULT_RIFLE_PRIMARY;
120 }
121
122 }