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.types.HasSetOfCollectable; import com.github.dtschust.zork.objects.ZorkObjectTypes; import com.github.dtschust.zork.objects.ZorkObject; 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 arguments) { return arguments.get(0).equals("Add"); } @Override public int getMinimumArgCount() { return 4; } @Override public boolean run(ZorkGame game, List arguments) { final String object = arguments.get(1); final String destination = arguments.get(3); try { ZorkObjectTypes destType = game.getTypeFromLookup(destination); ZorkObjectTypes objType = game.getTypeFromLookup(object); ZorkObject tempObject = game.get(destType, destination); ((HasSetOfCollectable) tempObject).getSetFromType(objType).add(object); game.put(destType, tempObject); } catch (Exception e) { return false; } return true; } }