Files
Bubberstation/code/datums/components/faction_granter.dm
LemonInTheDark ae5a4f955d Pulls apart the vestiges of components still hanging onto signals (#75914)
## About The Pull Request

Signals were initially only usable with component listeners, which while
no longer the case has lead to outdated documentation, names, and a
similar location in code.

This pr pulls the two apart. Partially because mso thinks we should, but
also because they really aren't directly linked anymore, and having them
in this midstate just confuses people.

[Renames comp_lookup to listen_lookup, since that's what it
does](102b79694f)

[Moves signal procs over to their own
file](33d07d01fd)

[Renames the PREQDELETING and QDELETING comsigs to drop the parent bit
since they can hook to more then just comps
now](335ea4ad08)

[Does something similar to the attackby comsigs (PARENT ->
ATOM)](210e57051d)

[And finally passes over the examine
signals](65917658fb)

## Why It's Good For The Game

Code makes more sense, things are better teased apart, s just good imo

## Changelog
🆑
refactor: Pulled apart the last vestiges of names/docs directly linking
signals to components
/🆑
2023-06-09 06:14:31 +00:00

56 lines
2.2 KiB
Plaintext

/**
* ## faction granter component!
*
* component attached to items, lets them be used in hand once to add yourself to a certain faction
* one good example is the chaplain plushie that grants you the carp faction, making you friendly with them.
*/
/datum/component/faction_granter
dupe_mode = COMPONENT_DUPE_ALLOWED
///whichever faction the parent adds upon using in hand
var/faction_to_grant
///whether you need to be holy to get the faction.
var/holy_role_required
///message given when granting the faction.
var/grant_message
///boolean on whether it has been used
var/used = FALSE
/datum/component/faction_granter/Initialize(faction_to_grant, holy_role_required = NONE, grant_message)
if(!isitem(parent))
return COMPONENT_INCOMPATIBLE
if(!grant_message) //Yes we could do this in the init call with default args, but it scares people
grant_message = "You have become friends with [faction_to_grant]"
src.faction_to_grant = faction_to_grant
src.holy_role_required = holy_role_required
src.grant_message = grant_message
/datum/component/faction_granter/RegisterWithParent()
RegisterSignal(parent, COMSIG_ITEM_ATTACK_SELF, PROC_REF(on_self_attack))
RegisterSignal(parent, COMSIG_ATOM_EXAMINE, PROC_REF(on_examine))
/datum/component/faction_granter/UnregisterFromParent()
UnregisterSignal(parent, list(COMSIG_ITEM_ATTACK_SELF, COMSIG_ATOM_EXAMINE))
///signal called on parent being examined
/datum/component/faction_granter/proc/on_examine(datum/source, mob/user, list/examine_list)
SIGNAL_HANDLER
if(used)
examine_list += span_notice("[parent]'s favor granting power has been used up.")
else
examine_list += span_notice("Using [parent] in your hand will grant you favor with [faction_to_grant]\s")
///signal called on parent being interacted with in hand
/datum/component/faction_granter/proc/on_self_attack(atom/source, mob/user)
SIGNAL_HANDLER
if(used)
to_chat(user, span_warning("The power of [parent] has been used up!"))
return
if(user.mind?.holy_role < holy_role_required)
to_chat(user, span_warning("You are not holy enough to invoke the power of [parent]!"))
return
to_chat(user, grant_message)
user.faction |= faction_to_grant
used = TRUE