Files
Bubberstation/code/modules/admin/smites/puzzgrid.dm
T
san7890 bf6f81a9b5 Implements AddTraits and RemoveTraits procs for adding/removing multiple traits + swag unit test (#74037)
On the tin, doing it like this means we can reduce our overall line
fingerprint whenever we have to add two or more traits from the same
source on the same target. Especially helps when we get to the 4+ range
of traits, a breath of fresh air even.

Doesn't mean we have to do for loops, as that's already handled within
the define as well. I replaced some of the checks with `length()`
checks, let me know if I should switch it over to something else (maybe
`islist()`)? We stack_trace whenever we're not passed a list reference
on purpose, and sometimes var/lists are null by default (or just empty,
making this redundant).
## Why It's Good For The Game

I commonly feel the urge to write "use `AddTraits()`" or something in
reviews, then am sad when I remember it doesn't exist. I will no longer
be sad.

Can ensure a lot more trait safety as well by using static lists- when
both ADD_TRAIT_LIST and REMOVE_TRAIT_LIST re-use the same list, you are
confident (from a static point of view) that everything that you want to
be adding/removing works.

I may have missed a few things where this could be used, but both macros
implemented in this PR still use the same framework that was being used
in the last four years- so stuff won't break if left untouched. Just a
nifty new tool for developers.

also fixed up some code in the area, numerous bugs were found and
exploded
2023-03-18 01:57:06 +00:00

114 lines
3.6 KiB
Plaintext

/// Turns the user into a puzzgrid
/datum/smite/puzzgrid
name = "Puzzgrid"
var/timer
var/gib_on_loss
/datum/smite/puzzgrid/configure(client/user)
var/timer = input(user, "How long should other people have to solve the grid? 0 gives infinite time.", "Puzzgrid", 0) as num | null
if (isnull(timer))
return FALSE
var/gib_on_loss = tgui_alert(user, "What should happen to them when they lose?", "Puzzgrid", list("Gib", "New puzzle")) == "Gib"
src.gib_on_loss = gib_on_loss
src.timer = timer == 0 ? null : (timer * 1 SECONDS)
return TRUE
/datum/smite/puzzgrid/effect(client/user, mob/living/target)
. = ..()
var/datum/puzzgrid/puzzgrid = create_random_puzzgrid()
if (isnull(puzzgrid))
to_chat(user, span_warning("Couldn't create a puzzgrid! Maybe the config isn't setup?"))
return
var/obj/structure/puzzgrid_effect/puzzgrid_effect = new(target.loc, target, puzzgrid, timer, gib_on_loss)
target.forceMove(puzzgrid_effect)
puzzgrid_effect.visible_message(span_warning("[target] has suddenly transformed into a fiendishly hard puzzle!"))
playsound(puzzgrid_effect, 'sound/effects/magic.ogg', 70)
/obj/structure/puzzgrid_effect
anchored = TRUE
density = TRUE
resistance_flags = INDESTRUCTIBLE
icon = 'icons/effects/effects.dmi'
icon_state = "shield2"
var/mob/living/victim
var/timer
var/gib_on_loss
/obj/structure/puzzgrid_effect/Initialize(mapload, mob/living/victim, datum/puzzgrid/puzzgrid, timer, gib_on_loss)
. = ..()
if (isnull(victim))
return
src.victim = victim
src.timer = timer
src.gib_on_loss = gib_on_loss
name = "[victim]'s fiendish curse"
victim.add_traits(list(TRAIT_HANDS_BLOCKED, TRAIT_IMMOBILIZED), "[type]")
add_puzzgrid_component(puzzgrid)
/obj/structure/puzzgrid_effect/Destroy()
QDEL_NULL(victim)
return ..()
/obj/structure/puzzgrid_effect/proc/add_puzzgrid_component(datum/puzzgrid/puzzgrid)
AddComponent( \
/datum/component/puzzgrid, \
puzzgrid = puzzgrid, \
timer = timer, \
on_victory_callback = CALLBACK(src, PROC_REF(on_victory)), \
on_fail_callback = CALLBACK(src, gib_on_loss ? PROC_REF(loss_gib) : PROC_REF(loss_restart)), \
)
/obj/structure/puzzgrid_effect/proc/on_victory()
victim.forceMove(loc)
victim.Paralyze(5 SECONDS)
victim.visible_message(
span_notice("[victim] is unshackled from their fiendish prison!"),
span_notice("You are unshackled from your fiendish prison!"),
)
victim.remove_traits(list(TRAIT_HANDS_BLOCKED, TRAIT_IMMOBILIZED), "[type]")
victim = null
qdel(src)
/obj/structure/puzzgrid_effect/proc/loss_gib()
victim.forceMove(loc)
victim.visible_message(
span_bolddanger("You were unable to free [victim] from their fiendish prison, leaving them as nothing more than a smattering of mush!"),
span_bolddanger("Your compatriates were unable to free you from your fiendish prison, leaving you as nothing more than a smattering of mush!"),
)
victim.gib()
victim = null
qdel(src)
/obj/structure/puzzgrid_effect/proc/loss_restart()
var/datum/puzzgrid/puzzgrid = create_random_puzzgrid()
if (isnull(puzzgrid))
victim.forceMove(loc)
victim.Paralyze(5 SECONDS)
victim.visible_message(span_bolddanger("Despite completely failing the puzzle, through unbelievable luck, [victim] manages to break out anyway!"))
victim.remove_traits(list(TRAIT_HANDS_BLOCKED, TRAIT_IMMOBILIZED), "[type]")
qdel(src)
victim = null
return
visible_message(span_danger("The fiendishly hard puzzle shapeshifts into a different, equally as challenging puzzle!"))
// Defer until after the fail proc finishes, since that will qdel the component.
addtimer(CALLBACK(src, PROC_REF(add_puzzgrid_component), puzzgrid), 0)