Skip to content

Commit

Permalink
please dont break chain grabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapu1178 committed Jan 16, 2025
1 parent bc437d8 commit 2951ed6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion code/modules/grab/grab_living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions code/modules/unit_tests/mobswap.dm
Original file line number Diff line number Diff line change
@@ -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."))

0 comments on commit 2951ed6

Please sign in to comment.