Skip to content

Commit

Permalink
Removes try_attach_accessory() stub, generalizes accessory equipping.
Browse files Browse the repository at this point in the history
  • Loading branch information
MistakeNot4892 committed Apr 22, 2024
1 parent 6dbc496 commit 04fb0eb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
7 changes: 0 additions & 7 deletions code/modules/clothing/_clothing.dm
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,3 @@
. = ..()
LAZYADD(., /decl/interaction_handler/clothing_set_sensors)

// This stub is so the linter stops yelling about sleeping during Initialize()
// due to corpse props equipping themselves, which calls equip_to_slot, which
// calls attackby(), which sometimes sleeps due to input(). Yeah.
// Remove this if a better fix presents itself.
/obj/item/clothing/proc/try_attach_accessory(var/obj/item/accessory, var/mob/user)
set waitfor = FALSE
attackby(accessory, user)
26 changes: 13 additions & 13 deletions code/modules/clothing/_clothing_accessories.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@
/obj/item/clothing/proc/get_initial_accessory_hide_on_states()
return null

/obj/item/clothing/proc/can_attach_accessory(obj/item/clothing/accessory)
if(valid_accessory_slots && istype(accessory) && !isnull(accessory.accessory_slot) && (accessory.accessory_slot in valid_accessory_slots))
. = 1
else
return 0
/obj/item/clothing/proc/can_attach_accessory(obj/item/clothing/accessory, mob/user)
if(!length(valid_accessory_slots))
to_chat(user, SPAN_WARNING("You cannot attach accessories of any kind to \the [src]."))
return FALSE
if(!istype(accessory) || isnull(accessory.accessory_slot) || !(accessory.accessory_slot in valid_accessory_slots))
to_chat(user, SPAN_WARNING("You cannot attach accessories of this kind to \the [src]."))
return FALSE
if(LAZYLEN(accessories) && restricted_accessory_slots && (accessory.accessory_slot in restricted_accessory_slots))
for(var/obj/item/clothing/other_accessory in accessories)
if (other_accessory.accessory_slot == accessory.accessory_slot)
return 0
to_chat(user, SPAN_WARNING("You cannot attach more accessories of this kind to \the [src]."))
return FALSE
return TRUE

// Override for action buttons.
/obj/item/clothing/attack_self(mob/user)
Expand All @@ -43,20 +47,16 @@
return ..()

/obj/item/clothing/attackby(var/obj/item/I, var/mob/user)

if(istype(I, /obj/item/clothing))

var/obj/item/clothing/accessory = I
if(!isnull(accessory.accessory_slot))

if(!valid_accessory_slots || !valid_accessory_slots.len)
to_chat(usr, SPAN_WARNING("You cannot attach accessories of any kind to \the [src]."))
return TRUE

if(can_attach_accessory(accessory))
if(can_attach_accessory(accessory, user))
if(user.try_unequip(accessory))
attach_accessory(user, accessory)
else
to_chat(user, SPAN_WARNING("You cannot attach more accessories of this type to [src]."))
to_chat(user, SPAN_WARNING("You cannot attach \the [I] to \the [src]."))
return TRUE

if(length(accessories))
Expand Down
24 changes: 18 additions & 6 deletions code/modules/mob/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,24 @@
return TRUE

if(slot == slot_tie_str)
var/try_equip_slot = W.get_fallback_slot()
if(!try_equip_slot || try_equip_slot == slot_tie_str)
try_equip_slot = slot_w_uniform_str
var/obj/item/clothing/uniform = get_equipped_item(try_equip_slot)
if(istype(uniform))
uniform.try_attach_accessory(W, src)

var/list/check_slots = get_inventory_slots()
if(islist(check_slots))

check_slots = check_slots.Copy()
check_slots -= global.all_hand_slots

var/try_equip_slot = W.get_fallback_slot()
if(try_equip_slot)
check_slots -= try_equip_slot
check_slots.Insert(1, try_equip_slot)

for(var/slot_string in check_slots)
var/obj/item/clothing/clothes = get_equipped_item(slot_string)
if(istype(clothes) && clothes.can_attach_accessory(W, src))
clothes.attach_accessory(src, W)
break

return TRUE

unequip(W)
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/stripping.dm
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
admin_attack_log(user, src, "Attempted to strip \a [target_slot]", "Target of a failed strip of \a [target_slot].", "attempted to strip \a [target_slot] from")
else if(user.try_unequip(held))
var/obj/item/clothing/C = get_equipped_item(slot_to_strip_text)
if(istype(C) && C.can_attach_accessory(held))
if(istype(C) && C.can_attach_accessory(held, user))
C.attach_accessory(user, held)
else if(!equip_to_slot_if_possible(held, slot_to_strip_text, del_on_fail=0, disable_warning=1, redraw_mob=1))
user.put_in_active_hand(held)
Expand Down

0 comments on commit 04fb0eb

Please sign in to comment.