Exemplo n.º 1
0
 @Override
 public DisplayInterface run(String command, User aUser) throws MudException {
   for (Wielding position : Wielding.values()) {
     aUser.wield(null, position);
   }
   aUser.getRoom().sendMessageExcl(aUser, "%SNAME disarms %SHIMHERself completely.<br/>\r\n");
   aUser.writeMessage("You disarm yourself completely.<br/>\r\n");
   return aUser.getRoom();
 }
Exemplo n.º 2
0
 /**
  * Tries out the sell command. There are a couple of requirements that need to be met, before a
  * successful sale takes place.
  *
  * <ol>
  *   <li>command struct. should be "<I>sell [&lt;amount&gt;] &lt;item&gt; to
  *       &lt;character&gt;</I>", for example: "<I>sell gold ring to Karcas</I>".
  *   <li>keeper buying the item should
  *       <ol>
  *         <li>exist,
  *         <li>be in the same room and
  *         <li>have a god==4 to indicate a "keeper" and
  *         <li>has enough money
  *       </ol>
  *   <li>the customer should have the item
  *   <li>the item is not being wielded
  *   <li>the item is not being worn
  *   <li>the item itself should <I>NOT</I> have a attribute called "notsellable".
  *   <li>the item should not contain any items
  * </ol>
  *
  * A best effort is tried, this means the following sequence of events:
  *
  * <ol>
  *   <li>the item is transferred into the inventory of the keeper
  *   <li>money is transferred into the inventory of the customer
  *   <li>continue with next item
  * </ol>
  *
  * @param command the command entered.
  * @param aUser the character doing the selling.
  * @return a simple displayinterface, in our case the room.
  */
 @Override
 public DisplayInterface run(String command, User aUser) throws MudException {
   List<String> parsed = new ArrayList<>(Arrays.asList(parseCommand(command)));
   parsed.remove(0); // remove "sell"
   String shopkeeperName = parsed.get(parsed.size() - 1);
   parsed.remove(parsed.size() - 1); // remove shopkeeper
   parsed.remove(parsed.size() - 1); // remove "to"
   int amount = 1;
   try {
     amount = Integer.parseInt(parsed.get(0));
     parsed.remove(0);
   } catch (NumberFormatException e) { // do nothing here, we assume we need to drop only one item.
   }
   if (amount <= 0) {
     aUser.writeMessage("That is an illegal amount.<br/>\n");
     return aUser.getRoom();
   }
   // find the item on ourselves
   List<Item> itemsFound = aUser.findItems(parsed);
   if (itemsFound.isEmpty()) {
     aUser.writeMessage("You don't have that.<br/>\n");
     return aUser.getRoom();
   }
   if (itemsFound.size() < amount) {
     aUser.writeMessage("You do not have that many items in your inventory.<br/>\r\n");
     return aUser.getRoom();
   }
   Person keeper = aUser.getRoom().getPerson(shopkeeperName);
   if (keeper == null) {
     aUser.writeMessage("Unable to locate shopkeeper.<br/>\r\n");
     return aUser.getRoom();
   }
   if (keeper.getGod() != God.SHOPKEEPER) {
     aUser.writeMessage("That's not a shopkeeper!<br/>\r\n");
     return aUser.getRoom();
   }
   Shopkeeper shopkeeper = (Shopkeeper) keeper;
   boolean sold = false;
   ItemBean itemBean = getItemBean();
   for (Item item : itemsFound) {
     // item is not used.
     if (item.getCopper() <= 1) {
       String message = "That item is not worth anything.";
       aUser
           .getRoom()
           .sendMessage(
               shopkeeper, aUser, "%SNAME say%VERB2 [to %TNAME] : " + message + "<br/>\r\n");
       continue;
     }
     if (shopkeeper.getCopper() < item.getCopper()) {
       aUser.writeMessage(
           shopkeeper.getName() + " mutters something about not having enough money.<br/>\r\n");
       break;
     }
     if (!aUser.unused(item)) {
       aUser.writeMessage("You are wearing or wielding this item.<BR>\r\n");
       continue;
     }
     if (!item.isSellable()) {
       aUser.writeMessage("You cannot sell that item.<BR>\r\n");
       continue;
     }
     Integer moneyPaid = itemBean.sell(item, aUser, shopkeeper);
     if (moneyPaid == null) {
       continue;
     }
     aUser
         .getRoom()
         .sendMessage(
             aUser,
             "%SNAME sold%VERB2 "
                 + item.getDescription()
                 + " to "
                 + shopkeeper.getName()
                 + " for "
                 + Constants.getDescriptionOfMoney(moneyPaid)
                 + ".<br/>\r\n");
     sold = true;
     amount--;
     if (amount == 0) {
       return aUser.getRoom();
     }
   }
   if (!sold) {
     aUser.writeMessage("You did not sell anything.<br/>\r\n");
   } else {
     aUser.writeMessage("You sold some of the items.<br/>\r\n");
   }
   return aUser.getRoom();
 }