Package games.stendhal.server.entity.trade

Examples of games.stendhal.server.entity.trade.Offer


public class OfferTransformer implements Transformer {

 
  public RPObject transform(RPObject object) {
    return new Offer(object);
  }
View Full Code Here


        if (offerMap == null) {
          npc.say("Please check your offers first.");
          return;
        }
        if(offerMap.containsKey(offerNumber)) {
          Offer o = offerMap.get(offerNumber);
          if(o.getOfferer().equals(player.getName())) {
            setOffer(o);
            int quantity = 1;
            if (o.hasItem()) {
              quantity = getQuantity(o.getItem());
            }
            StringBuilder message = new StringBuilder();
           
            if (TradeCenterZoneConfigurator.getShopFromZone(player.getZone()).contains(o)) {
              message.append("Your offer of ");
              message.append(Grammar.quantityplnoun(quantity, o.getItemName(), "one"));
              message.append(" would expire in ");
              message.append(TimeUtil.approxTimeUntil((int) ((o.getTimestamp() - System.currentTimeMillis() + 1000 * OfferExpirer.TIME_TO_EXPIRING) / 1000)));
              message.append(". Do you want to prolong it to last for ");
              message.append(TimeUtil.timeUntil(OfferExpirer.TIME_TO_EXPIRING));
              message.append(" for ");
              message.append(TradingUtility.calculateFee(player, o.getPrice()).intValue());
              message.append(" money?");
            } else {
              message.append("Do you want to prolong your offer of ");
              message.append(Grammar.quantityplnoun(quantity, o.getItemName(), "one"));
              message.append(" at a price of ");
              message.append(o.getPrice());
              message.append(" for a fee of ");
              message.append(TradingUtility.calculateFee(player, o.getPrice()).intValue());
              message.append(" money?");
            }
            npc.say(message.toString());
            npc.setCurrentState(ConversationStates.SERVICE_OFFERED);
          } else {
View Full Code Here

    }
  }
 
  protected class ConfirmProlongOfferChatAction implements ChatAction {
    public void fire (Player player, Sentence sentence, EventRaiser npc) {
      Offer offer = getOffer();
      if (!wouldOverflowMaxOffers(player, offer)) {
        Integer fee = Integer.valueOf(TradingUtility.calculateFee(player, offer.getPrice()).intValue());
        if (player.isEquipped("money", fee)) {
          if (prolongOffer(player, offer)) {
            TradingUtility.substractTradingFee(player, offer.getPrice());
            npc.say("I prolonged your offer and took the fee of "+fee.toString()+" again.");
          } else {
            npc.say("Sorry, that offer has already been removed from the market.");
          }
          // Changed the status, or it has been changed by expiration. Obsolete the offers
View Full Code Here

      if (offerMap == null) {
        npc.say("Please take a look at the list of offers first.");
        return;
      }
      if(offerMap.containsKey(offerNumber)) {
        Offer o = offerMap.get(offerNumber);
        if (o.hasItem()) {
          player.sendPrivateText(o.getItem().describe());
          showImage(player, o.getItem());
          return;
        }
      }
      npc.say("Sorry, please choose a number from those I told you.");
    } catch (NumberFormatException e) {
View Full Code Here

   * @param word a word to check in item name or type
   */
  private void filterForWord(List<Offer> offers, String word) {
    Iterator<Offer> it = offers.iterator();
    while (it.hasNext()) {
      Offer o = it.next();
      if (o.hasItem()) {
        Item item = o.getItem();
        if (!(item.getName().indexOf(word) != -1 || word.equals(item.getItemClass()))) {
          it.remove();
        }
      }
    }
View Full Code Here

     * @return true if making the offer was successful, false otherwise
     */
    private boolean createOffer(Player player, Item item, int price, int number) {
      Market shop = TradeCenterZoneConfigurator.getShopFromZone(player.getZone());
      if(shop != null) {
        Offer o = shop.createOffer(player, item, Integer.valueOf(price), Integer.valueOf(number));
        if (o == null) {
          return false;
        }

        StringBuilder message = new StringBuilder("Offer for some ");
View Full Code Here

        if (offerMap == null) {
          npc.say("Please take a look at the list of offers first.");
          return;
        }
        if(offerMap.containsKey(offerNumber)) {
          Offer o = offerMap.get(offerNumber);
          if (o.hasItem()) {
            setOffer(o);
            int quantity = getQuantity(o.getItem());
            npc.say("Do you want to buy " + Grammar.quantityplnoun(quantity, o.getItem().getName(), "a") + " for " + o.getPrice() + " money?");
            npc.setCurrentState(ConversationStates.BUY_PRICE_OFFERED);
            return;
          }
        }
        npc.say("Sorry, please choose a number from those I told you to accept an offer.");
View Full Code Here

    }
  }

  class ConfirmAcceptOfferChatAction implements ChatAction {
    public void fire (Player player, Sentence sentence, EventRaiser npc) {
      Offer offer = getOffer();
      Market m = TradeCenterZoneConfigurator.getShopFromZone(player.getZone());
      String itemname = offer.getItemName();
      if (m.acceptOffer(offer,player)) {
        // Successful trade. Tell the offerer
        StringBuilder earningToFetchMessage = new StringBuilder();
        earningToFetchMessage.append("Your ");
        earningToFetchMessage.append(itemname);
        earningToFetchMessage.append(" was sold. You can now fetch your earnings from me.");

        logger.debug("sending a notice to '" + offer.getOfferer() + "': " + earningToFetchMessage.toString());
        DBCommandQueue.get().enqueue(new StoreMessageCommand("Harold", offer.getOfferer(), earningToFetchMessage.toString(), "N"));

        npc.say("Thanks.");
        // Obsolete the offers, since the list has changed
        ((MarketManagerNPC) npc.getEntity()).getOfferMap().clear();
      } else {
        // Trade failed for some reason. Check why, and inform the player
        if (!m.contains(offer)) {
          int quantity = getQuantity(offer.getItem());
          npc.say("I'm sorry, but " + Grammar.thatthose(quantity) + " "
              + Grammar.quantityplnoun(quantity, offer.getItem().getName(), "the")
              + " " + Grammar.isare(quantity)
              + " no longer for sale.");
        } else {
          npc.say("Sorry, you don't have enough money!");
        }
View Full Code Here

      ((MarketManagerNPC) npc.getEntity()).getOfferMap().clear();
    }
  }
 
  private void removeOffer(Player player, EventRaiser npc) {
    Offer offer = getOffer();
    Market m = TradeCenterZoneConfigurator.getShopFromZone(player.getZone());
    m.removeOffer(offer,player);
    npc.say("Ok.");
  }
View Full Code Here

        if (offerMap.isEmpty()) {
          npc.say("Please check your offers first.");
          return;
        }
        if(offerMap.containsKey(offerNumber)) {
          Offer o = offerMap.get(offerNumber);
          if(o.getOfferer().equals(player.getName())) {
            setOffer(o);
            // Ask for confirmation only if the offer is still active
            if (TradeCenterZoneConfigurator.getShopFromZone(player.getZone()).contains(o)) {
              int quantity = 1;
              if (o.hasItem()) {
                quantity = getQuantity(o.getItem());
              }
              npc.say("Do you want to remove your offer of " + Grammar.quantityplnoun(quantity, o.getItemName(), "one") + "?");
              npc.setCurrentState(ConversationStates.QUESTION_1);
            } else {
              removeOffer(player, npc);
              // Changed the status, or it has been changed by expiration. Obsolete the offers
              ((MarketManagerNPC) npc.getEntity()).getOfferMap().clear();
View Full Code Here

TOP

Related Classes of games.stendhal.server.entity.trade.Offer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.