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
This commit is contained in:
oranges
2019-02-25 05:31:44 +00:00
parent ccc010c05e
commit fca3d16576
+7 -2
View File
@@ -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, "<span class='hypnophrase'>[hypnotic_phrase]</span>")
/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, "<span class='hypnophrase'>$1</span>")
return message
return message