Adds yawn propagation (#62639)

This commit is contained in:
Ryll Ryll
2021-11-08 01:36:27 -08:00
committed by GitHub
parent c19b63c22b
commit dc6ccd3ecc
3 changed files with 52 additions and 0 deletions
+47
View File
@@ -414,11 +414,58 @@
key_third_person = "wsmiles"
message = "smiles weakly."
/// The base chance for your yawn to propagate to someone else if they're on the same tile as you
#define YAWN_PROPAGATE_CHANCE_BASE 60
/// The base chance for your yawn to propagate to someone else if they're on the same tile as you
#define YAWN_PROPAGATE_CHANCE_DECAY 10
/datum/emote/living/yawn
key = "yawn"
key_third_person = "yawns"
message = "yawns."
emote_type = EMOTE_AUDIBLE
cooldown = 3 SECONDS
/datum/emote/living/yawn/run_emote(mob/user, params, type_override, intentional)
. = ..()
if(!. || !isliving(user))
return
if(!TIMER_COOLDOWN_CHECK(user, COOLDOWN_YAWN_PROPAGATION))
TIMER_COOLDOWN_START(user, COOLDOWN_YAWN_PROPAGATION, cooldown * 3)
var/mob/living/carbon/carbon_user = user
if(istype(carbon_user) && ((carbon_user.wear_mask?.flags_inv & HIDEFACE) || carbon_user.head?.flags_inv & HIDEFACE))
return // if your face is obscured, skip propagation
var/propagation_distance = user.client ? 5 : 2 // mindless mobs are less able to spread yawns
for(var/mob/living/iter_living in view(user, propagation_distance))
if(IS_DEAD_OR_INCAP(iter_living) || TIMER_COOLDOWN_CHECK(user, COOLDOWN_YAWN_PROPAGATION))
continue
var/dist_between = get_dist(user, iter_living)
var/recently_examined = FALSE // if you yawn just after someone looks at you, it forces them to yawn as well. Tradecraft!
if(iter_living.client)
var/examine_time = LAZYACCESS(iter_living.client?.recent_examines, user)
if(examine_time && (world.time - examine_time < YAWN_PROPAGATION_EXAMINE_WINDOW))
recently_examined = TRUE
if(!recently_examined && !prob(YAWN_PROPAGATE_CHANCE_BASE - (YAWN_PROPAGATE_CHANCE_DECAY * dist_between)))
continue
var/yawn_delay = rand(0.25 SECONDS, 0.75 SECONDS) * dist_between
addtimer(CALLBACK(src, .proc/propagate_yawn, iter_living), yawn_delay)
/// This yawn has been triggered by someone else yawning specifically, likely after a delay. Check again if they don't have the yawned recently trait
/datum/emote/living/yawn/proc/propagate_yawn(mob/user)
if(!istype(user) || TIMER_COOLDOWN_CHECK(user, COOLDOWN_YAWN_PROPAGATION))
return
user.emote("yawn")
#undef YAWN_PROPAGATE_CHANCE_BASE
#undef YAWN_PROPAGATE_CHANCE_DECAY
/datum/emote/living/gurgle
key = "gurgle"