Class ProducerBehaviour


public class ProducerBehaviour extends TransactionBehaviour
The behaviour of an NPC who is able to produce something for a player if the player brings the required resources. Production takes time, depending on the amount of ordered products.
Author:
daniel
  • Constructor Details

    • ProducerBehaviour

      public ProducerBehaviour(String questSlot, String productionActivity, String productName, Map<String,​Integer> requiredResourcesPerItem, int productionTimePerItem)
      Creates a new ProducerBehaviour.
      Parameters:
      questSlot - the slot that is used to store the status
      productionActivity - the name of the activity, e.g. "build", "forge", "bake"
      productName - the name of the product, e.g. "plate armor". It must be a valid item name.
      requiredResourcesPerItem - a mapping which maps the name of each required resource (e.g. "iron ore") to the amount of this resource that is required for one unit of the product.
      productionTimePerItem - the number of seconds required to produce one unit of the product.
    • ProducerBehaviour

      public ProducerBehaviour(String questSlot, String productionActivity, String productName, Map<String,​Integer> requiredResourcesPerItem, int productionTimePerItem, boolean productBound)
      Creates a new ProducerBehaviour.
      Parameters:
      questSlot - the slot that is used to store the status
      productionActivity - the name of the activity, e.g. "build", "forge", "bake"
      productName - the name of the product, e.g. "plate armor". It must be a valid item name.
      requiredResourcesPerItem - a mapping which maps the name of each required resource (e.g. "iron ore") to the amount of this resource that is required for one unit of the product.
      productionTimePerItem - the number of seconds required to produce one unit of the product.
      productBound - Whether the produced item should be player bound. Use only for special one-time items.
  • Method Details

    • getQuestSlot

      public String getQuestSlot()
    • getRequiredResourcesPerItem

      protected Map<String,​Integer> getRequiredResourcesPerItem()
    • getProductionActivity

      public String getProductionActivity()
    • getProductName

      public String getProductName()
      Return item name of the product to produce.
      Returns:
      product name
    • getProductionTime

      public int getProductionTime(int amount)
    • isProductBound

      public boolean isProductBound()
      Determine whether the produced item should be player bound.
      Returns:
      true if the product should be bound.
    • getRequiredResourceNamesWithHashes

      protected String getRequiredResourceNamesWithHashes(int amount)
      Gets a nicely formulated string that describes the amounts and names of the resources that are required to produce amount units of the product, with hashes before the resource names in order to highlight them, e.g. "4 #wood, 2 #iron, and 6 #leather".
      Parameters:
      amount - The amount of products that were requested
      Returns:
      A string describing the required resources woth hashes
    • getRequiredResourceNames

      public String getRequiredResourceNames(int amount)
      Gets a nicely formulated string that describes the amounts and names of the resources that are required to produce amount units of the product
      Parameters:
      amount - The amount of products that were requested
      Returns:
      A string describing the required resources.
    • getApproximateRemainingTime

      public String getApproximateRemainingTime(Player player)
      Create a text representing a saying of approximate time until the order being produced is ready
      Parameters:
      player -
      Returns:
      A string describing the remaining time.
    • isOrderReady

      public boolean isOrderReady(Player player)
      Is the order ready for this player?
      Parameters:
      player -
      Returns:
      true if the order is ready.
    • getNumberOfProductItems

      public int getNumberOfProductItems(Player player)
      Checks how many items are being produced on this particular order
      Parameters:
      player -
      Returns:
      number of items
    • getMaximalAmount

      protected int getMaximalAmount(Player player)
      Checks how many items the NPC can offer to produce based on what the player is carrying
      Parameters:
      player -
      Returns:
      maximum number of items
    • askForResources

      public boolean askForResources(ItemParserResult res, EventRaiser npc, Player player)
      Tries to take all the resources required to produce amount units of the product from the player. If this is possible, asks the user if the order should be initiated.
      Parameters:
      res -
      npc -
      player -
      Returns:
      true if all resources can be taken
    • transactAgreedDeal

      public boolean transactAgreedDeal(ItemParserResult res, EventRaiser npc, Player player)
      Tries to take all the resources required to produce the agreed amount of the product from the player. If this is possible, initiates an order.
      Specified by:
      transactAgreedDeal in class TransactionBehaviour
      Parameters:
      npc - the involved NPC
      player - the involved player
      res - result of the Behaviour parsing
      Returns:
      true if the transaction was successful.
    • giveProduct

      public void giveProduct(EventRaiser npc, Player player)
      This method is called when the player returns to pick up the finished product. It checks if the NPC is already done with the order. If that is the case, the player is given the product. Otherwise, the NPC asks the player to come back later.
      Parameters:
      npc - The producing NPC
      player - The player who wants to fetch the product
    • getErrormessage

      public String getErrormessage(ItemParserResult res, String npcAction)
      Answer with an error message in case the request could not be fulfilled.
      Parameters:
      res -
      npcAction -
      Returns:
      error message