Class ExampleCommand1

java.lang.Object
  extended bycom.swath.UserDefinedCommand
      extended byExampleCommand1
All Implemented Interfaces:
CommandIfc

public class ExampleCommand1
extends UserDefinedCommand

This is my first SWATH command. It does simple trading at the port in the current sector.

Since:
SWATH 1.7
See Also:
Trade

Field Summary
 
Fields inherited from class com.swath.UserDefinedCommand
RETURN_KEY
 
Constructor Summary
ExampleCommand1()
           
 
Method Summary
 void endCommand(boolean finished)
          Called by the framework when the command is finished.
static int exec(int fuel, int organics, int equipment)
          Simple trading at the port in the current sector.
 java.lang.String getName()
          Called by the framework to get the name of the command.
 boolean initCommand()
          Called by the framework to initialise the command.
 void onEvent(EventIfc event)
          This method is called for each posted event.
 void onText(java.lang.String buffer, java.lang.String text)
          This method is called when new text has arrived from the game server.
 void startCommand()
          Called by the framework to start executing the command.
 
Methods inherited from class com.swath.UserDefinedCommand
atPrompt, execInstance, getClassName, getParams, getResource, initInstance, isInternal, isUserDefined, postEvent, printTrace, printTrace, registerParam, sendString, setBufferText, setResult, skipBufferText
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExampleCommand1

public ExampleCommand1()
Method Detail

getName

public java.lang.String getName()
Description copied from class: UserDefinedCommand
Called by the framework to get the name of the command.
You should override this method.

Specified by:
getName in interface CommandIfc
Overrides:
getName in class UserDefinedCommand
Returns:
The command name.

initCommand

public boolean initCommand()
                    throws java.lang.Exception
Description copied from class: UserDefinedCommand
Called by the framework to initialise the command.
You should override this method to make your own initialisation.

Overrides:
initCommand in class UserDefinedCommand
Returns:
true if the initialisation was successful, otherwise false.
Throws:
java.lang.Exception
See Also:
UserDefinedCommand.atPrompt(int), UserDefinedCommand.printTrace(java.lang.String), UserDefinedCommand.setResult(java.lang.Object)

startCommand

public void startCommand()
                  throws java.lang.Exception
Description copied from class: UserDefinedCommand
Called by the framework to start executing the command.
You should override this method.

Normally you send some text to the TW server and then handle all incoming text and events using the methods onText and onEvent.

Overrides:
startCommand in class UserDefinedCommand
Throws:
java.lang.Exception
See Also:
UserDefinedCommand.sendString(java.lang.String), UserDefinedCommand.postEvent(com.swath.UserDefinedEvent), UserDefinedCommand.printTrace(java.lang.String), UserDefinedCommand.setResult(java.lang.Object), UserDefinedCommand.onText(java.lang.String, java.lang.String), UserDefinedCommand.onEvent(com.swath.EventIfc)

endCommand

public void endCommand(boolean finished)
                throws java.lang.Exception
Description copied from class: UserDefinedCommand
Called by the framework when the command is finished.
You can override this method to clean up after the command if needed.

Overrides:
endCommand in class UserDefinedCommand
Parameters:
finished - true if the command finished correctly or false if the command was interrupted in some way.
Throws:
java.lang.Exception

onText

public void onText(java.lang.String buffer,
                   java.lang.String text)
            throws java.lang.Exception
Description copied from class: UserDefinedCommand
This method is called when new text has arrived from the game server.
You can override this method to scan for incoming text.

The current text buffer contains both the previous text and the new text that just arrived. You can use it when searching for information using the string helper methods. To remove text from the current buffer or reset its content, use the skipBufferText and setBufferText methods.

Overrides:
onText in class UserDefinedCommand
Parameters:
buffer - The current text buffer.
text - The new incoming text.
Throws:
java.lang.Exception
See Also:
UserDefinedCommand.skipBufferText(int), UserDefinedCommand.setBufferText(java.lang.String), UserDefinedCommand.sendString(java.lang.String), UserDefinedCommand.postEvent(com.swath.UserDefinedEvent), UserDefinedCommand.printTrace(java.lang.String), UserDefinedCommand.setResult(java.lang.Object)

onEvent

public void onEvent(EventIfc event)
             throws java.lang.Exception
Description copied from class: UserDefinedCommand
This method is called for each posted event.
You can override this method to handle events.

Overrides:
onEvent in class UserDefinedCommand
Parameters:
event - The event.
Throws:
java.lang.Exception
See Also:
UserDefinedCommand.sendString(java.lang.String), UserDefinedCommand.postEvent(com.swath.UserDefinedEvent), UserDefinedCommand.printTrace(java.lang.String), UserDefinedCommand.setResult(java.lang.Object)

exec

public static int exec(int fuel,
                       int organics,
                       int equipment)
                throws java.lang.Exception
Simple trading at the port in the current sector. Positive amount of product means buying and negative amount means selling.

Parameters:
fuel - The amount of Fuel Ore to buy/sell.
organics - The amount of Organics to buy/sell.
equipment - The amount of Equipment to buy/sell.
Returns:
The total amount of credits spent.
Throws:
java.lang.Exception