From b72c477743a69769e04e878add6e64b2ee7a829e Mon Sep 17 00:00:00 2001 From: itsmeow Date: Sat, 3 Sep 2022 16:24:32 -0500 Subject: [PATCH 1/2] Fix spawning multiple pirate ships and refactor comms console answer keys (#7608) --- code/__DEFINES/misc.dm | 4 + .../game/machinery/computer/communications.dm | 50 ++ code/modules/events/pirates.dm | 24 + .../tgui/interfaces/CommunicationsConsole.js | 794 ++++++++++++++++++ 4 files changed, 872 insertions(+) create mode 100644 tgui/packages/tgui/interfaces/CommunicationsConsole.js diff --git a/code/__DEFINES/misc.dm b/code/__DEFINES/misc.dm index c20cf59c50e..7260f4b139a 100644 --- a/code/__DEFINES/misc.dm +++ b/code/__DEFINES/misc.dm @@ -476,3 +476,7 @@ GLOBAL_LIST_INIT(pda_styles, sortList(list(MONO, VT, ORBITRON, SHARE))) #define ALIGNMENT_GOOD "good" #define ALIGNMENT_NEUT "neutral" #define ALIGNMENT_EVIL "evil" + +// Pirates threat +#define PIRATE_RESPONSE_NO_PAY "pirate_answer_no_pay" +#define PIRATE_RESPONSE_PAY "pirate_answer_pay" diff --git a/code/game/machinery/computer/communications.dm b/code/game/machinery/computer/communications.dm index 58fe97af97d..46fa9df6c20 100755 --- a/code/game/machinery/computer/communications.dm +++ b/code/game/machinery/computer/communications.dm @@ -431,10 +431,60 @@ to_chat(user, "Unable to establish a connection: \black You're too far away from the station!") return +<<<<<<< HEAD var/dat = "" if(SSshuttle.emergency.mode == SHUTTLE_CALL) var/timeleft = SSshuttle.emergency.timeLeft() dat += "Emergency shuttle\n
\nETA: [timeleft / 60 % 60]:[add_leading(num2text(timeleft % 60), 2, "0")]" +======= + switch (action) + if ("answerMessage") + if (!authenticated(usr)) + return + var/answer_key = params["answer"] + var/message_index = text2num(params["message"]) + if (!answer_key || !message_index || message_index < 1) + return + var/datum/comm_message/message = messages[message_index] + if (!(answer_key in message.possible_answers) || message.answered) + return + message.answered = answer_key + message.answer_callback.InvokeAsync() + . = TRUE + if ("callShuttle") + if (!authenticated(usr)) + return + var/reason = trim(params["reason"], MAX_MESSAGE_LEN) + if (length(reason) < CALL_SHUTTLE_REASON_LENGTH) + return + SSshuttle.requestEvac(usr, reason) + post_status("shuttle") + . = TRUE + if ("changeSecurityLevel") + if (!authenticated_as_silicon_or_captain(usr)) + return + + // Check if they have + if (!issilicon(usr)) + var/obj/item/held_item = usr.get_active_held_item() + var/obj/item/card/id/id_card = held_item?.GetID() + if (!istype(id_card)) + to_chat(usr, "You need to swipe your ID!") + playsound(src, 'sound/machines/terminal_prompt_deny.ogg', 50, FALSE) + return + if (!(ACCESS_CAPTAIN in id_card.access)) + to_chat(usr, "You are not authorized to do this!") + playsound(src, 'sound/machines/terminal_prompt_deny.ogg', 50, FALSE) + return + + var/new_sec_level = seclevel2num(params["newSecurityLevel"]) + if (new_sec_level != SEC_LEVEL_GREEN && new_sec_level != SEC_LEVEL_BLUE) + return + if (GLOB.security_level == new_sec_level) + return + + set_security_level(new_sec_level) +>>>>>>> cd56f3f974... Fix spawning multiple pirate ships and refactor comms console answer keys (#7608) var/datum/browser/popup = new(user, "communications", "Communications Console", 400, 500) diff --git a/code/modules/events/pirates.dm b/code/modules/events/pirates.dm index 798bdabf34b..c3a73f73370 100644 --- a/code/modules/events/pirates.dm +++ b/code/modules/events/pirates.dm @@ -37,12 +37,28 @@ payoff = max(payoff_min, FLOOR(D.account_balance * 0.80, 1000)) threat.title = "Business proposition" threat.content = "This is [ship_name]. Pay up [payoff] credits or you'll walk the plank." +<<<<<<< HEAD threat.possible_answers = list("We'll pay.","No way.") threat.answer_callback = CALLBACK(src,.proc/answered) SScommunications.send_message(threat,unique = TRUE) /datum/round_event/pirates/proc/answered() if(threat && threat.answered == 1) +======= + threat.possible_answers = list( + PIRATE_RESPONSE_PAY = "We'll pay.", + PIRATE_RESPONSE_NO_PAY = "No way.", + ) + threat.answer_callback = CALLBACK(GLOBAL_PROC, .proc/pirates_answered, threat, payoff, ship_name, initial_send_time, response_max_time) + addtimer(CALLBACK(GLOBAL_PROC, .proc/spawn_pirates, threat, FALSE), response_max_time) + SScommunications.send_message(threat,unique = TRUE) + +/proc/pirates_answered(datum/comm_message/threat, payoff, ship_name, initial_send_time, response_max_time) + if(world.time > initial_send_time + response_max_time) + priority_announce("Too late to beg for mercy!",sender_override = ship_name) + return + if(threat?.answered) +>>>>>>> cd56f3f974... Fix spawning multiple pirate ships and refactor comms console answer keys (#7608) var/datum/bank_account/D = SSeconomy.get_dep_account(ACCOUNT_CAR) if(D) if(D.adjust_money(-payoff)) @@ -51,6 +67,7 @@ return else priority_announce("Trying to cheat us? You'll regret this!", sound = SSstation.announcer.get_rand_alert_sound(), sender_override = ship_name) +<<<<<<< HEAD if(!shuttle_spawned) spawn_shuttle() else @@ -65,6 +82,13 @@ /datum/round_event/pirates/proc/spawn_shuttle() shuttle_spawned = TRUE +======= + spawn_pirates(threat, TRUE) + +/proc/spawn_pirates(datum/comm_message/threat, skip_answer_check) + if(!skip_answer_check && threat?.answered == PIRATE_RESPONSE_NO_PAY) + return +>>>>>>> cd56f3f974... Fix spawning multiple pirate ships and refactor comms console answer keys (#7608) var/list/candidates = pollGhostCandidates("Do you wish to be considered for pirate crew?", ROLE_TRAITOR) shuffle_inplace(candidates) diff --git a/tgui/packages/tgui/interfaces/CommunicationsConsole.js b/tgui/packages/tgui/interfaces/CommunicationsConsole.js new file mode 100644 index 00000000000..19f8e52e056 --- /dev/null +++ b/tgui/packages/tgui/interfaces/CommunicationsConsole.js @@ -0,0 +1,794 @@ +import { sortBy } from "common/collections"; +import { capitalize } from "common/string"; +import { useBackend, useLocalState } from "../backend"; +import { Blink, Box, Button, Dimmer, Flex, Icon, Input, Modal, NoticeBox, Section, Stack, Tabs, TextArea, Tooltip } from "../components"; +import { Window } from "../layouts"; +import { sanitizeText } from "../sanitize"; + +const STATE_BUYING_SHUTTLE = "buying_shuttle"; +const STATE_CHANGING_STATUS = "changing_status"; +const STATE_MESSAGES = "messages"; + +// Used for whether or not you need to swipe to confirm an alert level change +const SWIPE_NEEDED = "SWIPE_NEEDED"; + +const ILLEGAL_SHUTTLE_NOTICE + = "Warning: Safety features disabled. This shuttle is uncertified. Order at your own peril."; +const sortShuttles = sortBy( + shuttle => !shuttle.illegal, + shuttle => shuttle.creditCost +); + +const AlertButton = (props, context) => { + const { act, data } = useBackend(context); + const { alertLevelTick, canSetAlertLevel } = data; + const { alertLevel, setShowAlertLevelConfirm } = props; + + const thisIsCurrent = data.alertLevel === alertLevel; + + return ( +