[MIRROR] Fix chemicals not recognizing end of metabolization (#756)

* Fix chemicals not recognizing end of metabolization (#53550)

* Fix chemicals not recognizing end of metabolization

* Make generic to all organs

* Fix chemicals not recognizing end of metabolization

Co-authored-by: Jared-Fogle <35135081+Jared-Fogle@users.noreply.github.com>
This commit is contained in:
SkyratBot
2020-09-11 23:21:10 +02:00
committed by GitHub
co-authored by Jared-Fogle
parent fc542177be
commit a669313e10
4 changed files with 44 additions and 5 deletions
+12 -4
View File
@@ -614,12 +614,20 @@
for(var/_reagent in cached_reagents)
var/datum/reagent/R = _reagent
if(R.type == reagent)
if(my_atom && isliving(my_atom))
var/mob/living/M = my_atom
var/mob/living/mob_consumer
if (isliving(my_atom))
mob_consumer = my_atom
else if (istype(my_atom, /obj/item/organ))
var/obj/item/organ/organ = my_atom
mob_consumer = organ.owner
if (mob_consumer)
if(R.metabolizing)
R.metabolizing = FALSE
R.on_mob_end_metabolize(M)
R.on_mob_delete(M)
R.on_mob_end_metabolize(mob_consumer)
R.on_mob_delete(mob_consumer)
//Clear from relevant lists
addiction_list -= R
reagent_list -= R
+6
View File
@@ -2,6 +2,7 @@
//Keep this sorted alphabetically
#ifdef UNIT_TESTS
/// Asserts that a condition is true
/// If the condition is not true, fails the test
#define TEST_ASSERT(assertion, reason) if (!(assertion)) { return Fail("Assertion failed: [reason || "No reason"]") }
@@ -14,6 +15,11 @@
/// Optionally allows an additional message in the case of a failure
#define TEST_ASSERT_NOTEQUAL(a, b, message) if ((a) == (b)) { return Fail("Expected [isnull(a) ? "null" : a] to not be equal to [isnull(b) ? "null" : b].[message ? " [message]" : ""]") }
/// *Only* run the test provided within the parentheses
/// This is useful for debugging when you want to reduce noise, but should never be pushed
/// Intended to be used in the manner of `TEST_FOCUS(/datum/unit_test/math)`
#define TEST_FOCUS(test_path) ##test_path { focus = TRUE; }
#include "anchored_mobs.dm"
#include "bespoke_id.dm"
#include "binary_insert.dm"
+17
View File
@@ -17,3 +17,20 @@
/datum/unit_test/metabolization/Destroy()
SSmobs.ignite()
return ..()
/datum/unit_test/on_mob_end_metabolize/Run()
var/mob/living/carbon/human/user = allocate(/mob/living/carbon/human)
var/obj/item/reagent_containers/pill/pill = allocate(/obj/item/reagent_containers/pill)
var/datum/reagent/drug/methamphetamine/meth = /datum/reagent/drug/methamphetamine
// Give them enough meth to be consumed in 2 metabolizations
pill.reagents.add_reagent(meth, initial(meth.metabolization_rate) * 1.9)
pill.attack(user, user)
user.Life()
TEST_ASSERT(user.has_reagent(meth), "User does not have meth in their system after consuming it")
TEST_ASSERT(user.has_movespeed_modifier(/datum/movespeed_modifier/reagent/methamphetamine), "User consumed meth, but did not gain movespeed modifier")
user.Life()
TEST_ASSERT(!user.has_reagent(meth), "User still has meth in their system when it should've finished metabolizing")
TEST_ASSERT(!user.has_movespeed_modifier(/datum/movespeed_modifier/reagent/methamphetamine), "User still has movespeed modifier despite not containing any more meth")
+9 -1
View File
@@ -24,6 +24,7 @@ GLOBAL_VAR(test_log)
var/turf/run_loc_top_right
//internal shit
var/focus = FALSE
var/succeeded = TRUE
var/list/allocated
var/list/fail_reasons
@@ -66,7 +67,14 @@ GLOBAL_VAR(test_log)
/proc/RunUnitTests()
CHECK_TICK
for(var/I in subtypesof(/datum/unit_test))
var/tests_to_run = subtypesof(/datum/unit_test)
for (var/_test_to_run in tests_to_run)
var/datum/unit_test/test_to_run = _test_to_run
if (initial(test_to_run.focus))
tests_to_run = list(test_to_run)
break
for(var/I in tests_to_run)
var/datum/unit_test/test = new I
GLOB.current_test = test