From 1b63289e3680eccff2ef54ab80bdd567d9ff0467 Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Sun, 27 Nov 2022 23:32:15 -0600 Subject: [PATCH] Fixes dragons not dropping their consumed mobs on despawn (#71537) ## About The Pull Request This was fixed a while back, but was accidentally reverted / regressed due to a refactor Basically, the dragon needs to be killed before being deleted, being killed will drop all of their stuff and handle "dragon is dead" events, then it can be fully deleted and removed as expected Unit tests it, since this is a regression Fixes #71536 ## Why It's Good For The Game Having a lot of mobs deleted is kinda really bad ## Changelog :cl: Melbert fix: Fixes dragon despawn deleting all the people they consumed /:cl: Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> --- .../antagonists/space_dragon/space_dragon.dm | 1 + code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/dragon_expiration.dm | 28 +++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 code/modules/unit_tests/dragon_expiration.dm diff --git a/code/modules/antagonists/space_dragon/space_dragon.dm b/code/modules/antagonists/space_dragon/space_dragon.dm index d4b89aa027a..38d8abeee46 100644 --- a/code/modules/antagonists/space_dragon/space_dragon.dm +++ b/code/modules/antagonists/space_dragon/space_dragon.dm @@ -92,6 +92,7 @@ to_chat(owner.current, span_boldwarning("You've failed to summon the rift in a timely manner! You're being pulled back from whence you came!")) destroy_rifts() SEND_SOUND(owner.current, sound('sound/magic/demon_dies.ogg')) + owner.current.death(/* gibbed = */ TRUE) QDEL_NULL(owner.current) /** diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index d6fdc13c7e9..de3c7d697ef 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -100,6 +100,7 @@ #include "create_and_destroy.dm" #include "dcs_get_id_from_elements.dm" #include "designs.dm" +#include "dragon_expiration.dm" #include "dummy_spawn.dm" #include "dynamic_ruleset_sanity.dm" #include "egg_glands.dm" diff --git a/code/modules/unit_tests/dragon_expiration.dm b/code/modules/unit_tests/dragon_expiration.dm new file mode 100644 index 00000000000..7b36b576291 --- /dev/null +++ b/code/modules/unit_tests/dragon_expiration.dm @@ -0,0 +1,28 @@ +/// Unit test for the contents barfer element +/datum/unit_test/contents_barfer + +/datum/unit_test/contents_barfer/Run() + var/mob/living/simple_animal/hostile/space_dragon/dragon_time = allocate(/mob/living/simple_animal/hostile/space_dragon) + var/mob/living/carbon/human/to_be_consumed = allocate(/mob/living/carbon/human/consistent) + TEST_ASSERT(dragon_time.eat(to_be_consumed), "The space dragon failed to consume the dummy!") + TEST_ASSERT_EQUAL(to_be_consumed.loc, dragon_time, "The dummy's location, after being successfuly consumed, was not within the space dragon's contents!") + dragon_time.death() + TEST_ASSERT(isturf(to_be_consumed.loc), "After dying, the space dragon did not eject the consumed dummy content barfer element.") + +/// Unit tests that the space dragon - when its rift expires and it gets qdel'd - doesn't delete all the mobs it has eaten +/datum/unit_test/space_dragon_expiration + +/datum/unit_test/space_dragon_expiration/Run() + var/mob/living/simple_animal/hostile/space_dragon/dragon_time = allocate(/mob/living/simple_animal/hostile/space_dragon) + var/mob/living/carbon/human/to_be_consumed = allocate(/mob/living/carbon/human/consistent) + + dragon_time.mind_initialize() + var/datum/antagonist/space_dragon/dragon_antag_datum = dragon_time.mind.add_antag_datum(/datum/antagonist/space_dragon) + dragon_time.eat(to_be_consumed) + + dragon_antag_datum.riftTimer = dragon_antag_datum.maxRiftTimer + 1 + dragon_antag_datum.rift_checks() + + TEST_ASSERT(QDELETED(dragon_time), "The space dragon wasn't deleted after having its rift timer exceeded!") + TEST_ASSERT(!QDELETED(to_be_consumed), "After having its rift timer exceeded, the dragon deleted the dummy instead! The dragon should be dead prior to being deleted!") + TEST_ASSERT(isturf(to_be_consumed.loc), "After having its rift timer exceeded, the dragon did not eject the dummy! (Dummy's loc: [to_be_consumed.loc])")