Add cooldown for unintentional emotes (#19078)

* Add cooldown for unintentional emotes

* Oops, let's try that again.
- Adds a separate cooldown system for unintentional emotes.
- Unintentional emotes will fire audio at most once every 2 seconds.
- Emotes like deathgasp can override this out of necessity.
- Scream's is longer because...come on.

* The part that makes the rest of it actualy work
This commit is contained in:
Luc
2022-09-25 12:31:26 -04:00
committed by GitHub
parent 6aefc49682
commit 96aab66dc6
7 changed files with 43 additions and 18 deletions
@@ -99,6 +99,7 @@
vary = TRUE
age_based = TRUE
cooldown = 5 SECONDS
unintentional_audio_cooldown = 3.5 SECONDS
mob_type_blacklist_typecache = list(
/mob/living/carbon/human/monkey, // screech instead
/mob/living/silicon // Robot sounds
+1
View File
@@ -71,6 +71,7 @@
cooldown = 10 SECONDS
volume = 40
unintentional_stat_allowed = DEAD
bypass_unintentional_cooldown = TRUE // again, this absolutely MUST play when a user dies, if it can.
message = "seizes up and falls limp, their eyes dead and lifeless..."
message_alien = "seizes up and falls limp, their eyes dead and lifeless..."
message_robot = "shudders violently for a moment before falling still, its eyes slowly darkening."
@@ -1542,7 +1542,7 @@ GLOBAL_LIST_INIT(robot_verbs_default, list(
if(!is_component_functioning("power cell") || !cell || !cell.charge)
if(!start_audio_emote_cooldown(10 SECONDS))
if(!start_audio_emote_cooldown(TRUE, 10 SECONDS))
to_chat(src, "<span class='warning'>The low-power capacitor for your speaker system is still recharging, please try again later.</span>")
return
visible_message("<span class='warning'>The power warning light on <span class='name'>[src]</span> flashes urgently.</span>",\
+3 -1
View File
@@ -102,12 +102,14 @@
/// Cooldown on audio effects from emotes.
var/audio_emote_cd_status = EMOTE_READY
/// Cooldown on audio effects from unintentional emotes.
var/audio_emote_unintentional_cd_status = EMOTE_READY
/// Override for cooldowns on non-audio emotes. Should be a number in deciseconds.
var/emote_cooldown_override = null
/// Tracks last uses of emotes for cooldown purposes
var/list/emotes_used
var/list/emotes_on_cooldown
var/job = null //Living
+27 -13
View File
@@ -755,8 +755,9 @@ GLOBAL_LIST_INIT(intents, list(INTENT_HELP,INTENT_DISARM,INTENT_GRAB,INTENT_HARM
/**
* Helper proc to determine if a mob can use emotes that make sound or not.
*/
/mob/proc/can_use_audio_emote()
switch(audio_emote_cd_status)
/mob/proc/can_use_audio_emote(intentional)
var/emote_status = intentional ? audio_emote_cd_status : audio_emote_unintentional_cd_status
switch(emote_status)
if(EMOTE_INFINITE) // Spam those emotes
return TRUE
if(EMOTE_ADMIN_BLOCKED) // Cooldown emotes were disabled by an admin, prevent use
@@ -769,24 +770,37 @@ GLOBAL_LIST_INIT(intents, list(INTENT_HELP,INTENT_DISARM,INTENT_GRAB,INTENT_HARM
CRASH("Invalid emote type")
/**
* # Start the cooldown for an emote that plays audio.
* Start the cooldown for an emote that plays audio.
*
* * cooldown: The amount of time that should be waited before any other audio emote can fire.
* Arguments:
* * intentional - Whether or not the user deliberately triggered this emote.
* * cooldown - The amount of time that should be waited before any other audio emote can fire.
*/
/mob/proc/start_audio_emote_cooldown(cooldown = AUDIO_EMOTE_COOLDOWN)
if(!can_use_audio_emote())
/mob/proc/start_audio_emote_cooldown(intentional, cooldown = AUDIO_EMOTE_COOLDOWN)
if(!can_use_audio_emote(intentional))
return FALSE
if(audio_emote_cd_status == EMOTE_READY)
audio_emote_cd_status = EMOTE_ON_COOLDOWN // Starting cooldown
addtimer(CALLBACK(src, .proc/on_audio_emote_cooldown_end), cooldown)
var/cooldown_source = intentional ? audio_emote_cd_status : audio_emote_unintentional_cd_status
if(cooldown_source == EMOTE_READY)
// we do have to juggle between cooldowns a little bit, but this lets us keep them on separate cooldowns so
// a user screaming every five seconds doesn't prevent them from sneezing.
if(intentional)
audio_emote_cd_status = EMOTE_ON_COOLDOWN // Starting cooldown
else
audio_emote_unintentional_cd_status = EMOTE_ON_COOLDOWN
addtimer(CALLBACK(src, .proc/on_audio_emote_cooldown_end, intentional), cooldown)
return TRUE // proceed with emote
/mob/proc/on_audio_emote_cooldown_end()
if(audio_emote_cd_status == EMOTE_ON_COOLDOWN)
// only reset emotes that probably weren't set by an admin
audio_emote_cd_status = EMOTE_READY
/mob/proc/on_audio_emote_cooldown_end(intentional)
if(intentional)
if(audio_emote_cd_status == EMOTE_ON_COOLDOWN)
// only reset to ready if we're in a cooldown state
audio_emote_cd_status = EMOTE_READY
else
if(audio_emote_unintentional_cd_status == EMOTE_ON_COOLDOWN)
audio_emote_unintentional_cd_status = EMOTE_READY
/proc/stat_to_text(stat)
switch(stat)