Skip to content

Commit

Permalink
bugfix: Correct Health Updates (#5657)
Browse files Browse the repository at this point in the history
Correct Update Health Updates
  • Loading branch information
Gottfrei authored Aug 5, 2024
1 parent 6d9b7d4 commit f23ac59
Show file tree
Hide file tree
Showing 13 changed files with 194 additions and 75 deletions.
24 changes: 18 additions & 6 deletions code/datums/diseases/viruses/advance/symptoms/damage_converter.dm
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ Bonus
if(ishuman(M))
var/mob/living/carbon/human/H = M

var/list/parts = H.get_damaged_organs(TRUE, TRUE, AFFECT_ORGANIC_ORGAN) //1,1 because it needs inputs.
var/list/parts = H.get_damaged_organs(1, 1, AFFECT_ORGANIC_ORGAN) //1,1 because it needs inputs.

if(!parts.len)
if(!length(parts))
return
var/healed = 0
for(var/obj/item/organ/external/E as anything in parts)
healed += min(E.brute_dam, get_damage) + min(E.burn_dam, get_damage)
E.heal_damage(get_damage, get_damage, updating_health = TRUE)
M.adjustToxLoss(healed)
var/update_health = STATUS_UPDATE_NONE
var/update_damage_icon = NONE
for(var/obj/item/organ/external/bodypart as anything in parts)
var/brute_was = bodypart.brute_dam
var/burn_was = bodypart.burn_dam
update_damage_icon |= bodypart.heal_damage(get_damage, get_damage, updating_health = TRUE)
if(bodypart.brute_dam != brute_was || bodypart.burn_dam != burn_was)
update_health |= STATUS_UPDATE_HEALTH
healed += max(((bodypart.brute_dam - brute_was) + (bodypart.burn_dam - burn_was)), get_damage)

if(healed)
update_health |= H.apply_damage(healed, TOX)
if(update_health)
H.updatehealth("[name]")
if(update_damage_icon)
H.UpdateDamageIcon()

else
if(M.getFireLoss() > 0 || M.getBruteLoss() > 0)
Expand Down
13 changes: 9 additions & 4 deletions code/game/dna/genes/goon_powers.dm
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,23 @@
/obj/effect/proc_holder/spell/eat/proc/doHeal(mob/user)
if(ishuman(user))
var/mob/living/carbon/human/H = user
var/update = NONE
var/should_update_health = FALSE
var/update_damage_icon = NONE
for(var/name in H.bodyparts_by_name)
var/obj/item/organ/external/affecting = null
if(!H.bodyparts_by_name[name])
continue
affecting = H.bodyparts_by_name[name]
if(!isexternalorgan(affecting))
continue
update |= affecting.heal_damage(4, 0, updating_health = FALSE)
if(update)
var/brute_was = affecting.brute_dam
update_damage_icon |= affecting.heal_damage(4, updating_health = FALSE)
if(affecting.brute_dam != brute_was)
should_update_health = TRUE
if(should_update_health)
H.updatehealth("[name] heal")
if(update_damage_icon)
H.UpdateDamageIcon()
H.updatehealth()


/obj/effect/proc_holder/spell/eat/cast(list/targets, mob/user = usr)
Expand Down
19 changes: 17 additions & 2 deletions code/game/objects/items/stacks/medical.dm
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,13 @@
var/remburn = max(0, heal_burn - affecting.burn_dam) // And deduct it from their health (aka deal damage)
var/nrembrute = rembrute
var/nremburn = remburn
affecting.heal_damage(heal_brute, heal_burn)
var/should_update_health = FALSE
var/update_damage_icon = NONE
var/affecting_brute_was = affecting.brute_dam
var/affecting_burn_was = affecting.burn_dam
update_damage_icon |= affecting.heal_damage(heal_brute, heal_burn, updating_health = FALSE)
if(affecting.brute_dam != affecting_brute_was || affecting.burn_dam != affecting_burn_was)
should_update_health = TRUE
var/list/achildlist
if(LAZYLEN(affecting.children))
achildlist = affecting.children.Copy()
Expand All @@ -122,11 +128,20 @@
continue
nrembrute = max(0, rembrute - E.brute_dam) // Deduct the healed damage from the remain
nremburn = max(0, remburn - E.burn_dam)
E.heal_damage(rembrute, remburn)
var/brute_was = E.brute_dam
var/burn_was = E.burn_dam
update_damage_icon |= E.heal_damage(rembrute, remburn, updating_health = FALSE)
if(E.brute_dam != brute_was || E.burn_dam != burn_was)
should_update_health = TRUE
rembrute = nrembrute
remburn = nremburn
user.visible_message("<span class='green'>[user] [healverb]s the wounds on [H]'s [E.name] with the remaining medication.</span>", \
"<span class='green'>You [healverb] the wounds on [H]'s [E.name] with the remaining medication.</span>" )
if(should_update_health)
H.updatehealth("[name] heal")
if(update_damage_icon)
H.UpdateDamageIcon()


//Bruise Packs//

Expand Down
19 changes: 13 additions & 6 deletions code/game/objects/items/stacks/nanopaste.dm
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
/obj/item/stack/nanopaste/cyborg
is_cyborg = 1

/obj/item/stack/nanopaste/cyborg/attack(mob/living/M as mob, mob/user as mob)
/obj/item/stack/nanopaste/cyborg/attack(mob/living/M, mob/user)
if(!get_amount())
to_chat(user, "<span class='danger'>Not enough nanopaste!</span>")
return
else
. = ..()

/obj/item/stack/nanopaste/attack(mob/living/M as mob, mob/user as mob)
/obj/item/stack/nanopaste/attack(mob/living/M, mob/user)
if(!istype(M) || !istype(user))
return 0
if(istype(M,/mob/living/silicon/robot)) //Repairing cyborgs
Expand Down Expand Up @@ -49,11 +49,12 @@
use(1)
var/remheal = 15
var/nremheal = 0
S.heal_damage(robo_repair = TRUE) //should in, theory, heal the robotic organs in just the targeted area with it being S instead of E
var/childlist
if(LAZYLEN(S.children))
childlist = S.children.Copy()
var/parenthealed = FALSE
var/should_update_health = FALSE
var/update_damage_icon = NONE
while(remheal > 0)
var/obj/item/organ/external/E
if(S.get_damage())
Expand All @@ -70,11 +71,17 @@
else
break
nremheal = max(remheal - E.get_damage(), 0)
E.heal_damage(remheal, 0, FALSE, TRUE) //Healing Brute
E.heal_damage(0, remheal, FALSE, TRUE) //Healing Burn
var/brute_was = E.brute_dam
var/burn_was = E.burn_dam
update_damage_icon |= E.heal_damage(remheal, remheal, FALSE, TRUE, FALSE)
if(E.brute_dam != brute_was || E.burn_dam != burn_was)
should_update_health = TRUE
remheal = nremheal
H.UpdateDamageIcon()
user.visible_message("<span class='notice'>\The [user] applies some nanite paste at \the [M]'s [E.name] with \the [src].</span>")
if(should_update_health)
H.updatehealth("nanopaste repair")
if(update_damage_icon)
H.UpdateDamageIcon()
if(H.bleed_rate && ismachineperson(H))
H.bleed_rate = 0
else
Expand Down
16 changes: 13 additions & 3 deletions code/game/objects/items/weapons/storage/bible.dm
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,26 @@
new /obj/item/stack/spacecash(src)
new /obj/item/stack/spacecash(src)


//BS12 EDIT
// All cult functionality moved to Null Rod
/obj/item/storage/bible/proc/bless(mob/living/carbon/M)
if(ishuman(M))
var/mob/living/carbon/human/H = M
var/heal_amt = 10
var/should_update_health = FALSE
var/update_damage_icon = NONE
for(var/obj/item/organ/external/affecting as anything in H.bodyparts)
if(affecting.heal_damage(heal_amt, heal_amt))
H.UpdateDamageIcon()
return
var/brute_was = affecting.brute_dam
var/burn_was = affecting.burn_dam
update_damage_icon |= affecting.heal_damage(heal_amt, heal_amt, updating_health = FALSE)
if(affecting.brute_dam != brute_was || affecting.burn_dam != burn_was)
should_update_health = TRUE
if(should_update_health)
M.updatehealth("bless heal")
if(update_damage_icon)
M.UpdateDamageIcon()


/obj/item/storage/bible/proc/god_forgive()
god_punishment = max(0, god_punishment - round((world.time - last_used) / (30 SECONDS))) //forgive 1 sin every 30 seconds
Expand Down
10 changes: 9 additions & 1 deletion code/modules/mob/living/carbon/human/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1143,13 +1143,18 @@
dna.species.create_organs(src, missing_bodyparts, additional_organs)

//Apply relevant damages and variables to the new organs.
var/should_update_health = FALSE
for(var/obj/item/organ/external/bodypart as anything in bodyparts)
for(var/stats in bodypart_damages)
if(bodypart.limb_zone == stats["zone"])
var/brute_dmg = stats["brute"]
var/burn_dmg = stats["burn"]
if(brute_dmg || burn_dmg)
bodypart.external_receive_damage(brute_dmg, burn_dmg, forced = TRUE, silent = TRUE)
var/brute_was = bodypart.brute_dam
var/burn_was = bodypart.burn_dam
bodypart.external_receive_damage(brute_dmg, burn_dmg, forced = TRUE, updating_health = FALSE, silent = TRUE)
if(bodypart.brute_dam != brute_was || bodypart.burn_dam != burn_was)
should_update_health = TRUE
var/status = stats["status"]
if(status & ORGAN_INT_BLEED)
bodypart.internal_bleeding(silent = TRUE)
Expand All @@ -1163,6 +1168,9 @@
bodypart.mutate(silent = TRUE)
break

if(should_update_health)
updatehealth("set_species damage retain")

for(var/obj/item/organ/internal/organ as anything in internal_organs)
for(var/stats in internal_damages)
if(organ.slot == stats["slot"])
Expand Down
58 changes: 45 additions & 13 deletions code/modules/mob/living/carbon/human/human_damage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,16 @@
)
. = STATUS_UPDATE_NONE
var/obj/item/organ/external/picked = safepick(get_damaged_organs(brute, burn, flags = affect_robotic ? AFFECT_ALL_ORGANS : AFFECT_ORGANIC_ORGAN))
if(picked?.heal_damage(brute, burn, internal, affect_robotic, updating_health))
if(!picked)
return .
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam
if(picked.heal_damage(brute, burn, internal, affect_robotic, updating_health = FALSE))
UpdateDamageIcon()
return STATUS_UPDATE_HEALTH
if(picked.brute_dam != brute_was || picked.burn_dam != burn_was)
. |= STATUS_UPDATE_HEALTH
if(updating_health)
updatehealth("heal organ damage")


/mob/living/carbon/human/take_organ_damage(
Expand All @@ -352,9 +359,16 @@
return ..()
. = STATUS_UPDATE_NONE
var/obj/item/organ/external/picked = safepick(get_damageable_organs(affect_robotic))
if(picked?.external_receive_damage(brute, burn, blocked, sharp, used_weapon, forced = forced, updating_health = updating_health, silent = silent))
if(!picked)
return .
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam
if(picked.external_receive_damage(brute, burn, blocked, sharp, used_weapon, forced = forced, updating_health = FALSE, silent = silent))
UpdateDamageIcon()
return STATUS_UPDATE_HEALTH
if(QDELETED(picked) || picked.loc != src || picked.brute_dam != brute_was || picked.burn_dam != burn_was)
. |= STATUS_UPDATE_HEALTH
if(updating_health)
updatehealth("take organ damage")


/mob/living/carbon/human/heal_overall_damage(
Expand All @@ -370,26 +384,35 @@
brute = abs(brute)
burn = abs(burn)

var/list/obj/item/organ/external/parts = get_damaged_organs(brute, burn)
var/list/obj/item/organ/external/parts = get_damaged_organs(brute, burn, flags = affect_robotic ? AFFECT_ALL_ORGANS : AFFECT_ORGANIC_ORGAN)

var/update = NONE
var/should_update_health = FALSE
var/update_damage_icon = NONE
while(parts.len && (brute > 0 || burn > 0))
var/obj/item/organ/external/picked = pick(parts)
var/brute_per_part = round(brute/parts.len, DAMAGE_PRECISION)
var/burn_per_part = round(burn/parts.len, DAMAGE_PRECISION)

update |= picked.heal_damage(brute_per_part, burn_per_part, internal, affect_robotic, updating_health = FALSE)
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam

update_damage_icon |= picked.heal_damage(brute_per_part, burn_per_part, internal, affect_robotic, updating_health = FALSE)

if(picked.brute_dam != brute_was || picked.burn_dam != burn_was)
should_update_health = TRUE

brute = max(brute - brute_per_part, 0)
burn = max(burn - burn_per_part, 0)

parts -= picked

if(update)
if(should_update_health)
. |= STATUS_UPDATE_HEALTH
if(updating_health)
updatehealth("heal overall damage")

if(update_damage_icon)
UpdateDamageIcon()
return STATUS_UPDATE_HEALTH


/mob/living/carbon/human/take_overall_damage(
Expand All @@ -416,24 +439,33 @@
brute = abs(brute)
burn = abs(burn)

var/update = NONE
var/should_update_health = FALSE
var/update_damage_icon = NONE
while(parts.len && (brute > 0 || burn > 0))
var/obj/item/organ/external/picked = pick(parts)
var/brute_per_part = round(brute/parts.len, DAMAGE_PRECISION)
var/burn_per_part = round(burn/parts.len, DAMAGE_PRECISION)

update |= picked.external_receive_damage(brute_per_part, burn_per_part, blocked, sharp, used_weapon, forced = forced, updating_health = FALSE, silent = silent)
var/brute_was = picked.brute_dam
var/burn_was = picked.burn_dam

update_damage_icon |= picked.external_receive_damage(brute_per_part, burn_per_part, blocked, sharp, used_weapon, forced = forced, updating_health = FALSE, silent = silent)

if(QDELETED(picked) || picked.loc != src || picked.brute_dam != brute_was || picked.burn_dam != burn_was)
should_update_health = TRUE

brute = max(brute - brute_per_part, 0)
burn = max(burn - burn_per_part, 0)

parts -= picked

if(update)
if(should_update_health)
. |= STATUS_UPDATE_HEALTH
if(updating_health)
updatehealth("take overall damage")

if(update_damage_icon)
UpdateDamageIcon()
return STATUS_UPDATE_HEALTH


////////////////////////////////////////////
Expand Down
34 changes: 27 additions & 7 deletions code/modules/mob/living/carbon/human/human_defense.dm
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ emp_act
if(LAZYLEN(S.children))
childlist = S.children.Copy()
var/parenthealed = FALSE
var/should_update_health = FALSE
var/update_damage_icon = NONE
while(rembrute > 0)
var/obj/item/organ/external/E
if(S.brute_dam)
Expand All @@ -125,10 +127,16 @@ emp_act
else
break
nrembrute = max(rembrute - E.brute_dam, 0)
E.heal_damage(rembrute, 0, FALSE, TRUE)
var/brute_was = E.brute_dam
update_damage_icon |= E.heal_damage(rembrute, 0, FALSE, TRUE, FALSE)
if(E.brute_dam != brute_was)
should_update_health = TRUE
rembrute = nrembrute
H.UpdateDamageIcon()
user.visible_message("<span class='alert'>[user] patches some dents on [src]'s [E.name] with [I].</span>")
if(should_update_health)
H.updatehealth("welder repair")
if(update_damage_icon)
H.UpdateDamageIcon()
if(bleed_rate && ismachineperson(src))
bleed_rate = 0
user.visible_message("<span class='alert'>[user] patches some leaks on [src] with [I].</span>")
Expand Down Expand Up @@ -362,20 +370,32 @@ emp_act
damaged += .

//DAMAGE//
var/update_damage = FALSE
var/should_update_health = FALSE
var/update_damage_icon = NONE
for(var/obj/item/organ/external/affecting as anything in damaged)
if(affecting.external_receive_damage(acidity, 2 * acidity))
update_damage = TRUE
var/brute_was = affecting.brute_dam
var/burn_was = affecting.burn_dam
update_damage_icon |= affecting.external_receive_damage(acidity, 2 * acidity, updating_health = FALSE)
if(QDELETED(affecting) || affecting.loc != src)
should_update_health = TRUE
continue
if(affecting.brute_dam != brute_was || affecting.burn_dam != burn_was)
should_update_health = TRUE
if(!istype(affecting, /obj/item/organ/external/head) || !prob(min(acidpwr * acid_volume / 10, 90))) //Applies disfigurement
continue
var/obj/item/organ/external/head/head_organ = affecting
emote("scream")
if(has_pain())
emote("scream")
head_organ.h_style = "Bald"
head_organ.f_style = "Shaved"
update_hair()
update_fhair()
head_organ.disfigure()
if(update_damage)

if(should_update_health)
updatehealth("acid act")

if(update_damage_icon)
UpdateDamageIcon()

//MELTING INVENTORY ITEMS//
Expand Down
Loading

0 comments on commit f23ac59

Please sign in to comment.