Skip to content

Commit

Permalink
You walk faster with canes on missing limbs (MrMelbert#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMelbert authored Mar 24, 2024
1 parent 756f535 commit b45c2cf
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
3 changes: 3 additions & 0 deletions code/__DEFINES/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions code/game/objects/items/weaponry.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
. = ..()
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion code/modules/mob/living/living.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions maplestation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
51 changes: 51 additions & 0 deletions maplestation_modules/code/datums/components/limbless_aid.dm
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b45c2cf

Please sign in to comment.