From 852d550b5056473eb2abebc1332c211259603b2a Mon Sep 17 00:00:00 2001 From: FalloutFalcon <86381784+FalloutFalcon@users.noreply.github.com> Date: Sun, 29 Sep 2024 08:29:30 -0500 Subject: [PATCH] sawnoff weapons now call sawoff on init (#3428) ## About The Pull Request you dont have to re declare all your sawn off variables ## Why It's Good For The Game easier sawn off weapons ## Changelog :cl: fix: sawnoff weapons made from init now function correctly /:cl: --- code/modules/projectiles/gun.dm | 45 +++++++++++++++++++ code/modules/projectiles/guns/ballistic.dm | 40 +---------------- .../projectiles/guns/ballistic/rifle.dm | 11 +---- .../projectiles/guns/ballistic/shotgun.dm | 38 +++++----------- 4 files changed, 61 insertions(+), 73 deletions(-) diff --git a/code/modules/projectiles/gun.dm b/code/modules/projectiles/gun.dm index 28ef8cecdd80..94cc4f6f1e38 100644 --- a/code/modules/projectiles/gun.dm +++ b/code/modules/projectiles/gun.dm @@ -331,6 +331,8 @@ muzzle_flash = new(src, muzzleflash_iconstate) build_zooming() build_firemodes() + if(sawn_off) + sawoff(forced = TRUE) /obj/item/gun/ComponentInitialize() . = ..() @@ -1109,3 +1111,46 @@ var/safety_prefix = "[our_gun.adjust_fire_select_icon_state_on_safety ? "[our_gun.safety ? "safety_" : ""]" : ""]" button_icon_state = "[safety_prefix][our_gun.fire_select_icon_state_prefix][current_firemode]" return ..() + +GLOBAL_LIST_INIT(gun_saw_types, typecacheof(list( + /obj/item/gun/energy/plasmacutter, + /obj/item/melee/transforming/energy, + ))) + +///Handles all the logic of sawing off guns, +/obj/item/gun/proc/try_sawoff(mob/user, obj/item/saw) + if(!saw.get_sharpness() || !is_type_in_typecache(saw, GLOB.gun_saw_types) && saw.tool_behaviour != TOOL_SAW) //needs to be sharp. Otherwise turned off eswords can cut this. + return + if(sawn_off) + to_chat(user, span_warning("\The [src] is already shortened!")) + return + user.changeNext_move(CLICK_CD_MELEE) + user.visible_message(span_notice("[user] begins to shorten \the [src]."), span_notice("You begin to shorten \the [src]...")) + + //if there's any live ammo inside the gun, makes it go off + if(blow_up(user)) + user.visible_message(span_danger("\The [src] goes off!"), span_danger("\The [src] goes off in your face!")) + return + + if(do_after(user, 30, target = src)) + user.visible_message(span_notice("[user] shortens \the [src]!"), span_notice("You shorten \the [src].")) + sawoff(user, saw) + +///Used on init or try_sawoff +/obj/item/gun/proc/sawoff(forced = FALSE) + if(sawn_off && !forced) + return + name = "sawn-off [src.name]" + desc = sawn_desc + w_class = WEIGHT_CLASS_NORMAL + item_state = "gun" + slot_flags &= ~ITEM_SLOT_BACK //you can't sling it on your back + slot_flags |= ITEM_SLOT_BELT //but you can wear it on your belt (poorly concealed under a trenchcoat, ideally) + recoil = SAWN_OFF_RECOIL + sawn_off = TRUE + update_appearance() + return TRUE + +///used for sawing guns, causes the gun to fire without the input of the user +/obj/item/gun/proc/blow_up(mob/user) + return diff --git a/code/modules/projectiles/guns/ballistic.dm b/code/modules/projectiles/guns/ballistic.dm index 00f48cc29239..ccc399906365 100644 --- a/code/modules/projectiles/guns/ballistic.dm +++ b/code/modules/projectiles/guns/ballistic.dm @@ -230,7 +230,7 @@ update_appearance() return if (can_be_sawn_off) - if (sawoff(user, A)) + if (try_sawoff(user, A)) return return FALSE @@ -336,43 +336,7 @@ rounds.Add(magazine.ammo_list(drop_all)) return rounds -GLOBAL_LIST_INIT(gun_saw_types, typecacheof(list( - /obj/item/gun/energy/plasmacutter, - /obj/item/melee/transforming/energy, - ))) - -///Handles all the logic of sawing off guns, -/obj/item/gun/ballistic/proc/sawoff(mob/user, obj/item/saw) - if(!saw.get_sharpness() || !is_type_in_typecache(saw, GLOB.gun_saw_types) && saw.tool_behaviour != TOOL_SAW) //needs to be sharp. Otherwise turned off eswords can cut this. - return - if(sawn_off) - to_chat(user, "\The [src] is already shortened!") - return - user.changeNext_move(CLICK_CD_MELEE) - user.visible_message("[user] begins to shorten \the [src].", "You begin to shorten \the [src]...") - - //if there's any live ammo inside the gun, makes it go off - if(blow_up(user)) - user.visible_message("\The [src] goes off!", "\The [src] goes off in your face!") - return - - if(do_after(user, 30, target = src)) - if(sawn_off) - return - user.visible_message("[user] shortens \the [src]!", "You shorten \the [src].") - name = "sawn-off [src.name]" - desc = sawn_desc - w_class = WEIGHT_CLASS_NORMAL - item_state = "gun" - slot_flags &= ~ITEM_SLOT_BACK //you can't sling it on your back - slot_flags |= ITEM_SLOT_BELT //but you can wear it on your belt (poorly concealed under a trenchcoat, ideally) - recoil = SAWN_OFF_RECOIL - sawn_off = TRUE - update_appearance() - return TRUE - -///used for sawing guns, causes the gun to fire without the input of the user -/obj/item/gun/ballistic/proc/blow_up(mob/user) +/obj/item/gun/ballistic/blow_up(mob/user) . = FALSE for(var/obj/item/ammo_casing/AC in magazine.stored_ammo) if(AC.BB) diff --git a/code/modules/projectiles/guns/ballistic/rifle.dm b/code/modules/projectiles/guns/ballistic/rifle.dm index 2be77ee20835..a61413057606 100644 --- a/code/modules/projectiles/guns/ballistic/rifle.dm +++ b/code/modules/projectiles/guns/ballistic/rifle.dm @@ -94,7 +94,7 @@ /obj/item/gun/ballistic/rifle/illestren/empty //i had to name it empty instead of no_mag because else it wouldnt work with guncases. sorry! spawnwithmagazine = FALSE -/obj/item/gun/ballistic/rifle/illestren/sawoff(mob/user) +/obj/item/gun/ballistic/rifle/illestren/sawoff(forced = FALSE) . = ..() if(.) spread = 24 @@ -114,22 +114,15 @@ icon_state = "illestren_factory" item_state = "illestren_factory" -/obj/item/gun/ballistic/rifle/illestren/sawoff(mob/user) +/obj/item/gun/ballistic/rifle/illestren/sawoff(forced = FALSE) . = ..() if(.) item_state = "illestren_factory_sawn" mob_overlay_state = item_state /obj/item/gun/ballistic/rifle/illestren/sawn - name = "sawn-off Illestren rifle" desc = "An Illestren rifle sawn down to a ridiculously small size. There was probably a reason it wasn't made this short to begin with, but it still packs a punch." - item_state = "illestren_sawn" sawn_off = TRUE - weapon_weight = WEAPON_MEDIUM - w_class = WEIGHT_CLASS_NORMAL - spread = 24 - spread_unwielded = 30 - slot_flags = ITEM_SLOT_BELT /obj/item/gun/ballistic/rifle/solgov name = "SSG-669C" diff --git a/code/modules/projectiles/guns/ballistic/shotgun.dm b/code/modules/projectiles/guns/ballistic/shotgun.dm index 2d70bf9851bb..ab85fb9a01c4 100644 --- a/code/modules/projectiles/guns/ballistic/shotgun.dm +++ b/code/modules/projectiles/guns/ballistic/shotgun.dm @@ -74,7 +74,7 @@ can_be_sawn_off = TRUE -/obj/item/gun/ballistic/shotgun/brimstone/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/brimstone/sawoff(forced = FALSE) . = ..() if(.) weapon_weight = WEAPON_MEDIUM @@ -108,7 +108,7 @@ rack_sound = 'sound/weapons/gun/shotgun/rack_alt.ogg' fire_delay = 0.1 SECONDS -/obj/item/gun/ballistic/shotgun/hellfire/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/hellfire/sawoff(forced = FALSE) . = ..() if(.) var/obj/item/ammo_box/magazine/internal/tube = magazine @@ -316,7 +316,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) if(unique_reskin && !current_skin && user.canUseTopic(src, BE_CLOSE, NO_DEXTERITY) && (!bolt_locked)) reskin_obj(user) -/obj/item/gun/ballistic/shotgun/doublebarrel/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/doublebarrel/sawoff(forced = FALSE) . = ..() if(.) weapon_weight = WEAPON_MEDIUM @@ -361,7 +361,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) item_state = "dshotgun_srm" unique_reskin = null -/obj/item/gun/ballistic/shotgun/doublebarrel/roumain/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/doublebarrel/roumain/sawoff(forced = FALSE) . = ..() if(.) item_state = "dshotgun_srm_sawn" @@ -416,7 +416,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) if(sawn_off) . += "ishotgun_sawn" -/obj/item/gun/ballistic/shotgun/doublebarrel/improvised/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/doublebarrel/improvised/sawoff(forced = FALSE) . = ..() if(. && slung) //sawing off the gun removes the sling new /obj/item/stack/cable_coil(get_turf(src), 10) @@ -424,21 +424,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) update_appearance() /obj/item/gun/ballistic/shotgun/doublebarrel/improvised/sawn - name = "sawn-off improvised shotgun" - desc = "A single-shot shotgun. Better not miss." - icon_state = "ishotgun_sawn" - item_state = "ishotgun_sawn" - w_class = WEIGHT_CLASS_NORMAL sawn_off = TRUE - slot_flags = ITEM_SLOT_BELT - - wield_slowdown = 0.25 - wield_delay = 0.3 SECONDS //OP? maybe - - spread = 8 - spread_unwielded = 15 - recoil = 3 //or not - recoil_unwielded = 5 /obj/item/gun/ballistic/shotgun/automatic/combat/compact/compact name = "compact compact combat shotgun" @@ -604,7 +590,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) balloon_alert_to_viewers("quickly racks!") fire_delay = 0 SECONDS -/obj/item/gun/ballistic/shotgun/flamingarrow/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/flamingarrow/sawoff(forced = FALSE) . = ..() if(.) var/obj/item/ammo_box/magazine/internal/tube = magazine @@ -629,7 +615,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) base_icon_state = "flamingarrow_factory" item_state = "flamingarrow_factory" -/obj/item/gun/ballistic/shotgun/flamingarrow/factory/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/flamingarrow/factory/sawoff(forced = FALSE) . = ..() if(.) item_state = "flamingarrow_factory_sawn" @@ -642,7 +628,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) icon_state = "flamingbolt" item_state = "flamingbolt" -/obj/item/gun/ballistic/shotgun/flamingarrow/bolt/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/flamingarrow/bolt/sawoff(forced = FALSE) . = ..() if(.) item_state = "flamingbolt_sawn" @@ -658,7 +644,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) sawn_desc = "A large lever-action rifle, sawn down for portability. It looks much cooler, but you should probably be using a revolver..." mag_type = /obj/item/ammo_box/magazine/internal/shot/winchester/absolution -/obj/item/gun/ballistic/shotgun/flamingarrow/absolution/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/flamingarrow/absolution/sawoff(forced = FALSE) . = ..() if(.) var/obj/item/ammo_box/magazine/internal/tube = magazine @@ -690,7 +676,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) sawn_desc = "A lever action shotgun that's been sawed down for portability. The recoil makes it mostly useless outside of point-blank range, but it hits hard for its size and, more importantly, can be flipped around stylishly." mag_type = /obj/item/ammo_box/magazine/internal/shot/winchester/conflagration -/obj/item/gun/ballistic/shotgun/flamingarrow/conflagration/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/flamingarrow/conflagration/sawoff(forced = FALSE) . = ..() if(.) var/obj/item/ammo_box/magazine/internal/tube = magazine @@ -773,7 +759,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) gun_firemodes = list(FIREMODE_SEMIAUTO) default_firemode = FIREMODE_SEMIAUTO -/obj/item/gun/ballistic/shotgun/doublebarrel/beacon/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/doublebarrel/beacon/sawoff(forced = FALSE) . = ..() if(.) item_state = "beacon_sawn" @@ -796,7 +782,7 @@ EMPTY_GUN_HELPER(shotgun/automatic/bulldog/inteq) icon_state = "beacon_factory" item_state = "beacon_factory" -/obj/item/gun/ballistic/shotgun/doublebarrel/beacon/factory/sawoff(mob/user) +/obj/item/gun/ballistic/shotgun/doublebarrel/beacon/factory/sawoff(forced = FALSE) . = ..() if(.) item_state = "beacon_factory_sawn"