diff --git a/code/modules/games/cards.dm b/code/modules/games/cards.dm index ad5e29ab160..83d32b64ac4 100644 --- a/code/modules/games/cards.dm +++ b/code/modules/games/cards.dm @@ -50,10 +50,16 @@ /obj/item/deck/Initialize(mapload) . = ..() + build_decks() + update_icon(UPDATE_ICON_STATE) + +/obj/item/deck/proc/build_decks() + if(length(cards)) + // prevent building decks more than once + return for(var/deck in 1 to deck_size) build_deck() deck_total = length(cards) - update_icon(UPDATE_ICON_STATE) /obj/item/deck/proc/build_deck() return @@ -227,8 +233,10 @@ var/mob/living/user = usr if(cooldown < world.time - 1 SECONDS) cards = shuffle(cards) - user.visible_message("[user] shuffles [src].") - playsound(user, 'sound/items/cardshuffle.ogg', 50, 1) + + if(user) + user.visible_message("[user] shuffles [src].") + playsound(user, 'sound/items/cardshuffle.ogg', 50, TRUE) cooldown = world.time diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 7f234307d41..76f2504ef03 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -2,6 +2,7 @@ //Keep this sorted alphabetically #ifdef UNIT_TESTS +#include "games\test_cards.dm" #include "jobs\test_job_globals.dm" #include "aicard_icons.dm" #include "announcements.dm" diff --git a/code/modules/unit_tests/games/test_cards.dm b/code/modules/unit_tests/games/test_cards.dm new file mode 100644 index 00000000000..bde0b9f1f8b --- /dev/null +++ b/code/modules/unit_tests/games/test_cards.dm @@ -0,0 +1,30 @@ +/datum/unit_test/card_deck/proc/validate_deck(obj/item/deck/deck) + var/list/card_count = list() + for(var/datum/playingcard/card in deck.cards) + if(card_count[card.name] == null) + card_count[card.name] = 1 + else if(card.name == "Joker") + card_count[card.name]++ + else + // duplicate card in deck + return FALSE + + if(length(card_count) != 53) // 2 Jokers, so 53 unique cards + return FALSE + return TRUE + + +/datum/unit_test/card_deck/Run() + // setup + var/loc = pick(block(run_loc_bottom_left, run_loc_top_right)) + var/obj/item/deck/cards/cards = new /obj/item/deck/cards(loc) + cards.build_decks() + + // is deck proper upon spawning + if(!validate_deck(cards)) + Fail("52 card deck not initialized correctly.") + + // is deck proper after shuffling + cards.deckshuffle() + if(!validate_deck(cards)) + Fail("52 card deck broken after shuffling.")