Skip to content

Commit

Permalink
should make it way better
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien committed Aug 6, 2023
1 parent ca8a469 commit 8aebcba
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
4 changes: 1 addition & 3 deletions code/game/objects/items/storage/belt.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1476,9 +1476,7 @@
/obj/item/storage/belt/gun/flaregun/attackby(obj/item/W, mob/user)
if(istype(W, /obj/item/storage/box/m94))
var/obj/item/storage/box/m94/M = W
storage_slots = 16
dump_into(M,user)
storage_slots = 17
dump_ammo_into_belt_holster(M,user)
else
return ..()

Expand Down
43 changes: 42 additions & 1 deletion code/game/objects/items/storage/storage.dm
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
var/list/content_watchers //list of mobs currently seeing the storage's contents
var/storage_flags = STORAGE_FLAGS_DEFAULT
var/has_gamemode_skin = FALSE ///Whether to use map-variant skins.

/// TRUE mean this belt as an holster for a gun. this variable is used for the dump into action.

/obj/item/storage/MouseDrop(obj/over_object as obj)
if(CAN_PICKUP(usr, src))
Expand Down Expand Up @@ -697,7 +697,9 @@ W is always an item. stop_warning prevents messaging. user may be null.**/
if(ammo_dumping.flags_magazine & AMMUNITION_HANDFUL_BOX)
var/handfuls = round(ammo_dumping.current_rounds / amount_to_dump, 1) //The number of handfuls, we round up because we still want the last one that isn't full
if(ammo_dumping.current_rounds != 0)

if(contents.len < storage_slots)

to_chat(user, SPAN_NOTICE("You start refilling [src] with [ammo_dumping]."))
if(!do_after(user, 1.5 SECONDS, INTERRUPT_ALL, BUSY_ICON_GENERIC)) return
for(var/i = 1 to handfuls)
Expand All @@ -721,6 +723,45 @@ W is always an item. stop_warning prevents messaging. user may be null.**/
to_chat(user, SPAN_WARNING("[ammo_dumping] is empty."))
return TRUE

/obj/item/storage/proc/dump_ammo_into_belt_holster(obj/item/ammo_magazine/ammo_dumping, mob/user, amount_to_dump = 5) //amount_to_dump should never actually need to be used as default value
if(user.action_busy)
return

if(ammo_dumping.flags_magazine & AMMUNITION_CANNOT_REMOVE_BULLETS)
to_chat(user, SPAN_WARNING("You can't remove ammo from \the [ammo_dumping]!"))
return

if(ammo_dumping.flags_magazine & AMMUNITION_HANDFUL_BOX)
var/handfuls = round(ammo_dumping.current_rounds / amount_to_dump, 1) //The number of handfuls, we round up because we still want the last one that isn't full
if(ammo_dumping.current_rounds != 0)

if(contents.len < (storage_slots - 1))

to_chat(user, SPAN_NOTICE("You start refilling [src] with [ammo_dumping]."))
if(!do_after(user, 1.5 SECONDS, INTERRUPT_ALL, BUSY_ICON_GENERIC)) return
for(var/i = 1 to handfuls)
if(contents.len < (storage_slots - 1))
//Hijacked from /obj/item/ammo_magazine/proc/create_handful because it had to be handled differently
//All this because shell types are instances and not their own objects :)

var/obj/item/ammo_magazine/handful/new_handful = new /obj/item/ammo_magazine/handful
var/transferred_handfuls = min(ammo_dumping.current_rounds, amount_to_dump)
new_handful.generate_handful(ammo_dumping.default_ammo, ammo_dumping.caliber, amount_to_dump, transferred_handfuls, ammo_dumping.gun_type)
ammo_dumping.current_rounds -= transferred_handfuls
handle_item_insertion(new_handful, TRUE,user)
update_icon(-transferred_handfuls)
else
break
playsound(user.loc, "rustle", 15, TRUE, 6)
ammo_dumping.update_icon()
else
to_chat(user, SPAN_WARNING("[src] is full."))
else
to_chat(user, SPAN_WARNING("[ammo_dumping] is empty."))
return TRUE



/obj/item/storage/proc/dump_into(obj/item/storage/M, mob/user)
if(user.action_busy)
return
Expand Down

0 comments on commit 8aebcba

Please sign in to comment.