org.starhope.appius.game
Class GameEvent

java.lang.Object
  extended by org.starhope.appius.game.GameEvent
All Implemented Interfaces:
Comparable<Object>, RoomListener, AcceptsMetronomeTicks, HasName
Direct Known Subclasses:
LaserTagGame, PropsWeather

public abstract class GameEvent
extends Object
implements AcceptsMetronomeTicks, RoomListener, Comparable<Object>

A GameEvent is a room-wide (or multi-room) game that occurs within the larger context of the game. Think “arena” or similar.

Author:
brpocock@star-hope.org

Field Summary
private  boolean endingSolo
          Shitty recursion guard endingSolo (GameEvent)
protected  boolean freezeTag
          freeze game actions
protected  char gameCode
          the one-char identifier for this game
protected  GameStateFlag gameState
          the current game state (mode)
private  ConcurrentHashMap<Integer,Integer> playerEvents
          the events in the global events table for each player, used for recording scores
protected  ConcurrentSkipListSet<Integer> players
          the players (in any room)
protected  ConcurrentSkipListSet<Room> rooms
          The rooms which this GameEvent controls
protected  ConcurrentHashMap<Integer,Integer> scores
          the current scores for all players
protected  ConcurrentSkipListSet<Room> scoreWatchRooms
          The rooms which this GameEvent will report the score to (in addition to rooms) scoreWatchRooms (GameEvent)
private static long serialVersionUID
          Java serialization unique ID serialVersionUID (long)
private static ConcurrentLinkedQueue<Map.Entry<GameEvent,GameStateFlag>> stateChangeQueue
          Queue for state changes in all GameEvents
private  long timer
          The game (countdown/play time) timer
private  Zone zone
          The zone zone (GameEvent)
 
Constructor Summary
protected GameEvent(Zone z, char c)
           
 
Method Summary
 void acceptCommand(AbstractUser u, Room arena, String[] command)
           
 void acceptCommand(GeneralUser user, Room room, Zone zone2, String[] command)
          Accept a developer-level command and react to it.
 void acceptGameStateChange(GameEvent game, GameStateFlag newGameState)
          This is an overriding method.
 void acceptObjectJoinRoom(Room room, RoomListener newListener)
          Notification that someone has entered the room.
 void acceptObjectPartRoom(Room room, RoomListener object)
          Notification that someone has left a room
 void acceptPublicMessage(AbstractUser sender, Room room, String message)
          This is an overriding method.
 void acceptUserVariableUpdate(AbstractUser user, String varName, String varValue)
          Receive notification of the change of an user variable
protected  void changeGameState(GameStateFlag newState)
           
 int compareTo(Object o)
           
protected  void decrementScore(int userID, int howMuch)
          decrease a user's score, but do not allow it to drop below 0.
 void destroySelf()
          Destroy this event — during Zone shutdown usually
 void disconnect()
          disconnect the game event from the associated rooms.
private  void endAllEvents()
          close out all pending events
 boolean equals(GameEvent other)
          Stupid case of equals override.
 boolean equals(Object other)
          This is an overriding method.
protected  long getCountdownDuration()
          Time (in ms) for the game countdown period timer.
 Set<AbstractUser> getEveryone()
           
 char getGameCode()
           
protected  long getGameDuration()
          Time (in ms) for the game play period timer.
abstract  String getGameEventPrefix()
          Get the prefix to be applied to event types for this game
 String getGameShortName()
           
protected  int getLeaderBonus()
           
 Set<AbstractUser> getPlayers()
           
 Room getRoom()
          This is an overriding method.
 Set<Room> getRooms()
          Get all of the rooms participating in this GameEvent
 Set<Room> getScoreWatchRooms()
          Get all of the rooms which are either participating in this GameEvent, or monitoring its scores
 Set<AbstractUser> getSpectators()
           
 long getTimer()
           
 Zone getZone()
          This is an overriding method.
 int hashCode()
          This is an overriding method.
 void incrementScore(int who, int howMuch)
           
static void propagateGameStateChange()
          Propagate any waiting game state changes to listeners
protected  void resetPlayers()
          Clear all players; clear all scores; put all users into player or spectator queues
protected  void sendEndEvents(String gameMoniker)
           
private  void sendScoreUpdate(NetIOThread playerThread, int score, AbstractUser player)
          Send an update on the score of the game to a player
protected  void sendStartEvents(String gameMoniker)
          Send the start of events to all players
private  void sendTimers()
          Send the game timers out to players and spectators.
 void tick(long currentTime, long deltaTime)
          This method is called periodically from the metronome thread.
 String toString()
          This is an overriding method.
protected  void updateRoomVars()
          Send updated room variables with the game score and status.
protected  void updateScore(AbstractUser who)
          notify a player of their score
protected  void updateScores()
          update all players of their scores and update room vars to boot
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.starhope.appius.util.HasName
getName
 
Methods inherited from interface org.starhope.appius.game.RoomListener
acceptGameAction, acceptOutOfBandMessage, acceptPublicMessage, acceptUserAction
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Java serialization unique ID serialVersionUID (long)

See Also:
Constant Field Values

stateChangeQueue

private static ConcurrentLinkedQueue<Map.Entry<GameEvent,GameStateFlag>> stateChangeQueue
Queue for state changes in all GameEvents


endingSolo

private boolean endingSolo
Shitty recursion guard endingSolo (GameEvent)


freezeTag

protected boolean freezeTag
freeze game actions


gameCode

protected final char gameCode
the one-char identifier for this game


gameState

protected GameStateFlag gameState
the current game state (mode)


playerEvents

private final ConcurrentHashMap<Integer,Integer> playerEvents
the events in the global events table for each player, used for recording scores


players

protected ConcurrentSkipListSet<Integer> players
the players (in any room)


rooms

protected final ConcurrentSkipListSet<Room> rooms
The rooms which this GameEvent controls


scores

protected final ConcurrentHashMap<Integer,Integer> scores
the current scores for all players


scoreWatchRooms

protected final ConcurrentSkipListSet<Room> scoreWatchRooms
The rooms which this GameEvent will report the score to (in addition to rooms) scoreWatchRooms (GameEvent)


timer

private long timer
The game (countdown/play time) timer


zone

private final Zone zone
The zone zone (GameEvent)

Constructor Detail

GameEvent

protected GameEvent(Zone z,
                    char c)
Parameters:
z - the zone in which the game is being played
c - the game code character
Method Detail

propagateGameStateChange

public static void propagateGameStateChange()
Propagate any waiting game state changes to listeners


acceptCommand

public void acceptCommand(AbstractUser u,
                          Room arena,
                          String[] command)
Parameters:
u - The operator issuing the command
arena - The room in which the operator's command is being executed
command - The command and parameters

acceptCommand

public void acceptCommand(GeneralUser user,
                          Room room,
                          Zone zone2,
                          String[] command)
Accept a developer-level command and react to it.

Parameters:
zone2 - The zone in which the game is attached (should be "zone" usually)
room - The room in which the invoking user exists
user - The invoking user
command - A command string split on whitespace

acceptGameStateChange

public void acceptGameStateChange(GameEvent game,
                                  GameStateFlag newGameState)
This is an overriding method.

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

acceptObjectJoinRoom

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

Specified by:
acceptObjectJoinRoom in interface RoomListener
Parameters:
room - The room
newListener - The thing (probably user) entering
See Also:
RoomListener.acceptObjectJoinRoom(Room, RoomListener)

acceptObjectPartRoom

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

Specified by:
acceptObjectPartRoom in interface RoomListener
Parameters:
room - The room
object - The thing (probably user) departing
See Also:
RoomListener.acceptObjectPartRoom(Room, RoomListener)

acceptPublicMessage

public void acceptPublicMessage(AbstractUser sender,
                                Room room,
                                String message)
This is an overriding method.

Specified by:
acceptPublicMessage in interface RoomListener
Parameters:
sender - The speaker
room - The room in which the words were spoken
message - The spoken text or /emote
See Also:
RoomListener.acceptPublicMessage(AbstractUser, Room, String)

acceptUserVariableUpdate

public void acceptUserVariableUpdate(AbstractUser user,
                                     String varName,
                                     String varValue)
Receive notification of the change of an user variable

Specified by:
acceptUserVariableUpdate in interface RoomListener
Parameters:
user - The user updating their variable
varName - The name of the variable (key)
varValue - The new value (null if unset)

changeGameState

protected void changeGameState(GameStateFlag newState)
Parameters:
newState - the new state of the game

compareTo

public int compareTo(Object o)
Specified by:
compareTo in interface Comparable<Object>
See Also:
Comparable.compareTo(java.lang.Object)

decrementScore

protected void decrementScore(int userID,
                              int howMuch)
decrease a user's score, but do not allow it to drop below 0.

Parameters:
userID - who lost points
howMuch - the number of points to lose

destroySelf

public void destroySelf()
Destroy this event — during Zone shutdown usually


disconnect

public void disconnect()
disconnect the game event from the associated rooms.


endAllEvents

private void endAllEvents()
close out all pending events


equals

public boolean equals(GameEvent other)
Stupid case of equals override.

Parameters:
other - other game event
Returns:
true if they're the same

equals

public boolean equals(Object other)
This is an overriding method.

Overrides:
equals in class Object
See Also:
Object.equals(java.lang.Object)

getCountdownDuration

protected long getCountdownDuration()
Time (in ms) for the game countdown period timer. Can be overridden by derived classes.

Returns:
The game countdown timer in ms

getEveryone

public Set<AbstractUser> getEveryone()
Returns:
all players and spectators

getGameCode

public char getGameCode()
Returns:
the gameCode

getGameDuration

protected long getGameDuration()
Time (in ms) for the game play period timer. Can be overridden by derived classes.

Returns:
The game play timer in ms

getGameEventPrefix

public abstract String getGameEventPrefix()
Get the prefix to be applied to event types for this game

Returns:
the string prefix used to find event types for this game

getGameShortName

public String getGameShortName()
Returns:
the short name of the game: the class name without its package (canonical) prefix

getLeaderBonus

protected int getLeaderBonus()
Returns:
bonus points awarded to the leader, or else anyone tied for max score

getPlayers

public Set<AbstractUser> getPlayers()
Returns:
all players

getRoom

public Room getRoom()
This is an overriding method.

Specified by:
getRoom in interface RoomListener
Returns:
the Room in which this NPC can be found. This can be null.
See Also:
RoomListener.getRoom()

getRooms

public Set<Room> getRooms()
Get all of the rooms participating in this GameEvent

Returns:
the set of all rooms participating in this GameEvent

getScoreWatchRooms

public Set<Room> getScoreWatchRooms()
Get all of the rooms which are either participating in this GameEvent, or monitoring its scores

Returns:
all rooms participating in, or watching the score from, this GameEvent

getSpectators

public Set<AbstractUser> getSpectators()
Returns:
all spectators

getTimer

public long getTimer()
Returns:
the timer

getZone

public Zone getZone()
This is an overriding method.

Specified by:
getZone in interface RoomListener
Returns:
the Zone in which this listener can be found
See Also:
RoomListener.getZone()

hashCode

public int hashCode()
This is an overriding method.

Overrides:
hashCode in class Object
See Also:
Object.hashCode()

incrementScore

public void incrementScore(int who,
                           int howMuch)
Parameters:
who - user ID of the player to have score increased
howMuch - increment amount, can be negative

resetPlayers

protected void resetPlayers()
Clear all players; clear all scores; put all users into player or spectator queues


sendEndEvents

protected void sendEndEvents(String gameMoniker)
Parameters:
gameMoniker - The unique event moniker for this game

sendScoreUpdate

private void sendScoreUpdate(NetIOThread playerThread,
                             int score,
                             AbstractUser player)
Send an update on the score of the game to a player

Parameters:
playerThread - The player's AppiusClaudiusCaecus server thread
score - the player's score
player - the player him/her-self

sendStartEvents

protected void sendStartEvents(String gameMoniker)
Send the start of events to all players

Parameters:
gameMoniker - The game's unique event moniker

sendTimers

private void sendTimers()
Send the game timers out to players and spectators. Uses the server time broadcast.


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
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)

toString

public String toString()
This is an overriding method.

Overrides:
toString in class Object
See Also:
Object.toString()

updateRoomVars

protected void updateRoomVars()
Send updated room variables with the game score and status.


updateScore

protected void updateScore(AbstractUser who)
notify a player of their score

Parameters:
who - the player whose score is being sent

updateScores

protected void updateScores()
update all players of their scores and update room vars to boot