mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-08-01 01:15:59 -04:00
438 lines
14 KiB
Plaintext
438 lines
14 KiB
Plaintext
/**
|
|
* Copyright (c)2000-2002 Sony Online Entertainment Inc.
|
|
* All Rights Reserved
|
|
*
|
|
* Title: cloning_facility.script
|
|
* Description: script for cloning facilities
|
|
* @author $Author:$
|
|
* @version $Revision:$
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.player_structure;
|
|
include library.planetary_map;
|
|
include library.structure;
|
|
include library.city;
|
|
include library.cloninglib;
|
|
include library.regions;
|
|
include library.space_dungeon;
|
|
include library.utils;
|
|
include java.util.Enumeration;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string SCRIPT_CLONING_FACILITY = "structure.municipal.cloning_facility";
|
|
|
|
const string VAR_NUM_RESPAWN_TUBES = "numRespawnTubes";
|
|
const string VAR_CURRENT_RESPAWN_TUBE = "currentTube";
|
|
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
|
|
trigger OnAttach()
|
|
{
|
|
if ( player_structure.isCivic( self ) )
|
|
{
|
|
// Player city registration.
|
|
int city_id = getCityAtLocation( getLocation( self ), 0 );
|
|
city.setCloneInfo( city_id, getLocation( self ), cloninglib.getCloneSpawnLocation(self), self );
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnDetach()
|
|
{
|
|
obj_id planet = getPlanetByName(getCurrentSceneName());
|
|
if (isIdValid(planet))
|
|
{
|
|
dictionary params = new dictionary();
|
|
params.put("id", self);
|
|
messageTo(planet, "unregisterCloningFacility", params, 1.0f, false);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnInitialize()
|
|
{
|
|
if(!requestCloningFacilityRegistration(self))
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center "+self+" registration reports a failure. Attempted to register cloning center("+getTemplateName(self)+"/"+self+") but this action failed.");
|
|
}
|
|
|
|
int numberOfRetry = 0;
|
|
dictionary params = new dictionary();
|
|
params.put("number_of_retry", numberOfRetry);
|
|
messageTo(self, "retryInitializeCloningFacility", params, 120.0f, false);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
trigger OnDestroy()
|
|
{
|
|
if ( player_structure.isCivic( self ) )
|
|
{
|
|
// Player city deregistration.
|
|
int city_id = getLocatedInCityId( self );
|
|
city.setCloneInfo( city_id, null, null, null );
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id planet = getPlanetByName(getCurrentSceneName());
|
|
if (isIdValid(planet))
|
|
{
|
|
dictionary params = new dictionary();
|
|
params.put("id", self);
|
|
messageTo(planet, "unregisterCloningFacility", params, 1.0f, false);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/**
|
|
* Special trigger that should be attached to cloning facilities. This is used to tell the server
|
|
* which tube the player should be respawned in.
|
|
*
|
|
* @param tubeIndex to be filled with the index of the tube to respawn in
|
|
*
|
|
* @return ignored
|
|
*/
|
|
trigger OnGetRespawnLocation(modifiable_int tubeIndex)
|
|
{
|
|
// see if we have respawn tubes
|
|
deltadictionary scriptvars = self.getScriptVars();
|
|
int numTubes = scriptvars.getInt(VAR_NUM_RESPAWN_TUBES);
|
|
if ( numTubes > 0 )
|
|
{
|
|
// get the tube to respawn in
|
|
int currentTube = scriptvars.getInt(VAR_CURRENT_RESPAWN_TUBE);
|
|
tubeIndex.set(currentTube++);
|
|
|
|
// set the next tube to respawn in
|
|
if ( currentTube == numTubes )
|
|
currentTube = 0;
|
|
scriptvars.put(VAR_CURRENT_RESPAWN_TUBE, currentTube);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
|
|
|
|
/***** MESSAGEHANDLERS *************************************************/
|
|
|
|
messageHandler registerCloningFacility()
|
|
{
|
|
// get datatable entry
|
|
string myTemplate = getTemplateName(self);
|
|
dictionary facilityData = new dictionary();
|
|
|
|
if (params.containsKey("facilityData"))
|
|
{
|
|
facilityData = params.getDictionary("facilityData");
|
|
}
|
|
else
|
|
{
|
|
facilityData = dataTableGetRow(structure.DATATABLE_CLONING_FACILITY_RESPAWN, myTemplate);
|
|
}
|
|
|
|
// register with the planet
|
|
string planetName = getCurrentSceneName();
|
|
obj_id planet = getPlanetByName(planetName);
|
|
if (isIdValid(planet))
|
|
{
|
|
location spawnLoc = cloninglib.getCloneSpawnLocation(getLocation(self), facilityData);
|
|
if ( spawnLoc != null )
|
|
{
|
|
if (regions.isInPvPRegion(self))
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "Attempted to register cloning center("+getTemplateName(self)+"/"+self+") but was within a PvP region.)");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int cloneType = 0;
|
|
if (facilityData != null)
|
|
cloneType = facilityData.getInt("CLONE_TYPE");
|
|
|
|
dictionary data = new dictionary();
|
|
data.put("id", self);
|
|
location facilityLoc = getLocation(self);
|
|
data.put("loc", facilityLoc);
|
|
data.put("respawn", spawnLoc);
|
|
data.put("type", cloneType);
|
|
|
|
string cloneName = getCloneName(cloneType, facilityData.getString("NAME"));
|
|
if (cloneName == null)
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "Unable to determine facility name for Cloning Facility("+getTemplateName(self)+"/"+self+") at location("+getLocation(self)+") - Waiting...");
|
|
messageTo(self, "registerCloningFacility", params, 180.0f, false);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
data.put("name", cloneName);
|
|
|
|
obj_id pobId = null;
|
|
if (space_dungeon.isSpaceDungeon(self) || hasObjVar(self, "isControllerObject"))
|
|
{
|
|
pobId = self;
|
|
}
|
|
else
|
|
{
|
|
pobId = getTopMostContainer(self);
|
|
if (pobId == self) pobId = obj_id.NULL_ID;
|
|
}
|
|
data.put("areaId", pobId);
|
|
|
|
location facilityWorldLoc = getWorldLocation(self);
|
|
string buildoutName = cloninglib.getBuildoutAreaName(facilityWorldLoc.x, facilityWorldLoc.z);
|
|
dictionary cloneAreaList = cloninglib.getCloningAreas(planetName, buildoutName);
|
|
|
|
CustomerServiceLog("Cloning_Center", "Registering Cloning Facility("+getTemplateName(self)+"/"+self+") at location("+getLocation(self)+") spawnLoc("+spawnLoc+") cloneType("+cloneType+")");
|
|
|
|
int idx = 0;
|
|
while (cloneAreaList.containsKey("scene_"+idx))
|
|
{
|
|
string cloneScene = cloneAreaList.getString("scene_"+idx);
|
|
string cloneArea = cloneAreaList.getString("area_"+idx);
|
|
|
|
data.put("buildout", cloneArea);
|
|
|
|
obj_id scene = getPlanetByName(cloneScene);
|
|
if (isIdValid(scene))
|
|
{
|
|
messageTo(scene, "registerCloningFacility", data, 1.0f, false);
|
|
CustomerServiceLog("Cloning_Center", "Mapping Cloning Region("+getTemplateName(self)+"/"+self+") to "+cloneScene+"("+cloneArea+")");
|
|
}
|
|
else
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "Failed to map clone region("+getTemplateName(self)+"/"+self+") invalid scene name "+cloneScene);
|
|
}
|
|
idx++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
LOG("DESIGNER_FATAL","************* registerCloningFacility ****************");
|
|
LOG("DESIGNER_FATAL","spawnLoc was returned as null & therefore aborted facility registration");
|
|
LOG("DESIGNER_FATAL","facility = " + self + " on planet = " + getCurrentSceneName());
|
|
LOG("DESIGNER_FATAL","facility location = " + getLocation(self).toString());
|
|
LOG("DESIGNER_FATAL","facility template = " + getTemplateName(self));
|
|
CustomerServiceLog("Cloning_Center", "Attempted to register cloning center but spawn location was null: ("+getTemplateName(self)+"/"+self+") failed to register on planet("+getCurrentSceneName()+")");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "Attempted to register cloning center("+getTemplateName(self)+"/"+self+") but could not find planet object for("+getCurrentSceneName()+")");
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
string getCloneName(obj_id self)
|
|
{
|
|
string myTemplate = getTemplateName(self);
|
|
|
|
dictionary facilityData = dataTableGetRow(structure.DATATABLE_CLONING_FACILITY_RESPAWN, myTemplate);
|
|
|
|
if (facilityData == null)
|
|
return "@base_player:clone_location_unknown";
|
|
|
|
return getCloneName(facilityData.getInt("CLONE_TYPE"), facilityData.getString("NAME"));
|
|
}
|
|
|
|
string getCloneName(int cloneType, string nameOverride)
|
|
{
|
|
obj_id self = getSelf();
|
|
|
|
string cloneName = "@base_player:clone_location_unknown";
|
|
switch (cloneType)
|
|
{
|
|
case cloninglib.CLONE_TYPE_STANDARD:
|
|
case cloninglib.CLONE_TYPE_PLAYER_CITY:
|
|
case cloninglib.CLONE_TYPE_RESTRICTED:
|
|
map_location cl = getPlanetaryMapLocation(self);
|
|
if ( cl != null )
|
|
{
|
|
cloneName = cl.getLocationName();
|
|
}
|
|
else if (nameOverride != null && nameOverride != "")
|
|
{
|
|
cloneName = nameOverride;
|
|
}
|
|
else
|
|
{
|
|
cloneName = null;
|
|
}
|
|
break;
|
|
|
|
case cloninglib.CLONE_TYPE_JEDI_ONLY:
|
|
location spawnLoc = cloninglib.getCloneSpawnLocation(self);
|
|
cloneName = "@base_player:clone_location_force_shrine ("+(int)spawnLoc.x+", "+(int)spawnLoc.z+")";
|
|
break;
|
|
|
|
case cloninglib.CLONE_TYPE_LIGHT_JEDI_ONLY:
|
|
case cloninglib.CLONE_TYPE_DARK_JEDI_ONLY:
|
|
cloneName = "@base_player:clone_location_jedi_enclave";
|
|
break;
|
|
case cloninglib.CLONE_TYPE_FACTION_IMPERIAL:
|
|
cloneName = nameOverride;
|
|
break;
|
|
case cloninglib.CLONE_TYPE_FACTION_REBEL:
|
|
cloneName = nameOverride;
|
|
break;
|
|
case cloninglib.CLONE_TYPE_PVP_REGION_ADVANCED_IMPERIAL:
|
|
cloneName = nameOverride;
|
|
break;
|
|
case cloninglib.CLONE_TYPE_PVP_REGION_ADVANCED_REBEL:
|
|
cloneName = nameOverride;
|
|
break;
|
|
case cloninglib.CLONE_TYPE_CAMP:
|
|
obj_id parent = getObjIdObjVar(self, "theater.parent");
|
|
|
|
if(isIdValid(parent))
|
|
{
|
|
string name = getName(parent);
|
|
|
|
if(name != null && !name.equals(""))
|
|
cloneName = name;
|
|
else
|
|
cloneName = nameOverride;
|
|
}
|
|
else
|
|
cloneName = nameOverride;
|
|
|
|
break;
|
|
|
|
case cloninglib.CLONE_TYPE_PRIVATE_INSTANCE:
|
|
cloneName = nameOverride;
|
|
break;
|
|
}
|
|
|
|
return cloneName;
|
|
}
|
|
messageHandler requestCloningData()
|
|
{
|
|
obj_id requester = params.getObjId("requester");
|
|
|
|
dictionary data = new dictionary();
|
|
|
|
string cloneName = getCloneName(self);
|
|
location facilityLoc = getLocation(self);
|
|
location spawnLoc = cloninglib.getCloneSpawnLocation(self);
|
|
|
|
data.put("faciltyId", self);
|
|
data.put("cloneName", cloneName);
|
|
data.put("facilityLoc", facilityLoc);
|
|
data.put("spawnLoc", spawnLoc);
|
|
|
|
messageTo(requester, "handleCloningDataUpdate", data, 0, false);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler retryInitializeCloningFacility()
|
|
{
|
|
// stop after 5 retry
|
|
int numberOfRetry = params.getInt("number_of_retry");
|
|
if (numberOfRetry >= 5)
|
|
return SCRIPT_CONTINUE;
|
|
|
|
string planetName = getCurrentSceneName();
|
|
if(planetName == null || planetName.length() <= 0)
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center "+self+" registration reports a failure. Attempted to register cloning center but could not get a valid planet name! Aborting registration.");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id planet = getPlanetByName(planetName);
|
|
if(!isValidId(planet))
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center "+self+" registration reports a failure. Attempted to register cloning center but could not get a valid planet OID for planet: "+planetName+". Aborting registration.");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id[] idList = utils.getObjIdArrayScriptVar(planet, cloninglib.VAR_PLANET_CLONE_ID);
|
|
if(idList != null && idList.length > 0)
|
|
{
|
|
for(int i = 0; i < idList.length - 1; i++)
|
|
{
|
|
if(idList[i] != self)
|
|
continue;
|
|
|
|
//the cloning facility has been registered
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
|
|
// if the idList doesnt have the clonign facility, try again
|
|
if(!requestCloningFacilityRegistration(self))
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center "+self+" registration reports a failure. Attempted to register cloning center("+getTemplateName(self)+"/"+self+") but this action failed.");
|
|
}
|
|
|
|
// check again in 1 minute and try again if for some reason we didn't get initialized
|
|
++numberOfRetry;
|
|
if (numberOfRetry < 5)
|
|
{
|
|
params.put("number_of_retry", numberOfRetry);
|
|
messageTo(self, "retryInitializeCloningFacility", params, 120.0f, false);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
boolean requestCloningFacilityRegistration(obj_id cloningFacility)
|
|
{
|
|
if(!isValidId(cloningFacility))
|
|
return false;
|
|
|
|
if ( player_structure.isCivic( cloningFacility ) )
|
|
{
|
|
planetary_map.addMapLocation( cloningFacility );
|
|
|
|
// Rick do I need to do this each time?
|
|
int city_id = getCityAtLocation( getLocation( cloningFacility ), 0 );
|
|
if(city_id < 0)
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center (which is "+cloningFacility+") could not continue the planet registration process because the city_id was invalid. Registeration of cloning center("+getTemplateName(cloningFacility)+"/"+cloningFacility+") aborted.");
|
|
return false;
|
|
}
|
|
|
|
city.setCloneInfo( city_id, getLocation( cloningFacility ), cloninglib.getCloneSpawnLocation(cloningFacility), cloningFacility );
|
|
}
|
|
|
|
// get datatable entry
|
|
string myTemplate = getTemplateName(cloningFacility);
|
|
if(myTemplate == null || myTemplate.length() <= 0)
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center which is "+cloningFacility+" could not continue the planet registration process because the object template for the cloning center was invalid. Registeration of cloning center("+getTemplateName(cloningFacility)+"/"+cloningFacility+") aborted.");
|
|
return false;
|
|
}
|
|
|
|
dictionary facilityData = dataTableGetRow(structure.DATATABLE_CLONING_FACILITY_RESPAWN, myTemplate);
|
|
if(facilityData == null)
|
|
{
|
|
CustomerServiceLog("Cloning_Center", "The cloning center (which is "+cloningFacility+" of template: "+myTemplate+") was not found in the datatables/structure/municipal/cloning_facility_respawn.iff table. Registeration aborted.");
|
|
return false;
|
|
}
|
|
|
|
dictionary dict = new dictionary();
|
|
dict.put("facilityData", facilityData);
|
|
|
|
// determine how many spawning tubes we have
|
|
int numTubes = 0;
|
|
if (facilityData != null)
|
|
numTubes = facilityData.getInt(structure.DATATABLE_COL_TUBES);
|
|
if ( numTubes > 0 )
|
|
{
|
|
deltadictionary scriptvars = cloningFacility.getScriptVars();
|
|
scriptvars.put(VAR_NUM_RESPAWN_TUBES, numTubes);
|
|
scriptvars.put(VAR_CURRENT_RESPAWN_TUBE, 0);
|
|
}
|
|
|
|
messageTo(cloningFacility, "registerCloningFacility", dict, 60.0f, false);
|
|
return true;
|
|
} |