From b45c2cf318de551d2386a1d215e16ca1861dfc52 Mon Sep 17 00:00:00 2001 From: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:24:37 -0500 Subject: [PATCH] You walk faster with canes on missing limbs (#459) --- code/__DEFINES/living.dm | 3 ++ code/game/objects/items/weaponry.dm | 17 +++++++ code/modules/mob/living/living.dm | 10 +++- maplestation.dme | 1 + .../code/datums/components/limbless_aid.dm | 51 +++++++++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 maplestation_modules/code/datums/components/limbless_aid.dm diff --git a/code/__DEFINES/living.dm b/code/__DEFINES/living.dm index 2bd16e2cf591..7fd839bacfb5 100644 --- a/code/__DEFINES/living.dm +++ b/code/__DEFINES/living.dm @@ -5,6 +5,9 @@ // NON-MODULE CHANGE // Sticking these here for now because i'm dumb +/// Updating a mob's movespeed when lacking limbs. (list/modifiers) +#define COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE "living_get_movespeed_modifiers" + // -- Defines for the pain system. -- /// Sent when a carbon gains pain. (source = mob/living/carbon/human, obj/item/bodypart/affected_bodypart, amount, type) diff --git a/code/game/objects/items/weaponry.dm b/code/game/objects/items/weaponry.dm index 3c6c7f56e826..06bda335b9af 100644 --- a/code/game/objects/items/weaponry.dm +++ b/code/game/objects/items/weaponry.dm @@ -450,10 +450,21 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301 custom_materials = list(/datum/material/iron= SMALL_MATERIAL_AMOUNT * 0.5) attack_verb_continuous = list("bludgeons", "whacks", "disciplines", "thrashes") attack_verb_simple = list("bludgeon", "whack", "discipline", "thrash") + /// Only exists so the white cane doesn't spawn with its "effects" while unextended + var/start_with_effects = TRUE /obj/item/cane/Initialize(mapload) . = ..() + if(start_with_effects) + add_effects() + +/obj/item/cane/proc/add_effects() ADD_TRAIT(src, TRAIT_BLIND_TOOL, INNATE_TRAIT) + AddComponent(/datum/component/limbless_aid) + +/obj/item/cane/proc/remove_effects() + REMOVE_TRAIT(src, TRAIT_BLIND_TOOL, INNATE_TRAIT) + qdel(GetComponent(/datum/component/limbless_aid)) /obj/item/cane/white name = "white cane" @@ -465,6 +476,7 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301 force = 1 w_class = WEIGHT_CLASS_SMALL custom_materials = list(/datum/material/iron = SMALL_MATERIAL_AMOUNT * 6) + start_with_effects = FALSE /obj/item/cane/white/Initialize(mapload) . = ..() @@ -487,6 +499,11 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301 /obj/item/cane/white/proc/on_transform(obj/item/source, mob/user, active) SIGNAL_HANDLER + if(active) + add_effects() + else + remove_effects() + if(user) balloon_alert(user, active ? "extended" : "collapsed") playsound(src, 'sound/weapons/batonextend.ogg', 50, TRUE) diff --git a/code/modules/mob/living/living.dm b/code/modules/mob/living/living.dm index d5a22141c829..e0147cd57795 100644 --- a/code/modules/mob/living/living.dm +++ b/code/modules/mob/living/living.dm @@ -2289,15 +2289,23 @@ GLOBAL_LIST_EMPTY(fire_appearances) if(!usable_hands) ADD_TRAIT(src, TRAIT_IMMOBILIZED, LACKING_LOCOMOTION_APPENDAGES_TRAIT) + update_limbless_movespeed_mod() + +/// Updates the mob's movespeed based on how many limbs they have or are missing. +/mob/living/proc/update_limbless_movespeed_mod() if(usable_legs < default_num_legs) var/limbless_slowdown = (default_num_legs - usable_legs) * 3 if(!usable_legs && usable_hands < default_num_hands) limbless_slowdown += (default_num_hands - usable_hands) * 3 + + var/list/slowdown_mods = list() + SEND_SIGNAL(src, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE, slowdown_mods) + for(var/num in slowdown_mods) + limbless_slowdown *= slowdown_mods add_or_update_variable_movespeed_modifier(/datum/movespeed_modifier/limbless, multiplicative_slowdown = limbless_slowdown) else remove_movespeed_modifier(/datum/movespeed_modifier/limbless) - ///Proc to modify the value of num_hands and hook behavior associated to this event. /mob/living/proc/set_num_hands(new_value) if(num_hands == new_value) diff --git a/maplestation.dme b/maplestation.dme index b3c8c6f94298..c1af89d37e26 100644 --- a/maplestation.dme +++ b/maplestation.dme @@ -6090,6 +6090,7 @@ #include "maplestation_modules\code\controllers\subsystem\pain_subsystem.dm" #include "maplestation_modules\code\datums\shuttles.dm" #include "maplestation_modules\code\datums\components\easy_ignite.dm" +#include "maplestation_modules\code\datums\components\limbless_aid.dm" #include "maplestation_modules\code\datums\components\make_item_slow.dm" #include "maplestation_modules\code\datums\components\remote_materials.dm" #include "maplestation_modules\code\datums\components\stackable_item.dm" diff --git a/maplestation_modules/code/datums/components/limbless_aid.dm b/maplestation_modules/code/datums/components/limbless_aid.dm new file mode 100644 index 000000000000..fcd0be2f8ff0 --- /dev/null +++ b/maplestation_modules/code/datums/components/limbless_aid.dm @@ -0,0 +1,51 @@ +/// Attach to items that help mobs missing limbs move faster when held. +/datum/component/limbless_aid + /// What slot flags must the parent item have to provide the bonus? + var/required_slot = ITEM_SLOT_HANDS + /// How much should the movespeed be modified? + var/movespeed_mod = 0.5 + +/datum/component/limbless_aid/Initialize(required_slot = ITEM_SLOT_HANDS, movespeed_mod = 0.5) + if(!isitem(parent)) + return COMPONENT_INCOMPATIBLE + + src.required_slot = required_slot + src.movespeed_mod = movespeed_mod + +/datum/component/limbless_aid/RegisterWithParent() + RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(on_equip)) + RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(on_drop)) + + var/obj/item/item_parent = parent + if(isliving(item_parent.loc)) + var/mob/living/wearer = item_parent.loc + on_equip(parent, wearer, wearer.get_slot_by_item(parent)) + +/datum/component/limbless_aid/UnregisterFromParent() + UnregisterSignal(parent, list(COMSIG_ITEM_EQUIPPED, COMSIG_ITEM_DROPPED)) + + var/obj/item/item_parent = parent + if(isliving(item_parent.loc)) + var/mob/living/wearer = item_parent.loc + UnregisterSignal(wearer, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE) + wearer.update_limbless_movespeed_mod() + +/datum/component/limbless_aid/proc/on_equip(obj/item/source, mob/living/user, slot) + SIGNAL_HANDLER + + if(!(slot & required_slot)) + return + + RegisterSignal(user, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE, PROC_REF(modify_movespeed), override = TRUE) + user.update_limbless_movespeed_mod() + +/datum/component/limbless_aid/proc/on_drop(obj/item/source, mob/living/user) + SIGNAL_HANDLER + + UnregisterSignal(user, COMSIG_LIVING_LIMBLESS_MOVESPEED_UPDATE) + user.update_limbless_movespeed_mod() + +/datum/component/limbless_aid/proc/modify_movespeed(mob/living/source, list/modifiers) + SIGNAL_HANDLER + + modifiers += movespeed_mod