Files
Bubberstation/code/game/objects/items/scrolls.dm
SkyratBot b8afddcbd6 [MIRROR] Teleport scroll charges cannot be bypassed via clicking the action button [MDB IGNORE] (#19563)
* Teleport scroll charges cannot be bypassed via clicking the action button (#73653)

## About The Pull Request

Teleport scrolls would only deplete a charge if used in hand, however
their implementation actually granted you the spell as an item action
which you could use by hitting the action button, This would not deplete
a charge, and had no cooldown whatsoever.
The action button is convenient and should stay, but I modified the code
so that instead of depleting a charge when clicked it depletes a charge
when the spell contained by the item successfully casts.

I also changed the order of operations slightly in `spell/after_cast`
because using the signal to delete the scroll would also delete the
spell (sensibly, it should clean up after itself) before the last cast
could make smoke, which was sad.

## Why It's Good For The Game

On live the teleport scroll gives all wizards _and_ apprentices the
teleport spell with absolutely no cooldown and infinite usage, which is
probably not intended.

## Changelog

🆑
fix: Using a teleport scroll will deplete a charge regardless of whether
used in-hand or by pressing the action button.
/🆑

* Teleport scroll charges cannot be bypassed via clicking the action button

---------

Co-authored-by: Jacquerel <hnevard@gmail.com>
2023-02-26 19:28:58 -08:00

67 lines
2.0 KiB
Plaintext

/obj/item/teleportation_scroll
name = "scroll of teleportation"
desc = "A scroll for moving around."
icon = 'icons/obj/wizard.dmi'
icon_state = "scroll"
worn_icon_state = "scroll"
w_class = WEIGHT_CLASS_SMALL
inhand_icon_state = "paper"
throw_speed = 3
throw_range = 7
resistance_flags = FLAMMABLE
actions_types = list(/datum/action/cooldown/spell/teleport/area_teleport/wizard/scroll)
/// Number of uses the scroll gets.
var/uses = 4
/obj/item/teleportation_scroll/Initialize(mapload)
. = ..()
// In the future, this can be generalized into just "magic scrolls that give you a specific spell".
var/datum/action/cooldown/spell/teleport/area_teleport/wizard/scroll/teleport = locate() in actions
if(!teleport)
return
teleport.name = name
teleport.button_icon = icon
teleport.button_icon_state = icon_state
RegisterSignal(teleport, COMSIG_SPELL_AFTER_CAST, PROC_REF(on_spell_cast))
/// Deplete charges if spell is cast successfully
/obj/item/teleportation_scroll/proc/on_spell_cast(datum/action/cooldown/spell/cast_spell, mob/living/cast_on)
SIGNAL_HANDLER
uses--
if(uses > 0)
return
to_chat(cast_on, span_warning("[src] runs out of uses and crumbles to dust!"))
qdel(src)
/obj/item/teleportation_scroll/item_action_slot_check(slot, mob/user)
return (slot & ITEM_SLOT_HANDS)
/obj/item/teleportation_scroll/apprentice
name = "lesser scroll of teleportation"
uses = 1
/obj/item/teleportation_scroll/examine(mob/user)
. = ..()
if(uses > 0)
. += "It has [uses] use\s remaining."
/obj/item/teleportation_scroll/attack_self(mob/user)
. = ..()
if(.)
return
if(!uses)
return
if(!ishuman(user))
return
var/mob/living/carbon/human/human_user = user
if(human_user.incapacitated() || !human_user.is_holding(src))
return
var/datum/action/cooldown/spell/teleport/area_teleport/wizard/scroll/teleport = locate() in actions
if(!teleport)
to_chat(user, span_warning("[src] seems to be a faulty teleportation scroll, and has no magic associated."))
return
if(!teleport.Activate(user))
return
return TRUE