From c208faf5a0e54ba446623a4796911d6e1f5c1f7c Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 26 Jul 2023 08:54:22 -0700 Subject: [PATCH] fix another long-standing bug --- .../dcs/signals/atom/signals_item.dm | 3 +++ code/modules/projectiles/gun.dm | 2 ++ code/modules/projectiles/gun_attachables.dm | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/code/__DEFINES/dcs/signals/atom/signals_item.dm b/code/__DEFINES/dcs/signals/atom/signals_item.dm index 138e88d21746..2be5afe1056f 100644 --- a/code/__DEFINES/dcs/signals/atom/signals_item.dm +++ b/code/__DEFINES/dcs/signals/atom/signals_item.dm @@ -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" diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index e9f40bfb5310..cc4f53ca147e 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -429,6 +429,8 @@ setup_firemodes() + SEND_SIGNAL(src, COMSIG_GUN_RECALCULATE_ATTACHMENT_BONUSES) + /obj/item/weapon/gun/proc/handle_random_attachments() var/attachmentchoice diff --git a/code/modules/projectiles/gun_attachables.dm b/code/modules/projectiles/gun_attachables.dm index 90350558d688..e6382dde7921 100644 --- a/code/modules/projectiles/gun_attachables.dm +++ b/code/modules/projectiles/gun_attachables.dm @@ -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 @@ -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 @@ -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))