wyvern.lib.commands
Class OfferCommand

java.lang.Object
  extended bywyvern.lib.commands.OfferCommand
All Implemented Interfaces:
BuiltInCommand, Command

public class OfferCommand
extends java.lang.Object
implements BuiltInCommand

Implements a safe-trading system. A player can "offer" an item for sale in their inventory, optionally specifying a particular player to sell it to.

Version:
1.0, Apr 26, 2003
Author:
Steve Yegge

Field Summary
static int AUCTION_FEE
           
 
Method Summary
 void addCommands(java.util.Map commands, CommandList list)
          Adds commands.
 CommandEvent createBuyEvent(CommandEvent event)
          Creates an event for buying an item from a player.
 CommandEvent createEvent(CommandEvent event)
          Implements Command.createEvent()
 CommandEvent createRescindEvent(CommandEvent event)
          Creates an event for rescinding an offer.
 boolean execute(CommandEvent ev)
          Executes the event by marking the item for sale.
 boolean executeBuyEvent(CommandEvent ev)
          Executes a purchase.
 boolean executeRescindEvent(CommandEvent ev)
          Executes a rescind.
static OfferCommand getImpl()
           
 CommandEvent getTarget(CommandEvent event)
          Looks for the thing to offer for sale.
 boolean knowsCommand(java.lang.String command)
          Built-in commands always return true, so that *someone* handles it.
static void main(java.lang.String[] args)
          Tests the regular expression for matching args.
 CommandEvent parseArgs(CommandEvent event)
          Splits up the args to the event.
static void removeOfferingProperties(GameObject obj)
          Removes the properties set by the "offer" command, including the suffix showing the price.
 CommandEvent usage(CommandEvent event)
          Vetoes the event with a Usage message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

AUCTION_FEE

public static final int AUCTION_FEE
See Also:
Constant Field Values
Method Detail

getImpl

public static OfferCommand getImpl()

addCommands

public void addCommands(java.util.Map commands,
                        CommandList list)
Adds commands.

Specified by:
addCommands in interface BuiltInCommand
Parameters:
commands - the map to add to
list - the command list we're registering in, from which we can derive the command agent (i.e. player or monster) and other information.

knowsCommand

public boolean knowsCommand(java.lang.String command)
Built-in commands always return true, so that *someone* handles it.

Specified by:
knowsCommand in interface Command
Parameters:
command - the complete original text of the command.
Returns:
true if we want to handle the command.

createEvent

public CommandEvent createEvent(CommandEvent event)
Implements Command.createEvent()

Specified by:
createEvent in interface Command
Parameters:
event - the initial, raw event
Returns:
a new event containing everything a Hook callback would need in order to modify or veto the event.

parseArgs

public CommandEvent parseArgs(CommandEvent event)
Splits up the args to the event.

Parameters:
event - the initial event
Returns:
the event, with up to 3 new properties set: - "target-obj": the description of the object - "price": the offering price - "buyer": the single player to offer it to (optional) Vetoes the event if it doesn't have well-formed arguments.

usage

public CommandEvent usage(CommandEvent event)
Vetoes the event with a Usage message.


getTarget

public CommandEvent getTarget(CommandEvent event)
Looks for the thing to offer for sale.

Parameters:
event - the original event, with args parsed into "item", "price", and optional "buyer" properties.
Returns:
If we found the target, returns a new TargetedEvent wrapping the target, containing the "price" and optional "buyer" properties. If not, returns the original event, vetoed with an appropriate failure message.

execute

public boolean execute(CommandEvent ev)
Executes the event by marking the item for sale.

Specified by:
execute in interface Command
Parameters:
ev - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.

createRescindEvent

public CommandEvent createRescindEvent(CommandEvent event)
Creates an event for rescinding an offer.


executeRescindEvent

public boolean executeRescindEvent(CommandEvent ev)
Executes a rescind.


removeOfferingProperties

public static void removeOfferingProperties(GameObject obj)
Removes the properties set by the "offer" command, including the suffix showing the price. Called when rescinding an offer, and when someone buys the item successfully.

Parameters:
obj - an offered object for which to remove the properties
Returns:
the object, with "offer-price", "offered-by", etc. removed. The object is invalidated.

createBuyEvent

public CommandEvent createBuyEvent(CommandEvent event)
Creates an event for buying an item from a player.

Parameters:
event - the original event encapsulating the command
Returns:
an event containing "seller" and "item" properties, or else an event vetoed with an appropriate message.

executeBuyEvent

public boolean executeBuyEvent(CommandEvent ev)
Executes a purchase.

Parameters:
ev - a TargetedEvent created by createBuyEvent()
Returns:
true if successful

main

public static void main(java.lang.String[] args)
Tests the regular expression for matching args.