View Javadoc

1   package nl.tudelft.pogamut.ut2004.agent.module.shooting.weapon;
2   
3   import java.util.concurrent.TimeUnit;
4   
5   import nl.tudelft.pogamut.unreal.agent.module.shooting.AbstractWeaponShooting;
6   import nl.tudelft.pogamut.unreal.agent.module.shooting.util.FacingUtil;
7   import cz.cuni.amis.pogamut.ut2004.agent.module.sensomotoric.Weaponry;
8   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.AgentInfo;
9   import cz.cuni.amis.pogamut.ut2004.agent.module.sensor.WeaponPref;
10  import cz.cuni.amis.pogamut.ut2004.bot.command.ImprovedShooting;
11  import cz.cuni.amis.pogamut.ut2004.bot.impl.UT2004Bot;
12  import cz.cuni.amis.pogamut.ut2004.communication.messages.UT2004ItemType;
13  import cz.cuni.amis.pogamut.ut2004.communication.messages.gbinfomessages.Player;
14  import cz.cuni.amis.utils.Heatup;
15  
16  /**
17   * 
18   * <p>
19   * Module to work efficiently with the Ion Painter.
20   * </p>
21   * 
22   * <p>
23   * </p>
24   * 
25   * @author mpkorstanje
26   * 
27   */
28  public class IonPainterShooting extends AbstractWeaponShooting {
29  
30  	protected static final WeaponPref DEFAULT_WEAPON_PREF = new WeaponPref(UT2004ItemType.ION_PAINTER, false);
31  
32  	public IonPainterShooting(UT2004Bot<?, ?, ?> agent, AgentInfo info, ImprovedShooting shoot, Weaponry weaponry) {
33  		super(agent, info, shoot, weaponry);
34  	}
35  
36  	protected static int ION_PAINTER_CHARGE_TIME = 3;
37  	
38  	private Heatup chargeTime = new Heatup(ION_PAINTER_CHARGE_TIME, TimeUnit.SECONDS);
39  
40  	@Override
41  	protected void shoot() {
42  
43  		// Wrong weapon, wait up.
44  		if (!isWeaponReady()) {
45  			return;
46  		}
47  
48  		// No target, no shoot.
49  		if (!hasTarget()) {
50  			shoot.stopShooting();
51  			return;
52  		}
53   
54  		if (chargeTime.isHot()) {
55  			return;
56  		}
57  
58  		if (!(target instanceof Player)) {
59  			shoot.shootPrimaryCharged(target, ION_PAINTER_CHARGE_TIME);
60  			chargeTime.heat();
61  			return;
62  		}
63  
64  		Player player = (Player) target;
65  
66  		// Target not visible, hold fire.
67  		if (!player.isVisible() || !FacingUtil.isFacing2D(info, player, FACING_ANGLE)) {
68  			return;
69  		}
70  		
71  		shoot.shootPrimaryCharged(player, ION_PAINTER_CHARGE_TIME);
72  		chargeTime.heat();
73  
74  	}
75  
76  	@Override
77  	protected WeaponPref getDefaultWeaponPref() {
78  		return DEFAULT_WEAPON_PREF;
79  	}
80  
81  }