Files
Bubberstation/code/datums/elements/pet_bonus.dm
T
BloopandGitHub fc0a1f4068 Removes timeout_mod arg from add_mood_effect (#80964)
## About The Pull Request

Partial Revert of https://github.com/tgstation/tgstation/pull/80800

Assuming every num passed in the parameters of `add_mood_effect` is a
`timeout_mod` is incorrect, because there can be mood events that take a
numeric arg which is not meant to be multiplied against the timeout.

This leads to the same issue as multiplying it with strings essentially
(in one case, shown below, this results in a negative duration of a
timer).


![image](https://github.com/tgstation/tgstation/assets/13398309/f8af858f-04ef-4144-9a0b-2fae60b71272)


![Code_ZN176cpMqA](https://github.com/tgstation/tgstation/assets/13398309/a6ec7689-0171-4909-91cb-a17b56454eb6)

Plus having a keyword arg that may or may not actually be what the
keyword arg claims to be is really confusing and bad.

Instead here's what I propose: passing in an instantiated mood datum
itself, which has been modified, and copying the timeout from it before
discarding it.

It is not as clean as I'd prefer either, but at least it's logically
sound and the intent is clear, and it's the best I can think of short of
a major refactor of the entire system for this one small thing which is
only being used by food quality.


![image](https://github.com/tgstation/tgstation/assets/13398309/8560c066-bb0b-4066-af94-372d5ea62679)

## Why It's Good For The Game

Clearer, less smelly code.

## Changelog

🆑
code: removed the timeout_mod arg from add_mood_event, which was only
used for one thing and causes more issues than it's worth
/🆑
2024-01-16 20:57:42 +01:00

40 lines
1.3 KiB
Plaintext

/**
* # Pet bonus element!
*
* Bespoke element that plays a fun message, sends a heart out, and gives a stronger mood bonus when you pet this animal.
* I may have been able to make this work for carbons, but it would have been interjecting on some help mode interactions anyways.
*/
/datum/element/pet_bonus
element_flags = ELEMENT_BESPOKE
argument_hash_start_idx = 2
///optional cute message to send when you pet your pet!
var/emote_message
///actual moodlet given, defaults to the pet animal one
var/moodlet
/datum/element/pet_bonus/Attach(datum/target, emote_message, moodlet = /datum/mood_event/pet_animal)
. = ..()
if(!isliving(target))
return ELEMENT_INCOMPATIBLE
src.emote_message = emote_message
src.moodlet = moodlet
RegisterSignal(target, COMSIG_ATOM_ATTACK_HAND, PROC_REF(on_attack_hand))
/datum/element/pet_bonus/Detach(datum/target)
. = ..()
UnregisterSignal(target, COMSIG_ATOM_ATTACK_HAND)
/datum/element/pet_bonus/proc/on_attack_hand(mob/living/pet, mob/living/petter, list/modifiers)
SIGNAL_HANDLER
if(pet.stat != CONSCIOUS || petter.combat_mode || LAZYACCESS(modifiers, RIGHT_CLICK))
return
new /obj/effect/temp_visual/heart(pet.loc)
SEND_SIGNAL(pet, COMSIG_ANIMAL_PET, petter, modifiers)
if(emote_message && prob(33))
pet.manual_emote(emote_message)
petter.add_mood_event("petting_bonus", moodlet, pet)