mirror of
https://github.com/CHOMPStation2/CHOMPStation2.git
synced 2025-12-11 10:43:20 +00:00
[MIRROR] Dizzy and jittery components (#11273)
Co-authored-by: Will <7099514+Willburd@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
105391bfee
commit
fb4d35fb7a
85
code/datums/components/animations/dizzy.dm
Normal file
85
code/datums/components/animations/dizzy.dm
Normal file
@@ -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)
|
||||
86
code/datums/components/animations/jittery.dm
Normal file
86
code/datums/components/animations/jittery.dm
Normal file
@@ -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
|
||||
|
||||
@@ -65,9 +65,9 @@ BONUS
|
||||
if(1)
|
||||
to_chat(M, span_notice("You feel bloated."))
|
||||
|
||||
if(!M.jitteriness)
|
||||
if(!M.get_jittery())
|
||||
to_chat(M, span_notice("You feel a bit jittery."))
|
||||
M.jitteriness = 10
|
||||
M.make_jittery(100 + rand(12,16))
|
||||
|
||||
if(2)
|
||||
if(ishuman(M))
|
||||
|
||||
@@ -65,7 +65,7 @@ Bonus
|
||||
switch(A.stage)
|
||||
if(2 to 3)
|
||||
if(prob(power) && H.stat)
|
||||
H.jitteriness += (2 * power)
|
||||
H.make_jittery(2 * power)
|
||||
H.emote("twitch")
|
||||
to_chat(H, span_notice("[pick("you feel energetic!", "You feel well-rested.", "You feel great!")]"))
|
||||
if(4 to 5)
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
span_userdanger("You have a panic attack!")
|
||||
)
|
||||
affected_mob.AdjustConfused(rand(12, 16))
|
||||
affected_mob.jitteriness = rand(12, 16)
|
||||
affected_mob.make_jittery(100 + rand(12, 16))
|
||||
if(prob(2))
|
||||
affected_mob.visible_message(
|
||||
span_danger("[affected_mob] coughs up butterflies!"),
|
||||
|
||||
Reference in New Issue
Block a user