Files
dsrc/sku.0/sys.server/compiled/game/script/event/planet_event_handler.script
T
2013-09-10 23:17:15 -07:00

328 lines
12 KiB
Plaintext

//This script is attached to Tatooine and is used to handle certain cluster wide events and data saving, such as life day competition.
/***** INCLUDES ********************************************************/
include library.holiday;
include library.utils;
/***** CONSTANTS *******************************************************/
const string EVENT_TIMESTAMP = "lifeday.time_stamp";
// ----------------------------------------------------------------------
/*
This script is attached via the planet.planet_base script. It is not
*/
trigger OnAttach()
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnAttach: trigger initialized.");
string lifedayRunning = getConfigSetting("GameServer", "lifeday");
if (lifedayRunning != null && !lifedayRunning.equals("false"))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnAttach: Life Day oconfig found.");
checkLifeDayData(self);
}
else if (hasObjVar(self, "lifeday"))
removeObjVar(self, "lifeday");
if(!checkForHolidayEventConfigs(self))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnAttach: checkForHolidayEventConfigs failed.");
}
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnInitialize: trigger initialized.");
string lifedayRunning = getConfigSetting("GameServer", "lifeday");
if (lifedayRunning != null && !lifedayRunning.equals("false"))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnInitialize: Life Day oconfig found.");
checkLifeDayData(self);
}
else if (hasObjVar(self, "lifeday"))
removeObjVar(self, "lifeday");
if(!checkForHolidayEventConfigs(self))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnInitialize: checkForHolidayEventConfigs failed.");
}
return SCRIPT_CONTINUE;
}
void checkLifeDayData(obj_id self)
{
if (!hasObjVar(self, EVENT_TIMESTAMP))
newTimeStamp(self);
if (!hasObjVar(self, "lifeday.emptyScoreBoard"))
setObjVar(self, "lifeday.emptyScoreBoard", "true");
if (hasObjVar(self, "lifeday.positionOne.playerScore"))
{
if (!newDay(self))
setObjVar(self, "lifeday.emptyScoreBoard", "false");
}
if (newDay(self))
{
removeObjVar(self, "lifeday");
setObjVar(self, "lifeday.emptyScoreBoard", "true");
newTimeStamp(self);
createDailyAlarmClock(self, "lifeDayDailyAlarm", null, 10, 0, 0);
}
}
//Checking if it's a new day
boolean newDay(obj_id self)
{
if (hasObjVar(self, EVENT_TIMESTAMP))
{
int now = getCalendarTime();
int then = getIntObjVar(self, EVENT_TIMESTAMP);
if (now > then)
return true;
else
return false;
}
return true;
}
//Set a new time stamp for 10 a.m GMT.
void newTimeStamp(obj_id self)
{
int now = getCalendarTime();
int secondsUntil = secondsUntilNextDailyTime(10, 0, 0);
int then = now + secondsUntil;
setObjVar(self, EVENT_TIMESTAMP, then);
createDailyAlarmClock(self, "lifeDayDailyAlarm", null, 10, 0, 0);
}
messageHandler setUpEventLeaderBoard()
{
CustomerServiceLog("holidayEvent", "planet_event_handler.setUpEventLeaderBoard: Event Leader Board Data being initialized.");
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
string eventVar = params.getString("eventVar");
if(eventVar == null || eventVar.length() <= 0)
return SCRIPT_CONTINUE;
//When the planet comes up, check for Event DATA, if it exists blow it away.
if(hasObjVar(self, holiday.PLANET_VAR_EVENT_PREFIX + eventVar))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.OnInitialize: Event data found: "+eventVar+", removing data so we can start new.");
removeObjVar(self, holiday.PLANET_VAR_EVENT_PREFIX + eventVar);
}
//if someone wants to create a better system than
//string comparison, please do.
if(eventVar.equals(holiday.PLANET_VAR_EMPIRE_DAY))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.setUpEventLeaderBoard: Setting up Empire Day data for the first time.");
if(!hasObjVar(self, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY + holiday.PLANET_VAR_SCORE_TIMESTAMP))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.setUpEventLeaderBoard: Setting up Empire Day score time stamp.");
//---SET TIME STAMP FOR SCORES
int now = getCalendarTime();
int secondsUntil = holiday.getEmpireDayLockoutDelay();
int then = now + secondsUntil;
setObjVar(self, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY + holiday.PLANET_VAR_SCORE_TIMESTAMP, then);
//---SEND A MESSAGE TO CHECK FOR REMOVAL AT TIME EXPIRE
//We already have the params, now we forward them
messageTo(self, "resetEventDataAfterDelay", params, secondsUntil, false);
CustomerServiceLog("holidayEvent", "planet_event_handler.setUpEventLeaderBoard: Sending message to reset scores in: "+secondsUntil+". Message has payload: "+params);
setupInitialEventScores(self, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY + holiday.PLANET_VAR_SCORE, 5, true);
}
}
return SCRIPT_CONTINUE;
}
messageHandler resetEventDataAfterDelay()
{
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Message Handler Initialized.");
if(params == null || params.isEmpty())
{
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Could not find params for reset.");
return SCRIPT_CONTINUE;
}
string eventVar = params.getString("eventVar");
if(eventVar == null || eventVar.length() <= 0)
{
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Could not find eventVar params for reset.");
return SCRIPT_CONTINUE;
}
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Event to reset: "+eventVar);
string eventConfig = params.getString("eventConfig");
if(eventConfig == null || eventConfig.length() <= 0)
{
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Could not find eventConfig params for reset.");
return SCRIPT_CONTINUE;
}
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Event config to reset: "+eventConfig);
string eventRunning = getConfigSetting("GameServer", eventConfig);
if(eventRunning != null && !eventRunning.equals("false"))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Event running: "+eventRunning);
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Message received with cargo. eventVar: "+eventVar+" with eventConfig: "+eventConfig+". The data is being reset because the delay time has expired as planned.");
messageTo (self, "setUpEventLeaderBoard", params, 3.0f, false);
}
else
{
CustomerServiceLog("holidayEvent", "planet_event_handler.resetEventDataAfterDelay: Message received with cargo. eventVar: "+eventVar+" with eventConfig: "+eventConfig+". The data WAS NOT reset because the event was not running.");
//The event is not running, remove unneeded vars.
if(hasObjVar(self, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY))
{
removeObjVar(self, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY);
}
}
return SCRIPT_CONTINUE;
}
messageHandler lifeDayDailyAlarm()
{
string lifedayRunning = getConfigSetting("GameServer", "lifeday");
if (lifedayRunning != null && !lifedayRunning.equals("false"))
checkLifeDayData(self);
else if (hasObjVar(self, "lifeday"))
removeObjVar(self, "lifeday");
return SCRIPT_CONTINUE;
}
messageHandler lifeDayScoreBoardUpdate()
{
if (params == null || params.isEmpty())
return SCRIPT_CONTINUE;
obj_id player = params.getObjId("player");
checkLifeDayData(self);
string scoreBoardEmpty = "true";
int thirdPlaceScore = 0;
int secondPlaceScore = 0;
int firstPlaceScore = 0;
if (hasObjVar(self, "lifeday.emptyScoreBoard"))
scoreBoardEmpty = getStringObjVar(self, "lifeday.emptyScoreBoard");
if (hasObjVar(self, "lifeday.positionThree.playerScore"))
thirdPlaceScore = getIntObjVar (self, "lifeday.positionThree.playerScore");
if (hasObjVar(self, "lifeday.positionTwo.playerScore"))
secondPlaceScore = getIntObjVar (self, "lifeday.positionTwo.playerScore");
if (hasObjVar(self, "lifeday.positionOne.playerScore"))
firstPlaceScore = getIntObjVar (self, "lifeday.positionOne.playerScore");
dictionary newParams = new dictionary();
newParams.put("scoreBoardEmpty", scoreBoardEmpty);
newParams.put("thirdPlaceScore", thirdPlaceScore);
newParams.put("secondPlaceScore", secondPlaceScore);
newParams.put("firstPlaceScore", firstPlaceScore);
messageTo (player, "scoreBoardCheck", newParams, 3.0f, false);
return SCRIPT_CONTINUE;
}
//sets up an initial score for any event
boolean setupInitialEventScores(obj_id planet, string scoreObjVar, int modifier, boolean faction)
{
if(!isValidId(planet) || !exists(planet))
return false;
if(scoreObjVar == null || scoreObjVar.length() <= 0)
return false;
if(modifier < 0)
return false;
if(!faction)
{
for(int i = 1, score = modifier; i <= holiday.MAX_NUMBER_OF_PLANET_HIGH_SCORES; i++)
{
int randomPosition = rand(0,holiday.DEFAULT_HIGH_SCORE_LIST.length-1);
string name = holiday.DEFAULT_HIGH_SCORE_LIST[randomPosition];
setObjVar(planet, scoreObjVar+".slot_"+i+holiday.PLANET_VAR_PLAYER_NAME, name);
setObjVar(planet, scoreObjVar+".slot_"+i+holiday.PLANET_VAR_PLAYER_SCORE, score);
score --;
}
}
else
{
for(int i = 1, score = modifier; i <= holiday.MAX_NUMBER_OF_PLANET_HIGH_SCORES; i++)
{
int randomPosition = rand(0,holiday.DEFAULT_HIGH_SCORE_LIST.length-1);
string name = holiday.DEFAULT_HIGH_SCORE_LIST[randomPosition];
setObjVar(planet, scoreObjVar+".slot_"+i+holiday.PLANET_VAR_PLAYER_FACTION_REB + holiday.PLANET_VAR_PLAYER_NAME, name);
setObjVar(planet, scoreObjVar+".slot_"+i+holiday.PLANET_VAR_PLAYER_FACTION_REB + holiday.PLANET_VAR_PLAYER_SCORE, score);
score --;
}
for(int i = 1, score = modifier; i <= holiday.MAX_NUMBER_OF_PLANET_HIGH_SCORES; i++)
{
int randomPosition = rand(0,holiday.DEFAULT_HIGH_SCORE_LIST.length-1);
string name = holiday.DEFAULT_HIGH_SCORE_LIST[randomPosition];
setObjVar(planet, scoreObjVar+".slot_"+i+holiday.PLANET_VAR_PLAYER_FACTION_IMP + holiday.PLANET_VAR_PLAYER_NAME, name);
setObjVar(planet, scoreObjVar+".slot_"+i+holiday.PLANET_VAR_PLAYER_FACTION_IMP + holiday.PLANET_VAR_PLAYER_SCORE, score);
score --;
}
}
return true;
}
boolean checkForHolidayEventConfigs(obj_id planet)
{
if(!isValidId(planet) || !exists(planet))
{
return false;
}
CustomerServiceLog("holidayEvent", "planet_event_handler.checkForHolidayEventConfigs: Function initialized.");
/*
EMPIRE DAY LEADER BOARD
get the server config -- do not use the
getCurrentUniverseWideEvents() because that wont
work for the planet coming up.
*/
string empiredayRunning = getConfigSetting("GameServer", "empireday_ceremony");
if(empiredayRunning != null && (empiredayRunning.equals("true") || empiredayRunning.equals("1")))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.checkForHolidayEventConfigs: EMPIRE DAY CONFIG FOUND.");
dictionary params = new dictionary();
params.put("eventVar", holiday.PLANET_VAR_EMPIRE_DAY);
params.put("eventConfig", "empireday_ceremony");
messageTo (planet, "setUpEventLeaderBoard", params, 3.0f, false);
}
else
{
//The event is not running, remove unneeded vars.
if(hasObjVar(planet, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY))
{
CustomerServiceLog("holidayEvent", "planet_event_handler.checkForHolidayEventConfigs: Var: "+holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY+" removed because the event was not running.");
removeObjVar(planet, holiday.PLANET_VAR_EVENT_PREFIX + holiday.PLANET_VAR_EMPIRE_DAY);
}
}
return true;
}