39 lines
1.2 KiB
Java
39 lines
1.2 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.ZorkContainer;
|
|
|
|
import java.util.List;
|
|
|
|
import static com.github.dtschust.zork.objects.ZorkObjectTypes.CONTAINER;
|
|
|
|
public class PutAction implements Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("put");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public boolean run(ZorkGame game, List<String> arguments) {
|
|
final String what = arguments.get(1);
|
|
final String destination = arguments.get(3);
|
|
|
|
if (game.getCurrentRoom().getContainer().contains(destination)) {
|
|
ZorkContainer tempContainer = (ZorkContainer) game.get(CONTAINER, destination);
|
|
if (tempContainer.isOpen() && game.inventory.contains(what)) {
|
|
tempContainer.addItem(what);
|
|
game.inventory.remove(what);
|
|
System.out.println("Item " + what + " added to " + destination + ".");
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|