Files
Bubberstation/code/datums/components/martial_art_giver.dm
TimandRoxy 5a21a35e25 Fix martial arts gloves runtiming when destroyed while equip (#91892)
## About The Pull Request
If you wear the boxing gloves from the baseball field holodeck sim and
walk off, it causes a runtime where it gets deleted and then attempts to
drop it shortly after. The problem is the martial arts component
`Destroy()` nulls the martial arts style first, then later tries to
unlearn the style, which doesn't exist anymore. This causes the style to
never be properly forgotten.

You could theoretically abuse this to destroy several gloves while
wearing them to gain multiple martial arts styles.

## Why It's Good For The Game
Less runtimes and exploits.

## Changelog
🆑
fix: Fix martial arts gloves runtiming when destroyed while equip
/🆑
2025-07-04 16:33:38 -04:00

41 lines
1.2 KiB
Plaintext

/// when equipped and unequipped this item gives a martial art
/datum/component/martial_art_giver
/// the style we give
var/datum/martial_art/style
/datum/component/martial_art_giver/Initialize(style_type)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
style = new style_type(src)
/datum/component/martial_art_giver/Destroy()
var/obj/item/item = parent
var/mob/living/wearer = item.loc
if(isliving(wearer))
style.unlearn(wearer)
QDEL_NULL(style)
return ..()
/datum/component/martial_art_giver/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(equipped))
RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(dropped))
var/obj/item/item = parent
var/mob/living/wearer = item.loc
if(istype(wearer))
equipped(item, wearer, wearer.get_slot_by_item(item))
/datum/component/martial_art_giver/UnregisterFromParent(datum/source)
UnregisterSignal(parent, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED))
/datum/component/martial_art_giver/proc/equipped(obj/item/source, mob/user, slot)
SIGNAL_HANDLER
if(!(source.slot_flags & slot))
return
style.teach(user)
/datum/component/martial_art_giver/proc/dropped(obj/item/source, mob/user)
SIGNAL_HANDLER
style.unlearn(user)