Class MultiProducerBehaviour


public class MultiProducerBehaviour extends TransactionBehaviour
The behaviour of an NPC who is able to produce one or more things for a player, given that the player brings the necessary resources. Production takes time, depending on the amount of the product requested.
Author:
omero
  • Constructor Details

    • MultiProducerBehaviour

      public MultiProducerBehaviour(String questSlot, String productionActivity, HashSet<String> productsNames, HashMap<String,​Map<String,​Integer>> requiredResourcesPerProduct, HashMap<String,​Integer> productionTimesPerProduct, HashMap<String,​Boolean> productsBound)
      Creates a new MultiProducerBehaviour.
      Parameters:
      questSlot - The slot that is used to store the status of the production.
      productionActivity - The name of the activity, e.g. "build", "brew", "bake"
      productsNames - The set of items that the NPC is able to produce. All must be valid items names.
      requiredResourcesPerProduct - The mapping which maps the name of each product to the mapping of resources required for producing that product, stated as
      productionTimesPerProduct - The mapping of the name of a product to the amount of time required to produce it
      productsBound - The mapping of the name of a product to whether or not that product will be bound to the player.
  • Method Details

    • getQuestSlot

      public String getQuestSlot()
    • getRequiredResourcesPerProduct

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

      public String getProductionActivity()
    • getProductsNames

      public HashSet<String> getProductsNames()
      Return what products the NPC is able to produce
      Returns:
      products names
    • getProductionTime

      protected int getProductionTime(String productName, int amount)
      Return how much time is required to make the requested amount of products
      Parameters:
      productName -
      amount -
      Returns:
      amount of time to produce amount of product
    • isProductBound

      public boolean isProductBound(String productName)
      Return whether the requested product will be bound to the player.
      Parameters:
      productName -
      Returns:
      true if the product should be bound.
    • 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 for this particular order
      Parameters:
      player -
      Returns:
      number of items
    • getRequiredResourceNamesWithHashes

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

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

      protected int getMaximalAmount(String productName, Player player)
      At the time the order is made, Checks how many items the NPC can offer to produce based on what the player is carrying
      Parameters:
      productName - The requested product name
      player -
      Returns:
      maximum number of items
    • askForResources

      public boolean askForResources(ItemParserResult res, EventRaiser npc, Player player)
      At the time the order is made, 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)
      At the time the order is made, tries to take all the resources required to produce the agreed amount of the chosen 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)
      At the time the player returns to pick up the finished product, check that the NPC is done with the order. If that is the case, the player is given the product, otherwise the NPC tells to 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