From c3c81454f5f1b29a60e91168cf22f3045cac6a55 Mon Sep 17 00:00:00 2001 From: Couls Date: Fri, 8 May 2020 22:41:25 -0400 Subject: [PATCH] Give a little (#50710) Co-Authored-By: Jordan Brown --- code/_onclick/hud/alert.dm | 33 +++++++++++++++ code/datums/keybinding/carbon.dm | 11 +++++ code/modules/mob/living/carbon/inventory.dm | 46 +++++++++++++++++++++ code/modules/mob/mob.dm | 1 + 4 files changed, 91 insertions(+) diff --git a/code/_onclick/hud/alert.dm b/code/_onclick/hud/alert.dm index 357d3c45318..ef1a1a7d2c5 100644 --- a/code/_onclick/hud/alert.dm +++ b/code/_onclick/hud/alert.dm @@ -278,6 +278,39 @@ or shoot a gun to move around via Newton's 3rd Law of Motion." if(L.mobility_flags & MOBILITY_MOVE) return L.resist_fire() //I just want to start a flame in your hearrrrrrtttttt. +/obj/screen/alert/give // information set when the give alert is made + icon_state = "default" + var/mob/living/carbon/giver + var/obj/item/receiving + +/** + * Handles assigning most of the variables for the alert that pops up when an item is offered + * + * Handles setting the name, description and icon of the alert and tracking the person giving + * and the item being offered, also registers a signal that removes the alert from anyone who moves away from the giver + * Arguments: + * * taker - The person receiving the alert + * * giver - The person giving the alert and item + * * receiving - The item being given by the giver + */ +/obj/screen/alert/give/proc/setup(mob/living/carbon/taker, mob/living/carbon/giver, obj/item/receiving) + name = "[giver] is offering [receiving]" + desc = "[giver] is offering [receiving]. Click this alert to take it." + icon_state = "template" + cut_overlays() + add_overlay(receiving) + src.receiving = receiving + src.giver = giver + RegisterSignal(taker, COMSIG_MOVABLE_MOVED, .proc/removeAlert) + +/obj/screen/alert/give/proc/removeAlert() + to_chat(owner, "You moved out of range of [giver]!") + owner.clear_alert("[giver]") + +/obj/screen/alert/give/Click(location, control, params) + . = ..() + var/mob/living/carbon/C = owner + C.take(giver, receiving) //ALIENS diff --git a/code/datums/keybinding/carbon.dm b/code/datums/keybinding/carbon.dm index abf84c9aadf..2d9909760dc 100644 --- a/code/datums/keybinding/carbon.dm +++ b/code/datums/keybinding/carbon.dm @@ -64,3 +64,14 @@ /datum/keybinding/carbon/select_harm_intent/down(client/user) user.mob?.a_intent_change(INTENT_HARM) return TRUE + +/datum/keybinding/carbon/give + hotkey_keys = list("G") + name = "Give_Item" + full_name = "Give item" + description = "Give the item you're currently holding" + +/datum/keybinding/carbon/give/down(client/user) + var/mob/living/carbon/C = user.mob + C.give() + return TRUE diff --git a/code/modules/mob/living/carbon/inventory.dm b/code/modules/mob/living/carbon/inventory.dm index 394522800b0..f52ab5dde1b 100644 --- a/code/modules/mob/living/carbon/inventory.dm +++ b/code/modules/mob/living/carbon/inventory.dm @@ -155,3 +155,49 @@ /mob/living/carbon/proc/get_holding_bodypart_of_item(obj/item/I) var/index = get_held_index_of_item(I) return index && hand_bodyparts[index] + +/** + * Proc called when giving an item to another player + * + * This handles creating an alert and adding an overlay to it + */ +/mob/living/carbon/proc/give() + var/obj/item/receiving = get_active_held_item() + if(!receiving) + to_chat(src, "You're not holding anything to give!") + return + visible_message("[src] is offering [receiving]", \ + "You offer [receiving]", null, 2) + for(var/mob/living/carbon/C in orange(1, src)) + if(!CanReach(C)) + return + var/obj/screen/alert/give/G = C.throw_alert("[src]", /obj/screen/alert/give) + if(!G) + return + G.setup(C, src, receiving) + +/** + * Proc called when the player clicks the give alert + * + * Handles checking if the player taking the item has open slots and is in range of the giver + * Also deals with the actual transferring of the item to the players hands + * Arguments: + * * giver - The person giving the original item + * * I - The item being given by the giver + */ +/mob/living/carbon/proc/take(mob/living/carbon/giver, obj/item/I) + clear_alert("[giver]") + if(get_dist(src, giver) > 1) + to_chat(src, "[giver] is out of range! ") + return + if(!I || giver.get_active_held_item() != I) + to_chat(src, "[giver] is no longer holding the item they were offering! ") + return + if(!get_empty_held_indexes()) + to_chat(src, "You have no empty hands!") + return + if(!giver.temporarilyRemoveItemFromInventory(I)) + visible_message("[src] tries to hand over [I] but it's stuck to them....", \ + " You make a fool of yourself trying to give away an item stuck to your hands") + return + put_in_hands(I) diff --git a/code/modules/mob/mob.dm b/code/modules/mob/mob.dm index 1446d3f3cb2..d43e0ca34e9 100644 --- a/code/modules/mob/mob.dm +++ b/code/modules/mob/mob.dm @@ -397,6 +397,7 @@ /mob/proc/show_inv(mob/user) return + /** * Examine a mob *