diff --git a/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/defense_manager.java b/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/defense_manager.java new file mode 100644 index 0000000..a193312 --- /dev/null +++ b/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/defense_manager.java @@ -0,0 +1,472 @@ +package script.faction_perk.hq; + +import script.*; +import script.library.*; + +import java.util.Vector; + +public class defense_manager extends script.base_script +{ + public defense_manager() + { + } + private static final float RESOURCE_REPAIR_RATIO = 0.5f; + public int OnAttach(obj_id self) throws InterruptedException + { + if (!isInvulnerable(self)) + { + setInvulnerable(self, true); + } + hq.prepareHqDefenses(self); + return SCRIPT_CONTINUE; + } + public int OnInitialize(obj_id self) throws InterruptedException + { + if (!isInvulnerable(self)) + { + setInvulnerable(self, true); + } + messageTo(self, "handleDefenseValidation", null, 10.0f, false); + return SCRIPT_CONTINUE; + } + public int OnDestroy(obj_id self) throws InterruptedException + { + hq.cleanupHqDefenses(self); + hq.cleanupHqSecurityTeam(self); + return SCRIPT_CONTINUE; + } + public int handleCreateMinefield(obj_id self, dictionary params) throws InterruptedException + { + hq.createMinefield(self); + return SCRIPT_CONTINUE; + } + public int OnMaintenanceLoop(obj_id self, dictionary params) throws InterruptedException + { + messageTo(self, "handleRepairDefenses", null, 10.0f, false); + return SCRIPT_CONTINUE; + } + public int handleRepairDefenses(obj_id self, dictionary params) throws InterruptedException + { + if (!hasObjVar(self, hq.VAR_DEFENSE_BASE)) + { + return SCRIPT_CONTINUE; + } + int ireserve = getIntObjVar(self, hq.VAR_HQ_RESOURCE_CNT); + if (ireserve < 1) + { + messageTo(self, "handleDefenseValidation", null, 10.0f, false); + return SCRIPT_CONTINUE; + } + float reserve = ireserve; + obj_var_list ovl = getObjVarList(self, hq.VAR_DEFENSE_BASE); + if (ovl == null) + { + return SCRIPT_CONTINUE; + } + int numType = ovl.getNumItems(); + obj_var ov; + obj_id[] defenses; + for (int i = 0; i < numType; i++) + { + if (reserve < 1.0f) + { + break; + } + ov = ovl.getObjVar(i); + defenses = ov.getObjIdArrayData(); + if (defenses != null && defenses.length > 0) + { + for (obj_id defense : defenses) { + int curres = getIntObjVar(self, hq.VAR_HQ_RESOURCE_CNT); + if (isIdValid(defense)) { + int hp = getHitpoints(defense); + int max = getMaxHitpoints(defense); + if (hp < 1) { + destroyObject(defense); + } else if (hp < max) { + int diff = max - hp; + float cost = diff * RESOURCE_REPAIR_RATIO; + if (cost > curres) { + diff = (int) (curres / RESOURCE_REPAIR_RATIO); + cost = curres; + } + curres -= cost; + setHitpoints(defense, hp + diff); + int used = (int) cost; + int total = curres - used; + if (total < 0) { + removeObjVar(self, hq.VAR_HQ_RESOURCE_CNT); + break; + } + setObjVar(self, hq.VAR_HQ_RESOURCE_CNT, total); + if (curres < 1.0f) { + break; + } + } + } + } + } + } + messageTo(self, "handleDefenseValidation", null, 10.0f, false); + return SCRIPT_CONTINUE; + } + public int handleAddDefense(obj_id self, dictionary params) throws InterruptedException + { + if (params == null || params.isEmpty()) + { + return SCRIPT_CONTINUE; + } + String defenseType = params.getString("type"); + if (defenseType == null || defenseType.equals("")) + { + return SCRIPT_CONTINUE; + } + else if (defenseType.equals("mine")) + { + int mineType = params.getInt("mineType"); + addMine(self, mineType); + return SCRIPT_CONTINUE; + } + String template = params.getString("template"); + if (template == null || template.equals("")) + { + return SCRIPT_CONTINUE; + } + else if (!hasObjVar(self, hq.VAR_DEFENSE_BASE)) + { + return SCRIPT_CONTINUE; + } + obj_id[] data = getObjIdArrayObjVar(self, hq.VAR_DEFENSE_BASE + "." + defenseType); + if (data == null || data.length == 0) + { + return SCRIPT_CONTINUE; + } + int pos = utils.getFirstNonValidIdIndex(data); + if (pos < 0 || pos > data.length - 1) + { + return SCRIPT_CONTINUE; + } + else if (isIdValid(data[pos])) + { + return SCRIPT_CONTINUE; + } + String tbl = hq.TBL_DEFENSE_PATH + utils.getTemplateFilenameNoPath(self); + String locData = dataTableGetString(tbl, pos, toUpper(defenseType)); + if (locData == null || locData.equals("")) + { + return SCRIPT_CONTINUE; + } + String[] locSplit = split(locData, ','); + if (locSplit == null || locSplit.length == 0) + { + return SCRIPT_CONTINUE; + } + float dx = utils.stringToFloat(locSplit[0]); + if (dx == Float.NEGATIVE_INFINITY) + { + return SCRIPT_CONTINUE; + } + float dy = utils.stringToFloat(locSplit[1]); + if (dy == Float.NEGATIVE_INFINITY) + { + return SCRIPT_CONTINUE; + } + float dz = utils.stringToFloat(locSplit[2]); + if (dz == Float.NEGATIVE_INFINITY) + { + return SCRIPT_CONTINUE; + } + float dyaw = utils.stringToFloat(locSplit[3]); + if (dyaw == Float.NEGATIVE_INFINITY) + { + return SCRIPT_CONTINUE; + } + location here = getLocation(self); + float yaw = getYaw(self); + location there = player_structure.transformDeltaWorldCoord(here, dx, dz, getYaw(self)); + there.y = here.y; + int myFac = pvpGetAlignedFaction(self); + String myFacName = factions.getFaction(self); + obj_id defense; + //fixed some issues that was causing the wrong sized turrets to be spawned. + if (defenseType.equals("turret")) + { + int turretType = advanced_turret.TYPE_BLOCK; + int turretSize = advanced_turret.SIZE_SMALL; + int turretMinDam = 3500; + int turretMaxDam = 4500; + int turretHitpoints = 200000; + float turretRange = 64.0f; + float turretSpeed = 2.0f; + if (template.contains("tower")) + { + turretType = advanced_turret.TYPE_TOWER; + turretMinDam = 5000; + turretMaxDam = 7000; + turretSpeed = 3.0f; + if (template.contains("lg")) + { + turretSize = advanced_turret.SIZE_LARGE; + turretHitpoints = 600000; + turretRange = 96.0f; + } + else if (template.contains("med")) + { + turretSize = advanced_turret.SIZE_MEDIUM; + turretHitpoints = 400000; + turretRange = 80.0f; + } + } + else if (template.contains("dish")) + { + turretType = advanced_turret.TYPE_DISH; + turretMinDam = 1750; + turretMaxDam = 2250; + turretSpeed = 1.0f; + if (template.contains("lg")) + { + turretSize = advanced_turret.SIZE_LARGE; + turretHitpoints = 600000; + turretRange = 96.0f; + } + else if (template.contains("med")) + { + turretSize = advanced_turret.SIZE_MEDIUM; + turretHitpoints = 400000; + turretRange = 80.0f; + } + } + else if (template.contains("lg")) + { + turretSize = advanced_turret.SIZE_LARGE; + turretHitpoints = 600000; + turretRange = 96.0f; + } + else if (template.contains("med")) + { + turretSize = advanced_turret.SIZE_MEDIUM; + turretHitpoints = 400000; + turretRange = 80.0f; + } + defense = advanced_turret.createTurret(there, (yaw + dyaw), turretType, turretSize, DAMAGE_ENERGY, turretMinDam, turretMaxDam, turretHitpoints, turretRange, turretSpeed, myFacName); + } + else + { + defense = createObject(template, there); + if (isIdValid(defense)) + { + setYaw(defense, yaw + dyaw); + pvpSetAlignedFaction(defense, myFac); + pvpMakeDeclared(defense); + if (myFacName != null && myFacName.equals("")) + { + factions.setFaction(defense, myFacName); + } + String temp = getTemplateName(defense); + int index = player_structure.getStructureTableIndex(temp); + if (index != -1) + { + int condition = dataTableGetInt(player_structure.PLAYER_STRUCTURE_DATATABLE, index, player_structure.DATATABLE_COL_CONDITION); + if (condition > 0) + { + setMaxHitpoints(defense, condition); + setInvulnerableHitpoints(defense, condition); + } + } + } + } + if (isIdValid(defense)) + { + persistObject(defense); + attachScript(defense, hq.SCRIPT_DEFENSE_OBJECT); + setObjVar(defense, hq.VAR_DEFENSE_PARENT, self); + setOwner(defense, self); + data[pos] = defense; + setObjVar(self, hq.VAR_DEFENSE_BASE + "." + defenseType, data); + } + return SCRIPT_CONTINUE; + } + public int handleRemoveDefense(obj_id self, dictionary params) throws InterruptedException + { + if (params == null || params.isEmpty()) + { + return SCRIPT_CONTINUE; + } + obj_id sender = params.getObjId("sender"); + if (!isIdValid(sender)) + { + return SCRIPT_CONTINUE; + } + else if (!hasObjVar(self, hq.VAR_DEFENSE_BASE)) + { + return SCRIPT_CONTINUE; + } + obj_var_list ovl = getObjVarList(self, hq.VAR_DEFENSE_BASE); + if (ovl == null) + { + return SCRIPT_CONTINUE; + } + int numTypes = ovl.getNumItems(); + obj_var ov; + obj_id[] data; + for (int i = 0; i < numTypes; i++) + { + ov = ovl.getObjVar(i); + data = ov.getObjIdArrayData(); + int idx = utils.getElementPositionInArray(data, sender); + if (idx > -1) + { + data[idx] = obj_id.NULL_ID; + setObjVar(self, hq.VAR_DEFENSE_BASE + "." + ov.getName(), data); + break; + } + } + messageTo(self, "terminalOff", null, 1, false); + obj_id[] numTur = getObjIdArrayObjVar(self, "hq.defense.turret"); + if (numTur == null || numTur.length == 0) + { + detachScript(self, "faction_perk.hq.base_block"); + } + int pos = utils.getFirstValidIdIndex(numTur); + if (pos < 0 || (numTur != null && pos > numTur.length - 1)) + { + detachScript(self, "faction_perk.hq.base_block"); + } + return SCRIPT_CONTINUE; + } + public int handleDefenseValidation(obj_id self, dictionary params) throws InterruptedException + { + hq.validateDefenseTracking(self); + return SCRIPT_CONTINUE; + } + public int handleMinefieldValidation(obj_id self, dictionary params) throws InterruptedException + { + if (hasObjVar(self, "mines")) + { + int[] mines = getIntArrayObjVar(self, "mines"); + if (mines.length >= hq.MAX_MINE_TYPES) + { + return SCRIPT_CONTINUE; + } + int[] new_mines = new int[hq.MAX_MINE_TYPES]; + // this may bomb... depends on how big "mines" ends up being... if mines.length is bigger than hq.MAX_MINE_TYPES + // then it will bomb. Correct the issue by making arraycopy only go to hq.MAX_MINE_TYPES instead of mines.length + System.arraycopy(mines, 0, new_mines, 0, mines.length); + setObjVar(self, "mines", new_mines); + return SCRIPT_CONTINUE; + } + if (hasObjVar(self, hq.VAR_DEFENSE_BASE + ".minefield")) + { + obj_id[] old_minefields = getObjIdArrayObjVar(self, hq.VAR_DEFENSE_BASE + ".minefield"); + for (obj_id old_minefield : old_minefields) { + if (isIdValid(old_minefield)) { + destroyObject(old_minefield); + } + } + } + messageTo(self, "handleCreateMinefield", null, 5.0f, false); + setObjVar(self, "mines", new int[hq.MAX_MINE_TYPES]); + return SCRIPT_CONTINUE; + } + public int handleTurretControl(obj_id self, dictionary params) throws InterruptedException + { + obj_id turret = params.getObjId("defense"); + if (!isIdValid(turret)) + { + return SCRIPT_CONTINUE; + } + obj_var_list ovl = getObjVarList(self, hq.VAR_DEFENSE_BASE); + if (ovl == null) + { + return SCRIPT_CONTINUE; + } + int numTypes = ovl.getNumItems(); + obj_id[] data; + for (int i = 0; i < numTypes; i++) + { + data = ovl.getObjVar(i).getObjIdArrayData(); + int pos = utils.getElementPositionInArray(data, turret); + if (pos > -1 && pos < 4) + { + setObjVar(self, "turret" + (pos + 1), turret); + } + } + return SCRIPT_CONTINUE; + } + public int handleResetTurretControl(obj_id self, dictionary params) throws InterruptedException + { + obj_id turret = params.getObjId("sender"); + if (!isIdValid(turret)) + { + return SCRIPT_CONTINUE; + } + if (!exists(turret)) + { + return SCRIPT_CONTINUE; + } + obj_var_list ovl = getObjVarList(self, hq.VAR_DEFENSE_BASE); + if (ovl == null) + { + return SCRIPT_CONTINUE; + } + int numTypes = ovl.getNumItems(); + obj_id[] data; + for (int i = 0; i < numTypes; i++) + { + data = ovl.getObjVar(i).getObjIdArrayData(); + int pos = utils.getElementPositionInArray(data, turret); + if (pos > -1 && pos < 4) + { + setObjVar(self, "turret" + (pos + 1), turret); + } + } + return SCRIPT_CONTINUE; + } + public int handleSpawnSecurityRover(obj_id self, dictionary params) throws InterruptedException + { + String guardType = params.getString("guard"); + location start = params.getLocation("start"); + obj_id guard = create.object(guardType, start); + if (isIdValid(guard)) + { + ai_lib.setPatrolPath(guard, params.getLocationArray("locs")); + if (utils.hasScriptVar(self, "hq.spawn.security")) + { + Vector securityTeam = utils.getResizeableObjIdArrayScriptVar(self, "hq.spawn.security"); + securityTeam = utils.addElement(securityTeam, guard); + utils.setScriptVar(self, "hq.spawn.security", securityTeam); + } + else + { + Vector securityTeam = new Vector(); + securityTeam.setSize(0); + securityTeam = utils.addElement(securityTeam, guard); + utils.setScriptVar(self, "hq.spawn.security", securityTeam); + } + } + return SCRIPT_CONTINUE; + } + private boolean addMine(obj_id self, int mineType) throws InterruptedException + { + if (mineType == -1) + { + return false; + } + int[] mines = new int[hq.MAX_MINE_TYPES]; + if (hasObjVar(self, "mines")) + { + mines = getIntArrayObjVar(self, "mines"); + } + if (mineType >= mines.length) + { + return false; + } + mines[mineType]++; + if (mines[mineType] <= 0) + { + mines[mineType] = 1; + } + setObjVar(self, "mines", mines); + return true; + } +} diff --git a/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/terminal.java b/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/terminal.java new file mode 100644 index 0000000..816bc69 --- /dev/null +++ b/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/terminal.java @@ -0,0 +1,1208 @@ +package script.faction_perk.hq; + +import script.*; +import script.library.*; + +import java.util.Calendar; +import java.util.Vector; + +public class terminal extends script.terminal.base.base_terminal +{ + public terminal() + { + } + private static final string_id MNU_DONATE = new string_id("hq", "mnu_donate"); + private static final string_id MNU_DONATE_MONEY = new string_id("hq", "mnu_donate_money"); + public static final string_id MNU_DONATE_RESOURCE = new string_id("hq", "mnu_donate_resource"); + private static final string_id MNU_DONATE_DEED = new string_id("hq", "mnu_donate_deed"); + private static final string_id UNDER_ATTACK = new string_id("hq", "under_attack"); + private static final string_id MNU_OVERLOAD = new string_id("hq", "mnu_overload"); + private static final string_id MNU_OVERLOAD_GOD = new string_id("hq", "mnu_overload_god_intentional_code_string"); + private static final string_id MNU_SHUTDOWN = new string_id("hq", "mnu_shutdown"); + private static final string_id MNU_DEFENSE_STATUS = new string_id("hq", "mnu_defense_status"); + private static final string_id MNU_RESET_VULNERABILITY = new string_id("hq", "mnu_reset_vulnerability"); + private static final String[] ACCEPTED_DEED_TYPES = + { + "turret", + "mine" + }; + private static final String SCRIPTVAR_COUNTDOWN = "countdownInProgress"; + private static final string_id SID_TERMINAL_MANAGEMENT = new string_id("player_structure", "management"); + private static final string_id SID_TERMINAL_MANAGEMENT_STATUS = new string_id("player_structure", "management_status"); + private static final string_id SID_TERMINAL_MANAGEMENT_PAY = new string_id("player_structure", "management_pay"); + private static final string_id SID_TERMINAL_MANAGEMENT_DESTROY = new string_id("player_structure", "permission_destroy"); + private static final string_id SID_VULNERABILITY_RESET = new string_id("hq", "vulnerability_reset"); + public static final string_id SID_VULNERABILITY_RESET_BLACKOUT_PERIOD = new string_id("hq", "vulnerability_reset_blackout_period"); + private static final string_id SID_VULNERABILITY_RESET_WRONG_CELL = new string_id("hq", "vulnerability_reset_wrong_cell"); + private static final string_id SID_VULNERABILITY_RESET_NO_LONGER_IN_STRUCTURE = new string_id("hq", "vulnerability_reset_no_longer_in_structure"); + private static final string_id SID_VULNERABILITY_RESET_REQUEST_RECEIVED = new string_id("hq", "vulnerability_reset_request_received"); + private static final string_id SID_VULNERABILITY_RESET_NOT_ALIVE = new string_id("hq", "vulnerability_reset_not_alive"); + private static final String STRING_FILE_LOC = "faction/faction_hq/faction_hq_response"; + private static final string_id SID_NO_STEALTH = new string_id("hq", "no_stealth"); + public int OnInitialize(obj_id self) throws InterruptedException + { + if (hasScript(self, hq.SCRIPT_TERMINAL_DISABLE)) + { + detachScript(self, hq.SCRIPT_TERMINAL_DISABLE); + } + return super.OnInitialize(self); + } + public int OnObjectMenuRequest(obj_id self, obj_id player, menu_info mi) throws InterruptedException + { + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return super.OnObjectMenuRequest(self, player, mi); + } + if (isGod(player) && getGodLevel(player) >= 15) + { + mi.addRootMenu(menu_info_types.SERVER_MENU12, MNU_OVERLOAD_GOD); + } + int intState = getState(player, STATE_FEIGN_DEATH); + if (isDead(player) || isIncapacitated(player) || intState > 0) + { + return super.OnObjectMenuRequest(self, player, mi); + } + obj_id structure = player_structure.getStructure(player); + if (!isIdValid(structure)) + { + return super.OnObjectMenuRequest(self, player, mi); + } + String buildingTemplate = getTemplateName(structure); + if (pvpGetAlignedFaction(player) != pvpGetAlignedFaction(structure)) + { + if (pvpGetType(player) == PVPTYPE_NEUTRAL) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response01")); + return super.OnObjectMenuRequest(self, player, mi); + } + if (hasObjVar(structure, hq.VAR_OBJECTIVE_TRACKING)) + { + obj_id[] objectives = getObjIdArrayObjVar(structure, hq.VAR_OBJECTIVE_ID); + if (objectives == null || objectives.length == 0) + { + return super.OnObjectMenuRequest(self, player, mi); + } + obj_id[] disabled = getObjIdArrayObjVar(structure, hq.VAR_OBJECTIVE_DISABLED); + if (disabled == null || disabled.length != objectives.length) + { + prose_package ppDisableOther = prose.getPackage(hq.PROSE_DISABLE_OTHER, objectives[objectives.length - 1], self); + sendSystemMessageProse(player, ppDisableOther); + return super.OnObjectMenuRequest(self, player, mi); + } + mi.addRootMenu(menu_info_types.ITEM_USE, MNU_OVERLOAD); + } + return super.OnObjectMenuRequest(self, player, mi); + } + int management_root = mi.addRootMenu(menu_info_types.ITEM_USE, SID_TERMINAL_MANAGEMENT); + if (management_root > -1) + { + mi.addSubMenu(management_root, menu_info_types.SERVER_TERMINAL_MANAGEMENT_STATUS, SID_TERMINAL_MANAGEMENT_STATUS); + if (player_structure.isAdmin(structure, player)) + { + if (!player_structure.isFactionPerkBase(buildingTemplate)) + { + mi.addSubMenu(management_root, menu_info_types.SERVER_TERMINAL_MANAGEMENT_PAY, SID_TERMINAL_MANAGEMENT_PAY); + } + if (hasObjVar(structure, "isPvpBase")) + { + int stamp = getIntObjVar(structure, "lastReset"); + int now = getGameTime(); + if (now > stamp + 1209600 || !hasObjVar(structure, "lastReset")) + { + mi.addSubMenu(management_root, menu_info_types.SERVER_MENU6, MNU_RESET_VULNERABILITY); + } + } + mi.addSubMenu(management_root, menu_info_types.SERVER_MENU5, MNU_DEFENSE_STATUS); + mi.addSubMenu(management_root, menu_info_types.SERVER_TERMINAL_MANAGEMENT_DESTROY, SID_TERMINAL_MANAGEMENT_DESTROY); + } + } + int mnuDonate = -1; + if (!player_structure.isFactionPerkBase(buildingTemplate)) + { + mnuDonate = mi.addRootMenu(menu_info_types.SERVER_MENU1, MNU_DONATE); + mi.addSubMenu(mnuDonate, menu_info_types.SERVER_MENU2, MNU_DONATE_MONEY); + } + if (hasObjVar(structure, hq.VAR_OBJECTIVE_TRACKING) || isGod(player)) + { + if (mnuDonate <= -1) + { + mnuDonate = mi.addRootMenu(menu_info_types.SERVER_MENU1, MNU_DONATE); + } + mi.addSubMenu(mnuDonate, menu_info_types.SERVER_MENU3, MNU_DONATE_DEED); + } + + //re-enable donatipn of turrents and mines + mnuDonate = mi.addRootMenu(menu_info_types.SERVER_MENU1, MNU_DONATE); + mi.addSubMenu(mnuDonate, menu_info_types.SERVER_MENU3, MNU_DONATE_DEED); + + if (utils.hasScriptVar(self, SCRIPTVAR_COUNTDOWN) && pvpGetType(player) != PVPTYPE_NEUTRAL) + { + if (hasObjVar(structure, "isPvpBase")) + { + mi.addRootMenu(menu_info_types.SERVER_MENU9, MNU_SHUTDOWN); + } + } + return super.OnObjectMenuRequest(self, player, mi); + } + public int OnObjectMenuSelect(obj_id self, obj_id player, int item) throws InterruptedException + { + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + if (isGod(player) && item == menu_info_types.SERVER_MENU12 && getGodLevel(player) >= 15) + { + startCountdown(self, player); + } + int intState = getState(player, STATE_FEIGN_DEATH); + if (isDead(player) || isIncapacitated(player) || intState > 0) + { + return SCRIPT_CONTINUE; + } + obj_id structure = player_structure.getStructure(player); + if (!isIdValid(structure)) + { + return SCRIPT_CONTINUE; + } + String buildingTemplate = getTemplateName(structure); + if (pvpGetAlignedFaction(player) != pvpGetAlignedFaction(structure)) + { + if (pvpGetType(player) == PVPTYPE_NEUTRAL) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response01")); + return SCRIPT_CONTINUE; + } + if (item == menu_info_types.ITEM_USE) + { + if (hasObjVar(structure, hq.VAR_OBJECTIVE_TRACKING)) + { + if (utils.hasScriptVar(self, SCRIPTVAR_COUNTDOWN)) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response02")); + return SCRIPT_CONTINUE; + } + obj_id[] objectives = getObjIdArrayObjVar(structure, hq.VAR_OBJECTIVE_ID); + if (objectives == null || objectives.length == 0) + { + return SCRIPT_CONTINUE; + } + obj_id[] disabled = getObjIdArrayObjVar(structure, hq.VAR_OBJECTIVE_DISABLED); + if (disabled == null || disabled.length != objectives.length) + { + prose_package ppDisableOther = prose.getPackage(hq.PROSE_DISABLE_OTHER, objectives[objectives.length - 1], self); + sendSystemMessageProse(player, ppDisableOther); + return SCRIPT_CONTINUE; + } + if (!hasSkill(player, "class_officer_phase1_novice")) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response03")); + return SCRIPT_CONTINUE; + } + startCountdown(self, player); + return SCRIPT_CONTINUE; + } + } + return SCRIPT_OVERRIDE; + } + if ((item == menu_info_types.SERVER_TERMINAL_MANAGEMENT) || (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_STATUS) || (item == menu_info_types.ITEM_USE)) + { + queueCommand(player, (335013253), null, "", COMMAND_PRIORITY_DEFAULT); + } + else if (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_PAY) + { + if (!player_structure.isFactionPerkBase(buildingTemplate)) + { + queueCommand(player, (-404530384), null, "", COMMAND_PRIORITY_DEFAULT); + } + } + else if (item == menu_info_types.SERVER_TERMINAL_MANAGEMENT_DESTROY) + { + queueCommand(player, (419174182), null, "", COMMAND_PRIORITY_DEFAULT); + } + if (item == menu_info_types.ITEM_USE) + { + return SCRIPT_CONTINUE; + } + if (item == menu_info_types.SERVER_MENU1) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response04")); + return SCRIPT_CONTINUE; + } + else if (item == menu_info_types.SERVER_MENU2) + { + if (!player_structure.isFactionPerkBase(buildingTemplate)) + { + int total = getTotalMoney(player); + if (total < 1) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response05")); + return SCRIPT_CONTINUE; + } + else + { + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response18")); + String prompt = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response17")); + sui.transfer(self, player, prompt, title, "@faction/faction_hq/faction_hq_response:terminal_response30", total, "@faction/faction_hq/faction_hq_response:terminal_response31", 0, "handleRequestDonation"); + } + } + } + else if (item == menu_info_types.SERVER_MENU3) + { + + if (hasObjVar(structure, "donateTerminalOff")) + { + int terminalOff_time = utils.getIntObjVar(structure, "donateTerminalOff"); + int termOff_remaining = 3600 - (getGameTime() - terminalOff_time); + String timeOff_remaining = player_structure.assembleTimeRemaining(player_structure.convertSecondsTime(termOff_remaining)); + prose_package ppTimeRemaining = prose.getPackage(UNDER_ATTACK, timeOff_remaining); + sendSystemMessageProse(player, ppTimeRemaining); + return SCRIPT_CONTINUE; + } + else + { + + //re-enable donation of turrets and mines + showDeedDonationUI(self, player); + /*if (hasObjVar(structure, hq.VAR_OBJECTIVE_TRACKING) || isGod(player)) + { + if (isGod(player)) + { + sendSystemMessage(player, "Warning: You are using donation function while in Godmode.", null); + } + showDeedDonationUI(self, player); + }*/ + } + } + else if (item == menu_info_types.SERVER_MENU5) + { + if (player_structure.isAdmin(structure, player)) + { + showDefenseStatusUI(self, player); + } + } + else if (item == menu_info_types.SERVER_MENU6) + { + if (player_structure.isAdmin(structure, player)) + { + if (hasObjVar(structure, "isPvpBase")) + { + int hqBlackoutPeriodStart = utils.getIntConfigSetting("ScriptFlags", "hqBlackoutPeriodStart"); + if (hqBlackoutPeriodStart == 0) + { + hqBlackoutPeriodStart = 2; + } + int hqBlackoutPeriodEnd = utils.getIntConfigSetting("ScriptFlags", "hqBlackoutPeriodEnd"); + if (hqBlackoutPeriodEnd == 0) + { + hqBlackoutPeriodEnd = 6; + } + Calendar currentCalendar = Calendar.getInstance(); + int currentHourOfDay = currentCalendar.get(Calendar.HOUR_OF_DAY); + if ((currentHourOfDay >= hqBlackoutPeriodStart) && (currentHourOfDay <= hqBlackoutPeriodEnd)) + { + prose_package pp1a = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response32"), hqBlackoutPeriodStart); + prose_package pp2a = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response37"), hqBlackoutPeriodEnd); + String oob1 = packOutOfBandProsePackage(null, pp1a); + oob1 = packOutOfBandProsePackage(oob1, pp2a); + sendSystemMessageOob(player, oob1); + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response38"), currentHourOfDay)); + } + else + { + long now = System.currentTimeMillis(); + long curTime = ((now / 1000) - 1072224000); + int currentTime = (int)curTime; + setObjVar(structure, hq.VAR_OBJECTIVE_STAMP, currentTime); + setObjVar(structure, "lastReset", getGameTime()); + sendSystemMessage(player, SID_VULNERABILITY_RESET); + } + } + } + } + else if (item == menu_info_types.SERVER_MENU9) + { + if (hasObjVar(structure, "isPvpBase")) + { + if (pvpGetType(player) != PVPTYPE_NEUTRAL) + { + if (factions.isNewlyDeclared(player)) + { + int declared_time = utils.getIntScriptVar(player, factions.VAR_NEWLY_DECLARED); + int time_remaining = factions.NEWLY_DECLARED_INTERVAL - (getGameTime() - declared_time); + LOG("LOG_CHANNEL", "declared_time ->" + declared_time + " time_remaining ->" + time_remaining); + if (time_remaining > 0) + { + String time_str = player_structure.assembleTimeRemaining(player_structure.convertSecondsTime(time_remaining)); + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response41"), time_str)); + } + else + { + utils.removeScriptVar(player, factions.VAR_NEWLY_DECLARED); + facilityShutdownDelay(self, player); + } + } + else + { + facilityShutdownDelay(self, player); + } + } + else + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response06")); + } + } + } + return SCRIPT_CONTINUE; + } + private void shutdownFacility(obj_id self) throws InterruptedException + { + attachScript(self, hq.SCRIPT_TERMINAL_DISABLE); + obj_id structure = player_structure.getStructure(self); + if (isIdValid(structure)) + { + hq.disableHqTerminals(structure); + } + abortCountdown(self); + hq.activateHackAlarms(structure, false); + messageTo(self, "handleFacilityReboot", null, 30.0f, false); + } + private void startCountdown(obj_id self, obj_id player) throws InterruptedException + { + int meleemod = getSkillStatMod(player, "group_melee_defense"); + int rangemod = getSkillStatMod(player, "group_range_defense"); + float mod = (100.0f - (meleemod + rangemod)) / 100.0f; + if (mod < 0.0f) + { + mod = 0.0f; + } + float delay = 300.0f + 300.0f * mod; + int minutes = Math.round(delay / 60.0f); + if (isGod(player) && getGodLevel(player) >= 15) + { + delay = 60; + } + obj_id[] players = player_structure.getPlayersInBuilding(getTopMostContainer(self)); + if (players != null && players.length > 0) + { + for (obj_id player1 : players) { + sendSystemMessageProse(player1, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response40"), minutes)); + } + } + int stamp = getGameTime() + Math.round(delay); + utils.setScriptVar(self, SCRIPTVAR_COUNTDOWN, stamp); + dictionary d = new dictionary(); + d.put("player", player); + d.put("cnt", minutes); + messageTo(self, "handleCountdown", d, 10.0f, false); + } + private void abortCountdown(obj_id self) throws InterruptedException + { + obj_id structure = getTopMostContainer(self); + hq.activateDestructAlarms(structure, false); + utils.removeScriptVar(self, SCRIPTVAR_COUNTDOWN); + obj_id[] players = player_structure.getPlayersInBuilding(structure); + if (players != null && players.length > 0) + { + for (obj_id player : players) { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response07")); + } + } + } + public int handleFacilityReboot(obj_id self, dictionary params) throws InterruptedException + { + detachScript(self, hq.SCRIPT_TERMINAL_DISABLE); + obj_id structure = player_structure.getStructure(self); + if (isIdValid(structure)) + { + hq.enableHqTerminals(structure); + } + obj_id[] players = player_structure.getPlayersInBuilding(getTopMostContainer(self)); + if (players != null && players.length > 0) + { + for (obj_id player : players) { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response08")); + } + } + return SCRIPT_CONTINUE; + } + public int handleCountdown(obj_id self, dictionary params) throws InterruptedException + { + if (!utils.hasScriptVar(self, SCRIPTVAR_COUNTDOWN)) + { + return SCRIPT_CONTINUE; + } + obj_id player = params.getObjId("player"); + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + if (!isIdValid(player)) + { + abortCountdown(self); + return SCRIPT_CONTINUE; + } + int cnt = params.getInt("cnt"); + int stamp = utils.getIntScriptVar(self, SCRIPTVAR_COUNTDOWN); + LOG("hqObjective", "stamp = " + stamp); + int now = getGameTime(); + LOG("hqObjective", "now = " + now); + int timeLeft = stamp - now; + int minutes = Math.round(timeLeft / 60.0f); + obj_id structure = player_structure.getStructure(self); + if (!isIdValid(structure)) + { + abortCountdown(self); + return SCRIPT_CONTINUE; + } + LOG("hqObjective", "timeLeft = " + timeLeft); + if (timeLeft < 1) + { + utils.setScriptVar(structure, "faction_hq.detonator", player); + hq.detonateHq(structure); + String hqName = getName(structure); + CustomerServiceLog("faction_hq", "Initiating destroy for Faction HQ " + hqName + " (" + structure + "), by normal terminal overload."); + return SCRIPT_CONTINUE; + } + prose_package msg = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response39"), minutes); + if (minutes >= 1) { + if (minutes < cnt) + { + obj_id[] players = player_structure.getPlayersInBuilding(structure); + if (players != null && players.length > 0) + { + for (obj_id player1 : players) { + sendSystemMessageProse(player1, msg); + } + } + params.put("cnt", minutes); + } + } + hq.activateDestructAlarms(structure, true); + messageTo(self, "handleCountdown", params, 10.0f, false); + return SCRIPT_CONTINUE; + } + public int handleDonateDeed(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = sui.getPlayerId(params); + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + String scriptvar_sui = player + ".deed.sui"; + String scriptvar_opt = player + ".deed.opt"; + obj_id[] deeds = utils.getObjIdBatchScriptVar(self, scriptvar_opt); + utils.removeScriptVar(self, scriptvar_sui); + utils.removeBatchScriptVar(self, scriptvar_opt); + if (deeds == null || deeds.length == 0) + { + return SCRIPT_CONTINUE; + } + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + int idx = sui.getListboxSelectedRow(params); + if (idx == -1 || idx > deeds.length - 1) + { + return SCRIPT_CONTINUE; + } + obj_id deed = deeds[idx]; + if (!isIdValid(deed)) + { + return SCRIPT_CONTINUE; + } + if (!utils.isNestedWithin(deed, player)) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response09")); + return SCRIPT_CONTINUE; + } + String deedType = getStringObjVar(deed, "perkDeedType"); + if (deedType != null && !deedType.equals("")) + { + if (utils.getElementPositionInArray(ACCEPTED_DEED_TYPES, deedType) == -1) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response10")); + return SCRIPT_CONTINUE; + } + else + { + if (deedType.equals("turret")) + { + obj_id objBuilding = getTopMostContainer(self); + if (isIdValid(objBuilding)) + { + //Enable turret donations to SF bases + /*if (hasObjVar(objBuilding, "isPvpBase")) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response_special_forces_no_turrets")); + return SCRIPT_CONTINUE; + }*/ + } + else + { + debugServerConsoleMsg(player, "Trying to donate turrets to a Factional HQ terminal without a topmost container"); + return SCRIPT_CONTINUE; + } + } + } + } + String displayType = utils.packStringId(new string_id("faction_perk", deedType)); + String template = ""; + int mineType = -1; + obj_id structure = player_structure.getStructure(player); + if (!isIdValid(structure)) + { + return SCRIPT_CONTINUE; + } + if (deedType != null && deedType.equals("mine")) + { + int numMines = hq.getTotalMines(structure); + if (numMines >= hq.getMaxMines(structure)) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "max_number_mines")); + return SCRIPT_CONTINUE; + } + if (hasObjVar(deed, "mineType")) + { + mineType = getIntObjVar(deed, "mineType"); + } + } + else + { + obj_id[] defensesOfType = getObjIdArrayObjVar(structure, hq.VAR_DEFENSE_BASE + "." + deedType); + if (defensesOfType == null || defensesOfType.length == 0) + { + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response43"), displayType)); + return SCRIPT_CONTINUE; + } + int pos = utils.getFirstNonValidIdIndex(defensesOfType); + if (pos < 0 || pos > defensesOfType.length - 1) + { + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response44"), displayType)); + return SCRIPT_CONTINUE; + } + template = player_structure.getDeedTemplate(deed); + if (template == null || template.equals("")) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response11")); + return SCRIPT_CONTINUE; + } + } + String sFacName = factions.getFaction(structure); + if (sFacName == null || sFacName.equals("")) + { + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response45"), displayType)); + CustomerServiceLog("faction_hq", "%TU donates a " + displayType + " deed to Factional HQ " + structure, player, null); + } + else + { + prose_package pp1b = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response46"), displayType); + prose_package pp2b = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response47"), sFacName); + String oob2 = packOutOfBandProsePackage(null, pp1b); + oob2 = packOutOfBandProsePackage(oob2, pp2b); + CustomerServiceLog("faction_hq", "%TU donates a " + displayType + " deed to Factional HQ " + structure, player, null); + sendSystemMessageOob(player, oob2); + } + destroyObject(deed); + dictionary d = new dictionary(); + d.put("template", template); + d.put("type", deedType); + d.put("mineType", mineType); + messageTo(structure, "handleAddDefense", d, 1, true); + return SCRIPT_CONTINUE; + } + public int handleDonateResourceType(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = sui.getPlayerId(params); + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + String scriptvar_sui = player + ".resource.sui"; + String scriptvar_opt = player + ".resource.opt"; + obj_id[] crates = utils.getObjIdBatchScriptVar(self, scriptvar_opt); + utils.removeScriptVar(self, scriptvar_sui); + utils.removeBatchScriptVar(self, scriptvar_opt); + if (crates == null || crates.length == 0) + { + return SCRIPT_CONTINUE; + } + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + int idx = sui.getListboxSelectedRow(params); + if (idx == -1 || idx > crates.length - 1) + { + return SCRIPT_CONTINUE; + } + obj_id crate = crates[idx]; + if (!isIdValid(crate)) + { + return SCRIPT_CONTINUE; + } + if (!utils.isNestedWithin(crate, player)) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response12")); + return SCRIPT_CONTINUE; + } + int amt = getResourceContainerQuantity(crate); + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response20")); + String prompt = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response19")); + int pid = sui.transfer(self, player, prompt, title, "@faction/faction_hq/faction_hq_response:terminal_response36", amt, "@faction/faction_hq/faction_hq_response:terminal_response31", 0, "handleDonateResourceAmt"); + if (pid > -1) + { + utils.setScriptVar(self, scriptvar_sui, pid); + utils.setScriptVar(self, scriptvar_opt, crate); + } + return SCRIPT_CONTINUE; + } + public int handleDonateResourceAmt(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = sui.getPlayerId(params); + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + String scriptvar_sui = player + ".resource.sui"; + String scriptvar_opt = player + ".resource.opt"; + obj_id crate = utils.getObjIdScriptVar(self, scriptvar_opt); + utils.removeScriptVar(self, scriptvar_sui); + utils.removeScriptVar(self, scriptvar_opt); + if (!isIdValid(crate)) + { + return SCRIPT_CONTINUE; + } + if (!utils.isNestedWithin(crate, player)) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response12")); + return SCRIPT_CONTINUE; + } + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + int amt = sui.getTransferInputTo(params); + if (amt == 0) + { + return SCRIPT_CONTINUE; + } + obj_id rtype = getResourceContainerResourceType(crate); + if (!isIdValid(rtype)) + { + return SCRIPT_CONTINUE; + } + String res_name = getResourceName(rtype); + if (removeResourceFromContainer(crate, rtype, amt)) + { + obj_id structure = player_structure.getStructure(player); + String sFacName = factions.getFaction(structure); + if (sFacName == null || sFacName.equals("")) + { + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response48"), amt)); + CustomerServiceLog("faction_hq", "%TU donates " + amt + " units of " + res_name + " to Factional HQ " + structure, player, null); + } + else + { + prose_package pp1c = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response49"), amt); + prose_package pp2c = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response50"), sFacName); + String oob3 = packOutOfBandProsePackage(null, pp1c); + oob3 = packOutOfBandProsePackage(oob3, pp2c); + CustomerServiceLog("faction_hq", "%TU donates " + amt + " units of " + res_name + " to Factional HQ " + structure, player, null); + sendSystemMessageOob(player, oob3); + } + if (!isIdValid(structure)) + { + return SCRIPT_CONTINUE; + } + int total = getIntObjVar(structure, hq.VAR_HQ_RESOURCE_CNT); + total += amt; + setObjVar(structure, hq.VAR_HQ_RESOURCE_CNT, total); + } + return SCRIPT_CONTINUE; + } + public int handleRequestDonation(obj_id self, dictionary params) throws InterruptedException + { + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + obj_id player = sui.getPlayerId(params); + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + int amt = sui.getTransferInputTo(params); + if (amt == 0) + { + return SCRIPT_CONTINUE; + } + money.requestPayment(player, self, amt, "handleCreditDonation", null, true); + return SCRIPT_CONTINUE; + } + public int handleCreditDonation(obj_id self, dictionary params) throws InterruptedException + { + if (params == null || params.isEmpty()) + { + return SCRIPT_CONTINUE; + } + int ret = params.getInt(money.DICT_CODE); + if (ret == money.RET_FAIL) + { + return SCRIPT_CONTINUE; + } + obj_id player = params.getObjId(money.DICT_PLAYER_ID); + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + obj_id structure = player_structure.getStructure(player); + int amt = params.getInt(money.DICT_TOTAL); + String sFacName = factions.getFaction(structure); + if (sFacName == null || sFacName.equals("")) + { + sendSystemMessageProse(player, prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response51"), amt)); + CustomerServiceLog("faction_hq", "%TU donated " + amt + " credits to Faction HQ " + structure, player, null); + } + else + { + prose_package pp1d = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response52"), amt); + prose_package pp2d = prose.getPackage(new string_id(STRING_FILE_LOC, "terminal_response53"), sFacName); + String oob4 = packOutOfBandProsePackage(null, pp1d); + oob4 = packOutOfBandProsePackage(oob4, pp2d); + sendSystemMessageOob(player, oob4); + CustomerServiceLog("faction_hq", "%TU donated " + amt + " credits to Faction HQ " + structure, player, null); + } + if (isIdValid(structure)) + { + money.bankTo(self, structure, amt); + } + return SCRIPT_CONTINUE; + } + public int handleDefenseSelection(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = sui.getPlayerId(params); + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + String scriptvar_sui = player + ".defense.sui"; + String scriptvar_opt = player + ".defense.opt"; + obj_id[] opt = utils.getObjIdBatchScriptVar(self, scriptvar_opt); + utils.removeScriptVar(self, scriptvar_sui); + utils.removeBatchScriptVar(self, scriptvar_opt); + if (opt == null || opt.length == 0) + { + return SCRIPT_CONTINUE; + } + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + int idx = sui.getListboxSelectedRow(params); + if (idx == -1 || idx > opt.length - 1) + { + return SCRIPT_CONTINUE; + } + obj_id defense = opt[idx]; + if (!isIdValid(defense)) + { + return SCRIPT_CONTINUE; + } + if (!exists(defense) || !defense.isLoaded()) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response13")); + return SCRIPT_CONTINUE; + } + int max_hp = getMaxHitpoints(defense); + int cur_hp = getHitpoints(defense); + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response24")); + String prompt = getString(new string_id(STRING_FILE_LOC, "terminal_response25")); + prompt += "/n/n" + getString(new string_id(STRING_FILE_LOC, "selected_defense")) + utils.getStringName(defense) + " [" + cur_hp + "/" + max_hp + "]"; + if (hasScript(defense, "faction_perk.minefield.advanced_minefield")) + { + prompt = getString(new string_id(STRING_FILE_LOC, "terminal_response25a")); + } + int pid = sui.msgbox(self, player, prompt, sui.YES_NO, title, "handleDefenseRemoveConfirm"); + if (pid > -1) + { + utils.setScriptVar(self, scriptvar_sui, pid); + utils.setScriptVar(self, scriptvar_opt, defense); + } + return SCRIPT_CONTINUE; + } + public int handleDefenseRemoveConfirm(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = sui.getPlayerId(params); + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + String scriptvar_sui = player + ".defense.sui"; + String scriptvar_opt = player + ".defense.opt"; + obj_id defense = utils.getObjIdScriptVar(self, scriptvar_opt); + utils.removeScriptVar(self, scriptvar_sui); + utils.removeScriptVar(self, scriptvar_opt); + if (!isIdValid(defense) || !exists(defense) || !defense.isLoaded()) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response13")); + return SCRIPT_CONTINUE; + } + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response58")); + utils.setScriptVar(defense, "hq.defense.remover", player); + if (hasScript(defense, "faction_perk.minefield.advanced_minefield")) + { + hq.clearMinefield(player_structure.getStructure(player)); + } + else + { + destroyObject(defense); + } + return SCRIPT_CONTINUE; + } + public void showResourceDonationUI(obj_id terminal, obj_id player) throws InterruptedException + { + if (!isIdValid(terminal) || !isIdValid(player)) + { + return; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return; + } + String scriptvar_sui = player + ".resource.sui"; + String scriptvar_opt = player + ".resource.opt"; + if (utils.hasScriptVar(terminal, scriptvar_sui)) + { + sui.closeSUI(player, utils.getIntScriptVar(terminal, scriptvar_sui)); + utils.removeScriptVar(terminal, scriptvar_sui); + utils.removeBatchScriptVar(terminal, scriptvar_opt); + } + obj_id[] crates = utils.getContainedGOTObjects(player, GOT_resource_container, true, true); + if (crates == null || crates.length == 0) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response14")); + return; + } + Vector entries = new Vector(); + entries.setSize(0); + for (obj_id crate : crates) { + if (isIdValid(crate)) { + entries = utils.addElement(entries, getString(getNameStringId(crate)) + " [" + getResourceContainerQuantity(crate) + "]"); + } + } + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response20")); + String prompt = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response29")); + int pid = sui.listbox(terminal, player, prompt, sui.OK_CANCEL, title, entries, "handleDonateResourceType"); + if (pid > -1) + { + utils.setScriptVar(terminal, scriptvar_sui, pid); + utils.setBatchScriptVar(terminal, scriptvar_opt, crates); + } + } + private void showDeedDonationUI(obj_id terminal, obj_id player) throws InterruptedException + { + if (!isIdValid(terminal) || !isIdValid(player)) + { + return; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return; + } + LOG("hq", " //***// showDeedDonationUI entered... passed in terminal:" + terminal + " and player:" + player); + String scriptvar_sui = player + ".deed.sui"; + String scriptvar_opt = player + ".deed.opt"; + LOG("hq", " //***// showDeedDonationUI ... string scriptvar_sui =" + scriptvar_sui + " and string scriptvar_opt =" + scriptvar_opt); + if (utils.hasScriptVar(terminal, scriptvar_sui)) + { + LOG("hq", " //***// showDeedDonationUI ... utils.hasScriptVar(terminal, scriptvar_sui) is AFFIRM"); + sui.closeSUI(player, utils.getIntScriptVar(terminal, scriptvar_sui)); + utils.removeScriptVar(terminal, scriptvar_sui); + utils.removeScriptVar(terminal, scriptvar_opt); + } + obj_id[] deeds = utils.getContainedObjectsWithObjVar(player, "perkDeedType", true); + if (deeds == null || deeds.length == 0) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response15")); + return; + } + Vector entries = new Vector(); + entries.setSize(0); + Vector opt = new Vector(); + opt.setSize(0); + for (int i = 0; i < deeds.length; i++) + { + LOG("hq", " //***// showDeedDonationUI ... counting through GOT_deed objects in player inventory. Currently on item# " + i); + obj_id deed = deeds[i]; + if (isIdValid(deed)) + { + String deedType = getStringObjVar(deed, "perkDeedType"); + if (deedType != null && !deedType.equals("")) + { + LOG("hq", " //***// showDeedDonationUI ... deed item# " + i + " has 'perkDeedType' objvar of: " + deedType); + if (utils.getElementPositionInArray(ACCEPTED_DEED_TYPES, deedType) > -1) + { + opt = utils.addElement(opt, deed); + entries = utils.addElement(entries, getEncodedName(deed)); + } + } + } + } + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response26")); + String prompt = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response23")); + LOG("hq", " //***// showDeedDonationUI ... title= " + title + " and prompt = " + prompt + " size of 'entries' array is:" + entries.size()); + int pid = sui.listbox(terminal, player, prompt, sui.OK_CANCEL, title, entries, "handleDonateDeed"); + if (pid > -1) + { + utils.setScriptVar(terminal, scriptvar_sui, pid); + utils.setBatchScriptVar(terminal, scriptvar_opt, opt); + } + } + private void showDefenseStatusUI(obj_id terminal, obj_id player) throws InterruptedException + { + if (!isIdValid(terminal) || !isIdValid(player)) + { + return; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return; + } + String scriptvar_sui = player + ".defense.sui"; + String scriptvar_opt = player + ".defense.opt"; + if (utils.hasScriptVar(terminal, scriptvar_sui)) + { + sui.closeSUI(player, utils.getIntScriptVar(terminal, scriptvar_sui)); + utils.removeScriptVar(terminal, scriptvar_sui); + utils.removeScriptVar(terminal, scriptvar_opt); + } + obj_id structure = player_structure.getStructure(player); + if (!isIdValid(structure)) + { + return; + } + Vector entries = new Vector(); + entries.setSize(0); + Vector opt = new Vector(); + opt.setSize(0); + obj_var_list ovl = getObjVarList(structure, hq.VAR_DEFENSE_BASE); + if (ovl == null) + { + sendSystemMessage(player, new string_id(STRING_FILE_LOC, "terminal_response14")); + return; + } + int numTypes = ovl.getNumItems(); + obj_var ov; + String ovName; + obj_id[] data; + String sName; + for (int i = 0; i < numTypes; i++) + { + ov = ovl.getObjVar(i); + ovName = ov.getName(); + entries = utils.addElement(entries, toUpper(ovName)); + opt = utils.addElement(opt, obj_id.NULL_ID); + data = ov.getObjIdArrayData(); + if (data != null && data.length > 0) + { + int validCount = 0; + for (obj_id aData : data) { + if (isIdValid(aData)) { + sName = utils.getStringName(aData); + int max_hp = getMaxHitpoints(aData); + int cur_hp = getHitpoints(aData); + if (hasScript(aData, "faction_perk.minefield.advanced_minefield")) { + entries = utils.addElement(entries, "- " + hq.getTotalMines(structure) + "/" + hq.getMaxMines(structure) + " mines"); + } else { + entries = utils.addElement(entries, "- " + sName + " [" + cur_hp + "/" + max_hp + "]"); + } + opt = utils.addElement(opt, aData); + validCount++; + } + } + if (validCount == 0) + { + entries = utils.addElement(entries, "- none"); + opt = utils.addElement(opt, obj_id.NULL_ID); + } + } + } + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response23")); + String prompt = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response22")); + int pid = sui.listbox(terminal, player, prompt, sui.REMOVE_CANCEL, title, entries, "handleDefenseSelection"); + if (pid > -1) + { + utils.setScriptVar(terminal, scriptvar_sui, pid); + utils.setBatchScriptVar(terminal, scriptvar_opt, opt); + } + } + private void facilityShutdownDelay(obj_id terminal, obj_id player) throws InterruptedException + { + if (!isIdValid(terminal) || !isIdValid(player)) + { + return; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return; + } + String currentCell = null; + location locTest = getLocation(player); + if (isIdValid(locTest.cell)) + { + currentCell = getCellName(locTest.cell); + } + sendSystemMessage(player, SID_VULNERABILITY_RESET_REQUEST_RECEIVED); + dictionary params = new dictionary(); + params.put("player", player); + if (currentCell != null && !currentCell.equals("null")) + { + params.put("cellName", currentCell); + } + messageTo(terminal, "handleShutdownCountdownComplete", params, 60.0f, false); + } + public int handleShutdownCountdownComplete(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = params.getObjId("player"); + String triggeringCell = params.getString("cellName"); + if (!isIdValid(player) || !isIdValid(self)) + { + return SCRIPT_CONTINUE; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + obj_id structure = player_structure.getStructure(self); + if (!isIdValid(structure)) + { + return SCRIPT_CONTINUE; + } + if (hasObjVar(structure, hq.VAR_TERMINAL_DISABLE)) + { + boolean structureState = getBooleanObjVar(structure, hq.VAR_TERMINAL_DISABLE); + if (structureState) + { + return SCRIPT_CONTINUE; + } + } + String currentCell = null; + location locTest = getLocation(player); + if (isIdValid(locTest.cell)) + { + currentCell = getCellName(locTest.cell); + } + if ((!isIdValid(locTest.cell)) || (currentCell != null && !currentCell.equals(triggeringCell))) + { + sendSystemMessage(player, SID_VULNERABILITY_RESET_WRONG_CELL); + return SCRIPT_CONTINUE; + } + if (isIncapacitated(player) || isDead(player)) + { + sendSystemMessage(player, SID_VULNERABILITY_RESET_NOT_ALIVE); + return SCRIPT_CONTINUE; + } + String title = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response27")); + String prompt = utils.packStringId(new string_id(STRING_FILE_LOC, "terminal_response28")); + sui.msgbox(self, player, title, sui.YES_NO, prompt, "handleShutdownConfirm"); + return SCRIPT_CONTINUE; + } + public int handleShutdownConfirm(obj_id self, dictionary params) throws InterruptedException + { + obj_id player = sui.getPlayerId(params); + if (!isIdValid(player)) + { + return SCRIPT_CONTINUE; + } + if (stealth.hasInvisibleBuff(player)) + { + sendSystemMessage(player, SID_NO_STEALTH); + return SCRIPT_CONTINUE; + } + int bp = sui.getIntButtonPressed(params); + if (bp == sui.BP_CANCEL) + { + return SCRIPT_CONTINUE; + } + obj_id structure = player_structure.getStructure(self); + if (hasObjVar(structure, hq.VAR_TERMINAL_DISABLE)) + { + boolean structureState = getBooleanObjVar(structure, hq.VAR_TERMINAL_DISABLE); + if (structureState) + { + return SCRIPT_CONTINUE; + } + } + obj_id currentStructure = player_structure.getStructure(player); + if (currentStructure != structure) + { + sendSystemMessage(player, SID_VULNERABILITY_RESET_NO_LONGER_IN_STRUCTURE); + return SCRIPT_CONTINUE; + } + shutdownFacility(self); + return SCRIPT_CONTINUE; + } + public int handleAlarmMute(obj_id self, dictionary params) throws InterruptedException + { + obj_id structure = player_structure.getStructure(self); + if (isIdValid(structure)) + { + hq.activateHackAlarms(structure, false); + } + return SCRIPT_CONTINUE; + } +} diff --git a/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/terminal_manager.java b/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/terminal_manager.java new file mode 100644 index 0000000..2a97703 --- /dev/null +++ b/Enable Turrets/dsrc/sku.0/sys.server/compiled/game/script/faction_perk/hq/terminal_manager.java @@ -0,0 +1,53 @@ +package script.faction_perk.hq; + +import script.dictionary; +import script.library.hq; +import script.obj_id; + +public class terminal_manager extends script.base_script +{ + public terminal_manager() + { + } + public int OnInitialize(obj_id self) throws InterruptedException + { + hq.loadHqTerminals(self); + hq.enableHqTerminals(self); + hq.loadAlarmUnits(self); + hq.loadTurretTerminals(self); + return SCRIPT_CONTINUE; + } + public int OnDestroy(obj_id self) throws InterruptedException + { + hq.cleanupBaseAlarmUnits(self); + return SCRIPT_CONTINUE; + } + public int OnMaintenanceLoop(obj_id self, dictionary params) throws InterruptedException + { + int hp = getHitpoints(self); + boolean disabled = getBooleanObjVar(self, hq.VAR_TERMINAL_DISABLE); + if (hp > 0 && disabled) + { + hq.enableHqTerminals(self); + } + else if (hp < 1 && !disabled) + { + hq.disableHqTerminals(self); + } + return SCRIPT_CONTINUE; + } + public int terminalOff(obj_id self, dictionary params) throws InterruptedException + { + if (hasObjVar(self, "hq.objective.tracking")) + { + setObjVar(self, "donateTerminalOff", getGameTime()); + messageTo(self, "terminalOn", null, 3600.0f, true); + } + return SCRIPT_CONTINUE; + } + public int terminalOn(obj_id self, dictionary params) throws InterruptedException + { + removeObjVar(self, "donateTerminalOff"); + return SCRIPT_CONTINUE; + } +}