Class MerchantBehaviour
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.MerchantBehaviour
- Direct Known Subclasses:
BuyerBehaviour,OutfitChangerBehaviour,SellerBehaviour
Represents the behaviour of a NPC who is able to either sell items to a
player, or buy items from a player.
-
Field Summary
FieldsFields inherited from class games.stendhal.common.grammar.ItemParser
itemNames -
Constructor Summary
ConstructorsConstructorDescriptionMerchantBehaviour(Map<String, Integer> priceList) MerchantBehaviour(Map<String, Integer> priceList, Float priceFactor) Creates a new MerchantBehaviour with price list & price factor. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddConditions(SpeakerNPC merchant, Map<String, ChatCondition> conditions) Adds a list of items that are dealt only if a condition is met.Returns a set of the names of all items that the NPC deals with.intgetCharge(ItemParserResult res, Player player) Returns the price of the desired amount of the chosen item.intgetUnitPrice(String item) Returns the price of one unit of a given item.booleanChecks whether the NPC deals with the specified item.Methods inherited from class games.stendhal.server.entity.npc.behaviour.impl.TransactionBehaviour
transactAgreedDealMethods inherited from class games.stendhal.server.entity.npc.behaviour.impl.Behaviour
getRejectedTransactionAction, getTransactionConditionMethods inherited from class games.stendhal.common.grammar.ItemParser
getErrormessage, parse
-
Field Details
-
priceCalculator
-
-
Constructor Details
-
MerchantBehaviour
public MerchantBehaviour() -
MerchantBehaviour
-
MerchantBehaviour
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
Returns a set of the names of all items that the NPC deals with.- Returns:
- The dealt items.
-
hasItem
Checks whether the NPC deals with the specified item.- Parameters:
item- The name of the item.- Returns:
trueif the NPC deals with the item.
-
getUnitPrice
Returns the price of one unit of a given item.- Parameters:
item- the name of the item- Returns:
- the unit price
-
getCharge
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
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
- Overrides:
getItemNamesin classItemParser- Returns:
- the recognized item names
-