org.starhope.appius.game.npc
Class ChatterBot

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

public class ChatterBot
extends AbstractNonPlayerCharacter

A ChatterBot mostly just wanders about and talks to players. They're instanced into each zone, though.

For purposes of Tootsvilleâ„¢ backward-compatibility, ChatterBots can be programmed with a SuperTootBot record. They still need a backing user account, however, which SuperTootBots did not check against.

For future ChatterBots, using a ConversationTree is recommended.

Author:
brpocock@star-hope.org

Field Summary
private  Deque<Goal> alternateGoal
          Alternate goals for the character
 String[] casualSpeechRingBuffer
          A ring buffer for casual comments that can be used to fill time.
 int casualSpeechRingPointer
          A pointer into the casual speech ring buffer.
private  double happiness
          How happy is the customer? Expressed as a tip rate.
private  long lastCasualSpeech
          The last time at which some casual chatter was emitted
private  long lastMovement
          last time moved
private  long lastSpoken
          The last time at which the NPC spoke (at all)
private static AtomicInteger nextID
           Provide an unique ID counter for multiple instances of the same cook character in different Zones at the same time.
private  Goal primaryGoal
          State, see Goal
private  Deque<String> toBeSpoken
          Things which need to be said (but we're pretending to be typing and giving people time to read, so they're not just being dumped down the pipeline)
private  ConversationTree tree
          tree of actions to undertake
private  String wantFood
          Food they want
 
Fields inherited from class org.starhope.appius.user.AbstractNonPlayerCharacter
buddyList, casualSpeechQueue, casualSpeechRate, instanceID, kalendor, lastActive
 
Fields inherited from class org.starhope.appius.user.GeneralUser
collisionBounds, currentRoom, facing, lastUserMovement, userRecord
 
Constructor Summary
ChatterBot(ConversationTree newTree)
          WRITEME: Document this constructor brpocock@star-hope.org
ChatterBot(Room newRoom, org.json.JSONObject superTootBot)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
 void acceptMessage(String title, String label, String content)
          Accept an administrative/moderator message with the full range of options.
 void acceptObjectJoinRoom(Room whichRoom, RoomListener object)
          Notification that someone has entered the room.
 void acceptObjectPartRoom(Room inRoom, RoomListener thing)
          Notification that someone has left a room
 void acceptOutOfBandMessage(AbstractUser sender, Room inRoom, org.json.JSONObject body)
          Accept an out-of-band communications packet that was broadcast to a room in which this Listener is listening.
 void acceptPublicMessage(AbstractUser sender, Room inRoom, String message)
          Accept a public chat message or /emote.
 void acceptPublicMessage(AbstractUser from, String message)
          Accept a public chat message.
 void acceptUserVariableUpdate(AbstractUser user, String varName, String varValue)
          Receive notification of the change of an user variable
 void ban(AbstractUser u, String banReason)
           
 double getHappiness()
           
protected  int getInstanceID()
           
 Goal getState()
           
 String getWantFood()
           
private  void goalCompleted()
          call this routine to pick a new goal
 void sendEarnings(Room roomEarnedIn, String string)
           
 void sendMigrate(AbstractZone refugeeZone)
          WRITEME: document this method (brpocock@star-hope.org, Jan 11, 2010)
 void sendWardrobe()
          WRITEME
 void setHappiness(double newHappiness)
           
 void setState(Goal newState)
           
 void setWantFood(String wantFoodNow)
           
 void speakCasually(String phrase)
          Say something, when there's time, if we get time.
 void tick(long currentTime, long deltaTime)
          This method is called periodically from the metronome thread.
 int timeToSpeak(String speech)
          WRITEME: Document this method brpocock@star-hope.org
 
Methods inherited from class org.starhope.appius.user.AbstractNonPlayerCharacter
acceptErrorReply, acceptGameAction, acceptGameStateChange, acceptPrivateMessage, acceptSuccessReply, acceptUserList, addBuddy, addGiftSubscription, addItem, canTalk, destroy, doTransport, equals, 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, sendOops, sendResponse, setLastActive, setMail, setParent, speak, toJSON, toSFSXML, toString, whenAtTarget
 
Methods inherited from class org.starhope.appius.user.GeneralUser
assertLocationUnlocked, assertStaffLevel, attend, canApproveSelf, canBetaTest, canEnterChatZone, canEnterMenuZone, compareTo, deleteVariable, doffClothes, getAge, getAgeGroup, getApprovedDateString, getCenterOfMass, getCollisionBounds, getCurrentAction, getD, getDialect, getDisplayName, getEndMovementTime, getExtraColor, getFacing, getGameEquipItems_JSON, getGameEquipItems, getHeight, getHouse, getInventory, getItemsByType, getItemsByType, getItemsByTypeAsArray, getKickedByUserID, getKickedReasonCode, getKickedUntil, getLocationForUpdate, getMass, getMoney, getPublicInfo, getRegisteredAt, getRegisteredDate, getRegisteredDateString, getRequestedName, getResponsibleMail, getRoom, getRoomNumber, getSizeScalar, getStaffLevel, getStartMovementTime, getStartT, getTarget, getTravelRate, getTravelStart, getUserID, getUserListIterator, getUserName, getUserVariables, getVariable, getVariables, getVariablesJSON, getVelocity, getWallet, getZone, hasStaffLevel, hasVariable, ignore, isActive, isApproved, isBanned, isCanceled, isKicked, isPaidMember, local_publicInfo, purchase, removeBuddy, resetVariables, setAgeGroupToSystem, setBaseColor, setCanTalk, setCenterOfMass, setCurrentAction, setExtraColor, setFacing, setLocation, setRoom, setStartT, setTarget, setTravelRate, setTravelStart, setVariable, setVariable, setVariables, setVelocity, unlockLocation, updateWallet
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

nextID

private static AtomicInteger nextID

Provide an unique ID counter for multiple instances of the same cook character in different Zones at the same time.


alternateGoal

private final Deque<Goal> alternateGoal
Alternate goals for the character


casualSpeechRingBuffer

public final String[] casualSpeechRingBuffer
A ring buffer for casual comments that can be used to fill time.


casualSpeechRingPointer

public int casualSpeechRingPointer
A pointer into the casual speech ring buffer. Casual statements are overwritten, as new ones are thought up.


happiness

private double happiness
How happy is the customer? Expressed as a tip rate. Begins at 18% and can vary from 5%, up. If it drops below 5%, they'll just walk out.


lastCasualSpeech

private long lastCasualSpeech
The last time at which some casual chatter was emitted


lastMovement

private long lastMovement
last time moved


lastSpoken

private long lastSpoken
The last time at which the NPC spoke (at all)


primaryGoal

private Goal primaryGoal
State, see Goal


toBeSpoken

private final Deque<String> toBeSpoken
Things which need to be said (but we're pretending to be typing and giving people time to read, so they're not just being dumped down the pipeline)


tree

private final ConversationTree tree
tree of actions to undertake


wantFood

private String wantFood
Food they want

Constructor Detail

ChatterBot

public ChatterBot(ConversationTree newTree)
           throws GameLogicException
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
newTree - WRITEME
Throws:
GameLogicException - WRITEME

ChatterBot

public ChatterBot(Room newRoom,
                  org.json.JSONObject superTootBot)
           throws NotFoundException,
                  GameLogicException,
                  org.json.JSONException
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
newRoom - WRITEME
superTootBot - WRITEME
Throws:
NotFoundException - WRITEME
GameLogicException - WRITEME
org.json.JSONException - WRITEME
Method Detail

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:
AbstractUser.acceptMessage(java.lang.String, java.lang.String, java.lang.String)

acceptObjectJoinRoom

public void acceptObjectJoinRoom(Room whichRoom,
                                 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:
whichRoom - The room
object - The thing (probably user) entering
See Also:
RoomListener.acceptObjectJoinRoom(org.starhope.appius.game.Room, org.starhope.appius.game.RoomListener)

acceptObjectPartRoom

public void acceptObjectPartRoom(Room inRoom,
                                 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:
inRoom - The room
thing - The thing (probably user) departing
See Also:
RoomListener.acceptObjectPartRoom(org.starhope.appius.game.Room, org.starhope.appius.game.RoomListener)

acceptOutOfBandMessage

public void acceptOutOfBandMessage(AbstractUser sender,
                                   Room inRoom,
                                   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
inRoom - 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:
RoomListener.acceptOutOfBandMessage(org.starhope.appius.user.AbstractUser, org.starhope.appius.game.Room, org.json.JSONObject)

acceptPublicMessage

public void acceptPublicMessage(AbstractUser sender,
                                Room inRoom,
                                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
inRoom - The room in which the words were spoken
message - The spoken text or /emote
See Also:
RoomListener.acceptPublicMessage(org.starhope.appius.user.AbstractUser, org.starhope.appius.game.Room, java.lang.String)

acceptPublicMessage

public void acceptPublicMessage(AbstractUser from,
                                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:
from - The speaker
message - The spoken text or /emote
See Also:
RoomListener.acceptPublicMessage(org.starhope.appius.user.AbstractUser, java.lang.String)

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:
RoomListener.acceptUserVariableUpdate(org.starhope.appius.user.AbstractUser, java.lang.String, java.lang.String)

ban

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

getHappiness

public double getHappiness()
Returns:
the happiness

getInstanceID

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

getState

public Goal getState()
Returns:
the state

getWantFood

public String getWantFood()
Returns:
the wantFood

goalCompleted

private void goalCompleted()
call this routine to pick a new goal


sendEarnings

public void sendEarnings(Room roomEarnedIn,
                         String string)
Specified by:
sendEarnings in interface AbstractUser
Overrides:
sendEarnings in class GeneralUser
Parameters:
roomEarnedIn - WRITEME
string - WRITEME
See Also:
AbstractUser.sendEarnings(org.starhope.appius.game.Room, java.lang.String)

sendMigrate

public void sendMigrate(AbstractZone refugeeZone)
                 throws UserDeadException
Description copied from interface: AbstractUser
WRITEME: document this method (brpocock@star-hope.org, Jan 11, 2010)

Specified by:
sendMigrate in interface AbstractUser
Overrides:
sendMigrate in class AbstractNonPlayerCharacter
Parameters:
refugeeZone - WRITEME
Throws:
UserDeadException - WRITEME
See Also:
AbstractUser.sendMigrate(org.starhope.appius.types.AbstractZone)

sendWardrobe

public void sendWardrobe()
Description copied from interface: AbstractUser
WRITEME

Specified by:
sendWardrobe in interface AbstractUser
Overrides:
sendWardrobe in class GeneralUser
See Also:
AbstractUser.sendWardrobe()

setHappiness

public void setHappiness(double newHappiness)
Parameters:
newHappiness - the happiness to set

setState

public void setState(Goal newState)
Parameters:
newState - the state to set

setWantFood

public void setWantFood(String wantFoodNow)
Parameters:
wantFoodNow - the wantFood to set

speakCasually

public void speakCasually(String phrase)
Say something, when there's time, if we get time.

Overrides:
speakCasually in class AbstractNonPlayerCharacter
Parameters:
phrase - a phrase to be casually spoken at some indeterminate time in the future

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:
AcceptsMetronomeTicks.tick(long, long)

timeToSpeak

public int timeToSpeak(String speech)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
speech - WRITEME
Returns:
WRITEME