Files
Bubberstation/code/modules/unit_tests/mafia.dm
SkyratBot f48008411c [MIRROR] Mafia now starts without admin intervention [MDB IGNORE] (#24793)
* Mafia now starts without admin intervention (#79348)

## About The Pull Request

Mafia should now start without the need of admin intervention.
I made a unit test that should always have a PDA and a ghost spawning in
a game of Mafia and having it run through basic setup to confirm they
both successfully sign up and the game starts.

I had to change a lot of things in order to get this working, such as
giving unique ckeys to mock clients, fixing harddels in Mafia, and
plenty of minor fixes. This is the first time any of this code is put in
CI, so a lot of uncaught errors are now showing their faces.

Because loading maps mid-round runtimes due to smoothing, I have mafia
their own unit test-only map that doesn't use smoothing.

I also split the mafia ui code into its own file, and moved a single
helper that was sitting around in mafia's file into a helpers file.

I also added some comments to explain why certain things are the way
they are, because I wrote some undocumented code previously and forgot a
few things, leading to self-inflicted wasted time.

## Why It's Good For The Game

^

## Changelog

🆑
fix: Mafia games can now start properly.
/🆑

---------

Co-authored-by: Ghom <42542238+Ghommie@ users.noreply.github.com>

* Mafia now starts without admin intervention

---------

Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com>
Co-authored-by: Ghom <42542238+Ghommie@ users.noreply.github.com>
2023-11-04 23:56:03 -04:00

49 lines
2.4 KiB
Plaintext

///Checks if a Mafia game with a Modular Computer and a Ghost will run with 'basic_setup', which is the default
///way the game is ran, without admin-intervention.
///The game should immediately end in a Town Victory due to lack of evils, but we can verify that both the PDA and the ghost
///successfully managed to get into the round.
/datum/unit_test/mafia
///Boolean on whether the Mafia game started or not. Will Fail if it hasn't.
var/mafia_game_started = FALSE
/datum/unit_test/mafia/Run()
RegisterSignal(SSdcs, COMSIG_MAFIA_GAME_START, PROC_REF(on_mafia_start))
var/datum/mafia_controller/controller = GLOB.mafia_game || new()
TEST_ASSERT(controller, "No Mafia game was found, nor was it able to be created properly.")
//spawn human and give them a laptop.
var/mob/living/carbon/human/consistent/living_player = allocate(/mob/living/carbon/human/consistent)
var/obj/item/modular_computer/laptop/preset/mafia/modpc_player = allocate(/obj/item/modular_computer/laptop/preset/mafia)
living_player.put_in_active_hand(modpc_player, TRUE)
//make the laptop run Mafia app.
var/datum/computer_file/program/mafia/mafia_program = locate() in modpc_player.stored_files
TEST_ASSERT(mafia_program, "Mafia program was unable to be found on [modpc_player].")
modpc_player.active_program = mafia_program
//Spawn a ghost and make them eligible to use the Mafia UI (just to be safe).
var/mob/dead/observer/ghost_player = allocate(/mob/dead/observer)
var/datum/client_interface/mock_client = new()
ghost_player.mock_client = mock_client
mock_client.mob = ghost_player
ADD_TRAIT(ghost_player, TRAIT_PRESERVE_UI_WITHOUT_CLIENT, TRAIT_SOURCE_UNIT_TESTS)
//First make the human sign up for Mafia, then the ghost, then we'll auto-start it.
controller.signup_mafia(living_player, modpc = modpc_player)
controller.signup_mafia(ghost_player, ghost_client = mock_client)
controller.basic_setup()
TEST_ASSERT(mafia_game_started, "Mafia game did not start despite basic_setup being called.")
TEST_ASSERT_NOTNULL(controller.player_role_lookup[modpc_player], "The Modular Computer was unable to join a game of Mafia.")
TEST_ASSERT_NOTNULL(controller.player_role_lookup[mock_client.ckey], "The Mock client wasn't put into a game of Mafia.")
mock_client.mob = null
qdel(controller)
/datum/unit_test/mafia/proc/on_mafia_start(datum/controller/subsystem/processing/dcs/source, datum/mafia_controller/game)
SIGNAL_HANDLER
mafia_game_started = TRUE