|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Represents a single character logged in to the game. It's one of the most important/commonly-used interfaces in the game, since most code deals with players, in one way or another.
The first thing you should know about Player objects is that you shouldn't store direct references to them, if you can avoid it. If you need to remember a Player in your code, you should store the player's name, and when you need to access the player later, use World.getPlayer(name). This is because players can, of course, log out, and if you keep a reference to their actual Player object around, you'll prevent it from being garbage-collected. Worse, you might be doing stuff to the wrong object: if they logged out and logged back in again, you'll be manipulating their old Player object. So store the name!
It's OK to use Player references inside a single function, of course, or pass them from function to function, as long as you don't store the reference in an instance variable or a list of some sort.
Lots of Player attributes are stored as properties on the player, so they can be saved. Normally, you can modify properties on game objects directly with setProperty(), setIntProperty(), and so on. For Players, however, you should first check to see if there's a special method for accessing the attribute. For instance, you don't want to call player.adjustIntProperty("hp", 10), because it won't update their HP display on their client. Use player.adjustHP(10) instead. Similarly, you don't want to use getProperty("title"), because there's a getTitle() that returns the correct title.
The Player interface gives you the ability to access, modify, and control lots of things about the player:
Plus all of the methods available to Monsters, Commandables, and GameObjects, all of which Players inherit from.
Like any other Wyvern object, some of the methods are there specifically for the game engine, and others are there for the Wizard API. We don't currently show, in this API documentation, which ones are which, but we'll add that soon. In the meantime, ask Rhialto if you're not sure whether you can use a particular method or not.
There are various pubsub Messages published by the Player class:
Field Summary | |
static int |
DEFAULT_PLAYER_SPEED
If a player has no "move-speed" property, this is the default speed at which the monster moves. |
static int |
DEFAULT_WAKE_MONSTER_RADIUS
The range in which to wake up monsters if we fail sneaking. |
static int |
END_COMBAT_DELAY
Number of milliseconds that elapse after combat ends before the player is considered "not in combat" anymore. |
static int |
MAX_VIEW_SIZE
The maximum width or height for a normal player's view. |
static int |
MAX_WIZ_VIEW_SIZE
The maximum width or height for a wizard's view. |
Fields inherited from interface wyvern.lib.Monster |
DEFAULT_MONSTER_ATTACK_SPEED, DEFAULT_MONSTER_SPEED, DEFAULT_MONSTER_STRENGTH, MONSTER_XP_CAP |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Fields inherited from interface wyvern.common.net.RemoteAudio |
DEFAULT_ALERT_GAIN, DEFAULT_ALERT_REPEAT_DELAY, DEFAULT_ALERT_REPEATS, DEFAULT_GAIN, DEFAULT_REPEAT_DELAY, DEFAULT_REPEATS |
Method Summary | |
void |
adjustAlign(int adjust)
Adjusts the player's alignment upwards or downwards. |
void |
adjustFood(int adjust)
Adjusts the player's food amount by the specified amount. |
void |
adjustShoutPoints(int adjust)
Adjusts the player's shout points upwards or downwards. |
void |
adjustSkill(java.lang.String name,
int adjust)
Adjusts the transient value of a skill for the player. |
void |
adjustXP(int adjust)
Adjusts the player's experience points upwards or downwards. |
boolean |
autosave()
Saves the current state of the player to the player's file, without issuing any message to the player. |
long |
combatTimeLeft()
Returns time left before we change this API. |
void |
controlCamera(boolean control)
Tells the Player to control its own camera (if true) or notifies the Player that the camera will be controlled externally (if false). |
void |
enqueueCommand(java.lang.String command,
boolean user)
Puts a command in our command queue. |
int |
getAge()
Returns the player's age in seconds. |
java.util.Map |
getAliases()
Returns the aliases for this player. |
int |
getAlignment()
Returns player's alignment |
RemoteClient |
getClient()
Returns the RemoteClient implementation for this player. |
CommandList |
getCommandList()
Returns the CommandList for this player. |
int |
getFood()
Returns the player's current food level. |
java.lang.String |
getFullTitle()
Returns a full title, such as "Rawk the Elven Adventurer". |
Camera |
getGroundCamera()
Returns the camera that displays the ground beneath the player. |
GameObject |
getGroundObject(int index)
This is a rather special-purpose method: it returns the game object that's currently being displayed in the client's ground display at the specified index. |
java.lang.String |
getHostAddress()
Returns the IP address this player is connected from. |
int |
getIdleTime()
Returns the number of seconds the player has been idle. |
Camera |
getMapCamera()
Returns the camera that displays the map. |
int |
getMaxFood()
Returns the max food the player can eat/drink. |
MusicState |
getMusicState()
Returns the MusicState object keeping track of this player's running soundtrack. |
java.lang.String |
getPassword()
Returns the player's encrypted password. |
Point |
getPositionInViewport()
Returns the relative offets of the player within the player's map camera. |
java.lang.String |
getRace()
Returns player's race. |
wyvern.server.IClientSession |
getSession()
Returns the ClientSession for this player. |
java.lang.String |
getSex()
Returns player's gender. |
int |
getShoutPoints()
Returns the player's shout points. |
SpellList |
getSpellList()
Returns the player's SpellList, or null if they don't know any spells (or are a Wizard who can cast anything.) |
java.util.Date |
getStartDate()
Returns the time when the player logged in. |
long |
getStartTime()
Returns System.currentTimeMillis() when the player logged in. |
java.lang.String |
getTitle()
Returns the player's title, e.g. |
int |
getXP()
Returns the player's experience. |
boolean |
inCombat()
Returns true if the player has recently been in combat. |
void |
init(RemoteClient client,
Dimension viewsize)
Initializes the player instance and data structures using the specified RemoteClient. |
boolean |
isGuest()
Returns true if the player is a guest. |
boolean |
isHandheld()
Returns true if the player is connected via a handheld client. |
boolean |
isNetDead()
Returns true if the player is currently net-dead. |
boolean |
isShutDown()
Returns true if this Player object is defunct (the player has logged out). |
boolean |
isTelnet()
Returns true if we're connected via a Telnet client. |
boolean |
isWizard()
Returns true if the player is a Wizard (any level). |
long |
lastCombat()
Returns the last time the player had an updateCombat() method called. |
boolean |
outranks(Commandable other)
Returns true if this player outranks the passed player. |
void |
quit()
Dumps the player out of the game, dropping all inventory before saving the player. |
void |
quitSafely()
Player's quitting in an Inn or somewhere they can keep their inventory. |
void |
readAliases()
Rebuilds the table of aliases for this player, by looking through all the player's properties that start with "alias-". |
void |
reconnect(RemoteClient client,
Dimension d)
Reconnects a net-dead player. |
void |
resetIdleTimer()
Resets the number of seconds the player has been idle to zero. |
boolean |
save()
Saves the player with notification. |
void |
sendFile(java.lang.String path,
java.lang.String command)
Downloads a file to the client. |
void |
sendFood()
Updates player's food display on the client. |
void |
sendHP()
Updates the player's hit-points display on the client. |
void |
sendLevel()
Updates player's level display on the client. |
void |
sendLoad()
Updates the player's encumbrance display on the client. |
void |
sendName()
Updates the player's name on the client. |
void |
sendRange()
Updates the player's range-weapon on the client. |
void |
sendSP()
Updates the player's spell-points display on the client. |
void |
sendSpells()
Resends the player's list of known spells to the client. |
void |
sendXP()
Updates the player's experience display on the client. |
void |
serverTransfer(java.lang.String host)
Tells the client to connect to a different server after a successful transfer. |
void |
setNetDead()
Sets the net-dead flag. |
void |
setSession(wyvern.server.IClientSession s)
Sets the ClientSession (the thread reading from the socket). |
void |
setTitle(java.lang.String title)
Sets the player's title, e.g. |
void |
setViewSize(int width,
int height)
Sets new dimensions for the map camera. |
boolean |
solvedQuest(java.lang.String name)
Returns true if the player has solved the specified quest. |
void |
startPoison()
Turns the client HP indicator green. |
void |
stopPoison()
Returns the client HP indicator red. |
void |
tellLater(java.lang.String msg,
byte style)
Puts a message in the player's event queue that will be displayed to the player after all current events in the queue are processed. |
void |
uncacheImage(java.lang.String path)
Tells the client to uncache the specified image, and request it to be reloaded if it views it again. |
void |
updateClient()
Sends all our visible stats to the client. |
void |
updateCombat()
Marks the player as being in combat. |
void |
viewMap(GameMap map,
int x,
int y)
Sets the player's viewport to the specified map and (x,y) location. |
Methods inherited from interface wyvern.lib.Monster |
adjustSP, adjustStat, adjustWallet, burial, createInventory, dropAll, dropAllForce, getLevel, getMaxSP, getPartsList, getSP, getWallet, isAlive, setHP, setSP |
Methods inherited from interface wyvern.lib.Commandable |
addAttack, addMessageListener, command, command, commandNow, getAI, getCapName, getCombatQueue, getCommand, getEncumbrance, getFiringPoint, getInventory, getName, getQueue, isStarted, message, message, message, registerCommand, removeAttack, removeMessageListener, sendPicture, sendPicture, setAI, setEncumbrance, setName, start, stop, unregisterCommand |
Methods inherited from interface wyvern.lib.Hookable |
addHook, getHookList, getHooks, removeHook, runFailedPostHook, runPostHook, runPreHook |
Methods inherited from interface wyvern.lib.MethodHookable |
addMethodHook, removeMethodHook, runMethodHook |
Methods inherited from interface wyvern.lib.Broadcaster |
broadcast, broadcast, broadcast, broadcast, broadcast |
Methods inherited from interface wyvern.common.net.RemoteAudio |
pauseSound, playAlert, playAlert, playDefaultMusic, playPriorityMusic, playPriorityMusic, playSound, playSound, resumeSound, setMusicGain, setSoundGain, stopAllSounds, stopMusic, stopSound |
Methods inherited from interface wyvern.lib.properties.Attackable |
getXPAward, notifyAttacked |
Methods inherited from interface wyvern.lib.properties.Damageable |
adjustHP, getHP, getMaxHP, kill |
Methods inherited from interface wyvern.world.MapLoaderListener |
mapLoaded, mapLoadFailed |
Field Detail |
public static final int DEFAULT_WAKE_MONSTER_RADIUS
public static final int DEFAULT_PLAYER_SPEED
public static final int MAX_VIEW_SIZE
public static final int MAX_WIZ_VIEW_SIZE
public static final int END_COMBAT_DELAY
Method Detail |
public void viewMap(GameMap map, int x, int y)
map
- the GameMap to viewx
- the map x-coordinate to center the view ony
- the map y-coordinate the center the view onpublic void init(RemoteClient client, Dimension viewsize)
client
- the RemoteClient used for sending information.viewsize
- the size of the client's map viewportpublic void sendName()
public void sendHP()
public void sendSP()
public void sendXP()
public void sendLevel()
public void sendFood()
public void sendRange()
public void sendSpells()
public void sendLoad()
public void updateClient()
public void serverTransfer(java.lang.String host)
host
- the host of the server the player is now visitingpublic void sendFile(java.lang.String path, java.lang.String command)
path
- the relative path to the file. There are
restrictions on what file extensions are allowed - call
wyvern.server.request.SendFile.getApprovedExtensions()
to see which ones it will send. There are also limits
on max file size: SendFile.MAX_DATA_FILE_LENGTH is the
current limit.command
- the original "#download public int getXP()
public void adjustXP(int adjust)
adjust
- a number (possibly negative) to add to the player's xppublic int getShoutPoints()
public void adjustShoutPoints(int adjust)
adjust
- a number (possibly negative) to add to the player's shppublic int getAlignment()
public void adjustAlign(int adjust)
adjust
- a number (possibly negative) to add to the player's
"align" property. Runs a method-hook called "align", where
the data parameter is an Integer containing the adjustment.
It's run after the adjustment is applied, so subtract the
adjustment to see what the old alignment was.public java.lang.String getTitle()
public void setTitle(java.lang.String title)
title
- the new title for the playerpublic java.lang.String getFullTitle()
public void adjustFood(int adjust)
public int getFood()
public int getMaxFood()
public int getAge()
public java.lang.String getRace()
public java.lang.String getSex()
public Camera getMapCamera()
public Camera getGroundCamera()
public void controlCamera(boolean control)
control
- false to grab control of the camera, true to
return control to the Player.public GameObject getGroundObject(int index)
index
- the 0-based index of the selected item
public Point getPositionInViewport()
public boolean save()
public boolean autosave()
public void quit()
public void quitSafely()
Lots of things happen in this method:
When a player quits, a pubsub message is published. The Message sent out has the following attributes:
Registering for this PubSub message is easier and more reliable than using the quitPostHook. The quitPostHook is only run if the player types "quit". If the player applies a bed, or is booted off the game, then you won't get the hook callback. The PubSub message goes out no matter how the player leaves the game.
public int getIdleTime()
public void resetIdleTimer()
public java.util.Date getStartDate()
public long getStartTime()
public void readAliases()
public java.util.Map getAliases()
public boolean isNetDead()
public void setNetDead()
public boolean isTelnet()
isTelnet
in interface Commandable
public RemoteClient getClient()
public void startPoison()
public void stopPoison()
public java.lang.String getPassword()
public java.lang.String getHostAddress()
public void setViewSize(int width, int height)
width
- the new camera view width (in tiles)height
- the new camera view height (in tiles)public boolean solvedQuest(java.lang.String name)
name
- the quest name, e.g. "moonquest"
public boolean isWizard()
isWizard
in interface GameObject
public boolean isGuest()
public void adjustSkill(java.lang.String name, int adjust)
name
- the skill name, such as "sk-incantation"adjust
- the adjustment (can be negative)public boolean outranks(Commandable other)
other
- the other player
public boolean isHandheld()
public CommandList getCommandList()
public void tellLater(java.lang.String msg, byte style)
msg
- the message to sendstyle
- the RPCConstants.TextStylepublic void uncacheImage(java.lang.String path)
path
- the relative path to the image, such as
wiz/rhialto/images/big_rock (note: no extension).public void enqueueCommand(java.lang.String command, boolean user)
command
- the command stringuser
- true if the command was initiated by the player,
false if it came from an object on the server (such as a
charm-monster spell).public MusicState getMusicState()
public boolean inCombat()
public long lastCombat()
public long combatTimeLeft()
public void updateCombat()
public boolean isShutDown()
public void setSession(wyvern.server.IClientSession s)
s
- the thread reading from the client socketpublic wyvern.server.IClientSession getSession()
public void reconnect(RemoteClient client, Dimension d)
client
- the new RemoteClient handling server outputd
- the client view width and heightpublic SpellList getSpellList()
getSpellList
in interface Monster
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |