mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-29 23:15:55 -04:00
345 lines
12 KiB
Plaintext
345 lines
12 KiB
Plaintext
|
|
include library.cloninglib;
|
|
include library.gcw;
|
|
include library.regions;
|
|
include library.scheduled_drop;
|
|
include library.utils;
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
trigger OnUniverseComplete()
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.OnUniverseComplete: trigger initialized.");
|
|
|
|
dictionary dctParams = new dictionary();
|
|
messageTo(self, "doSpawnSetup", dctParams, 60, true);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
messageHandler doSpawnSetup()
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: messageHandler initialized.");
|
|
|
|
//string strPlanet = regions.getPlanetNameByObjId(self);
|
|
|
|
string strPlanet = getNameForPlanetObject(self);
|
|
//string strPlanet = "blargh";
|
|
|
|
if(strPlanet==null)
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: Planet name for this object is NULL. Notify SWG Development.");
|
|
|
|
debugServerConsoleMsg(self, "Man you're so fucked. Your scenename is null. Go get justin!");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: Planet name for this object is: " +strPlanet);
|
|
|
|
debugServerConsoleMsg(self, "************************************BASE PLANET INITIALIZATION***************************************");
|
|
debugServerConsoleMsg(self, "onInitialize, my current scene is "+strPlanet);
|
|
debugServerConsoleMsg(self, "************************************BASE PLANET INITIALIZATION***************************************");
|
|
|
|
if(strPlanet != "tutorial" && !hasScript(self, "systems.spawning.spawn_master"))
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: Non-tutorial Planet detected. Attaching systems.spawning.spawn_master");
|
|
|
|
debugServerConsoleMsg(self, "************************************SPAWN ERROR****************************************************");
|
|
debugServerConsoleMsg(self, "No spawnmaster script found! Attaching one!");
|
|
debugServerConsoleMsg(self, "************************************SPAWN ERROR****************************************************");
|
|
attachScript(self, "systems.spawning.spawn_master");
|
|
}
|
|
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: doSpawnSetup complete.");
|
|
obj_id tatooinePlanet = getPlanetByName("tatooine");
|
|
if(isIdValid(tatooinePlanet) && exists(tatooinePlanet))
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: Tatooine Planet detected obj_id: "+tatooinePlanet);
|
|
if (!hasScript(tatooinePlanet, "event.planet_event_handler"))
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: Tatooine Planet detected. Script Not Attached. Attaching event.planet_event_handler");
|
|
attachScript (tatooinePlanet, "event.planet_event_handler");
|
|
}
|
|
scheduled_drop.instantiatePromotionsOnCluster();
|
|
}
|
|
else
|
|
{
|
|
CustomerServiceLog("holidayEvent", "planet_base.doSpawnSetup: Tatooine Planet not found!! Notify development.");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
trigger OnDetach()
|
|
{
|
|
|
|
//string strPlanet = regions.getPlanetNameByObjId(self);
|
|
string strPlanet = getCurrentSceneName();
|
|
if(strPlanet==null)
|
|
{
|
|
|
|
debugServerConsoleMsg(self, "Man you're so fucked. Your scenename is null. Go get justin!");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
string strRegionScript;
|
|
|
|
strRegionScript = "systems.spawning.spawn_regions.";
|
|
|
|
debugServerConsoleMsg(self, "region script name is "+strRegionScript+"regions_"+strPlanet);
|
|
|
|
detachScript(self, strRegionScript+"regions_"+strPlanet);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
messageHandler registerCloningFacility()
|
|
{
|
|
obj_id facilityId = params.getObjId("id"); // obj_id of the facility
|
|
string cloneName = params.getString("name"); // name of the cloning facility
|
|
string areaName = params.getString("buildout"); // buildout region that the facility is restricted to, "" for entire planet
|
|
obj_id areaId = params.getObjId("areaId"); // buildout region id
|
|
location facilityLoc = params.getLocation("loc"); // location of the facility
|
|
location facilityRespawn = params.getLocation("respawn"); // location to spawn the player at
|
|
int cloneType = params.getInt("type"); // flag for cloning facility restrictions
|
|
|
|
resizeable obj_id[] idList = utils.getResizeableObjIdArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_ID);
|
|
resizeable string[] nameList = utils.getResizeableStringArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_NAME);
|
|
resizeable string[] areaList = utils.getResizeableStringArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA);
|
|
resizeable obj_id[] areaIdList = utils.getResizeableObjIdArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA_ID);
|
|
resizeable location[] locList = utils.getResizeableLocationArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_LOC);
|
|
resizeable location[] respawnList = utils.getResizeableLocationArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_RESPAWN);
|
|
resizeable int[] cloneTypeList = utils.getResizeableIntArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_TYPE);
|
|
|
|
if (idList == null || areaList == null || areaIdList == null || locList == null || respawnList == null || cloneTypeList == null)
|
|
{
|
|
idList = utils.addElement(null, facilityId);
|
|
nameList = utils.addElement(null, cloneName);
|
|
areaList = utils.addElement(null, areaName);
|
|
areaIdList = utils.addElement(null, areaId);
|
|
locList = utils.addElement(null, facilityLoc);
|
|
respawnList = utils.addElement(null, facilityRespawn);
|
|
cloneTypeList = utils.addElement(null, cloneType);
|
|
}
|
|
else
|
|
{
|
|
int pos = utils.getElementPositionInArray(idList, facilityId);
|
|
if (pos >= 0)
|
|
{
|
|
nameList[pos] = cloneName;
|
|
areaList[pos] = areaName;
|
|
areaIdList[pos] = areaId;
|
|
locList[pos] = facilityLoc;
|
|
respawnList[pos] = facilityRespawn;
|
|
cloneTypeList[pos] = cloneType;
|
|
}
|
|
else
|
|
{
|
|
idList = utils.addElement(idList, facilityId);
|
|
nameList = utils.addElement(nameList, cloneName);
|
|
areaList = utils.addElement(areaList, areaName);
|
|
areaIdList = utils.addElement(areaIdList, areaId);
|
|
locList = utils.addElement(locList, facilityLoc);
|
|
respawnList = utils.addElement(respawnList, facilityRespawn);
|
|
cloneTypeList = utils.addElement(cloneTypeList, cloneType);
|
|
}
|
|
}
|
|
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_ID, idList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_NAME, nameList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA, areaList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA_ID, areaIdList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_LOC, locList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_RESPAWN, respawnList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_TYPE, cloneTypeList);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
messageHandler unregisterCloningFacility()
|
|
{
|
|
obj_id facilityId = params.getObjId("id");
|
|
|
|
resizeable obj_id[] idList = utils.getResizeableObjIdArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_ID);
|
|
resizeable string[] nameList = utils.getResizeableStringArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_NAME);
|
|
resizeable string[] areaList = utils.getResizeableStringArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA);
|
|
resizeable obj_id[] areaIdList = utils.getResizeableObjIdArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA_ID);
|
|
resizeable location[] locList = utils.getResizeableLocationArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_LOC);
|
|
resizeable location[] respawnList = utils.getResizeableLocationArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_RESPAWN);
|
|
resizeable int[] cloneTypeList = utils.getResizeableIntArrayScriptVar(self, cloninglib.VAR_PLANET_CLONE_TYPE);
|
|
|
|
if (idList != null && nameList != null && areaList != null && areaIdList != null && locList != null && respawnList != null && cloneTypeList != null)
|
|
{
|
|
int pos = utils.getElementPositionInArray(idList, facilityId);
|
|
if (pos >= 0)
|
|
{
|
|
idList = utils.removeElementAt(idList, pos);
|
|
nameList = utils.removeElementAt(nameList, pos);
|
|
areaList = utils.removeElementAt(areaList, pos);
|
|
areaIdList = utils.removeElementAt(areaIdList, pos);
|
|
locList = utils.removeElementAt(locList, pos);
|
|
respawnList = utils.removeElementAt(respawnList, pos);
|
|
cloneTypeList = utils.removeElementAt(cloneTypeList, pos);
|
|
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_ID, idList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_NAME, nameList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA, areaList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_AREA_ID, areaIdList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_LOC, locList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_RESPAWN, respawnList);
|
|
utils.setScriptVar(self, cloninglib.VAR_PLANET_CLONE_TYPE, cloneTypeList);
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// Schedule 1
|
|
// 1 Bestine
|
|
// 2 Dearic
|
|
// 3 Keren
|
|
|
|
// Schedule 2:
|
|
// 1 Bestine, Dearic
|
|
// 2 Dearic, Keren
|
|
// 3 Keren, Bestine
|
|
|
|
// Schedule 3:
|
|
// All three simultaneously.
|
|
|
|
void gcwInvasionMessage(obj_id self, obj_id citySequencer, string city)
|
|
{
|
|
if(isIdValid(self) && exists(self) && isIdValid(citySequencer))
|
|
{
|
|
LOG("gcwlog", "planet_base gcwInvasionTracker citySequencer: " + citySequencer);
|
|
|
|
utils.setScriptVar(self, "gcw.time." + city, getGameTime());
|
|
utils.setScriptVar(self, "gcw.object." + city, citySequencer);
|
|
utils.setScriptVar(self, "gcw.calendar_time." + city, getCalendarTime());
|
|
|
|
messageTo(citySequencer, "beginInvasion", null, 1.0f, false);
|
|
}
|
|
}
|
|
|
|
messageHandler gcwInvasionTracker()
|
|
{
|
|
if(params == null)
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
string city = params.getString("city");
|
|
obj_id sequencer = params.getObjId("sequencer");
|
|
|
|
int messageGameTime = params.getInt("gameTime" + city);
|
|
int lastTrackTime = utils.getIntScriptVar(self, "gcw.lastTrackTime." + city);
|
|
|
|
if(messageGameTime != lastTrackTime)
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int gameTime = getGameTime();
|
|
|
|
params.put("gameTime" + city, gameTime);
|
|
utils.setScriptVar(self, "gcw.lastTrackTime." + city, gameTime);
|
|
|
|
if(!isIdValid(sequencer))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int cityInvasionMaximum = gcw.gcwGetInvasionMaximumRunning();
|
|
|
|
if(cityInvasionMaximum <= 0)
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int scheduleTime = utils.getIntScriptVar(self, "gcw.calendar_time." + city);
|
|
|
|
int calendarTime = getCalendarTime();
|
|
|
|
int timeToInvasion = gcw.gcwGetNextInvasionTime(city);
|
|
|
|
if(timeToInvasion == 0)
|
|
{
|
|
timeToInvasion = 1;
|
|
}
|
|
|
|
utils.setScriptVar(self, "gcw.calendar_time." + city, calendarTime);
|
|
|
|
if(scheduleTime <= 0)
|
|
{
|
|
// The time has been calculated incorrectly? Let's retry the calculation in a little bit.
|
|
if(timeToInvasion < 0)
|
|
{
|
|
LOG("gcwlog", "gcwInvasionTracker city: " + city + " has an invalid time. Retrying the calculation.");
|
|
|
|
utils.removeScriptVar(self, "gcw.calendar_time." + city);
|
|
messageTo(self, "gcwInvasionTracker", params, 5.0f, false);
|
|
}
|
|
else
|
|
{
|
|
LOG("gcwlog", "gcwInvasionTracker city: " + city + " has not been run today. timeToInvasion: " + timeToInvasion);
|
|
|
|
messageTo(self, "gcwInvasionTracker", params, timeToInvasion, false);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if(timeToInvasion > 0)
|
|
{
|
|
LOG("gcwlog", "gcwInvasionTracker city: " + city + " is starting now. Next invasion after this one: " + timeToInvasion);
|
|
|
|
gcwInvasionMessage(self, sequencer, city);
|
|
messageTo(self, "gcwInvasionTracker", params, timeToInvasion, false);
|
|
}
|
|
else // Bad invasion time. Let's retry the calculation.
|
|
{
|
|
LOG("gcwlog", "gcwInvasionTracker city: " + city + " has an invalid time. Retrying the calculation.");
|
|
|
|
utils.removeScriptVar(self, "gcw.calendar_time." + city);
|
|
messageTo(self, "gcwInvasionTracker", params, 5.0f, false);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler gcwGetInvasionObject()
|
|
{
|
|
if(params == null)
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
dictionary newParams = new dictionary();
|
|
|
|
string cityName = params.getString("city");
|
|
obj_id whoToMessage = params.getObjId("object");
|
|
string message = params.getString("messageHandler");
|
|
|
|
if(utils.hasScriptVar(self, "gcw.object." + cityName))
|
|
{
|
|
obj_id invasionObject = utils.getObjIdScriptVar(self, "gcw.object." + cityName);
|
|
|
|
newParams.put("invasionObject", invasionObject);
|
|
|
|
messageTo(whoToMessage, message, newParams, 1.0f, false);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|