Strange Reagent correctly revives station pets, (and humans), correctly again. (#71430)

Also makes the healing factor non hardcoded

<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

Strange Reagent had a callback to call /mob/living/revive; however the
arguments for that proc were changed but the callback arguments were not
changed.

Also makes it so that the healing per unit is no longer hardcoded,
although its still kept at the stock 5 healing per unit.
Also, the max health cutoff was also hardcoded, even though we have a
getter for a mob's max health?

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

## Why It's Good For The Game

resolves https://github.com/tgstation/tgstation/issues/71417

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
fix: Strange Reagent is once again Strange! (it works at all)
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->
This commit is contained in:
Zephyr
2022-11-24 14:30:15 -05:00
committed by GitHub
parent edb26f97a1
commit 4ee7995b9c
5 changed files with 239 additions and 10 deletions
+1
View File
@@ -189,6 +189,7 @@
#include "stack_singular_name.dm"
#include "station_trait_tests.dm"
#include "stomach.dm"
#include "strange_reagent.dm"
#include "strippable.dm"
#include "subsystem_init.dm"
#include "suit_storage_icons.dm"
+149
View File
@@ -0,0 +1,149 @@
/// Checks to ensure strange reagent works as expected
/datum/unit_test/strange_reagent
priority = TEST_LONGER
var/datum/reagent/medicine/strange_reagent/instant/strange_reagent
var/target_max_health
var/amount_needed_to_full_heal
var/amount_needed_to_revive
/datum/unit_test/strange_reagent/Run()
strange_reagent = new
var/list/types_to_check = typecacheof(list(
/mob/living/carbon/human,
/mob/living/simple_animal,
/mob/living/basic,
))
types_to_check -= /mob/living/simple_animal/pet/gondola/gondolapod // need a pod, which we don't have
types_to_check -= typesof(/mob/living/simple_animal/hostile/megafauna) // no
types_to_check -= typesof(/mob/living/basic/mouse) // qdel themselves on death; why dont they use DEL_ON_DEATH you might ask. I-unno
types_to_check -= typesof(/mob/living/simple_animal/slime) // if they roll the 50% chance to spawn as an adult, they can just at random split and qdel themselves
for(var/mob/living/type as anything in types_to_check)
var/mob/living/target = allocate_new_target(type)
var/is_basic = istype(target, /mob/living/basic)
var/is_simple = istype(target, /mob/living/simple_animal)
// check some basic stuff
if(target.status_flags & GODMODE)
continue
if(!(target.mob_biotypes & MOB_ORGANIC))
continue
if(is_simple)
var/mob/living/simple_animal/simple_animal = target
if(simple_animal.del_on_death)
continue
simple_animal.loot?.Cut()
if(is_basic)
var/mob/living/basic/basic = target
if(basic.basic_mob_flags & DEL_ON_DEATH)
continue
test_damage_but_no_death(type)
test_death_no_damage(type)
test_death_with_damage(type)
test_death_with_damage_but_not_enough_reagent(type)
if(!is_basic && !is_simple) // simple/basic mobs cannot have negative health
test_death_with_full_heal(type)
test_death_from_damage(type)
test_death_from_too_much_damage(type)
// cleanup our vars
QDEL_NULL(strange_reagent)
allocate_new_target(null)
/datum/unit_test/strange_reagent/proc/allocate_new_target(type)
// cache the last one created so that we don't create N instances of the exact same mob
var/static/mob/living/pre_allocated
if(!type)
pre_allocated = null
return
if(pre_allocated?.type == type)
pre_allocated.revive(ALL) // for some reason HEAL_ADMIN doesn't work?
return pre_allocated
pre_allocated = allocate(type)
target_max_health = pre_allocated.getMaxHealth()
update_amounts(pre_allocated)
return pre_allocated
/datum/unit_test/strange_reagent/proc/update_amounts(mob/living/target)
amount_needed_to_full_heal = strange_reagent.calculate_amount_needed_to_full_heal(target)
amount_needed_to_revive = strange_reagent.calculate_amount_needed_to_revive(target)
/datum/unit_test/strange_reagent/proc/damage_target_to_percentage(mob/living/target, percent)
var/damage = target_max_health * percent * 0.5
target.setBruteLoss(damage, updating_health=FALSE) // no point running health update logic here
target.setFireLoss(damage, updating_health=TRUE) // since we do it here
update_amounts(target)
if(percent >= 1)
target.death()
return TRUE
/datum/unit_test/strange_reagent/proc/get_target_organic_health_manual(mob/living/target)
return target.getMaxHealth() - (target.getBruteLoss() + target.getFireLoss())
/datum/unit_test/strange_reagent/proc/test_damage_but_no_death(target_type)
var/mob/living/target = allocate_new_target(target_type)
if(!damage_target_to_percentage(target, 0.8))
return
var/health = get_target_organic_health_manual(target)
strange_reagent.expose_mob(target, INGEST, 20)
TEST_ASSERT_EQUAL(health, get_target_organic_health_manual(target), "Strange Reagent healed a target type [target.type] that was not dead.")
/datum/unit_test/strange_reagent/proc/test_death_no_damage(target_type)
var/mob/living/target = allocate_new_target(target_type)
target.death()
update_amounts(target)
strange_reagent.expose_mob(target, INGEST, amount_needed_to_revive)
TEST_ASSERT_NOTEQUAL(target.stat, DEAD, "Strange Reagent did not revive a dead target type [target.type].")
/datum/unit_test/strange_reagent/proc/test_death_with_damage(target_type)
var/mob/living/target = allocate_new_target(target_type)
if(!damage_target_to_percentage(target, 0.8))
return
target.death()
update_amounts(target)
strange_reagent.expose_mob(target, INGEST, amount_needed_to_revive)
TEST_ASSERT_NOTEQUAL(target.stat, DEAD, "Strange Reagent did not revive a dead target type [target.type].")
/datum/unit_test/strange_reagent/proc/test_death_with_damage_but_not_enough_reagent(target_type)
var/mob/living/target = allocate_new_target(target_type)
if(!damage_target_to_percentage(target, 1.2))
return
update_amounts(target)
strange_reagent.expose_mob(target, INGEST, amount_needed_to_revive - 1)
TEST_ASSERT_EQUAL(target.stat, DEAD, "Strange Reagent revived a dead target type [target.type] without enough reagent.")
/datum/unit_test/strange_reagent/proc/test_death_with_full_heal(target_type)
var/mob/living/target = allocate_new_target(target_type)
if(!damage_target_to_percentage(target, 0.8))
return
target.death()
update_amounts(target)
strange_reagent.expose_mob(target, INGEST, amount_needed_to_full_heal)
TEST_ASSERT_EQUAL(target_max_health, get_target_organic_health_manual(target), "Strange Reagent did not fully heal a dead target type [target.type] with the expected amount.")
/datum/unit_test/strange_reagent/proc/test_death_from_damage(target_type)
var/mob/living/target = allocate_new_target(target_type)
if(!damage_target_to_percentage(target, strange_reagent.max_revive_damage_ratio * 0.9)) // 10% under the damage cap
return
update_amounts(target)
strange_reagent.expose_mob(target, INGEST, amount_needed_to_revive)
TEST_ASSERT_NOTEQUAL(target.stat, DEAD, "Strange Reagent did not revive a target type [target.type] who died from damage.")
/datum/unit_test/strange_reagent/proc/test_death_from_too_much_damage(target_type)
var/mob/living/target = allocate_new_target(target_type)
if(!damage_target_to_percentage(target, strange_reagent.max_revive_damage_ratio * 1.1)) // 10% over the damage cap
return
update_amounts(target)
strange_reagent.expose_mob(target, INGEST, amount_needed_to_revive)
TEST_ASSERT_EQUAL(target.stat, DEAD, "Strange Reagent revived a target type [target.type] with more than double their max health in damage.")