Class ProducerBehaviour
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.ProducerBehaviour
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
-
Field Summary
Fields inherited from class games.stendhal.common.grammar.ItemParser
itemNames
-
Constructor Summary
ConstructorDescriptionProducerBehaviour(String questSlot, String productionActivity, String productName, Map<String,Integer> requiredResourcesPerItem, int productionTimePerItem)
Creates a new ProducerBehaviour.ProducerBehaviour(String questSlot, String productionActivity, String productName, Map<String,Integer> requiredResourcesPerItem, int productionTimePerItem, boolean productBound)
Creates a new ProducerBehaviour. -
Method Summary
Modifier and TypeMethodDescriptionboolean
askForResources(ItemParserResult res, EventRaiser npc, Player player)
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(Player player)
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 on this particular orderint
getProductionTime(int amount)
Return item name of the product to produce.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 productprotected 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.void
giveProduct(EventRaiser npc, Player player)
This method is called when the player returns to pick up the finished product.boolean
isOrderReady(Player player)
Is the order ready for this player?boolean
Determine whether the produced item should be player bound.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.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
-
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 statusproductionActivity
- 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 statusproductionActivity
- 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
-
getRequiredResourcesPerItem
-
getProductionActivity
-
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
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
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
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 on this particular order- Parameters:
player
-- Returns:
- number of items
-
getMaximalAmount
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
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
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 classTransactionBehaviour
- Parameters:
npc
- the involved NPCplayer
- the involved playerres
- result of the Behaviour parsing- Returns:
- true if the transaction was successful.
-
giveProduct
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 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
-