mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-08 22:50:51 +01:00
21b4095dfd
Upstream 04/17/2026 fixes https://github.com/Bubberstation/Bubberstation/issues/5549 --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: tgstation-ci[bot] <179393467+tgstation-ci[bot]@users.noreply.github.com> Co-authored-by: ArcaneMusic <41715314+ArcaneMusic@users.noreply.github.com> Co-authored-by: MrMelbert <51863163+MrMelbert@users.noreply.github.com> Co-authored-by: Rhials <28870487+Rhials@users.noreply.github.com> Co-authored-by: rageguy505 <54517726+rageguy505@users.noreply.github.com> Co-authored-by: LemonInTheDark <58055496+LemonInTheDark@users.noreply.github.com> Co-authored-by: John Willard <53777086+JohnFulpWillard@users.noreply.github.com> Co-authored-by: Aliceee2ch <160794176+Aliceee2ch@users.noreply.github.com> Co-authored-by: Time-Green <7501474+Time-Green@users.noreply.github.com> Co-authored-by: Tsar-Salat <62388554+Tsar-Salat@users.noreply.github.com> Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: Maxipat <108554989+Maxipat112@users.noreply.github.com> Co-authored-by: SyncIt21 <110812394+SyncIt21@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: SimplyLogan <47579821+loganuk@users.noreply.github.com> Co-authored-by: loganuk <fakeemail123@aol.com> Co-authored-by: Leland Kemble <70413276+lelandkemble@users.noreply.github.com> Co-authored-by: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Co-authored-by: Roxy <75404941+TealSeer@users.noreply.github.com> Co-authored-by: Lucy <lucy@absolucy.moe> Co-authored-by: siliconOpossum <138069572+siliconOpossum@users.noreply.github.com> Co-authored-by: Isratosh <Isratosh@hotmail.com> Co-authored-by: TheRyeGuyWhoWillNowDie <70169560+TheRyeGuyWhoWillNowDie@users.noreply.github.com> Co-authored-by: Neocloudy <88008002+Neocloudy@users.noreply.github.com> Co-authored-by: Alexander V. <volas@ya.ru> Co-authored-by: ElGitificador <168473461+ElGitificador@users.noreply.github.com> Co-authored-by: Twaticus <46540570+Twaticus@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Bloop <13398309+vinylspiders@users.noreply.github.com> Co-authored-by: Cameron Lennox <killer65311@gmail.com> Co-authored-by: Tim <timothymtorres@gmail.com> Co-authored-by: Iamgoofball <iamgoofball@gmail.com> Co-authored-by: Layzu666 <121319428+Layzu666@users.noreply.github.com> Co-authored-by: Arturlang <24881678+Arturlang@users.noreply.github.com> Co-authored-by: _0Steven <42909981+00-Steven@users.noreply.github.com> Co-authored-by: mrmanlikesbt <99309552+mrmanlikesbt@users.noreply.github.com> Co-authored-by: Ben10Omintrix <138636438+Ben10Omintrix@users.noreply.github.com> Co-authored-by: John F. Kennedy <54908920+MacaroniCritter@users.noreply.github.com> Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com> Co-authored-by: Josh <josh.adam.powell@gmail.com> Co-authored-by: Josh Powell <josh.powell@softwire.com> Co-authored-by: Yobrocharlie <Charliemiller5617@gmail.com> Co-authored-by: Hardly3D <66234359+Hardly3D@users.noreply.github.com> Co-authored-by: shayoki <96078776+shayoki@users.noreply.github.com> Co-authored-by: LT3 <83487515+lessthnthree@users.noreply.github.com>
107 lines
4.0 KiB
Plaintext
107 lines
4.0 KiB
Plaintext
/**
|
|
* ## Limb Applicable
|
|
*
|
|
* Allows item to be attached to limbs by clicking on humans with them while limb targeting
|
|
*
|
|
* The item then goes in the limb's contents, where it will be added to the limb's applied_items list
|
|
* The applied_items is indexed by category so you can easily check for the presence of a given item or category of item
|
|
*/
|
|
/datum/component/limb_applicable
|
|
/// List of body zones we can apply parent to
|
|
var/list/valid_zones
|
|
/// Category that the parent is applied to
|
|
/// Defaults to REF(parent), ie, you can apply any number of this item to a limb
|
|
/// Setting it to a category will prevent multiple items of that category being applied unless override_existing is TRUE
|
|
var/apply_category
|
|
/// If TRUE, replaces existing items with new ones
|
|
/// If FALSE, application will fail if an item of the same category is already applied
|
|
var/override_existing
|
|
/// Callback to determine if application can be attempted. Cannot sleep. (Return FALSE to block application)
|
|
var/datum/callback/can_apply
|
|
/// Callback to attempt application, I.E. do_after()s. Can sleep.
|
|
var/datum/callback/do_apply
|
|
/// Callback invoked after application
|
|
var/datum/callback/on_apply
|
|
|
|
/datum/component/limb_applicable/Initialize(
|
|
list/valid_zones = GLOB.all_body_zones.Copy(),
|
|
apply_category,
|
|
override_existing = TRUE,
|
|
datum/callback/can_apply,
|
|
datum/callback/do_apply,
|
|
datum/callback/on_apply,
|
|
)
|
|
if(!isitem(parent))
|
|
return COMPONENT_INCOMPATIBLE
|
|
|
|
src.valid_zones = valid_zones
|
|
src.apply_category = apply_category || REF(parent)
|
|
src.override_existing = override_existing
|
|
src.can_apply = can_apply
|
|
src.do_apply = do_apply
|
|
src.on_apply = on_apply
|
|
|
|
|
|
/datum/component/limb_applicable/RegisterWithParent()
|
|
RegisterSignal(parent, COMSIG_ITEM_INTERACTING_WITH_ATOM, PROC_REF(on_apply))
|
|
RegisterSignal(parent, COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET, PROC_REF(add_context))
|
|
|
|
var/obj/item/applying_item = parent
|
|
applying_item.flags_1 |= HAS_CONTEXTUAL_SCREENTIPS_1
|
|
|
|
/datum/component/limb_applicable/UnregisterFromParent()
|
|
UnregisterSignal(parent, COMSIG_ITEM_INTERACTING_WITH_ATOM)
|
|
UnregisterSignal(parent, COMSIG_ITEM_REQUESTING_CONTEXT_FOR_TARGET)
|
|
|
|
/datum/component/limb_applicable/proc/add_context(obj/item/source, list/context, atom/target, mob/living/user)
|
|
if(isliving(target))
|
|
context[SCREENTIP_CONTEXT_LMB] = "Apply [source.name]"
|
|
return CONTEXTUAL_SCREENTIP_SET
|
|
return NONE
|
|
|
|
/datum/component/limb_applicable/proc/on_apply(datum/source, mob/user, atom/interacting_with)
|
|
SIGNAL_HANDLER
|
|
|
|
if(!isliving(interacting_with))
|
|
return NONE
|
|
|
|
var/mob/living/target = interacting_with
|
|
var/obj/item/bodypart/applying_to = target.get_bodypart(deprecise_zone(user.zone_selected))
|
|
|
|
if(isnull(applying_to))
|
|
target.balloon_alert(user, "no bodypart!")
|
|
return ITEM_INTERACT_BLOCKING
|
|
|
|
if(!(applying_to.body_zone in valid_zones))
|
|
target.balloon_alert(user, "can't be applied there!")
|
|
return ITEM_INTERACT_BLOCKING
|
|
|
|
if(!override_existing)
|
|
var/obj/item/existing = LAZYACCESS(applying_to.applied_items, apply_category)
|
|
if(!isnull(existing))
|
|
target.balloon_alert(user, "something is already there!")
|
|
return ITEM_INTERACT_BLOCKING
|
|
|
|
if(can_apply)
|
|
var/try_apply = can_apply.Invoke(user, target, applying_to)
|
|
if(try_apply & LIMB_APPLICABLE_BLOCK_APPLICATION)
|
|
return (try_apply & LIMB_APPLICABLE_BLOCK_ITEM_INTERACTION) ? ITEM_INTERACT_BLOCKING : NONE
|
|
|
|
INVOKE_ASYNC(src, PROC_REF(on_apply_async), user, interacting_with, applying_to)
|
|
return ITEM_INTERACT_BLOCKING
|
|
|
|
/datum/component/limb_applicable/proc/on_apply_async(mob/user, mob/living/target, obj/item/bodypart/applying_to)
|
|
if(!do_apply?.Invoke(user, target, applying_to))
|
|
return
|
|
var/obj/item/applying = parent
|
|
if(isstack(parent))
|
|
var/obj/item/stack/stack_parent = parent
|
|
applying = stack_parent.split_stack(1)
|
|
|
|
else if(!user.temporarilyRemoveItemFromInventory(applying))
|
|
target.balloon_alert(user, "can't part with [applying.name]!")
|
|
return
|
|
|
|
applying_to.apply_item(applying, apply_category, override_existing)
|
|
on_apply?.Invoke(user, target, applying_to)
|