mirror of
https://github.com/Skyrat-SS13/Skyrat-tg.git
synced 2026-08-26 14:28:52 +01:00
[MIRROR] Converts common speech modifiers into a component (#28752)
* Converts common speech modifiers into a component * modular --------- Co-authored-by: SmArtKar <44720187+SmArtKar@users.noreply.github.com> Co-authored-by: SpaceLoveSs13 <68121607+SpaceLoveSs13@users.noreply.github.com>
This commit is contained in:
co-authored by
SmArtKar
SpaceLoveSs13
parent
1c342cb317
commit
99337c670f
@@ -0,0 +1,125 @@
|
||||
/// Used to apply certain speech patterns
|
||||
/// Can be used on organs, wearables, mutations and mobs
|
||||
/datum/component/speechmod
|
||||
/// Assoc list for strings/regexes and their replacements. Should be lowercase, as case will be automatically changed
|
||||
var/list/replacements = list()
|
||||
/// String added to the end of the message
|
||||
var/end_string = ""
|
||||
/// Chance for the end string to be applied
|
||||
var/end_string_chance = 100
|
||||
/// Current target for modification
|
||||
var/mob/targeted
|
||||
/// Slot tags in which this item works when equipped
|
||||
var/slots
|
||||
/// If set to true, turns all text to uppercase
|
||||
var/uppercase = FALSE
|
||||
|
||||
/datum/component/speechmod/Initialize(replacements = list(), end_string = "", end_string_chance = 100, slots, uppercase = FALSE)
|
||||
if (!ismob(parent) && !isitem(parent) && !istype(parent, /datum/mutation/human))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
src.replacements = replacements
|
||||
src.end_string = end_string
|
||||
src.end_string_chance = end_string_chance
|
||||
src.slots = slots
|
||||
src.uppercase = uppercase
|
||||
|
||||
if (istype(parent, /datum/mutation/human))
|
||||
RegisterSignal(parent, COMSIG_MUTATION_GAINED, PROC_REF(on_mutation_gained))
|
||||
RegisterSignal(parent, COMSIG_MUTATION_LOST, PROC_REF(on_mutation_lost))
|
||||
return
|
||||
|
||||
var/atom/owner = parent
|
||||
|
||||
if (ismob(parent))
|
||||
targeted = parent
|
||||
RegisterSignal(targeted, COMSIG_MOB_SAY, PROC_REF(handle_speech))
|
||||
return
|
||||
|
||||
if (ismob(owner.loc))
|
||||
targeted = owner.loc
|
||||
RegisterSignal(targeted, COMSIG_MOB_SAY, PROC_REF(handle_speech))
|
||||
|
||||
RegisterSignal(parent, COMSIG_ITEM_EQUIPPED, PROC_REF(on_equipped))
|
||||
RegisterSignal(parent, COMSIG_ITEM_DROPPED, PROC_REF(on_unequipped))
|
||||
RegisterSignal(parent, COMSIG_ORGAN_IMPLANTED, PROC_REF(on_implanted))
|
||||
RegisterSignal(parent, COMSIG_ORGAN_REMOVED, PROC_REF(on_removed))
|
||||
|
||||
/datum/component/speechmod/proc/handle_speech(datum/source, list/speech_args)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
var/message = speech_args[SPEECH_MESSAGE]
|
||||
if(message[1] == "*")
|
||||
return
|
||||
|
||||
for (var/to_replace in replacements)
|
||||
var/replacement = replacements[to_replace]
|
||||
// Values can be lists to be picked randomly from
|
||||
if (islist(replacement))
|
||||
replacement = pick(replacement)
|
||||
|
||||
message = replacetextEx(message, to_replace, replacement)
|
||||
message = trim(message)
|
||||
if (prob(end_string_chance))
|
||||
message += islist(end_string) ? pick(end_string) : end_string
|
||||
speech_args[SPEECH_MESSAGE] = trim(message)
|
||||
|
||||
if (uppercase)
|
||||
return COMPONENT_UPPERCASE_SPEECH
|
||||
|
||||
/datum/component/speechmod/proc/on_equipped(datum/source, mob/living/user, slot)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (!isnull(slots) && !(slot & slots))
|
||||
if (!isnull(targeted))
|
||||
UnregisterSignal(targeted, COMSIG_MOB_SAY)
|
||||
targeted = null
|
||||
return
|
||||
|
||||
if (targeted == user)
|
||||
return
|
||||
|
||||
targeted = user
|
||||
RegisterSignal(targeted, COMSIG_MOB_SAY, PROC_REF(handle_speech))
|
||||
|
||||
/datum/component/speechmod/proc/on_unequipped(datum/source, mob/living/user)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (isnull(targeted))
|
||||
return
|
||||
UnregisterSignal(targeted, COMSIG_MOB_SAY)
|
||||
targeted = null
|
||||
|
||||
/datum/component/speechmod/proc/on_implanted(datum/source, mob/living/carbon/receiver)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (targeted == receiver)
|
||||
return
|
||||
|
||||
targeted = receiver
|
||||
RegisterSignal(targeted, COMSIG_MOB_SAY, PROC_REF(handle_speech))
|
||||
|
||||
/datum/component/speechmod/proc/on_removed(datum/source, mob/living/carbon/former_owner)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (isnull(targeted))
|
||||
return
|
||||
UnregisterSignal(targeted, COMSIG_MOB_SAY)
|
||||
targeted = null
|
||||
|
||||
/datum/component/speechmod/proc/on_mutation_gained(datum/source, mob/living/carbon/human/owner)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (targeted == owner)
|
||||
return
|
||||
|
||||
targeted = owner
|
||||
RegisterSignal(targeted, COMSIG_MOB_SAY, PROC_REF(handle_speech))
|
||||
|
||||
/datum/component/speechmod/proc/on_mutation_lost(datum/source, mob/living/carbon/human/owner)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if (isnull(targeted))
|
||||
return
|
||||
UnregisterSignal(targeted, COMSIG_MOB_SAY)
|
||||
targeted = null
|
||||
Reference in New Issue
Block a user