diff --git a/code/game/objects/items/stunbaton.dm b/code/game/objects/items/stunbaton.dm
index f21d69fcfb..8a7a638539 100644
--- a/code/game/objects/items/stunbaton.dm
+++ b/code/game/objects/items/stunbaton.dm
@@ -46,7 +46,7 @@
/obj/item/melee/baton/loaded //this one starts with a cell pre-installed.
preload_cell_type = /obj/item/stock_parts/cell/high
-/obj/item/melee/baton/proc/deductcharge(chrgdeductamt, chargecheck = TRUE)
+/obj/item/melee/baton/proc/deductcharge(chrgdeductamt, chargecheck = TRUE, explode = TRUE)
var/obj/item/stock_parts/cell/copper_top = cell
if(iscyborg(loc))
var/mob/living/silicon/robot/R = loc
@@ -56,8 +56,9 @@
return FALSE
//Note this value returned is significant, as it will determine
//if a stun is applied or not
- . = copper_top.use(chrgdeductamt)
- if(status && (!. || (chargecheck && copper_top.charge < hitcost * STUNBATON_CHARGE_LENIENCY)))
+
+ copper_top.use(min(chrgdeductamt, copper_top.charge), explode)
+ if(status && (!copper_top.charge || (chargecheck && copper_top.charge < (hitcost * STUNBATON_CHARGE_LENIENCY))))
//we're below minimum, turn off
switch_status(FALSE)
@@ -73,7 +74,8 @@
update_icon()
/obj/item/melee/baton/process()
- deductcharge(hitcost * 0.004, FALSE)
+ . = ..()
+ deductcharge(hitcost * 0.004, FALSE, FALSE)
/obj/item/melee/baton/update_icon()
if(status)
@@ -96,7 +98,7 @@
if(cell)
to_chat(user, "[src] already has a cell.")
else
- if(C.maxcharge < hitcost * STUNBATON_CHARGE_LENIENCY)
+ if(C.maxcharge < (hitcost * STUNBATON_CHARGE_LENIENCY))
to_chat(user, "[src] requires a higher capacity cell.")
return
if(!user.transferItemToLoc(W, src))
@@ -116,15 +118,19 @@
return ..()
/obj/item/melee/baton/attack_self(mob/user)
- if(cell && cell.charge > hitcost * STUNBATON_CHARGE_LENIENCY)
- switch_status(!status)
- to_chat(user, "[src] is now [status ? "on" : "off"].")
- else
+ var/obj/item/stock_parts/cell/copper_top = cell
+ if(iscyborg(loc))
+ var/mob/living/silicon/robot/R = loc
+ copper_top = R.cell
+ if(!copper_top || copper_top.charge < (hitcost * STUNBATON_CHARGE_LENIENCY))
switch_status(FALSE, TRUE)
- if(!cell)
+ if(!copper_top)
to_chat(user, "[src] does not have a power source!")
else
to_chat(user, "[src] is out of charge.")
+ else
+ switch_status(!status)
+ to_chat(user, "[src] is now [status ? "on" : "off"].")
add_fingerprint(user)
/obj/item/melee/baton/attack(mob/M, mob/living/carbon/human/user)
@@ -176,10 +182,12 @@
return FALSE
var/stuncharge = our_cell.charge
deductcharge(hitcost, FALSE)
+ if(QDELETED(src)) //it was rigged
+ return
if(stuncharge < hitcost)
- if(stuncharge < hitcost * STUNBATON_CHARGE_LENIENCY)
- L.visible_message("[user] has prodded [L] with [src]. Luckily it din't have enough charge left.", \
- "[user] has prodded you with [src]. Luckily it din't have enough charge left.")
+ if(stuncharge < (hitcost * STUNBATON_CHARGE_LENIENCY))
+ L.visible_message("[user] has prodded [L] with [src]. Luckily it is out of charge.", \
+ "[user] has prodded you with [src]. Luckily it is out of charge.")
return FALSE
stunpwr *= round(stuncharge/hitcost, 0.1)
@@ -214,7 +222,7 @@
. = ..()
if (!(. & EMP_PROTECT_SELF))
switch_status(FALSE)
- deductcharge(1000 / severity)
+ deductcharge(1000 / severity, TRUE, FALSE)
//Makeshift stun baton. Replacement for stun gloves.
/obj/item/melee/baton/cattleprod
diff --git a/code/modules/power/cell.dm b/code/modules/power/cell.dm
index b6473b8913..5c1df573b3 100644
--- a/code/modules/power/cell.dm
+++ b/code/modules/power/cell.dm
@@ -69,8 +69,8 @@
return 100*charge/maxcharge
// use power from a cell
-/obj/item/stock_parts/cell/use(amount)
- if(rigged && amount > 0)
+/obj/item/stock_parts/cell/use(amount, can_explode = TRUE)
+ if(rigged && amount > 0 && can_explode)
explode()
return 0
if(charge < amount)