Skip to content

Commit

Permalink
Merge pull request #4794 from MistakeNot4892/fixes/holster
Browse files Browse the repository at this point in the history
Holster fixes, quick interactions.
  • Loading branch information
out-of-phaze authored Jan 23, 2025
2 parents 93e7ba4 + e6f947b commit a807d65
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
4 changes: 2 additions & 2 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@
return A.CtrlClick(src)

/atom/proc/CtrlClick(var/mob/user)
if(loc == user)
if(get_recursive_loc_of_type(/mob) == user)
var/decl/interaction_handler/handler = get_quick_interaction_handler(user)
if(handler)
var/using_item = user.get_active_held_item() || user.get_usable_hand_slot_organ()
var/using_item = user.get_active_held_item()
if(handler.is_possible(src, user, using_item))
return handler.invoked(src, user, using_item)
return FALSE
Expand Down
63 changes: 61 additions & 2 deletions code/datums/extensions/holster/holster.dm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
to_chat(user, "It is empty.")

/datum/extension/holster/proc/check_holster()
if(holstered.loc != storage)
if(holstered.loc != storage.holder)
clear_holster()

/atom/proc/holster_verb(var/holster_name in get_holsters())
Expand Down Expand Up @@ -154,4 +154,63 @@
else
for(var/i = 1 to holster_accessories.len)
var/holster_name = "[accessory_name] [i]"
.[holster_name] = get_extension(holster_accessories[i], /datum/extension/holster)
.[holster_name] = get_extension(holster_accessories[i], /datum/extension/holster)

// Basic unholster for an item at the top level.
/decl/interaction_handler/unholster
name = "Unholster"

/decl/interaction_handler/unholster/is_possible(atom/target, mob/user, obj/item/prop)
. = ..() && !prop
if(.)
var/datum/extension/holster/holster = get_extension(target, /datum/extension/holster)
return !!holster?.holstered

/decl/interaction_handler/unholster/invoked(atom/target, mob/user, obj/item/prop)
var/datum/extension/holster/holster = get_extension(target, /datum/extension/holster)
return holster?.unholster(user, avoid_intent = TRUE)

// Interaction procs for getting this interaction for basic items.
/obj/item/get_quick_interaction_handler(mob/user)
if(!(. = ..()))
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(holster?.holstered)
return GET_DECL(/decl/interaction_handler/unholster)

// More complex version of the above that iterates clothing accessories.
/decl/interaction_handler/unholster_accessory
name = "Unholster From Accessory"
expected_target_type = /obj/item/clothing

/decl/interaction_handler/unholster_accessory/is_possible(atom/target, mob/user, obj/item/prop)
. = ..() && !prop
if(.)
var/obj/item/clothing/clothes = target
for(var/obj/item/thing in clothes.accessories)
var/datum/extension/holster/holster = get_extension(thing, /datum/extension/holster)
if(holster?.holstered)
return TRUE
return FALSE

/decl/interaction_handler/unholster_accessory/invoked(atom/target, mob/user, obj/item/prop)
var/obj/item/clothing/clothes = target
for(var/obj/item/thing in clothes.accessories)
var/datum/extension/holster/holster = get_extension(thing, /datum/extension/holster)
if(holster?.unholster(user, avoid_intent = TRUE))
return TRUE
return FALSE

// Interaction procs for getting this interaction for clothing accessories.
/obj/item/clothing/get_alt_interactions(mob/user)
. = ..()
for(var/obj/item/thing in accessories)
var/datum/extension/holster/holster = get_extension(thing, /datum/extension/holster)
if(holster?.holstered)
LAZYADD(., GET_DECL(/decl/interaction_handler/unholster_accessory))

/obj/item/clothing/get_quick_interaction_handler(mob/user)
if(!(. = ..()))
for(var/obj/item/thing in accessories)
var/datum/extension/holster/holster = get_extension(thing, /datum/extension/holster)
if(holster?.holstered)
return GET_DECL(/decl/interaction_handler/unholster_accessory)
37 changes: 15 additions & 22 deletions code/game/objects/items/weapons/storage/belt.dm
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
. = ..()
if(overlay_flags & BELT_OVERLAY_ITEMS)
var/list/cur_overlays
for(var/obj/item/I in contents)
if(I.use_single_icon)
LAZYADD(cur_overlays, I.get_on_belt_overlay())
for(var/obj/item/thing in contents)
if(thing.use_single_icon)
LAZYADD(cur_overlays, thing.get_on_belt_overlay())
else
LAZYADD(cur_overlays, overlay_image('icons/obj/clothing/obj_belt_overlays.dmi', I.icon_state))
LAZYADD(cur_overlays, overlay_image('icons/obj/clothing/obj_belt_overlays.dmi', thing.icon_state))

if(LAZYLEN(cur_overlays))
add_overlay(cur_overlays)
Expand All @@ -37,8 +37,8 @@
/obj/item/belt/get_mob_overlay(mob/user_mob, slot, bodypart, use_fallback_if_icon_missing = TRUE, skip_adjustment = FALSE)
var/image/ret = ..()
if(ret && slot == slot_belt_str && length(contents))
for(var/obj/item/I in contents)
var/image/new_overlay = I.get_mob_overlay(user_mob, slot, bodypart, use_fallback_if_icon_missing, TRUE)
for(var/obj/item/thing in contents)
var/image/new_overlay = thing.get_mob_overlay(user_mob, slot, bodypart, use_fallback_if_icon_missing, TRUE)
if(new_overlay)
ret.overlays += new_overlay
return ret
Expand All @@ -57,13 +57,6 @@
. = ..()
set_extension(src, /datum/extension/holster, storage, sound_in, sound_out, can_holster)

/obj/item/belt/holster/get_stored_inventory()
. = ..()
if(length(.))
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(holster.holstered)
. -= holster.holstered

/obj/item/belt/holster/attackby(obj/item/used_item, mob/user)
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(holster?.holster(used_item, user))
Expand All @@ -73,27 +66,27 @@
/obj/item/belt/holster/attack_hand(mob/user)
if(!user.check_dexterity(DEXTERITY_HOLD_ITEM, TRUE))
return ..()
var/datum/extension/holster/H = get_extension(src, /datum/extension/holster)
if(H.unholster(user))
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(holster?.unholster(user))
return TRUE
return ..()

/obj/item/belt/holster/examine(mob/user)
. = ..()
var/datum/extension/holster/H = get_extension(src, /datum/extension/holster)
H.examine_holster(user)
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
holster.examine_holster(user)

/obj/item/belt/holster/on_update_icon()
. = ..()
var/datum/extension/holster/H = get_extension(src, /datum/extension/holster)
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(overlay_flags)
var/list/cur_overlays
for(var/obj/item/I in contents)
if(I == H.holstered)
for(var/obj/item/thing in contents)
if(thing == holster.holstered)
if(overlay_flags & BELT_OVERLAY_HOLSTER)
LAZYADD(cur_overlays, overlay_image('icons/obj/clothing/obj_belt_overlays.dmi', I.icon_state))
LAZYADD(cur_overlays, overlay_image('icons/obj/clothing/obj_belt_overlays.dmi', thing.icon_state))
else if(overlay_flags & BELT_OVERLAY_ITEMS)
LAZYADD(cur_overlays, overlay_image('icons/obj/clothing/obj_belt_overlays.dmi', I.icon_state))
LAZYADD(cur_overlays, overlay_image('icons/obj/clothing/obj_belt_overlays.dmi', thing.icon_state))

if(LAZYLEN(cur_overlays))
add_overlay(cur_overlays)
Expand Down
17 changes: 8 additions & 9 deletions code/modules/clothing/webbing/holster.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@
. = ..()
set_extension(src, /datum/extension/holster, storage, sound_in, sound_out, can_holster)

/obj/item/clothing/webbing/holster/attackby(obj/item/W, mob/user)
var/datum/extension/holster/H = get_extension(src, /datum/extension/holster)
if(H.holster(W, user))
/obj/item/clothing/webbing/holster/attackby(obj/item/used_item, mob/user)
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(holster.holster(used_item, user))
return TRUE
else
. = ..(W, user)
return ..(used_item, user)

/obj/item/clothing/webbing/holster/attack_hand(mob/user)
if(!user.check_dexterity(DEXTERITY_HOLD_ITEM, TRUE))
return ..()
var/datum/extension/holster/H = get_extension(src, /datum/extension/holster)
if(H.unholster(user))
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
if(holster.unholster(user))
return TRUE
return ..()

/obj/item/clothing/webbing/holster/examine(mob/user)
. = ..(user)
var/datum/extension/holster/H = get_extension(src, /datum/extension/holster)
H.examine_holster(user)
var/datum/extension/holster/holster = get_extension(src, /datum/extension/holster)
holster.examine_holster(user)

/obj/item/clothing/webbing/holster/on_attached(var/obj/item/clothing/holder, var/mob/user)
. = ..()
Expand Down

0 comments on commit a807d65

Please sign in to comment.