Class BuyCommand

Object
NormalCommand
BuyCommand
All Implemented Interfaces:
Command

public class BuyCommand extends NormalCommand
Buys an item from a shopkeeper. Syntax : buy [<amount>] <item> from <character>. For example "buy bucket to Karcas".
Author:
maartenl
See Also:
  • Constructor Details

    • BuyCommand

      public BuyCommand(String aRegExpr)
  • Method Details

    • run

      public DisplayInterface run(String command, User aUser) throws MudException
      Tries out the buy command. There are a couple of requirements that need to be met, before a successful sale takes place.
      1. command struct. should be "buy [<amount>] <item> from <character>", for example: "sell gold ring to Karcas".
      2. shopkeeper selling the item should
        1. exist,
        2. be in the same room and
        3. have a god==4 to indicate a "shopkeeper" and
        4. has the item for sale
      3. the customer should have the money
      4. the item itself should NOT have a attribute called "notbuyable".
      5. the item should not contain any items
      A best effort is tried, this means the following sequence of events:
      1. the item is transferred into the inventory of the user
      2. money is transferred into the inventory of the shopkeeper
      3. continue with next item
      Specified by:
      run in interface Command
      Specified by:
      run in class NormalCommand
      Parameters:
      command - the command entered.
      aUser - the character doing the buying.
      Returns:
      a simple displayinterface, in our case the room.
      Throws:
      MudException - if something goes wrong.