fixing runtime errors when removing a brain with skillchips. (#88178)

## About The Pull Request
The organs code changes bundled with the organ fishing PR have broken a
few things, while unveiling a bunch of other problems that flew under
the radar. This concern the first category actually. Anyway, I've also
included a unit test to ensure this won't be an inssue in the future.

## Why It's Good For The Game
Fixing some errors.
This commit is contained in:
Ghom
2024-12-03 18:10:46 -06:00
committed by GitHub
parent ba9e3a0219
commit ee96509686
3 changed files with 30 additions and 8 deletions
@@ -97,25 +97,28 @@
* Arguments:
* * silent - Boolean. Whether or not an activation message should be shown to the user.
* * force - Boolean. Whether or not to just force de-activation if it would be prevented for any reason.
* * brain_owner - the owner var of the brain is set to null on organ/on_mob_remove(), so we need this if owner is null.
*/
/obj/item/skillchip/proc/try_deactivate_skillchip(silent = FALSE, force = FALSE)
/obj/item/skillchip/proc/try_deactivate_skillchip(silent = FALSE, force = FALSE, mob/living/brain_owner)
if(!active)
return "Skillchip is not active."
// Should not happen. Holding brain is destroyed and the chip hasn't had its state set appropriately.
if(!holding_brain)
stack_trace("Skillchip's owner is null or qdeleted brain.")
stack_trace("Skillchip doesn't have a holding brain.")
return "Skillchip cannot detect viable brain."
if(!brain_owner)
brain_owner = holding_brain.owner
// Also should not happen. We're somehow deactivating skillchips in a bodyless brain.
if(QDELETED(holding_brain.owner))
if(QDELETED(brain_owner))
active = FALSE
stack_trace("Skillchip's brain has no owner, owner is null or owner qdeleted.")
return "Skillchip cannot detect viable body."
// We have a holding brain, the holding brain has an owner. If we're forcing this, do it hard and fast.
if(force)
on_deactivate(holding_brain.owner, silent)
on_deactivate(brain_owner, silent)
return
// Is the chip still experiencing a cooldown period?
@@ -123,7 +126,7 @@
return "Skillchip is still recharging for [COOLDOWN_TIMELEFT(src, chip_cooldown) * 0.1]s"
// We're good to go. Deactive this chip.
on_deactivate(holding_brain.owner, silent)
on_deactivate(brain_owner, silent)
/**
* Called when a skillchip is inserted in a user's brain.