mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 04:30:44 +01:00
On the tin, doing it like this means we can reduce our overall line fingerprint whenever we have to add two or more traits from the same source on the same target. Especially helps when we get to the 4+ range of traits, a breath of fresh air even. Doesn't mean we have to do for loops, as that's already handled within the define as well. I replaced some of the checks with `length()` checks, let me know if I should switch it over to something else (maybe `islist()`)? We stack_trace whenever we're not passed a list reference on purpose, and sometimes var/lists are null by default (or just empty, making this redundant). ## Why It's Good For The Game I commonly feel the urge to write "use `AddTraits()`" or something in reviews, then am sad when I remember it doesn't exist. I will no longer be sad. Can ensure a lot more trait safety as well by using static lists- when both ADD_TRAIT_LIST and REMOVE_TRAIT_LIST re-use the same list, you are confident (from a static point of view) that everything that you want to be adding/removing works. I may have missed a few things where this could be used, but both macros implemented in this PR still use the same framework that was being used in the last four years- so stuff won't break if left untouched. Just a nifty new tool for developers. also fixed up some code in the area, numerous bugs were found and exploded
92 lines
3.2 KiB
Plaintext
92 lines
3.2 KiB
Plaintext
/**
|
|
* organ set bonus element; which makes organs in the same set, all in one person, provide a unique bonus!
|
|
*
|
|
* Used for infused organs!
|
|
*/
|
|
/datum/element/organ_set_bonus
|
|
element_flags = ELEMENT_BESPOKE
|
|
argument_hash_start_idx = 2
|
|
/// Status Effect typepath to instantiate and apply to the mob.
|
|
var/datum/status_effect/organ_set_bonus/bonus_type
|
|
|
|
/datum/element/organ_set_bonus/Attach(datum/target, bonus_type)
|
|
. = ..()
|
|
|
|
if(!isorgan(target))
|
|
return ELEMENT_INCOMPATIBLE
|
|
src.bonus_type = bonus_type
|
|
RegisterSignal(target, COMSIG_ORGAN_IMPLANTED, PROC_REF(on_implanted))
|
|
RegisterSignal(target, COMSIG_ORGAN_REMOVED, PROC_REF(on_removed))
|
|
|
|
/datum/element/organ_set_bonus/Detach(obj/item/organ/target)
|
|
UnregisterSignal(target, list(COMSIG_ORGAN_IMPLANTED, COMSIG_ORGAN_REMOVED))
|
|
if(target.owner)
|
|
UnregisterSignal(target.owner, COMSIG_PARENT_EXAMINE)
|
|
return ..()
|
|
|
|
/datum/element/organ_set_bonus/proc/on_implanted(obj/item/organ/target, mob/living/carbon/receiver)
|
|
SIGNAL_HANDLER
|
|
|
|
var/datum/status_effect/organ_set_bonus/set_bonus = receiver.has_status_effect(bonus_type)
|
|
if(!set_bonus)
|
|
set_bonus = receiver.apply_status_effect(bonus_type)
|
|
set_bonus.set_organs(set_bonus.organs + 1)
|
|
|
|
/datum/element/organ_set_bonus/proc/on_removed(obj/item/organ/target, mob/living/carbon/loser)
|
|
SIGNAL_HANDLER
|
|
|
|
//get status effect or remove it
|
|
var/datum/status_effect/organ_set_bonus/set_bonus = loser.has_status_effect(bonus_type)
|
|
if(set_bonus)
|
|
set_bonus.set_organs(set_bonus.organs - 1)
|
|
|
|
/datum/status_effect/organ_set_bonus
|
|
id = "organ_set_bonus"
|
|
duration = -1
|
|
tick_interval = -1
|
|
alert_type = null
|
|
///how many organs the carbon with this has in the set
|
|
var/organs = 0
|
|
///how many organs in the set you need to enable the bonus
|
|
var/organs_needed = 0
|
|
///if the bonus is active
|
|
var/bonus_active = FALSE
|
|
var/bonus_activate_text = span_notice("??? DNA is deeply infused with you! You've learned how to make error reports!")
|
|
var/bonus_deactivate_text = span_notice("Your DNA is no longer majority ???. You did make an issue report, right?")
|
|
/// Required mob bio-type. Also checks DNA validity it's set to MOB_ORGANIC.
|
|
var/required_biotype = MOB_ORGANIC
|
|
/// A list of traits added to the mob upon bonus activation, can be of any length.
|
|
var/list/bonus_traits = list()
|
|
|
|
/datum/status_effect/organ_set_bonus/proc/set_organs(new_value)
|
|
organs = new_value
|
|
if(!organs) //initial value but won't kick in without calling the setter
|
|
qdel(src)
|
|
if(organs >= organs_needed)
|
|
if(!bonus_active)
|
|
INVOKE_ASYNC(src, PROC_REF(enable_bonus))
|
|
else if(bonus_active)
|
|
INVOKE_ASYNC(src, PROC_REF(disable_bonus))
|
|
|
|
/datum/status_effect/organ_set_bonus/proc/enable_bonus()
|
|
SHOULD_CALL_PARENT(TRUE)
|
|
if(required_biotype)
|
|
if(!(owner.mob_biotypes & required_biotype))
|
|
return FALSE
|
|
if((required_biotype == MOB_ORGANIC) && !owner.can_mutate())
|
|
return FALSE
|
|
bonus_active = TRUE
|
|
if(length(bonus_traits))
|
|
owner.add_traits(bonus_traits, REF(src))
|
|
if(bonus_activate_text)
|
|
to_chat(owner, bonus_activate_text)
|
|
return TRUE
|
|
|
|
/datum/status_effect/organ_set_bonus/proc/disable_bonus()
|
|
SHOULD_CALL_PARENT(TRUE)
|
|
bonus_active = FALSE
|
|
if(length(bonus_traits))
|
|
owner.remove_traits(bonus_traits, REF(src))
|
|
if(bonus_deactivate_text)
|
|
to_chat(owner, bonus_deactivate_text)
|