/** * Copyright (c)2000-2002 Sony Online Entertainment Inc. * All Rights Reserved * * Title: spawn_player.script * Description: this is the spawn system handler that lives on the player. It communicates with the master spawn object at set intervals * @author $Author:$ * @version $Revision:$ */ // Includes include library.buff; include library.craftinglib; include library.create; include library.datatable; include library.group; include library.locations; include library.regions; include library.skill; include library.space_utils; include library.spawning; include library.sui; include library.utils; inherits systems.spawning.spawn_base; trigger OnInitialize() { removeObjVar(self, "spawning.verboseMode"); return SCRIPT_CONTINUE; } commandHandler showSpawnRegion() { region[] rgnRegionList = getRegionsWithSpawnableAtPoint(getLocation(self), regions.SPAWN_TRUE); if(rgnRegionList==null) { rgnRegionList = getRegionsWithSpawnableAtPoint(getLocation(self), regions.SPAWN_DEFAULT); } if(rgnRegionList==null) { sendSystemMessageTestingOnly(self, "Catastrophic failure, no spawn region at this point"); return SCRIPT_CONTINUE; } region rgnOverloadRegion = null; region[] rgnOverloadRegions = getRegionsWithGeographicalAtPoint(getLocation(self), regions.GEO_OVERLOAD); if((rgnOverloadRegions!=null)&&(rgnOverloadRegions.length>0)) { rgnOverloadRegion = rgnOverloadRegions[rand(0, rgnOverloadRegions.length-1)]; } region rgnSpawnRegion = locations.getSmallestRegion(rgnRegionList); if(rgnOverloadRegion!=null) { sendSystemMessageTestingOnly(self, "Multiple Spawn Regions found : "); sendSystemMessageTestingOnly(self, "Overload region is "+rgnOverloadRegion.getName()); } else { sendSystemMessageTestingOnly(self, "Spawn Region:"); } sendSystemMessageTestingOnly(self, "Region: "+rgnSpawnRegion.getName()); return SCRIPT_CONTINUE; } commandHandler secretSpawnSpam() { if(hasObjVar(self, "spawning.verboseMode")) { removeObjVar(self, "spawning.verboseMode"); sendSystemMessageTestingOnly(self, "Verbose spawn checks disabled"); } else { setObjVar(self, "spawning.verboseMode", 1); sendSystemMessageTestingOnly(self, "Verbose spawning checks enabled"); } return SCRIPT_CONTINUE; } trigger OnAddedToWorld() { //attempt to apply crafting station buff icons for players //logging into a cell with stations messageTo(self, "checkStationCells", null, 2, false); return SCRIPT_CONTINUE; } // Consts trigger OnAttach() { //setObjVar(self, "intStopSpawner", 1); ////////LOG("player_spawner", "The spawn system is active. To turn it off say stopspawner"); //Uncomment this line to turn off the spawner by default //setObjVar(self, "intStopSpawner", 1); return SCRIPT_CONTINUE; } commandHandler createSpawningElement() { if(params=="") { sendSystemMessageTestingOnly(self, "You must provide a datatable and an index for this to work properly"); return SCRIPT_CONTINUE; } int intIndex = params.indexOf(" "); string strTable = params.substring(0, intIndex); strTable = "datatables/spawning/spawn_lists/"+strTable+".iff"; debugSpeakMsg(self, "strTable is "+strTable); string strNumber =params.substring(intIndex+1, params.length()); debugSpeakMsg(self, "strNumber is "+strNumber); if(!dataTableOpen(strTable)) { sendSystemMessageTestingOnly(self, strTable+" is not a valid dataTable"); return SCRIPT_CONTINUE; } Integer ServerSpawnLimit = new Integer(0); Integer intTestIndex = new Integer(0); try { intTestIndex = new Integer(strNumber); } // try with error handling catch (NumberFormatException err) { sendSystemMessageTestingOnly(self, strNumber+" is not a valid index"); return SCRIPT_CONTINUE; } intIndex = intTestIndex.intValue(); dictionary dctRow = dataTableGetRow(strTable, intIndex); if(dctRow==null) { sendSystemMessageTestingOnly(self, "Not a valid combination of data"); } // we'll spawn in 3 quadrants? int intMinDifficulty = dctRow.getInt("intMinDifficulty"); int intMaxDifficulty = dctRow.getInt("intMaxDifficulty"); int intPlayerDifficulty=rand(intMinDifficulty, intMaxDifficulty); int intNumToSpawn = dctRow.getInt("intNumToSpawn"); string strTemplateToSpawn = dctRow.getString("strTemplateToSpawn"); string strTemplate = dctRow.getString("strTemplate"); string strLairType = dctRow.getString("strLairType"); string strBuildingType = dctRow.getString("strBuildingType"); obj_id objCreatedTemplate = createObject(strTemplate, getLocation(self)); //LOG("spawning", self+" created templante "+strTemplate+" at location +"+getLocation(self)); if (!(objCreatedTemplate==null)) { //LOG("spawning", self+ "checking if player is grouped"); if(group.isGrouped(self)) { //LOG("spawning", self+ "player is grouped"); obj_id objGroup = getGroupObject(self); if(objGroup!=null) { //LOG("spawning", self+ "i got a group obect"); int intGroupSize = getGroupSize(objGroup); setObjVar(objCreatedTemplate, "spawning.intGroupSize", intGroupSize); } } setObjVar(objCreatedTemplate, "spawning.intDifficultyLevel", intPlayerDifficulty); string strDifficulty = create.getLairDifficulty(intMinDifficulty, intMaxDifficulty, intPlayerDifficulty); setObjVar(objCreatedTemplate, "spawning.lairDifficulty", strDifficulty); setObjVar(objCreatedTemplate, "spawning.lairType", strLairType); setObjVar(objCreatedTemplate, "spawning.buildingTrackingType", strBuildingType); if(strBuildingType!="") { setObjVar(objCreatedTemplate, "spawning.buildingType", strBuildingType); } } else { debugSpeakMsg(self, "I made a null object"); debugSpeakMsg(self, "row was "+dctRow.toString()); } return SCRIPT_CONTINUE; } commandHandler createSpawningElementWithDifficulty() { if(params=="") { sendSystemMessageTestingOnly(self, "You must provide a datatable, difficulty and an index for this to work properly"); return SCRIPT_CONTINUE; } int intIndex = params.indexOf(" "); string strTable = params.substring(0, intIndex); strTable = "datatables/spawning/spawn_lists/"+strTable+".iff"; string strRemainingString = params.substring(intIndex+1, params.length()); int intNextIndex = strRemainingString.indexOf(" "); string strNumber =strRemainingString.substring(0, intNextIndex); string strDifficultyInt = strRemainingString.substring(intNextIndex+1, strRemainingString.length()); if(!dataTableOpen(strTable)) { sendSystemMessageTestingOnly(self, strTable+" is not a valid dataTable"); return SCRIPT_CONTINUE; } Integer ServerSpawnLimit = new Integer(0); Integer intTestIndex = new Integer(0); try { intTestIndex = new Integer(strNumber); } // try with error handling catch (NumberFormatException err) { sendSystemMessageTestingOnly(self, strNumber+" is not a valid index"); return SCRIPT_CONTINUE; } intIndex = intTestIndex.intValue(); Integer intTestDifficulty = new Integer(0); try { intTestIndex = new Integer(strDifficultyInt); } // try with error handling catch (NumberFormatException err) { sendSystemMessageTestingOnly(self, strDifficultyInt+" is not a valid index"); return SCRIPT_CONTINUE; } int intLevel = intTestIndex.intValue(); dictionary dctRow = dataTableGetRow(strTable, intIndex); if(dctRow==null) { sendSystemMessageTestingOnly(self, "Not a valid combination of data"); } // we'll spawn in 3 quadrants? int intMinDifficulty = dctRow.getInt("intMinDifficulty"); int intMaxDifficulty = dctRow.getInt("intMaxDifficulty"); int intPlayerDifficulty=rand(intMinDifficulty, intMaxDifficulty); int intNumToSpawn = dctRow.getInt("intNumToSpawn"); string strTemplateToSpawn = dctRow.getString("strTemplateToSpawn"); string strTemplate = dctRow.getString("strTemplate"); string strLairType = dctRow.getString("strLairType"); string strBuildingType = dctRow.getString("strBuildingType"); obj_id objCreatedTemplate = createObject(strTemplate, getLocation(self)); //LOG("spawning", self+" created templante "+strTemplate+" at location +"+getLocation(self)); if (!(objCreatedTemplate==null)) { //LOG("spawning", self+ "checking if player is grouped"); if(group.isGrouped(self)) { //LOG("spawning", self+ "player is grouped"); obj_id objGroup = getGroupObject(self); if(objGroup!=null) { //LOG("spawning", self+ "i got a group obect"); int intGroupSize = getGroupSize(objGroup); setObjVar(objCreatedTemplate, "spawning.intGroupSize", intGroupSize); } } setObjVar(objCreatedTemplate, "spawning.intDifficultyLevel", intLevel); string strDifficulty = create.getLairDifficulty(intMinDifficulty, intMaxDifficulty, intLevel); setObjVar(objCreatedTemplate, "spawning.lairDifficulty", strDifficulty); setObjVar(objCreatedTemplate, "spawning.lairType", strLairType); setObjVar(objCreatedTemplate, "spawning.buildingTrackingType", strBuildingType); if(strBuildingType!="") { setObjVar(objCreatedTemplate, "spawning.buildingType", strBuildingType); } } else { debugSpeakMsg(self, "I made a null object"); debugSpeakMsg(self, "row was "+dctRow.toString()); } return SCRIPT_CONTINUE; } commandHandler startSpawner() { location locCurrentLocation = getLocation(self); obj_id objMasterSpawner = getPlanetByName(locCurrentLocation.area); if( objMasterSpawner == null ) { ////////LOG("player_spawner", "************************************SPAWN ERROR****************************************************"); ////////LOG("player_spawner", "Cannot find master spawn object! This is a critical spawn system failure!"); ////////LOG("player_spawner", "************************************SPAWN ERROR****************************************************"); return SCRIPT_CONTINUE; } if(!hasScript(objMasterSpawner, "systems.spawning.spawn_master")) { ////////LOG("player_spawner", "************************************SPAWN ERROR****************************************************"); ////////LOG("player_spawner", "The master spawner object, "+objMasterSpawner.getValue()+ ", does not have the master spawner script attached!"); ////////LOG("player_spawner", "Attaching the master spawning script to: "+objMasterSpawner.getValue()+"."); ////////LOG("player_spawner", "************************************SPAWN ERROR****************************************************"); attachScript(objMasterSpawner, "systems.spawning.spawn_master"); } // does it already have the status objvar? if(!hasObjVar(objMasterSpawner, "boolSpawnerIsOn")) { sendSystemMessageTestingOnly(self, "The masterspawner is not setup correctly. Resetting it to off."); setObjVar(objMasterSpawner, "boolSpawnerIsOn", false); return SCRIPT_OVERRIDE; } // if it has the objvar else { boolean boolSpawnerIsOn; boolSpawnerIsOn = getBooleanObjVar(objMasterSpawner, "boolSpawnerIsOn"); // is it set to off? if(boolSpawnerIsOn == false) { setObjVar(objMasterSpawner, "boolSpawnerIsOn", true); sendSystemMessageTestingOnly(self, "The master spawner is now on!"); return SCRIPT_OVERRIDE; } // it's already set to true, so don't worry about it. else { sendSystemMessageTestingOnly(self, "The master spawner is already on!"); return SCRIPT_OVERRIDE; } } } trigger OnLogin() { //attempt to apply crafting station buff icons for players //logging into a cell with stations messageTo(self, "checkStationCells", null, 2, false); removeObjVar(self, "spawning.locSpawnLocation"); return SCRIPT_CONTINUE; } messageHandler spawn_Trigger() { if(!isIdValid(self)) return SCRIPT_CONTINUE; // lets' see what spawn system we should use. location locTest = getLocation(self); if(utils.checkConfigFlag("ScriptFlags", "newSpawnSystem_" + locTest.area)) { spawning.activateSpawnerHack(self); return SCRIPT_CONTINUE; } dictionary dctParams = new dictionary(); ////LOG("spawning", "SPAWN TRIGGER WENT OFF OFOR A GIVEN FRAME"); location locCurrentLocation = getLocation(self); if (locCurrentLocation == null) return SCRIPT_CONTINUE; //boolean boolCheckForTheaters = false; //RPALACIO: commented due to lack of need if(canSpawn(self, locCurrentLocation, false, null)) { dictionary dctSpawnParams = new dictionary(); int intLevel = 0; intLevel = skill.getGroupLevel(self); intLevel = locations.normalizeDifficultyForRegion(intLevel, locCurrentLocation); // Returns a random level based on the smallest difficulty range. dctSpawnParams.put("intDifficulty", intLevel); dctSpawnParams.put("objPlayer", self); region rgnSpawnRegion = getSpawnRegion(self); if(rgnSpawnRegion == null) { return SCRIPT_CONTINUE; } string strRegionName = rgnSpawnRegion.getName(); string strPlanet = rgnSpawnRegion.getPlanetName(); string strTestPlanet = locCurrentLocation.area; if(strPlanet!=strTestPlanet) { LOG("DESIGNER_FATAL", "For region "+strRegionName+" planet is "+strPlanet); LOG("DESIGNER_FATAL", "But planet name for player is "+strTestPlanet); } if(strRegionName != null) { dctSpawnParams.put("strRegionName", strRegionName); } if(strPlanet != null) { dctSpawnParams.put("strPlanet", strPlanet); } boolean boolTheatersAllowed = false; int intNumRules = getNumRunTimeRules(); if(intNumRules>0) { if(intNumRules 0 ) { setSUIProperty(pid, sui.INPUTBOX_INPUT, sui.PROP_TEXT, defaultText); } } sui.showSUIPage(pid); return SCRIPT_CONTINUE; } if(strCommands[0]=="dumpBuildout") { string strDataTable = ""; if(strCommands.length>1) { strDataTable = "datatables/spawning/ground_spawning/buildouts/"+strCommands[1]+".tab"; } else { sendSystemMessageTestingOnly(self, "You must provide a filename. Syntax: dumpBuildout "); return SCRIPT_CONTINUE; } location locTest = getLocation(self); obj_id objCell = locTest.cell; boolean boolInBuilding = true; if(!isIdValid(objCell)) { boolInBuilding = false; } obj_id objBuilding= null; if(boolInBuilding) { objBuilding = getContainedBy(objCell); if(!isIdValid(objBuilding)) { boolean boolInbuilding = false; } } string[] strHeaderTypes = { "s","f","f","f","f","f","f","f","f","f", "p", "s", "s"}; string[] strHeaders = {"strTemplate","fltJX","fltJY","fltJZ","fltKX","fltKY","fltKZ","fltPX","fltPY","fltPZ", "strObjVars", "strScripts", "strCellName"}; boolean boolTest = datatable.createDataTable(strDataTable, strHeaders,strHeaderTypes); if(!boolTest) { sendSystemMessageTestingOnly(self, "No dattable made"); return SCRIPT_CONTINUE; } obj_id[] objObjects = null; if(boolInBuilding) { objObjects = spawning.getAllContents(objBuilding); } else { objObjects = getAllObjectsWithObjVar(getLocation(self), 15000, "intSpawnLocation"); } sendSystemMessageTestingOnly(self, "dumping contents of "+objBuilding); for(int intI = 0; intI 0) { int pid = sui.listbox(user, user, "Select Mine Type", packedMineStrings, "handleSelectMineType"); if(pid > -1) { showSUIPage(pid); } } } messageHandler handleSelectMineType() { obj_id player = sui.getPlayerId(params); int idx = sui.getListboxSelectedRow(params); if(idx < 0) return SCRIPT_CONTINUE; utils.setScriptVar(player, "mineCreation.mineType", idx); sui.inputbox( player, player, "What is the Radius of this field", sui.OK_CANCEL, "Test", sui.INPUT_NORMAL, null, "handleSetFieldRadius", null ); return SCRIPT_CONTINUE; } messageHandler handleSetFieldRadius() { int button = sui.getIntButtonPressed(params); if ( button== sui.BP_CANCEL ) { sendSystemMessageTestingOnly(self, "Cancelling mine field creation"); clearMineScriptVar(self); return SCRIPT_CONTINUE; } string stringFieldRadius = sui.getInputBoxText(params); float floatFieldRadius = utils.stringToFloat(stringFieldRadius); utils.setScriptVar(self, "mineCreation.fieldRadius", floatFieldRadius); sui.inputbox( self, self, "What is the Mine Count of this field", sui.OK_CANCEL, "Test", sui.INPUT_NORMAL, null, "handleSetMineCount", null ); return SCRIPT_CONTINUE; } messageHandler handleSetMineCount() { int button = sui.getIntButtonPressed(params); if ( button== sui.BP_CANCEL ) { sendSystemMessageTestingOnly(self, "Cancelling mine field creation"); clearMineScriptVar(self); return SCRIPT_CONTINUE; } string stringMineCount = sui.getInputBoxText(params); int intMineCount = utils.stringToInt(stringMineCount); utils.setScriptVar(self, "mineCreation.mineCount", intMineCount); sui.inputbox( self, self, "What is the respawn time of this field", sui.OK_CANCEL, "Test", sui.INPUT_NORMAL, null, "handleSetMineRespawn", null ); return SCRIPT_CONTINUE; } messageHandler handleSetMineRespawn() { int button = sui.getIntButtonPressed(params); if ( button== sui.BP_CANCEL ) { sendSystemMessageTestingOnly(self, "Cancelling mine field creation"); clearMineScriptVar(self); return SCRIPT_CONTINUE; } string stringMineRespawn = sui.getInputBoxText(params); int intMineRespawn = utils.stringToInt(stringMineRespawn); utils.setScriptVar(self, "mineCreation.mineRespawn", intMineRespawn); doLogging("handleMineRespawn", "Call generateMineField"); generateMineField(); return SCRIPT_CONTINUE; } void generateMineField() { obj_id player = getSelf(); transform tranx = getTransform_o2p(player); location fieldLoc = getLocation(player); obj_id mineFieldController = createObject( "object/tangible/ground_spawning/minefield_spawner.iff", tranx, fieldLoc.cell); doLogging("generateMineField", "mineFieldController isIdValid? "+isIdValid(mineFieldController)); persistObject(mineFieldController); int intMineType = utils.getIntScriptVar(player, "mineCreation.mineType"); string stringMineType = dataTableGetString("datatables/combat/npc_landmines.iff", intMineType, "mineType"); setObjVar(mineFieldController, "mineField.mineType", stringMineType); float fieldRadius = utils.getFloatScriptVar(player, "mineCreation.fieldRadius"); setObjVar(mineFieldController, "mineField.fieldRadius", fieldRadius); int mineCount = utils.getIntScriptVar(player, "mineCreation.mineCount"); setObjVar(mineFieldController, "mineField.mineCount", mineCount); int mineRespawn = utils.getIntScriptVar(player, "mineCreation.mineRespawn"); setObjVar(mineFieldController, "mineField.mineRespawn", mineRespawn); attachScript(mineFieldController, "systems.combat.combat_mine_spawner"); clearMineScriptVar(player); } void clearMineScriptVar(obj_id player) { utils.removeScriptVar(player, "mineCreation"); } void doLogging(string section, string message) { //LOG("debug/spawn_player/"+section, message); } messageHandler checkStationCells() { //should only have the station buffs in indoors if(isInWorldCell(self)) return SCRIPT_CONTINUE; //try to find cell obj_id cell = getContainedBy(self); //validate if(!isIdValid(cell) || !exists(cell)) return SCRIPT_CONTINUE; //check for presence of scriptvar if(utils.hasScriptVar(cell, craftinglib.SCRIPTVAR_CELL_STATIONS)) { //get the list of stations obj_id[] stations = utils.getObjIdArrayScriptVar(cell, craftinglib.SCRIPTVAR_CELL_STATIONS); if(stations == null || stations.length <= 0) return SCRIPT_CONTINUE; for(int i = 0; i < stations.length; ++i) { if(!isIdValid(stations[i])) { continue; } //get crafting type int craftingType = getIntObjVar(stations[i], craftinglib.OBJVAR_CRAFTING_TYPE); //get the buffname based on crafting type string buffName = craftinglib.getCraftingStationBuffName(craftingType); if(buffName == null || buffName.equals("")) { continue; } //apply the buff buff.applyBuff(self, stations[i], buffName); } } return SCRIPT_CONTINUE; }