/********************************************************************** * Title: npe * Description: Library for npe functionality **********************************************************************/ include library.utils; include library.space_dungeon; include library.space_transition; include library.space_utils; include library.static_item; include library.groundquests; include java.util.HashSet; /******************** CONSTANTS ********************/ const string SCRIPT_PUBLIC_TRAVEL = "npe.npe_instance_travel_player"; const string SCRIPT_SPACE_TRAVEL = "npe.travel_player_space_dungeon_falcon"; const string DUNGEON_PUBLIC_MANAGER_NAME = "npe_public_instances"; const string DUNGEON_HANGAR = "npe_hangar"; const string DUNGEON_MILLENIUM_FALCON = "npe_space"; const string DUNGEON_SPACE_STATION = "npe_space_station"; const string DUNGEON_ORD_SPACE_STATION = "npe_space_dungeon"; const string BUILDOUT_NAME_SHARED_STATION = "npe_shared_station"; const string BUILDOUT_NAME_SPACE_DUNGEON = "npe_dungeon"; const string SCENE_SPACE_ORD_MANTELL = "space_ord_mantell"; const string SCENE_SPACE_NPE_FALCON = "space_npe_falcon"; const string VAR_NPE_PHASE = "npe.phase_number"; const string VAR_ORD_SCENE_NAME = "npe.ord_scene_name"; const string SCRIPT_VAR_FROM_ORD_SPACE = "npe.coming_from_ord_space"; const string SCRIPT_VAR_ORD_SPACE_DESTINATION = "npe.ord_space_destination"; const string SCRIPT_VAR_INSTANCE_OVERRIDE = "npe.instance_override"; const string SCRIPT_VAR_DO_HYPERSPACE = "npe.do_hyperspace"; const string FROM_ORD_SPACE_TO_STATION_CELL = "hangarbay1"; const float FROM_ORD_SPACE_TO_STATION_X = 47.0f; const float FROM_ORD_SPACE_TO_STATION_Y = 0.8f; const float FROM_ORD_SPACE_TO_STATION_Z = 34.1f; const float PLAYER_PLACEMENT_RANGE = 3.0f; const float SPACE_PLAYER_PLACEMENT_RANGE = 100.0f; const string FINISH_PLANET = "tatooine"; const float FINISH_X = 3528.0f; const float FINISH_Z = -4804.0f; const int QUEST_ENUMERATION = 1; const string QUEST_REWORK_VAR = "npe.questRegrant"; const string QUEST_REWORK_TABLE = "datatables/npe/reworked_quests.iff"; const string GROUND_QUESTS = "strGroundQuests"; const string SPACE_QUEST_TYPE = "strSpaceType"; const string SPACE_QUEST_NAME = "strSpaceName"; const string_id NOT_FROM_SPACE = new string_id("npe", "gamma_travel_not_from_space"); const int LEVEL_CAP = 10; /******************** METHODS ********************/ void setResetDungeonObjvar(obj_id player) { if (isIdValid(space_dungeon.getDungeonIdForPlayer(player))) { setObjVar(player, space_dungeon.VAR_RESET_DUNGEON, space_dungeon.getDungeonIdForPlayer(player)); space_dungeon.cleanupPlayerDungeonObjvars(player); } } void randomizeLocation(location loc) { loc.x += ((-1.0f + (2.0f * random.rand())) * PLAYER_PLACEMENT_RANGE); loc.z += ((-1.0f + (2.0f * random.rand())) * PLAYER_PLACEMENT_RANGE); } void randomizeSpaceLocation(location loc) { loc.x += ((-1.0f + (2.0f * random.rand())) * SPACE_PLAYER_PLACEMENT_RANGE); loc.y += ((-1.0f + (2.0f * random.rand())) * SPACE_PLAYER_PLACEMENT_RANGE); loc.z += ((-1.0f + (2.0f * random.rand())) * SPACE_PLAYER_PLACEMENT_RANGE); } boolean performTransitionFromClusterWideData(obj_id player, dictionary[] stations, string station) { if (station.equals(DUNGEON_SPACE_STATION+"*")) { dictionary info = getNpeInstanceInfo(DUNGEON_SPACE_STATION); int instance_index = getBestStationInstanceIndex(player, stations); if (instance_index == -1 || instance_index >= stations.length) return false; dictionary station_info = stations[instance_index]; if (station_info == null) return false; // if the player is coming from ord space, they have a different start location if (utils.hasScriptVar(player, SCRIPT_VAR_FROM_ORD_SPACE)) { removeObjVar(player, SCRIPT_VAR_FROM_ORD_SPACE); utils.removeScriptVar(player, SCRIPT_VAR_FROM_ORD_SPACE); info.put("cell", FROM_ORD_SPACE_TO_STATION_CELL); location cell_loc = new location(FROM_ORD_SPACE_TO_STATION_X, FROM_ORD_SPACE_TO_STATION_Y, FROM_ORD_SPACE_TO_STATION_Z); info.put("cell_loc", cell_loc); } obj_id station_id = station_info.getObjId("building_id"); string planet = info.getString("planet"); location world_loc = new location(station_info.getFloat("world_location.x"), station_info.getFloat("world_location.y"), station_info.getFloat("world_location.z")); string cell = info.getString("cell"); location cell_loc = info.getLocation("cell_loc"); randomizeLocation(cell_loc); LIVE_LOG("npe", "Found " + stations.length + " buildings, moving " + player + " to " + station_id + " s:" + planet + " c:" + cell + " w:" + world_loc.x + " " + world_loc.y + " " + world_loc.z + " l:" + cell_loc.x + " " + cell_loc.y + " " + cell_loc.z); if (utils.hasScriptVar(player, SCRIPT_VAR_DO_HYPERSPACE)) { utils.removeScriptVar(player, SCRIPT_VAR_DO_HYPERSPACE); hyperspacePlayerToLocation(player, planet, world_loc.x, world_loc.y, world_loc.z, station_id, cell, cell_loc.x, cell_loc.y, cell_loc.z, "msgNpeInstanceTravelComplete", false); } else { warpPlayer(player, planet, world_loc.x, world_loc.y, world_loc.z, station_id, cell, cell_loc.x, cell_loc.y, cell_loc.z, "msgNpeInstanceTravelComplete", false); } return true; } else if (station.equals(DUNGEON_ORD_SPACE_STATION+"*")) { if (utils.hasScriptVar(player, SCRIPT_VAR_ORD_SPACE_DESTINATION)) { location new_loc = utils.getLocationScriptVar(player, SCRIPT_VAR_ORD_SPACE_DESTINATION); utils.removeScriptVar(player, SCRIPT_VAR_ORD_SPACE_DESTINATION); int index = getBestDungeonInstanceIndex(player, stations); // always send them to space_or_mantell string scene = SCENE_SPACE_ORD_MANTELL; if (!isIdValid(getPlanetByName(scene))) { //hopefully this wont happen return false; } obj_id ship = setupLaunchToSpace(player); if (!isIdValid(ship)) return false; new_loc.area = scene; location ground_loc = getWorldLocation(player); obj_id[] members = new obj_id[0]; randomizeSpaceLocation(new_loc); space_transition.launch(player, ship, members, new_loc, ground_loc); return true; } else { string ord_scene = getCurrentSceneName(); dictionary info = getNpeInstanceInfo(DUNGEON_ORD_SPACE_STATION); dictionary station_info = getBestOrdSpaceStation(player, stations, ord_scene); if (station_info == null) return false; setObjVar(player, npe.VAR_ORD_SCENE_NAME, ord_scene); obj_id station_id = station_info.getObjId("building_id"); string planet = info.getString("planet"); location world_loc = new location(station_info.getFloat("world_location.x"), station_info.getFloat("world_location.y"), station_info.getFloat("world_location.z")); string cell = info.getString("cell"); location cell_loc = info.getLocation("cell_loc"); randomizeLocation(cell_loc); LIVE_LOG("npe", "Found " + stations.length + " buildings, moving " + player + " to " + station_id + " s:" + planet + " c:" + cell + " w:" + world_loc.x + " " + world_loc.y + " " + world_loc.z + " l:" + cell_loc.x + " " + cell_loc.y + " " + cell_loc.z); if (utils.hasScriptVar(player, SCRIPT_VAR_DO_HYPERSPACE)) { utils.removeScriptVar(player, SCRIPT_VAR_DO_HYPERSPACE); hyperspacePlayerToLocation(player, planet, world_loc.x, world_loc.y, world_loc.z, station_id, cell, cell_loc.x, cell_loc.y, cell_loc.z, "msgNpeInstanceTravelComplete", false); } else { warpPlayer(player, planet, world_loc.x, world_loc.y, world_loc.z, station_id, cell, cell_loc.x, cell_loc.y, cell_loc.z, "msgNpeInstanceTravelComplete", false); } return true; } } else { LIVE_LOG("npe", "Player is trying to perform a cluster wide transition, but is going to an unsupported station " + station + " should be " + DUNGEON_SPACE_STATION + "*, " + DUNGEON_ORD_SPACE_STATION + "*"); return false; } } dictionary getNpeInstanceInfo(String row) { string table = "datatables/travel/zone_transition.iff"; string column = "destination"; string destination = dataTableGetString(table, row, column); string[] parsed_list = split(destination, ':'); dictionary ret = new dictionary(); ret.put("planet", parsed_list[2]); ret.put("cell", parsed_list[3]); location cell_loc = new location (utils.stringToFloat(parsed_list[4]), utils.stringToFloat(parsed_list[5]), utils.stringToFloat(parsed_list[6])); ret.put("cell_loc", cell_loc); return ret; } int getMinInstancePopulation() { /// @TODO - create a static config map class for java to cache config values like this return utils.stringToInt(getConfigSetting("GameServer", "npeMinInstancePopulation")); } int getMaxInstancePopulation() { /// @TODO - create a static config map class for java to cache config values like this return utils.stringToInt(getConfigSetting("GameServer", "npeMaxInstancePopulation")); } int getBestStationInstanceIndex(obj_id player, dictionary[] stations) { if (stations == null || stations.length == 0) { LOG("npe", "getBestSpaceStation called with null stations array!"); return -1; } if (utils.hasScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE)) { int index = utils.getIntScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE); utils.removeScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE); if (index < -1 || index >= stations.length) { sendSystemMessageTestingOnly(player, "You have specified an invalid Tansarii station index override (max of " + (stations.length-1) + "). Sending to default station"); if (stations[0] != null) return 0; } if (stations[index] != null) return index; sendSystemMessageTestingOnly(player, "The Tansarii station index override you specified is null! Defaulting to normal behavior"); } int return_index = -1; int population = -1; for (int i = 0; i < stations.length; ++i) { if (stations[i] == null) { LOG("npe", "getBestStationInstanceIndex: Got a null entry in stations array"); continue; } obj_id new_station = stations[i].getObjId("building_id"); int new_pop = stations[i].getInt("population_num"); if (!isIdValid(new_station)) { LOG("npe", "getBestStationInstanceIndex: stations array passed into getBestStationInstanceIndex contained a null or invalid station id"); continue; } // if this stations' priority is higher than the current, use it if (return_index == -1 || isSecondInstanceBetter(population, new_pop)) { return_index = i; population = new_pop; } } if (return_index == -1) { LOG("npe", "getBestStationInstanceIndex: Was not able to find a space station in getBestStationInstanceIndex!"); } return return_index; } int getBestDungeonInstanceIndex(obj_id player, dictionary[] dungeons) { if (dungeons == null || dungeons.length == 0) { LOG("npe", "getBestDungeonInstanceIndex called with null dungeons array!"); return -1; } if (utils.hasScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE)) { int index = utils.getIntScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE); utils.removeScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE); if (index < -1 || index >= dungeons.length) { sendSystemMessageTestingOnly(player, "You have specified an invalid station Gamma index override (max of " + (dungeons.length-1) + "). Sending to default station"); if (dungeons[0] != null) return 0; } if (dungeons[index] != null) return index; sendSystemMessageTestingOnly(player, "The station Gamma index override you specified is null! Defaulting to normal behavior"); } int numOrdSpace = getNumberOfOrdSpaceScenes(); int return_index = -1; int population = -1; for (int i = 0; i < dungeons.length && i < numOrdSpace; ++i) { if (dungeons[i] == null) { LOG("npe", "getBestDungeonInstanceIndex: Got a null entry in dungeons array"); continue; } obj_id new_station = dungeons[i].getObjId("building_id"); int new_pop = dungeons[i].getInt("population_num"); if (!isIdValid(new_station)) { LOG("npe", "getBestDungeonInstanceIndex: dungeons array passed into getBestDungeonInstanceIndex contained a null or invalid station id"); continue; } string ordSpaceScene = SCENE_SPACE_ORD_MANTELL; if (i > 0) ordSpaceScene += ("_"+(i+1)); if (isAreaTooFullForTravel(ordSpaceScene, 0, 0)) { LOG("npe", "getBestDungeonInstanceIndex: skipping ord scene " + ordSpaceScene + " because it is full"); continue; } // if this dungeons' priority is higher than the current, use it if (return_index == -1 || isSecondInstanceBetter(population, new_pop)) { return_index = i; population = new_pop; } } if (return_index == -1) { LOG("npe", "getBestDungeonInstanceIndex: Was not able to find a station Gamma in getBestDungeonInstanceIndex!"); } return return_index; } boolean isSecondInstanceBetter(int pop, int new_pop) { // if either is less than the minimum, take the lowest (nonzero) of the two if (pop != 0 && pop < getMinInstancePopulation() && (new_pop == 0 || pop <= new_pop)) return false; if (new_pop != 0 && new_pop < getMinInstancePopulation() && (pop == 0 || new_pop <= pop)) return true; // station has less population than the current one if (new_pop < pop) return true; // they're equal, or pop < new_pop return false; } dictionary getBestOrdSpaceStation(obj_id player, dictionary[] stations, string ord_scene) { if (stations == null || stations.length == 0) { LOG("npe", "getBestOrdSpaceStation called with null stations array!"); return null; } if (utils.hasScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE)) { int index = utils.getIntScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE); utils.removeScriptVar(player, SCRIPT_VAR_INSTANCE_OVERRIDE); if (index < -1 || index >= stations.length) { sendSystemMessageTestingOnly(player, "You have specified an invalid station Gamma index override (max of " + (stations.length-1) + "). Sending to default station"); if (stations[0] != null) return stations[0]; } if (stations[index] != null) return stations[index]; sendSystemMessageTestingOnly(player, "The station Gamma index override you specified is null! Defaulting to normal behavior"); } /* if (!ord_scene.startsWith(SCENE_SPACE_ORD_MANTELL)) { LOG("npe", "getBestOrdSpaceStation called while player was not in an ord mantell space zone!"); return null; } */ // get the string version of the last character (digit) string ord_num_str = ord_scene.substring(ord_scene.length()-1); int ord_num_ind = utils.stringToInt(ord_num_str); // extra ord zones start with _2 --ord_num_ind; // this will also work in the case that the zone name doesn't end in a digit - stringToInt will return -1, then the default index (0) will be returned if (ord_num_ind > 0 && ord_num_ind < stations.length && stations[ord_num_ind] != null && isIdValid(stations[ord_num_ind].getObjId("building_id"))) return stations[ord_num_ind]; // otherwise, just return the first valid one for (int i = 0; i < stations.length; ++i) if (stations[i] != null && isIdValid(stations[i].getObjId("building_id"))) return stations[i]; return null; } int getNumberOfOrdSpaceScenes() { if (!isIdValid(getPlanetByName(SCENE_SPACE_ORD_MANTELL))) return 0; int maxIndex = 1; for (int i = 2; i < 10; ++i) { // check to see if the scene we want is valid and running if (!isIdValid(getPlanetByName(SCENE_SPACE_ORD_MANTELL + "_" + i))) break; maxIndex = i; } return maxIndex; } string getOpenOrdMantellSpaceZone() { int maxIndex = getNumberOfOrdSpaceScenes(); int returnIndex = rand(1, maxIndex); if (returnIndex == 1) return SCENE_SPACE_ORD_MANTELL; return (SCENE_SPACE_ORD_MANTELL + "_" + returnIndex); } obj_id setupLaunchToSpace(obj_id player) { obj_id[] shipControlDevices = space_transition.findShipControlDevicesForPlayer(player); if (shipControlDevices == null || shipControlDevices.length == 0) { LOG("npe", "Player " + player + " has no ship control devices"); return null; } obj_id ship = space_transition.getShipFromShipControlDevice(shipControlDevices[0]); if(!space_utils.isShipUsable(ship, player)) { LOG("npe", "Ship: " + ship + " is not useable"); return null; } if (!isIdValid(ship)) { LOG("npe", "Can't launch to space, player " + player + " does not have a valid ship"); return null; } return ship; } void resetPlayerForNpe(obj_id player) { detachScript(player, SCRIPT_SPACE_TRAVEL); detachScript(player, SCRIPT_PUBLIC_TRAVEL); } boolean movePlayerFromHangarToFalcon(obj_id player) { setObjVar(player, VAR_NPE_PHASE, 2); setResetDungeonObjvar(player); attachScript(player, SCRIPT_SPACE_TRAVEL); return space_dungeon.sendGroupToDungeonWithoutTicketCollector(player, DUNGEON_MILLENIUM_FALCON, "quest_type"); } boolean movePlayerFromFalconToSharedStation(obj_id player) { setObjVar(player, VAR_NPE_PHASE, 3); removeObjVar(player, space_dungeon.VAR_EJECT_OVERRIDE); detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); setResetDungeonObjvar(player); getClusterWideData(DUNGEON_PUBLIC_MANAGER_NAME, DUNGEON_SPACE_STATION+"*", false, player); return true; } boolean movePlayerFromInstanceToInstance(obj_id player, obj_id desired_station, location world_location, string instance_name, int cluster_wide_index) { if (!instance_name.equals(DUNGEON_SPACE_STATION) && !instance_name.equals(DUNGEON_ORD_SPACE_STATION)) { LIVE_LOG("npe", "Can't send player "+player+" to "+desired_station+" because the instance_name "+instance_name+" is not valid"); return false; } if (instance_name.equals(DUNGEON_ORD_SPACE_STATION)) { string ordSpaceScene = SCENE_SPACE_ORD_MANTELL; if (cluster_wide_index > 0) ordSpaceScene += ("_"+(cluster_wide_index+1)); setObjVar(player, VAR_ORD_SCENE_NAME, ordSpaceScene); } detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); dictionary info = getNpeInstanceInfo(instance_name); string planet = info.getString("planet"); string cell = info.getString("cell"); location loc = new location(info.getFloat("locx"), info.getFloat("locy"), info.getFloat("locz")); randomizeLocation(loc); warpPlayer(player, planet, world_location.x, world_location.y, world_location.z, desired_station, cell, loc.x, loc.y, loc.z, "msgNpeInstanceTravelComplete", false); return true; } boolean movePlayerFromSharedStationToOrdMantellSpace(obj_id player, location new_loc) { detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); utils.setScriptVar(player, SCRIPT_VAR_ORD_SPACE_DESTINATION, new_loc); getClusterWideData(DUNGEON_PUBLIC_MANAGER_NAME, DUNGEON_ORD_SPACE_STATION+"*", false, player); return true; } boolean movePlayerFromOrdMantellSpaceToSharedStation(obj_id player) { detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); utils.setScriptVar(player, SCRIPT_VAR_FROM_ORD_SPACE, 1); getClusterWideData(DUNGEON_PUBLIC_MANAGER_NAME, DUNGEON_SPACE_STATION+"*", false, player); return true; } boolean movePlayerFromSharedStationToOrdMantellDungeon(obj_id player) { detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); getClusterWideData(DUNGEON_PUBLIC_MANAGER_NAME, DUNGEON_ORD_SPACE_STATION+"*", false, player); return true; } boolean movePlayerFromOrdMantellDungeonToSharedStation(obj_id player) { detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); utils.setScriptVar(player, SCRIPT_VAR_FROM_ORD_SPACE, 1); getClusterWideData(DUNGEON_PUBLIC_MANAGER_NAME, DUNGEON_SPACE_STATION+"*", false, player); return true; } boolean movePlayerFromOrdMantellSpaceToOrdMantellDungeon(obj_id player) { detachScript(player, SCRIPT_SPACE_TRAVEL); attachScript(player, SCRIPT_PUBLIC_TRAVEL); getClusterWideData(DUNGEON_PUBLIC_MANAGER_NAME, DUNGEON_ORD_SPACE_STATION+"*", false, player); return true; } boolean movePlayerFromOrdMantellDungeonToOrdMantellSpace(obj_id player, location new_loc) { string scene = getStringObjVar(player, VAR_ORD_SCENE_NAME); if (scene == null || scene == "" || scene != "space_ord_mantell") { LOG("npe", "movePlayerFromOrdMantellDungeonToOrdMantellSpace: empty scene id found: " + player); scene = "space_ord_mantell"; //return false; } if (isAreaTooFullForTravel(scene, 0, 0)) { scene = getOpenOrdMantellSpaceZone(); if (scene == null || scene == "") { LIVE_LOG("npe", "movePlayerFromOrdMantellDungeonToOrdMantellSpace: player " + player + " can't be moved to ord mantell, all scenes are full"); return false; } } obj_id ship = setupLaunchToSpace(player); if (!isIdValid(ship)) return false; removeObjVar(player, VAR_ORD_SCENE_NAME); new_loc.area = scene; location ground_loc = getWorldLocation(player); obj_id[] members = new obj_id[0]; randomizeSpaceLocation(new_loc); space_transition.launch(player, ship, members, new_loc, ground_loc); return true; } boolean movePlayerFromSharedStationToFinishLocation(obj_id player) { removeObjVar(player, "npe"); detachScript(player, SCRIPT_PUBLIC_TRAVEL); detachScript(player, "npe.trigger_journal"); removeObjVar(player, VAR_NPE_PHASE); removeObjVar(player, VAR_ORD_SCENE_NAME); newbieTutorialEnableHudElement(player, "radar", true, 0); attachScript (player, "npe.handoff_to_tatooine"); setCompletedTutorial(player, true); setObjVar(player, "comingFromTutorial", 1); warpPlayer(player, FINISH_PLANET, FINISH_X, 0, FINISH_Z, null, 0.0f, 0.0f, 0.0f, null, false); return true; } boolean teleportPlayerToLaunchLoc(obj_id player, boolean hyperspace) { string scene = getCurrentSceneName(); if (scene == null) { // yikes! We don't know what scene we're in? to be safe, teleport them to the shared station movePlayerFromOrdMantellSpaceToSharedStation(player); } else if (scene.startsWith(SCENE_SPACE_ORD_MANTELL)) { // if they are in ord_mantell, then they need to either go to the shared station or the ord mantell dungeon if (hyperspace) utils.setScriptVar(player, SCRIPT_VAR_DO_HYPERSPACE, 1); // get the buildout launch name if they have one location launchLocation = getLocationObjVar(player, "space.launch.worldLoc"); string launchBuildoutName = BUILDOUT_NAME_SHARED_STATION; // get the buildout name from the launch location, default to shared station if they have no launchlocation if (launchLocation != null) { string buildoutName = getBuildoutAreaName(launchLocation.x, launchLocation.z, launchLocation.area); if (buildoutName != null && !buildoutName.equals("")) launchBuildoutName = buildoutName; } if (launchBuildoutName.equals(BUILDOUT_NAME_SPACE_DUNGEON)) movePlayerFromOrdMantellSpaceToOrdMantellDungeon(player); else { // if the buildout name isn't the shared station or the space dungeon, log and send them to the shared station if (!launchBuildoutName.equals(BUILDOUT_NAME_SHARED_STATION)) LIVE_LOG("npe", "Player (" + player + ") did not have a valid launch location (" + launchLocation + ") or a valid launch buildout name (" + launchBuildoutName + ") sending to npe_shared_station instead"); movePlayerFromOrdMantellSpaceToSharedStation(player); } } else if (scene.startsWith(SCENE_SPACE_NPE_FALCON)) { // we are in the npe falcon, and logged out and let the instance die - start over sendPlayerToTutorial(player); } else if (isFreeTrialAccount(player)) { // we should never have a free trial account that is in a space zone other than space_ord_mantell or space_npe_falcon - force back to the tutorial start LIVE_LOG("npe", "Player("+player+") is a free trial player in an invalid space zone("+scene+"), sending to tutorial start"); sendPlayerToTutorial(player); } else { // they have the npe objvar, but are in none of the npe planets, and are not a free trial account... // let the space_transition code handle them, since the tatooine fallback is valid in case of failure return false; } return true; } //Grants newbie armor. obj_id[] grantNewbArmor(obj_id player) { obj_id pInv = utils.getInventoryContainer(player); int pSpecies = getSpecies(player); string playerTemplate = getSkillTemplate(player); int pGender = getGender(player); HashSet theSet = new HashSet(); if(utils.isProfession(player, utils.FORCE_SENSITIVE)) theSet.add(static_item.createNewItemFunction("item_npe_fs_robe_02_01", pInv)); else if(pSpecies == SPECIES_WOOKIEE) { theSet.add(static_item.createNewItemFunction("item_wookiee_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_wookiee_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_wookiee_hat_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_wookiee_gloves_02_01", pInv)); } else if(pSpecies == SPECIES_ITHORIAN) { theSet.add(static_item.createNewItemFunction("item_ithorian_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_ithorian_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_ithorian_vest_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_ithorian_gloves_02_01", pInv)); } else if(utils.isProfession(player, utils.SMUGGLER)) { theSet.add(static_item.createNewItemFunction("item_smuggler_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_smuggler_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_smuggler_vest_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_smuggler_boots_02_01", pInv)); } else if(utils.isProfession(player, utils.BOUNTY_HUNTER)) { theSet.add(static_item.createNewItemFunction("item_bounty_hunter_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_bounty_hunter_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_bounty_hunter_vest_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_bounty_hunter_boots_02_01", pInv)); } else if(utils.isProfession(player, utils.OFFICER)) { theSet.add(static_item.createNewItemFunction("item_officer_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_officer_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_officer_belt_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_officer_boots_02_01", pInv)); } else if(utils.isProfession(player, utils.COMMANDO)) { theSet.add(static_item.createNewItemFunction("item_commando_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_commando_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_commando_vest_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_commando_boots_02_01", pInv)); } else if(utils.isProfession(player, utils.MEDIC)) { theSet.add(static_item.createNewItemFunction("item_medic_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_medic_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_medic_vest_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_medic_shoes_02_01", pInv)); } else if(utils.isProfession(player, utils.SPY)) { theSet.add(static_item.createNewItemFunction("item_spy_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_spy_pants_02_01", pInv)); if(pSpecies != SPECIES_MON_CALAMARI && pSpecies != SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_spy_gloves_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_spy_boots_02_01", pInv)); } else if(utils.isProfession(player, utils.ENTERTAINER)) { if(pGender == GENDER_MALE) { theSet.add(static_item.createNewItemFunction("item_entertainer_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_entertainer_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_entertainer_hat_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_entertainer_boots_02_01", pInv)); } else { theSet.add(static_item.createNewItemFunction("item_entertainer_shirt_02_02", pInv)); theSet.add(static_item.createNewItemFunction("item_entertainer_skirt_02_01", pInv)); if(pSpecies != SPECIES_MON_CALAMARI && pSpecies != SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_entertainer_gloves_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_entertainer_shoes_02_01", pInv)); } } else if(utils.isProfession(player, utils.TRADER)) { theSet.add(static_item.createNewItemFunction("item_trader_shirt_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_trader_pants_02_01", pInv)); theSet.add(static_item.createNewItemFunction("item_trader_vest_02_01", pInv)); if(pSpecies == SPECIES_TRANDOSHAN) theSet.add(static_item.createNewItemFunction("item_npe_trando_necklace_01_01", pInv)); else theSet.add(static_item.createNewItemFunction("item_trader_shoes_02_01", pInv)); } obj_id[] items = new obj_id[theSet.size()]; theSet.toArray(items); showLootBox(player, items); return items; } obj_id grantNpeResourceStack(obj_id player, string strResourceType, int intAmount) { int maxResource = 1000000; obj_id objContainer = utils.getInventoryContainer(player); obj_id[] objResourceIds = getResourceTypes(strResourceType); obj_id objResourceId = null; if((objResourceIds!=null)&&(objResourceIds.length>0)) { objResourceId = objResourceIds[rand(0, objResourceIds.length-1)]; } if(!isIdValid(objResourceId)) { return null; } obj_id objStack = getResourceStack(objContainer, objResourceId); if(isIdValid(objStack)) { int intCount = getResourceContainerQuantity(objStack); intCount += intAmount; if(intCount>maxResource) { // add the diff intCount = intCount - maxResource; //sendSystemMessageTestingOnly(objPilot, "Add the Diff! " + intCount); // add the diff intAmount = intAmount - intCount; addResourceToContainer(objStack, objResourceId , intAmount, null); objStack = null; } else { // increment the count addResourceToContainer(objStack, objResourceId, intAmount, null); //sendSystemMessageTestingOnly(objPilot, "Incrementing count!"); } } else { // make a new stack and set the count objStack = createResourceCrate(objResourceId, intAmount, objContainer); if (isIdValid(objStack)) { return objStack; } } return null; } int harvestNpeResourceStack(obj_id player, string strResourceType, int intAmount) { int maxResource = 1000000; obj_id objContainer = utils.getInventoryContainer(player); obj_id[] objResourceIds = getResourceTypes(strResourceType); obj_id objResourceId = null; if((objResourceIds!=null)&&(objResourceIds.length>0)) { objResourceId = objResourceIds[0]; } if(!isIdValid(objResourceId)) { return 0; } obj_id objStack = getResourceStack(objContainer, objResourceId); if(isIdValid(objStack)) { int intCount = getResourceContainerQuantity(objStack); intCount += intAmount; if(intCount>maxResource) { // add the diff intCount = intCount - maxResource; //sendSystemMessageTestingOnly(objPilot, "Add the Diff! " + intCount); // add the diff intAmount = intAmount - intCount; addResourceToContainer(objStack, objResourceId , intAmount, null); objStack = null; utils.setScriptVar( player, "resource.lastAmt", intAmount ); return intAmount; } else { // increment the count addResourceToContainer(objStack, objResourceId, intAmount, null); utils.setScriptVar( player, "resource.lastAmt", intAmount ); return intAmount; //sendSystemMessageTestingOnly(objPilot, "Incrementing count!"); } } else { // make a new stack and set the count objStack = createResourceCrate(objResourceId, intAmount, objContainer); if (isIdValid(objStack)) { utils.setScriptVar( player, "resource.lastAmt", intAmount ); return intAmount; } } return 0; } obj_id getResourceStack(obj_id objContainer, obj_id objResource) { int maxResource = 1000000; if(!isIdValid(objContainer)) { return null; } obj_id[] objContents= getContents(objContainer); if(objContents==null) { return null; } for ( int intI= 0; intI< objContents.length; intI++) { obj_id objType = getResourceContainerResourceType(objContents[intI]); if(objType==objResource) { int intCount = getResourceContainerQuantity(objContents[intI]); if(intCount= LEVEL_CAP) { return true; } } return false; }