Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds /atom/proc/get_mob_owner() + blocks a delayed possession of item that's possessed by a player already #9128

Closed
wants to merge 11 commits into from
15 changes: 15 additions & 0 deletions code/__HELPERS/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,18 @@ B --><-- A
return get_step(ref, base_dir)

*/

/// returns a mob that possesses this atom(usually item),
/// or returns null if it is possessed by no mob.
/atom/proc/get_mob_loc(as_first_mob=TRUE)
var/atom/upper = src
EvilDragonfiend marked this conversation as resolved.
Show resolved Hide resolved
var/final_mob
while(upper)
upper = upper.loc
if(ismob(upper))
final_mob = upper
// if this is TRUE, it will immediately return a mob that holds the atom
// if this is FALSE, it will find a final mob when it's chain-contained (i.e. mob in mob in mob...)
if(as_first_mob)
return final_mob
return final_mob
9 changes: 1 addition & 8 deletions code/modules/clothing/chameleon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,7 @@
/datum/action/item_action/chameleon/change/proc/update_mob_hud(atom/card_holder)
// we're going to find a human, and store human ref to 'card_holder' by checking loc multiple time.
if(!ishuman(card_holder))
if(!card_holder)
card_holder = target.loc
if(istype(card_holder, /obj/item/storage/wallet))
card_holder = card_holder.loc // this should be human
if(istype(card_holder, /obj/item/computer_hardware/card_slot))
card_holder = card_holder.loc
if(istype(card_holder, /obj/item/modular_computer/tablet))
card_holder = card_holder.loc // tihs should be human
card_holder = target.get_mob_loc()
if(!ishuman(card_holder))
return
var/mob/living/carbon/human/card_holding_human = card_holder
Expand Down
13 changes: 9 additions & 4 deletions code/modules/mob/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
/mob/proc/can_equip(obj/item/I, slot, disable_warning = FALSE, bypass_equip_delay_self = FALSE)
return FALSE

/mob/proc/can_put_in_hand(I, hand_index)
/mob/proc/can_put_in_hand(atom/I, hand_index)
if(hand_index > length(held_items))
return FALSE
if(!put_in_hand_check(I))
Expand Down Expand Up @@ -209,7 +209,12 @@
return FALSE

//Puts the item into our active hand if possible. returns TRUE on success.
/mob/proc/put_in_active_hand(obj/item/I, forced = FALSE, ignore_animation = TRUE)
/mob/proc/put_in_active_hand(obj/item/I, forced = FALSE, ignore_animation = TRUE, checks_mob_loc=TRUE)
if(checks_mob_loc) // checks if it's possessed by a mob to prevent client delay. offer code sends this as FALSE.
var/owner = I.get_mob_loc()
if(ismob(owner) && owner != src)
show_message("<span class='notice'>You wanted to pick up [src], but it's already on someone's hand. You feel bad about the space latency...</span>")
return FALSE // sorry, you won't get the benefit of your bad latency.
return put_in_hand(I, active_hand_index, forced, ignore_animation)


Expand All @@ -221,7 +226,7 @@
//Puts the item our active hand if possible. Failing that it tries other hands. Returns TRUE on success.
//If both fail it drops it on the floor and returns FALSE.
//This is probably the main one you need to know :)
/mob/proc/put_in_hands(obj/item/I, del_on_fail = FALSE, merge_stacks = TRUE, forced = FALSE)
/mob/proc/put_in_hands(obj/item/I, del_on_fail = FALSE, merge_stacks = TRUE, forced = FALSE, checks_mob_loc = TRUE)
if(QDELETED(I))
return FALSE

Expand All @@ -245,7 +250,7 @@
to_chat(usr, "<span class='notice'>Your [inactive_stack.name] stack now contains [inactive_stack.get_amount()] [inactive_stack.singular_name]\s.</span>")
return TRUE

if(put_in_active_hand(I, forced))
if(put_in_active_hand(I, forced, checks_mob_loc=checks_mob_loc))
return TRUE

var/hand = get_empty_held_index_for_side("l")
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,4 @@
return
visible_message("<span class='notice'>[src] takes [I] from [offerer]</span>", \
"<span class='notice'>You take [I] from [offerer]</span>")
put_in_hands(I)
put_in_hands(I, checks_mob_loc=FALSE)
Loading