Skip to content

Commit

Permalink
small improvments to attachment code, default attachs work, better gu…
Browse files Browse the repository at this point in the history
…n stat handling
  • Loading branch information
FalloutFalcon committed Jun 10, 2024
1 parent 08fa2f6 commit 1ac8243
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 21 deletions.
1 change: 1 addition & 0 deletions code/__DEFINES/guns.dm
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ DEFINE_BITFIELD(attach_slots, list(
#define ATTACH_REMOVABLE_HAND (1<<0)
#define ATTACH_REMOVABLE_TOOL (1<<1)
#define ATTACH_TOGGLE (1<<2)
#define ATTACH_NO_SPRITE (1<<3)

/////////////////
// PROJECTILES //
Expand Down
10 changes: 6 additions & 4 deletions code/datums/components/attachment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@
return TRUE

/datum/component/attachment/proc/update_overlays(obj/item/parent, list/overlays, list/offset)
overlays += mutable_appearance(parent.icon, "[parent.icon_state]-attached")
if(!(attach_features_flags & ATTACH_NO_SPRITE))
overlays += mutable_appearance(parent.icon, "[parent.icon_state]-attached")

/datum/component/attachment/proc/try_attach(obj/item/parent, obj/item/holder, mob/user)
/datum/component/attachment/proc/try_attach(obj/item/parent, obj/item/holder, mob/user, bypass_checks)
SIGNAL_HANDLER

if(!parent.Adjacent(user) || (length(valid_parent_types) && (holder.type in valid_parent_types)))
return FALSE
if(!bypass_checks)
if(!parent.Adjacent(user) || (length(valid_parent_types) && (holder.type in valid_parent_types)))
return FALSE

if(on_attach && !on_attach.Invoke(holder, user))
return FALSE
Expand Down
11 changes: 6 additions & 5 deletions code/datums/components/attachment_holder.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

if(!isgun(parent))
return COMPONENT_INCOMPATIBLE
var/obj/item/gun/parent_gun = parent

src.slot_room = slot_room
src.valid_types = valid_types
Expand All @@ -30,9 +31,9 @@
RegisterSignal(parent, COMSIG_ATOM_UPDATE_OVERLAYS, PROC_REF(handle_overlays))

if(length(default_attachments))
for(var/obj/item/attachment/attachment in default_attachments)
var/obj/item/attachment/new_attachment = new(attachment)
INVOKE_ASYNC(src, PROC_REF(do_attach), new_attachment, null)
for(var/attachment in default_attachments)
var/obj/item/attachment/new_attachment = new attachment(parent_gun.loc)
INVOKE_ASYNC(src, PROC_REF(do_attach), new_attachment, null, TRUE)

/datum/component/attachment_holder/proc/handle_overlays(obj/item/parent, list/overlays)
SIGNAL_HANDLER
Expand Down Expand Up @@ -104,7 +105,7 @@
for(var/obj/item/attach as anything in attachments)
SEND_SIGNAL(attach, COMSIG_ATTACHMENT_EXAMINE_MORE, user, examine_list)

/datum/component/attachment_holder/proc/do_attach(obj/item/attachment, mob/user)
/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))
Expand All @@ -114,7 +115,7 @@
to_chat(user, span_notice("[parent] does not contain room for [attachment]!"))
return
slot_room[slot]--
. = SEND_SIGNAL(attachment, COMSIG_ATTACHMENT_ATTACH, parent, user)
. = SEND_SIGNAL(attachment, COMSIG_ATTACHMENT_ATTACH, parent, user, bypass_checks)
if(.)
attachments += attachment
var/atom/parent = src.parent
Expand Down
12 changes: 9 additions & 3 deletions code/game/objects/items/attachments/_attachment.dm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
var/pixel_shift_y = 16

var/spread_mod = 0
var/spread_unwielded_mod = 0
var/wield_delay = 0
var/size_mod = 0

/obj/item/attachment/Initialize()
. = ..()
Expand Down Expand Up @@ -75,8 +78,11 @@
/obj/item/attachment/proc/apply_modifiers(obj/item/gun/gun, mob/user, attaching)
if(attaching)
gun.spread += spread_mod
gun.spread_unwielded += spread_mod
gun.spread_unwielded += spread_unwielded_mod
gun.wield_delay += wield_delay
gun.w_class += size_mod
else
gun.spread -= spread_mod
gun.spread_unwielded -= spread_mod

gun.spread_unwielded -= spread_unwielded_mod
gun.wield_delay -= wield_delay
gun.w_class -= size_mod
5 changes: 3 additions & 2 deletions code/game/objects/items/attachments/bayonet.dm
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
icon_state = "bayonet"
force = 15
throwforce = 10
pixel_shift_x = 1
pixel_shift_y = 4
pickup_sound = 'sound/items/handling/knife1_pickup.ogg'
drop_sound = 'sound/items/handling/knife3_drop.ogg'
hitsound = 'sound/weapons/bladeslice.ogg'
attack_verb = list("slashed", "stabbed", "sliced", "torn", "ripped", "diced", "cut")
sharpness = IS_SHARP_ACCURATE

pixel_shift_x = 1
pixel_shift_y = 4
spread_mod = 1
wield_delay = 0.1 SECONDS

/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))
Expand Down
13 changes: 11 additions & 2 deletions code/game/objects/items/attachments/laser_sight.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
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_HAND|ATTACH_TOGGLE
pixel_shift_x = 1
pixel_shift_y = 4

spread_mod = -1
wield_delay = 0.1 SECONDS

/obj/item/attachment/laser_sight/Toggle(obj/item/gun/gun, mob/user)
. = ..()

if(toggled)
gun.spread -= 3
gun.spread_unwielded -= 3
gun.wield_delay -= 0.3 SECONDS
else
gun.spread += 3
gun.spread_unwielded += 3
gun.wield_delay += 0.3 SECONDS

playsound(user, toggled ? 'sound/weapons/magin.ogg' : 'sound/weapons/magout.ogg', 40, TRUE)
9 changes: 5 additions & 4 deletions code/game/objects/items/attachments/rail_light.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
name = "rail light"
desc = "Rail mounted gun light for better visibility down range."
icon_state = "raillight"
attach_features_flags = ATTACH_REMOVABLE_HAND|ATTACH_TOGGLE
pixel_shift_x = 1
pixel_shift_y = 4

light_color = "#FFCC66"
light_system = MOVABLE_LIGHT_DIRECTIONAL
light_range = 4
light_power = 0.8
light_on = FALSE

attach_features_flags = ATTACH_REMOVABLE_HAND|ATTACH_TOGGLE
pixel_shift_x = 1
pixel_shift_y = 4
wield_delay = 0.1 SECONDS

/obj/item/attachment/rail_light/Toggle(obj/item/gun/gun, mob/user)
. = ..()
set_light_on(toggled)
Expand Down
3 changes: 2 additions & 1 deletion code/game/objects/items/attachments/silencer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
name = "silencer"
desc = "For when you need to kill someone but not be seen killing someone!"
icon_state = "silencer"

slot = ATTACHMENT_SLOT_MUZZLE
pixel_shift_x = 1
pixel_shift_y = 2

spread_mod = -1
size_mod = 1

/obj/item/attachment/silencer/Attach(obj/item/gun/gun, mob/user)
. = ..()
Expand Down

0 comments on commit 1ac8243

Please sign in to comment.