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
14 changes: 14 additions & 0 deletions code/__HELPERS/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -350,3 +350,17 @@ B --><-- A
return get_step(ref, base_dir)

*/

/// returns a mob that possesses this atom(usually item)
EvilDragonfiend marked this conversation as resolved.
Show resolved Hide resolved
/atom/proc/get_loc_mob(as_first_mob=TRUE)
EvilDragonfiend marked this conversation as resolved.
Show resolved Hide resolved
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 || FALSE
EvilDragonfiend marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 1 addition & 8 deletions code/modules/clothing/chameleon.dm
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,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_loc_mob()
if(!ishuman(card_holder))
return
var/mob/living/carbon/human/card_holding_human = card_holder
Expand Down
12 changes: 8 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 > held_items.len)
return FALSE
if(!put_in_hand_check(I))
Expand Down Expand Up @@ -209,7 +209,11 @@
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, offered=FALSE)
if(!offered) // check if a clicked item is in possession of someone already unless it's offered.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a rather snowflake check for something used twice vs a proc used hundreds of places. just add this check to places setting offered = true instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted a cleaner way, but I couldn't find anything better than adding this snowflake because of how offer code works.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put in nactive hand should simply put the item in your active hand and not do any of this. Add the logic to offering instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really want to do a fancier way, but offer code isn't really compatible well with this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be done a better way that is more modularised and contained

var/owner = I.get_loc_mob()
if(ismob(owner) && owner != src)
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 +225,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, offered = FALSE)
if(QDELETED(I))
return FALSE

Expand All @@ -245,7 +249,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, offered=offered))
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, offered=TRUE)
EvilDragonfiend marked this conversation as resolved.
Show resolved Hide resolved