test suite: mob attack chain (#28440)

* test suite: mob attack chain

* 100% random zone probability in tests
This commit is contained in:
warriorstar-orion
2025-02-20 10:03:21 -05:00
committed by GitHub
parent 0c48363fd1
commit 6359d3f41b
10 changed files with 189 additions and 4 deletions
+3
View File
@@ -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__))
@@ -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 { \
+8
View File
@@ -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
@@ -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")
@@ -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
View File
@@ -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"