Files
Bubberstation/code/datums/components/holderloving.dm
MrMelbert df7b3e4c31 Reverts a check added in [NO GBP] Fixes drone toolbox issues, fixes clothing unequipping, unit test (#87131)
## About The Pull Request

Fixes #87129

[This
change](https://github.com/tgstation/tgstation/pull/87073/files#diff-c8ab5fbc20de60e202b839834b039649cbb69a1c4b99b27a5e467f3889442ccd)
added in #87073, passing `invdrop = FALSE` to `doUnEquip`, breaks the
behavior of unequipping dropping your items. Because that's what
`invdrop` does. If you pass it as `FALSE` it prevents other items from
dropping off the mob, intended for like, outfit use / "quick swapping"
an item out

So I reverted it. Drone tools still seem to work I guess. @SyncIt21 

## Changelog

🆑 Melbert
fix: Fixes stuff staying on your body after removing your clothes
/🆑
2024-11-14 16:04:17 -08:00

93 lines
3.1 KiB
Plaintext

/** Holder Loving Component
*
* This component is assigned to an [/obj/item], and also keeps track of a [holder].
* The [parent] is 'bound' to [holder]. [parent] will be kept either directly
* inside [holder], or in the inventory of a [/mob] that is itself holding [holder].
*
* If [parent] is placed in a [loc] that is not [holder] or [holder].[loc]
* (if it's a mob), it is placed back inside [holder].
*
* This is intended for items that are a 'part' of another item.
*
* It can also delete [parent] when [holder] is deleted.
*
*/
/datum/component/holderloving
can_transfer = TRUE
/** Item that parent is bound to.
* We try to keep parent either directly in holder, or in holder's loc if loc is a mob,
* and warp parent into holder if they go anywhere else.
*/
var/atom/holder
/// If parent is deleted when the holder gets deleted
var/del_parent_with_holder = FALSE
/datum/component/holderloving/Initialize(holder, del_parent_with_holder)
if(!isitem(parent) || !holder)
return COMPONENT_INCOMPATIBLE
src.holder = holder
if(del_parent_with_holder)
src.del_parent_with_holder = del_parent_with_holder
/datum/component/holderloving/RegisterWithParent()
RegisterSignal(holder, COMSIG_MOVABLE_MOVED, PROC_REF(check_my_loc))
RegisterSignal(holder, COMSIG_QDELETING, PROC_REF(holder_deleting))
RegisterSignals(parent, list(
COMSIG_ITEM_DROPPED,
COMSIG_ITEM_EQUIPPED,
COMSIG_ATOM_ENTERED,
COMSIG_ATOM_EXITED,
COMSIG_ITEM_STORED,
), PROC_REF(check_my_loc))
RegisterSignal(parent, COMSIG_ITEM_PRE_UNEQUIP, PROC_REF(no_unequip))
/datum/component/holderloving/UnregisterFromParent()
UnregisterSignal(holder, list(COMSIG_MOVABLE_MOVED, COMSIG_QDELETING))
UnregisterSignal(parent, list(
COMSIG_ITEM_DROPPED,
COMSIG_ITEM_EQUIPPED,
COMSIG_ATOM_ENTERED,
COMSIG_ATOM_EXITED,
COMSIG_ITEM_STORED,
COMSIG_ITEM_PRE_UNEQUIP,
))
/datum/component/holderloving/PostTransfer()
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
/datum/component/holderloving/InheritComponent(datum/component/holderloving/friend, i_am_original, list/arguments)
if(i_am_original)
holder = friend.holder
/datum/component/holderloving/proc/check_valid_loc(atom/location)
return (location == holder || ( location == holder.loc && ismob(holder.loc) ))
/datum/component/holderloving/proc/holder_deleting(datum/source, force)
SIGNAL_HANDLER
if(del_parent_with_holder)
qdel(parent)
else
qdel(src)
/datum/component/holderloving/proc/check_my_loc(datum/source)
SIGNAL_HANDLER
var/obj/item/item_parent = parent
if(!check_valid_loc(item_parent.loc))
item_parent.forceMove(holder)
/datum/component/holderloving/proc/no_unequip(obj/item/I, force, atom/newloc, no_move, invdrop, silent)
SIGNAL_HANDLER
// just allow it
if(force)
return NONE
// dropping onto a turf just forcemoves it back to the holder. let it happen, it's intuitive
// no_move says it's just going to be moved a second time. so let it happen, it'll just be moved back if it's invalid anyway
if(isturf(newloc) || no_move)
return NONE
// the item is being unequipped to somewhere invalid. stop it
return COMPONENT_ITEM_BLOCK_UNEQUIP