Files
Yogstation/code/modules/projectiles/ammunition/_ammunition.dm
2023-10-31 13:08:02 -05:00

90 lines
3.6 KiB
Plaintext

/obj/item/ammo_casing
name = "bullet casing"
desc = "A bullet casing."
icon = 'icons/obj/ammo.dmi'
icon_state = "s-casing"
flags_1 = CONDUCT_1
slot_flags = ITEM_SLOT_BELT
throwforce = 0
w_class = WEIGHT_CLASS_TINY
materials = list(/datum/material/iron = 500)
/// Bitflags for casings, check code\__DEFINES\combat.dm for a list of available flags and what they do
var/casing_flags = NONE
var/fire_sound = null //What sound should play when this ammo is fired
var/caliber = null //Which kind of guns it can be loaded into
var/projectile_type = null //The bullet type to create when New() is called
var/obj/projectile/BB = null //The loaded bullet
var/pellets = 1 //Pellets for spreadshot
var/variance = 0 //Variance for inaccuracy fundamental to the casing
var/randomspread = 0 //Randomspread for automatics
var/delay = 0 //Delay for energy weapons
var/click_cooldown_override = 0 //Override this to make your gun have a faster fire rate, in tenths of a second. 4 is the default gun cooldown.
var/firing_effect_type = /obj/effect/temp_visual/dir_setting/firing_effect //the visual effect appearing when the ammo is fired.
var/harmful = TRUE //pacifism check for boolet, set to FALSE if bullet is non-lethal
/obj/item/ammo_casing/spent
name = "spent bullet casing"
BB = null
/obj/item/ammo_casing/Initialize(mapload)
. = ..()
if(projectile_type)
BB = new projectile_type(src)
pixel_x = rand(-10, 10)
pixel_y = rand(-10, 10)
setDir(pick(GLOB.alldirs))
update_appearance(UPDATE_ICON)
/obj/item/ammo_casing/update_icon_state()
. = ..()
icon_state = "[initial(icon_state)][BB && !CHECK_BITFIELD(casing_flags, CASINGFLAG_NO_LIVE_SPRITE) ? "-live" : ""]"
/obj/item/ammo_casing/update_desc(updates=ALL)
. = ..()
desc = "[initial(desc)][!BB && !CHECK_BITFIELD(casing_flags, CASINGFLAG_NO_LIVE_SPRITE) ? " This one is spent." : ""]"
//proc to magically refill a casing with a new projectile
/obj/item/ammo_casing/proc/newshot() //For energy weapons, syringe gun, shotgun shells and wands (!).
if(!BB)
BB = new projectile_type(src, src)
/obj/item/ammo_casing/attackby(obj/item/I, mob/user, params)
if(istype(I, /obj/item/ammo_box))
var/obj/item/ammo_box/box = I
if(isturf(loc))
var/boolets = 0
for(var/obj/item/ammo_casing/bullet in loc)
if (box.stored_ammo.len >= box.max_ammo)
break
if (bullet.BB)
if (box.give_round(bullet, 0))
boolets++
else
continue
if (boolets > 0)
box.update_appearance(UPDATE_ICON)
to_chat(user, span_notice("You collect [boolets] shell\s. [box] now contains [box.stored_ammo.len] shell\s."))
else
to_chat(user, span_warning("You fail to collect anything!"))
else
return ..()
/obj/item/ammo_casing/throw_impact(atom/hit_atom, datum/thrownthing/throwingdatum)
if(!CHECK_BITFIELD(casing_flags, CASINGFLAG_NOT_HEAVY_METAL))
bounce_away(FALSE, NONE)
. = ..()
/obj/item/ammo_casing/proc/bounce_away(still_warm = FALSE, bounce_delay = 3)
update_appearance(UPDATE_ICON)
SpinAnimation(10, 1)
var/matrix/M = matrix(transform)
M.Turn(rand(-170,170))
transform = M
pixel_x = rand(-12, 12)
pixel_y = rand(-12, 12)
var/turf/T = get_turf(src)
if(still_warm && T && T.bullet_sizzle)
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(playsound), src, 'sound/items/welder.ogg', 20, 1), bounce_delay) //If the turf is made of water and the shell casing is still hot, make a sizzling sound when it's ejected.
else if(T && T.bullet_bounce_sound)
addtimer(CALLBACK(GLOBAL_PROC, GLOBAL_PROC_REF(playsound), src, T.bullet_bounce_sound, 60, 1), bounce_delay) //Soft / non-solid turfs that shouldn't make a sound when a shell casing is ejected over them.