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 17:31:26 +01:00
committed by GitHub
parent 6aefc49682
commit 96aab66dc6
7 changed files with 43 additions and 18 deletions
+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)