diff --git a/code/game/objects/items/devices/magnetic_lock.dm b/code/game/objects/items/devices/magnetic_lock.dm
index 9b261401..c3376454 100644
--- a/code/game/objects/items/devices/magnetic_lock.dm
+++ b/code/game/objects/items/devices/magnetic_lock.dm
@@ -115,7 +115,11 @@
return
if (istype(I, /obj/item/weapon/crowbar))
user << "You remove \the [powercell] from \the [src]."
- powercell.loc = loc
+ if (ismob(loc))
+ var/mob/M = loc
+ M.put_in_hands(powercell)
+ else
+ powercell.loc = loc
powercell = null
return
if (istype(I, /obj/item/weapon/weldingtool))
@@ -149,6 +153,20 @@
visible_message("[src] beeps loudly and falls off \the [target]; its powercell having run out of power.")
setstatus(STATUS_INACTIVE)
+/obj/item/device/magnetic_lock/update_icon()
+ if (constructionstate && status != STATUS_BROKEN)
+ icon_state = "deconstruct_[constructionstate]"
+ return
+ else
+ switch (status)
+ if (STATUS_INACTIVE)
+ icon_state = "inactive"
+ if (STATUS_ACTIVE)
+ icon_state = "active"
+ if (STATUS_BROKEN)
+ icon_state = "broken"
+ return
+
/obj/item/device/magnetic_lock/proc/attachto(var/obj/machinery/door/airlock/newtarget, var/mob/user as mob)
if (status == STATUS_BROKEN)
user << "[src] is damaged beyond repair! It cannot be used!"
@@ -191,7 +209,6 @@
return
detach()
- icon_state = "inactive"
status = newstatus
if (STATUS_ACTIVE)
@@ -201,7 +218,6 @@
return
attach(newtarget)
- icon_state = "active"
status = newstatus
if (STATUS_BROKEN)
@@ -214,22 +230,19 @@
detach(playflick)
- icon_state = "broken"
status = newstatus
+ update_icon()
+
/obj/item/device/magnetic_lock/proc/setconstructionstate(var/newstate)
constructionstate = newstate
- if (newstate == 0)
- if (status == STATUS_ACTIVE)
- icon_state = "active"
- else
- icon_state = "inactive"
- else if (newstate == 2)
+ if (newstate == 2)
flick("deconstruct_2_anim", src)
- else if (newstate == 4)
+
+ if (newstate == 4)
setstatus(STATUS_BROKEN)
- else
- icon_state = "deconstruct_[constructionstate]"
+
+ update_icon()
/obj/item/device/magnetic_lock/proc/detach(var/playflick = 1)
if (target)
@@ -241,6 +254,7 @@
layer = LAYER_NORMAL
target.bracer = null
+ target = null
processing_objects.Remove(src)