package bvyy.command;
// Copyright(C)1998 Brian Yap
// This program is free software; you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2 of the License, or (at your
// option) any later version.
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the Free Software Foundation, Inc., 675 Mass
// Ave, Cambridge, MA 02139, USA.
import bvyy.database.*;
import java.util.*;
/**
* The Assemble command attempts to create a new object out of the component
* objects.
*
* @see bvyy.command.Disassemble
*
* @version 0.0.1 27 October 1998
* @author (c)1998 Brian Voon Yee Yap
*/
public class Assemble extends Operate {
/**
* Creates a new Assemble command.
*/
public Assemble() {
super();
}
/**
* Creates a new Assemble command with a description of S.
*
* @param s the event description.
*/
public Assemble(String S) {
super(S);
}
/**
* Executes this command.
*
* This command:
*
* - Determines if there is such a category object exists. A No-Such-
* Category-Exception is thrown if the category does not exist.
* - Determines if the components are sufficient to create the object. If
* they are not, it will return a Command-Completely-Failed-Exception.
* The object will not have been created.
* - Determines if the capabilities are sufficient to create the object.
* If they are not, it will return a Command-Completely-Failed-
* Exception. The object will not have been created.
* - Determines if the tools are sufficient to create the object. If
* they are not, it will return a Command-Completely-Failed-Exception.
* The object will not have been created.
* - Determines if the components are sufficient to create the object. If
* they are not, it will return a Command-Completely-Failed-Exception.
* The object will not have been created.
* - Assemble the objects out of the supplied components using both
* mandatory and optional components. In this processing any surplus
* objects will be ignored.
*
* Arguments:
*
* - Category - The object template of the object to be
* assembled.
* - String - The name to be assigned to the object being created.
* If this string is null then the default name suplied
* in the category will be used.
* - Vector - A set of 0 to N component things that are to be used
* to create the new thing. Any components requried
* (mandatory or optional) are consumed. Any surplus
* components are not consumed.
* - Vector - A set of 0 to N tools that are to be used to
* create the new thing. Any tools marked as being consumed
* will be destroyed by the construction process. The
* lifetime cycle of the tool will be incremented as
* required.
* - Vector - A set of 0 to N capabilities that are to be used to
* create the new thing. Any temporary or permanent
* reductions or increases in the performance of the skills
* will be processed.
* - Vector - A set of 0 to N characteristics that are to be used to
* create the new thing. Any temporary or permanent
* reductions or increases will be processed.
* - Thing - The location where the thing is to be created.
*
*/
public void execute(Hashtable theArguments)
throws CommandCompletelyFailedException,
CommandPartlyFailedException,
NoSuchCategoryException {
private Category theCategory;
private Thing theThing = null;
private GameThing gameThing = new GameThing();
System.out.println("Command: Assemble: Execute");
if (!(theArguments.contains("Category")) then {
throw CommandCompletelyFailedException("No category supplied.");
}
if (!(theArguments.contains("Location")) then {
throw CommandCompletelyFailedException("No location supplied.");
}
//grab a data base lock
// Start The creation process
theCategory = theArguments.get("Category");
if (gameThing.getCategoryIndex.getFlatCategoryList.contains(theArguments.get("Category").getName())) {
try (theThing = theCategory.buildThing(theArguments.get("Components"),
theArguments.get("Tools"),
theArguments.get("Capabilities"),
theArguments.get("Characteristics"),
theArguments.get("Location") )
catch (ContructionFailedExcpetion) {
throw CommandCompeletelyFailedException = new CommandCompeletelyFailedException(ContructionFailedExcpetion.getMessage());
};
};
} else {
throw NoSuchCategoryException = new NoSuchCategoryException("Not a registered category. Category is: "
+ theArguments.get("Category").getName())
+ ".");
};
}