Files
dsrc/sku.0/sys.server/compiled/game/script/structure/house_control_device.script
T

241 lines
6.7 KiB
Plaintext

include library.utils;
include library.sui;
include library.player_structure;
include library.trace;
include player.base.base_player;
const string_id UNPACK_HOUSE = new string_id("sui", "unpack_house");
const string_id SID_NO_PLACING_STRUCTURES_IN_SPACE = new string_id("space/space_interaction", "no_placing_structures_in_space");
const string IN_USE_OBJVAR = "house_redeed.inUse";
trigger OnAttach()
{
setObjVar(self, "noTrade", 1);
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
setObjVar(self, "noTrade", 1);
removeObjVar(self, IN_USE_OBJVAR);
// add the scene restrictions if they are missing
if(!hasObjVar( self, player_structure.VAR_DEED_SCENE))
{
obj_id[] contents = getContents(self);
if(contents != null && contents.length == 1)
{
obj_id structure = contents[0];
if(isIdValid (structure))
{
if(hasObjVar(structure, player_structure.VAR_DEED_SCENE))
{
setObjVar(self, player_structure.VAR_DEED_SCENE, player_structure.getDeedScene(structure));
}
}
}
}
if(hasObjVar(self, "player_structure.deed.scene"))
{
string deed_scene = getStringObjVar( self, "player_structure.deed.scene" );
if (deed_scene != null && deed_scene.length() > 0)
{
//removed because harvesters no longer worked
if(deed_scene.equals("tatooine,lok,naboo,rori,dantooine,corellia,talus"))
{
CustomerServiceLog("playerStructure", "Deed " + self + " has had all invalid/old objvars removed.");
removeObjVar(self, "player_structure.deed.scene");
}
}
}
return SCRIPT_CONTINUE;
}
trigger OnDestroy()
{
obj_id player = utils.getContainingPlayer(self);
trace.log("housepackup", "Structure control device " + self + ", contained by %TU has been destroyed.", player, trace.TL_CS_LOG);
return SCRIPT_CONTINUE;
}
trigger OnLostItem(obj_id destContainer, obj_id transferer, obj_id item)
{
destroyObject(self);
return SCRIPT_CONTINUE;
}
trigger OnGetAttributes( obj_id objPlayer, string[] strNames, string[] strAttribs)
{
int intIndex= utils.getValidAttributeIndex(strNames);
if (intIndex==-1)
{
return SCRIPT_CONTINUE;
}
string strName = getAssignedName(self);
//LOG("space", "strName is "+strName);
if((strName!=null)&&(strName!=""))
{
strNames[intIndex] = "ship_name";
strAttribs[intIndex] = strName;
intIndex++;
}
if ( hasObjVar( self, player_structure.VAR_DEED_SCENE ) )
{
string deed_scene = player_structure.getDeedScene( self );
java.util.StringTokenizer st = new java.util.StringTokenizer( deed_scene, "," );
while ( st.hasMoreTokens() )
{
string curScene = st.nextToken();
strNames[intIndex] = "examine_scene";
strAttribs[intIndex] = curScene;
intIndex++;
}
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if(!utils.isNestedWithin(self, player))
{
return SCRIPT_CONTINUE;
}
if(isDead(player) || isIncapacitated(player))
{
return SCRIPT_CONTINUE;
}
mi.addRootMenu(menu_info_types.SERVER_MENU9, UNPACK_HOUSE);
mi.addRootMenu(menu_info_types.SERVER_TERMINAL_MANAGEMENT_STATUS, new string_id("player_structure", "management_status"));
mi.addRootMenu(menu_info_types.SERVER_TERMINAL_MANAGEMENT_PAY, new string_id("player_structure", "management_pay"));
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if(hasObjVar(self, "player_structure.deed.scene"))
{
string deed_scene = getStringObjVar( self, "player_structure.deed.scene" );
if (deed_scene != null && deed_scene.length() > 0)
{
//removed because harvesters no longer worked
if(deed_scene.equals("tatooine,lok,naboo,rori,dantooine,corellia,talus"))
{
CustomerServiceLog("playerStructure", "Deed " + self + " has had all invalid/old objvars removed.");
removeObjVar(self, "player_structure.deed.scene");
}
}
}
if(!utils.isNestedWithin(self, player))
{
return SCRIPT_CONTINUE;
}
if(isDead(player) || isIncapacitated(player))
{
return SCRIPT_CONTINUE;
}
obj_id[] contents = getContents(self);
if(contents == null || contents.length != 1)
{
return SCRIPT_CONTINUE;
}
obj_id structure = contents[0];
if(item == menu_info_types.SERVER_MENU9) // Unpack House
{
if(isSpaceScene())
{
sendSystemMessage(player, SID_NO_PLACING_STRUCTURES_IN_SPACE);
return SCRIPT_CONTINUE;
}
queueCommand(player, ##"placeStructureMode", self, "", COMMAND_PRIORITY_DEFAULT);
}
else if(item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_STATUS)
{
queueCommand(player, ##"structureStatus", structure, "", COMMAND_PRIORITY_DEFAULT);
}
else if (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_PAY)
{
queueCommand(player, ##"payMaintenance", structure, "", COMMAND_PRIORITY_DEFAULT);
}
return SCRIPT_CONTINUE;
}
trigger OnAboutToBeTransferred(obj_id destContainer, obj_id transferer)
{
return SCRIPT_OVERRIDE;
}
messageHandler OnPack()
{
// get the contained structure
obj_id[] contents = getContents(self);
if(contents == null || contents.length != 1)
{
return SCRIPT_CONTINUE;
}
obj_id structure = contents[0];
if(!isIdValid(structure))
return SCRIPT_CONTINUE;
// get the template of our contained house.
string template = getTemplateName(structure);
if(template == null || template == "")
return SCRIPT_CONTINUE;
// TODO: The code to get the number of lots should really be broken out of the
// player_structure.scriptlib "addStructure" call and be its own method.
// get the footprint template
string footprint_template = player_structure.getFootprintTemplate(template);
if(footprint_template == null || footprint_template=="")
return SCRIPT_CONTINUE;
// get the lot count for the footprint.
// Get our datatable entry index.
int idx = player_structure.getStructureTableIndex( template );
if ( idx == -1 )
return SCRIPT_CONTINUE; // no entry for the template.
int ignore_lots = dataTableGetInt( player_structure.PLAYER_STRUCTURE_DATATABLE, idx, player_structure.DATATABLE_COL_NO_LOT_REQ );
int struct_lots = 0;
if ( ignore_lots != 1 )
{
struct_lots = (player_structure.getNumberOfLots(footprint_template) / 4) - dataTableGetInt( player_structure.PLAYER_STRUCTURE_DATATABLE, idx, player_structure.DATATABLE_COL_LOT_REDUCTION );
if (struct_lots < 1)
struct_lots = 1;
}
// get our parent.
obj_id player = utils.getContainingPlayer(self);
if(!isIdValid(player))
return SCRIPT_CONTINUE;
// find out if he has the lot objvar
if(hasObjVar(player, base_player.CTS_LOT_COUNT))
{
// if so, increase its value by the number of lots that we contain.
struct_lots = struct_lots + getIntObjVar(player, base_player.CTS_LOT_COUNT);
}
// and set the lot count.
CustomerServiceLog("CharacterTransfer", "setting lot count adjustment(" + self + ", " + struct_lots + ")" );
setObjVar(player, base_player.CTS_LOT_COUNT, struct_lots);
return SCRIPT_CONTINUE;
}