41 lines
1.3 KiB
Java
41 lines
1.3 KiB
Java
package com.github.dtschust.zork.repl.actions;
|
|
|
|
import com.github.dtschust.zork.ZorkGame;
|
|
import com.github.dtschust.zork.repl.Action;
|
|
import com.github.dtschust.zork.objects.ZorkCreature;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.github.dtschust.zork.objects.ZorkObjectTypes.CREATURE;
|
|
|
|
/**
|
|
* Attempt an attack, do you feel lucky?
|
|
*/
|
|
public class AttackAction implements Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("attack");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public boolean run(ZorkGame game, List<String> arguments) {
|
|
final String tempString = arguments.get(1);
|
|
final String weapon = arguments.get(3);
|
|
|
|
if (game.getCurrentRoom().getCreature().contains(tempString)) {
|
|
ZorkCreature tempCreature = (ZorkCreature) game.get(CREATURE, tempString);
|
|
if (tempCreature != null && game.inventory.contains(weapon) && tempCreature.isAttackSuccessful(game, weapon)) {
|
|
System.out.println("You assault the " + tempString + " with the " + weapon + ".");
|
|
tempCreature.printAndExecuteActions(game);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|