com.planet_ink.coffee_mud.Common
Class DefaultTimeClock

java.lang.Object
  extended by com.planet_ink.coffee_mud.Common.DefaultTimeClock
All Implemented Interfaces:
CMCommon, TimeClock, CMObject, Tickable, java.lang.Cloneable, java.lang.Comparable<CMObject>

public class DefaultTimeClock
extends java.lang.Object
implements TimeClock


Field Summary
protected  int[] dawnToDusk
           
protected  int day
           
protected  int daysInMonth
           
protected  int hoursInDay
           
 long lastTicked
           
protected  boolean loaded
           
protected  java.lang.String loadName
           
protected  int month
           
protected  java.lang.String[] monthsInYear
           
protected  long tickStatus
           
protected  int time
           
protected  java.lang.String[] weekNames
           
protected  int year
           
protected  java.lang.String[] yearNames
           
 
Fields inherited from interface com.planet_ink.coffee_mud.Common.interfaces.TimeClock
MOON_PHASES, PHASE_BLUE, PHASE_DESC, PHASE_FULL, PHASE_NEW, PHASE_WANDEQUARTER, PHASE_WANECRESCENT, PHASE_WANEGIBBOUS, PHASE_WAXCRESCENT, PHASE_WAXGIBBOUS, PHASE_WAXQUARTER, SEASON_DESCS, SEASON_FALL, SEASON_SPRING, SEASON_SUMMER, SEASON_WINTER, TIME_DAWN, TIME_DAY, TIME_DUSK, TIME_NIGHT, TOD_DESC
 
Fields inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
STATUS_AFFECT, STATUS_ALIVE, STATUS_BEHAVIOR, STATUS_CLASS, STATUS_DEAD, STATUS_END, STATUS_FIGHT, STATUS_MISC, STATUS_MISC2, STATUS_MISC3, STATUS_MISC4, STATUS_MISC5, STATUS_MISC6, STATUS_MISC7, STATUS_NOT, STATUS_OTHER, STATUS_RACE, STATUS_REBIRTH, STATUS_SCRIPT, STATUS_START, STATUS_WEATHER, TICKID_AREA, TICKID_CLAN, TICKID_CLANITEM, TICKID_DEADBODY_DECAY, TICKID_EMAIL, TICKID_EXIT_BEHAVIOR, TICKID_EXIT_REOPEN, TICKID_ITEM_BEHAVIOR, TICKID_ITEM_BOUNCEBACK, TICKID_LIGHT_FLICKERS, TICKID_LIVEAUCTION, TICKID_LONGERMASK, TICKID_MOB, TICKID_QUEST, TICKID_READYTOSTOP, TICKID_ROOM_BEHAVIOR, TICKID_ROOM_ITEM_REJUV, TICKID_SPELL_AFFECT, TICKID_TIMEAUCTION, TICKID_TRAP_DESTRUCTION, TICKID_TRAP_RESET, TICKMASK_SOLITARY, TICKS_PER_RLMIN, TIME_MILIS_PER_MUDHOUR, TIME_TICK, TIME_TICK_DOUBLE
 
Constructor Summary
DefaultTimeClock()
           
 
Method Summary
 int compareTo(CMObject o)
           
 CMObject copyOf()
          Similar to Cloneable.clone(), but does its best to make sure that any internal objects to this class are also copyOfed.
 TimeClock deriveClock(long millis)
          Using the current time and date as a yardstick, and assuming constant running and perfect timing, this method will derive a mud date and time from the given real life date/time in milliseconds.
 java.lang.String deriveEllapsedTimeString(long millis)
          Using the given number of milliseconds, this method will return a string describing the number of mud days, hours, etc that is represented by that amount of real time, assuming constant running and perfect timing.
 long deriveMillisAfter(TimeClock C)
          This method will discover the difference in mud hours between this time clock and the given EARLIER clock, assuming they use the same scale of measurement.
 int[] getDawnToDusk()
          Gets the dawn to dusk values, indexed by the TOD constants.
 int getDayOfMonth()
          Gets the current day of month.
 int getDaysInMonth()
          Gets the days in a month.
 int getDaysInWeek()
          Gets the number of days in each week
 int getHoursInDay()
          Gets the hours in a day.
 int getMonth()
          Gets the current month.
 java.lang.String[] getMonthNames()
          Gets the month names, in order, indexed by 0.
 int getMonthsInYear()
          Gets the months in a year.
 int getMoonPhase()
          Gets the moon phase an an enumeration.
 int getSeasonCode()
          Gets the season code.
 java.lang.String getShortestTimeDescription()
          Gets the shortest time description, showing only the date and time in brief numeric format.
 java.lang.String getShortTimeDescription()
          Gets a shorter time description, showing the date and time in full sentence format, but skipping lunar orientation.
 long getTickStatus()
          A coded status for this object during the period where its tick method is being called.
 int getTimeOfDay()
          Gets the current time of day (the hour).
 int getTODCode()
          Gets the TOD code, which is the sun-orientation (morning, evening, etc)
 java.lang.String[] getWeekNames()
          Gets the week names, which is the names of the days of each week, a string array indexed by the day of the week - 1.
 int getYear()
          Gets the current year.
 java.lang.String[] getYearNames()
          Gets the names of the year, an arbitrary sized list that is rotated through from year to year.
 java.lang.String ID()
          The CoffeeMud Java Class ID shared by all instances of this object.
 void initializeClass()
          Called ONCE after all objects are loaded, but before the map is read in during initialization.
 void initializeINIClock(CMProps page)
          Initialize ini clock by reading calendar values from the given properties page.
 java.lang.String name()
          The nice displayable name of this instance of this object
 CMObject newInstance()
          Returns a new instance of this class.
 void raiseLowerTheSunEverywhere()
           
 void save()
          Saves the current time/date information where ever its supposed to be saved.
 void setDawnToDusk(int dawn, int day, int dusk, int night)
          Sets the dawn to dusk values as absolute hours when that particular time of day begins.
 void setDayOfMonth(int d)
          Sets the current day of month.
 void setDaysInMonth(int d)
          Sets the days in a month.
 void setDaysInWeek(java.lang.String[] days)
          Sets the number of days in each week by naming each of them in a string array
 void setHoursInDay(int h)
          Sets the hours in a day.
 void setLoadName(java.lang.String name)
          Sets the name of this time object for the purposes of database loading and saving.
 void setMonth(int m)
          Sets the current month.
 void setMonthsInYear(java.lang.String[] months)
          Sets the months in year as a string array of names, arranged in order.
 boolean setTimeOfDay(int t)
          Sets the time of day (the hour).
 void setYear(int y)
          Sets the current year.
 void setYearNames(java.lang.String[] years)
          Sets the year names, which is an arbitrary sized list that is rotated through from year to year.
 boolean tick(Tickable ticking, int tickID)
          this is the method which is called periodically by the threading engine.
 void tickTock(int howManyHours)
          Alters the time/day by the given number of hours (forward or backward)
 java.lang.String timeDescription(MOB mob, Room room)
          Returns a complete description of the date, time, and lunar orientation, and day of the week in a full sentence word format.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tickStatus

protected long tickStatus

loaded

protected boolean loaded

loadName

protected java.lang.String loadName

year

protected int year

month

protected int month

day

protected int day

time

protected int time

hoursInDay

protected int hoursInDay

monthsInYear

protected java.lang.String[] monthsInYear

daysInMonth

protected int daysInMonth

dawnToDusk

protected int[] dawnToDusk

weekNames

protected java.lang.String[] weekNames

yearNames

protected java.lang.String[] yearNames

lastTicked

public long lastTicked
Constructor Detail

DefaultTimeClock

public DefaultTimeClock()
Method Detail

ID

public java.lang.String ID()
Description copied from interface: CMObject
The CoffeeMud Java Class ID shared by all instances of this object. Unlike the Java Class name, this method does not include package information. However, it must return a String value unique to its class category in the ClassLoader. Class categories include Libraries, Common, Areas, Abilities, Behaviors, CharClasses, Commands, Exits Locales, MOBS, Races, WebMacros, Basic Items, Armor, Weapons, ClanItems, MiscTech. The name is typically identical to the class name.

Specified by:
ID in interface CMObject
Returns:
the name of this class

name

public java.lang.String name()
Description copied from interface: Tickable
The nice displayable name of this instance of this object

Specified by:
name in interface Tickable
Returns:
the displayable name of this object instance

newInstance

public CMObject newInstance()
Description copied from interface: CMObject
Returns a new instance of this class.

Specified by:
newInstance in interface CMObject
Returns:
a new instance of this class

initializeClass

public void initializeClass()
Description copied from interface: CMObject
Called ONCE after all objects are loaded, but before the map is read in during initialization.

Specified by:
initializeClass in interface CMObject

getTickStatus

public long getTickStatus()
Description copied from interface: Tickable
A coded status for this object during the period where its tick method is being called. The statis is defined, at least in part, by constants in this interface STATUS_*. STATUS_NOT should be returned when the objects tick method is not currently in execution. It should never return STATUS_NOT when the objects tick method is in execution.

Specified by:
getTickStatus in interface Tickable
Returns:
the numeric status of this object
See Also:
Tickable.tick(Tickable, int)

setLoadName

public void setLoadName(java.lang.String name)
Description copied from interface: TimeClock
Sets the name of this time object for the purposes of database loading and saving. This is required for the save method to do anything at all.

Specified by:
setLoadName in interface TimeClock
Parameters:
name - the new load name
See Also:
TimeClock.save()

getHoursInDay

public int getHoursInDay()
Description copied from interface: TimeClock
Gets the hours in a day.

Specified by:
getHoursInDay in interface TimeClock
Returns:
the hours in a day
See Also:
TimeClock.setHoursInDay(int)

setHoursInDay

public void setHoursInDay(int h)
Description copied from interface: TimeClock
Sets the hours in a day.

Specified by:
setHoursInDay in interface TimeClock
Parameters:
h - the new hours in a day
See Also:
TimeClock.getHoursInDay()

getDaysInMonth

public int getDaysInMonth()
Description copied from interface: TimeClock
Gets the days in a month.

Specified by:
getDaysInMonth in interface TimeClock
Returns:
the days in a month
See Also:
TimeClock.setDaysInMonth(int)

setDaysInMonth

public void setDaysInMonth(int d)
Description copied from interface: TimeClock
Sets the days in a month.

Specified by:
setDaysInMonth in interface TimeClock
Parameters:
d - the new days in a month
See Also:
TimeClock.getDaysInMonth()

getMonthsInYear

public int getMonthsInYear()
Description copied from interface: TimeClock
Gets the months in a year.

Specified by:
getMonthsInYear in interface TimeClock
Returns:
the months in a year
See Also:
TimeClock.setMonthsInYear(String[]), TimeClock.getMonthNames()

getMonthNames

public java.lang.String[] getMonthNames()
Description copied from interface: TimeClock
Gets the month names, in order, indexed by 0.

Specified by:
getMonthNames in interface TimeClock
Returns:
the month names
See Also:
TimeClock.setMonthsInYear(String[]), TimeClock.getMonthNames()

setMonthsInYear

public void setMonthsInYear(java.lang.String[] months)
Description copied from interface: TimeClock
Sets the months in year as a string array of names, arranged in order.

Specified by:
setMonthsInYear in interface TimeClock
Parameters:
months - the new month names in a year
See Also:
TimeClock.getMonthNames(), TimeClock.getMonthsInYear()

getDawnToDusk

public int[] getDawnToDusk()
Description copied from interface: TimeClock
Gets the dawn to dusk values, indexed by the TOD constants. Each entry is an hour when the TOD starts. The order of the values is DAWN, DAY, DUSK, NIGHT.

Specified by:
getDawnToDusk in interface TimeClock
Returns:
the dawn to dusk array
See Also:
TimeClock.getTODCode(), TimeClock.setDawnToDusk(int, int, int, int), TimeClock.TIME_DAWN, TimeClock.TIME_DUSK, TimeClock.TIME_DAY, TimeClock.TIME_NIGHT, TimeClock.TOD_DESC

getYearNames

public java.lang.String[] getYearNames()
Description copied from interface: TimeClock
Gets the names of the year, an arbitrary sized list that is rotated through from year to year. (think: "year of the donkey", etc..)

Specified by:
getYearNames in interface TimeClock
Returns:
the year names, if any.
See Also:
TimeClock.setYearNames(String[])

setYearNames

public void setYearNames(java.lang.String[] years)
Description copied from interface: TimeClock
Sets the year names, which is an arbitrary sized list that is rotated through from year to year. (think: "year of the donkey", etc..)

Specified by:
setYearNames in interface TimeClock
Parameters:
years - the new years names
See Also:
TimeClock.getYearNames()

setDawnToDusk

public void setDawnToDusk(int dawn,
                          int day,
                          int dusk,
                          int night)
Description copied from interface: TimeClock
Sets the dawn to dusk values as absolute hours when that particular time of day begins.

Specified by:
setDawnToDusk in interface TimeClock
Parameters:
dawn - the dawn hour
day - the day hour
dusk - the dusk hour
night - the night hour
See Also:
TimeClock.getDawnToDusk(), TimeClock.getTODCode(), TimeClock.TIME_DAWN, TimeClock.TIME_DUSK, TimeClock.TIME_DAY, TimeClock.TIME_NIGHT, TimeClock.TOD_DESC

getWeekNames

public java.lang.String[] getWeekNames()
Description copied from interface: TimeClock
Gets the week names, which is the names of the days of each week, a string array indexed by the day of the week - 1.

Specified by:
getWeekNames in interface TimeClock
Returns:
the week names as an array of strings
See Also:
TimeClock.setDaysInWeek(String[]), TimeClock.getDaysInWeek()

getDaysInWeek

public int getDaysInWeek()
Description copied from interface: TimeClock
Gets the number of days in each week

Specified by:
getDaysInWeek in interface TimeClock
Returns:
the days in each week
See Also:
TimeClock.setDaysInWeek(String[]), TimeClock.getWeekNames()

setDaysInWeek

public void setDaysInWeek(java.lang.String[] days)
Description copied from interface: TimeClock
Sets the number of days in each week by naming each of them in a string array

Specified by:
setDaysInWeek in interface TimeClock
Parameters:
days - the new days in each week string array
See Also:
TimeClock.getDaysInWeek(), TimeClock.getWeekNames()

getShortestTimeDescription

public java.lang.String getShortestTimeDescription()
Description copied from interface: TimeClock
Gets the shortest time description, showing only the date and time in brief numeric format.

Specified by:
getShortestTimeDescription in interface TimeClock
Returns:
the shortest time description
See Also:
TimeClock.timeDescription(MOB, Room), TimeClock.getShortTimeDescription()

getShortTimeDescription

public java.lang.String getShortTimeDescription()
Description copied from interface: TimeClock
Gets a shorter time description, showing the date and time in full sentence format, but skipping lunar orientation.

Specified by:
getShortTimeDescription in interface TimeClock
Returns:
the short time description
See Also:
TimeClock.timeDescription(MOB, Room), TimeClock.getShortestTimeDescription()

initializeINIClock

public void initializeINIClock(CMProps page)
Description copied from interface: TimeClock
Initialize ini clock by reading calendar values from the given properties page. Does not load current values from anywhere.

Specified by:
initializeINIClock in interface TimeClock
Parameters:
page - the properties page

timeDescription

public java.lang.String timeDescription(MOB mob,
                                        Room room)
Description copied from interface: TimeClock
Returns a complete description of the date, time, and lunar orientation, and day of the week in a full sentence word format.

Specified by:
timeDescription in interface TimeClock
Parameters:
mob - the mob who wants to know the time
room - the room the room where the mob is wanting the time
Returns:
the string representing the date and time
See Also:
TimeClock.getShortTimeDescription(), TimeClock.getShortestTimeDescription()

getYear

public int getYear()
Description copied from interface: TimeClock
Gets the current year.

Specified by:
getYear in interface TimeClock
Returns:
the current year
See Also:
TimeClock.setYear(int)

setYear

public void setYear(int y)
Description copied from interface: TimeClock
Sets the current year.

Specified by:
setYear in interface TimeClock
Parameters:
y - the new year
See Also:
TimeClock.getYear()

getSeasonCode

public int getSeasonCode()
Description copied from interface: TimeClock
Gets the season code.

Specified by:
getSeasonCode in interface TimeClock
Returns:
the season code
See Also:
TimeClock.SEASON_DESCS, TimeClock.SEASON_FALL, TimeClock.SEASON_SPRING, TimeClock.SEASON_SUMMER, TimeClock.SEASON_WINTER

getMonth

public int getMonth()
Description copied from interface: TimeClock
Gets the current month.

Specified by:
getMonth in interface TimeClock
Returns:
the current month
See Also:
TimeClock.setMonth(int)

setMonth

public void setMonth(int m)
Description copied from interface: TimeClock
Sets the current month.

Specified by:
setMonth in interface TimeClock
Parameters:
m - the new month
See Also:
TimeClock.getMonth()

getMoonPhase

public int getMoonPhase()
Description copied from interface: TimeClock
Gets the moon phase an an enumeration.

Specified by:
getMoonPhase in interface TimeClock
Returns:
the moon phase as an enumeration
See Also:
TimeClock.MOON_PHASES, TimeClock.PHASE_DESC, TimeClock.PHASE_FULL, TimeClock.PHASE_NEW

getDayOfMonth

public int getDayOfMonth()
Description copied from interface: TimeClock
Gets the current day of month.

Specified by:
getDayOfMonth in interface TimeClock
Returns:
the day of month
See Also:
TimeClock.setDayOfMonth(int)

setDayOfMonth

public void setDayOfMonth(int d)
Description copied from interface: TimeClock
Sets the current day of month.

Specified by:
setDayOfMonth in interface TimeClock
Parameters:
d - the new day of month
See Also:
TimeClock.getDayOfMonth()

getTimeOfDay

public int getTimeOfDay()
Description copied from interface: TimeClock
Gets the current time of day (the hour).

Specified by:
getTimeOfDay in interface TimeClock
Returns:
the time of day (hour)
See Also:
TimeClock.setTimeOfDay(int)

getTODCode

public int getTODCode()
Description copied from interface: TimeClock
Gets the TOD code, which is the sun-orientation (morning, evening, etc)

Specified by:
getTODCode in interface TimeClock
Returns:
the TOD code
See Also:
TimeClock.setTimeOfDay(int), TimeClock.setDawnToDusk(int, int, int, int), TimeClock.TIME_DAWN, TimeClock.TIME_DUSK, TimeClock.TIME_DAY, TimeClock.TIME_NIGHT, TimeClock.TOD_DESC

setTimeOfDay

public boolean setTimeOfDay(int t)
Description copied from interface: TimeClock
Sets the time of day (the hour).

Specified by:
setTimeOfDay in interface TimeClock
Parameters:
t - the time of day (the hour)
Returns:
true, if the new time denotes a change of sun-orientation, false otherwise
See Also:
TimeClock.getTimeOfDay()

copyOf

public CMObject copyOf()
Description copied from interface: CMObject
Similar to Cloneable.clone(), but does its best to make sure that any internal objects to this class are also copyOfed.

Specified by:
copyOf in interface CMObject
Returns:
a clone of this object

deriveClock

public TimeClock deriveClock(long millis)
Description copied from interface: TimeClock
Using the current time and date as a yardstick, and assuming constant running and perfect timing, this method will derive a mud date and time from the given real life date/time in milliseconds.

Specified by:
deriveClock in interface TimeClock
Parameters:
millis - the milliseconds since 1970
Returns:
the time clock object representing that real life time
See Also:
TimeClock.deriveMillisAfter(TimeClock), TimeClock.deriveEllapsedTimeString(long)

deriveEllapsedTimeString

public java.lang.String deriveEllapsedTimeString(long millis)
Description copied from interface: TimeClock
Using the given number of milliseconds, this method will return a string describing the number of mud days, hours, etc that is represented by that amount of real time, assuming constant running and perfect timing.

Specified by:
deriveEllapsedTimeString in interface TimeClock
Parameters:
millis - the milliseconds of elapsed time represented
Returns:
the string representing the elapsed mud time
See Also:
TimeClock.deriveMillisAfter(TimeClock), TimeClock.deriveClock(long)

deriveMillisAfter

public long deriveMillisAfter(TimeClock C)
Description copied from interface: TimeClock
This method will discover the difference in mud hours between this time clock and the given EARLIER clock, assuming they use the same scale of measurement. It will then return the number of actual milliseconds would have elapsed, assuming constant running and perfect timing.

Specified by:
deriveMillisAfter in interface TimeClock
Parameters:
C - the earlier time clock object
Returns:
the number of milliseconds elapsed since the given clock
See Also:
TimeClock.deriveClock(long), TimeClock.deriveEllapsedTimeString(long)

raiseLowerTheSunEverywhere

public void raiseLowerTheSunEverywhere()

tickTock

public void tickTock(int howManyHours)
Description copied from interface: TimeClock
Alters the time/day by the given number of hours (forward or backward)

Specified by:
tickTock in interface TimeClock
Parameters:
howManyHours - the how many hours to alter the time by

save

public void save()
Description copied from interface: TimeClock
Saves the current time/date information where ever its supposed to be saved. Requires that setLoadName be called before.

Specified by:
save in interface TimeClock
See Also:
TimeClock.setLoadName(String)

tick

public boolean tick(Tickable ticking,
                    int tickID)
Description copied from interface: Tickable
this is the method which is called periodically by the threading engine. How often it is called depends on the parameters passed to the threadding engine when it is submitted for thread access. Typically the period is once per TIME_TICK period, but that is determined when the object is submitted to the thread engine.

Specified by:
tick in interface Tickable
Parameters:
ticking - a reference to this Tickable object
tickID - the TICKID_ constant describing this periodic call, as defined in Tickable
Returns:
true always, unless this object no longer wishes to ever tick again, in which case false
See Also:
Tickable, ServiceEngine, TickableGroup

compareTo

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