From 973c2c8a6ccb8c8b767ff672e591297daa043049 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Mon, 22 Mar 2021 14:04:45 +0100 Subject: [PATCH] [MIRROR] Autodocs the slippery component + changes the hardcoded slot whitelist to a variable (#4318) * Autodocs the slippery component + changes the hardcoded slot whitelist to a variable (#57878) * Autodocs the slippery component + changes the hardcoded slot whitelist to a variable Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> --- code/datums/components/slippery.dm | 65 ++++++++++++++++--- .../objects/items/devices/PDA/PDA_types.dm | 2 +- 2 files changed, 56 insertions(+), 11 deletions(-) diff --git a/code/datums/components/slippery.dm b/code/datums/components/slippery.dm index c159aae6839..de839164f95 100644 --- a/code/datums/components/slippery.dm +++ b/code/datums/components/slippery.dm @@ -1,17 +1,27 @@ +/// Slippery component, for making anything slippery. Of course. /datum/component/slippery + /// If the slip forces you to drop held items. var/force_drop_items = FALSE + /// How long the slip keeps you knocked down. var/knockdown_time = 0 + /// How long the slip paralyzes for. var/paralyze_time = 0 + /// Flags for how slippery the parent is. See [__DEFINES/mobs.dm] var/lube_flags + /// A proc callback to call on slip. var/datum/callback/callback + /// If parent is an item, this is the person currently holding/wearing the parent (or the parent if no one is holding it) var/mob/living/holder + /// Whitelist of item slots the parent can be equipped in that make the holder slippery. If null or empty, it will always make the holder slippery. + var/list/slot_whitelist -/datum/component/slippery/Initialize(_knockdown, _lube_flags = NONE, datum/callback/_callback, _paralyze, _force_drop = FALSE) - knockdown_time = max(_knockdown, 0) - paralyze_time = max(_paralyze, 0) - force_drop_items = _force_drop - lube_flags = _lube_flags - callback = _callback +/datum/component/slippery/Initialize(knockdown, lube_flags = NONE, datum/callback/callback, paralyze, force_drop = FALSE, slot_whitelist) + src.knockdown_time = max(knockdown, 0) + src.paralyze_time = max(paralyze, 0) + src.force_drop_items = force_drop + src.lube_flags = lube_flags + src.callback = callback + src.slot_whitelist = slot_whitelist RegisterSignal(parent, COMSIG_MOVABLE_CROSSED, .proc/Slip) if(isitem(parent)) holder = parent @@ -20,6 +30,12 @@ else RegisterSignal(parent, COMSIG_ATOM_ENTERED, .proc/Slip) +/* + * The proc that does the sliping. Invokes the slip callback we have set. + * + * source - the source of the signal + * AM - the atom/movable that is being slipped. + */ /datum/component/slippery/proc/Slip(datum/source, atom/movable/AM) SIGNAL_HANDLER @@ -27,35 +43,64 @@ if(istype(victim) && !(victim.movement_type & FLYING) && victim.slip(knockdown_time, parent, lube_flags, paralyze_time, force_drop_items) && callback) callback.Invoke(victim) -///gets called when COMSIG_ITEM_EQUIPPED is sent to parent +/* + * Gets called when COMSIG_ITEM_EQUIPPED is sent to parent. + * This proc register slip signals to the equipper. + * If we have a slot whitelist, we only register the signals if the slot is valid (ex: clown PDA only slips in ID or belt slot). + * + * source - the source of the signal + * equipper - the mob we're equipping the slippery thing to + * slot - the slot we're equipping the slippery thing to on the equipper. + */ /datum/component/slippery/proc/on_equip(datum/source, mob/equipper, slot) SIGNAL_HANDLER - if((slot in list(ITEM_SLOT_ID, ITEM_SLOT_BELT)) && isliving(equipper)) + if((!LAZYLEN(slot_whitelist) || (slot in slot_whitelist)) && isliving(equipper)) holder = equipper RegisterSignal(holder, COMSIG_MOVABLE_CROSSED, .proc/Slip_on_wearer) RegisterSignal(holder, COMSIG_PARENT_PREQDELETED, .proc/holder_deleted) +/* + * Detects if the holder mob is deleted. + * If our holder mob is the holder set in this component, we null it. + * + * source - the source of the signal + * possible_holder - the mob being deleted. + */ /datum/component/slippery/proc/holder_deleted(datum/source, datum/possible_holder) SIGNAL_HANDLER if(possible_holder == holder) holder = null -///gets called when COMSIG_ITEM_DROPPED is sent to parent +/* + * Gets called when COMSIG_ITEM_DROPPED is sent to parent. + * Makes our holder mob un-slippery. + * + * source - the source of the signal + * user - the mob that was formerly wearing our slippery item. + */ /datum/component/slippery/proc/on_drop(datum/source, mob/user) SIGNAL_HANDLER holder = null UnregisterSignal(user, COMSIG_MOVABLE_CROSSED) +/* + * The slip proc, but for equipped items. + * Slips the person who crossed us if we're lying down and unbuckled. + * + * source - the source of the signal + * AM - the atom/movable that slipped on us. + */ /datum/component/slippery/proc/Slip_on_wearer(datum/source, atom/movable/AM) SIGNAL_HANDLER if(holder.body_position == LYING_DOWN && !holder.buckled) Slip(source, AM) -/datum/component/slippery/clowning //used for making the clown PDA only slip if the clown is wearing his shoes and the elusive banana-skin belt +/// Used for making the clown PDA only slip if the clown is wearing his shoes and the elusive banana-skin belt +/datum/component/slippery/clowning /datum/component/slippery/clowning/Slip_on_wearer(datum/source, atom/movable/AM) var/obj/item/I = holder.get_item_by_slot(ITEM_SLOT_FEET) diff --git a/code/game/objects/items/devices/PDA/PDA_types.dm b/code/game/objects/items/devices/PDA/PDA_types.dm index 4aec3fffbd6..ac4d635050a 100644 --- a/code/game/objects/items/devices/PDA/PDA_types.dm +++ b/code/game/objects/items/devices/PDA/PDA_types.dm @@ -9,7 +9,7 @@ /obj/item/pda/clown/ComponentInitialize() . = ..() - AddComponent(/datum/component/slippery/clowning, 120, NO_SLIP_WHEN_WALKING, CALLBACK(src, .proc/AfterSlip)) + AddComponent(/datum/component/slippery/clowning, 120, NO_SLIP_WHEN_WALKING, CALLBACK(src, .proc/AfterSlip), slot_whitelist = list(ITEM_SLOT_ID, ITEM_SLOT_BELT)) AddComponent(/datum/component/wearertargeting/sitcomlaughter, CALLBACK(src, .proc/after_sitcom_laugh)) /obj/item/pda/clown/proc/AfterSlip(mob/living/carbon/human/M)