Skip to content
This repository has been archived by the owner on Sep 8, 2022. It is now read-only.

[MIRROR] Fix spawning multiple pirate ships and refactor comms console answer keys #1019

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions code/__DEFINES/misc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,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"
8 changes: 4 additions & 4 deletions code/game/machinery/computer/communications.dm
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@
if ("answerMessage")
if (!authenticated(usr))
return
var/answer_index = text2num(params["answer"])
var/answer_key = params["answer"]
var/message_index = text2num(params["message"])
if (!answer_index || !message_index || answer_index < 1 || message_index < 1)
if (!answer_key || !message_index || message_index < 1)
return
var/datum/comm_message/message = messages[message_index]
if (message.answered)
if (!(answer_key in message.possible_answers) || message.answered)
return
message.answered = answer_index
message.answered = answer_key
message.answer_callback.InvokeAsync()
. = TRUE
if ("callShuttle")
Expand Down
24 changes: 24 additions & 0 deletions code/modules/events/pirates.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions tgui/packages/tgui/interfaces/CommunicationsConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ const PageBuyingShuttle = (props, context) => {
data.budget < shuttle.creditCost ? (`You need ${
shuttle.creditCost - data.budget
} more credits.`
) : (shuttle.illegal
? ILLEGAL_SHUTTLE_NOTICE
) : (shuttle.illegal
? ILLEGAL_SHUTTLE_NOTICE
: undefined)
}
tooltipPosition="left"
Expand Down Expand Up @@ -619,17 +619,17 @@ const PageMessages = (props, context) => {
messages.map((message, messageIndex) => {
let answers = null;

if (message.possibleAnswers.length > 0) {
if (Object.keys(message.possibleAnswers).length > 0) {
answers = (
<Box mt={1}>
{message.possibleAnswers.map((answer, answerIndex) => (
{Object.entries(message.possibleAnswers).map((answer) => (
<Button
content={answer}
color={message.answered === answerIndex + 1 ? "good" : undefined}
key={answerIndex}
content={answer[1]}
color={message.answered === answer[0] ? "good" : undefined}
key={answer[0]}
onClick={message.answered ? undefined : () => act("answerMessage", {
message: messageIndex + 1,
answer: answerIndex + 1,
answer: answer[0],
})}
/>
))}
Expand Down Expand Up @@ -678,7 +678,7 @@ const ConditionalTooltip = (props, context) => {
{
return children;
}

return (
<Tooltip {...rest}>
{children}
Expand Down Expand Up @@ -748,7 +748,7 @@ export const CommunicationsConsole = (props, context) => {
<Tabs.Tab fluid
icon="shopping-cart"
selected={page===STATE_BUYING_SHUTTLE}
onClick={() => act("setState",
onClick={() => act("setState",
{ state: STATE_BUYING_SHUTTLE }
)}>
Purchase Shuttle
Expand Down