Skip to content

Commit 30e1a5d

Browse files
Adds lens functionality to turrets (ParadiseSS13#29039)
1 parent b9c5468 commit 30e1a5d

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

code/game/machinery/portable_turret.dm

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@
7373
var/initial_eprojectile = null
7474
/// What non-lethal mode projectile with the turret start with?
7575
var/initial_projectile = null
76+
/// What lens is fitted to the turret/gun?
77+
var/obj/item/smithed_item/lens/fitted_lens
7678

7779

7880
/obj/machinery/porta_turret/Initialize(mapload)
@@ -381,6 +383,10 @@ GLOBAL_LIST_EMPTY(turret_icons)
381383
if(installation)
382384
var/obj/item/gun/energy/Gun = new installation(loc)
383385
Gun.cell.charge = gun_charge
386+
if(fitted_lens)
387+
Gun.current_lens = fitted_lens
388+
fitted_lens.forceMove(Gun)
389+
Gun.current_lens.on_attached(Gun)
384390
Gun.update_icon()
385391
if(prob(50))
386392
new /obj/item/stack/sheet/metal(loc, rand(1,4))
@@ -390,6 +396,18 @@ GLOBAL_LIST_EMPTY(turret_icons)
390396
to_chat(user, "<span class='notice'>You remove the turret but did not manage to salvage anything.</span>")
391397
qdel(src) // qdel
392398

399+
/obj/machinery/porta_turret/screwdriver_act(mob/living/user, obj/item/I)
400+
if(user.a_intent != INTENT_HELP)
401+
return FALSE
402+
403+
if(!fitted_lens)
404+
to_chat(user, "<span class='notice'>[src] has no attached lenses.</span>")
405+
return
406+
to_chat(user, "<span class='notice'>You remove the lens from [src]</span>")
407+
user.put_in_hands(fitted_lens)
408+
fitted_lens = null
409+
return TRUE
410+
393411
/obj/machinery/porta_turret/item_interaction(mob/living/user, obj/item/used, list/modifiers)
394412
if((stat & BROKEN) && !syndicate)
395413
return ITEM_INTERACT_COMPLETE
@@ -406,6 +424,17 @@ GLOBAL_LIST_EMPTY(turret_icons)
406424

407425
return ITEM_INTERACT_COMPLETE
408426

427+
if(istype(used, /obj/item/smithed_item/lens))
428+
if(used.flags & NODROP || !user.drop_item() || !used.forceMove(src))
429+
to_chat(user, "<span class='warning'>[used] is stuck to your hand!</span>")
430+
return ITEM_INTERACT_COMPLETE
431+
var/obj/item/smithed_item/lens/new_lens = used
432+
if(fitted_lens)
433+
to_chat(user, "<span class='notice'>You swap the fitted lens in [src].</span>")
434+
user.put_in_hands(fitted_lens)
435+
fitted_lens = new_lens
436+
return ITEM_INTERACT_COMPLETE
437+
409438
if(user.a_intent == INTENT_HELP)
410439
return ..()
411440

@@ -759,7 +788,7 @@ GLOBAL_LIST_EMPTY(turret_icons)
759788
return
760789

761790
if(!emagged) //if it hasn't been emagged, cooldown before shooting again
762-
if((last_fired + shot_delay > world.time) || !raised)
791+
if((last_fired + (shot_delay / fitted_lens.fire_rate_mult) > world.time) || !raised)
763792
return
764793
last_fired = world.time
765794

@@ -779,9 +808,16 @@ GLOBAL_LIST_EMPTY(turret_icons)
779808
A = new projectile(loc)
780809
playsound(loc, shot_sound, 75, 1)
781810

811+
var/lens_power_mult = 1
812+
if(fitted_lens)
813+
A.damage = A.damage * fitted_lens.damage_mult
814+
A.stamina = A.damage * fitted_lens.damage_mult
815+
A.speed = A.speed / fitted_lens.laser_speed_mult
816+
lens_power_mult = fitted_lens.power_mult
817+
782818
// Lethal/emagged turrets use twice the power due to higher energy beams
783819
// Emagged turrets again use twice as much power due to higher firing rates
784-
use_power(reqpower * (2 * (emagged || lethal)) * (2 * emagged))
820+
use_power(lens_power_mult * (reqpower * (2 * (emagged || lethal)) * (2 * emagged)))
785821

786822
if(istype(A))
787823
A.original = target
@@ -868,6 +904,8 @@ GLOBAL_LIST_EMPTY(turret_icons)
868904
var/finish_name="turret" //the name applied to the product turret
869905
var/installation = null //the gun type installed
870906
var/gun_charge = 0 //the gun charge of the gun type installed
907+
/// The lens attached to the gun used
908+
var/obj/item/smithed_item/lens/gun_lens
871909

872910
/obj/machinery/porta_turret_construct/item_interaction(mob/living/user, obj/item/used, list/modifiers)
873911
//this is a bit unwieldy but self-explanatory
@@ -925,6 +963,7 @@ GLOBAL_LIST_EMPTY(turret_icons)
925963
return ITEM_INTERACT_COMPLETE
926964
installation = used.type //installation becomes used.type
927965
gun_charge = E.cell.charge //the gun's charge is stored in gun_charge
966+
gun_lens = E.current_lens
928967
to_chat(user, "<span class='notice'>You add [used] to the turret.</span>")
929968

930969
if(istype(E, /obj/item/gun/energy/laser/tag/blue))
@@ -1018,6 +1057,8 @@ GLOBAL_LIST_EMPTY(turret_icons)
10181057
Turret.name = finish_name
10191058
Turret.installation = installation
10201059
Turret.gun_charge = gun_charge
1060+
gun_lens.forceMove(Turret)
1061+
Turret.fitted_lens = gun_lens
10211062
Turret.enabled = FALSE
10221063
Turret.setup()
10231064

0 commit comments

Comments
 (0)