From 855df65ba225b4b2c4204799f3cfa4a64404016e Mon Sep 17 00:00:00 2001 From: DeltaFire Date: Tue, 16 Nov 2021 22:56:31 +0100 Subject: [PATCH] cord cell charge --- code/modules/power/cell.dm | 17 ----- code/modules/surgery/organs/augments_arms.dm | 68 ++++++++++++++------ 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/code/modules/power/cell.dm b/code/modules/power/cell.dm index 0af16013ec..02c8b666bc 100644 --- a/code/modules/power/cell.dm +++ b/code/modules/power/cell.dm @@ -187,23 +187,6 @@ /obj/item/stock_parts/cell/get_part_rating() return rating * maxcharge -// stuff so ipcs and synthlizards can eat power cells, taken from how moths can eat clothing -/obj/item/reagent_containers/food/snacks/cell - name = "oops" - desc = "If you're reading this it means I messed up. This is related to ipcs/synths eating cells and I didn't know a better way to do it than making a new food object." - list_reagents = list(/datum/reagent/consumable/nutriment = 0.5) - tastes = list("electricity" = 1, "metal" = 1) - -/obj/item/stock_parts/cell/attack(mob/M, mob/user, def_zone) - if(user.a_intent != INTENT_HARM && isrobotic(M)) - var/obj/item/reagent_containers/food/snacks/cell/cell_as_food = new - cell_as_food.name = name - if(cell_as_food.attack(M, user, def_zone)) - take_damage(40, sound_effect=FALSE) - qdel(cell_as_food) - else - return ..() - /* Cell variants*/ /obj/item/stock_parts/cell/empty start_charged = FALSE diff --git a/code/modules/surgery/organs/augments_arms.dm b/code/modules/surgery/organs/augments_arms.dm index e3c32ad009..0d2659dff8 100644 --- a/code/modules/surgery/organs/augments_arms.dm +++ b/code/modules/surgery/organs/augments_arms.dm @@ -326,49 +326,79 @@ desc = "An internal power cord hooked up to a battery. Useful if you run on electricity. Not so much otherwise." icon = 'icons/obj/power.dmi' icon_state = "wire1" + var/in_use = FALSE //No stacking doafters /obj/item/apc_powercord/afterattack(atom/target, mob/user, proximity_flag, click_parameters) - if(!istype(target, /obj/machinery/power/apc) || !ishuman(user) || !proximity_flag) + if((!istype(target, /obj/machinery/power/apc) && !istype(target, /obj/item/stock_parts/cell)) || !ishuman(user) || !proximity_flag) return ..() user.DelayNextAction(CLICK_CD_MELEE) - var/obj/machinery/power/apc/A = target var/mob/living/carbon/human/H = user + if(in_use) + to_chat(H, "[src] is already connected to something!") + return var/obj/item/organ/stomach/ipc/cell = locate(/obj/item/organ/stomach/ipc) in H.internal_organs if(!cell) - to_chat(H, "You try to siphon energy from the [A], but your power cell is gone!") + to_chat(H, "You try to siphon energy from [target], but your power cell is gone!") return - - if(A.cell && A.cell.charge > 0) - if(H.nutrition >= NUTRITION_LEVEL_WELL_FED) - to_chat(user, "You are already fully charged!") + if(H.nutrition >= NUTRITION_LEVEL_WELL_FED) + to_chat(user, "You are already fully charged!") + return + if(istype(target, /obj/machinery/power/apc)) + var/obj/machinery/power/apc/A = target + if(A.cell && A.cell.charge > 0) + in_use = TRUE + apc_powerdraw_loop(A, H) return - else - powerdraw_loop(A, H) + else //We only let through cells and APCs, so this has to be a cell + var/obj/item/stock_parts/cell/C = target + if(C.charge > 0) + in_use = TRUE + cell_powerdraw_loop(C, H) return - to_chat(user, "There is no charge to draw from that APC.") + to_chat(user, "There is no charge to draw from [target].") -/obj/item/apc_powercord/proc/powerdraw_loop(obj/machinery/power/apc/A, mob/living/carbon/human/H) - H.visible_message("[H] inserts a power connector into the [A].", "You begin to draw power from the [A].") +/obj/item/apc_powercord/proc/apc_powerdraw_loop(obj/machinery/power/apc/A, mob/living/carbon/human/H) + H.visible_message("[H] inserts a power connector into [A].", "You begin to draw power from [A].") while(do_after(H, 10, target = A)) if(loc != H) to_chat(H, "You must keep your connector out while charging!") break if(A.cell.charge == 0) - to_chat(H, "The [A] doesn't have enough charge to spare.") + to_chat(H, "[A] doesn't have enough charge to spare.") break A.charging = 1 if(A.cell.charge >= 500) do_sparks(1, FALSE, A) - H.nutrition += 50 - A.cell.charge -= 150 + H.adjust_nutrition(50) + A.cell.use(150) to_chat(H, "You siphon off some of the stored charge for your own use.") else - H.nutrition += A.cell.charge/10 - A.cell.charge = 0 - to_chat(H, "You siphon off as much as the [A] can spare.") + H.adjust_nutrition(A.cell.charge/10) + A.cell.use(A.cell.charge) + to_chat(H, "You siphon off as much as [A] can spare.") break if(H.nutrition > NUTRITION_LEVEL_WELL_FED) to_chat(H, "You are now fully charged.") break - H.visible_message("[H] unplugs from the [A].", "You unplug from the [A].") + in_use = FALSE + H.visible_message("[H] unplugs from [A].", "You unplug from [A].") + +/obj/item/apc_powercord/proc/cell_powerdraw_loop(obj/item/stock_parts/cell/C, mob/living/carbon/human/H) + H.visible_message("[H] connects a power cord to [C]", "You begin to draw power from [C].") + while(do_after(H, 10, target = C)) + if(loc != H) + to_chat(H, "You must keep your connector out while charging!") + break + if(C.charge == 0) + to_chat(H, "[C] doesn't have any charge remaining.") + break + var/siphoned_charge = min(C.charge, 2000) + C.use(siphoned_charge) + do_sparks(1, FALSE, C) + H.adjust_nutrition(siphoned_charge / 100) //Less efficient on a pure power basis than APC recharge. Still a very viable way of gaining nutrition. (100 nutrition / base 10k cell) + if(H.nutrition > NUTRITION_LEVEL_WELL_FED) + to_chat(H, "You are now fully charged.") + break + in_use = FALSE + H.visible_message("[H] disconnects [src] from [C].", "You disconnect from [C].")