Skip to content

Commit

Permalink
test suite: mob attack chain (ParadiseSS13#28440)
Browse files Browse the repository at this point in the history
* test suite: mob attack chain

* 100% random zone probability in tests
  • Loading branch information
warriorstar-orion authored Feb 20, 2025
1 parent 0c48363 commit 6359d3f
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 4 deletions.
4 changes: 3 additions & 1 deletion code/datums/elements/strippable.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
if(!isatom(target))
return ELEMENT_INCOMPATIBLE

RegisterSignal(target, COMSIG_DO_MOB_STRIP, PROC_REF(mouse_drop_onto))
// TODO: override = TRUE because strippable can get reattached to dead mobs after
// revival. Will fix for basic mobs probably maybe.
RegisterSignal(target, COMSIG_DO_MOB_STRIP, PROC_REF(mouse_drop_onto), override = TRUE)

src.items = items

Expand Down
3 changes: 2 additions & 1 deletion code/modules/martial_arts/martial.dm
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
streak += intent_to_streak(step)
var/mob/living/carbon/human/owner = locateUID(owner_UID)
if(istype(owner) && !QDELETED(owner))
owner.hud_used.combo_display.update_icon(ALL, streak)
if(owner.hud_used)
owner.hud_used.combo_display.update_icon(ALL, streak)
return check_combos(step, user, target, could_start_new_combo)
return FALSE

Expand Down
3 changes: 2 additions & 1 deletion code/modules/mob/living/simple_animal/friendly/dog.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
var/last_eaten = 0
footstep_type = FOOTSTEP_MOB_CLAW
var/next_spin_message = 0
var/razor_shave_delay = 5 SECONDS

/mob/living/simple_animal/pet/dog/npc_safe(mob/user)
return TRUE
Expand Down Expand Up @@ -193,7 +194,7 @@
to_chat(user, "<span class='warning'>You can't shave this corgi, it doesn't have a fur coat!</span>")
return
user.visible_message("<span class='notice'>[user] starts to shave [src] using \the [O].", "<span class='notice'>You start to shave [src] using \the [O]...</span>")
if(do_after(user, 50, target = src))
if(do_after(user, razor_shave_delay, target = src))
user.visible_message("<span class='notice'>[user] shaves [src]'s hair using \the [O].</span>")
playsound(loc, O.usesound, 20, TRUE)
shaved = TRUE
Expand Down
4 changes: 3 additions & 1 deletion code/modules/mob/mob_misc_procs.dm
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@
// Do not use this if someone is intentionally trying to hit a specific body part.
// Use get_zone_with_miss_chance() for that.
/proc/ran_zone(zone, probability = 80)

#ifdef GAME_TESTS
probability = 100
#endif
zone = check_zone(zone)

if(prob(probability))
Expand Down
10 changes: 10 additions & 0 deletions code/modules/tgui/tgui_input/alert_input.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
var/client/client = user
user = client.mob

#ifndef GAME_TESTS
if(isnull(user.client))
return
#endif

// A gentle nudge - you should not be using TGUI alert for anything other than a simple message.
if(length(buttons) > 3)
Expand All @@ -37,11 +39,15 @@

var/datum/tgui_alert/alert = new(user, message, title, buttons, timeout, autofocus, ui_state)

#ifdef GAME_TESTS
LAZYADD(GLOB.game_test_tguis[user.mind.key], alert)
#else
alert.ui_interact(user)
alert.wait()
if(alert)
. = alert.choice
qdel(alert)
#endif

/**
* # tgui_alert
Expand Down Expand Up @@ -87,6 +93,10 @@
SStgui.close_uis(src)
state = null
deltimer(deletion_timer)
#ifdef GAME_TESTS
for(var/test_user_key in GLOB.game_test_tguis)
GLOB.game_test_tguis[test_user_key] -= src
#endif
return ..()

/**
Expand Down
3 changes: 3 additions & 0 deletions code/tests/_game_test.dm
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
GLOBAL_LIST_EMPTY(game_test_chats)
GLOBAL_LIST_EMPTY(game_test_tguis)

/// For advanced cases, fail unconditionally but don't return (so a test can return multiple results)
#define TEST_FAIL(reason) (Fail(reason || "No reason", __FILE__, __LINE__))
Expand All @@ -21,6 +22,8 @@ GLOBAL_LIST_EMPTY(game_test_chats)

#define TEST_ASSERT_NOT_CHATLOG(puppet, text) if(puppet.any_chatlog_has_text(text)) { return Fail("Didn't expect `[text]` in any chatlog but got [jointext(puppet.get_chatlogs(), "\n")]", __FILE__, __LINE__) }

#define TEST_ASSERT_SUBSTRING(haystack, needle) if(!findtextEx(haystack, needle)) { return Fail("`[needle]` not found in string `[haystack]`", __FILE__, __LINE__) }

/// Asserts that the two parameters passed are equal, fails otherwise
/// Optionally allows an additional message in the case of a failure
#define TEST_ASSERT_EQUAL(a, b, message) do { \
Expand Down
8 changes: 8 additions & 0 deletions code/tests/_game_test_puppeteer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@
if(istype(A, atom_type))
return A

/datum/test_puppeteer/proc/get_last_tgui()
if(!(puppet.mind.key in GLOB.game_test_tguis))
return null
var/list/tgui_list = GLOB.game_test_tguis[puppet.mind.key]
if(!length(tgui_list))
return null
return tgui_list[length(tgui_list)]

// No we don't technically need to put these things into an actual backpack and
// so forth, we could just leave them lying around and teleport them to the
// player but this keeps things realistic and may surface issues we wouldn't
Expand Down
36 changes: 36 additions & 0 deletions code/tests/attack_chain/test_attack_chain_borgs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/datum/game_test/attack_chain_borgs/Run()
var/datum/test_puppeteer/player = new(src)
player.puppet.name = "Player"

var/mob/living/silicon/robot/borg = player.spawn_mob_nearby(/mob/living/silicon/robot)
borg.name = "BORGO"

player.set_intent(INTENT_HARM)
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "but doesn't leave a dent")

player.set_intent(INTENT_HELP)
player.spawn_obj_in_hand(/obj/item/card/id/roboticist)
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "You unlock BORGO's interface")
player.puppet.swap_hand()
var/obj/item/crowbar = player.spawn_obj_in_hand(/obj/item/crowbar)
crowbar.attack_verb = list("bashed")
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "You open the cover")
player.put_away(crowbar)
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "You remove the high-capacity power cell")
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "You insert the power cell")
player.retrieve(crowbar)
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "You close the cover")
player.puppet.swap_hand()
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "You lock BORGO's interface")
player.puppet.swap_hand()
player.set_intent(INTENT_HARM)
player.click_on(borg)
TEST_ASSERT_LAST_CHATLOG(player, "Player has bashed BORGO with the crowbar")
TEST_ASSERT(borg.health <= borg.maxHealth, "borg did not take damage")
120 changes: 120 additions & 0 deletions code/tests/attack_chain/test_attack_chain_mobs.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/datum/game_test/attack_chain_mobs/Run()
var/datum/test_puppeteer/player = new(src)
player.puppet.name = "Player"
// To ensure punches do damage without knockdowns
player.puppet.dna.species.punchdamagelow = 5
player.puppet.dna.species.punchdamagehigh = 5

var/mob/living/simple_animal/hostile/morph/morph = player.spawn_mob_nearby(/mob/living/simple_animal/hostile/morph)
morph.ambush_prepared = TRUE
player.spawn_obj_in_hand(/obj/item/screwdriver)
player.click_on(morph)

TEST_ASSERT_ANY_CHATLOG(player, "You try to use")
TEST_ASSERT_ANY_CHATLOG(player, "suddenly collapses in on itself")
qdel(morph)
// Get us back up
player.rejuvenate()

var/datum/test_puppeteer/victim = player.spawn_puppet_nearby()
victim.puppet.name = "Victim"
player.click_on(victim)
TEST_ASSERT_LAST_CHATLOG(player, "You hug Victim")
player.set_intent(INTENT_HARM)
player.click_on(victim)
TEST_ASSERT_LAST_CHATLOG(player, "Player punched Victim")
victim.rejuvenate()
var/obj/knife = player.spawn_obj_in_hand(/obj/item/kitchen/knife)
player.puppet.zone_selected = BODY_ZONE_PRECISE_L_FOOT
player.click_on(victim)
TEST_ASSERT_LAST_CHATLOG(player, "Victim in the left foot")
victim.rejuvenate()
player.put_away(knife)

// Test CQC attack interception
var/datum/martial_art/cqc/cqc = new()
cqc.teach(player.puppet)
player.puppet.swap_hand()
victim.puppet.lay_down()
player.click_on(victim)
TEST_ASSERT_LAST_CHATLOG(player, "stomps on Victim")
victim.rejuvenate()
cqc.remove(player.puppet)

player.set_intent(INTENT_HELP)
var/mob/mining_drone = player.spawn_mob_nearby(/mob/living/simple_animal/hostile/mining_drone)
var/obj/scanner = player.spawn_obj_in_hand(/obj/item/mining_scanner)
player.click_on(mining_drone)
TEST_ASSERT_LAST_CHATLOG(player, "drop any collected ore.")
qdel(scanner)
player.spawn_obj_in_hand(/obj/item/borg/upgrade/modkit/cooldown/minebot)
player.click_on(mining_drone)
TEST_ASSERT_LAST_CHATLOG(player, "You install the modkit")
player.retrieve(knife)
player.set_intent(INTENT_HARM)
player.click_on(mining_drone)
TEST_ASSERT_LAST_CHATLOG(player, "the nanotrasen minebot with the kitchen knife")
qdel(mining_drone)

RegisterSignal(victim.puppet, COMSIG_HUMAN_ATTACKED, PROC_REF(cancel_attack_chain))
player.click_on(victim)
TEST_ASSERT_LAST_CHATLOG(player, "Attack chain cancelled by signal")
UnregisterSignal(victim.puppet, COMSIG_HUMAN_ATTACKED)

var/mob/living/simple_animal/pet/dog/corgi/corgi = player.spawn_mob_nearby(/mob/living/simple_animal/pet/dog/corgi)
corgi.anchored = TRUE
player.click_on(corgi)
TEST_ASSERT_LAST_CHATLOG(player, "corgi with the kitchen knife")
player.put_away(knife)
corgi.rejuvenate()
player.set_intent(INTENT_HELP)
var/obj/collar = player.spawn_obj_in_hand(/obj/item/petcollar)
player.click_on(corgi)
TEST_ASSERT(collar in corgi.contents, "did not put collar on corgi")
var/obj/razor = player.spawn_obj_in_hand(/obj/item/razor)
corgi.razor_shave_delay = 0
player.click_on(corgi)
TEST_ASSERT(corgi.shaved, "corgi was not shaved")
player.put_away(razor)
corgi.death()
var/obj/laz_injector = player.spawn_obj_in_hand(/obj/item/lazarus_injector)
player.click_on(corgi)
TEST_ASSERT_LAST_CHATLOG(player, "injects the corgi")
qdel(laz_injector)

var/mob/slime = player.spawn_mob_nearby(/mob/living/simple_animal/slime)
slime.anchored = TRUE

player.spawn_obj_in_hand(/obj/item/slimepotion/slime/docility)
player.click_on(corgi)
TEST_ASSERT_LAST_CHATLOG(player, "only works on slimes!")
player.click_on(slime)
TEST_ASSERT_LAST_CHATLOG(player, "You feed the slime the potion")

var/obj/mind_transfer_slime_potion = player.spawn_obj_in_hand(/obj/item/slimepotion/transference)
player.click_on(corgi)
var/datum/tgui_alert/alert = player.get_last_tgui()
TEST_ASSERT_NOTNULL(alert, "no TGUI")
TEST_ASSERT_SUBSTRING(alert.message, "transfer your consciousness to the corgi")
alert.set_choice("No")

player.click_on(slime)
alert = player.get_last_tgui()
TEST_ASSERT_NOTNULL(alert, "no TGUI")
TEST_ASSERT_SUBSTRING(alert.message, "transfer your consciousness to the pet slime")
alert.set_choice("No")

qdel(mind_transfer_slime_potion)
qdel(corgi)
qdel(slime)

victim.puppet.death()
player.spawn_obj_in_hand(/obj/item/kitchen/knife/butcher/meatcleaver)
player.set_intent(INTENT_HARM)
player.click_on(victim)
// Even before this test, butchering items included a second attack message
TEST_ASSERT_ANY_CHATLOG(player, "You hack off a chunk of meat from Victim")

/datum/game_test/attack_chain_mobs/proc/cancel_attack_chain(datum/source, mob/user)
to_chat(user, "Attack chain cancelled by signal")
return COMPONENT_CANCEL_ATTACK_CHAIN
2 changes: 2 additions & 0 deletions code/tests/game_tests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

#ifdef GAME_TESTS
#include "atmos\test_ventcrawl.dm"
#include "attack_chain\test_attack_chain_borgs.dm"
#include "attack_chain\test_attack_chain_cult_dagger.dm"
#include "attack_chain\test_attack_chain_machinery.dm"
#include "attack_chain\test_attack_chain_stunbaton.dm"
#include "attack_chain\test_attack_chain_mobs.dm"
#include "attack_chain\test_attack_chain_turf.dm"
#include "attack_chain\test_attack_chain_vehicles.dm"
#include "games\test_cards.dm"
Expand Down

0 comments on commit 6359d3f

Please sign in to comment.