Class MultiProducerBehaviour
java.lang.Object
games.stendhal.common.grammar.ItemParser
games.stendhal.server.entity.npc.behaviour.impl.Behaviour
games.stendhal.server.entity.npc.behaviour.impl.TransactionBehaviour
games.stendhal.server.entity.npc.behaviour.impl.MultiProducerBehaviour
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
-
Field Summary
Fields inherited from class games.stendhal.common.grammar.ItemParser
itemNames
-
Constructor Summary
ConstructorDescriptionMultiProducerBehaviour(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. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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.getApproximateRemainingTime(Player player)
Create a text representing a saying of approximate time until the order being produced is readygetErrormessage(ItemParserResult res, String npcAction)
Answer with an error message in case the request could not be fulfilled.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 carryingint
getNumberOfProductItems(Player player)
Checks how many items are being produced for this particular orderprotected int
getProductionTime(String productName, int amount)
Return how much time is required to make the requested amount of productsReturn what products the NPC is able to producegetRequiredResourceNames(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.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.getRequiredResourcesPerProduct(String productName)
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.boolean
isOrderReady(Player player)
Is the order ready for this player?boolean
isProductBound(String productName)
Return whether the requested product will be bound to the player.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.Methods inherited from class games.stendhal.server.entity.npc.behaviour.impl.Behaviour
getRejectedTransactionAction, getTransactionCondition
Methods inherited from class games.stendhal.common.grammar.ItemParser
getErrormessage, getItemNames, parse
-
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 asproductionTimesPerProduct
- The mapping of the name of a product to the amount of time required to produce itproductsBound
- The mapping of the name of a product to whether or not that product will be bound to the player.
-
-
Method Details
-
getQuestSlot
-
getRequiredResourcesPerProduct
-
getProductionActivity
-
getProductsNames
Return what products the NPC is able to produce- Returns:
- products names
-
getProductionTime
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
Return whether the requested product will be bound to the player.- Parameters:
productName
-- Returns:
true
if the product should be bound.
-
getApproximateRemainingTime
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
Is the order ready for this player?- Parameters:
player
-- Returns:
- true if the order is ready.
-
getNumberOfProductItems
Checks how many items are being produced for this particular order- Parameters:
player
-- Returns:
- number of items
-
getRequiredResourceNamesWithHashes
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 nameamount
- The amount of products that were requested- Returns:
- A string describing the required resources with hashes.
-
getRequiredResourceNames
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 nameamount
- The amount of products that were requested- Returns:
- A string describing the required resources.
-
getMaximalAmount
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 nameplayer
-- Returns:
- maximum number of items
-
askForResources
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
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 classTransactionBehaviour
- Parameters:
npc
- the involved NPCplayer
- the involved playerres
- result of the Behaviour parsing- Returns:
- true if the transaction was successful.
-
giveProduct
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 NPCplayer
- The player who wants to fetch the product
-
getErrormessage
Answer with an error message in case the request could not be fulfilled.- Parameters:
res
-npcAction
-- Returns:
- error message
-