mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-12 00:27:31 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
152 lines
5.6 KiB
Plaintext
152 lines
5.6 KiB
Plaintext
/**
|
|
* A mob with this component passes all damage (and healing) it takes to another mob, passed as a parameter
|
|
* Essentially we use another mob's health bar as our health bar
|
|
*/
|
|
/datum/component/life_link
|
|
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
|
|
/// Mob we pass all of our damage to
|
|
var/mob/living/host
|
|
/// Optional callback invoked when damage gets transferred
|
|
var/datum/callback/on_passed_damage
|
|
/// Optional callback invoked when the linked mob dies
|
|
var/datum/callback/on_linked_death
|
|
|
|
/datum/component/life_link/Initialize(mob/living/host, datum/callback/on_passed_damage, datum/callback/on_linked_death)
|
|
. = ..()
|
|
if (!isliving(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
if (!istype(host))
|
|
CRASH("Life link created on [parent.type] and attempted to link to invalid type [host?.type].")
|
|
register_host(host)
|
|
src.on_passed_damage = on_passed_damage
|
|
src.on_linked_death = on_linked_death
|
|
|
|
/datum/component/life_link/RegisterWithParent()
|
|
RegisterSignal(parent, COMSIG_CARBON_LIMB_DAMAGED, PROC_REF(on_limb_damage))
|
|
RegisterSignals(parent, COMSIG_LIVING_ADJUST_STANDARD_DAMAGE_TYPES, PROC_REF(on_damage_adjusted))
|
|
RegisterSignal(parent, COMSIG_LIVING_HEALTH_UPDATE, PROC_REF(on_health_updated))
|
|
if (!isnull(host))
|
|
var/mob/living/living_parent = parent
|
|
living_parent.updatehealth()
|
|
|
|
/datum/component/life_link/UnregisterFromParent()
|
|
unregister_host()
|
|
UnregisterSignal(parent, list(COMSIG_CARBON_LIMB_DAMAGED, COMSIG_LIVING_HEALTH_UPDATE) + COMSIG_LIVING_ADJUST_STANDARD_DAMAGE_TYPES)
|
|
|
|
/datum/component/life_link/InheritComponent(datum/component/new_comp, i_am_original, mob/living/host, datum/callback/on_passed_damage, datum/callback/on_linked_death)
|
|
register_host(host)
|
|
|
|
/// Set someone up as our new host
|
|
/datum/component/life_link/proc/register_host(mob/living/new_host)
|
|
unregister_host()
|
|
if (isnull(new_host))
|
|
return
|
|
host = new_host
|
|
RegisterSignal(host, COMSIG_LIVING_DEATH, PROC_REF(on_host_died))
|
|
RegisterSignal(host, COMSIG_LIVING_HEALTH_UPDATE, PROC_REF(on_health_updated))
|
|
RegisterSignal(host, COMSIG_LIVING_REVIVE, PROC_REF(on_host_revived))
|
|
RegisterSignal(host, COMSIG_QDELETING, PROC_REF(on_host_deleted))
|
|
var/mob/living/living_parent = parent
|
|
living_parent.updatehealth()
|
|
|
|
/// Drop someone from being our host
|
|
/datum/component/life_link/proc/unregister_host()
|
|
if (isnull(host))
|
|
return
|
|
UnregisterSignal(host, list(COMSIG_LIVING_DEATH, COMSIG_LIVING_HEALTH_UPDATE, COMSIG_LIVING_REVIVE, COMSIG_QDELETING))
|
|
host = null
|
|
|
|
/// Called when your damage goes up or down
|
|
/datum/component/life_link/proc/on_damage_adjusted(mob/living/our_mob, type, amount, forced)
|
|
SIGNAL_HANDLER
|
|
if (forced)
|
|
return
|
|
amount *= our_mob.get_damage_mod(type)
|
|
switch (type)
|
|
if(BRUTE)
|
|
host.adjust_brute_loss(amount, forced = TRUE)
|
|
if(BURN)
|
|
host.adjust_fire_loss(amount, forced = TRUE)
|
|
if(TOX)
|
|
host.adjust_tox_loss(amount, forced = TRUE)
|
|
if(OXY)
|
|
host.adjust_oxy_loss(amount, forced = TRUE)
|
|
|
|
on_passed_damage?.Invoke(our_mob, host, amount)
|
|
return COMPONENT_IGNORE_CHANGE
|
|
|
|
/// Called when someone hurts one of our limbs, bypassing normal damage adjustment
|
|
/datum/component/life_link/proc/on_limb_damage(mob/living/our_mob, limb, brute, burn)
|
|
SIGNAL_HANDLER
|
|
if (brute != 0)
|
|
host.adjust_brute_loss(brute, updating_health = FALSE)
|
|
if (burn != 0)
|
|
host.adjust_fire_loss(burn, updating_health = FALSE)
|
|
if (brute != 0 || burn != 0)
|
|
host.updatehealth()
|
|
on_passed_damage?.Invoke(our_mob, host, brute + burn)
|
|
return COMPONENT_PREVENT_LIMB_DAMAGE
|
|
|
|
/// Called when either the host or parent's health tries to update, update our displayed health
|
|
/datum/component/life_link/proc/on_health_updated()
|
|
SIGNAL_HANDLER
|
|
update_health_hud(parent)
|
|
update_med_hud_health(parent)
|
|
update_med_hud_status(parent)
|
|
|
|
/// Update our parent's health display based on how harmed our host is
|
|
/datum/component/life_link/proc/update_health_hud(mob/living/mob_parent)
|
|
var/severity = 0
|
|
var/healthpercent = health_percentage(host)
|
|
switch(healthpercent)
|
|
if(100 to INFINITY)
|
|
severity = 0
|
|
if(85 to 100)
|
|
severity = 1
|
|
if(70 to 85)
|
|
severity = 2
|
|
if(55 to 70)
|
|
severity = 3
|
|
if(40 to 55)
|
|
severity = 4
|
|
if(25 to 40)
|
|
severity = 5
|
|
else
|
|
severity = 6
|
|
if(severity > 0)
|
|
mob_parent.overlay_fullscreen("brute", /atom/movable/screen/fullscreen/brute, severity)
|
|
else
|
|
mob_parent.clear_fullscreen("brute")
|
|
|
|
if(mob_parent.hud_used?.screen_objects[HUD_MOB_HEALTH])
|
|
mob_parent.hud_used.screen_objects[HUD_MOB_HEALTH].maptext = MAPTEXT("<div align='center' valign='middle' style='position:relative; top:0px; left:6px'><font color='#efeeef'>[round(healthpercent, 0.5)]%</font></div>")
|
|
|
|
/// Update our health on the medical hud
|
|
/datum/component/life_link/proc/update_med_hud_health(mob/living/mob_parent)
|
|
mob_parent.set_hud_image_state(HEALTH_HUD, "hud[RoundHealth(host)]")
|
|
|
|
/// Update our vital status on the medical hud
|
|
/datum/component/life_link/proc/update_med_hud_status(mob/living/mob_parent)
|
|
if(host.stat == DEAD || HAS_TRAIT(host, TRAIT_FAKEDEATH))
|
|
mob_parent.set_hud_image_state(STATUS_HUD, "huddead")
|
|
else
|
|
mob_parent.set_hud_image_state(STATUS_HUD, "hudhealthy")
|
|
|
|
/// Called when our host dies, we should die too
|
|
/datum/component/life_link/proc/on_host_died(mob/living/source, gibbed)
|
|
SIGNAL_HANDLER
|
|
on_linked_death?.Invoke(parent, host, gibbed)
|
|
var/mob/living/living_parent = parent
|
|
living_parent.death(gibbed)
|
|
|
|
/// Called when our host undies, we should undie too
|
|
/datum/component/life_link/proc/on_host_revived(mob/living/source, full_heal_flags)
|
|
SIGNAL_HANDLER
|
|
var/mob/living/living_parent = parent
|
|
living_parent.revive(full_heal_flags)
|
|
|
|
/// Called when
|
|
/datum/component/life_link/proc/on_host_deleted()
|
|
SIGNAL_HANDLER
|
|
qdel(src)
|