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 BioRifleShooting extends AbstractWeaponShooting {
15
16 protected static final WeaponPref BIO_RIFLE_PRIMARY = new WeaponPref(ItemType.BIO_RIFLE, true);
17 protected static final double BIO_RIFLE_SPLASH_RADIUS = 200;
18 private static final int BIO_RIFLE_SPLASH_DAMAGE = 75;
19
20 public BioRifleShooting(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()) < BIO_RIFLE_SPLASH_RADIUS;
45 boolean healthy = info.getHealth() > BIO_RIFLE_SPLASH_DAMAGE;
46 boolean safe = !close || healthy;
47
48 if (!(target instanceof Player)) {
49 shootTarget(target, facing, safe);
50 return;
51 }
52
53 Player player = (Player) target;
54
55 if (weaponPref.isPrimary()) {
56 shootPrimary(player, facing, safe);
57 } else {
58 shootSecondary(player, facing, safe);
59 }
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.shootPrimary(player);
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 BIO_RIFLE_PRIMARY;
120 }
121
122
123 }