Skip to content

Commit

Permalink
Merge pull request #3314 from OverDriveZ/smart-inventory-slot-unsheat…
Browse files Browse the repository at this point in the history
…hing

Smart inventory slot unsheathing [ready to merge]
  • Loading branch information
Superlagg authored Oct 10, 2023
2 parents 95be20b + 675c006 commit 626b538
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 7 deletions.
5 changes: 1 addition & 4 deletions code/modules/keybindings/keybind/human.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
else if(isanimal(user.mob))
var/mob/living/simple_animal/SA = user.mob
SA.quick_equip()


/*
/datum/keybinding/human/quick_equipbelt
hotkey_keys = list("ShiftE")
name = "quick_equipbelt"
Expand All @@ -39,11 +37,10 @@
/datum/keybinding/human/bag_equip
hotkey_keys = list("ShiftB")
name = "bag_equip"
full_name = "Bag equip"
full_name = "Quick equip bag"
description = "Put held thing in backpack or take out most recent thing from backpack"

/datum/keybinding/human/bag_equip/down(client/user)
var/mob/living/carbon/human/H = user.mob
H.smart_equipbag()
return TRUE
*/
72 changes: 70 additions & 2 deletions code/modules/mob/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -448,15 +448,83 @@
to_chat(M, span_warning("You are unable to equip that!"))
return FALSE


//-->
// Stupidly complicated smart equip/unequip, what is this supposed to do:
// If the user is empty handed and triggers this function, then unholster an item with priority and with exceptions
// in the following order:
// 1-Armor slot;
// 2-Belt slot;
// 3-Holster contents, return ONLY firearms, all other items will be ignored;
// 4-Boot contents.

// There's one more twist to this, for example, if the user had previously unsheathed a revolver from a shoulder holster,
// we clearly want the revolver to be re-sheathed in the previous location.
// If anything is broken, or not working properly, contact me or fix it -leonzrygin
//<--
/mob/verb/quick_equip()
set name = "quick-equip"
set hidden = 1

if(incapacitated())
return

var/obj/item/storage
var/obj/item/I = get_active_held_item()
if (I)

//obj/item/melee/onehanded

if(I) //are we holding something in our hands?
storage = get_item_by_slot(SLOT_S_STORE)
if(storage) //if it's empty, put the revolver there (if I'm carrying a pouch there for example)
if(istype(I, /obj/item/gun/ballistic/revolver) || istype(I, /obj/item/gun/ballistic/automatic/pistol))
storage = get_item_by_slot(SLOT_NECK)
if(storage)
if(SEND_SIGNAL(storage, COMSIG_CONTAINS_STORAGE))
if(SEND_SIGNAL(storage, COMSIG_TRY_STORAGE_INSERT, I, src))
return

storage = get_item_by_slot(SLOT_SHOES)
if(istype(I, /obj/item/melee/onehanded/knife))
if(storage)
if(SEND_SIGNAL(storage, COMSIG_CONTAINS_STORAGE))
if(SEND_SIGNAL(storage, COMSIG_TRY_STORAGE_INSERT, I, src))
return
I.equip_to_best_slot(src)

else //Are we empty handed?
storage = get_item_by_slot(SLOT_S_STORE)
if(storage) //Are we carrying something in this storage slot?
if(!istype(storage, /obj/item/flashlight)) //this is my personal preference, basically it ignores returning flashlights on your hands, why? because it's silly otherwise!
if(!SEND_SIGNAL(storage, COMSIG_CONTAINS_STORAGE)) //Is this NOT a storage item? (we don't want to return a pouch or something in our hands, only items that have no storage)
storage.attack_hand(src) //Slap my hands with the contents of this storage, which is allegedly only one item.
return
storage = get_item_by_slot(SLOT_BELT)
if(storage) //We basically repeat the same checks but for belts
if(!istype(storage, /obj/item/flashlight)) //this is my personal preference, basically it ignores returning flashlights on your hands, why? because it's silly otherwise!
if(!SEND_SIGNAL(storage, COMSIG_CONTAINS_STORAGE))
storage.attack_hand(src)
return
storage = get_item_by_slot(SLOT_NECK) //Are we wearing a holster? If yes, we want to prioritize the unholstering of the gun.
if(storage) //Are we carrying something in this storage slot?
if(SEND_SIGNAL(storage, COMSIG_CONTAINS_STORAGE)) //Is this a storage item?
if(storage.contents.len) //there's something to take out.
var/obj/item/gun/firearm
for(var/obj/item/gun/F in storage.contents) //First thing, we want to obviously prioritize the unholstering of the gun.
firearm = F
break
if(firearm && !firearm.on_found(src))
firearm.allow_quickdraw = TRUE
firearm.attack_hand(src) //Slap my hands with the contents of this storage, which is allegedly only one item.
return
storage = get_item_by_slot(SLOT_SHOES) //Shoes are a little different, we don't want to return the item itself, but rather its contents.
if(storage) //Are we carrying something in this storage slot?
if(SEND_SIGNAL(storage, COMSIG_CONTAINS_STORAGE)) //Is this a storage item?
if(storage.contents.len) //there's something to take out.
I = storage.contents[storage.contents.len] //take the item out
if(I && !I.on_found(src))
I.attack_hand(src) //Slap my hands with the contents of this storage, which is allegedly only one item.
return

//used in code for items usable by both carbon and drones, this gives the proper back slot for each mob.(defibrillator, backpack watertank, ...)
/mob/proc/getBackSlot()
return SLOT_BACK
Expand Down
2 changes: 1 addition & 1 deletion code/modules/mob/living/carbon/human/inventory.dm
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
stored.attack_hand(src) // take out thing from backpack
return

/mob/living/carbon/human/proc/smart_equipbelt() // put held thing in belt or take most recent item out of belt
/mob/living/carbon/human/proc/smart_equipbelt() // put held thing in belt or take most recent item out of belt //
if(incapacitated())
return
var/obj/item/thing = get_active_held_item()
Expand Down
5 changes: 5 additions & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ ATTACHMENTS
var/use_casing_sounds
/// Is one of Kelp's wands?
var/is_kelpwand = FALSE
/// Allow quickdraw (delay to draw the gun is 0s)
var/allow_quickdraw = FALSE
/// Cooldown between times the gun will tell you it shot, 0.5 seconds cus its not super duper important
COOLDOWN_DECLARE(shoot_message_antispam)

Expand Down Expand Up @@ -876,6 +878,9 @@ ATTACHMENTS
/obj/item/gun/proc/weapondraw(obj/item/gun/G, mob/living/user) // Eventually, this will be /obj/item/weapon and guns will be /obj/item/weapon/gun/etc. SOON.tm
user.visible_message(span_danger("[user] grabs \a [G]!")) // probably could code in differences as to where you're picking it up from and so forth. later.
var/time_till_gun_is_ready = max(draw_time,(user.AmountWeaponDrawDelay()))
if(allow_quickdraw)
allow_quickdraw = FALSE
time_till_gun_is_ready = 0
user.SetWeaponDrawDelay(time_till_gun_is_ready)
if(safety && user.a_intent == INTENT_HARM)
toggle_safety(user, ignore_held = TRUE)
Expand Down

0 comments on commit 626b538

Please sign in to comment.