From 59ce9b5ead2f3bf4f013dfb3e75fd17157fe3aa5 Mon Sep 17 00:00:00 2001 From: Chap Date: Wed, 9 Oct 2024 12:47:19 +0200 Subject: [PATCH] [FIX] Prevent duplicate cyborg upgrades (#26731) * Disallows installing duplicate cyborg upgrades. * Prevent duplicate Cyborg modules * Unecessary spacing removed * Update code/game/objects/items/robot/robot_upgrades.dm Co-authored-by: CRUNCH <143041327+Fordoxia@users.noreply.github.com> Signed-off-by: Adrer * usr > user * Move nodrop check into do_install * ... Why did I do that? --------- Signed-off-by: Adrer Co-authored-by: adrermail@gmail.com Co-authored-by: CRUNCH <143041327+Fordoxia@users.noreply.github.com> --- .../objects/items/robot/robot_upgrades.dm | 50 +++++++++---------- .../mob/living/silicon/robot/robot_mob.dm | 6 +-- .../guns/energy/kinetic_accelerator.dm | 5 +- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/code/game/objects/items/robot/robot_upgrades.dm b/code/game/objects/items/robot/robot_upgrades.dm index 777564380bf..4b87c58ff21 100644 --- a/code/game/objects/items/robot/robot_upgrades.dm +++ b/code/game/objects/items/robot/robot_upgrades.dm @@ -17,6 +17,10 @@ var/list/items_to_add = list() /// A list of replacement items will need to be placed into a cyborg module's `special_rechargable` list after this upgrade is installed. var/list/special_rechargables = list() + /// Allow the same upgrade to be installed multiple times, FALSE by default + var/allow_duplicate = FALSE + /// Delete the module after installing it. For deleting upgrades that might be installed multiple times, like the rename/reset upgrades. + var/delete_after_install = FALSE /** * Called when someone clicks on a borg with an upgrade in their hand. @@ -24,12 +28,19 @@ * Arguments: * * R - the cyborg that was clicked on with an upgrade. */ -/obj/item/borg/upgrade/proc/action(mob/living/silicon/robot/R) - if(!pre_install_checks(R)) +/obj/item/borg/upgrade/proc/action(mob/user, mob/living/silicon/robot/R) + if(!pre_install_checks(user, R)) return - if(!do_install(R)) + if(!user.drop_item()) + to_chat(user, "\The [src] is stuck to your hand, you cannot install it in [R]") + return FALSE + if(!do_install(user, R)) return after_install(R) + if(delete_after_install) + qdel(src) + else + forceMove(R) return TRUE /** @@ -38,13 +49,17 @@ * Arguments: * * R - the cyborg that was clicked on with an upgrade. */ -/obj/item/borg/upgrade/proc/pre_install_checks(mob/living/silicon/robot/R) +/obj/item/borg/upgrade/proc/pre_install_checks(mob/user, mob/living/silicon/robot/R) if(R.stat == DEAD) - to_chat(usr, "[src] will not function on a deceased cyborg.") + to_chat(user, "[src] will not function on a deceased cyborg.") return if(module_type && !istype(R.module, module_type)) - to_chat(R, "Upgrade mounting error! No suitable hardpoint detected!") - to_chat(usr, "There's no mounting point for the module!") + to_chat(R, "Upgrade mounting error! No suitable hardpoint detected!") + to_chat(user, "There's no mounting point for the module!") + return + var/obj/item/borg/upgrade/u = locate(type) in R + if(u && !allow_duplicate) + to_chat(user, "This unit already has [src] installed!") return return TRUE @@ -89,6 +104,7 @@ desc = "Used to reset a cyborg's module. Destroys any other upgrades applied to the cyborg." icon_state = "cyborg_upgrade1" require_module = TRUE + delete_after_install = TRUE /obj/item/borg/upgrade/reset/do_install(mob/living/silicon/robot/R) R.reset_module() @@ -101,6 +117,7 @@ name = "cyborg reclassification board" desc = "Used to rename a cyborg." icon_state = "cyborg_upgrade1" + delete_after_install = TRUE var/heldname = "default name" /obj/item/borg/upgrade/rename/attack_self(mob/user) @@ -125,6 +142,7 @@ name = "cyborg emergency reboot module" desc = "Used to force a reboot of a disabled-but-repaired cyborg, bringing it back online." icon_state = "cyborg_upgrade1" + delete_after_install = TRUE /obj/item/borg/upgrade/restart/do_install(mob/living/silicon/robot/R) if(R.health < 0) @@ -150,10 +168,6 @@ origin_tech = "engineering=4;powerstorage=4" /obj/item/borg/upgrade/thrusters/do_install(mob/living/silicon/robot/R) - if(R.ionpulse) - to_chat(usr, "This unit already has ion thrusters installed!") - return - R.ionpulse = TRUE return TRUE @@ -170,11 +184,6 @@ var/mob/living/silicon/robot/cyborg /obj/item/borg/upgrade/selfrepair/do_install(mob/living/silicon/robot/R) - var/obj/item/borg/upgrade/selfrepair/U = locate() in R - if(U) - to_chat(usr, "This unit is already equipped with a self-repair module.") - return - cyborg = R icon_state = "selfrepair_off" var/datum/action/A = new /datum/action/item_action/toggle(src) @@ -259,11 +268,6 @@ origin_tech = "engineering=4;materials=5;programming=4" /obj/item/borg/upgrade/vtec/do_install(mob/living/silicon/robot/R) - for(var/obj/item/borg/upgrade/vtec/U in R.contents) - to_chat(R, "A VTEC unit is already installed!") - to_chat(usr, "There's no room for another VTEC unit!") - return - R.slowdown_cap = 3.5 return TRUE @@ -376,10 +380,6 @@ var/mob/living/silicon/robot/cyborg /obj/item/borg/upgrade/floorbuffer/do_install(mob/living/silicon/robot/R) - for(var/obj/item/borg/upgrade/floorbuffer/U in R) - to_chat(R, "A floor buffer unit is already installed!") - to_chat(usr, "There's no room for another floor buffer unit!") - return cyborg = R var/datum/action/A = new /datum/action/item_action/floor_buffer(src) A.Grant(R) diff --git a/code/modules/mob/living/silicon/robot/robot_mob.dm b/code/modules/mob/living/silicon/robot/robot_mob.dm index 223d9cfde8d..ef9af50dc9a 100644 --- a/code/modules/mob/living/silicon/robot/robot_mob.dm +++ b/code/modules/mob/living/silicon/robot/robot_mob.dm @@ -965,11 +965,9 @@ GLOBAL_LIST_INIT(robot_verbs_default, list( else if(!src.module && U.require_module) to_chat(user, "The borg must choose a module before it can be upgraded!") else - if(!user.drop_item()) - return - if(U.action(src)) + if(U.action(user, src)) user.visible_message("[user] applied [U] to [src].", "You apply [U] to [src].") - U.forceMove(src) + else if(istype(W, /obj/item/mmi_radio_upgrade)) if(!opened) diff --git a/code/modules/projectiles/guns/energy/kinetic_accelerator.dm b/code/modules/projectiles/guns/energy/kinetic_accelerator.dm index 70869766e3b..ad85a7e67f7 100644 --- a/code/modules/projectiles/guns/energy/kinetic_accelerator.dm +++ b/code/modules/projectiles/guns/energy/kinetic_accelerator.dm @@ -291,6 +291,7 @@ require_module = TRUE module_type = /obj/item/robot_module/miner usesound = 'sound/items/screwdriver.ogg' + allow_duplicate = TRUE var/denied_type = null var/maximum_of_type = 1 var/cost = 30 @@ -313,12 +314,12 @@ else return ..() -/obj/item/borg/upgrade/modkit/action(mob/living/silicon/robot/R) +/obj/item/borg/upgrade/modkit/action(mob/user, mob/living/silicon/robot/R) if(!..()) return for(var/obj/item/gun/energy/kinetic_accelerator/cyborg/H in R.module.modules) - return install(H, usr) + return install(H, user) /obj/item/borg/upgrade/modkit/proc/install(obj/item/gun/energy/kinetic_accelerator/KA, mob/user) . = TRUE