org.starhope.appius.game.npc.plebeian
Class Plebeian

java.lang.Object
  extended by org.starhope.appius.user.GeneralUser
      extended by org.starhope.appius.user.AbstractNonPlayerCharacter
          extended by org.starhope.appius.game.npc.plebeian.Plebeian
All Implemented Interfaces:
Serializable, Comparable<Object>, ScriptPuppet, RoomListener, Collidable, HasVariables, AbstractUser, DataRecordBacked<UserRecord>, AcceptsMetronomeTicks, HasName

public class Plebeian
extends AbstractNonPlayerCharacter
implements ScriptPuppet

The Plebeian class is a base class for simply scripted NPC:s using the Plebeian structure, which is meant to be a fairly understandable scripting language for basic state machine representation.

TODO: document secret Plebeian script language!

Note that there are probably significant problems with the implementation of simultaneous steps in a plebian script. For now, all scripts should use only the sequential keywords (e.g. "then" or "&" between steps). I haven't had time to resolve the issues involved in correctly handling simultaneous steps just yet — they might potentially “blow up” the script interpreter system.

Author:
brpocock@star-hope.org
See Also:
Serialized Form

Field Summary
private static AtomicInteger instanceCounter
          unique instance ID generator
(package private)  PlebeianScriptRunner scriptRunner
          script runner object
private static long serialVersionUID
          Java serialisation unique ID
 
Fields inherited from class org.starhope.appius.user.AbstractNonPlayerCharacter
buddyList, casualSpeechQueue, casualSpeechRate, instanceID, kalendor, lastActive, lastSpoken
 
Fields inherited from class org.starhope.appius.user.GeneralUser
baseStats, collisionBounds, currentRoom, facing, lastUserMovement, pathFinder, userRecord
 
Constructor Summary
Plebeian(Zone z, String login)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
 void acceptErrorReply(String command, String error, org.json.JSONObject result, Room userCurrentRoomInZone)
           
 void acceptGameAction(AbstractUser u, org.json.JSONObject action)
          Broadcast message of a game action taking place
 void acceptGameStateChange(GameEvent gameCode, GameStateFlag gameState)
          Notification of a GameEvent changing state for the room
 void acceptMessage(String title, String label, String content)
          Accept an administrative/moderator message with the full range of options.
 void acceptObjectJoinRoom(Room room, RoomListener object)
          Notification that someone has entered the room.
 void acceptObjectPartRoom(Room room, RoomListener thing)
          Notification that someone has left a room
 void acceptOutOfBandMessage(AbstractUser sender, Room room, org.json.JSONObject body)
          Accept an out-of-band communications packet that was broadcast to a room in which this Listener is listening.
 void acceptPrivateMessage(AbstractUser speaker, String speech)
          Accept a private message from another user (a whisper)
 void acceptPublicMessage(AbstractUser sender, Room room, String message)
          Accept a public chat message or /emote.
 void acceptPublicMessage(AbstractUser sender, String message)
          Accept a public chat message.
 void acceptSuccessReply(String command, org.json.JSONObject jsonData, Room room)
           
 void acceptUserVariableUpdate(AbstractUser user, String varName, String varValue)
          Receive notification of the change of an user variable
 void ban(AbstractUser u, String banReason)
           
protected  int getInstanceID()
           
 PlebeianScriptRunner getScriptRunner()
          WRITEME: Document this method brpocock@star-hope.org
 String getShortLabel()
          WRITEME: Document this method brpocock@star-hope.org
 void seekRoom(Room r)
          WRITEME: Document this method brpocock@star-hope.org
 void tick(long currentTime, long deltaTime)
          This method is called periodically from the metronome thread.
 
Methods inherited from class org.starhope.appius.user.AbstractNonPlayerCharacter
acceptUserList, addBuddy, addGiftSubscription, addItem, canTalk, destroy, doTransport, equals, getAccessibleRooms, getAvatarClass, getAvatarLabel, getBaseColor, getBuddyListNames, getDebugName, getGreeting, getIPAddress, getKickedMessage, getLag, getLanguage, getLocation, getMail, getName, getNameApprovedAt, getNameRequestedAt, getNameStripped, getPublicInfo_new, getServerThread, hashCode, inviteBuddy, isBuddy, isNPC, isOnline, kick, liftBan, needsParent, reportedToModeratorBy, reportedToModeratorBy, sendMigrate, sendOops, sendResponse, setLastActive, setMail, setParent, speak, speakCasually, toJSON, toSFSXML, toString, whenAtTarget
 
Methods inherited from class org.starhope.appius.user.GeneralUser
acceptUserAction, assertLocationUnlocked, assertStaffLevel, attend, canApproveSelf, canBetaTest, canEnterChatZone, canEnterMenuZone, changeBaseDefenses, compareTo, deleteVariable, doffClothes, getAge, getAgeGroup, getApprovedDateString, getBaseDefenses, getBaseStat, getCenterOfMass, getCollisionBounds, getCurrentAction, getD, getDialect, getDisplayName, getEffectiveDefenses, getEndMovementTime, getExtraColor, getFacing, getGameEquipItems_JSON, getGameEquipItems, getHeight, getHouse, getInventory, getItemsByType, getItemsByType, getItemsByTypeAsArray, getKickedByUserID, getKickedReasonCode, getKickedUntil, getLocationForUpdate, getMass, getMoney, getPathFinder, getPublicInfo, getRegisteredAt, getRegisteredDate, getRegisteredDateString, getRequestedName, getResponsibleMail, getRoom, getRoomNumber, getSizeScalar, getStaffLevel, getStartMovementTime, getStartT, getStat, getTarget, getTravelRate, getTravelStart, getUserID, getUserListIterator, getUserName, getUserVariables, getVariable, getVariables, getVariablesJSON, getVelocity, getWallet, getZone, handleWalkFail, hasStaffLevel, hasVariable, ignore, isActive, isApproved, isBanned, isCanceled, isKicked, isPaidMember, local_publicInfo, purchase, removeBuddy, resetVariables, sendBuddyList, sendEarnings, sendWardrobe, setAgeGroupToSystem, setBackingRecord, setBaseColor, setCanTalk, setCenterOfMass, setCurrentAction, setExtraColor, setFacing, setLocation, setRoom, setStartT, setTarget, setTravelRate, setTravelStart, setVariable, setVariable, setVariables, setVelocity, takeAttack, unlockLocation, updateWallet
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.starhope.appius.game.npc.plebeian.ScriptPuppet
isBuddy, speakCasually, whenAtTarget
 
Methods inherited from interface org.starhope.appius.user.AbstractUser
addBuddy, addGiftSubscription, addItem, assertLocationUnlocked, assertStaffLevel, attend, canTalk, doffClothes, doTransport, getAge, getAgeGroup, getApprovedDateString, getAvatarClass, getAvatarLabel, getBaseColor, getBuddyListNames, getCurrentAction, getDebugName, getDialect, getDisplayName, getExtraColor, getFacing, getHeight, getInventory, getIPAddress, getKickedByUserID, getKickedMessage, getKickedReasonCode, getKickedUntil, getLag, getLanguage, getLocation, getLocationForUpdate, getMail, getMoney, getNameApprovedAt, getNameRequestedAt, getPathFinder, getPublicInfo, getRegisteredDateString, getResponsibleMail, getRoomNumber, getServerThread, getSizeScalar, getStaffLevel, getStartT, getTarget, getTravelRate, getTravelStart, getUserID, getUserListIterator, getUserVariables, getVariable, getWallet, handleWalkFail, hasStaffLevel, hasVariable, ignore, isBanned, isCanceled, isKicked, isNPC, isOnline, isPaidMember, kick, liftBan, needsParent, purchase, removeBuddy, reportedToModeratorBy, reportedToModeratorBy, sendBuddyList, sendEarnings, sendMigrate, sendOops, sendResponse, sendWardrobe, setAgeGroupToSystem, setBaseColor, setCanTalk, setCurrentAction, setExtraColor, setFacing, setLastActive, setLocation, setMail, setParent, setRoom, setStartT, setTarget, setTravelRate, setTravelStart, setVariable, speak, takeAttack, toJSON, toSFSXML, unlockLocation, updateWallet
 
Methods inherited from interface org.starhope.appius.game.RoomListener
acceptUserAction, getRoom, getZone
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface org.starhope.appius.types.HasVariables
deleteVariable, getVariables, resetVariables, setVariable, setVariables
 
Methods inherited from interface org.starhope.appius.user.DataRecordBacked
setBackingRecord
 

Field Detail

instanceCounter

private static final AtomicInteger instanceCounter
unique instance ID generator


serialVersionUID

private static final long serialVersionUID
Java serialisation unique ID

See Also:
Constant Field Values

scriptRunner

PlebeianScriptRunner scriptRunner
script runner object

Constructor Detail

Plebeian

public Plebeian(Zone z,
                String login)
         throws NotFoundException,
                GameLogicException
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
z - the zone in which to spawn
login - WRITEME
Throws:
NotFoundException - WRITEME
GameLogicException - if the character is not an NPC or the .pleb script is not found
Method Detail

acceptErrorReply

public void acceptErrorReply(String command,
                             String error,
                             org.json.JSONObject result,
                             Room userCurrentRoomInZone)
Specified by:
acceptErrorReply in interface AbstractUser
Overrides:
acceptErrorReply in class AbstractNonPlayerCharacter
Parameters:
command - The command which produced the error
error - The error code
result - The additional JSON data describing the error
userCurrentRoomInZone - The room in which the user was standing when the error occurred.
See Also:
AbstractNonPlayerCharacter.acceptErrorReply(java.lang.String, java.lang.String, org.json.JSONObject, org.starhope.appius.game.Room)

acceptGameAction

public void acceptGameAction(AbstractUser u,
                             org.json.JSONObject action)
Description copied from interface: RoomListener
Broadcast message of a game action taking place

Specified by:
acceptGameAction in interface RoomListener
Overrides:
acceptGameAction in class AbstractNonPlayerCharacter
Parameters:
u - the sender
action - The game action. The verb is in action.getString("action").
See Also:
AbstractNonPlayerCharacter.acceptGameAction(org.starhope.appius.user.AbstractUser, org.json.JSONObject)

acceptGameStateChange

public void acceptGameStateChange(GameEvent gameCode,
                                  GameStateFlag gameState)
Description copied from interface: RoomListener
Notification of a GameEvent changing state for the room

Specified by:
acceptGameStateChange in interface RoomListener
Overrides:
acceptGameStateChange in class AbstractNonPlayerCharacter
Parameters:
gameCode - The GameEvent whose state is changing
gameState - The new state
See Also:
AbstractNonPlayerCharacter.acceptGameStateChange(org.starhope.appius.game.GameEvent, org.starhope.appius.game.GameStateFlag)

acceptMessage

public void acceptMessage(String title,
                          String label,
                          String content)
Description copied from interface: AbstractUser
Accept an administrative/moderator message with the full range of options. If the user is currently online, forward this message to them.

Specified by:
acceptMessage in interface AbstractUser
Overrides:
acceptMessage in class AbstractNonPlayerCharacter
Parameters:
title - The title of the message
label - A label which nominally identifies the source of the message
content - The contents of the message
See Also:
AbstractNonPlayerCharacter.acceptMessage(java.lang.String, java.lang.String, java.lang.String)

acceptObjectJoinRoom

public void acceptObjectJoinRoom(Room room,
                                 RoomListener object)
Description copied from interface: RoomListener
Notification that someone has entered the room.

Specified by:
acceptObjectJoinRoom in interface RoomListener
Overrides:
acceptObjectJoinRoom in class GeneralUser
Parameters:
room - The room
object - The thing (probably user) entering
See Also:
GeneralUser.acceptObjectJoinRoom(org.starhope.appius.game.Room, org.starhope.appius.game.RoomListener)

acceptObjectPartRoom

public void acceptObjectPartRoom(Room room,
                                 RoomListener thing)
Description copied from interface: RoomListener
Notification that someone has left a room

Specified by:
acceptObjectPartRoom in interface RoomListener
Overrides:
acceptObjectPartRoom in class GeneralUser
Parameters:
room - The room
thing - The thing (probably user) departing
See Also:
GeneralUser.acceptObjectPartRoom(org.starhope.appius.game.Room, org.starhope.appius.game.RoomListener)

acceptOutOfBandMessage

public void acceptOutOfBandMessage(AbstractUser sender,
                                   Room room,
                                   org.json.JSONObject body)
Description copied from interface: RoomListener
Accept an out-of-band communications packet that was broadcast to a room in which this Listener is listening.

Specified by:
acceptOutOfBandMessage in interface RoomListener
Overrides:
acceptOutOfBandMessage in class GeneralUser
Parameters:
sender - The sender of the OOB message
room - The room in which the OOB message is being broadcast
body - A JSON object containing the OOB message. The contents of this message are not constrained.
See Also:
GeneralUser.acceptOutOfBandMessage(org.starhope.appius.user.AbstractUser, org.starhope.appius.game.Room, org.json.JSONObject)

acceptPrivateMessage

public void acceptPrivateMessage(AbstractUser speaker,
                                 String speech)
Description copied from interface: AbstractUser
Accept a private message from another user (a whisper)

Specified by:
acceptPrivateMessage in interface AbstractUser
Overrides:
acceptPrivateMessage in class AbstractNonPlayerCharacter
Parameters:
speaker - the person whispering
speech - what was whispered
See Also:
AbstractNonPlayerCharacter.acceptPrivateMessage(org.starhope.appius.user.AbstractUser, java.lang.String)

acceptPublicMessage

public void acceptPublicMessage(AbstractUser sender,
                                Room room,
                                String message)
Description copied from interface: RoomListener
Accept a public chat message or /emote.

Specified by:
acceptPublicMessage in interface RoomListener
Overrides:
acceptPublicMessage in class AbstractNonPlayerCharacter
Parameters:
sender - The speaker
room - The room in which the words were spoken
message - The spoken text or /emote
See Also:
AbstractNonPlayerCharacter.acceptPublicMessage(org.starhope.appius.user.AbstractUser, org.starhope.appius.game.Room, java.lang.String)

acceptPublicMessage

public void acceptPublicMessage(AbstractUser sender,
                                String message)
Description copied from interface: RoomListener
Accept a public chat message. This prototype does not specify the room, on the (potentially invalid) assumption that the room listener doesn't care from which room the speech was made.

Specified by:
acceptPublicMessage in interface RoomListener
Overrides:
acceptPublicMessage in class AbstractNonPlayerCharacter
Parameters:
sender - The speaker
message - The spoken text or /emote
See Also:
AbstractNonPlayerCharacter.acceptPublicMessage(org.starhope.appius.user.AbstractUser, java.lang.String)

acceptSuccessReply

public void acceptSuccessReply(String command,
                               org.json.JSONObject jsonData,
                               Room room)
Specified by:
acceptSuccessReply in interface AbstractUser
Overrides:
acceptSuccessReply in class AbstractNonPlayerCharacter
Parameters:
command - WRITEME
jsonData - WRITEME
room - WRITEME
See Also:
AbstractNonPlayerCharacter.acceptSuccessReply(java.lang.String, org.json.JSONObject, org.starhope.appius.game.Room)

acceptUserVariableUpdate

public void acceptUserVariableUpdate(AbstractUser user,
                                     String varName,
                                     String varValue)
Description copied from interface: RoomListener
Receive notification of the change of an user variable

Specified by:
acceptUserVariableUpdate in interface RoomListener
Overrides:
acceptUserVariableUpdate in class GeneralUser
Parameters:
user - The user updating their variable
varName - The name of the variable (key)
varValue - The new value (null if unset)
See Also:
GeneralUser.acceptUserVariableUpdate(org.starhope.appius.user.AbstractUser, java.lang.String, java.lang.String)

ban

public void ban(AbstractUser u,
                String banReason)
         throws PrivilegeRequiredException
Specified by:
ban in interface AbstractUser
Parameters:
u - WRITEME
banReason - WRITEME
Throws:
PrivilegeRequiredException - WRITEME
See Also:
AbstractUser.ban(org.starhope.appius.user.AbstractUser, java.lang.String)

getInstanceID

protected int getInstanceID()
Specified by:
getInstanceID in class AbstractNonPlayerCharacter
Returns:
An unique ID for this instance of
See Also:
AbstractNonPlayerCharacter.getInstanceID()

getScriptRunner

public PlebeianScriptRunner getScriptRunner()
WRITEME: Document this method brpocock@star-hope.org

Specified by:
getScriptRunner in interface ScriptPuppet
Returns:
WRITEME

getShortLabel

public String getShortLabel()
Description copied from interface: ScriptPuppet
WRITEME: Document this method brpocock@star-hope.org

Specified by:
getShortLabel in interface ScriptPuppet
Returns:
the avatar label without any NPC instance ID's and such
See Also:
ScriptPuppet.getShortLabel()

seekRoom

public void seekRoom(Room r)
Description copied from interface: ScriptPuppet
WRITEME: Document this method brpocock@star-hope.org

Specified by:
seekRoom in interface ScriptPuppet
See Also:
ScriptPuppet.seekRoom(org.starhope.appius.game.Room)

tick

public void tick(long currentTime,
                 long deltaTime)
          throws UserDeadException
Description copied from interface: AcceptsMetronomeTicks
This method is called periodically from the metronome thread. To save computation, it receives both the current time since epoch in milliseconds at the start of the global tick propagation, and the delta time since the previous metronome tick.

Specified by:
tick in interface AcceptsMetronomeTicks
Overrides:
tick in class AbstractNonPlayerCharacter
Parameters:
currentTime - Time since epoch at the start of the global metronome propagation, as per System.currentTimeMillis()
deltaTime - Delta-time in milliseconds since the prior global metronome tick
Throws:
UserDeadException - if a user has died during this tick
See Also:
AbstractNonPlayerCharacter.tick(long, long)