From cbc45c1336696dd33b60bfc58b0e7f74d5bdca23 Mon Sep 17 00:00:00 2001 From: BiancaWilkson <42818125+BiancaWilkson@users.noreply.github.com> Date: Mon, 11 Dec 2023 11:53:11 -0500 Subject: [PATCH] Pneumatic Cannon Refactor (#22956) * camelcase and snakecase on the same line... * the rest, i dunno * PERIODDDDTTTTTT Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com> * the * new variable name * don't need that * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> * lewc's suggestions + new fun var to play with * Update code/game/objects/items/weapons/pneumaticCannon.dm Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com> * bjam's suggestion * adjusting settings is now a seperate proc * swap some stuff around --------- Co-authored-by: DGamerL <108773801+DGamerL@users.noreply.github.com> Co-authored-by: Luc <89928798+lewcc@users.noreply.github.com> Co-authored-by: Ryan <80364400+Sirryan2002@users.noreply.github.com> --- .../objects/items/weapons/pneumaticCannon.dm | 229 +++++++++--------- code/modules/crafting/recipes.dm | 11 + 2 files changed, 127 insertions(+), 113 deletions(-) diff --git a/code/game/objects/items/weapons/pneumaticCannon.dm b/code/game/objects/items/weapons/pneumaticCannon.dm index ddd1c7a220c..bb7afcb6919 100644 --- a/code/game/objects/items/weapons/pneumaticCannon.dm +++ b/code/game/objects/items/weapons/pneumaticCannon.dm @@ -10,16 +10,26 @@ lefthand_file = 'icons/mob/inhands/guns_lefthand.dmi' righthand_file = 'icons/mob/inhands/guns_righthand.dmi' armor = list(MELEE = 0, BULLET = 0, LASER = 0, ENERGY = 0, BOMB = 0, RAD = 0, FIRE = 60, ACID = 50) - var/maxWeightClass = 20 //The max weight of items that can fit into the cannon - var/loadedWeightClass = 0 //The weight of items currently in the cannon - var/obj/item/tank/internals/tank = null //The gas tank that is drawn from to fire things - var/gasPerThrow = 3 //How much gas is drawn from a tank's pressure to fire - var/list/loadedItems = list() //The items loaded into the cannon that will be fired out - var/pressureSetting = 1 //How powerful the cannon is - higher pressure = more gas but more powerful throws + ///The max weight of items that can fit into the cannon + var/max_weight_class = 20 + ///The weight of items currently in the cannon + var/loaded_weight_class = 0 + ///The gas tank that is drawn from to fire things + var/obj/item/tank/internals/tank = null + ///If the cannon needs a tank at all + var/requires_tank = TRUE + ///How many moles of gas is drawn from a tank's pressure to fire + var/gas_per_throw = 3 + ///The items loaded into the cannon that will be fired out + var/list/loaded_items = list() + ///How powerful the cannon is - higher pressure = more gas but more powerful throws + var/pressure_setting = 1 + ///In case we want a really strong cannon + var/max_pressure_setting = 3 /obj/item/pneumatic_cannon/Destroy() QDEL_NULL(tank) - QDEL_LIST_CONTENTS(loadedItems) + QDEL_LIST_CONTENTS(loaded_items) return ..() /obj/item/pneumatic_cannon/examine(mob/user) @@ -28,148 +38,127 @@ . += "You'll need to get closer to see any more." else if(tank) - . += "[bicon(tank)] It has \the [tank] mounted onto it." - for(var/obj/item/I in loadedItems) - . += "[bicon(I)] It has \the [I] loaded." + . += "[bicon(tank)] It has [tank] mounted onto it." + for(var/obj/item/I in loaded_items) + . += "[bicon(I)] It has [I] loaded." + +/** +* Arguments: +* * I - item to load into the cannon +* * user - the person loading the item in +* Returns: +* * True if item was loaded, false if it failed +*/ +/obj/item/pneumatic_cannon/proc/load_item(obj/item/I, mob/user) + if((loaded_weight_class + I.w_class) > max_weight_class) + to_chat(user, "[I] won't fit into [src]!") + return FALSE + if(I.w_class > w_class) + to_chat(user, "[I] is too large to fit into [src]!") + return FALSE + if(!user.unEquip(I) || I.flags & (ABSTRACT | NODROP | DROPDEL)) + to_chat(user, "You can't put [I] into [src]!") + return FALSE + to_chat(user, "You load [I] into [src].") + loaded_items.Add(I) + loaded_weight_class += I.w_class + I.forceMove(src) + return TRUE + +/obj/item/pneumatic_cannon/wrench_act(mob/living/user, obj/item/I) + adjust_setting(user) + return TRUE + +/obj/item/pneumatic_cannon/proc/adjust_setting(mob/living/user) + if(pressure_setting == max_pressure_setting) + pressure_setting = 1 + else + pressure_setting++ + to_chat(user, "You tweak [src]'s pressure output to [pressure_setting].") /obj/item/pneumatic_cannon/attackby(obj/item/W, mob/user, params) ..() - if(istype(W, /obj/item/tank/internals/) && !tank) + if(istype(W, /obj/item/tank/internals) && !tank) if(istype(W, /obj/item/tank/internals/emergency_oxygen)) - to_chat(user, "\The [W] is too small for \the [src].") + to_chat(user, "[W] is too small for [src].") return - updateTank(W, 0, user) + add_tank(W, user) return if(W.type == type) to_chat(user, "You're fairly certain that putting a pneumatic cannon inside another pneumatic cannon would cause a spacetime disruption.") return - if(istype(W, /obj/item/wrench)) - switch(pressureSetting) - if(1) - pressureSetting = 2 - if(2) - pressureSetting = 3 - if(3) - pressureSetting = 1 - to_chat(user, "You tweak \the [src]'s pressure output to [pressureSetting].") - return - if(loadedWeightClass >= maxWeightClass) - to_chat(user, "\The [src] can't hold any more items!") - return - if(isitem(W)) - var/obj/item/IW = W - if(IW.flags & (ABSTRACT | NODROP | DROPDEL)) - to_chat(user, "You can't put [IW] into [src]!") - return - if((loadedWeightClass + IW.w_class) > maxWeightClass) - to_chat(user, "\The [IW] won't fit into \the [src]!") - return - if(IW.w_class > src.w_class) - to_chat(user, "\The [IW] is too large to fit into \the [src]!") - return - if(!user.unEquip(W)) - return - to_chat(user, "You load \the [IW] into \the [src].") - loadedItems.Add(IW) - loadedWeightClass += IW.w_class - IW.loc = src - return + load_item(W, user) /obj/item/pneumatic_cannon/screwdriver_act(mob/living/user, obj/item/I) - if(!tank) - return - - updateTank(tank, 1, user) + remove_tank(user) return TRUE /obj/item/pneumatic_cannon/afterattack(atom/target, mob/living/carbon/human/user, flag, params) if(isstorage(target)) //So you can store it in backpacks return ..() - if(istype(target, /obj/structure/closet)) //So you can store it in closets - return ..() if(istype(target, /obj/structure/rack)) //So you can store it on racks return ..() if(!istype(user)) return ..() - Fire(user, target) + fire(user, target) -/obj/item/pneumatic_cannon/proc/Fire(mob/living/carbon/human/user, atom/target) +/obj/item/pneumatic_cannon/proc/fire(mob/living/carbon/human/user, atom/target) if(!istype(user) && !target) return - var/discharge = 0 - if(!loadedItems || !loadedWeightClass) - to_chat(user, "\The [src] has nothing loaded.") - return - if(!tank) - to_chat(user, "\The [src] can't fire without a source of gas.") - return - if(tank && !tank.air_contents.remove(gasPerThrow * pressureSetting)) - to_chat(user, "\The [src] lets out a weak hiss and doesn't react!") + var/has_discharged = FALSE + if(!loaded_items || !loaded_weight_class) + to_chat(user, "[src] has nothing loaded.") return + if(requires_tank) + if(!tank) + to_chat(user, "[src] can't fire without a source of gas.") + return + if(!tank.air_contents.boolean_remove(gas_per_throw * pressure_setting)) + to_chat(user, "[src] lets out a weak hiss and doesn't react!") + return if(user && HAS_TRAIT(user, TRAIT_CLUMSY) && prob(75)) user.visible_message("[user] loses [user.p_their()] grip on [src], causing it to go off!", "[src] slips out of your hands and goes off!") user.drop_item() + has_discharged = TRUE if(prob(10)) - target = get_turf(user) + target = user else var/list/possible_targets = range(3,src) target = pick(possible_targets) - discharge = 1 - if(!discharge) - user.visible_message("[user] fires \the [src]!", \ - "You fire \the [src]!") + if(!has_discharged) + user.visible_message("[user] fires [src]!", \ + "You fire [src]!") add_attack_logs(user, target, "Fired [src]") - playsound(src.loc, 'sound/weapons/sonic_jackhammer.ogg', 50, 1) - for(var/obj/item/ITD in loadedItems) //Item To Discharge - spawn(0) - loadedItems.Remove(ITD) - loadedWeightClass -= ITD.w_class - ITD.throw_speed = pressureSetting * 2 - ITD.loc = get_turf(src) - ITD.throw_at(target, pressureSetting * 5, pressureSetting * 2,user) - if(pressureSetting >= 3 && user) + playsound(loc, 'sound/weapons/sonic_jackhammer.ogg', 50, TRUE) + for(var/obj/item/loaded_item in loaded_items) + loaded_items.Remove(loaded_item) + loaded_weight_class -= loaded_item.w_class + loaded_item.throw_speed = pressure_setting * 2 + loaded_item.forceMove(get_turf(src)) + loaded_item.throw_at(target, pressure_setting * 5, pressure_setting * 2, user) + if(pressure_setting >= 3 && user) user.visible_message("[user] is thrown down by the force of the cannon!", "[src] slams into your shoulder, knocking you down!") - user.Weaken(3) + user.KnockDown(3 SECONDS) +/obj/item/pneumatic_cannon/proc/add_tank(obj/item/tank/new_tank, mob/living/carbon/human/user) + if(tank) + to_chat(user, "[src] already has a tank.") + return + if(!user.unEquip(new_tank)) + return + to_chat(user, "You hook [new_tank] up to [src].") + new_tank.forceMove(src) + tank = new_tank + update_icons() -/obj/item/pneumatic_cannon/ghetto //Obtainable by improvised methods; more gas per use, less capacity, but smaller - name = "improvised pneumatic cannon" - desc = "A gas-powered, object-firing cannon made out of common parts." - force = 5 - w_class = WEIGHT_CLASS_NORMAL - maxWeightClass = 7 - gasPerThrow = 5 - -/datum/crafting_recipe/improvised_pneumatic_cannon //Pretty easy to obtain but - name = "Pneumatic Cannon" - result = list(/obj/item/pneumatic_cannon/ghetto) - tools = list(TOOL_WELDER, TOOL_WRENCH) - reqs = list(/obj/item/stack/sheet/metal = 4, - /obj/item/stack/packageWrap = 8, - /obj/item/pipe = 2) - time = 300 - category = CAT_WEAPONRY - subcategory = CAT_WEAPON - -/obj/item/pneumatic_cannon/proc/updateTank(obj/item/tank/thetank, removing = 0, mob/living/carbon/human/user) - if(removing) - if(!src.tank) - return - to_chat(user, "You detach \the [thetank] from \the [src].") - src.tank.loc = get_turf(user) - user.put_in_hands(tank) - src.tank = null - if(!removing) - if(src.tank) - to_chat(user, "\The [src] already has a tank.") - return - if(!user.unEquip(thetank)) - return - to_chat(user, "You hook \the [thetank] up to \the [src].") - src.tank = thetank - thetank.loc = src - src.update_icons() +/obj/item/pneumatic_cannon/proc/remove_tank(mob/living/carbon/human/user) + if(!tank) + return FALSE + to_chat(user, "You detach [tank] from [src].") + user.put_in_hands(tank) + tank = null + update_icons() /obj/item/pneumatic_cannon/proc/update_icons() src.overlays.Cut() @@ -177,3 +166,17 @@ return src.overlays += image('icons/obj/pneumaticCannon.dmi', "[tank.icon_state]") src.update_icon() + +/obj/item/pneumatic_cannon/admin + name = "admin pnuematic cannon" + desc = "Infinite gas and infinite capacity, go crazy." + requires_tank = FALSE + max_weight_class = INFINITY + +/obj/item/pneumatic_cannon/ghetto //Obtainable by improvised methods; more gas per use, less capacity, but smaller + name = "improvised pneumatic cannon" + desc = "A gas-powered, object-firing cannon made out of common parts." + force = 5 + w_class = WEIGHT_CLASS_NORMAL + max_weight_class = 7 + gas_per_throw = 5 diff --git a/code/modules/crafting/recipes.dm b/code/modules/crafting/recipes.dm index e7f85338775..d61c901d1e5 100644 --- a/code/modules/crafting/recipes.dm +++ b/code/modules/crafting/recipes.dm @@ -77,6 +77,17 @@ category = CAT_WEAPONRY subcategory = CAT_WEAPON +/datum/crafting_recipe/improvised_pneumatic_cannon + name = "Pneumatic Cannon" + result = list(/obj/item/pneumatic_cannon/ghetto) + tools = list(TOOL_WELDER, TOOL_WRENCH) + reqs = list(/obj/item/stack/sheet/metal = 4, + /obj/item/stack/packageWrap = 8, + /obj/item/pipe = 2) + time = 300 + category = CAT_WEAPONRY + subcategory = CAT_WEAPON + /datum/crafting_recipe/throwing_croissant name = "Throwing croissant" reqs = list(