diff --git a/code/__DEFINES/cooldowns.dm b/code/__DEFINES/cooldowns.dm index bd6310575c3..87a65232532 100644 --- a/code/__DEFINES/cooldowns.dm +++ b/code/__DEFINES/cooldowns.dm @@ -59,9 +59,6 @@ // mob cooldowns #define COOLDOWN_YAWN_PROPAGATION "yawn_propagation_cooldown" -// admin verb cooldowns -#define COOLDOWN_INTERNET_SOUND "internet_sound" - //Shared cooldowns for actions #define MOB_SHARED_COOLDOWN_1 (1<<0) #define MOB_SHARED_COOLDOWN_2 (1<<1) @@ -124,3 +121,23 @@ return; \ } \ cd_source.cd_index += (cd_increment); \ + +/* + * Same as the above cooldown system, but uses REALTIMEOFDAY + * Primarily only used for times that need to be tracked with the client, such as sound or animations +*/ + +#define CLIENT_COOLDOWN_DECLARE(cd_index) var/##cd_index = 0 + +#define CLIENT_STATIC_COOLDOWN_DECLARE(cd_index) var/static/##cd_index = 0 + +#define CLIENT_COOLDOWN_START(cd_source, cd_index, cd_time) (cd_source.cd_index = REALTIMEOFDAY + (cd_time)) + +//Returns true if the cooldown has run its course, false otherwise +#define CLIENT_COOLDOWN_FINISHED(cd_source, cd_index) (cd_source.cd_index <= REALTIMEOFDAY) + +#define CLIENT_COOLDOWN_RESET(cd_source, cd_index) cd_source.cd_index = 0 + +#define CLIENT_COOLDOWN_STARTED(cd_source, cd_index) (cd_source.cd_index != 0) + +#define CLIENT_COOLDOWN_TIMELEFT(cd_source, cd_index) (max(0, cd_source.cd_index - REALTIMEOFDAY)) diff --git a/code/__HELPERS/roundend.dm b/code/__HELPERS/roundend.dm index 27debeb752e..d6080523ba0 100644 --- a/code/__HELPERS/roundend.dm +++ b/code/__HELPERS/roundend.dm @@ -224,7 +224,8 @@ GLOBAL_LIST_INIT(achievements_unlocked, list()) for(var/client/C in GLOB.clients) if(!C?.credits) C?.RollCredits() - C?.playtitlemusic(volume_multiplier = 0.5) + if(COOLDOWN_FINISHED(GLOB, web_sound_cooldown)) + C?.playtitlemusic(volume_multiplier = 0.5) if(speed_round && was_forced != ADMIN_FORCE_END_ROUND) C?.give_award(/datum/award/achievement/misc/speed_round, C?.mob) HandleRandomHardcoreScore(C) diff --git a/code/modules/admin/verbs/playsound.dm b/code/modules/admin/verbs/playsound.dm index 50b74d703c8..48788da7968 100644 --- a/code/modules/admin/verbs/playsound.dm +++ b/code/modules/admin/verbs/playsound.dm @@ -60,6 +60,8 @@ ADMIN_VERB(play_direct_mob_sound, R_SOUND, "Play Direct Mob Sound", "Play a soun SEND_SOUND(target, sound) BLACKBOX_LOG_ADMIN_VERB("Play Direct Mob Sound") +GLOBAL_VAR_INIT(web_sound_cooldown, 0) + ///Takes an input from either proc/play_web_sound or the request manager and runs it through yt-dlp and prompts the user before playing it to the server. /proc/web_sound(mob/user, input, credit) if(!check_rights(R_SOUND)) @@ -150,12 +152,15 @@ ADMIN_VERB(play_direct_mob_sound, R_SOUND, "Play Direct Mob Sound", "Play a soun var/mob/M = m var/client/C = M.client if(C.prefs.read_preference(/datum/preference/numeric/volume/sound_midi)) + // Stops playing lobby music and admin loaded music automatically. + SEND_SOUND(C, sound(null, channel = CHANNEL_LOBBYMUSIC)) + SEND_SOUND(C, sound(null, channel = CHANNEL_ADMIN)) if(!stop_web_sounds) C.tgui_panel?.play_music(web_sound_url, music_extra_data) else C.tgui_panel?.stop_music() - S_TIMER_COOLDOWN_START(SStimer, COOLDOWN_INTERNET_SOUND, duration) + CLIENT_COOLDOWN_START(GLOB, web_sound_cooldown, duration) BLACKBOX_LOG_ADMIN_VERB("Play Internet Sound") @@ -163,8 +168,8 @@ ADMIN_VERB_CUSTOM_EXIST_CHECK(play_web_sound) return !!CONFIG_GET(string/invoke_youtubedl) ADMIN_VERB(play_web_sound, R_SOUND, "Play Internet Sound", "Play a given internet sound to all players.", ADMIN_CATEGORY_FUN) - if(S_TIMER_COOLDOWN_TIMELEFT(SStimer, COOLDOWN_INTERNET_SOUND)) - if(tgui_alert(user, "Someone else is already playing an Internet sound! It has [DisplayTimeText(S_TIMER_COOLDOWN_TIMELEFT(SStimer, COOLDOWN_INTERNET_SOUND), 1)] remaining. \ + if(!CLIENT_COOLDOWN_FINISHED(GLOB, web_sound_cooldown)) + if(tgui_alert(user, "Someone else is already playing an Internet sound! It has [DisplayTimeText(CLIENT_COOLDOWN_TIMELEFT(GLOB, web_sound_cooldown), 1)] remaining. \ Would you like to override?", "Musicalis Interruptus", list("No","Yes")) != "Yes") return @@ -199,7 +204,7 @@ ADMIN_VERB(stop_sounds, R_NONE, "Stop All Playing Sounds", "Stops all playing so var/client/player_client = player.client player_client?.tgui_panel?.stop_music() - S_TIMER_COOLDOWN_RESET(SStimer, COOLDOWN_INTERNET_SOUND) + CLIENT_COOLDOWN_RESET(GLOB, web_sound_cooldown) BLACKBOX_LOG_ADMIN_VERB("Stop All Playing Sounds") //world/proc/shelleo