|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.kernel.properties.PList wyvern.kernel.maps.MapObject wyvern.lib.classes.Shop
The basic Shop object. It handles buying, selling, listing, and other shop commands. It also prevents players from doing various things with unpaid items.
Field Summary | |
protected static Predicate |
checkUnpaid_
|
protected static int |
ITEM_REDUCTION
|
protected java.util.HashSet |
items_
|
protected static int |
MAX_ITEMS
|
protected java.util.LinkedList |
sellList_
|
protected java.lang.String |
shopList_
|
protected java.util.HashSet |
targetedHooks_
This is a list of hook names, such as "applyPreHook", for commands that we don't allow on unpaid objects. |
Fields inherited from class wyvern.kernel.maps.MapObject |
IN_MAP_EDITOR, listenerList_ |
Fields inherited from class wyvern.kernel.properties.PList |
readOnly_ |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Constructor Summary | |
Shop()
|
Method Summary | |
CommandEvent |
createEvent(CommandEvent initialInfo)
Creates a CommandEvent that encapsulates all the state necessary to perform the command. |
boolean |
execute(CommandEvent event)
Executes the specified CommandEvent. |
static java.lang.String |
formatCurrency(int silver_value)
Formats a currency as platinum, gold and silver. |
Rectangle |
getBounds()
Returns the area covered by the shop. |
int[] |
getImageDescriptors()
Returns the list of (x, y, tile) image triples for this object. |
int |
getItemPrice(GameObject item)
Returns the price (in gold) the shop would pay for the item. |
static int |
getSellPriceForItem(GameObject target,
Monster agent)
Tells them how much a player will get for selling the thing (which may be a group of things) Helper function used by sell/value. |
java.lang.String |
getShopList()
Returns a string description of the shop's contents. |
boolean |
handleBuy(CommandEvent event,
Monster agent)
Agent wants to buy something. |
boolean |
handleList(CommandEvent event,
Monster agent)
Handles listing the contents of the shop. |
boolean |
handleRefund(CommandEvent event,
Monster mon)
Refunds the customer's money for the item. |
boolean |
handleSell(CommandEvent event,
Monster agent)
Agent wants to sell something. |
boolean |
handleUnsell(CommandEvent event,
Monster mon)
Allows a player to reverse a sale; i.e. get their item back and lose the money they got for it. |
boolean |
handleValue(CommandEvent event,
Monster agent)
Tells them how much the thing will cost (if unpaid), or how much they'd get for selling an unpaid item. |
void |
hookEvent(java.lang.String hookName,
CommandEvent event)
Movement hook handler - don't let them leave without paying. |
void |
hookEvent(java.lang.String hookName,
Rectangle room,
CommandEvent event)
Player is trying to do something that we might want to veto. |
void |
initialize()
Adds class-default properties. |
boolean |
knowsCommand(java.lang.String command)
Returns true if this Command wants to handle the command. |
void |
methodCalled(java.lang.String hookName,
MethodHookable target,
java.lang.Object data)
Map is finished loading - construct list of shop contents. |
protected void |
nukeExtraInventory()
If we pass the threshold for too many sold items, we nuke the ones that have been there the longest. |
void |
registerCommands(GameMap map,
Rectangle bounds)
Registers the commands we want to hook. |
protected void |
resetShopList()
Recomputes the cached string containing the shop contents. |
void |
scanObjects()
Looks for objects to add to the shop's item-list. |
boolean |
sellAll(CommandEvent event)
Agent wants to sell all non-kept stuff in inventory. |
void |
setMap(GameMap map,
int x,
int y)
Puts the shop in the map. |
void |
setSize(int width,
int height)
Throws out the cached image descriptors when the size changes. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final int MAX_ITEMS
protected static final int ITEM_REDUCTION
protected transient java.util.HashSet targetedHooks_
protected static Predicate checkUnpaid_
protected transient java.util.HashSet items_
protected transient java.util.LinkedList sellList_
protected java.lang.String shopList_
Constructor Detail |
public Shop()
Method Detail |
public void initialize()
initialize
in interface GameObject
initialize
in class MapObject
public void setMap(GameMap map, int x, int y)
setMap
in interface GameObject
setMap
in class MapObject
map
- the map to put us inx
- the x-coordinate of our upper-left cornery
- the y-coordinate of our upper-left cornerpublic Rectangle getBounds()
getBounds
in interface GameObject
getBounds
in class MapObject
public void registerCommands(GameMap map, Rectangle bounds)
map
- the map we're being added tobounds
- our boundspublic int[] getImageDescriptors()
getImageDescriptors
in interface GameObject
getImageDescriptors
in class MapObject
public void setSize(int width, int height)
setSize
in interface GameObject
setSize
in class MapObject
public void hookEvent(java.lang.String hookName, Rectangle room, CommandEvent event)
hookEvent
in interface RoomHookCallback
hookName
- the name of the hook (e.g. "applyPreHook")room
- the room in which the event took place, in case
the callback is registered for the same hook in more than
one room.event
- the command eventpublic void hookEvent(java.lang.String hookName, CommandEvent event)
hookEvent
in interface HookCallback
hookName
- hook nameevent
- the MoveEventpublic boolean knowsCommand(java.lang.String command)
This method exists to allow more than one game object to implement the same command, but with different expected arguments.
If two objects register for the same command and the same arguments, the object that was registered most recently gets first shot at the command.
knowsCommand
in interface Command
command
- the entire command string, including arguments
public CommandEvent createEvent(CommandEvent initialInfo)
This method is called by the kernel. The kernel passes the event to the pre-hook, then calls Command.execute() (below) to execute the event, and finally calls the post-hook.
createEvent
in interface Command
initialInfo
- a "blank" CommandEvent containing only the
command text and the agent who's performing the command. This
initial event is created by the originator of the event (e.g.
the AI or player's command preprocessor).
public boolean execute(CommandEvent event)
execute
in interface Command
event
- the CommandEvent to execute
public boolean handleBuy(CommandEvent event, Monster agent)
event
- the event containing the text of the thing to buyagent
- the agent to do the purchase
public boolean handleSell(CommandEvent event, Monster agent)
event
- the event containing the text of the thing to sellagent
- the agent to do the sale
public boolean sellAll(CommandEvent event)
public boolean handleList(CommandEvent event, Monster agent)
event
- the event with the command & argsagent
- the agent to send the list to
public void methodCalled(java.lang.String hookName, MethodHookable target, java.lang.Object data)
methodCalled
in interface MethodHookCallback
hookName
- the name of the hook being runtarget
- the object on which the method was invoked:
a GameMap or GameObject.data
- a method-specific data object; can be null.
Check the documentation for the method hook to see if
any data is passed to the callbacks.public void scanObjects()
protected void resetShopList()
public java.lang.String getShopList()
protected void nukeExtraInventory()
public boolean handleUnsell(CommandEvent event, Monster mon)
event
- the eventmon
- the player unselling the itempublic boolean handleRefund(CommandEvent event, Monster mon)
public boolean handleValue(CommandEvent event, Monster agent)
public static int getSellPriceForItem(GameObject target, Monster agent)
target
- the object to sellagent
- the player doing the selling
public int getItemPrice(GameObject item)
public static java.lang.String formatCurrency(int silver_value)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |