-
-
Notifications
You must be signed in to change notification settings - Fork 444
/
Copy pathgun.dm
777 lines (662 loc) · 25.6 KB
/
gun.dm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
#define DUALWIELD_PENALTY_EXTRA_MULTIPLIER 1.4
/obj/item/gun
name = "gun"
desc = "It's a gun. It's pretty terrible, though."
icon = 'icons/obj/guns/projectile.dmi'
icon_state = "detective"
item_state = "gun"
flags_1 = CONDUCT_1
obj_flags = UNIQUE_RENAME | UNIQUE_REDESC
slot_flags = ITEM_SLOT_BELT
materials = list(/datum/material/iron=2000)
w_class = WEIGHT_CLASS_NORMAL
throwforce = 5
throw_speed = 3
throw_range = 5
force = 5
item_flags = NEEDS_PERMIT
attack_verb = list("struck", "hit", "bashed")
cryo_preserve = TRUE
fryable = TRUE
appearance_flags = TILE_BOUND|PIXEL_SCALE|LONG_GLIDE|KEEP_TOGETHER
var/automatic = 0 //can gun use it, 0 is no, anything above 0 is the delay between clicks in ds
var/fire_sound = "gunshot"
var/vary_fire_sound = TRUE
var/fire_sound_volume = 50
var/dry_fire_sound = 'sound/weapons/gun_dry_fire.ogg'
var/obj/item/suppressor/suppressed //whether or not a message is displayed when fired
var/obj/item/enloudener/enloudened //whether or not an additional sound is played
var/can_suppress = FALSE
var/suppressed_sound = 'sound/weapons/gunshot_silenced.ogg'
var/suppressed_volume = 10
var/can_unsuppress = TRUE
var/recoil = 0 //boom boom shake the room
var/clumsy_check = TRUE
var/obj/item/ammo_casing/chambered = null
trigger_guard = TRIGGER_GUARD_NORMAL//trigger guard on the weapon, hulks can't fire them with their big meaty fingers
var/sawn_desc = null //description change if weapon is sawn-off
var/sawn_off = FALSE
var/burst_size = 1 //how large a burst is
var/fire_delay = 0 //rate of fire for burst firing and semi auto
var/firing_burst = 0 //Prevent the weapon from firing again while already firing
var/semicd = 0 //cooldown handler
var/weapon_weight = WEAPON_LIGHT
var/spread = 5 //Spread induced by the gun itself. SEE LINE BELOW.
var/semi_auto_spread = 5 //Equal to the value above by default. The spread that a weapon will have if it is switched to semi-auto from a burst-fire mode.
var/randomspread = 1 //Set to 0 for shotguns. This is used for weapons that don't fire all their bullets at once.
lefthand_file = 'icons/mob/inhands/weapons/guns_lefthand.dmi'
righthand_file = 'icons/mob/inhands/weapons/guns_righthand.dmi'
var/obj/item/firing_pin/pin = /obj/item/firing_pin //standard firing pin for most guns
var/no_pin_required = FALSE //whether the gun can be fired without a pin
var/can_flashlight = FALSE //if a flashlight can be added or removed if it already has one.
var/obj/item/flashlight/seclite/gun_light
var/datum/action/item_action/toggle_gunlight/gunlight_toggle
var/can_bayonet = FALSE //if a bayonet can be added or removed if it already has one.
var/obj/item/kitchen/knife/bayonet
var/knife_x_offset = 0
var/knife_y_offset = 0
var/list/available_attachments = list() // What attachments can this gun have
var/max_attachments = 0 // How many attachments can this gun hold, recommend not going over 5
var/list/current_attachments = list()
var/attachment_flags = 0
var/attachment_actions = list()
var/ammo_x_offset = 0 //used for positioning ammo count overlay on sprite
var/ammo_y_offset = 0
var/flight_x_offset = 0
var/flight_y_offset = 0
//Zooming
var/zoomable = FALSE //whether the gun generates a Zoom action on creation
var/zoomed = FALSE //Zoom toggle
var/zoom_amt = 3 //Distance in TURFs to move the user's screen forward (the "zoom" effect)
var/zoom_out_amt = 0
var/datum/action/toggle_scope_zoom/azoom
var/recent_shoot = null //time of the last shot with the gun. Used to track if firing happened for feedback out of all things
var/list/obj/effect/projectile/tracer/current_tracers
var/gunlight_state = "flight"
/obj/item/gun/Initialize(mapload)
. = ..()
if(pin)
if(no_pin_required)
pin = null
else
pin = new pin(src)
current_tracers = list()
build_zooming()
/obj/item/gun/Destroy()
if(isobj(pin)) //Can still be the initial path, then we skip
QDEL_NULL(pin)
if(gun_light)
QDEL_NULL(gun_light)
if(bayonet)
QDEL_NULL(bayonet)
if(chambered) //Not all guns are chambered (EMP'ed energy guns etc)
QDEL_NULL(chambered)
if(azoom)
QDEL_NULL(azoom)
return ..()
//ALL GUNS ARE NOW STAFF OF THE HONKMOTHER HONK
/obj/item/gun/honk_act()
new /obj/item/gun/magic/staff/honk(src.loc)
qdel(src)
/obj/item/gun/handle_atom_del(atom/A)
if(A == pin)
pin = null
if(A == chambered)
chambered = null
update_appearance()
if(A == bayonet)
clear_bayonet()
if(A == gun_light)
clear_gunlight()
if(A in current_attachments)
var/obj/item/attachment/T = A
T.on_detach(src)
return ..()
/obj/item/gun/CheckParts(list/parts_list)
..()
var/obj/item/gun/G = locate(/obj/item/gun) in contents
if(G)
G.forceMove(loc)
var/pin = G.pin
if(!pin)
visible_message("[G] has no pin to remove.", null, null, 3)
if(pin && G.pin.gun_remove()) //if this returns false the gun and pin are not going to exist
visible_message("[G] can now fit a new pin, but the old one was destroyed in the process.", null, null, 3)
QDEL_NULL(pin)
qdel(src)
/obj/item/gun/examine(mob/user)
. = ..()
if(!no_pin_required)
if(pin)
. += "It has \a [pin] installed."
else
. += "It doesn't have a <b>firing pin</b> installed, and won't fire."
if(gun_light)
. += "It has \a [gun_light] [can_flashlight ? "" : "permanently "]mounted on it."
if(can_flashlight) //if it has a light and this is false, the light is permanent.
. += span_info("[gun_light] looks like it can be <b>unscrewed</b> from [src].")
else if(can_flashlight)
. += "It has a mounting point for a <b>seclite</b>."
if(bayonet)
. += "It has \a [bayonet] [can_bayonet ? "" : "permanently "]affixed to it."
if(can_bayonet) //if it has a bayonet and this is false, the bayonet is permanent.
. += span_info("[bayonet] looks like it can be <b>unscrewed</b> from [src].")
else if(can_bayonet)
. += "It has a <b>bayonet</b> lug on it."
for(var/obj/item/attachment/A in current_attachments)
. += "It has \a [A] affixed to it."
/obj/item/gun/equipped(mob/living/user, slot)
. = ..()
for(var/obj/item/attachment/A in current_attachments)
A.set_user(user)
if(user.is_holding(src))
A.pickup_user(user)
else
A.equip_user(user)
if(zoomed && user.get_active_held_item() != src)
zoom(user, user.dir, FALSE) //we can only stay zoomed in if it's in our hands //yeah and we only unzoom if we're actually zoomed using the gun!!
//called after the gun has successfully fired its chambered ammo.
/obj/item/gun/proc/process_chamber()
return FALSE
//check if there's enough ammo/energy/whatever to shoot one time
//i.e if clicking would make it shoot
/obj/item/gun/proc/can_shoot()
return TRUE
/obj/item/gun/proc/shoot_with_empty_chamber(mob/living/user as mob|obj)
to_chat(user, span_danger("*click*"))
playsound(src, dry_fire_sound, 30, TRUE)
/obj/item/gun/proc/shoot_live_shot(mob/living/user, pointblank = 0, atom/pbtarget = null, message = 1)
if(recoil > 0)
shake_camera(user, recoil + 1, recoil)
if(suppressed)
playsound(user, suppressed_sound, suppressed_volume, vary_fire_sound)
if(istype(suppressed) && suppressed.break_chance && prob(suppressed.break_chance))
to_chat(user, span_warning("\the [suppressed] falls apart!"))
w_class -= suppressed.w_class
qdel(suppressed)
suppressed = null
update_appearance(UPDATE_ICON)
else
if(enloudened && enloudened.enloudened_sound)
playsound(user, enloudened.enloudened_sound, fire_sound_volume, vary_fire_sound)
playsound(user, fire_sound, fire_sound_volume, vary_fire_sound)
if(message)
if(pointblank)
user.visible_message(span_danger("[user] fires [src] point blank at [pbtarget]!"), null, null, COMBAT_MESSAGE_RANGE)
else
user.visible_message(span_danger("[user] fires [src]!"), null, null, COMBAT_MESSAGE_RANGE)
/obj/item/gun/emp_act(severity)
. = ..()
if(!(. & EMP_PROTECT_CONTENTS))
for(var/obj/O in contents)
O.emp_act(severity)
/obj/item/gun/afterattack(atom/target, mob/living/user, flag, params)
. = ..()
if(!target)
return
if(firing_burst)
return
if(flag) //It's adjacent, is the user, or is on the user's person
if(target in user.contents) //can't shoot stuff inside us.
return
if(!ismob(target) || user.combat_mode) //melee attack
return
if(target == user && user.zone_selected != BODY_ZONE_PRECISE_MOUTH) //so we can't shoot ourselves (unless mouth selected)
return
if(iscarbon(target))
var/mob/living/carbon/C = target
for(var/i in C.all_wounds)
var/datum/wound/W = i
if(W.try_treating(src, user))
return // another coward cured!
if(istype(user))//Check if the user can use the gun, if the user isn't alive(turrets) assume it can.
var/mob/living/L = user
if(!can_trigger_gun(L))
return
if(flag)
if(user.zone_selected == BODY_ZONE_PRECISE_MOUTH)
handle_suicide(user, target, params)
return
if(!can_shoot()) //Just because you can pull the trigger doesn't mean it can shoot.
shoot_with_empty_chamber(user)
return
//Exclude lasertag guns from the TRAIT_CLUMSY check.
if(check_botched(user))
return
if(weapon_weight == WEAPON_HEAVY && user.get_inactive_held_item())
to_chat(user, span_userdanger("You need both hands free to fire \the [src]!"))
return
//DUAL (or more!) WIELDING
var/bonus_spread = 0
var/cd_mod = CLICK_CD_RANGE
if(chambered?.click_cooldown_override)
cd_mod = chambered.click_cooldown_override
if(ishuman(user) && user.combat_mode)
var/mob/living/carbon/human/H = user
if(weapon_weight < WEAPON_MEDIUM && istype(H.held_items[H.get_inactive_hand_index()], /obj/item/gun) && can_trigger_gun(user))
bonus_spread += 18 * weapon_weight
cd_mod = cd_mod * 0.75
H.swap_hand()
process_fire(target, user, TRUE, params, null, bonus_spread, cd_mod)
/obj/item/gun/proc/check_botched(mob/living/user, params)
if(clumsy_check)
if(istype(user))
if(HAS_TRAIT(user, TRAIT_CLUMSY) && prob(40))
to_chat(user, span_userdanger("You shoot yourself in the foot with [src]!"))
var/shot_leg = pick(BODY_ZONE_L_LEG, BODY_ZONE_R_LEG)
process_fire(user, user, FALSE, params, shot_leg)
user.dropItemToGround(src, TRUE)
return TRUE
/obj/item/gun/can_trigger_gun(mob/living/user)
. = ..()
if(!handle_pins(user))
return FALSE
/obj/item/gun/proc/handle_pins(mob/living/user)
if(no_pin_required)
return TRUE
if(pin)
if(pin.pin_auth(user) || (pin.obj_flags & EMAGGED))
return TRUE
else
pin.auth_fail(user)
return FALSE
else
to_chat(user, span_warning("[src]'s trigger is locked. This weapon doesn't have a firing pin installed!"))
return FALSE
/obj/item/gun/proc/recharge_newshot()
return
/obj/item/gun/proc/process_burst(mob/living/user, atom/target, message = TRUE, params=null, zone_override = "", sprd = 0, randomized_gun_spread = 0, randomized_bonus_spread = 0, rand_spr = 0, iteration = 0)
if(!user || !firing_burst)
firing_burst = FALSE
return FALSE
if(!issilicon(user))
if(iteration > 1 && !(user.is_holding(src))) //for burst firing
firing_burst = FALSE
return FALSE
if(chambered && chambered.BB)
if(!synth_check(user, SYNTH_RESTRICTED_WEAPON))
return
if(HAS_TRAIT(user, TRAIT_PACIFISM)) // If the user has the pacifist trait, then they won't be able to fire [src] if the round chambered inside of [src] is lethal.
if(chambered.harmful) // Is the bullet chambered harmful?
to_chat(user, span_notice(" [src] is lethally chambered! You don't want to risk harming anyone..."))
return
if(HAS_TRAIT(user, TRAIT_NO_STUN_WEAPONS))
if(!chambered.harmful) // Is the bullet chambered not harmful?
to_chat(user, span_notice(" [src] is not lethally chambered! You cannot use non-lethal weapons!"))
return
if(randomspread)
sprd = round((rand() - 0.5) * DUALWIELD_PENALTY_EXTRA_MULTIPLIER * (randomized_gun_spread + randomized_bonus_spread))
else //Smart spread
sprd = round((((rand_spr/burst_size) * iteration) - (0.5 + (rand_spr * 0.25))) * (randomized_gun_spread + randomized_bonus_spread))
before_firing(target,user)
if(!chambered.fire_casing(target, user, params, ,suppressed, zone_override, sprd, src))
shoot_with_empty_chamber(user)
firing_burst = FALSE
return FALSE
else
if(get_dist(user, target) <= 1) //Making sure whether the target is in vicinity for the pointblank shot
shoot_live_shot(user, 1, target, message)
else
shoot_live_shot(user, 0, target, message)
if (iteration >= burst_size)
firing_burst = FALSE
else
shoot_with_empty_chamber(user)
firing_burst = FALSE
return FALSE
process_chamber()
update_appearance(UPDATE_ICON)
return TRUE
/// cd_override is FALSE or 0 by default (no override), if you want to make a gun have no click cooldown then just make it something small like 0.001
/obj/item/gun/proc/process_fire(atom/target, mob/living/user, message = TRUE, params = null, zone_override = "", bonus_spread = 0, cd_override = FALSE)
if(user)
SEND_SIGNAL(user, COMSIG_MOB_FIRED_GUN, user, target, params, zone_override)
for(var/obj/item/attachment/A in current_attachments)
A.on_gun_fire(src)
add_fingerprint(user)
if(semicd)
return
var/sprd = 0
var/randomized_gun_spread = 0
var/rand_spr = rand()
if(spread > 0)
randomized_gun_spread += rand(0,spread) * (8 - user.get_skill(SKILL_FITNESS)) / 5
if(ishuman(user)) //nice shootin' tex
var/mob/living/carbon/human/H = user
bonus_spread += H.dna.species.aiminginaccuracy
if(HAS_TRAIT(user, TRAIT_POOR_AIM))
bonus_spread += 25
var/randomized_bonus_spread = rand(0, bonus_spread)
if(burst_size > 1)
firing_burst = TRUE
for(var/i = 1 to burst_size)
addtimer(CALLBACK(src, PROC_REF(process_burst), user, target, message, params, zone_override, sprd, randomized_gun_spread, randomized_bonus_spread, rand_spr, i), fire_delay * (i - 1))
else
if(chambered)
if(!synth_check(user, SYNTH_RESTRICTED_WEAPON))
return
if(HAS_TRAIT(user, TRAIT_PACIFISM)) // If the user has the pacifist trait, then they won't be able to fire [src] if the round chambered inside of [src] is lethal.
if(chambered.harmful) // Is the bullet chambered harmful?
to_chat(user, span_notice(" [src] is lethally chambered! You don't want to risk harming anyone..."))
return
if(HAS_TRAIT(user, TRAIT_NO_STUN_WEAPONS))
if(!chambered.harmful) // Is the bullet chambered not harmful?
to_chat(user, span_notice(" [src] is not lethally chambered! You cannot use non-lethal weapons!"))
return
sprd = round((rand() - 0.5) * DUALWIELD_PENALTY_EXTRA_MULTIPLIER * (randomized_gun_spread + randomized_bonus_spread))
before_firing(target,user)
if(!chambered.fire_casing(target, user, params, , suppressed, zone_override, sprd, src, cd_override))
shoot_with_empty_chamber(user)
return
else
if(get_dist(user, target) <= 1) //Making sure whether the target is in vicinity for the pointblank shot
shoot_live_shot(user, 1, target, message)
else
shoot_live_shot(user, 0, target, message)
else
shoot_with_empty_chamber(user)
return
process_chamber()
update_appearance(UPDATE_ICON)
semicd = TRUE
addtimer(CALLBACK(src, PROC_REF(reset_semicd)), fire_delay)
if(user)
user.update_inv_hands()
SSblackbox.record_feedback("tally", "gun_fired", 1, type)
recent_shoot = world.time
return TRUE
/obj/item/gun/proc/reset_semicd()
semicd = FALSE
/obj/item/gun/attack(mob/M, mob/living/user, params)
if(user.combat_mode) //Flogging
if(bayonet)
M.attackby(bayonet, user)
return
else
return ..()
return
/obj/item/gun/attack_secondary(mob/living/victim, mob/living/user, params)
if(HAS_TRAIT(user, TRAIT_NO_HOLDUP))
return SECONDARY_ATTACK_CALL_NORMAL
if(user.GetComponent(/datum/component/gunpoint))
to_chat(user, span_warning("You are already holding someone up!"))
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
for(var/datum/component/gunpoint/G in user.GetComponents(/datum/component/gunpoint))
if(G && G.weapon == src) //spam check
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
user.AddComponent(/datum/component/gunpoint, victim, src)
return SECONDARY_ATTACK_CANCEL_ATTACK_CHAIN
/obj/item/gun/attack_atom(obj/O, mob/living/user)
if(user.combat_mode)
if(bayonet)
O.attackby(bayonet, user)
return
return ..()
/obj/item/gun/attackby(obj/item/I, mob/living/user, params)
if(user.combat_mode)
return ..()
else if (istype(I, /obj/item/attachment))
var/support = FALSE
for(var/n in available_attachments)
if(istype(I, n))
support = TRUE
break
if(!support)
to_chat(user, span_warning("\The [src] does not support \the [I]!"))
return ..()
var/already_has = FALSE
for(var/n in current_attachments)
if(istype(I, n))
already_has = TRUE
break
if(already_has)
to_chat(user, span_warning("\The [src] already has \a [I]!"))
return ..()
if(LAZYLEN(current_attachments) >= max_attachments)
to_chat(user, span_warning("\The [src] has no more room for any more attachments!"))
return ..()
var/obj/item/attachment/A = I
if(A.attachment_type != 0 && ((attachment_flags &= A.attachment_type) != 0))
to_chat(user, span_warning("\The [src] does not have any available places to attach \the [I] onto!"))
return ..()
to_chat(user, span_notice("You [A.attach_verb] \the [I] into place on [src]."))
A.on_attach(src, user)
else if(istype(I, /obj/item/flashlight/seclite))
if(!can_flashlight)
return ..()
var/obj/item/flashlight/seclite/S = I
if(gun_light)
return
if(!user.transferItemToLoc(I, src))
return
to_chat(user, span_notice("You click [S] into place on [src]."))
set_gun_light(S)
else if(istype(I, /obj/item/kitchen/knife))
var/obj/item/kitchen/knife/K = I
if(!can_bayonet || !K.bayonet || bayonet) //ensure the gun has an attachment point available, and that the knife is compatible with it.
return ..()
if(!user.transferItemToLoc(I, src))
return
to_chat(user, span_notice("You attach [K] to [src]'s bayonet lug."))
bayonet = K
update_appearance()
else
return ..()
/obj/item/gun/screwdriver_act(mob/living/user, obj/item/I)
. = ..()
if(.)
return
if(!user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK))
return
var/has_fl = FALSE
var/has_bayo = FALSE
var/amt_modular = LAZYLEN(current_attachments)
if(can_flashlight && gun_light)
has_fl = TRUE
if(bayonet && can_bayonet)
has_bayo = TRUE
var/attachments_amt = amt_modular + has_fl + has_bayo
if(attachments_amt > 1) //give them a choice instead of removing both
var/list/possible_items = list(gun_light, bayonet)
possible_items += current_attachments
var/obj/item/item_to_remove = input(user, "Select an attachment to remove", "Attachment Removal") as null|obj in possible_items
if(!item_to_remove || !user.canUseTopic(src, BE_CLOSE, FALSE, NO_TK))
return
return remove_gun_attachment(user, I, item_to_remove)
else if(amt_modular == 1)
return remove_gun_attachment(user, I, current_attachments[1], "unscrewed")
else if(has_fl) //if it has a gun_light and can_flashlight is false, the flashlight is permanently attached.
return remove_gun_attachment(user, I, gun_light, "unscrewed")
else if(has_bayo) //if it has a bayonet, and the bayonet can be removed
return remove_gun_attachment(user, I, bayonet, "unfix")
/obj/item/gun/proc/remove_gun_attachment(mob/living/user, obj/item/tool_item, obj/item/item_to_remove, removal_verb)
if(tool_item)
tool_item.play_tool_sound(src)
to_chat(user, span_notice("You [removal_verb ? removal_verb : "remove"] [item_to_remove] from [src]."))
item_to_remove.forceMove(drop_location())
if(Adjacent(user) && !issilicon(user))
user.put_in_hands(item_to_remove)
if(istype(item_to_remove, /obj/item/attachment))
var/obj/item/attachment/A = item_to_remove
return A.on_detach(src, user)
if(item_to_remove == bayonet)
return clear_bayonet()
else if(item_to_remove == gun_light)
return clear_gunlight()
/obj/item/gun/proc/clear_bayonet()
if(!bayonet)
return
bayonet = null
update_appearance(UPDATE_ICON)
return TRUE
/obj/item/gun/proc/clear_gunlight()
if(!gun_light)
return
var/obj/item/flashlight/seclite/removed_light = gun_light
set_gun_light(null)
removed_light.update_brightness()
return TRUE
///Called when gun_light value changes.
/obj/item/gun/proc/set_gun_light(obj/item/flashlight/seclite/new_light)
if(gun_light == new_light)
return
. = gun_light
gun_light = new_light
if(gun_light)
gun_light.set_light_flags(gun_light.light_flags | LIGHT_ATTACHED)
if(gun_light.loc != src)
gun_light.forceMove(src)
gunlight_toggle = new(src)
add_item_action(gunlight_toggle)
else if(.)
var/obj/item/flashlight/seclite/old_gun_light = .
old_gun_light.set_light_flags(old_gun_light.light_flags & ~LIGHT_ATTACHED)
if(old_gun_light.loc == src)
old_gun_light.forceMove(get_turf(src))
remove_item_action(gunlight_toggle)
gunlight_toggle = null
update_appearance()
/obj/item/gun/ui_action_click(mob/user, actiontype)
if(istype(actiontype, gunlight_toggle))
toggle_gunlight()
else
..()
/obj/item/gun/proc/toggle_gunlight()
if(!gun_light)
return
var/mob/living/carbon/human/user = usr
gun_light.toggle_light(user)
to_chat(user, span_notice("You toggle the gunlight [gun_light.light_on ? "on":"off"]."))
playsound(user, 'sound/weapons/empty.ogg', 100, TRUE)
update_appearance()
/obj/item/gun/update_overlays()
. = ..()
if(gun_light)
var/mutable_appearance/flashlight_overlay = mutable_appearance('icons/obj/guns/flashlights.dmi', "[gunlight_state][gun_light.light_on? "_on":""]")
flashlight_overlay.pixel_x = flight_x_offset
flashlight_overlay.pixel_y = flight_y_offset
. += flashlight_overlay
if(bayonet)
var/state = "bayonet" //Generic state.
if(bayonet.icon_state in icon_states('icons/obj/guns/attachment.dmi'))
state = bayonet.icon_state
var/icon/bayonet_icons = 'icons/obj/guns/attachment.dmi'
var/mutable_appearance/knife_overlay = mutable_appearance(bayonet_icons, state)
knife_overlay.pixel_x = knife_x_offset
knife_overlay.pixel_y = knife_y_offset
. += knife_overlay
var/att_position = 0
for(var/obj/item/attachment/A as anything in current_attachments)
var/mutable_appearance/M = mutable_appearance(A.icon, "[A.icon_state]_a")
M.pixel_x = att_position * 6
. += M
att_position++
for(var/datum/action/A as anything in actions)
A.build_all_button_icons()
/obj/item/gun/pickup(mob/user)
..()
for(var/obj/item/attachment/A in current_attachments)
A.set_user(user)
A.pickup_user(user)
for(var/datum/action/att_act in attachment_actions)
att_act.Grant(user)
if(azoom)
azoom.Grant(user)
/obj/item/gun/dropped(mob/user)
. = ..()
for(var/obj/item/attachment/A in current_attachments)
A.set_user()
A.drop_user(user)
for(var/datum/action/att_act in attachment_actions)
att_act.Remove(user)
if(azoom)
azoom.Remove(user)
if(zoomed)
zoom(user, user.dir)
/obj/item/gun/proc/handle_suicide(mob/living/carbon/human/user, mob/living/carbon/human/target, params, bypass_timer)
if(!ishuman(user) || !ishuman(target))
return
if(semicd)
return
if(user == target)
target.visible_message(span_warning("[user] sticks [src] in [user.p_their()] mouth, ready to pull the trigger..."), \
span_userdanger("You stick [src] in your mouth, ready to pull the trigger..."))
else
target.visible_message(span_warning("[user] points [src] at [target]'s head, ready to pull the trigger..."), \
span_userdanger("[user] points [src] at your head, ready to pull the trigger..."))
semicd = TRUE
if(!bypass_timer && (!do_after(user, 12 SECONDS, target) || user.zone_selected != BODY_ZONE_PRECISE_MOUTH))
if(user)
if(user == target)
user.visible_message(span_notice("[user] decided not to shoot."))
else if(target && target.Adjacent(user))
target.visible_message(span_notice("[user] has decided to spare [target]"), span_notice("[user] has decided to spare your life!"))
semicd = FALSE
return
semicd = FALSE
if(user == target && user.has_horror_inside())
user.visible_message(span_warning("[user] decided not to shoot."), span_notice("Something inside your head stops your action!"))
return
target.visible_message(span_warning("[user] pulls the trigger!"), span_userdanger("[(user == target) ? "You pull" : "[user] pulls"] the trigger!"))
if(chambered && chambered.BB)
chambered.BB.damage *= 5
if(chambered.BB.wound_bonus != CANT_WOUND)
chambered.BB.wound_bonus += 5
var/fired = process_fire(target, user, TRUE, params, BODY_ZONE_HEAD)
if(!fired && chambered?.BB)
chambered.BB.damage /= 5
if(chambered.BB.wound_bonus != CANT_WOUND)
chambered.BB.wound_bonus -= 5
/obj/item/gun/proc/unlock() //used in summon guns and as a convience for admins
if(pin)
qdel(pin)
pin = new /obj/item/firing_pin
//Happens before the actual projectile creation
/obj/item/gun/proc/before_firing(atom/target,mob/user)
return
/////////////
// ZOOMING //
/////////////
/datum/action/toggle_scope_zoom
name = "Toggle Scope"
check_flags = AB_CHECK_CONSCIOUS|AB_CHECK_HANDS_BLOCKED| AB_CHECK_IMMOBILE|AB_CHECK_LYING
button_icon = 'icons/mob/actions/actions_items.dmi'
button_icon_state = "sniper_zoom"
var/obj/item/gun/gun = null
/datum/action/toggle_scope_zoom/Trigger()
gun.zoom(owner, owner.dir)
/datum/action/toggle_scope_zoom/IsAvailable(feedback = FALSE)
. = ..()
if(!. && gun)
gun.zoom(owner, owner.dir, FALSE)
/datum/action/toggle_scope_zoom/Remove(mob/living/L)
gun.zoom(L, L.dir, FALSE)
..()
/obj/item/gun/proc/rotate(atom/thing, old_dir, new_dir)
if(ismob(thing))
var/mob/lad = thing
lad.client.view_size.zoomOut(zoom_out_amt, zoom_amt, new_dir)
/obj/item/gun/proc/zoom(mob/living/user, direc, forced_zoom)
if(!user || !user.client)
return
switch(forced_zoom)
if(FALSE)
zoomed = FALSE
if(TRUE)
zoomed = TRUE
else
zoomed = !zoomed
if(zoomed)
RegisterSignal(user, COMSIG_ATOM_DIR_CHANGE, PROC_REF(rotate))
user.client.view_size.zoomOut(zoom_out_amt, zoom_amt, direc)
else
UnregisterSignal(user, COMSIG_ATOM_DIR_CHANGE)
user.client.view_size.zoomIn()
return zoomed
//Proc, so that gun accessories/scopes/etc. can easily add zooming.
/obj/item/gun/proc/build_zooming()
if(azoom)
return
if(zoomable)
azoom = new()
azoom.gun = src