From 7c85f846eb873385f85119bbfa6a19a6646c6bfa Mon Sep 17 00:00:00 2001 From: Zuhayr Date: Fri, 4 Dec 2015 17:38:58 +1030 Subject: [PATCH] put_in_hands() refactor. --- code/game/objects/items.dm | 3 + .../objects/items/devices/chameleonproj.dm | 2 + code/modules/mob/inventory.dm | 56 +++++-------------- code/modules/mob/living/carbon/human/human.dm | 39 +++++++++++++ .../species/xenomorphs/alien_facehugger.dm | 1 + 5 files changed, 58 insertions(+), 43 deletions(-) diff --git a/code/game/objects/items.dm b/code/game/objects/items.dm index 2a68cb87f7f..fef7336371c 100644 --- a/code/game/objects/items.dm +++ b/code/game/objects/items.dm @@ -242,6 +242,9 @@ // for items that can be placed in multiple slots // note this isn't called during the initial dressing of a player /obj/item/proc/equipped(var/mob/user, var/slot) + layer = 20 + if(user.client) user.client.screen |= src + if(user.pulling == src) user.stop_pulling() return //Defines which slots correspond to which slot flags diff --git a/code/game/objects/items/devices/chameleonproj.dm b/code/game/objects/items/devices/chameleonproj.dm index f7ef8ad5c21..5a97968e93b 100644 --- a/code/game/objects/items/devices/chameleonproj.dm +++ b/code/game/objects/items/devices/chameleonproj.dm @@ -18,9 +18,11 @@ /obj/item/device/chameleon/dropped() disrupt() + ..() /obj/item/device/chameleon/equipped() disrupt() + ..() /obj/item/device/chameleon/attack_self() toggle() diff --git a/code/modules/mob/inventory.dm b/code/modules/mob/inventory.dm index d820e89cf97..8944bc31099 100644 --- a/code/modules/mob/inventory.dm +++ b/code/modules/mob/inventory.dm @@ -103,64 +103,34 @@ var/list/slot_equipment_priority = list( \ //Puts the item into your l_hand if possible and calls all necessary triggers/updates. returns 1 on success. /mob/proc/put_in_l_hand(var/obj/item/W) - if(lying) return 0 - if(!istype(W)) return 0 - if(!l_hand) - W.forceMove(src) //TODO: move to equipped? - l_hand = W - W.layer = 20 //TODO: move to equipped? -// l_hand.screen_loc = ui_lhand - W.equipped(src,slot_l_hand) - if(client) client.screen |= W - if(pulling == W) stop_pulling() - update_inv_l_hand() - return 1 - return 0 + if(lying || !istype(W)) + return 0 + return 1 //Puts the item into your r_hand if possible and calls all necessary triggers/updates. returns 1 on success. /mob/proc/put_in_r_hand(var/obj/item/W) - if(lying) return 0 - if(!istype(W)) return 0 - if(!r_hand) - W.forceMove(src) - r_hand = W - W.layer = 20 -// r_hand.screen_loc = ui_rhand - W.equipped(src,slot_r_hand) - if(client) client.screen |= W - if(pulling == W) stop_pulling() - update_inv_r_hand() - return 1 - return 0 + if(lying || !istype(W)) + return 0 + return 1 //Puts the item into our active hand if possible. returns 1 on success. /mob/proc/put_in_active_hand(var/obj/item/W) - if(hand) return put_in_l_hand(W) - else return put_in_r_hand(W) + return 0 // Moved to human procs because only they need to use hands. //Puts the item into our inactive hand if possible. returns 1 on success. /mob/proc/put_in_inactive_hand(var/obj/item/W) - if(hand) return put_in_r_hand(W) - else return put_in_l_hand(W) + return 0 // As above. //Puts the item our active hand if possible. Failing that it tries our inactive hand. Returns 1 on success. //If both fail it drops it on the floor and returns 0. //This is probably the main one you need to know :) /mob/proc/put_in_hands(var/obj/item/W) - if(!W) return 0 - if(put_in_active_hand(W)) - update_inv_l_hand() - update_inv_r_hand() - return 1 - else if(put_in_inactive_hand(W)) - update_inv_l_hand() - update_inv_r_hand() - return 1 - else - W.forceMove(get_turf(src)) - W.layer = initial(W.layer) - W.dropped() + if(!W) return 0 + W.forceMove(get_turf(src)) + W.layer = initial(W.layer) + W.dropped() + return 0 // Removes an item from inventory and places it in the target atom. // If canremove or other conditions need to be checked then use unEquip instead. diff --git a/code/modules/mob/living/carbon/human/human.dm b/code/modules/mob/living/carbon/human/human.dm index 308f2359e1f..5abb81b8dd9 100644 --- a/code/modules/mob/living/carbon/human/human.dm +++ b/code/modules/mob/living/carbon/human/human.dm @@ -1383,3 +1383,42 @@ get_scooped(H) return return ..() + +//Puts the item into our active hand if possible. returns 1 on success. +/mob/living/carbon/human/put_in_active_hand(var/obj/item/W) + return (hand ? put_in_l_hand(W) : put_in_r_hand(W)) + +//Puts the item into our inactive hand if possible. returns 1 on success. +/mob/living/carbon/human/put_in_inactive_hand(var/obj/item/W) + return (hand ? put_in_r_hand(W) : put_in_l_hand(W)) + +/mob/living/carbon/human/put_in_hands(var/obj/item/W) + if(!W) + return 0 + if(put_in_active_hand(W)) + update_inv_l_hand() + update_inv_r_hand() + return 1 + else if(put_in_inactive_hand(W)) + update_inv_l_hand() + update_inv_r_hand() + return 1 + else + return ..() + +/mob/living/carbon/human/put_in_l_hand(var/obj/item/W) + if(!..() || l_hand) + return 0 + W.forceMove(src) + l_hand = W + W.equipped(src,slot_l_hand) + update_inv_l_hand() + return 1 + +/mob/living/carbon/human/put_in_r_hand(var/obj/item/W) + if(!..() || r_hand) + return 0 + W.forceMove(src) + r_hand = W + W.equipped(src,slot_r_hand) + update_inv_r_hand() diff --git a/code/modules/mob/living/carbon/human/species/xenomorphs/alien_facehugger.dm b/code/modules/mob/living/carbon/human/species/xenomorphs/alien_facehugger.dm index d6767fbbc4e..34455a47a11 100644 --- a/code/modules/mob/living/carbon/human/species/xenomorphs/alien_facehugger.dm +++ b/code/modules/mob/living/carbon/human/species/xenomorphs/alien_facehugger.dm @@ -70,6 +70,7 @@ var/const/MAX_ACTIVE_TIME = 400 return /obj/item/clothing/mask/facehugger/equipped(mob/M) + ..() Attach(M) /obj/item/clothing/mask/facehugger/Crossed(atom/target)