Files
Bubberstation/code/modules/cards/deck/tarot.dm
T
MothblocksandGitHub ad929ac3a9 Lazily initialize decks of cards instead of initializing thousands of cards at once (.09s drop in init times) (#70999)
We're getting into the less than 0.1s realm of low hanging fruits now.

Decks of cards were initializing thousands of cards at once, not unlike
[paper bins](https://github.com/tgstation/tgstation/pull/69586) or
[circuit components](https://github.com/tgstation/tgstation/pull/69664).

Cards are more complicated than paper bins since we can't just keep a
count, and managing individual card object lifetimes is significantly
more complicated than incrementing/decrementing a number. Thus, the
logic here is slightly different.

Decks now have an `initial_cards` variable which can take card names
(which is most implementers), and for special decks, can specify an
interface that is basically a lazy function for creating a card atom.

When anything needs any real card atom, we just generate them all. The
runtime cost of this is extremely small, and affects neither dev cycles
(the motivation for the change) or ongoing rounds.
2022-11-22 08:21:29 +01:00

66 lines
2.7 KiB
Plaintext

#define TAROT_GHOST_TIMER (666 SECONDS) // this translates into 11 mins and 6 seconds
//These cards certainly won't tell the future, but you can play some nice games with them.
/obj/item/toy/cards/deck/tarot
name = "tarot game deck"
desc = "A full 78 card game deck of tarot cards. Complete with 4 suites of 14 cards, and a full suite of trump cards."
cardgame_desc = "tarot card reading"
icon_state = "deck_tarot_full"
deckstyle = "tarot"
is_standard_deck = FALSE
/obj/item/toy/cards/deck/tarot/Initialize(mapload)
. = ..()
for(var/suit in list("Hearts", "Pikes", "Clovers", "Tiles"))
for(var/i in 1 to 10)
initial_cards += "[i] of [suit]"
for(var/person in list("Valet", "Chevalier", "Dame", "Roi"))
initial_cards += "[person] of [suit]"
for(var/trump in list("The Magician", "The High Priestess", "The Empress", "The Emperor", "The Hierophant", "The Lover", "The Chariot", "Justice", "The Hermit", "The Wheel of Fortune", "Strength", "The Hanged Man", "Death", "Temperance", "The Devil", "The Tower", "The Star", "The Moon", "The Sun", "Judgement", "The World", "The Fool"))
initial_cards += trump
/obj/item/toy/cards/deck/tarot/draw(mob/user)
. = ..()
if(prob(50))
var/obj/item/toy/singlecard/card = .
var/matrix/M = matrix()
M.Turn(180)
card.transform = M
/obj/item/toy/cards/deck/tarot/haunted
name = "haunted tarot game deck"
desc = "A spooky looking tarot deck. You can sense a supernatural presence linked to the cards..."
/// ghost notification cooldown
COOLDOWN_DECLARE(ghost_alert_cooldown)
/obj/item/toy/cards/deck/tarot/haunted/on_wield(obj/item/source, mob/living/carbon/user)
. = ..()
ADD_TRAIT(user, TRAIT_SIXTHSENSE, MAGIC_TRAIT)
to_chat(user, span_notice("The veil to the underworld is opened. You can sense the dead souls calling out..."))
if(!COOLDOWN_FINISHED(src, ghost_alert_cooldown))
return
COOLDOWN_START(src, ghost_alert_cooldown, TAROT_GHOST_TIMER)
notify_ghosts(
"Someone has begun playing with a [src.name] in [get_area(src)]!",
source = src,
header = "Haunted Tarot Deck",
ghost_sound = 'sound/effects/ghost2.ogg',
notify_volume = 75,
action = NOTIFY_ORBIT,
)
/obj/item/toy/cards/deck/tarot/haunted/on_unwield(obj/item/source, mob/living/carbon/user)
. = ..()
REMOVE_TRAIT(user, TRAIT_SIXTHSENSE, MAGIC_TRAIT)
to_chat(user, span_notice("The veil to the underworld closes shut. You feel your senses returning to normal."))
/obj/item/toy/cards/deck/tarot/haunted/dropped(mob/living/carbon/user, silent)
. = ..()
if(wielded)
REMOVE_TRAIT(user, TRAIT_SIXTHSENSE, MAGIC_TRAIT)
to_chat(user, span_notice("The veil to the underworld closes shut. You feel your senses returning to normal."))
#undef TAROT_GHOST_TIMER