org.starhope.appius.user.events
Class EventRecord

java.lang.Object
  extended by org.starhope.appius.util.SimpleDataRecord<EventRecord>
      extended by org.starhope.appius.user.events.EventRecord
All Implemented Interfaces:
com.whirlycott.cache.Cacheable, Serializable, Comparable<EventRecord>, CTime, DataRecord, HasSubversionRevision

public class EventRecord
extends SimpleDataRecord<EventRecord>

Events are any thing that happens in the world that can influence a player's currency or inventory.

XXX:contains SQL

 ALTER TABLE eventTypes CHANGE COLUMN outcome outcome INT NOT NULL DEFAULT 3;
 ALTER TABLE eventTypes ADD CONSTRAINT FOREIGN KEY (outcome) REFERENCES eventOutcomes (ID);
 ALTER TABLE eventTypes CHANGE COLUMN filename filename VARCHAR(64) NOT NULL DEFAULT '';
 ALTER TABLE eventTypes CHANGE COLUMN description description TEXT NOT NULL;
 

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

Field Summary
private  long completionTimestamp
          WRITEME: Document this brpocock@star-hope.org
private  long creationTimestamp
          WRITEME: Document this brpocock@star-hope.org
private  int creatorID
          WRITEME: Document this brpocock@star-hope.org
private  BigDecimal currencyAmountEarned
          WRITEME: Document this brpocock@star-hope.org
private  Currency currencyEarned
          WRITEME: Document this brpocock@star-hope.org
private  int earnedItemID
          WRITEME
private  int eventTypeID
          WRITEME: Document this brpocock@star-hope.org
private  int id
          WRITEME: Document this brpocock@star-hope.org
private  Collection<MedalType> medals
          WRITEME
private  BigDecimal points
          WRITEME: Document this brpocock@star-hope.org
private  boolean sendHighScore
          Whether to send high scores when printing this event
private static long serialVersionUID
          WRITEME: Document this ewinkelman
 
Fields inherited from class org.starhope.appius.util.SimpleDataRecord
myLoader, timeLastChanged, timeLastSaved
 
Constructor Summary
EventRecord()
          WRITEME: Document this constructor brpocock@star-hope.org
EventRecord(EventRecordLoader loader)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
 void addMedalEarned(int medalTypeID)
          WRITEME: Document this method brpocock@star-hope.org
 void addMedalEarned(String medal)
          WRITEME: Document this method brpocock@star-hope.org
 void cancel()
          Cancel an event in progress.
private  BigDecimal determineRewardScalar(EventOutcomeRecord outcome)
           
private  void doOutcome()
          perform actions specified by the outcome for this event type
 void end(BigDecimal score)
          End an event (such as a game or minigame) with a singular score
 void end(GenericItemReference itemPurchased)
          purchase something.
 void end(InventoryItem item, AbstractUser u)
          End a “gift” event whereby an user has given an item to another user
 void end(LinkedHashMap<Integer,Integer> sortedScores)
          End this event for this player.
 int getCacheableID()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 String getCacheableIdent()
          Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.
 long getCompletionTimestamp()
           
 long getCreationTimestamp()
           
private  AbstractUser getCreator()
          WRITEME: Document this method brpocock@star-hope.org
 int getCreatorID()
           
 BigDecimal getCurrencyAmountEarned()
           
 Currency getCurrencyEarned()
           
 EventType getEventType()
           
 int getEventTypeID()
           
 int getID()
           
 int getItemEarned()
           
 Collection<MedalType> getMedalsEarned()
          WRITEME WRITEME: Document this method brpocock@star-hope.org
 BigDecimal getPoints()
           
 String getSubversionRevision()
           Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.
 boolean isSendHighScore()
           
private  void pushHighScoresIntoJSON(PreparedStatement getHighScores, org.json.JSONObject wrapper)
          WRITEME: document this method (brpocock@star-hope.org, Dec 1, 2009)
protected  void putEventHighScoresIntoJSON(org.json.JSONObject wrapper)
          Get high score information from the database and return it as a JSON object
private  void rewardWithCurrency(EventOutcomeRecord outcome, BigDecimal scalar)
          Award any currency earned
private  void rewardWithItem(EventOutcomeRecord outcome, BigDecimal scalar)
          Award any item earned
private  GenericItemReference rewardWithItemFromCollection(EventOutcomeRecord outcome, BigDecimal scalar)
          WRITEME: Document this method brpocock@star-hope.org
private  void rewardWithMedal(EventOutcomeRecord outcome, BigDecimal scalar)
          Is a medal to be awarded at this point? Note that this will overrule any medal earned during the event, presently, as medals are in the events table.
 void setCompletionTimestamp(long newTimestamp)
           
 void setCompletionTimestamp(Timestamp timestamp)
           
 void setCreationTimestamp(long newTimestamp)
          WRITEME: Document this method brpocock@star-hope.org
 void setCreationTimestamp(Timestamp timestamp)
           
 void setCreator(AbstractUser user)
          WRITEME: Document this method brpocock@star-hope.org
 void setCreatorID(int newCreatorID)
          WRITEME: Document this method brpocock@star-hope.org
 void setCurrencyEarned(String currencyType, BigDecimal amount)
          WRITEME: Document this method brpocock@star-hope.org
 void setEventTypeID(int newEventTypeID)
          WRITEME: Document this method brpocock@star-hope.org
 void setID(int newID)
          set the event's unique ID (normally done only once at creation)
 void setItemEarned(int itemID)
          WRITEME: Document this method brpocock@star-hope.org
private  void setPoints(BigDecimal score)
          WRITEME: Document this method brpocock@star-hope.org
 void setPoints(long newPoints)
           
 void setSendHighScore(boolean whether)
           
 org.json.JSONObject toJSON()
          WRITEME: Document this method brpocock@star-hope.org
 String toString()
           
 
Methods inherited from class org.starhope.appius.util.SimpleDataRecord
changed, checkStale, compareTo, equals, finalize, getRecordLoader, getTimeLastChanged, getTimeLastSaved, hashCode, isBeingLoaded, markAsLoaded, markAsSaved, markForReload, onRemove, onRetrieve, onStore, save, setRecordLoader
 
Methods inherited from class java.lang.Object
clone, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
WRITEME: Document this ewinkelman

See Also:
Constant Field Values

completionTimestamp

private long completionTimestamp
WRITEME: Document this brpocock@star-hope.org


creationTimestamp

private long creationTimestamp
WRITEME: Document this brpocock@star-hope.org


creatorID

private int creatorID
WRITEME: Document this brpocock@star-hope.org


currencyAmountEarned

private BigDecimal currencyAmountEarned
WRITEME: Document this brpocock@star-hope.org


currencyEarned

private Currency currencyEarned
WRITEME: Document this brpocock@star-hope.org


earnedItemID

private int earnedItemID
WRITEME


eventTypeID

private int eventTypeID
WRITEME: Document this brpocock@star-hope.org


id

private int id
WRITEME: Document this brpocock@star-hope.org


medals

private final Collection<MedalType> medals
WRITEME


points

private BigDecimal points
WRITEME: Document this brpocock@star-hope.org


sendHighScore

private boolean sendHighScore
Whether to send high scores when printing this event

FIXME: Move this into EventType now that it's been refactored away from SQLPeerEnum

Constructor Detail

EventRecord

public EventRecord()
WRITEME: Document this constructor brpocock@star-hope.org


EventRecord

public EventRecord(EventRecordLoader loader)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
loader - WRITEME
Method Detail

addMedalEarned

public void addMedalEarned(int medalTypeID)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
medalTypeID - WRITEME

addMedalEarned

public void addMedalEarned(String medal)
                    throws NotFoundException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
medal - WRITEME
Throws:
NotFoundException - invalid medal name

cancel

public void cancel()
Cancel an event in progress. Awards no points and triggers outcomes.


determineRewardScalar

private BigDecimal determineRewardScalar(EventOutcomeRecord outcome)
Parameters:
outcome - the outcome being executed
Returns:
the reward scalar for this event

doOutcome

private void doOutcome()
perform actions specified by the outcome for this event type


end

public void end(BigDecimal score)
End an event (such as a game or minigame) with a singular score

Parameters:
score - score earned by this player

end

public void end(GenericItemReference itemPurchased)
         throws NonSufficientFundsException
purchase something.

Parameters:
itemPurchased - what was purchased
Throws:
NonSufficientFundsException - couldn't afford it

end

public void end(InventoryItem item,
                AbstractUser u)
         throws GameLogicException
End a “gift” event whereby an user has given an item to another user

Parameters:
item - the item being given as a gift
u - the user giving the item as a gift
Throws:
GameLogicException - if the transaction cannot be completed

end

public void end(LinkedHashMap<Integer,Integer> sortedScores)
End this event for this player. Note that the scores will be reported to him/her, so it's usually the case that this should happen simultaneously for all players

Parameters:
sortedScores - scores earned by all players of a multiplayer event.

getCacheableID

public int getCacheableID()
                   throws NotFoundException
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Returns:
an unique ID number
Throws:
NotFoundException - if the item doesn't have a distinct numeric ID
See Also:
DataRecord.getCacheableID()

getCacheableIdent

public String getCacheableIdent()
Description copied from interface: DataRecord
Note that all records must have either a numeric ID ( DataRecord.getCacheableID() or a string identifier ( DataRecord.getCacheableIdent() or both.

Returns:
an unique identifier string
See Also:
DataRecord.getCacheableIdent()

getCompletionTimestamp

public long getCompletionTimestamp()
Returns:
the completionTimestamp

getCreationTimestamp

public long getCreationTimestamp()
Returns:
the creationTimestamp

getCreator

private AbstractUser getCreator()
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

getCreatorID

public int getCreatorID()
Returns:
the creatorID

getCurrencyAmountEarned

public BigDecimal getCurrencyAmountEarned()
Returns:
amount of currency earned

getCurrencyEarned

public Currency getCurrencyEarned()
Returns:
currency type earned

getEventType

public EventType getEventType()
Returns:
the type of event of which this record describes once incidence

getEventTypeID

public int getEventTypeID()
Returns:
the eventTypeID

getID

public int getID()
Returns:
the id

getItemEarned

public int getItemEarned()
Returns:
the itemEarned

getMedalsEarned

public Collection<MedalType> getMedalsEarned()
WRITEME WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME

getPoints

public BigDecimal getPoints()
Returns:
the points

getSubversionRevision

public String getSubversionRevision()
Description copied from interface: HasSubversionRevision

Return the Subversion revision level of this class's source code file, as supplied via the special "$Rev: " sequence.

As an example,the Subversion revision string for this file is "$Rev: 1968 $"

 
 @Override
 public String getSubversionRevision () {
        return "$Rev: ";
 }
 

Returns:
The Subversion revision level for this class's source code file.
See Also:
HasSubversionRevision.getSubversionRevision()

isSendHighScore

public boolean isSendHighScore()
Returns:
whether to send high scores when printing this event

pushHighScoresIntoJSON

private void pushHighScoresIntoJSON(PreparedStatement getHighScores,
                                    org.json.JSONObject wrapper)
                             throws SQLException,
                                    org.json.JSONException
WRITEME: document this method (brpocock@star-hope.org, Dec 1, 2009)

Parameters:
getHighScores - WRITEME
wrapper - WRITEME
Throws:
SQLException - WRITEME
org.json.JSONException - WRITEME

putEventHighScoresIntoJSON

protected void putEventHighScoresIntoJSON(org.json.JSONObject wrapper)
Get high score information from the database and return it as a JSON object

Parameters:
wrapper - the JSON container to absorb the high score list

rewardWithCurrency

private void rewardWithCurrency(EventOutcomeRecord outcome,
                                BigDecimal scalar)
Award any currency earned

Parameters:
outcome - the outcome being executed
scalar - the reward scalar

rewardWithItem

private void rewardWithItem(EventOutcomeRecord outcome,
                            BigDecimal scalar)
Award any item earned

Parameters:
outcome - the event outcome being applied
scalar - the scalar used to determine the outcome

rewardWithItemFromCollection

private GenericItemReference rewardWithItemFromCollection(EventOutcomeRecord outcome,
                                                          BigDecimal scalar)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
outcome - WRITEME
scalar - WRITEME
Returns:
WRITEME

rewardWithMedal

private void rewardWithMedal(EventOutcomeRecord outcome,
                             BigDecimal scalar)
Is a medal to be awarded at this point? Note that this will overrule any medal earned during the event, presently, as medals are in the events table.

Parameters:
outcome - the outcome being executed
scalar - the reward scalar

setCompletionTimestamp

public void setCompletionTimestamp(long newTimestamp)
Parameters:
newTimestamp - the completionTimestamp to set

setCompletionTimestamp

public void setCompletionTimestamp(Timestamp timestamp)
Parameters:
timestamp - the new completion timestamp

setCreationTimestamp

public void setCreationTimestamp(long newTimestamp)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
newTimestamp - WRITEME

setCreationTimestamp

public void setCreationTimestamp(Timestamp timestamp)
Parameters:
timestamp - the new creation timestamp

setCreator

public void setCreator(AbstractUser user)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
user - the creator of the event

setCreatorID

public void setCreatorID(int newCreatorID)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
newCreatorID - WRITEME

setCurrencyEarned

public void setCurrencyEarned(String currencyType,
                              BigDecimal amount)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
currencyType - WRITEME
amount - WRITEME

setEventTypeID

public void setEventTypeID(int newEventTypeID)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
newEventTypeID - WRITEME

setID

public void setID(int newID)
set the event's unique ID (normally done only once at creation)

Parameters:
newID - the new ID

setItemEarned

public void setItemEarned(int itemID)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
itemID - WRITEME

setPoints

private void setPoints(BigDecimal score)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
score - WRITEME

setPoints

public void setPoints(long newPoints)
Parameters:
newPoints - the points to set

setSendHighScore

public void setSendHighScore(boolean whether)
Parameters:
whether - whether to send high scores when printing this event

toJSON

public org.json.JSONObject toJSON()
                           throws org.json.JSONException
WRITEME: Document this method brpocock@star-hope.org

Returns:
WRITEME
Throws:
org.json.JSONException - if the contents can't be encoded in JSON for some reason

toString

public String toString()
Overrides:
toString in class SimpleDataRecord<EventRecord>
See Also:
Object.toString()