Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Underbarrel Gun Attachments #3825

Open
wants to merge 69 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
ff6b14a
take1
Gristlebee Jul 28, 2024
1d9b5e4
meh
Gristlebee Jul 29, 2024
2397e70
Merge branch 'master' into underbarrel-guns
Gristlebee Sep 20, 2024
e8eab9e
afterattack
Gristlebee Sep 20, 2024
98f2603
Update guns.dm
Gristlebee Sep 20, 2024
7026167
only melee works
Gristlebee Sep 20, 2024
458e803
the guns fire, yipee
Gristlebee Sep 20, 2024
1cf8584
shooty shooty bang bang
Gristlebee Sep 20, 2024
fc3189a
signals
Gristlebee Sep 20, 2024
c86d8f5
unique actions.
Gristlebee Sep 20, 2024
60258c2
take subtypes
Gristlebee Sep 21, 2024
c60ff87
types
Gristlebee Sep 21, 2024
eb70c79
override
Gristlebee Sep 21, 2024
b6d3769
safties
Gristlebee Sep 21, 2024
3302fd9
examines
Gristlebee Sep 22, 2024
9f54990
Update attachment_holder.dm
Gristlebee Sep 22, 2024
a083a1c
weh
Gristlebee Sep 22, 2024
8743eae
examines
Gristlebee Sep 23, 2024
be043a4
oops
Gristlebee Sep 23, 2024
c3da8c2
get the flamer. The mini flamer.
Gristlebee Sep 24, 2024
e510f7f
weh
Gristlebee Sep 24, 2024
b8650be
Merge branch 'master' into underbarrel-guns
Gristlebee Sep 24, 2024
b105d65
files
Gristlebee Sep 24, 2024
666be7e
kills redundant code
Gristlebee Sep 25, 2024
42e1ffe
examines
Gristlebee Sep 25, 2024
cd0f0de
firemodes
Gristlebee Sep 25, 2024
0e61b1b
underbarrel ballistics
Gristlebee Sep 25, 2024
7611d19
pew pew
Gristlebee Sep 25, 2024
eb0ffe6
bargo
Gristlebee Sep 25, 2024
e9b4f65
Update energy.dm
Gristlebee Oct 10, 2024
db4cbdb
Merge branch 'master' into underbarrel-guns
Gristlebee Nov 20, 2024
4dad52c
guh
Gristlebee Nov 20, 2024
114469f
icons
Gristlebee Nov 20, 2024
a029c7c
works out kinks
Gristlebee Nov 20, 2024
ba7bbf3
icons
Gristlebee Nov 20, 2024
3f02208
more kinks
Gristlebee Nov 20, 2024
29c9b7d
attachment slots
Gristlebee Nov 20, 2024
37b854c
firemodes
Gristlebee Nov 20, 2024
1500f73
recharger
Gristlebee Nov 20, 2024
474633e
oops
Gristlebee Nov 21, 2024
965cbb2
aaa
Gristlebee Nov 21, 2024
ea46e53
ordering
Gristlebee Nov 21, 2024
f90883f
comments
Gristlebee Nov 22, 2024
35b05f2
Update items.dm
Gristlebee Nov 22, 2024
934a874
oops
Gristlebee Nov 22, 2024
e4f04b3
Update ballistics.dm
Gristlebee Nov 22, 2024
d0698c5
pray
Gristlebee Nov 22, 2024
678b539
tests? maybe?
Gristlebee Nov 22, 2024
da32202
flaredgun
Gristlebee Nov 23, 2024
3814bb5
bargo. typo
Gristlebee Nov 23, 2024
1ba66b6
Update code/__DEFINES/guns.dm
Gristlebee Dec 4, 2024
bda16af
Update code/datums/components/attachment.dm
Gristlebee Dec 4, 2024
2656a4c
Update code/datums/components/attachment.dm
Gristlebee Dec 4, 2024
6784334
Update code/game/objects/items/attachments/gun_attachments/riot_launc…
Gristlebee Dec 4, 2024
cebcdb7
Update code/game/objects/items/attachments/gun_attachments/flamethrow…
Gristlebee Dec 4, 2024
84b52ef
Merge branch 'master' into underbarrel-guns
Gristlebee Dec 4, 2024
23df9b3
Merge branch 'underbarrel-guns' of https://github.com/Gristlebee/Ship…
Gristlebee Dec 4, 2024
2898bdc
signal(is)
Gristlebee Dec 4, 2024
8393254
Merge branch 'master' into underbarrel-guns
Gristlebee Dec 4, 2024
41a889b
Update shiptest.dme
Gristlebee Dec 4, 2024
5f156bf
sprite
Gristlebee Dec 4, 2024
99e4169
typecache
Gristlebee Dec 4, 2024
ec792ad
oops typo
Gristlebee Dec 4, 2024
686b2a5
Merge branch 'master' into underbarrel-guns
Gristlebee Dec 30, 2024
af5e885
latches/runtime fixes
Gristlebee Jan 3, 2025
b16e45b
typo
Gristlebee Jan 3, 2025
f60e961
examine hint
Gristlebee Jan 3, 2025
dbdac2d
Update code/modules/projectiles/guns/manufacturer/scarborough/ballist…
Gristlebee Jan 3, 2025
6367d7b
attachment points
Gristlebee Jan 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions code/__DEFINES/dcs/signals/signals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@
#define COMSIG_CLICK_CTRL_SHIFT "ctrl_shift_click"
///from base of atom/CtrlShiftRightClick(/mob)
#define COMSIG_CLICK_CTRL_SHIFT_RIGHT "ctrl_shift_right_click"
/// from mob/ver/do_unique_action
#define COMSIG_CLICK_UNIQUE_ACTION "unique_action"
#define OVERIDE_UNIQUE_ACTION 1
//from base of atom/MouseDrop(): (/atom/over, /mob/user)
#define COMSIG_MOUSEDROP_ONTO "mousedrop_onto"
#define COMPONENT_NO_MOUSEDROP 1
Expand Down
7 changes: 7 additions & 0 deletions code/__DEFINES/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,14 @@
#define COMSIG_ATTACHMENT_EXAMINE "attach-examine"
#define COMSIG_ATTACHMENT_EXAMINE_MORE "attach-examine-more"
#define COMSIG_ATTACHMENT_PRE_ATTACK "attach-pre-attack"
#define COMSIG_ATTACHMENT_AFTER_ATTACK "attach-after-attack"
#define COMSIG_ATTACHMENT_ATTACK "attach-attacked"
#define COMSIG_ATTACHMENT_WIELD "attach-wield"
#define COMSIG_ATTACHMENT_UNWIELD "attach-unwield"
#define COMSIG_ATTACHMENT_UPDATE_OVERLAY "attach-overlay"
#define COMSIG_ATTACHMENT_UNIQUE_ACTION "attach-unique-action"
#define COMSIG_ATTACHMENT_CTRL_CLICK "attach-ctrl-click"
#define COMSIG_ATTACHMENT_ALT_CLICK "attach-alt-click"

#define COMSIG_ATTACHMENT_TOGGLE "attach-toggle"

Expand Down Expand Up @@ -199,6 +205,7 @@
#define FIREMODE_FULLAUTO "auto"
#define FIREMODE_OTHER "other"
#define FIREMODE_OTHER_TWO "other2"
#define FIREMODE_UNDERBARREL "underbarrel"

#define GUN_LEFTHAND_ICON 'icons/mob/inhands/weapons/guns_lefthand.dmi'
#define GUN_RIGHTHAND_ICON 'icons/mob/inhands/weapons/guns_righthand.dmi'
8 changes: 6 additions & 2 deletions code/_onclick/click.dm
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,10 @@
UnarmedAttack(A,1)
else
if(W)
W.afterattack(A,src,0,params)
if(W.pre_attack(A,src,params))
return
else
W.afterattack(A,src,0,params)
else
RangedAttack(A,params)

Expand Down Expand Up @@ -342,10 +345,11 @@
A.AltClick(src)

/atom/proc/AltClick(mob/user)
SEND_SIGNAL(src, COMSIG_CLICK_ALT, user)
var/result = SEND_SIGNAL(src, COMSIG_CLICK_ALT, user)
var/turf/T = get_turf(src)
if(T && (isturf(loc) || isturf(src)) && user.TurfAdjacent(T))
user.set_listed_turf(T)
return result

/// Use this instead of [/mob/proc/AltClickOn] where you only want turf content listing without additional atom alt-click interaction
/atom/proc/AltClickNoInteract(mob/user, atom/A)
Expand Down
68 changes: 68 additions & 0 deletions code/datums/components/attachment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
var/datum/callback/on_attach
var/datum/callback/on_detach
var/datum/callback/on_toggle
var/datum/callback/on_attacked
var/datum/callback/on_unique_action
var/datum/callback/on_ctrl_click
var/datum/callback/on_alt_click
var/datum/callback/on_examine
///Called on the parents preattack
var/datum/callback/on_preattack
///Called on the parents wield
var/datum/callback/on_wield
///Called on the parents unwield
var/datum/callback/on_unwield
///Unused...Also a little broken..
var/list/datum/action/actions
///Generated if the attachment can toggle, sends COMSIG_ATTACHMENT_TOGGLE
Expand All @@ -23,6 +32,13 @@
datum/callback/on_detach = null,
datum/callback/on_toggle = null,
datum/callback/on_preattack = null,
datum/callback/on_attacked = null,
datum/callback/on_unique_action = null,
datum/callback/on_ctrl_click = null,
datum/callback/on_wield = null,
datum/callback/on_unwield = null,
datum/callback/on_examine = null,
datum/callback/on_alt_click = null,
list/signals = null
)

Expand All @@ -36,6 +52,13 @@
src.on_detach = on_detach
src.on_toggle = on_toggle
src.on_preattack = on_preattack
src.on_attacked = on_attacked
src.on_unique_action = on_unique_action
src.on_ctrl_click = on_ctrl_click
src.on_wield = on_wield
src.on_unwield = on_unwield
src.on_examine = on_examine
src.on_alt_click = on_alt_click

ADD_TRAIT(parent, TRAIT_ATTACHABLE, "attachable")
RegisterSignal(parent, COMSIG_ATTACHMENT_ATTACH, PROC_REF(try_attach))
Expand All @@ -48,6 +71,12 @@
RegisterSignal(parent, COMSIG_ATTACHMENT_PRE_ATTACK, PROC_REF(relay_pre_attack))
RegisterSignal(parent, COMSIG_ATTACHMENT_UPDATE_OVERLAY, PROC_REF(update_overlays))
RegisterSignal(parent, COMSIG_ATTACHMENT_GET_SLOT, PROC_REF(send_slot))
RegisterSignal(parent, COMSIG_ATTACHMENT_WIELD, PROC_REF(try_wield))
RegisterSignal(parent, COMSIG_ATTACHMENT_UNWIELD, PROC_REF(try_unwield))
RegisterSignal(parent, COMSIG_ATTACHMENT_ATTACK, PROC_REF(relay_attacked))
RegisterSignal(parent, COMSIG_ATTACHMENT_UNIQUE_ACTION, PROC_REF(relay_unique_action))
RegisterSignal(parent, COMSIG_ATTACHMENT_CTRL_CLICK, PROC_REF(relay_ctrl_click))
RegisterSignal(parent, COMSIG_ATTACHMENT_ALT_CLICK, PROC_REF(relay_alt_click))

for(var/signal in signals)
RegisterSignal(parent, signal, signals[signal])
Expand Down Expand Up @@ -129,6 +158,9 @@
/datum/component/attachment/proc/handle_examine(obj/item/parent, mob/user, list/examine_list)
SIGNAL_HANDLER

if(on_examine)
on_examine.Invoke(parent, user, examine_list)

/datum/component/attachment/proc/handle_examine_more(obj/item/parent, mob/user, list/examine_list)
SIGNAL_HANDLER

Expand All @@ -138,6 +170,42 @@
if(on_preattack)
return on_preattack.Invoke(gun, target_atom, user, params)

/datum/component/attachment/proc/relay_attacked(obj/item/parent, obj/item/gun, obj/item, mob/user, params)
SIGNAL_HANDLER_DOES_SLEEP

if(on_attacked)
return on_attacked.Invoke(gun, user, item)

/datum/component/attachment/proc/try_wield(obj/item/parent, obj/item/gun, mob/user, params)
SIGNAL_HANDLER_DOES_SLEEP

if(on_wield)
return on_wield.Invoke(gun, user, params)

/datum/component/attachment/proc/try_unwield(obj/item/parent, obj/item/gun, mob/user, params)
SIGNAL_HANDLER_DOES_SLEEP

if(on_unwield)
return on_unwield.Invoke(gun, user, params)

/datum/component/attachment/proc/relay_unique_action(obj/item/parent, obj/item/gun, mob/user, params)
SIGNAL_HANDLER_DOES_SLEEP

if(on_unique_action)
return on_unique_action.Invoke(gun, user, params)

/datum/component/attachment/proc/relay_ctrl_click(obj/item/parent, obj/item/gun, mob/user, params)
SIGNAL_HANDLER_DOES_SLEEP

if(on_ctrl_click)
return on_ctrl_click.Invoke(gun, user, params)

/datum/component/attachment/proc/relay_alt_click(obj/item/parent, obj/item/gun, mob/user, params)
SIGNAL_HANDLER_DOES_SLEEP

if(on_alt_click)
return on_alt_click.Invoke(gun, user, params)

/datum/component/attachment/proc/send_slot(obj/item/parent)
SIGNAL_HANDLER
return attachment_slot_to_bflag(slot)
Expand Down
53 changes: 47 additions & 6 deletions code/datums/components/attachment_holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@
var/obj/item/gun/parent_gun = parent

src.slot_room = slot_room
src.valid_types = valid_types
src.valid_types = typecacheof(valid_types)
src.slot_offsets = slot_offsets

RegisterSignal(parent, COMSIG_PARENT_ATTACKBY, PROC_REF(handle_attack))
RegisterSignal(parent, COMSIG_PARENT_EXAMINE, PROC_REF(handle_examine))
RegisterSignal(parent, COMSIG_PARENT_EXAMINE_MORE, PROC_REF(handle_examine_more))
RegisterSignal(parent, COMSIG_PARENT_QDELETING, PROC_REF(handle_qdel))
RegisterSignal(parent, COMSIG_ITEM_PRE_ATTACK, PROC_REF(handle_item_pre_attack))
RegisterSignal(parent, COMSIG_TWOHANDED_WIELD, PROC_REF(handle_item_wield))
RegisterSignal(parent, COMSIG_TWOHANDED_UNWIELD, PROC_REF(handle_item_unwield))
RegisterSignal(parent, COMSIG_CLICK_CTRL_SHIFT, PROC_REF(handle_ctrl_shift_click))
RegisterSignal(parent, COMSIG_CLICK_CTRL, PROC_REF(handle_ctrl_click))
RegisterSignal(parent, COMSIG_CLICK_ALT, PROC_REF(handle_alt_click))
RegisterSignal(parent, COMSIG_CLICK_UNIQUE_ACTION, PROC_REF(handle_unique_action))
RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(handle_overlays))

if(length(default_attachments))
Expand Down Expand Up @@ -80,7 +84,20 @@
/datum/component/attachment_holder/proc/handle_alt_click(obj/item/parent, mob/user)
SIGNAL_HANDLER

INVOKE_ASYNC(src, PROC_REF(handle_detach), parent, user)
if(user.a_intent == INTENT_HARM)
INVOKE_ASYNC(src, PROC_REF(handle_detach), parent, user)
return TRUE
else
for(var/obj/item/attach as anything in attachments)
if(SEND_SIGNAL(attach, COMSIG_ATTACHMENT_ALT_CLICK, parent, user))
return TRUE

/datum/component/attachment_holder/proc/handle_ctrl_click(obj/item/parent, mob/user)
SIGNAL_HANDLER

for(var/obj/item/attach as anything in attachments)
if(SEND_SIGNAL(attach, COMSIG_ATTACHMENT_CTRL_CLICK, parent, user))
return TRUE

/datum/component/attachment_holder/proc/do_attachment_radial(obj/item/parent, mob/user)
var/list/attachments_as_list = attachments_to_list(TRUE)
Expand All @@ -93,6 +110,7 @@
/datum/component/attachment_holder/proc/handle_examine(obj/item/parent, mob/user, list/examine_list)
if(length(attachments))
examine_list += span_notice("It has [length(attachments)] attachment\s.")
examine_list += span_notice("You can remove them by pressing alt-click on the [parent] on harm intent.")
for(var/obj/item/attach as anything in attachments)
SEND_SIGNAL(attach, COMSIG_ATTACHMENT_EXAMINE, user, examine_list)

Expand All @@ -114,7 +132,7 @@
/datum/component/attachment_holder/proc/do_attach(obj/item/attachment, mob/user, bypass_checks)
var/slot = SEND_SIGNAL(attachment, COMSIG_ATTACHMENT_GET_SLOT)
slot = attachment_slot_from_bflag(slot)
if(!(attachment.type in valid_types))
if(!(is_type_in_typecache(attachment,valid_types)))
to_chat(user, span_notice("[attachment] is not a valid attachment for this [parent]!"))
return
if(!slot_room[slot])
Expand Down Expand Up @@ -152,13 +170,15 @@
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)
if(selected)
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)
if(selected)
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)
Expand Down Expand Up @@ -186,3 +206,24 @@
for(var/obj/item/attach as anything in attachments)
if(SEND_SIGNAL(attach, COMSIG_ATTACHMENT_PRE_ATTACK, parent, target_atom, user, params))
return TRUE

/datum/component/attachment_holder/proc/handle_item_wield(obj/item/parent, mob/user, params)
SIGNAL_HANDLER

for(var/obj/item/attach as anything in attachments)
if(SEND_SIGNAL(attach, COMSIG_ATTACHMENT_WIELD , parent, user, params))
return TRUE

/datum/component/attachment_holder/proc/handle_item_unwield(obj/item/parent, mob/user, params)
SIGNAL_HANDLER

for(var/obj/item/attach as anything in attachments)
if(SEND_SIGNAL(attach, COMSIG_ATTACHMENT_UNWIELD, parent, user, params))
return TRUE

/datum/component/attachment_holder/proc/handle_unique_action(obj/item/parent, mob/user, params)
SIGNAL_HANDLER

for(var/obj/item/attach as anything in attachments)
if(SEND_SIGNAL(attach, COMSIG_ATTACHMENT_UNIQUE_ACTION, parent, user, params))
return TRUE
1 change: 1 addition & 0 deletions code/game/machinery/recharger.dm
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
/obj/item/modular_computer,
/obj/item/gun/ballistic/automatic/powered,
/obj/item/gun/ballistic/automatic/assault/e40,
/obj/item/attachment/gun/energy,
/obj/item/stock_parts/cell/gun
))

Expand Down
6 changes: 5 additions & 1 deletion code/game/objects/items.dm
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,12 @@ GLOBAL_VAR_INIT(embedpocalypse, FALSE) // if true, all items will be able to emb

///Intended for interactions with guns, like racking
/obj/item/proc/unique_action(mob/living/user)
return

///Called before unique action, if any other associated items should do a unique action or override it.
/obj/item/proc/pre_unique_action(mob/living/user)
if(SEND_SIGNAL(src,COMSIG_CLICK_UNIQUE_ACTION,user) & OVERIDE_UNIQUE_ACTION)
return TRUE
return FALSE //return true if the proc should end here
/**
* Returns null if this object cannot be used to interact with physical writing mediums such as paper.
* Returns a list of key attributes for this object interacting with paper otherwise.
Expand Down
34 changes: 34 additions & 0 deletions code/game/objects/items/attachments/_attachment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
CALLBACK(src, PROC_REF(remove_attachment)), \
CALLBACK(src, PROC_REF(toggle_attachment)), \
CALLBACK(src, PROC_REF(on_preattack)), \
CALLBACK(src, PROC_REF(on_attacked)), \
CALLBACK(src, PROC_REF(on_unique_action)), \
CALLBACK(src, PROC_REF(on_ctrl_click)), \
CALLBACK(src, PROC_REF(on_wield)), \
CALLBACK(src, PROC_REF(on_unwield)), \
CALLBACK(src, PROC_REF(on_examine)), \
CALLBACK(src, PROC_REF(on_alt_click)), \
signals)

/obj/item/attachment/Destroy()
Expand Down Expand Up @@ -89,6 +96,33 @@
/obj/item/attachment/proc/on_preattack(obj/item/gun/gun, atom/target, mob/user, list/params)
return FALSE

/obj/item/attachment/proc/on_wield(obj/item/gun/gun, mob/user, list/params)
return FALSE

/obj/item/attachment/proc/on_unwield(obj/item/gun/gun, mob/user, list/params)
return FALSE

/obj/item/attachment/proc/on_attacked(obj/item/gun/gun, mob/user, obj/item)
return FALSE

/obj/item/attachment/proc/on_unique_action(obj/item/gun/gun, mob/user, obj/item)
return FALSE

/obj/item/attachment/proc/on_ctrl_click(obj/item/gun/gun, mob/user, params)
return FALSE

/obj/item/attachment/proc/on_examine(obj/item/gun/gun, mob/user, list/examine_list)
return

/obj/item/attachment/proc/on_alt_click(obj/item/gun/gun, mob/user, list/examine_list)
AltClick(user)
return TRUE

/obj/item/attachment/examine(mob/user)
. = ..()
var/list/examine_info = list()
. += on_examine(examine_list = examine_info)

///Handles the modifiers to the parent gun
/obj/item/attachment/proc/apply_modifiers(obj/item/gun/gun, mob/user, attaching)
if(attaching)
Expand Down
Loading
Loading