up to upstream-merge-27868
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
desc = "A basic energy-based gun."
|
||||
icon = 'icons/obj/guns/energy.dmi'
|
||||
|
||||
var/obj/item/weapon/stock_parts/cell/power_supply //What type of power cell this uses
|
||||
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/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
|
||||
@@ -20,19 +20,22 @@
|
||||
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)
|
||||
power_supply.use(round(power_supply.charge / 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()
|
||||
. = ..()
|
||||
|
||||
/obj/item/weapon/gun/energy/Initialize()
|
||||
. = ..()
|
||||
if(cell_type)
|
||||
power_supply = new cell_type(src)
|
||||
cell = new cell_type(src)
|
||||
else
|
||||
power_supply = new(src)
|
||||
power_supply.give(power_supply.maxcharge)
|
||||
cell = new(src)
|
||||
cell.give(cell.maxcharge)
|
||||
update_ammo_types()
|
||||
recharge_newshot(1)
|
||||
if(selfcharge)
|
||||
@@ -50,9 +53,7 @@
|
||||
fire_delay = shot.delay
|
||||
|
||||
/obj/item/weapon/gun/energy/Destroy()
|
||||
if(power_supply)
|
||||
qdel(power_supply)
|
||||
power_supply = null
|
||||
QDEL_NULL(cell)
|
||||
STOP_PROCESSING(SSobj, src)
|
||||
return ..()
|
||||
|
||||
@@ -62,9 +63,9 @@
|
||||
if(charge_tick < charge_delay)
|
||||
return
|
||||
charge_tick = 0
|
||||
if(!power_supply)
|
||||
if(!cell)
|
||||
return
|
||||
power_supply.give(100)
|
||||
cell.give(100)
|
||||
if(!chambered) //if empty chamber we try to charge a new shot
|
||||
recharge_newshot(1)
|
||||
update_icon()
|
||||
@@ -76,10 +77,10 @@
|
||||
|
||||
/obj/item/weapon/gun/energy/can_shoot()
|
||||
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
|
||||
return power_supply.charge >= shot.e_cost
|
||||
return cell.charge >= shot.e_cost
|
||||
|
||||
/obj/item/weapon/gun/energy/recharge_newshot(no_cyborg_drain)
|
||||
if (!ammo_type || !power_supply)
|
||||
if (!ammo_type || !cell)
|
||||
return
|
||||
if(use_cyborg_cell && !no_cyborg_drain)
|
||||
if(iscyborg(loc))
|
||||
@@ -87,10 +88,10 @@
|
||||
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...
|
||||
power_supply.give(shot.e_cost) //... to recharge the shot
|
||||
cell.give(shot.e_cost) //... to recharge the shot
|
||||
if(!chambered)
|
||||
var/obj/item/ammo_casing/energy/AC = ammo_type[select]
|
||||
if(power_supply.charge >= AC.e_cost) //if there's enough power in the power_supply cell...
|
||||
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()
|
||||
@@ -98,7 +99,7 @@
|
||||
/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
|
||||
power_supply.use(shot.e_cost)//... drain the power_supply cell
|
||||
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
|
||||
|
||||
@@ -117,10 +118,10 @@
|
||||
return
|
||||
|
||||
/obj/item/weapon/gun/energy/update_icon()
|
||||
..()
|
||||
if(!automatic_charge_overlays)
|
||||
return
|
||||
var/ratio = Ceiling((power_supply.charge / power_supply.maxcharge) * charge_sections)
|
||||
..()
|
||||
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
|
||||
@@ -131,16 +132,16 @@
|
||||
iconState += "_[shot.select_name]"
|
||||
if(itemState)
|
||||
itemState += "[shot.select_name]"
|
||||
if(power_supply.charge < shot.e_cost)
|
||||
if(cell.charge < shot.e_cost)
|
||||
add_overlay("[icon_state]_empty")
|
||||
else
|
||||
if(!shaded_charge)
|
||||
var/mutable_appearance/charge_overlay = mutable_appearance(icon, iconState)
|
||||
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)
|
||||
charge_overlay.pixel_x = ammo_x_offset * (i - 1)
|
||||
add_overlay(charge_overlay)
|
||||
else
|
||||
add_overlay("[icon_state]_charge[ratio]")
|
||||
add_overlay("[icon_state]_charge[ratio]")
|
||||
if(itemState)
|
||||
itemState += "[ratio]"
|
||||
item_state = itemState
|
||||
@@ -156,7 +157,7 @@
|
||||
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]
|
||||
power_supply.use(shot.e_cost)
|
||||
cell.use(shot.e_cost)
|
||||
update_icon()
|
||||
return(FIRELOSS)
|
||||
else
|
||||
@@ -191,17 +192,17 @@
|
||||
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)
|
||||
power_supply.use(E.e_cost)
|
||||
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)
|
||||
power_supply.use(E.e_cost)
|
||||
cell.use(E.e_cost)
|
||||
qdel(A)
|
||||
. = ""
|
||||
else
|
||||
playsound(user, E.fire_sound, 50, 1)
|
||||
playsound(user, BB.hitsound, 50, 1)
|
||||
power_supply.use(E.e_cost)
|
||||
cell.use(E.e_cost)
|
||||
. = "<span class='danger'>[user] casually lights their [A.name] with [src]. Damn.</span>"
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
empty()
|
||||
|
||||
/obj/item/weapon/gun/energy/kinetic_accelerator/proc/empty()
|
||||
power_supply.use(500)
|
||||
cell.use(500)
|
||||
update_icon()
|
||||
|
||||
/obj/item/weapon/gun/energy/kinetic_accelerator/proc/attempt_reload(recharge_time)
|
||||
@@ -125,7 +125,7 @@
|
||||
return
|
||||
|
||||
/obj/item/weapon/gun/energy/kinetic_accelerator/proc/reload()
|
||||
power_supply.give(500)
|
||||
cell.give(500)
|
||||
recharge_newshot(1)
|
||||
if(!suppressed)
|
||||
playsound(src.loc, 'sound/weapons/kenetic_reload.ogg', 60, 1)
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
/obj/item/weapon/gun/energy/decloner/update_icon()
|
||||
..()
|
||||
var/obj/item/ammo_casing/energy/shot = ammo_type[select]
|
||||
if(power_supply.charge > shot.e_cost)
|
||||
if(cell.charge > shot.e_cost)
|
||||
add_overlay("decloner_spin")
|
||||
|
||||
/obj/item/weapon/gun/energy/floragun
|
||||
@@ -137,19 +137,19 @@
|
||||
|
||||
/obj/item/weapon/gun/energy/plasmacutter/examine(mob/user)
|
||||
..()
|
||||
if(power_supply)
|
||||
to_chat(user, "<span class='notice'>[src] is [round(power_supply.percent())]% charged.</span>")
|
||||
if(cell)
|
||||
to_chat(user, "<span class='notice'>[src] is [round(cell.percent())]% charged.</span>")
|
||||
|
||||
/obj/item/weapon/gun/energy/plasmacutter/attackby(obj/item/A, mob/user)
|
||||
if(istype(A, /obj/item/stack/sheet/mineral/plasma))
|
||||
var/obj/item/stack/sheet/S = A
|
||||
S.use(1)
|
||||
power_supply.give(1000)
|
||||
cell.give(1000)
|
||||
recharge_newshot(1)
|
||||
to_chat(user, "<span class='notice'>You insert [A] in [src], recharging it.</span>")
|
||||
else if(istype(A, /obj/item/weapon/ore/plasma))
|
||||
qdel(A)
|
||||
power_supply.give(500)
|
||||
cell.give(500)
|
||||
recharge_newshot(1)
|
||||
to_chat(user, "<span class='notice'>You insert [A] in [src], recharging it.</span>")
|
||||
else
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
return "chest"
|
||||
|
||||
/obj/item/projectile/proc/prehit(atom/target)
|
||||
return
|
||||
return TRUE
|
||||
|
||||
/obj/item/projectile/proc/on_hit(atom/target, blocked = 0)
|
||||
var/turf/target_loca = get_turf(target)
|
||||
@@ -142,7 +142,7 @@
|
||||
if(firer && !ricochets)
|
||||
if(A == firer || (A == firer.loc && istype(A, /obj/mecha))) //cannot shoot yourself or your mech
|
||||
loc = A.loc
|
||||
return 0
|
||||
return FALSE
|
||||
|
||||
var/distance = get_dist(get_turf(A), starting) // Get the distance between the turf shot from and the mob we hit and use that for the calculations.
|
||||
def_zone = ran_zone(def_zone, max(100-(7*distance), 5)) //Lower accurancy/longer range tradeoff. 7 is a balanced number to use.
|
||||
@@ -155,13 +155,14 @@
|
||||
|
||||
var/turf/target_turf = get_turf(A)
|
||||
|
||||
prehit(A)
|
||||
if(!prehit(A))
|
||||
return FALSE
|
||||
var/permutation = A.bullet_act(src, def_zone) // searches for return value, could be deleted after run so check A isn't null
|
||||
if(permutation == -1 || forcedodge)// the bullet passes through a dense object!
|
||||
loc = target_turf
|
||||
if(A)
|
||||
permutated.Add(A)
|
||||
return 0
|
||||
return FALSE
|
||||
else
|
||||
if(A && A.density && !ismob(A) && !(A.flags & ON_BORDER)) //if we hit a dense non-border obj or dense turf then we also hit one of the mobs on that tile.
|
||||
var/list/mobs_list = list()
|
||||
@@ -169,9 +170,11 @@
|
||||
mobs_list += L
|
||||
if(mobs_list.len)
|
||||
var/mob/living/picked_mob = pick(mobs_list)
|
||||
prehit(picked_mob)
|
||||
if(!prehit(picked_mob))
|
||||
return FALSE
|
||||
picked_mob.bullet_act(src, def_zone)
|
||||
qdel(src)
|
||||
return TRUE
|
||||
|
||||
/obj/item/projectile/proc/check_ricochet()
|
||||
if(prob(ricochet_chance))
|
||||
@@ -277,46 +280,53 @@
|
||||
Range()
|
||||
sleep(config.run_speed * 0.9)
|
||||
|
||||
|
||||
/obj/item/projectile/proc/preparePixelProjectile(atom/target, var/turf/targloc, mob/living/user, params, spread)
|
||||
var/turf/curloc = get_turf(user)
|
||||
src.loc = get_turf(user)
|
||||
src.starting = get_turf(user)
|
||||
src.current = curloc
|
||||
src.yo = targloc.y - curloc.y
|
||||
src.xo = targloc.x - curloc.x
|
||||
forceMove(get_turf(user))
|
||||
starting = get_turf(user)
|
||||
current = curloc
|
||||
yo = targloc.y - curloc.y
|
||||
xo = targloc.x - curloc.x
|
||||
|
||||
if(params)
|
||||
var/list/mouse_control = params2list(params)
|
||||
if(mouse_control["icon-x"])
|
||||
src.p_x = text2num(mouse_control["icon-x"])
|
||||
if(mouse_control["icon-y"])
|
||||
src.p_y = text2num(mouse_control["icon-y"])
|
||||
if(mouse_control["screen-loc"])
|
||||
//Split screen-loc up into X+Pixel_X and Y+Pixel_Y
|
||||
var/list/screen_loc_params = splittext(mouse_control["screen-loc"], ",")
|
||||
var/list/calculated = calculate_projectile_angle_and_pixel_offsets(user, params)
|
||||
Angle = calculated[1]
|
||||
p_x = calculated[2]
|
||||
p_y = calculated[3]
|
||||
|
||||
//Split X+Pixel_X up into list(X, Pixel_X)
|
||||
var/list/screen_loc_X = splittext(screen_loc_params[1],":")
|
||||
|
||||
//Split Y+Pixel_Y up into list(Y, Pixel_Y)
|
||||
var/list/screen_loc_Y = splittext(screen_loc_params[2],":")
|
||||
// to_chat(world, "X: [screen_loc_X[1]] PixelX: [screen_loc_X[2]] / Y: [screen_loc_Y[1]] PixelY: [screen_loc_Y[2]]")
|
||||
var/x = text2num(screen_loc_X[1]) * 32 + text2num(screen_loc_X[2]) - 32
|
||||
var/y = text2num(screen_loc_Y[1]) * 32 + text2num(screen_loc_Y[2]) - 32
|
||||
|
||||
//Calculate the "resolution" of screen based on client's view and world's icon size. This will work if the user can view more tiles than average.
|
||||
var/screenview = (user.client.view * 2 + 1) * world.icon_size //Refer to http://www.byond.com/docs/ref/info.html#/client/var/view for mad maths
|
||||
|
||||
var/ox = round(screenview/2) //"origin" x
|
||||
var/oy = round(screenview/2) //"origin" y
|
||||
// to_chat(world, "Pixel position: [x] [y]")
|
||||
var/angle = Atan2(y - oy, x - ox)
|
||||
// to_chat(world, "Angle: [angle]")
|
||||
src.Angle = angle
|
||||
if(spread)
|
||||
src.Angle += spread
|
||||
|
||||
/proc/calculate_projectile_angle_and_pixel_offsets(mob/user, params)
|
||||
var/list/mouse_control = params2list(params)
|
||||
var/p_x = 0
|
||||
var/p_y = 0
|
||||
var/angle = 0
|
||||
if(mouse_control["icon-x"])
|
||||
p_x = text2num(mouse_control["icon-x"])
|
||||
if(mouse_control["icon-y"])
|
||||
p_y = text2num(mouse_control["icon-y"])
|
||||
if(mouse_control["screen-loc"])
|
||||
//Split screen-loc up into X+Pixel_X and Y+Pixel_Y
|
||||
var/list/screen_loc_params = splittext(mouse_control["screen-loc"], ",")
|
||||
|
||||
//Split X+Pixel_X up into list(X, Pixel_X)
|
||||
var/list/screen_loc_X = splittext(screen_loc_params[1],":")
|
||||
|
||||
//Split Y+Pixel_Y up into list(Y, Pixel_Y)
|
||||
var/list/screen_loc_Y = splittext(screen_loc_params[2],":")
|
||||
// to_chat(world, "X: [screen_loc_X[1]] PixelX: [screen_loc_X[2]] / Y: [screen_loc_Y[1]] PixelY: [screen_loc_Y[2]]")
|
||||
var/x = text2num(screen_loc_X[1]) * 32 + text2num(screen_loc_X[2]) - 32
|
||||
var/y = text2num(screen_loc_Y[1]) * 32 + text2num(screen_loc_Y[2]) - 32
|
||||
|
||||
//Calculate the "resolution" of screen based on client's view and world's icon size. This will work if the user can view more tiles than average.
|
||||
var/screenview = (user.client.view * 2 + 1) * world.icon_size //Refer to http://www.byond.com/docs/ref/info.html#/client/var/view for mad maths
|
||||
|
||||
var/ox = round(screenview/2) - user.client.pixel_x //"origin" x
|
||||
var/oy = round(screenview/2) - user.client.pixel_y //"origin" y
|
||||
// to_chat(world, "Pixel position: [x] [y]")
|
||||
angle = Atan2(y - oy, x - ox)
|
||||
// to_chat(world, "Angle: [angle]")
|
||||
return list(angle, p_x, p_y)
|
||||
|
||||
/obj/item/projectile/Crossed(atom/movable/AM) //A mob moving on a tile with a projectile is hit by it.
|
||||
..()
|
||||
|
||||
Reference in New Issue
Block a user