Skip to content

Commit

Permalink
fix another long-standing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoe2013 committed Jul 26, 2023
1 parent d338bf7 commit c208faf
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions code/__DEFINES/dcs/signals/atom/signals_item.dm
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@
#define COMSIG_GUN_AUTOFIREDELAY_MODIFIED "gun_autofiredelay_modified"
#define COMSIG_GUN_BURST_SHOTS_TO_FIRE_MODIFIED "gun_burst_shots_to_fire_modified"
#define COMSIG_GUN_BURST_SHOT_DELAY_MODIFIED "gun_burst_shot_delay_modified"

/// from /obj/item/weapon/gun/proc/recalculate_attachment_bonuses() : ()
#define COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES "gun_recalculate_attachment_bonuses"
2 changes: 2 additions & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@

setup_firemodes()

SEND_SIGNAL(src, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES)

/obj/item/weapon/gun/proc/handle_random_attachments()
var/attachmentchoice

Expand Down
24 changes: 24 additions & 0 deletions code/modules/projectiles/gun_attachables.dm
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,28 @@ Defined in conflicts.dm of the #defines folder.
delay_scoped_nerf = FIRE_DELAY_TIER_9 //to compensate initial debuff. We want "high_fire_delay"
damage_falloff_scoped_buff = -0.4 //has to be negative

/obj/item/attachable/scope/Attach(obj/item/weapon/gun/gun)
. = ..()
RegisterSignal(gun, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES, PROC_REF(handle_attachment_recalc))

/obj/item/attachable/scope/Detach(mob/user, obj/item/weapon/gun/detaching_gub)
. = ..()
UnregisterSignal(detaching_gub, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES)


/// Due to the bipod's interesting way of handling stat modifications, this is necessary to prevent exploits.
/obj/item/attachable/scope/proc/handle_attachment_recalc(obj/item/weapon/gun/source)
SIGNAL_HANDLER

if(!source.zoom)
return

if(using_scope)
source.accuracy_mult += accuracy_scoped_buff
source.modify_fire_delay(delay_scoped_nerf)
source.damage_falloff_mult += damage_falloff_scoped_buff


/obj/item/attachable/scope/proc/apply_scoped_buff(obj/item/weapon/gun/G, mob/living/carbon/user)
if(G.zoom)
G.accuracy_mult += accuracy_scoped_buff
Expand Down Expand Up @@ -2651,6 +2673,7 @@ Defined in conflicts.dm of the #defines folder.
burst_scatter_mod = 0
delay_mod = FIRE_DELAY_TIER_10
G.recalculate_attachment_bonuses()
G.stop_fire()
var/mob/living/user
if(isliving(G.loc))
user = G.loc
Expand Down Expand Up @@ -2688,6 +2711,7 @@ Defined in conflicts.dm of the #defines folder.
else
delay_mod = -FIRE_DELAY_TIER_10
G.recalculate_attachment_bonuses()
G.stop_fire()

initial_mob_dir = user.dir
RegisterSignal(user, COMSIG_MOB_MOVE_OR_LOOK, PROC_REF(handle_mob_move_or_look))
Expand Down

0 comments on commit c208faf

Please sign in to comment.