From 08fa2f6a97da980f9d1a234c755fce1446b0ff70 Mon Sep 17 00:00:00 2001 From: FalloutFalcon Date: Sun, 9 Jun 2024 02:24:49 -0500 Subject: [PATCH] changes to attachment removal, moves it to alt click --- code/__DEFINES/guns.dm | 13 ++++--- code/datums/components/attachment.dm | 2 +- code/datums/components/attachment_holder.dm | 38 ++++++++++++++----- .../objects/items/attachments/_attachment.dm | 18 ++++++++- .../game/objects/items/attachments/bayonet.dm | 2 + .../objects/items/attachments/laser_sight.dm | 10 ++--- .../objects/items/attachments/rail_light.dm | 2 +- .../objects/items/attachments/silencer.dm | 2 + code/modules/projectiles/gun.dm | 1 + code/modules/projectiles/guns/ballistic.dm | 5 --- .../projectiles/guns/ballistic/pistol.dm | 1 + 11 files changed, 62 insertions(+), 32 deletions(-) diff --git a/code/__DEFINES/guns.dm b/code/__DEFINES/guns.dm index 94fd74c580f3..ba5c94562f82 100644 --- a/code/__DEFINES/guns.dm +++ b/code/__DEFINES/guns.dm @@ -104,10 +104,10 @@ #define COMSIG_ATTACHMENT_TOGGLE "attach-toggle" #define COMSIG_ATTACHMENT_GET_SLOT "attach-slot-who" -#define ATTACHMENT_SLOT_MUZZLE "attach-slot-muzzle" -#define ATTACHMENT_SLOT_SCOPE "attach-slot-scope" -#define ATTACHMENT_SLOT_GRIP "attach-slot-grip" -#define ATTACHMENT_SLOT_RAIL "attach-slot-rail" +#define ATTACHMENT_SLOT_MUZZLE "muzzle" +#define ATTACHMENT_SLOT_SCOPE "scope" +#define ATTACHMENT_SLOT_GRIP "grip" +#define ATTACHMENT_SLOT_RAIL "rail" /* #define BIT_ATTACHMENT_SLOT_MUZZLE (1<<0) @@ -153,8 +153,9 @@ DEFINE_BITFIELD(attach_slots, list( ) //attach_features_flags -#define ATTACH_REMOVABLE (1<<0) -#define ATTACH_TOGGLE (1<<1) +#define ATTACH_REMOVABLE_HAND (1<<0) +#define ATTACH_REMOVABLE_TOOL (1<<1) +#define ATTACH_TOGGLE (1<<2) ///////////////// // PROJECTILES // diff --git a/code/datums/components/attachment.dm b/code/datums/components/attachment.dm index c95db361d1f1..34f053e4d601 100644 --- a/code/datums/components/attachment.dm +++ b/code/datums/components/attachment.dm @@ -11,7 +11,7 @@ /datum/component/attachment/Initialize( slot = ATTACHMENT_SLOT_RAIL, - attach_features_flags = ATTACH_REMOVABLE, + attach_features_flags = ATTACH_REMOVABLE_HAND, valid_parent_types = list(/obj/item/gun), datum/callback/on_attach = null, datum/callback/on_detach = null, diff --git a/code/datums/components/attachment_holder.dm b/code/datums/components/attachment_holder.dm index c047546c44e8..9edae8c8063b 100644 --- a/code/datums/components/attachment_holder.dm +++ b/code/datums/components/attachment_holder.dm @@ -26,6 +26,7 @@ RegisterSignal(parent, COMSIG_PARENT_QDELETING, PROC_REF(handle_qdel)) RegisterSignal(parent, COMSIG_ITEM_PRE_ATTACK, PROC_REF(handle_item_pre_attack)) RegisterSignal(parent, COMSIG_CLICK_CTRL_SHIFT, PROC_REF(handle_ctrl_shift_click)) + RegisterSignal(parent, COMSIG_CLICK_ALT, PROC_REF(handle_alt_click)) RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(handle_overlays)) if(length(default_attachments)) @@ -72,6 +73,11 @@ INVOKE_ASYNC(src, PROC_REF(do_attachment_radial), parent, user) +/datum/component/attachment_holder/proc/handle_alt_click(obj/item/parent, mob/user) + SIGNAL_HANDLER + + INVOKE_ASYNC(src, PROC_REF(handle_detach), parent, user) + /datum/component/attachment_holder/proc/do_attachment_radial(obj/item/parent, mob/user) var/list/attachments_as_list = attachments_to_list(TRUE) var/selection = show_radial_menu(user, parent, attachments_as_list) @@ -93,7 +99,6 @@ examine_list += span_notice("It has the following attachments:") for(var/obj/item/attach as anything in attachments) examine_list += span_notice("\t- [attach.name]") - examine_list += span_notice("\tThey can be removed with a crowbar") for(var/obj/attach_type as anything in valid_types) examine_list += span_notice("It can accept [initial(attach_type.name)]") for(var/obj/item/attach as anything in attachments) @@ -126,15 +131,28 @@ var/atom/parent = src.parent parent.update_icon() -/datum/component/attachment_holder/proc/handle_detach(obj/item/parent, obj/item/tool, mob/user) - var/list/list = list() +/datum/component/attachment_holder/proc/handle_detach(obj/item/parent, mob/user, obj/item/tool) + var/list/tool_list = list() + var/list/hand_list = list() for(var/obj/item/attachment/attach as anything in attachments) - if(attach.attach_features_flags & ATTACH_REMOVABLE) - list[attach.name] = attach - var/selected = tgui_input_list(user, "Select Attachment", "Detach", list) - if(!parent.Adjacent(user) || !selected || !tool || !tool.use_tool(parent, user, 2 SECONDS * tool.toolspeed)) - return - do_detach(list[selected], user) + if(attach.attach_features_flags & ATTACH_REMOVABLE_TOOL) + tool_list[attach.name] = attach + if(attach.attach_features_flags & ATTACH_REMOVABLE_HAND) + hand_list[attach.name] = attach + if(tool) + if(!length(tool_list)) + return + var/selected = tgui_input_list(user, "Select Attachment", "Detach", tool_list) + if(!parent.Adjacent(user) || !selected || !tool || !tool.use_tool(parent, user, 2 SECONDS * tool.toolspeed)) + return + do_detach(tool_list[selected], user) + else + if(!length(hand_list)) + return + var/selected = tgui_input_list(user, "Select Attachment", "Detach", hand_list) + if(do_after(user, 2 SECONDS, parent)) + do_detach(hand_list[selected], user) + /datum/component/attachment_holder/proc/handle_attack(obj/item/parent, obj/item/item, mob/user) SIGNAL_HANDLER @@ -143,7 +161,7 @@ return if(item.tool_behaviour == TOOL_CROWBAR && length(attachments)) - INVOKE_ASYNC(src, PROC_REF(handle_detach), parent, item, user) + INVOKE_ASYNC(src, PROC_REF(handle_detach), parent, user, item) return TRUE if(HAS_TRAIT(item, TRAIT_ATTACHABLE)) diff --git a/code/game/objects/items/attachments/_attachment.dm b/code/game/objects/items/attachments/_attachment.dm index 8f0a3a360159..a78fc06d299d 100644 --- a/code/game/objects/items/attachments/_attachment.dm +++ b/code/game/objects/items/attachments/_attachment.dm @@ -4,8 +4,8 @@ icon = 'icons/obj/guns/attachments.dmi' var/slot = ATTACHMENT_SLOT_RAIL - ///various yes no flags associated with attachments. See defines for these: [ATTACH_REMOVABLE] - var/attach_features_flags = ATTACH_REMOVABLE + ///various yes no flags associated with attachments. See defines for these: [ATTACH_REMOVABLE_HAND] + var/attach_features_flags = ATTACH_REMOVABLE_HAND var/list/valid_parents = list() var/list/signals = list() var/datum/component/attachment/attachment_comp @@ -19,6 +19,8 @@ ///Determines the amount of pixels to move the icon state for the overlay. in the y direction var/pixel_shift_y = 16 + var/spread_mod = 0 + /obj/item/attachment/Initialize() . = ..() attachment_comp = AddComponent( \ @@ -52,6 +54,7 @@ to_chat(user, "You cannot attach [src] while it is active!") return FALSE + apply_modifiers(gun, user, TRUE) playsound(src.loc, 'sound/weapons/gun/pistol/mag_insert_alt.ogg', 75, 1) return TRUE @@ -61,8 +64,19 @@ if(toggled) Toggle(gun, user) + apply_modifiers(gun, user, FALSE) playsound(src.loc, 'sound/weapons/gun/pistol/mag_release_alt.ogg', 75, 1) return TRUE /obj/item/attachment/proc/PreAttack(obj/item/gun/gun, atom/target, mob/user, list/params) return FALSE + +///Handles the modifiers to the parent gun +/obj/item/attachment/proc/apply_modifiers(obj/item/gun/gun, mob/user, attaching) + if(attaching) + gun.spread += spread_mod + gun.spread_unwielded += spread_mod + else + gun.spread -= spread_mod + gun.spread_unwielded -= spread_mod + diff --git a/code/game/objects/items/attachments/bayonet.dm b/code/game/objects/items/attachments/bayonet.dm index c2022ea344d1..0bfac65b33c9 100644 --- a/code/game/objects/items/attachments/bayonet.dm +++ b/code/game/objects/items/attachments/bayonet.dm @@ -12,6 +12,8 @@ attack_verb = list("slashed", "stabbed", "sliced", "torn", "ripped", "diced", "cut") sharpness = IS_SHARP_ACCURATE + spread_mod = 1 + /obj/item/attachment/bayonet/PreAttack(obj/item/gun/gun, atom/target, mob/living/user, list/params) if(user.a_intent == INTENT_HARM && user.CanReach(target, src, TRUE)) melee_attack_chain(user, target, params) diff --git a/code/game/objects/items/attachments/laser_sight.dm b/code/game/objects/items/attachments/laser_sight.dm index 43af9b310c93..8f76ec51339f 100644 --- a/code/game/objects/items/attachments/laser_sight.dm +++ b/code/game/objects/items/attachments/laser_sight.dm @@ -2,17 +2,13 @@ name = "laser sight" desc = "This laser sight is designed to be rail-mounted on a compatible firearm to provide increased accuracy." icon_state = "laserpointer" - attach_features_flags = ATTACH_REMOVABLE|ATTACH_TOGGLE + attach_features_flags = ATTACH_REMOVABLE_HAND|ATTACH_TOGGLE pixel_shift_x = 1 pixel_shift_y = 4 + spread_mod = -1 + /obj/item/attachment/laser_sight/Toggle(obj/item/gun/gun, mob/user) . = ..() playsound(user, toggled ? 'sound/weapons/magin.ogg' : 'sound/weapons/magout.ogg', 40, TRUE) - - if(toggled) - gun.spread *= 0.6 - return - - gun.spread = initial(gun.spread) diff --git a/code/game/objects/items/attachments/rail_light.dm b/code/game/objects/items/attachments/rail_light.dm index d782e23123ac..9850a9f94ea6 100644 --- a/code/game/objects/items/attachments/rail_light.dm +++ b/code/game/objects/items/attachments/rail_light.dm @@ -2,7 +2,7 @@ name = "rail light" desc = "Rail mounted gun light for better visibility down range." icon_state = "raillight" - attach_features_flags = ATTACH_REMOVABLE|ATTACH_TOGGLE + attach_features_flags = ATTACH_REMOVABLE_HAND|ATTACH_TOGGLE pixel_shift_x = 1 pixel_shift_y = 4 diff --git a/code/game/objects/items/attachments/silencer.dm b/code/game/objects/items/attachments/silencer.dm index 19d3f16a82c1..a97ba1ea0375 100644 --- a/code/game/objects/items/attachments/silencer.dm +++ b/code/game/objects/items/attachments/silencer.dm @@ -6,6 +6,8 @@ pixel_shift_x = 1 pixel_shift_y = 2 + spread_mod = -1 + /obj/item/attachment/silencer/Attach(obj/item/gun/gun, mob/user) . = ..() gun.suppressed = TRUE diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index 1d5415339260..3188bb0a33f6 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -616,6 +616,7 @@ /obj/item/gun/proc/reset_current_cooldown() current_cooldown = FALSE + /obj/item/gun/proc/shoot_with_empty_chamber(mob/living/user as mob|obj) if(!safety) to_chat(user, "*[dry_fire_text]*") diff --git a/code/modules/projectiles/guns/ballistic.dm b/code/modules/projectiles/guns/ballistic.dm index c338c8172c71..6401b9228317 100644 --- a/code/modules/projectiles/guns/ballistic.dm +++ b/code/modules/projectiles/guns/ballistic.dm @@ -226,11 +226,6 @@ return return FALSE -/obj/item/gun/ballistic/AltClick(mob/user) - if (unique_reskin && !current_skin && user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY)) - reskin_obj(user) - return - ///Prefire empty checks for the bolt drop /obj/item/gun/ballistic/proc/prefire_empty_checks() if (!chambered && !get_ammo()) diff --git a/code/modules/projectiles/guns/ballistic/pistol.dm b/code/modules/projectiles/guns/ballistic/pistol.dm index 3b27175b56d2..3b05d764aa23 100644 --- a/code/modules/projectiles/guns/ballistic/pistol.dm +++ b/code/modules/projectiles/guns/ballistic/pistol.dm @@ -202,6 +202,7 @@ EMPTY_GUN_HELPER(automatic/pistol/commander/inteq) to_chat(user, "You toggle [src]'s vox audio functions.") /obj/item/gun/ballistic/automatic/pistol/commissar/AltClick(mob/user) + . = ..() if(!user.canUseTopic(src, BE_CLOSE, ismonkey(user))) return if((cooldown < world.time - 200) && funnysounds)