From fca3d16576f607acd5a8cb7af5d0460892e509b0 Mon Sep 17 00:00:00 2001 From: oranges Date: Mon, 25 Feb 2019 05:31:44 +0000 Subject: [PATCH] Hypnosis code improvements Hypnosis no longer runtimes forever if it can't generate a valid regex from the user phrase Hypnosis also no longer constantly regenerates the regex and instead just matches using the existing regex --- code/datums/brain_damage/hypnosis.dm | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/code/datums/brain_damage/hypnosis.dm b/code/datums/brain_damage/hypnosis.dm index 61e59026ebb..d3ce57ca672 100644 --- a/code/datums/brain_damage/hypnosis.dm +++ b/code/datums/brain_damage/hypnosis.dm @@ -7,11 +7,17 @@ resilience = TRAUMA_RESILIENCE_SURGERY var/hypnotic_phrase = "" + var/regex/target_phrase /datum/brain_trauma/hypnosis/New(phrase) if(!phrase) qdel(src) hypnotic_phrase = phrase + try + target_phrase = new("(\\b[hypnotic_phrase]\\b)","ig") + catch(var/exception/e) + stack_trace("[e] on [e.file]:[e.line]") + qdel(src) ..() /datum/brain_trauma/hypnosis/on_gain() @@ -43,6 +49,5 @@ new /datum/hallucination/chat(owner, TRUE, FALSE, "[hypnotic_phrase]") /datum/brain_trauma/hypnosis/on_hear(message, speaker, message_language, raw_message, radio_freq) - var/regex/target_phrase = new("(\\b[hypnotic_phrase]\\b)","ig") message = target_phrase.Replace(message, "$1") - return message \ No newline at end of file + return message