diff --git a/code/game/machinery/machinery.dm b/code/game/machinery/machinery.dm index 86764dddef1..5ec606a0fd8 100644 --- a/code/game/machinery/machinery.dm +++ b/code/game/machinery/machinery.dm @@ -502,6 +502,7 @@ Class Procs: "You apply some [O] at [src]'s damaged areas.") else return ..() + /obj/machinery/proc/exchange_parts(mob/user, obj/item/storage/part_replacer/W) var/shouldplaysound = 0 if((flags & NODECONSTRUCT)) @@ -519,15 +520,23 @@ Class Procs: break for(var/obj/item/stock_parts/B in W.contents) if(istype(B, P) && istype(A, P)) - if(B.rating > A.rating) - W.remove_from_storage(B, src) - W.handle_item_insertion(A, 1) - component_parts -= A - component_parts += B - B.loc = null - to_chat(user, "[A.name] replaced with [B.name].") - shouldplaysound = 1 - break + //If it's cell - check: 1) Max charge is better? 2) Max charge same but current charge better? - If both NO -> next content + if(ispath(B.type, /obj/item/stock_parts/cell)) + var/obj/item/stock_parts/cell/tA = A + var/obj/item/stock_parts/cell/tB = B + if(!(tB.maxcharge > tA.maxcharge) && !((tB.maxcharge == tA.maxcharge) && (tB.charge > tA.charge))) + continue + //If it's not cell and not better -> next content + else if(B.rating <= A.rating) + continue + W.remove_from_storage(B, src) + W.handle_item_insertion(A, 1) + component_parts -= A + component_parts += B + B.loc = null + to_chat(user, "[A.name] replaced with [B.name].") + shouldplaysound = 1 + break RefreshParts() else to_chat(user, display_parts(user))