Fixes Novaflowers not lighting people on fire, again. Unit tests it. Cleans up some unique plant genes stuff too. (#67597)

This commit is contained in:
MrMelbert
2022-06-11 04:04:32 -05:00
committed by GitHub
parent 6e75c07b75
commit c34afedcfc
5 changed files with 182 additions and 121 deletions
+38 -27
View File
@@ -3,7 +3,7 @@
/// If a user is protected with something like leather gloves, they can handle them normally.
/// If they're not protected properly, we invoke a callback on the user, harming or inconveniencing them.
/datum/element/plant_backfire
element_flags = ELEMENT_BESPOKE | ELEMENT_DETACH
element_flags = ELEMENT_BESPOKE
id_arg_index = 2
/// Whether we stop the current action if backfire is triggered (EX: returning CANCEL_ATTACK_CHAIN)
var/cancel_action = FALSE
@@ -29,52 +29,67 @@
. = ..()
UnregisterSignal(target, list(COMSIG_ITEM_PRE_ATTACK, COMSIG_ITEM_PICKUP, COMSIG_MOVABLE_PRE_THROW))
/*
/**
* Checks before we attack if we're okay to continue.
*
* source - our plant
* user - the mob wielding our [source]
*/
/datum/element/plant_backfire/proc/attack_safety_check(datum/source, atom/target, mob/user)
/datum/element/plant_backfire/proc/attack_safety_check(obj/item/source, atom/target, mob/user)
SIGNAL_HANDLER
if(plant_safety_check(source, user))
// Covers stuff like tk, since we aren't actually touching the plant.
if(!user.is_holding(source))
return
if(!backfire(source, user))
return
SEND_SIGNAL(source, COMSIG_PLANT_ON_BACKFIRE, user)
if(cancel_action)
return COMPONENT_CANCEL_ATTACK_CHAIN
/*
return cancel_action ? COMPONENT_CANCEL_ATTACK_CHAIN : NONE
/**
* Checks before we pick up the plant if we're okay to continue.
*
* source - our plant
* user - the mob picking our [source]
*/
/datum/element/plant_backfire/proc/pickup_safety_check(datum/source, mob/user)
/datum/element/plant_backfire/proc/pickup_safety_check(obj/item/source, mob/user)
SIGNAL_HANDLER
if(plant_safety_check(source, user))
return
SEND_SIGNAL(source, COMSIG_PLANT_ON_BACKFIRE, user)
backfire(source, user)
/*
/**
* Checks before we throw the plant if we're okay to continue.
*
* source - our plant
* thrower - the mob throwing our [source]
*/
/datum/element/plant_backfire/proc/throw_safety_check(datum/source, list/arguments)
/datum/element/plant_backfire/proc/throw_safety_check(obj/item/source, list/arguments)
SIGNAL_HANDLER
var/mob/living/thrower = arguments[4] // 4th arg = mob/thrower
if(plant_safety_check(source, thrower))
var/mob/living/thrower = arguments[4] // the 4th arg = the mob throwing our item
if(!thrower.is_holding(source))
return
if(!backfire(source, thrower))
return
SEND_SIGNAL(source, COMSIG_PLANT_ON_BACKFIRE, thrower)
if(cancel_action)
return COMPONENT_CANCEL_THROW
/*
return cancel_action ? COMPONENT_CANCEL_ATTACK_CHAIN : NONE
/**
* The actual backfire occurs here.
* Checks if the user is able to safely handle the plant.
* If not, sends the backfire signal (meaning backfire will occur and be handled by one or multiple genes).
*
* Returns FALSE if the user was safe and no backfire occured.
* Returns TRUE if the user was not safe and a backfire actually happened.
*/
/datum/element/plant_backfire/proc/backfire(obj/item/plant, mob/user)
if(plant_safety_check(plant, user))
return FALSE
SEND_SIGNAL(plant, COMSIG_PLANT_ON_BACKFIRE, user)
return TRUE
/**
* Actually checks if our user is safely handling our plant.
*
* Checks for TRAIT_PLANT_SAFE, and returns TRUE if we have it.
@@ -86,13 +101,10 @@
*
* returns FALSE if none of the checks are successful.
*/
/datum/element/plant_backfire/proc/plant_safety_check(datum/source, mob/living/carbon/user)
/datum/element/plant_backfire/proc/plant_safety_check(obj/item/plant, mob/living/carbon/user)
if(!istype(user))
return TRUE
if(istype(source, /obj/item/tk_grab)) // since we aren't actually touching the plant
return TRUE
if(HAS_TRAIT(user, TRAIT_PLANT_SAFE))
return TRUE
@@ -100,8 +112,7 @@
if(HAS_TRAIT(user, checked_trait))
return TRUE
var/obj/item/parent_item = source
var/obj/item/seeds/our_seed = parent_item.get_plant_seed()
var/obj/item/seeds/our_seed = plant.get_plant_seed()
if(our_seed)
for(var/checked_gene in extra_genes)
if(!our_seed.get_gene(checked_gene))
@@ -220,6 +220,7 @@
SEND_SIGNAL(owner, COMSIG_LIVING_IGNITED, owner)
cache_stacks()
update_overlay()
return TRUE
/**
* Handles mob extinguishing, should be the only way to set on_fire to FALSE