mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-22 12:41:09 +01:00
[MIRROR] Beauty is now an element. Fixing an issue with enter/exit area comsigs. (#3639)
* Beauty is now an element. Fixing an issue with enter/exit area comsigs. (#57147) Co-authored-by: Ghommie <425422238+Ghommie@ users.noreply.github.com> * Beauty is now an element. Fixing an issue with enter/exit area comsigs. Co-authored-by: Ghom <42542238+Ghommie@users.noreply.github.com> Co-authored-by: Ghommie <425422238+Ghommie@ users.noreply.github.com>
This commit is contained in:
co-authored by
Ghommie
Ghom
parent
a9abe3423d
commit
1f665ef7f7
@@ -1,57 +0,0 @@
|
||||
/**
|
||||
* Beauty component, makes the indoor area the parent is in prettier or uglier depending on the beauty var.
|
||||
* Clean and well decorated areas lead to positive moodlets for passerbies, while shabbier, dirtier ones
|
||||
* lead to negative moodlets exclusive to characters with the snob quirk.
|
||||
*
|
||||
* Keep in mind AddComponent is used for BOTH adding and removing beauty value here,
|
||||
* so please don't use qdel/RemoveComponent unless necessary.
|
||||
*/
|
||||
/datum/component/beauty
|
||||
var/beauty = 0
|
||||
dupe_mode = COMPONENT_DUPE_UNIQUE_PASSARGS
|
||||
|
||||
/datum/component/beauty/Initialize(beautyamount)
|
||||
if(!isatom(parent) || isarea(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
beauty = beautyamount
|
||||
|
||||
if(ismovable(parent))
|
||||
RegisterSignal(parent, COMSIG_ENTER_AREA, .proc/enter_area)
|
||||
RegisterSignal(parent, COMSIG_EXIT_AREA, .proc/exit_area)
|
||||
|
||||
var/area/A = get_area(parent)
|
||||
if(A)
|
||||
enter_area(null, A)
|
||||
|
||||
/datum/component/beauty/proc/enter_area(datum/source, area/A)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(A.outdoors)
|
||||
return
|
||||
A.totalbeauty += beauty
|
||||
A.update_beauty()
|
||||
|
||||
/datum/component/beauty/proc/exit_area(datum/source, area/A)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(A.outdoors)
|
||||
return
|
||||
A.totalbeauty -= beauty
|
||||
A.update_beauty()
|
||||
|
||||
/datum/component/beauty/InheritComponent(datum/component/beauty/new_comp , i_am_original, beautyamount)
|
||||
if((beauty + beautyamount) == 0)
|
||||
qdel(src)
|
||||
return
|
||||
beauty += beautyamount
|
||||
var/area/A = get_area(parent)
|
||||
if(A && !A.outdoors)
|
||||
A.totalbeauty += beautyamount
|
||||
A.update_beauty()
|
||||
|
||||
/datum/component/beauty/Destroy()
|
||||
. = ..()
|
||||
var/area/A = get_area(parent)
|
||||
if(A)
|
||||
exit_area(null, A)
|
||||
@@ -73,12 +73,12 @@
|
||||
|
||||
/datum/fantasy_affix/beautiful/apply(datum/component/fantasy/comp, newName)
|
||||
var/obj/item/master = comp.parent
|
||||
master.AddComponent(/datum/component/beauty, max(comp.quality, 1) * 250)
|
||||
master.AddElement(/datum/element/beauty, max(comp.quality, 1) * 250)
|
||||
return "[pick("aesthetic", "beautiful", "gorgeous", "pretty")] [newName]"
|
||||
|
||||
/datum/fantasy_affix/beautiful/remove(datum/component/fantasy/comp)
|
||||
var/obj/item/master = comp.parent
|
||||
master.AddComponent(/datum/component/beauty, -max(comp.quality, 1) * 250)
|
||||
master.RemoveElement(/datum/element/beauty, max(comp.quality, 1) * 250)
|
||||
|
||||
/datum/fantasy_affix/ugly
|
||||
placement = AFFIX_PREFIX
|
||||
@@ -86,9 +86,9 @@
|
||||
|
||||
/datum/fantasy_affix/ugly/apply(datum/component/fantasy/comp, newName)
|
||||
var/obj/item/master = comp.parent
|
||||
master.AddComponent(/datum/component/beauty, min(comp.quality, -1) * 250)
|
||||
master.AddElement(/datum/element/beauty, min(comp.quality, -1) * 250)
|
||||
return "[pick("fugly", "ugly", "grotesque", "hideous")] [newName]"
|
||||
|
||||
/datum/fantasy_affix/ugly/remove(datum/component/fantasy/comp)
|
||||
var/obj/item/master = comp.parent
|
||||
master.AddComponent(/datum/component/beauty, -min(comp.quality, -1) * 250)
|
||||
master.AddElement(/datum/element/beauty, min(comp.quality, -1) * 250)
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
RegisterSignal(parent, COMSIG_VOID_MASK_ACT, .proc/direct_sanity_drain)
|
||||
|
||||
var/mob/living/owner = parent
|
||||
owner.become_area_sensitive(MOOD_COMPONENT_TRAIT)
|
||||
if(owner.hud_used)
|
||||
modify_hud()
|
||||
var/datum/hud/hud = owner.hud_used
|
||||
@@ -36,6 +37,7 @@
|
||||
|
||||
/datum/component/mood/Destroy()
|
||||
STOP_PROCESSING(SSmood, src)
|
||||
REMOVE_TRAIT(parent, TRAIT_AREA_SENSITIVE, MOOD_COMPONENT_TRAIT)
|
||||
unmodify_hud()
|
||||
return ..()
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Beauty element. It makes the indoor area the parent is in prettier or uglier depending on the beauty var value.
|
||||
* Clean and well decorated areas lead to positive moodlets for passerbies;
|
||||
* Shabbier, dirtier ones lead to negative moodlets EXCLUSIVE to characters with the snob quirk.
|
||||
*/
|
||||
/datum/element/beauty
|
||||
element_flags = ELEMENT_BESPOKE|ELEMENT_DETACH
|
||||
id_arg_index = 2
|
||||
var/beauty = 0
|
||||
/**
|
||||
* Assoc list of atoms as keys and number of time the same element instance has been attached to them as assoc value.
|
||||
* So things don't get odd with same-valued yet dissimilar beauty modifiers being added to the same atom.
|
||||
*/
|
||||
var/beauty_counter = list()
|
||||
|
||||
/datum/element/beauty/Attach(datum/target, beauty)
|
||||
. = ..()
|
||||
if(!isatom(target) || isarea(target))
|
||||
return ELEMENT_INCOMPATIBLE
|
||||
|
||||
src.beauty = beauty
|
||||
|
||||
if(!beauty_counter[target] && ismovable(target))
|
||||
var/atom/movable/mov_target = target
|
||||
mov_target.become_area_sensitive(BEAUTY_ELEMENT_TRAIT)
|
||||
RegisterSignal(mov_target, COMSIG_ENTER_AREA, .proc/enter_area)
|
||||
RegisterSignal(mov_target, COMSIG_EXIT_AREA, .proc/exit_area)
|
||||
|
||||
beauty_counter[target]++
|
||||
|
||||
var/area/current_area = get_area(target)
|
||||
if(current_area && !current_area.outdoors)
|
||||
current_area.totalbeauty += beauty
|
||||
current_area.update_beauty()
|
||||
|
||||
/datum/element/beauty/proc/enter_area(datum/source, area/new_area)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(new_area.outdoors)
|
||||
return
|
||||
new_area.totalbeauty += beauty * beauty_counter[source]
|
||||
new_area.update_beauty()
|
||||
|
||||
/datum/element/beauty/proc/exit_area(datum/source, area/old_area)
|
||||
SIGNAL_HANDLER
|
||||
|
||||
if(old_area.outdoors)
|
||||
return
|
||||
old_area.totalbeauty -= beauty * beauty_counter[source]
|
||||
old_area.update_beauty()
|
||||
|
||||
/datum/element/beauty/Detach(datum/source, force)
|
||||
var/area/current_area = get_area(source)
|
||||
if(QDELETED(source))
|
||||
. = ..()
|
||||
UnregisterSignal(source, list(COMSIG_ENTER_AREA, COMSIG_EXIT_AREA))
|
||||
if(current_area)
|
||||
exit_area(source, current_area)
|
||||
beauty_counter -= source
|
||||
else //lower the 'counter' down by one, update the area, and call parent if it's reached zero.
|
||||
beauty_counter[source]--
|
||||
if(current_area && !current_area.outdoors)
|
||||
current_area.totalbeauty -= beauty
|
||||
current_area.update_beauty()
|
||||
if(!beauty_counter[source])
|
||||
. = ..()
|
||||
UnregisterSignal(source, list(COMSIG_ENTER_AREA, COMSIG_EXIT_AREA))
|
||||
beauty_counter -= source
|
||||
REMOVE_TRAIT(source, TRAIT_AREA_SENSITIVE, BEAUTY_ELEMENT_TRAIT)
|
||||
@@ -77,7 +77,7 @@ Simple datum which is instanced once per type and is used for every object of sa
|
||||
source.name = "[name] [source.name]"
|
||||
|
||||
if(beauty_modifier)
|
||||
source.AddComponent(/datum/component/beauty, beauty_modifier * amount)
|
||||
source.AddElement(/datum/element/beauty, beauty_modifier * amount)
|
||||
|
||||
if(istype(source, /obj)) //objs
|
||||
on_applied_obj(source, amount, material_flags)
|
||||
@@ -145,8 +145,8 @@ Simple datum which is instanced once per type and is used for every object of sa
|
||||
if(material_flags & MATERIAL_ADD_PREFIX)
|
||||
source.name = initial(source.name)
|
||||
|
||||
if(beauty_modifier) //component/beauty/InheritComponent() will handle the removal.
|
||||
source.AddComponent(/datum/component/beauty, -beauty_modifier * amount)
|
||||
if(beauty_modifier)
|
||||
source.RemoveElement(/datum/element/beauty, beauty_modifier * amount)
|
||||
|
||||
if(istype(source, /obj)) //objs
|
||||
on_removed_obj(source, amount, material_flags)
|
||||
|
||||
Reference in New Issue
Block a user