diff --git a/code/modules/grab/grab_living.dm b/code/modules/grab/grab_living.dm index bcf8e1ec62fa..08193b289d65 100644 --- a/code/modules/grab/grab_living.dm +++ b/code/modules/grab/grab_living.dm @@ -103,7 +103,7 @@ for(var/obj/item/hand_item/grab/G in active_grabs) var/atom/movable/pulling = G.affecting - if(!MultiZAdjacent(src, pulling)) + if(!MultiZAdjacent(pulling)) qdel(G) else if(!isturf(loc)) qdel(G) diff --git a/code/modules/unit_tests/mobswap.dm b/code/modules/unit_tests/mobswap.dm new file mode 100644 index 000000000000..0e577e055569 --- /dev/null +++ b/code/modules/unit_tests/mobswap.dm @@ -0,0 +1,40 @@ +/datum/unit_test/mob_swap_grab + name = "BUMPSWAP: Swapping Shall Break Grabs Under Correct Conditions" + +/datum/unit_test/mob_swap_grab/Run() + var/mob/living/carbon/human/grabbed = ALLOCATE_BOTTOM_LEFT() + var/mob/living/carbon/human/grabber = ALLOCATE_BOTTOM_LEFT() + var/mob/living/carbon/human/bumped = ALLOCATE_BOTTOM_LEFT() + + grabber.forceMove(get_step(grabber, EAST)) + grabbed.forceMove(get_step(grabber, EAST)) + + grabber.try_make_grab(grabbed) + + TEST_ASSERT(grabber.is_grabbing(grabbed), "Grabber failed to grab the target.") + + step(grabber, WEST) + + TEST_ASSERT(grabber.loc == run_loc_floor_bottom_left, "Grabber did not end up on the correct turf.") + TEST_ASSERT(!grabber.is_grabbing(grabbed, "Grab did not release after shuffling away.")) + +/datum/unit_test/mob_swap_grab_inverse + name = "BUMPSWAP: Swapping Shall Not Break Grabs Under Correct Conditions" + +/datum/unit_test/mob_swap_grab_inverse/Run() + var/mob/living/carbon/human/grabbed = ALLOCATE_BOTTOM_LEFT() + var/mob/living/carbon/human/grabber = ALLOCATE_BOTTOM_LEFT() + var/mob/living/carbon/human/bumped = ALLOCATE_BOTTOM_LEFT() + + grabber.forceMove(get_step(grabber, EAST)) + grabbed.forceMove(get_step(grabber, NORTH)) + + grabber.try_make_grab(grabbed) + + TEST_ASSERT(grabber.is_grabbing(grabbed), "Grabber failed to grab the target.") + + step(grabber, WEST) + + TEST_ASSERT(grabber.loc == run_loc_floor_bottom_left, "Grabber did not end up on the correct turf.") + TEST_ASSERT(grabber.is_grabbing(grabbed, "Grab released after shuffling, despite being adjacent still.")) +