38 lines
1.0 KiB
Java
38 lines
1.0 KiB
Java
package com.github.dtschust.zork.repl.actions;
|
|
|
|
import com.github.dtschust.zork.ZorkGame;
|
|
import com.github.dtschust.zork.repl.Action;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
* Add: figure out what type the destination is, then what type the object is. Then add object to destination if it makes sense
|
|
*/
|
|
public class AddAction implements Action {
|
|
@Override
|
|
public boolean matchesInput(List<String> arguments) {
|
|
return arguments.get(0).equals("Add");
|
|
}
|
|
|
|
@Override
|
|
public int getMinimumArgCount() {
|
|
return 4;
|
|
}
|
|
|
|
@Override
|
|
public boolean run(ZorkGame game, List<String> arguments) {
|
|
final String objectName = arguments.get(1);
|
|
final String destination = arguments.get(3);
|
|
|
|
try {
|
|
return game.getObject(objectName).map(o -> {
|
|
game.addObjectToCollection(o, destination);
|
|
return true;
|
|
}).orElse(false);
|
|
} catch (final UnsupportedOperationException ignored) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|