com.tootsville.game
Class MagicBox

java.lang.Object
  extended by org.starhope.appius.game.GameEvent
      extended by com.tootsville.game.MagicBox
All Implemented Interfaces:
Comparable<Object>, RoomListener, AcceptsMetronomeTicks, HasName

public class MagicBox
extends GameEvent

Author:
edward.winkelman@gmail.com

Nested Class Summary
private  class MagicBox.Box
          Utility class for tracking unique boxes and handling setting and clearing room variables
 
Field Summary
private  MagicBox.Box curBox
          Current box
private  long lastPlaced
          Time a box was last placed
private  Room mbRoom
          Magic Box data room object
private static AtomicInteger nextInstanceID
           
private  Zone zone
          This instance's zone
 
Fields inherited from class org.starhope.appius.game.GameEvent
freezeTag, gameCode, gameState, players, rooms, scores, scoreWatchRooms
 
Constructor Summary
MagicBox(Zone z)
          WRITEME edward.winkelman@gmail.com Sep 28, 2010
 
Method Summary
 void acceptGameAction(AbstractUser u, org.json.JSONObject action)
          Broadcast message of a game action taking place
 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 acceptPublicMessage(AbstractUser from, String message)
          Accept a public chat message.
 void acceptUserAction(Room r, AbstractUser u)
          User actions (go/do actions) propagate through this channel.
private  void clearBox()
          WRITEME ewinkelman Oct 16, 2010
 void destroySelf()
          Destroy this event — during Zone shutdown usually
private  int getABox()
          WRITEME ewinkelman Oct 16, 2010
private  int getBoxID(String str)
          WRITEME ewinkelman Oct 16, 2010
private  Room getBoxRoom()
          WRITEME ewinkelman Oct 16, 2010
private  int getBoxWeight(String str)
          WRITEME ewinkelman Oct 16, 2010
 String getGameEventPrefix()
          Get the prefix to be applied to event types for this game
 String getName()
          Return a user-visible, unique name for this class.
private  org.starhope.appius.geometry.Coord2D getPointInRoom(Room room)
          Gets a spawn point for the magic box in the room
(package private)  void giveReward(AbstractUser user, int itemID)
          WRITEME ewinkelman Oct 16, 2010
(package private)  void putBox()
          WRITEME ewinkelman Oct 16, 2010
private  void rewardWithItem(AbstractUser user, int value)
          WRITEME ewinkelman Oct 16, 2010
private  void rewardWithPeanuts(AbstractUser user, int value)
          WRITEME ewinkleman Oct 16, 2010
 void tick(long currentTime, long deltaTime)
          This method is called periodically from the metronome thread.
 
Methods inherited from class org.starhope.appius.game.GameEvent
acceptCommand, acceptCommand, acceptGameStateChange, acceptObjectJoinRoom, acceptObjectPartRoom, acceptPublicMessage, acceptUserVariableUpdate, changeGameState, compareTo, decrementScore, disconnect, equals, equals, getCountdownDuration, getEveryone, getGameCode, getGameDuration, getGameShortName, getLeaderBonus, getPlayers, getRoom, getRooms, getScoreWatchRooms, getSpectators, getTimer, getZone, hashCode, incrementScore, propagateGameStateChange, resetPlayers, sendEndEvents, sendStartEvents, toString, updateRoomVars, updateScore, updateScores
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

nextInstanceID

private static final AtomicInteger nextInstanceID

curBox

private transient MagicBox.Box curBox
Current box


lastPlaced

private transient long lastPlaced
Time a box was last placed


mbRoom

private final transient Room mbRoom
Magic Box data room object


zone

private final transient Zone zone
This instance's zone

Constructor Detail

MagicBox

public MagicBox(Zone z)
         throws NotFoundException,
                GameLogicException
WRITEME edward.winkelman@gmail.com Sep 28, 2010

Parameters:
z - Zone in which haunted organ is placed
Throws:
NotFoundException - WRITEME
GameLogicException - WRITEME
Method Detail

acceptGameAction

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

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

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.

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

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.

Parameters:
from - The speaker
message - The spoken text or /emote
See Also:
RoomListener.acceptPublicMessage(org.starhope.appius.user.AbstractUser, java.lang.String)

acceptUserAction

public void acceptUserAction(Room r,
                             AbstractUser u)
Description copied from interface: RoomListener
User actions (go/do actions) propagate through this channel.

Parameters:
r - the room in which the user is taking an action
u - the user taking an action
See Also:
RoomListener.acceptUserAction(org.starhope.appius.game.Room, org.starhope.appius.user.AbstractUser)

clearBox

private void clearBox()
WRITEME ewinkelman Oct 16, 2010


destroySelf

public void destroySelf()
Description copied from class: GameEvent
Destroy this event — during Zone shutdown usually

Overrides:
destroySelf in class GameEvent
See Also:
GameEvent.destroySelf()

getABox

private int getABox()
             throws NotFoundException
WRITEME ewinkelman Oct 16, 2010

Returns:
WRITEME
Throws:
NotFoundException - WRITEME

getBoxID

private int getBoxID(String str)
WRITEME ewinkelman Oct 16, 2010

Parameters:
str - WRITEME
Returns:
WRITEME

getBoxRoom

private Room getBoxRoom()
                 throws NotFoundException
WRITEME ewinkelman Oct 16, 2010

Returns:
WRITEME
Throws:
NotFoundException - WRITEME

getBoxWeight

private int getBoxWeight(String str)
WRITEME ewinkelman Oct 16, 2010

Parameters:
str - WRITEME
Returns:
WRITEME

getGameEventPrefix

public String getGameEventPrefix()
Description copied from class: GameEvent
Get the prefix to be applied to event types for this game

Specified by:
getGameEventPrefix in class GameEvent
Returns:
the string prefix used to find event types for this game
See Also:
GameEvent.getGameEventPrefix()

getName

public String getName()
Description copied from interface: HasName
Return a user-visible, unique name for this class. This name may not necessarily be globally unique, but must be unique across all objects of this class. For example, having both a User and a Zone named “Lightning” is acceptable, but there may not be two users with the same name.

Returns:
a user-visible string name for this instance
See Also:
HasName.getName()

getPointInRoom

private org.starhope.appius.geometry.Coord2D getPointInRoom(Room room)
                                                     throws NotFoundException
Gets a spawn point for the magic box in the room

Parameters:
room - WRITEME
Returns:
WRITEME
Throws:
NotFoundException - WRITEME

giveReward

void giveReward(AbstractUser user,
                int itemID)
WRITEME ewinkelman Oct 16, 2010

Parameters:
user - WRITEME
itemID - WRITEME

putBox

void putBox()
WRITEME ewinkelman Oct 16, 2010


rewardWithItem

private void rewardWithItem(AbstractUser user,
                            int value)
WRITEME ewinkelman Oct 16, 2010

Parameters:
user - WRITEME
value - WRITEME

rewardWithPeanuts

private void rewardWithPeanuts(AbstractUser user,
                               int value)
WRITEME ewinkleman Oct 16, 2010

Parameters:
user - WRITEME
value - WRITEME

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