wyvern.lib.classes
Class Teleporter
java.lang.Object
wyvern.kernel.properties.PList
wyvern.kernel.maps.MapObject
wyvern.lib.classes.Teleporter
- All Implemented Interfaces:
- Applyable, Broadcaster, GameObject, MethodHookable, PropertyList, WalkNotify
- Direct Known Subclasses:
- Bridge, PayTeleporter, QuestTeleporter, ServerBridge, Sokoban, SpiralStair, Stair, Structure, VaultTeleporter
- public class Teleporter
- extends MapObject
- implements Applyable, WalkNotify
The Teleporter is a fundamental game object responsible for moving
objects between maps. It can also put things in a different location
in the same map. Teleporters are used for entrances and exits, and
also to create "fake walls" or let you walk on terrain you couldn't
normally walk on.
- Version:
- 1.0, Nov 10, 1997
- Author:
- Steve Yegge
Field Summary |
static boolean |
FORCE_PLAYERS
This behavior might bother some people, so I've set a
compile-time flag for it, for now. |
static int |
MAX_DISTANCE
The maximum distance we'll try to randomly teleport someone
in a sparse map (applies to both x & y coordinates). |
static java.lang.String |
PLEASE_WAIT_MSG
Default message to print while destination map is loading.
|
Method Summary |
void |
apply(Commandable agent)
User applies the teleporter. |
protected void |
checkBounds(GameMap map,
Point dest,
Commandable agent)
Checks that the specified destination location is in the
bounds of the map. |
protected void |
checkPerPlayer(java.lang.String mapname)
Check if this teleporter's map is the same as
the map being loaded. |
protected java.lang.String |
checkRelativePath(Commandable agent,
java.lang.String name)
Checks whether the specified relative map path exists
under this teleporter's absolute path. |
static Point |
chooseRandomLocation(GameMap map,
Point ref)
Chooses a random place to teleport an object. |
Location |
getDestination()
Gets the destination for this teleporter. |
Point |
getDestLoc(GameMap map)
Figures out where to put the agent. |
GameMap |
getDestMap(Commandable agent)
Returns the destination map for the teleporter. |
java.lang.String |
getWaitMessage()
Returns the value of "please-wait-msg", if present, or
Teleporter.PLEASE_WAIT_MSG. |
void |
initialize()
Initializes the object's default properties. |
GameMap |
loadMap(java.lang.String path,
Commandable agent)
Locates & returns the GameMap specified by the destination. |
Location |
parseDestination(java.lang.String dest)
Turns a destination string into a Location object. |
static boolean |
passedClaim(GameMap map,
Commandable agent)
Checks whether a player is allowed to enter the map. |
static boolean |
pathOutIsBlocked(Commandable agent,
GameMap map)
Returns true if the specified map is part of the "way out" for
the agent. |
protected void |
printLoadMessage(Commandable agent)
If the map isn't loaded, prints an appropriate message -
either the unavailable-map, if there's no destination,
or a "please wait" message if it's going to load in the
background. |
void |
setDestination(int x,
int y,
java.lang.String map)
Sets the destination for this teleporter. |
void |
setDestination(Location loc)
Sets the destination for this teleporter. |
void |
setMap(GameMap map,
int x,
int y)
Autoloads our destination, if we have the "autoload" property. |
void |
startTeleport(Commandable agent)
Initiates a command that will teleport the agent. |
void |
steppedOn(Monster m)
WalkNotify: someone moved over us. |
boolean |
teleport(Commandable agent,
GameMap map,
Point dest)
Teleports a Commandable to destination point in a map. |
boolean |
teleport(Commandable agent,
java.lang.String mapname,
Point dest)
Teleports the agent to the specified map, loading the map if
necessary. |
protected boolean |
teleport(Location loc,
Commandable agent)
Teleports agent to the passed location. |
boolean |
teleport(java.lang.String mapname,
Commandable agent)
Teleports the agent to the specified map by asking the map
for a destination location. |
java.lang.String |
toString()
Returns a String representation of this object. |
protected void |
tryForcing(Commandable agent)
Adds a "force-map" property on the player with this teleporter's
destination, so that when the map is loaded, the player will
teleport there automatically. |
protected boolean |
validateLevel(Commandable agent)
Ensures the agent is in the specified experience level the
teleporter (or destination map) will allow. |
Methods inherited from class wyvern.kernel.maps.MapObject |
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getBounds, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getImageDescriptors, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, updateMapLocation |
Methods inherited from class wyvern.kernel.properties.PList |
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface wyvern.lib.PropertyList |
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty |
MAX_DISTANCE
public static final int MAX_DISTANCE
- The maximum distance we'll try to randomly teleport someone
in a sparse map (applies to both x & y coordinates).
- See Also:
- Constant Field Values
PLEASE_WAIT_MSG
public static final java.lang.String PLEASE_WAIT_MSG
- Default message to print while destination map is loading.
You can override it with a "please-wait-msg" property, or
by subclassing Teleporter and overriding getWaitMessage().
- See Also:
- Constant Field Values
FORCE_PLAYERS
public static final boolean FORCE_PLAYERS
- This behavior might bother some people, so I've set a
compile-time flag for it, for now. The behavior is that
all teleporters without the "no-force" property now force
you into the destination map after the map is loaded.
- See Also:
- Constant Field Values
Teleporter
public Teleporter()
initialize
public void initialize()
- Description copied from interface:
GameObject
- Initializes the object's default properties. Any GameObject
implementation that wishes to initialize itself should do so
here, rather than in the constructor. This is because nearly
all game objects inherit from an archetype, and the archetype
parent pointer isn't set until the object's constructor finishes.
This is a good place to add any class-default properties for
an object - properties that the object gets regardless of
which archetype it inherits from.
WARNING: don't forget to call the superclass' initialize()
method, or the object may not function properly. For instance,
it won't become animated even if it specifies animation parameters
in the archetype.
- Specified by:
initialize
in interface GameObject
- Overrides:
initialize
in class MapObject
setMap
public void setMap(GameMap map,
int x,
int y)
- Autoloads our destination, if we have the "autoload" property.
- Specified by:
setMap
in interface GameObject
- Overrides:
setMap
in class MapObject
setDestination
public void setDestination(int x,
int y,
java.lang.String map)
- Sets the destination for this teleporter.
setDestination
public void setDestination(Location loc)
- Sets the destination for this teleporter.
getDestination
public Location getDestination()
- Gets the destination for this teleporter.
- Returns:
- the Location to which this teleporter points, or null
if the teleporter isn't connected anywhere.
steppedOn
public void steppedOn(Monster m)
- WalkNotify: someone moved over us.
- Specified by:
steppedOn
in interface WalkNotify
- Parameters:
m
- the monster who walked on us
apply
public void apply(Commandable agent)
- User applies the teleporter. If the teleporter has
any restrictions on it, it checks them here. If
the agent passes the restrictions, it calls startTeleport(agent).
- Specified by:
apply
in interface Applyable
- Parameters:
agent
- the monster or player trying to pass through
startTeleport
public void startTeleport(Commandable agent)
- Initiates a command that will teleport the agent. The command
will be handled by the TeleportCommand class, which will in turn
call us back (via static utility methods) to perform the teleport.
Any Player (or subclass) or Commandable with the "teleportable"
property may go through a teleporter.
- Parameters:
agent
- the Commandable to teleport to our destination
printLoadMessage
protected void printLoadMessage(Commandable agent)
- If the map isn't loaded, prints an appropriate message -
either the unavailable-map, if there's no destination,
or a "please wait" message if it's going to load in the
background.
getDestMap
public GameMap getDestMap(Commandable agent)
- Returns the destination map for the teleporter.
- Parameters:
agent
- the agent to put in the map (for printing errors; null
if no error messages should be sent).
- Returns:
- the map to put the agent in, or null if not found
getDestLoc
public Point getDestLoc(GameMap map)
- Figures out where to put the agent.
- Parameters:
map
- the map to put them in
- Returns:
- the destination, depending on teleporter properties
checkBounds
protected void checkBounds(GameMap map,
Point dest,
Commandable agent)
- Checks that the specified destination location is in the
bounds of the map. If not, issues a message to the agent
and throws an IllegalArgumentException.
- Throws:
java.lang.IllegalArgumentException
- if the dest loc is OOB
validateLevel
protected boolean validateLevel(Commandable agent)
- Ensures the agent is in the specified experience level the
teleporter (or destination map) will allow.
- Parameters:
agent
- the Commandable to teleport to our destination
- Returns:
- true if the agent can enter
chooseRandomLocation
public static Point chooseRandomLocation(GameMap map,
Point ref)
- Chooses a random place to teleport an object.
- Parameters:
ref
- the starting point for the object - in sparse maps,
the object is never teleported more than MAX_DISTANCE from
this point. This parameter will be ignored (and can be null)
if the map is dense or it has a "bounds" property defining
the valid bounds for the map.map
- the map to teleport the object to
- Returns:
- a point in that map
parseDestination
public Location parseDestination(java.lang.String dest)
- Turns a destination string into a Location object.
- Parameters:
dest
- a destination string, such as "cities/blarg 20 30"
- Returns:
- a Location with sub-properties set from the string.
toString
public java.lang.String toString()
- Returns a String representation of this object.
- Overrides:
toString
in class MapObject
- Returns:
- a String that describes the teleporter and its destination
teleport
public boolean teleport(java.lang.String mapname,
Commandable agent)
- Teleports the agent to the specified map by asking the map
for a destination location.
- Parameters:
mapname
- the map to go to. ".map" extension is optional.agent
- the agent to send there.
- Returns:
- true if they got there
teleport
protected boolean teleport(Location loc,
Commandable agent)
- Teleports agent to the passed location. Normally you
don't use this method - you command the agent to
"goto map [x y]". In fact, don't use this method.
- Parameters:
loc
- the Location to go toagent
- the agent to send
- Returns:
- true if they got there
teleport
public boolean teleport(Commandable agent,
java.lang.String mapname,
Point dest)
- Teleports the agent to the specified map, loading the map if
necessary.
- Parameters:
agent
- the agent to sendmapname
- the relative path the map to go to.
".map" extension optional. Example: "village/village"dest
- the destination in the map. Can be null, in
which case the map is asked for the starting location.
- Returns:
- true if the agent got there
teleport
public boolean teleport(Commandable agent,
GameMap map,
Point dest)
- Teleports a Commandable to destination point in a map. Won't
put the agent over another blocking object; instead it looks
for a free location near the specified destination. If it
can't put the agent in the map, it issues a suitable message
to the agent and does nothing.
This is the final method in the teleporting sequence that
takes you to another location within a map, or within the
same map. It starts with the "teleport" command, which
creates a TeleportEvent, figures out the destination, runs
the hooks, loads the map in the background, issues map-entry
messages and background music changes, and so on. This
is the final method that actually performs the transfer
of the agent into the destination map.
- Parameters:
map
- the map to teleport todest
- the destination point to go to (can't be null)agent
- the agent to send there
- Returns:
- true if they got teleported successfully
loadMap
public GameMap loadMap(java.lang.String path,
Commandable agent)
- Locates & returns the GameMap specified by the destination.
- Parameters:
path
- the relative path to the map file. ".map"
extension is optional (but we prefer that you don't include it).agent
- the agent wanting to go to the map
- Returns:
- the GameMap, or null if it couldn't be loaded
checkPerPlayer
protected void checkPerPlayer(java.lang.String mapname)
- Check if this teleporter's map is the same as
the map being loaded. If so, we assume this is a per-player
teleporter. That makes it much simpler to create per-player
maps that have teleporters going to other places in the same map,
since you don't have to specify "per-player" on all of them.
It also means you can have a global (non-per-player) version
of the map, and the teleporters will work for that as well.
checkRelativePath
protected java.lang.String checkRelativePath(Commandable agent,
java.lang.String name)
- Checks whether the specified relative map path exists
under this teleporter's absolute path. If so, we return
that path. This is so wizards can forget to specify a
path for a teleporter - just a map name, or possibly a
subdirectory under the current path, and it'll work.
- Parameters:
agent
- the agent being teleportedname
- the name (or relative path plus name) of a map
- Returns:
- a "full" relative path under world/maps or wiz/,
or null if the file doesn't exist as a sub-path of the
current directory.
passedClaim
public static boolean passedClaim(GameMap map,
Commandable agent)
- Checks whether a player is allowed to enter the map.
- Parameters:
map
- the map to checkagent
- the player who wants to enter
- Returns:
- true if the player can enter the map
pathOutIsBlocked
public static boolean pathOutIsBlocked(Commandable agent,
GameMap map)
- Returns true if the specified map is part of the "way out" for
the agent. In particular, if you're trying to get out of a dungeon
that's a dead-end, and we don't want someone to be able to claim
the map that's your only way out.
- Parameters:
agent
- the player that's teleportingmap
- the map they're trying to teleport to
- Returns:
- true if they *have* to go through this map to get out,
where "out" is defined as "closer to the continent"
getWaitMessage
public java.lang.String getWaitMessage()
- Returns the value of "please-wait-msg", if present, or
Teleporter.PLEASE_WAIT_MSG.
- Returns:
- a message to print if the map isn't loaded yet.
tryForcing
protected void tryForcing(Commandable agent)
- Adds a "force-map" property on the player with this teleporter's
destination, so that when the map is loaded, the player will
teleport there automatically. If the teleporter has a "no-force"
property, this method will simply return without doing anything.
This method is called from startTeleport(), after printing
the "please wait" message. If the teleporter has no destination,
this method returns without doing anything.