[MIRROR] Dizzy and jittery components (#11273)

Co-authored-by: Will <7099514+Willburd@users.noreply.github.com>
This commit is contained in:
CHOMPStation2StaffMirrorBot
2025-07-30 16:20:22 -07:00
committed by GitHub
parent 105391bfee
commit fb4d35fb7a
26 changed files with 210 additions and 129 deletions
@@ -0,0 +1,85 @@
/*
dizzy process - wiggles the client's pixel offset over time
*/
/datum/component/dizzy_shake
var/mob/owner
var/dizziness
/datum/component/dizzy_shake/Initialize()
if (!ismob(parent))
return COMPONENT_INCOMPATIBLE
owner = parent
RegisterSignal(owner, COMSIG_LIVING_LIFE, PROC_REF(process_life))
RegisterSignal(owner, COMSIG_MOB_DEATH, PROC_REF(mob_death))
addtimer(CALLBACK(src, PROC_REF(handle_tick)), 1, TIMER_DELETE_ME) // Needs to be a LOT faster than life ticks
/datum/component/dizzy_shake/proc/process_life()
SIGNAL_HANDLER
if(QDELETED(parent))
return
//Resting
if(owner.resting)
dizziness -= 15
else
dizziness -= 3
// Handle jitters
if(dizziness <= 0)
qdel(src)
return
/datum/component/dizzy_shake/proc/handle_tick()
if(QDELETED(parent))
return
// Handle wobbles
if(dizziness <= 0)
qdel(src)
return
if(dizziness > 100 && owner.client)
var/amplitude = dizziness*(sin(dizziness * 0.044 * world.time) + 1) / 70
owner.client.pixel_x = amplitude * sin(0.008 * dizziness * world.time)
owner.client.pixel_y = amplitude * cos(0.008 * dizziness * world.time)
addtimer(CALLBACK(src, PROC_REF(handle_tick)), 1, TIMER_DELETE_ME)
/datum/component/dizzy_shake/proc/mob_death()
SIGNAL_HANDLER
dizziness = 0
qdel(src)
/datum/component/dizzy_shake/Destroy(force = FALSE)
UnregisterSignal(owner, COMSIG_LIVING_LIFE)
UnregisterSignal(owner, COMSIG_MOB_DEATH)
// Reset the pixel offsets to zero
if(owner.client)
owner.client.pixel_x = 0
owner.client.pixel_y = 0
owner = null
. = ..()
/* Dizzy
value of dizziness ranges from 0 to 1000
below 100 is not dizzy
*/
/mob/proc/make_dizzy(var/amount)
if(amount < 0 && get_dizzy() == 0) // If removing, check if we're already empty!
return
var/datum/component/dizzy_shake/DC = LoadComponent(/datum/component/dizzy_shake);
DC.dizziness = max(min(1000, DC.dizziness + amount),0) // store what will be new value
// clamped to max 1000
/mob/proc/clear_dizzy()
qdel(GetComponent(/datum/component/dizzy_shake))
/mob/proc/get_dizzy()
var/datum/component/dizzy_shake/DC = GetComponent(/datum/component/dizzy_shake);
if(!DC)
return 0
return max(DC.dizziness,0)
@@ -0,0 +1,86 @@
/*
jittery process - wiggles the mob's pixel offset over time
*/
/datum/component/jittery_shake
var/mob/owner
var/jitteriness
/datum/component/jittery_shake/Initialize()
if (!ismob(parent))
return COMPONENT_INCOMPATIBLE
owner = parent
RegisterSignal(owner, COMSIG_LIVING_LIFE, PROC_REF(process_life))
RegisterSignal(owner, COMSIG_MOB_DEATH, PROC_REF(mob_death))
addtimer(CALLBACK(src, PROC_REF(handle_tick)), 1, TIMER_DELETE_ME) // Needs to be a LOT faster than life ticks
/datum/component/jittery_shake/proc/process_life()
SIGNAL_HANDLER
if(QDELETED(parent))
return
//Resting
if(owner.resting)
jitteriness -= 15
else
jitteriness -= 3
// Handle jitters
if(jitteriness <= 0)
qdel(src)
return
/datum/component/jittery_shake/proc/handle_tick()
if(QDELETED(parent))
return
// Handle jitters
if(jitteriness <= 0)
qdel(src)
return
// Shakey shakey
if(jitteriness > 100)
var/amplitude = min(4, jitteriness / 100)
owner.pixel_x = owner.old_x + rand(-amplitude, amplitude)
owner.pixel_y = owner.old_y + rand(-amplitude/3, amplitude/3)
addtimer(CALLBACK(src, PROC_REF(handle_tick)), 1, TIMER_DELETE_ME)
/datum/component/jittery_shake/proc/mob_death()
SIGNAL_HANDLER
jitteriness = 0
qdel(src)
/datum/component/jittery_shake/Destroy(force = FALSE)
UnregisterSignal(owner, COMSIG_LIVING_LIFE)
UnregisterSignal(owner, COMSIG_MOB_DEATH)
// Reset the pixel offsets to zero
owner.pixel_x = owner.old_x
owner.pixel_y = owner.old_y
owner = null
. = ..()
/* jitteriness
value of jittery ranges from 0 to 1000
below 100 is not jittery
*/
/mob/proc/make_jittery(var/amount)
if(amount < 0 && get_jittery() == 0) // If removing, check if we're already empty!
return
var/datum/component/jittery_shake/JC = LoadComponent(/datum/component/jittery_shake);
JC.jitteriness = max(min(1000, JC.jitteriness + amount),0) // store what will be new value
// clamped to max 1000
/mob/proc/clear_jittery()
qdel(GetComponent(/datum/component/jittery_shake))
/mob/proc/get_jittery()
var/datum/component/jittery_shake/JC = GetComponent(/datum/component/jittery_shake);
if(!JC)
return 0
return max(JC.jitteriness,0)
@@ -19,7 +19,7 @@
return
if(prob(5) && prob(7))
owner.stuttering = max(15, owner.stuttering)
if(owner.jitteriness < 50)
if(owner.get_jittery() < 50)
owner.make_jittery(65)
/datum/component/nervousness_disability/Destroy(force = FALSE)
@@ -79,7 +79,7 @@
var/shock = 0.75*owner.traumatic_shock
//Caffeinated or otherwise overexcited xenochimera can become feral and have special messages
var/jittery = max(0, owner.jitteriness - 100)
var/jittery = max(0, owner.get_jittery() - 100)
//Are we in danger of ferality?
var/danger = FALSE