Class MerchantBehaviour

Direct Known Subclasses:
BuyerBehaviour, OutfitChangerBehaviour, SellerBehaviour

public abstract class MerchantBehaviour extends TransactionBehaviour
Represents the behaviour of a NPC who is able to either sell items to a player, or buy items from a player.
  • Field Details

  • Constructor Details

    • MerchantBehaviour

      public MerchantBehaviour()
    • MerchantBehaviour

      public MerchantBehaviour(Map<String,Integer> priceList)
    • MerchantBehaviour

      public MerchantBehaviour(Map<String,Integer> priceList, Float priceFactor)
      Creates a new MerchantBehaviour with price list & price factor.
      Parameters:
      priceList - List of item names and their prices.
      priceFactor - Skews prices of all items for this merchant.
  • Method Details

    • dealtItems

      public Set<String> dealtItems()
      Returns a set of the names of all items that the NPC deals with.
      Returns:
      The dealt items.
    • hasItem

      public boolean hasItem(String item)
      Checks whether the NPC deals with the specified item.
      Parameters:
      item - The name of the item.
      Returns:
      true if the NPC deals with the item.
    • getUnitPrice

      public int getUnitPrice(String item)
      Returns the price of one unit of a given item.
      Parameters:
      item - the name of the item
      Returns:
      the unit price
    • getCharge

      public int getCharge(ItemParserResult res, Player player)
      Returns the price of the desired amount of the chosen item.
      Parameters:
      res -
      player - The player who considers buying/selling
      Returns:
      The price; 0 if no item was chosen or if the amount is 0.
    • addConditions

      public void addConditions(SpeakerNPC merchant, Map<String,ChatCondition> conditions)
      Adds a list of items that are dealt only if a condition is met.
      Parameters:
      merchant - SpeakerNPC that is the merchant.
      conditions - List of conditions to check item availability against.
    • getItemNames

      public Set<String> getItemNames()
      Overrides:
      getItemNames in class ItemParser
      Returns:
      the recognized item names