Skip to content

Commit

Permalink
changes to attachment removal, moves it to alt click
Browse files Browse the repository at this point in the history
  • Loading branch information
FalloutFalcon committed Jun 9, 2024
1 parent a527125 commit 08fa2f6
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 32 deletions.
13 changes: 7 additions & 6 deletions code/__DEFINES/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 //
Expand Down
2 changes: 1 addition & 1 deletion code/datums/components/attachment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 28 additions & 10 deletions code/datums/components/attachment_holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand All @@ -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 <i>crowbar</i>")
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)
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
18 changes: 16 additions & 2 deletions code/game/objects/items/attachments/_attachment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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( \
Expand Down Expand Up @@ -52,6 +54,7 @@
to_chat(user, "<span class='warning'>You cannot attach [src] while it is active!</span>")
return FALSE

apply_modifiers(gun, user, TRUE)
playsound(src.loc, 'sound/weapons/gun/pistol/mag_insert_alt.ogg', 75, 1)
return TRUE

Expand All @@ -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

2 changes: 2 additions & 0 deletions code/game/objects/items/attachments/bayonet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 3 additions & 7 deletions code/game/objects/items/attachments/laser_sight.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion code/game/objects/items/attachments/rail_light.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions code/game/objects/items/attachments/silencer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<span class='danger'>*[dry_fire_text]*</span>")
Expand Down
5 changes: 0 additions & 5 deletions code/modules/projectiles/guns/ballistic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
1 change: 1 addition & 0 deletions code/modules/projectiles/guns/ballistic/pistol.dm
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ EMPTY_GUN_HELPER(automatic/pistol/commander/inteq)
to_chat(user, "<span class='notice'>You toggle [src]'s vox audio functions.</span>")

/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)
Expand Down

0 comments on commit 08fa2f6

Please sign in to comment.