Files
Bubberstation/code/datums/components/beetlejuice.dm
Tim 48e36ef2c7 Saycode refactor, unit tests, and fixes (#69799)
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request

<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

Fixes #69798
Fixes #71621

When using hypnosis on a victim, the language should be accounted for
and whether the victim can properly hear it. Before the hearing code
would magically translate any message, this is no longer the case.

This also fixes the language barrier involving hearing for:
- Mind echo trauma
- Phobia trauma
- Hypnotic trigger trauma
- Split Personality brainwashing trauma
- Codeword hearing
- Hypnotize status effect
- Impure Inacusiate reagent

## Why It's Good For The Game

<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

Better consistency, improved readability, and less bugs in the future.

## Changelog

<!-- If your PR modifies aspects of the game that can be concretely
observed by players or admins you should add a changelog. If your change
does NOT meet this description, remove this section. Be sure to properly
mark your PRs to prevent unnecessary GBP loss. You can read up on GBP
and it's effects on PRs in the tgstation guides for contributors. Please
note that maintainers freely reserve the right to remove and add tags
should they deem it appropriate. You can attempt to finagle the system
all you want, but it's best to shoot for clear communication right off
the bat. -->

🆑
fix: Fix hypnosis, mind echo trauma, phobia trauma, hypnotic trigger
trauma, split personality brainwashing trauma, codeword hearing, and
impure inacusiate reagent all bypassing language and hearing checks. If
you try to give commands to a victim in a language they don't
understand, they will no longer magically understand the words.
fix: Fix sign language having accent modifications
refactor: Refactored saycode to be more robust, readable, and have more
unit tests.
/🆑

<!-- Both 🆑's are required for the changelog to work! You can put
your name to the right of the first 🆑 if you want to overwrite your
GitHub username as author ingame. -->
<!-- You can use multiple of the same prefix (they're only used for the
icon ingame) and delete the unneeded ones. Despite some of the tags,
changelogs should generally represent how a player might be affected by
the changes rather than a summary of the PR's contents. -->

Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
2022-12-09 20:28:17 +01:00

63 lines
1.6 KiB
Plaintext

/datum/component/beetlejuice
var/keyword
var/list/first_heard
var/list/count
var/max_delay = 3 SECONDS //How fast they need to be said
var/min_count = 3
var/cooldown = 30 SECONDS //Delay between teleports
var/active = TRUE
var/case_sensitive = FALSE
var/regex/R
/datum/component/beetlejuice/Initialize()
if(!ismovable(parent))
return COMPONENT_INCOMPATIBLE
first_heard = list()
count = list()
var/atom/movable/O = parent
keyword = O.name
if(ismob(O))
var/mob/M = parent
keyword = M.real_name
update_regex()
RegisterSignal(SSdcs, COMSIG_GLOB_LIVING_SAY_SPECIAL, PROC_REF(say_react))
/datum/component/beetlejuice/proc/update_regex()
R = regex("[REGEX_QUOTE(keyword)]","g[case_sensitive ? "" : "i"]")
/datum/component/beetlejuice/vv_edit_var(var_name, var_value)
. = ..()
if (var_name == NAMEOF(src, keyword) || var_name == NAMEOF(src, case_sensitive))
update_regex()
/datum/component/beetlejuice/proc/say_react(datum/source, mob/speaker, message)
SIGNAL_HANDLER
if(!speaker || speaker == parent || !message || !active)
return
var/found = R.Find(message)
if(found)
var/occurences = 1
while(R.Find(message))
occurences++
R.next = 1
if(!first_heard[speaker] || (first_heard[speaker] + max_delay < world.time))
first_heard[speaker] = world.time
count[speaker] = 0
count[speaker] += occurences
if(count[speaker] >= min_count)
first_heard -= speaker
count -= speaker
apport(speaker)
/datum/component/beetlejuice/proc/apport(atom/target)
var/atom/movable/AM = parent
do_teleport(AM,get_turf(target))
active = FALSE
addtimer(VARSET_CALLBACK(src, active, TRUE), cooldown)