From b83f115501fb6e263ebbc64aa9cb4093a9d9e2ee Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Fri, 11 Aug 2023 21:44:31 -0500 Subject: [PATCH] Fixes Shadow Walk (#77518) ## About The Pull Request Phased mobs are not turfs so the new check failed. Fixes this and adds a unit test for it. Also makes shadow walk VV-able to any level of lightness. ## Changelog :cl: Melbert fix: Fixes Shadow Walk /:cl: --- .../spells/spell_types/jaunt/_jaunt.dm | 6 ++++++ .../spells/spell_types/jaunt/shadow_walk.dm | 21 +++++++++++++------ code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/spell_jaunt.dm | 21 +++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 code/modules/unit_tests/spell_jaunt.dm diff --git a/code/modules/spells/spell_types/jaunt/_jaunt.dm b/code/modules/spells/spell_types/jaunt/_jaunt.dm index 20271cd71ba..4a94f03c041 100644 --- a/code/modules/spells/spell_types/jaunt/_jaunt.dm +++ b/code/modules/spells/spell_types/jaunt/_jaunt.dm @@ -19,6 +19,12 @@ /// What dummy mob type do we put jaunters in on jaunt? var/jaunt_type = /obj/effect/dummy/phased_mob +/datum/action/cooldown/spell/jaunt/get_caster_from_target(atom/target) + if(istype(target.loc, jaunt_type)) + return target + + return ..() + /datum/action/cooldown/spell/jaunt/before_cast(atom/cast_on) return ..() | SPELL_NO_FEEDBACK // Don't do the feedback until after we're jaunting diff --git a/code/modules/spells/spell_types/jaunt/shadow_walk.dm b/code/modules/spells/spell_types/jaunt/shadow_walk.dm index 29bb8063367..de03f8e15e0 100644 --- a/code/modules/spells/spell_types/jaunt/shadow_walk.dm +++ b/code/modules/spells/spell_types/jaunt/shadow_walk.dm @@ -9,6 +9,9 @@ spell_requirements = NONE jaunt_type = /obj/effect/dummy/phased_mob/shadow + /// The max amount of lumens on a turf allowed before we can no longer enter jaunt with this + var/light_threshold = SHADOW_SPECIES_LIGHT_THRESHOLD + /datum/action/cooldown/spell/jaunt/shadow_walk/Grant(mob/grant_to) . = ..() RegisterSignal(grant_to, COMSIG_MOVABLE_MOVED, PROC_REF(update_status_on_signal)) @@ -17,6 +20,12 @@ . = ..() UnregisterSignal(remove_from, COMSIG_MOVABLE_MOVED) +/datum/action/cooldown/spell/jaunt/shadow_walk/enter_jaunt(mob/living/jaunter, turf/loc_override) + var/obj/effect/dummy/phased_mob/shadow/shadow = ..() + if(istype(shadow)) + shadow.light_max = light_threshold + return shadow + /datum/action/cooldown/spell/jaunt/shadow_walk/can_cast_spell(feedback = TRUE) . = ..() if(!.) @@ -24,7 +33,7 @@ if(is_jaunting(owner)) return TRUE var/turf/cast_turf = get_turf(owner) - if(cast_turf.get_lumcount() >= SHADOW_SPECIES_LIGHT_THRESHOLD) + if(cast_turf.get_lumcount() >= light_threshold) if(feedback) to_chat(owner, span_warning("It isn't dark enough here!")) return FALSE @@ -44,6 +53,8 @@ /obj/effect/dummy/phased_mob/shadow name = "shadows" + /// Max amount of light permitted before being kicked out + var/light_max = SHADOW_SPECIES_LIGHT_THRESHOLD /// The amount that shadow heals us per SSobj tick (times seconds_per_tick) var/healing_rate = 1.5 /// When cooldown is active, you are prevented from moving into tiles that would eject you from your jaunt @@ -109,11 +120,9 @@ * * location_to_check - The location to have its light level checked. */ -/obj/effect/dummy/phased_mob/shadow/proc/check_light_level(location_to_check) - var/turf/T = get_turf(location_to_check) - var/light_amount = T.get_lumcount() - if(light_amount > 0.2) // jaunt ends - return TRUE +/obj/effect/dummy/phased_mob/shadow/proc/check_light_level(atom/location_to_check) + var/turf/light_turf = get_turf(location_to_check) + return light_turf.get_lumcount() > light_max // jaunt ends on TRUE /** * Checks if the user should recieve a warning that they're moving into light. diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 081b83b609e..8e99e4bdc97 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -229,6 +229,7 @@ #include "species_unique_id.dm" #include "species_whitelists.dm" #include "spell_invocations.dm" +#include "spell_jaunt.dm" #include "spell_mindswap.dm" #include "spell_names.dm" #include "spell_shapeshift.dm" diff --git a/code/modules/unit_tests/spell_jaunt.dm b/code/modules/unit_tests/spell_jaunt.dm new file mode 100644 index 00000000000..41446b71a59 --- /dev/null +++ b/code/modules/unit_tests/spell_jaunt.dm @@ -0,0 +1,21 @@ +/// Tests Shadow Walk can be entered and exited +/datum/unit_test/shadow_jaunt + +/datum/unit_test/shadow_jaunt/Run() + var/mob/living/carbon/human/jaunter = allocate(/mob/living/carbon/human/consistent) + var/datum/action/cooldown/spell/jaunt/shadow_walk/walk = allocate(/datum/action/cooldown/spell/jaunt/shadow_walk, jaunter) + walk.Grant(jaunter) + + var/turf/jaunt_turf = jaunter.loc + TEST_ASSERT(istype(jaunt_turf), "Jaunter was not allocated to a turf, instead to [jaunt_turf || "nullspace"].") + TEST_ASSERT(walk.IsAvailable(), "Unit test room is not suitable to test [walk].") + + walk.Trigger() + + TEST_ASSERT_NOTEQUAL(jaunter.loc, jaunt_turf, "Jaunter's loc did not change on casting [walk].") + TEST_ASSERT(istype(jaunter.loc, walk.jaunt_type), "Jaunter failed to enter jaunt on casting [walk].") + + walk.next_use_time = -1 + walk.Trigger() + + TEST_ASSERT_EQUAL(jaunter.loc, jaunt_turf, "Jaunter failed to exit jaunt on exiting [walk].")