Skip to content

Commit

Permalink
cherrypicked init saw off behavior from #3213
Browse files Browse the repository at this point in the history
  • Loading branch information
FalloutFalcon committed Sep 24, 2024
1 parent 243ce9e commit 339a810
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 52 deletions.
45 changes: 45 additions & 0 deletions code/modules/projectiles/gun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@
muzzle_flash = new(src, muzzleflash_iconstate)
build_zooming()
build_firemodes()
if(sawn_off)
sawoff(forced = TRUE)

/obj/item/gun/ComponentInitialize()
. = ..()
Expand Down Expand Up @@ -1106,3 +1108,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
40 changes: 2 additions & 38 deletions code/modules/projectiles/guns/ballistic.dm
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
update_appearance()
return
if (can_be_sawn_off)
if (sawoff(user, A))
if (try_sawoff(user, A))
return
return FALSE

Expand Down Expand Up @@ -334,43 +334,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, "<span class='warning'>\The [src] is already shortened!</span>")
return
user.changeNext_move(CLICK_CD_MELEE)
user.visible_message("<span class='notice'>[user] begins to shorten \the [src].</span>", "<span class='notice'>You begin to shorten \the [src]...</span>")

//if there's any live ammo inside the gun, makes it go off
if(blow_up(user))
user.visible_message("<span class='danger'>\The [src] goes off!</span>", "<span class='danger'>\The [src] goes off in your face!</span>")
return

if(do_after(user, 30, target = src))
if(sawn_off)
return
user.visible_message("<span class='notice'>[user] shortens \the [src]!</span>", "<span class='notice'>You shorten \the [src].</span>")
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)
Expand Down
4 changes: 2 additions & 2 deletions code/modules/projectiles/guns/ballistic/rifle.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -114,7 +114,7 @@
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"
Expand Down
24 changes: 12 additions & 12 deletions code/modules/projectiles/guns/ballistic/shotgun.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -596,7 +596,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
Expand All @@ -621,7 +621,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"
Expand All @@ -634,7 +634,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"
Expand All @@ -650,7 +650,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
Expand Down Expand Up @@ -682,7 +682,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
Expand Down Expand Up @@ -765,7 +765,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"
Expand All @@ -788,7 +788,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"
Expand Down

0 comments on commit 339a810

Please sign in to comment.