Files
S.P.L.U.R.T-Station-13/code/modules/projectiles/guns/energy.dm
2017-06-11 00:04:00 -05:00

209 lines
6.8 KiB
Plaintext

/obj/item/weapon/gun/energy
icon_state = "energy"
name = "energy gun"
desc = "A basic energy-based gun."
icon = 'icons/obj/guns/energy.dmi'
var/obj/item/weapon/stock_parts/cell/cell //What type of power cell this uses
var/cell_type = /obj/item/weapon/stock_parts/cell
var/modifystate = 0
var/list/ammo_type = list(/obj/item/ammo_casing/energy)
var/select = 1 //The state of the select fire switch. Determines from the ammo_type list what kind of shot is fired next.
var/can_charge = 1 //Can it be charged in a recharger?
var/automatic_charge_overlays = TRUE //Do we handle overlays with base update_icon()?
var/charge_sections = 4
ammo_x_offset = 2
var/shaded_charge = 0 //if this gun uses a stateful charge bar for more detail
var/selfcharge = 0
var/charge_tick = 0
var/charge_delay = 4
var/use_cyborg_cell = 0 //whether the gun's cell drains the cyborg user's cell to recharge
/obj/item/weapon/gun/energy/emp_act(severity)
cell.use(round(cell.charge / severity))
chambered = null //we empty the chamber
recharge_newshot() //and try to charge a new shot
update_icon()
/obj/item/weapon/gun/energy/get_cell()
return cell
/obj/item/weapon/gun/energy/Initialize()
. = ..()
if(cell_type)
cell = new cell_type(src)
else
cell = new(src)
cell.give(cell.maxcharge)
update_ammo_types()
recharge_newshot(1)
if(selfcharge)
START_PROCESSING(SSobj, src)
update_icon()
/obj/item/weapon/gun/energy/proc/update_ammo_types()
var/obj/item/ammo_casing/energy/shot
for (var/i = 1, i <= ammo_type.len, i++)
var/shottype = ammo_type[i]
shot = new shottype(src)
ammo_type[i] = shot
shot = ammo_type[select]
fire_sound = shot.fire_sound
fire_delay = shot.delay
/obj/item/weapon/gun/energy/Destroy()
QDEL_NULL(cell)
STOP_PROCESSING(SSobj, src)
return ..()
/obj/item/weapon/gun/energy/process()
if(selfcharge)
charge_tick++
if(charge_tick < charge_delay)
return
charge_tick = 0
if(!cell)
return
cell.give(100)
if(!chambered) //if empty chamber we try to charge a new shot
recharge_newshot(1)
update_icon()
/obj/item/weapon/gun/energy/attack_self(mob/living/user as mob)
if(ammo_type.len > 1)
select_fire(user)
update_icon()
/obj/item/weapon/gun/energy/can_shoot()
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
return cell.charge >= shot.e_cost
/obj/item/weapon/gun/energy/recharge_newshot(no_cyborg_drain)
if (!ammo_type || !cell)
return
if(use_cyborg_cell && !no_cyborg_drain)
if(iscyborg(loc))
var/mob/living/silicon/robot/R = loc
if(R.cell)
var/obj/item/ammo_casing/energy/shot = ammo_type[select] //Necessary to find cost of shot
if(R.cell.use(shot.e_cost)) //Take power from the borg...
cell.give(shot.e_cost) //... to recharge the shot
if(!chambered)
var/obj/item/ammo_casing/energy/AC = ammo_type[select]
if(cell.charge >= AC.e_cost) //if there's enough power in the cell cell...
chambered = AC //...prepare a new shot based on the current ammo type selected
if(!chambered.BB)
chambered.newshot()
/obj/item/weapon/gun/energy/process_chamber()
if(chambered && !chambered.BB) //if BB is null, i.e the shot has been fired...
var/obj/item/ammo_casing/energy/shot = chambered
cell.use(shot.e_cost)//... drain the cell cell
chambered = null //either way, released the prepared shot
recharge_newshot() //try to charge a new shot
/obj/item/weapon/gun/energy/proc/select_fire(mob/living/user)
select++
if (select > ammo_type.len)
select = 1
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
fire_sound = shot.fire_sound
fire_delay = shot.delay
if (shot.select_name)
to_chat(user, "<span class='notice'>[src] is now set to [shot.select_name].</span>")
chambered = null
recharge_newshot(1)
update_icon()
return
/obj/item/weapon/gun/energy/update_icon()
..()
if(!automatic_charge_overlays)
return
var/ratio = Ceiling((cell.charge / cell.maxcharge) * charge_sections)
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
var/iconState = "[icon_state]_charge"
var/itemState = null
if(!initial(item_state))
itemState = icon_state
if (modifystate)
add_overlay("[icon_state]_[shot.select_name]")
iconState += "_[shot.select_name]"
if(itemState)
itemState += "[shot.select_name]"
if(cell.charge < shot.e_cost)
add_overlay("[icon_state]_empty")
else
if(!shaded_charge)
var/mutable_appearance/charge_overlay = mutable_appearance(icon, iconState)
for(var/i = ratio, i >= 1, i--)
charge_overlay.pixel_x = ammo_x_offset * (i - 1)
add_overlay(charge_overlay)
else
add_overlay("[icon_state]_charge[ratio]")
if(itemState)
itemState += "[ratio]"
item_state = itemState
/obj/item/weapon/gun/energy/ui_action_click()
toggle_gunlight()
/obj/item/weapon/gun/energy/suicide_act(mob/user)
if (src.can_shoot())
user.visible_message("<span class='suicide'>[user] is putting the barrel of [src] in [user.p_their()] mouth. It looks like [user.p_theyre()] trying to commit suicide!</span>")
sleep(25)
if(user.is_holding(src))
user.visible_message("<span class='suicide'>[user] melts [user.p_their()] face off with [src]!</span>")
playsound(loc, fire_sound, 50, 1, -1)
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
cell.use(shot.e_cost)
update_icon()
return(FIRELOSS)
else
user.visible_message("<span class='suicide'>[user] panics and starts choking to death!</span>")
return(OXYLOSS)
else
user.visible_message("<span class='suicide'>[user] is pretending to blow [user.p_their()] brains out with [src]! It looks like [user.p_theyre()] trying to commit suicide!</b></span>")
playsound(loc, 'sound/weapons/empty.ogg', 50, 1, -1)
return (OXYLOSS)
/obj/item/weapon/gun/energy/vv_edit_var(var_name, var_value)
switch(var_name)
if("selfcharge")
if(var_value)
START_PROCESSING(SSobj, src)
else
STOP_PROCESSING(SSobj, src)
. = ..()
/obj/item/weapon/gun/energy/ignition_effect(atom/A, mob/living/user)
if(!can_shoot() || !ammo_type[select])
shoot_with_empty_chamber()
. = ""
else
var/obj/item/ammo_casing/energy/E = ammo_type[select]
var/obj/item/projectile/energy/BB = E.BB
if(!BB)
. = ""
else if(BB.nodamage || !BB.damage || BB.damage_type == STAMINA)
user.visible_message("<span class='danger'>[user] tries to light their [A.name] with [src], but it doesn't do anything. Dumbass.</span>")
playsound(user, E.fire_sound, 50, 1)
playsound(user, BB.hitsound, 50, 1)
cell.use(E.e_cost)
. = ""
else if(BB.damage_type != BURN)
user.visible_message("<span class='danger'>[user] tries to light their [A.name] with [src], but only succeeds in utterly destroying it. Dumbass.</span>")
playsound(user, E.fire_sound, 50, 1)
playsound(user, BB.hitsound, 50, 1)
cell.use(E.e_cost)
qdel(A)
. = ""
else
playsound(user, E.fire_sound, 50, 1)
playsound(user, BB.hitsound, 50, 1)
cell.use(E.e_cost)
. = "<span class='danger'>[user] casually lights their [A.name] with [src]. Damn.</span>"