From 8fc7a3e8d89fd24b20c3a3c0e3f7e99bb4916c61 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sun, 20 Jun 2021 03:23:52 +0200 Subject: [PATCH] [MIRROR] Fixes OOC heart commendations (#6393) * Fixes OOC heart commendations (#59543) At some point in the last few weeks, the OOC heart commendations that players were polled for during the shuttle's return trip at the end of the round stopped appearing for people on the live servers, even though admin logs showed it was still calculating how many people were supposed to be asked, and it seemed to be working fine on my local server. My only guess is it might somehow be related to #58419 since that was the last PR to touch hearted.dm, even if it's not clear how it might've broken it. I also neaten up the code for commendations a bit, making it so the procs are easier to follow and have less unnecessary checks. Also, the proc nominate_heart has been reworked to receive_heart, since it makes more sense for it to run on the person receiving the commendation as opposed to the person sending it. It will also properly cancel polling if the "how many to ask" check returns 0 people, rather than always polling at least one. Edit: Figured it out, #58419 was indeed the culprit, it blindly replaced src with usr without considering that src and usr aren't necessarily the same thing (as it was here, since query_heart() was called by the ticker SS) * Fixes OOC heart commendations Co-authored-by: Ryll Ryll <3589655+Ryll-Ryll@users.noreply.github.com> --- code/__HELPERS/hearted.dm | 30 ++++++++++++++++++------------ code/modules/admin/topic.dm | 7 ++----- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/code/__HELPERS/hearted.dm b/code/__HELPERS/hearted.dm index 391f45ab303..75957b1a93a 100644 --- a/code/__HELPERS/hearted.dm +++ b/code/__HELPERS/hearted.dm @@ -4,6 +4,9 @@ return var/number_to_ask = round(LAZYLEN(GLOB.joined_player_list) * CONFIG_GET(number/commendation_percent_poll)) + rand(0,1) + if(number_to_ask == 0) + message_admins("Not enough eligible players to poll for commendations.") + return message_admins("Polling [number_to_ask] players for commendations.") for(var/i in GLOB.joined_player_list) @@ -31,9 +34,9 @@ /// Ask someone if they'd like to award a commendation for the round, 3 tries to get the name they want before we give up /mob/proc/query_heart(attempt=1) - if(!mind || !client || attempt > 3) + if(!client || attempt > 3) return - if(attempt == 1 && tgui_alert(usr, "Was there another character you noticed being kind this round that you would like to anonymously thank?", "<3?", list("Yes", "No"), timeout = 30 SECONDS) != "Yes") + if(attempt == 1 && tgui_alert(src, "Was there another character you noticed being kind this round that you would like to anonymously thank?", "<3?", list("Yes", "No"), timeout = 30 SECONDS) != "Yes") return var/heart_nominee @@ -60,9 +63,9 @@ if(heart_contender == src) continue - switch(tgui_alert(usr, "Is this the person: [heart_contender.real_name]?", "<3?", list("Yes!", "Nope", "Cancel"), timeout = 15 SECONDS)) + switch(tgui_alert(src, "Is this the person: [heart_contender.real_name]?", "<3?", list("Yes!", "Nope", "Cancel"), timeout = 15 SECONDS)) if("Yes!") - nominate_heart(heart_contender) + heart_contender.receive_heart(src) return if("Nope") continue @@ -74,18 +77,21 @@ /* * Once we've confirmed who we're commending, either set their status now or log it for the end of the round * +* This used to be reversed, being named nominate_heart and being called on the mob sending the commendation and the first argument being +* the heart_recepient, but that was confusing and unintuitive, so now src is the person being commended and the sender is now the first argument. +* * Arguments: -* * heart_recepient: The reference to the mob who we want to commend. Note that if we delay to the end of the round, we log the mob's current ckey in case they change bodies +* * heart_sender: The reference to the mob who sent the commendation, just for the purposes of logging * * duration: How long from the moment it's applied the heart will last * * instant: If TRUE (or if the round is already over), we'll give them the heart status now, if FALSE, we wait until the end of the round (which is the standard behavior) */ -/mob/proc/nominate_heart(mob/heart_recepient, duration = 24 HOURS, instant = FALSE) - if(!mind || !client || !heart_recepient?.client) +/mob/proc/receive_heart(mob/heart_sender, duration = 24 HOURS, instant = FALSE) + if(!client) return - to_chat(src, span_nicegreen("Commendation sent!")) - message_admins("[key_name(src)] commended [key_name(heart_recepient)] [instant ? "" : "(roundend)"]") - log_admin("[key_name(src)] commended [key_name(heart_recepient)] [instant ? "" : "(roundend)"]") + to_chat(heart_sender, span_nicegreen("Commendation sent!")) + message_admins("[key_name(heart_sender)] commended [key_name(src)] [instant ? "(instant)" : ""]") + log_admin("[key_name(heart_sender)] commended [key_name(src)] [instant ? "(instant)" : ""]") if(instant || SSticker.current_state == GAME_STATE_FINISHED) - heart_recepient.client?.adjust_heart(duration) + client.adjust_heart(duration) else - LAZYADD(SSticker.hearts, heart_recepient.ckey) + LAZYADD(SSticker.hearts, ckey) diff --git a/code/modules/admin/topic.dm b/code/modules/admin/topic.dm index 3c5b9ae93f2..37ba3ac92f6 100644 --- a/code/modules/admin/topic.dm +++ b/code/modules/admin/topic.dm @@ -1995,9 +1995,6 @@ poll_option_parse_href(href_list, poll, option) else if(href_list["admincommend"]) - if(!SSticker.IsRoundInProgress()) - to_chat(usr, span_warning("The round must be in progress to use this!")) - return var/mob/heart_recepient = locate(href_list["admincommend"]) if(!heart_recepient?.ckey) to_chat(usr, span_warning("This mob either no longer exists or no longer is being controlled by someone!")) @@ -2005,9 +2002,9 @@ switch(tgui_alert(usr, "Would you like the effects to apply immediately or at the end of the round? Applying them now will make it clear it was an admin commendation.", "<3?", list("Apply now", "Apply at round end", "Cancel"))) if("Apply now") - usr.nominate_heart(heart_recepient, instant = TRUE) + heart_recepient.receive_heart(usr, instant = TRUE) if("Apply at round end") - usr.nominate_heart(heart_recepient) + heart_recepient.receive_heart(usr) else return