Skip to content

Commit a364097

Browse files
committed
Added Precision Shot weapon requirement unit test
1 parent 8daf90f commit a364097

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

core/src/main/java/com/pipai/wf/battle/action/RifleAttackAction.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,11 @@ protected void performImpl() throws IllegalActionException {
3434
Agent a = getPerformer();
3535
Agent target = getTarget();
3636
Weapon w = a.getCurrentWeapon();
37-
if (!a.getAbilities().hasAbility(SnapShotAbility.class) && a.hasUsedAP())
38-
{
37+
if (!a.getAbilities().hasAbility(SnapShotAbility.class) && a.hasUsedAP()) {
3938
throw new IllegalActionException("Cannot fire rifle after moving");
4039
}
4140
if (w.needsAmmunition() && w.currentAmmo() == 0) {
4241
throw new IllegalActionException("Not enough ammo to fire " + w.name());
43-
}
44-
if (a.hasUsedAP()) {
45-
4642
}
4743
DamageResult result = DamageCalculator.rollDamageGeneral(this, new WeaponDamageFunction(w), 0);
4844
a.setAP(0);

core/src/test/java/com/pipai/wf/test/battle/AbilityTest.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void testPrecisionShotCooldown() {
103103
GridPosition enemyPos = new GridPosition(2, 2);
104104
AgentState playerState = AgentStateFactory.newBattleAgentState(Team.PLAYER, playerPos, 3, 5, 2, 5, 65, 0);
105105
playerState.abilities.add(new PrecisionShotAbility());
106-
playerState.weapons.add(new Pistol());
106+
playerState.weapons.add(new Rifle());
107107
map.addAgent(playerState);
108108
map.addAgent(AgentStateFactory.newBattleAgentState(Team.ENEMY, enemyPos, 3, 5, 2, 5, 65, 0));
109109
BattleController battle = new BattleController(map);
@@ -132,6 +132,27 @@ public void testPrecisionShotCooldown() {
132132
}
133133
}
134134

135+
@Test
136+
public void testPrecisionShotWeaponReq() {
137+
BattleMap map = new BattleMap(3, 4);
138+
GridPosition playerPos = new GridPosition(1, 0);
139+
GridPosition enemyPos = new GridPosition(2, 2);
140+
AgentState playerState = AgentStateFactory.newBattleAgentState(Team.PLAYER, playerPos, 3, 5, 2, 5, 65, 0);
141+
playerState.abilities.add(new PrecisionShotAbility());
142+
playerState.weapons.add(new Pistol());
143+
map.addAgent(playerState);
144+
map.addAgent(AgentStateFactory.newBattleAgentState(Team.ENEMY, enemyPos, 3, 5, 2, 5, 65, 0));
145+
BattleController battle = new BattleController(map);
146+
Agent agent = map.getAgentAtPos(playerPos);
147+
Agent target = map.getAgentAtPos(enemyPos);
148+
try {
149+
battle.performAction(new PrecisionShotAction(agent, target));
150+
fail("Expected exception not thrown");
151+
} catch (IllegalActionException e) {
152+
}
153+
}
154+
155+
135156
@Test
136157
public void testNoSnapShot() {
137158
BattleMap map = new BattleMap(5, 5);

0 commit comments

Comments
 (0)