Skip to content

Commit

Permalink
Magazine quickload (#493)
Browse files Browse the repository at this point in the history
* Magazine quickload

* Tiny fix & tweak
  • Loading branch information
EgorDinamit authored Dec 29, 2023
1 parent b0f8d28 commit 68767b0
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion code/modules/projectiles/ammunition.dm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,38 @@
SetName("[name] ([english_list(labels, and_text = ", ")])")
update_icon()

/obj/item/ammo_magazine/afterattack(atom/target, mob/living/user, proximity_flag)
if(!proximity_flag || (!istype(target, /turf) && !istype(target, /obj/item/ammo_casing)))
return ..()

var/turf/T = istype(target, /turf) ? target : get_turf(target)
if(istype(target, /turf))
if(!locate(/obj/item/ammo_casing) in T)
return ..()

var/curr_ammo = length(stored_ammo)
if(curr_ammo >= max_ammo)
to_chat(user, "<span class='warning'>[src] is full!</span>")
return

to_chat(user, SPAN_NOTICE("You begin inserting casings into \the [src]..."))
if(!do_after(user, (max_ammo - curr_ammo) * 2, src))
return

for(var/obj/item/ammo_casing/C in T)
if(stored_ammo.len >= max_ammo)
break
if(C.caliber != caliber)
continue
stored_ammo.Add(C)
C.forceMove(src)

if(length(stored_ammo) - curr_ammo)
to_chat(user, SPAN_NOTICE("You insert [length(stored_ammo) - curr_ammo] casings into \the [src]."))
update_icon()
else
to_chat(user, SPAN_WARNING("You fail to collect any casings!"))

/obj/item/ammo_magazine/attackby(obj/item/W as obj, mob/user as mob)
if(istype(W, /obj/item/ammo_casing))
var/obj/item/ammo_casing/C = W
Expand All @@ -155,14 +187,20 @@
if(!stored_ammo.len)
to_chat(user, "<span class='notice'>[src] is already empty!</span>")
return
if(!do_after(user, 10, src))
return
to_chat(user, "<span class='notice'>You empty [src].</span>")
var/curr_sounds = 0
var/max_sounds = clamp(round(length(stored_ammo) * 0.2), 1, 10)
for(var/obj/item/ammo_casing/C in stored_ammo)
C.forceMove(user.loc)
C.set_dir(pick(GLOB.alldirs))
if(LAZYLEN(C.fall_sounds) && curr_sounds < max_sounds)
playsound(user.loc, pick(C.fall_sounds), 20, TRUE)
curr_sounds += 1
stored_ammo.Cut()
update_icon()


/obj/item/ammo_magazine/attack_hand(mob/user)
if(user.get_inactive_hand() == src)
if(!stored_ammo.len)
Expand Down

0 comments on commit 68767b0

Please sign in to comment.