diff --git a/modular_nova/modules/aesthetics/rack/code/rack.dm b/modular_nova/modules/aesthetics/rack/code/rack.dm index 0e822321d65..7eb25f836e4 100644 --- a/modular_nova/modules/aesthetics/rack/code/rack.dm +++ b/modular_nova/modules/aesthetics/rack/code/rack.dm @@ -6,50 +6,3 @@ desc = "A shelf, for storing things on. Conveinent!" icon = 'modular_nova/modules/aesthetics/rack/icons/rack.dmi' icon_state = "shelf" - -/obj/item/gun - var/on_rack = FALSE - -/obj/item/gun/proc/place_on_rack() - on_rack = TRUE - var/matrix/M = matrix() - M.Turn(-90) - transform = M - -/obj/item/gun/proc/remove_from_rack() - if(on_rack) - var/matrix/M = matrix() - transform = M - on_rack = FALSE - -/obj/item/gun/pickup(mob/user) - . = ..() - remove_from_rack() - -/obj/structure/rack/gunrack - name = "gun rack" - desc = "A gun rack for storing guns." - icon_state = "gunrack" - -/obj/structure/rack/gunrack/Initialize(mapload) - . = ..() - if(mapload) - for(var/obj/item/I in loc.contents) - if(istype(I, /obj/item/gun)) - var/obj/item/gun/to_place = I - to_place.place_on_rack() - -/obj/structure/rack/gunrack/attackby(obj/item/W, mob/living/user, params) - var/list/modifiers = params2list(params) - if (W.tool_behaviour == TOOL_WRENCH && !(obj_flags & NO_DECONSTRUCTION) && LAZYACCESS(modifiers, RIGHT_CLICK)) - W.play_tool_sound(src) - deconstruct(TRUE) - return - if(user.combat_mode) - return ..() - if(user.transferItemToLoc(W, drop_location())) - if(istype(W, /obj/item/gun)) - var/obj/item/gun/our_gun = W - our_gun.place_on_rack() - our_gun.pixel_x = rand(-10, 10) - return TRUE diff --git a/modular_nova/modules/modular_weapons/code/gun_racks.dm b/modular_nova/modules/modular_weapons/code/gun_racks.dm new file mode 100644 index 00000000000..c3678a1c76b --- /dev/null +++ b/modular_nova/modules/modular_weapons/code/gun_racks.dm @@ -0,0 +1,58 @@ +/obj/structure/rack/gunrack + name = "gun rack" + desc = "A tall rack for storing guns." + icon = 'modular_nova/modules/modular_weapons/icons/gun_rack.dmi' + icon_state = "gunrack" + +/obj/structure/rack/gunrack/Initialize(mapload) + . = ..() + var/static/list/loc_connections = list( + COMSIG_ATOM_EXIT = PROC_REF(on_exit), + ) + AddElement(/datum/element/connect_loc, loc_connections) + if(!mapload) + return + for(var/obj/item/found_item in loc.contents) + if(!isgun(found_item)) + continue + rotate_weapon(found_item) + +/obj/structure/rack/gunrack/attackby(obj/item/attacking_item, mob/living/user, params) + var/list/modifiers = params2list(params) + if(attacking_item.tool_behaviour == TOOL_WRENCH && !(obj_flags & NO_DECONSTRUCTION) && LAZYACCESS(modifiers, RIGHT_CLICK)) + attacking_item.play_tool_sound(src) + deconstruct(TRUE) + return + if(user.combat_mode) + return ..() + if(user.transferItemToLoc(attacking_item, drop_location())) + if(istype(attacking_item, /obj/item/gun)) + var/obj/item/gun/our_gun = attacking_item + rotate_weapon(our_gun) + our_gun.pixel_x = rand(-10, 10) + our_gun.base_pixel_x + return TRUE + +/// Rotates the weapon or resets its transform based on the being_removed variable +/obj/structure/rack/gunrack/proc/rotate_weapon(obj/item/incoming_weapon, being_removed = FALSE) + var/matrix/new_matrix = matrix() + if(!being_removed) + new_matrix.Turn(-90) + incoming_weapon.transform = new_matrix + RegisterSignal(incoming_weapon, COMSIG_ITEM_EQUIPPED, PROC_REF(item_picked_up)) + +/// Checks when something is leaving our turf, if its a gun then make sure to reset its transform so its not permanently rotated +/obj/structure/rack/gunrack/proc/on_exit(datum/source, atom/movable/leaving, direction) + SIGNAL_HANDLER + + if(!isgun(leaving)) + return + var/obj/item/leaving_item = leaving + rotate_weapon(leaving_item, TRUE) + +/// Handles the guns being picked up to unrotate them +/obj/structure/rack/gunrack/proc/item_picked_up(datum/source, mob/equipper, slot) + SIGNAL_HANDLER + + var/obj/item/leaving_item = source + rotate_weapon(leaving_item, TRUE) + UnregisterSignal(leaving_item, COMSIG_ITEM_EQUIPPED) diff --git a/modular_nova/modules/modular_weapons/icons/gun_rack.dmi b/modular_nova/modules/modular_weapons/icons/gun_rack.dmi new file mode 100644 index 00000000000..d0c4f0c96fd Binary files /dev/null and b/modular_nova/modules/modular_weapons/icons/gun_rack.dmi differ diff --git a/modular_nova/modules/sec_haul/code/guns/armory_spawns.dm b/modular_nova/modules/sec_haul/code/guns/armory_spawns.dm index 2dd13b95c8a..0d46d561b1d 100644 --- a/modular_nova/modules/sec_haul/code/guns/armory_spawns.dm +++ b/modular_nova/modules/sec_haul/code/guns/armory_spawns.dm @@ -16,27 +16,36 @@ /obj/effect/spawner/armory_spawn/Initialize(mapload) . = ..() - if(guns) - var/gun_count = 0 - var/offset_percent = 20 / guns.len - for(var/gun in guns) // 11/20/21: Gun spawners now spawn 1 of each gun in it's list no matter what, so as to reduce the RNG of the armory stock. - var/obj/item/gun/spawned_gun = new gun(loc) - - if(vertical_guns) - spawned_gun.place_on_rack() - spawned_gun.pixel_x = -10 + (offset_percent * gun_count) - else if (fan_out_items) - spawned_gun.pixel_x = spawned_gun.pixel_y = ((!(gun_count%2)*gun_count/2)*-1)+((gun_count%2)*(gun_count+1)/2*1) - - gun_count++ - - if(istype(spawned_gun, /obj/item/gun/ballistic)) - var/obj/item/gun/ballistic/spawned_ballistic_gun = spawned_gun - if(spawned_ballistic_gun.magazine && !istype(spawned_ballistic_gun.magazine, /obj/item/ammo_box/magazine/internal)) - var/obj/item/storage/box/ammo_box/spawned_box = new(loc) - spawned_box.name = "ammo box - [spawned_ballistic_gun.name]" - for(var/i in 1 to mags_to_spawn) - new spawned_ballistic_gun.spawn_magazine_type (spawned_box) + if(!guns) + return + + var/obj/structure/rack/gunrack/rack_on_tile + for(var/obj/structure/rack/gunrack/found_rack in loc.contents) + rack_on_tile = found_rack + break + + var/gun_count = 0 + var/offset_percent = 20 / guns.len + for(var/gun in guns) // 11/20/21: Gun spawners now spawn 1 of each gun in it's list no matter what, so as to reduce the RNG of the armory stock. + var/obj/item/gun/spawned_gun = new gun(loc) + + if(vertical_guns && rack_on_tile) + rack_on_tile.rotate_weapon(spawned_gun) + spawned_gun.pixel_x = -10 + (offset_percent * gun_count) + spawned_gun.base_pixel_x + else if (fan_out_items) + spawned_gun.pixel_x = spawned_gun.pixel_y = ((!(gun_count%2)*gun_count/2)*-1)+((gun_count%2)*(gun_count+1)/2*1) + + gun_count++ + + if(!istype(spawned_gun, /obj/item/gun/ballistic)) + continue + + var/obj/item/gun/ballistic/spawned_ballistic_gun = spawned_gun + if(spawned_ballistic_gun.magazine && !istype(spawned_ballistic_gun.magazine, /obj/item/ammo_box/magazine/internal)) + var/obj/item/storage/box/ammo_box/spawned_box = new(loc) + spawned_box.name = "ammo box - [spawned_ballistic_gun.name]" + for(var/i in 1 to mags_to_spawn) + new spawned_ballistic_gun.spawn_magazine_type(spawned_box) /obj/effect/spawner/armory_spawn/shotguns guns = list( diff --git a/tgstation.dme b/tgstation.dme index 5a0c546a7a5..659a3392dce 100644 --- a/tgstation.dme +++ b/tgstation.dme @@ -7691,6 +7691,7 @@ #include "modular_nova\modules\modular_weapons\code\conversion_kits.dm" #include "modular_nova\modules\modular_weapons\code\energy.dm" #include "modular_nova\modules\modular_weapons\code\gun_launches_little_guys_element.dm" +#include "modular_nova\modules\modular_weapons\code\gun_racks.dm" #include "modular_nova\modules\modular_weapons\code\gunsets.dm" #include "modular_nova\modules\modular_weapons\code\melee.dm" #include "modular_nova\modules\modular_weapons\code\modular_projectiles.dm"