From 4691d1bd07e096cd3c0a76f2710cc5beb8a785c5 Mon Sep 17 00:00:00 2001 From: NovaBot <154629622+NovaBot13@users.noreply.github.com> Date: Thu, 18 Apr 2024 01:02:07 -0400 Subject: [PATCH] [MIRROR] turns martial arts gloves into a component (#2039) * turns martial arts gloves into a component * Update krav_maga.dm --------- Co-authored-by: jimmyl <70376633+mc-oofert@users.noreply.github.com> Co-authored-by: Mal <13398309+vinylspiders@users.noreply.github.com> --- code/datums/components/martial_art_giver.dm | 45 +++++++++++++++++++++ code/datums/martial/boxing.dm | 17 +------- code/datums/martial/krav_maga.dm | 17 +------- code/datums/martial/sleeping_carp.dm | 20 +-------- code/datums/martial/wrestling.dm | 17 +------- tgstation.dme | 1 + 6 files changed, 51 insertions(+), 66 deletions(-) create mode 100644 code/datums/components/martial_art_giver.dm diff --git a/code/datums/components/martial_art_giver.dm b/code/datums/components/martial_art_giver.dm new file mode 100644 index 00000000000..1a0bfa9951a --- /dev/null +++ b/code/datums/components/martial_art_giver.dm @@ -0,0 +1,45 @@ +/// 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() + style.allow_temp_override = FALSE + +/datum/component/martial_art_giver/RegisterWithParent() + RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(equipped)) + RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(dropped)) + +/datum/component/martial_art_giver/UnregisterFromParent(datum/source) + UnregisterSignal(parent, list(COMSIG_ITEM_POST_EQUIPPED, COMSIG_ITEM_POST_UNEQUIP)) + var/obj/item/parent_item = parent + if(ismob(parent_item?.loc)) + UnregisterSignal(parent, list(COMSIG_MOB_MIND_TRANSFERRED_INTO, COMSIG_MOB_MIND_INITIALIZED, COMSIG_MOB_MIND_TRANSFERRED_OUT_OF)) + QDEL_NULL(style) + +/datum/component/martial_art_giver/proc/equipped(obj/item/source, mob/user, slot) + SIGNAL_HANDLER + if(!(source.slot_flags & slot)) + return + RegisterSignals(user, list(COMSIG_MOB_MIND_TRANSFERRED_INTO, COMSIG_MOB_MIND_INITIALIZED), PROC_REF(teach)) + RegisterSignal(user, COMSIG_MOB_MIND_TRANSFERRED_OUT_OF, PROC_REF(forget)) + teach(user) + +/datum/component/martial_art_giver/proc/dropped(obj/item/source, mob/user) + SIGNAL_HANDLER + forget(user) + UnregisterSignal(user, list(COMSIG_MOB_MIND_TRANSFERRED_INTO, COMSIG_MOB_MIND_INITIALIZED, COMSIG_MOB_MIND_TRANSFERRED_OUT_OF)) + +/datum/component/martial_art_giver/proc/teach(mob/source) + if(isnull(style)) + return + style.teach(source, TRUE) + +/datum/component/martial_art_giver/proc/forget(mob/source) + if(isnull(style)) + return + style.fully_remove(source) diff --git a/code/datums/martial/boxing.dm b/code/datums/martial/boxing.dm index 8ef30db63aa..ec111fb3cf0 100644 --- a/code/datums/martial/boxing.dm +++ b/code/datums/martial/boxing.dm @@ -74,7 +74,6 @@ return ..() /obj/item/clothing/gloves/boxing - var/datum/martial_art/boxing/style /obj/item/clothing/gloves/boxing/Initialize(mapload) . = ..() @@ -85,18 +84,4 @@ slapcraft_recipes = slapcraft_recipe_list,\ ) - style = new() - style.allow_temp_override = FALSE - -/obj/item/clothing/gloves/boxing/Destroy() - QDEL_NULL(style) - return ..() - -/obj/item/clothing/gloves/boxing/equipped(mob/user, slot) - . = ..() - if(slot & ITEM_SLOT_GLOVES) - style.teach(user, TRUE) - -/obj/item/clothing/gloves/boxing/dropped(mob/user) - . = ..() - style.fully_remove(user) + AddComponent(/datum/component/martial_art_giver, /datum/martial_art/boxing) diff --git a/code/datums/martial/krav_maga.dm b/code/datums/martial/krav_maga.dm index 66d092e886e..57e158cf669 100644 --- a/code/datums/martial/krav_maga.dm +++ b/code/datums/martial/krav_maga.dm @@ -208,26 +208,11 @@ //Krav Maga Gloves /obj/item/clothing/gloves/krav_maga - var/datum/martial_art/krav_maga/style clothing_traits = list(TRAIT_FAST_CUFFING) /obj/item/clothing/gloves/krav_maga/Initialize(mapload) . = ..() - style = new() - style.allow_temp_override = FALSE - -/obj/item/clothing/gloves/krav_maga/Destroy() - QDEL_NULL(style) - return ..() - -/obj/item/clothing/gloves/krav_maga/equipped(mob/user, slot) - . = ..() - if(slot & ITEM_SLOT_GLOVES) - style.teach(user, TRUE) - -/obj/item/clothing/gloves/krav_maga/dropped(mob/user) - . = ..() - style.fully_remove(user) + AddComponent(/datum/component/martial_art_giver, /datum/martial_art/krav_maga) /obj/item/clothing/gloves/krav_maga/sec//more obviously named, given to sec name = "krav maga gloves" diff --git a/code/datums/martial/sleeping_carp.dm b/code/datums/martial/sleeping_carp.dm index 800aa3ca552..13e8ecb774a 100644 --- a/code/datums/martial/sleeping_carp.dm +++ b/code/datums/martial/sleeping_carp.dm @@ -325,7 +325,7 @@ /obj/item/clothing/gloves/the_sleeping_carp name = "carp gloves" - desc = "This gloves are capable of making people use The Sleeping Carp." + desc = "These gloves are capable of making people use The Sleeping Carp." icon_state = "black" greyscale_colors = COLOR_BLACK cold_protection = HANDS @@ -333,26 +333,10 @@ heat_protection = HANDS max_heat_protection_temperature = GLOVES_MAX_TEMP_PROTECT resistance_flags = NONE - var/datum/martial_art/the_sleeping_carp/style /obj/item/clothing/gloves/the_sleeping_carp/Initialize(mapload) . = ..() - style = new() - style.allow_temp_override = FALSE - -/obj/item/clothing/gloves/the_sleeping_carp/Destroy() - QDEL_NULL(style) - return ..() - -/obj/item/clothing/gloves/the_sleeping_carp/equipped(mob/user, slot) - . = ..() - if(slot & ITEM_SLOT_GLOVES) - style.teach(user, TRUE) - -/obj/item/clothing/gloves/the_sleeping_carp/dropped(mob/user) - . = ..() - if(!isnull(style)) - style.fully_remove(user) + AddComponent(/datum/component/martial_art_giver, /datum/martial_art/the_sleeping_carp) #undef STRONG_PUNCH_COMBO #undef LAUNCH_KICK_COMBO diff --git a/code/datums/martial/wrestling.dm b/code/datums/martial/wrestling.dm index 6969c3eeb9e..4bcaf02b2d5 100644 --- a/code/datums/martial/wrestling.dm +++ b/code/datums/martial/wrestling.dm @@ -490,22 +490,7 @@ If you make a derivative work from this code, you must include this notification /obj/item/storage/belt/champion/wrestling name = "Wrestling Belt" - var/datum/martial_art/wrestling/style /obj/item/storage/belt/champion/wrestling/Initialize(mapload) . = ..() - style = new() - style.allow_temp_override = FALSE - -/obj/item/storage/belt/champion/wrestling/Destroy() - QDEL_NULL(style) - return ..() - -/obj/item/storage/belt/champion/wrestling/equipped(mob/user, slot) - . = ..() - if(slot & ITEM_SLOT_BELT) - style.teach(user, TRUE) - -/obj/item/storage/belt/champion/wrestling/dropped(mob/user) - . = ..() - style.fully_remove(user) + AddComponent(/datum/component/martial_art_giver, /datum/martial_art/wrestling) diff --git a/tgstation.dme b/tgstation.dme index 4c011a1c3d9..6fcba386bf6 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -1228,6 +1228,7 @@ #include "code\datums\components\manual_breathing.dm" #include "code\datums\components\manual_heart.dm" #include "code\datums\components\marionette.dm" +#include "code\datums\components\martial_art_giver.dm" #include "code\datums\components\mind_linker.dm" #include "code\datums\components\mirv.dm" #include "code\datums\components\mob_chain.dm"