datums
This commit is contained in:
+102
-71
@@ -1,3 +1,6 @@
|
||||
#define MINOR_INSANITY_PEN 5
|
||||
#define MAJOR_INSANITY_PEN 10
|
||||
|
||||
/datum/component/mood
|
||||
var/mood //Real happiness
|
||||
var/sanity = 100 //Current sanity
|
||||
@@ -5,25 +8,32 @@
|
||||
var/mood_level = 5 //To track what stage of moodies they're on
|
||||
var/mood_modifier = 1 //Modifier to allow certain mobs to be less affected by moodlets
|
||||
var/datum/mood_event/list/mood_events = list()
|
||||
var/mob/living/owner
|
||||
var/datum/looping_sound/reverse_bear_trap/slow/soundloop //Insanity ticking
|
||||
var/insanity_effect = 0 //is the owner being punished for low mood? If so, how much?
|
||||
var/holdmyinsanityeffect = 0 //before we edit our sanity lets take a look
|
||||
var/obj/screen/mood/screen_obj
|
||||
|
||||
/datum/component/mood/Initialize()
|
||||
if(!isliving(parent))
|
||||
return COMPONENT_INCOMPATIBLE
|
||||
|
||||
START_PROCESSING(SSmood, src)
|
||||
owner = parent
|
||||
soundloop = new(list(owner), FALSE, TRUE)
|
||||
|
||||
RegisterSignal(parent, COMSIG_ADD_MOOD_EVENT, .proc/add_event)
|
||||
RegisterSignal(parent, COMSIG_CLEAR_MOOD_EVENT, .proc/clear_event)
|
||||
RegisterSignal(parent, COMSIG_ENTER_AREA, .proc/update_beauty)
|
||||
|
||||
RegisterSignal(parent, COMSIG_MOB_HUD_CREATED, .proc/modify_hud)
|
||||
var/mob/living/owner = parent
|
||||
if(owner.hud_used)
|
||||
modify_hud()
|
||||
var/datum/hud/hud = owner.hud_used
|
||||
hud.show_hud(hud.hud_version)
|
||||
|
||||
/datum/component/mood/Destroy()
|
||||
STOP_PROCESSING(SSmood, src)
|
||||
QDEL_NULL(soundloop)
|
||||
unmodify_hud()
|
||||
return ..()
|
||||
|
||||
/datum/component/mood/proc/print_mood()
|
||||
/datum/component/mood/proc/print_mood(mob/user)
|
||||
var/msg = "<span class='info'>*---------*\n<EM>Your current mood</EM>\n"
|
||||
msg += "<span class='notice'>My mental status: </span>" //Long term
|
||||
switch(sanity)
|
||||
@@ -67,8 +77,8 @@
|
||||
var/datum/mood_event/event = mood_events[i]
|
||||
msg += event.description
|
||||
else
|
||||
msg += "<span class='nicegreen'>Nothing special has happened to me lately!<span>\n"
|
||||
to_chat(owner, msg)
|
||||
msg += "<span class='nicegreen'>I don't have much of a reaction to anything right now.<span>\n"
|
||||
to_chat(user || parent, msg)
|
||||
|
||||
/datum/component/mood/proc/update_mood() //Called whenever a mood event is added or removed
|
||||
mood = 0
|
||||
@@ -104,41 +114,25 @@
|
||||
|
||||
|
||||
/datum/component/mood/proc/update_mood_icon()
|
||||
var/mob/living/owner = parent
|
||||
if(owner.client && owner.hud_used)
|
||||
if(sanity < 25)
|
||||
owner.hud_used.mood.icon_state = "mood_insane"
|
||||
screen_obj.icon_state = "mood_insane"
|
||||
else
|
||||
owner.hud_used.mood.icon_state = "mood[mood_level]"
|
||||
screen_obj.icon_state = "mood[mood_level]"
|
||||
|
||||
/datum/component/mood/process() //Called on SSmood process
|
||||
switch(sanity)
|
||||
if(SANITY_INSANE to SANITY_CRAZY)
|
||||
owner.overlay_fullscreen("depression", /obj/screen/fullscreen/depression, 3)
|
||||
update_mood_icon()
|
||||
if(prob(7))
|
||||
owner.playsound_local(null, pick(CREEPY_SOUNDS), 40, 1)
|
||||
soundloop.start()
|
||||
if(SANITY_INSANE to SANITY_UNSTABLE)
|
||||
owner.overlay_fullscreen("depression", /obj/screen/fullscreen/depression, 2)
|
||||
if(prob(3))
|
||||
owner.playsound_local(null, pick(CREEPY_SOUNDS), 20, 1)
|
||||
soundloop.stop()
|
||||
if(SANITY_UNSTABLE to SANITY_DISTURBED)
|
||||
owner.overlay_fullscreen("depression", /obj/screen/fullscreen/depression, 1)
|
||||
soundloop.stop()
|
||||
if(SANITY_DISTURBED to INFINITY)
|
||||
owner.clear_fullscreen("depression")
|
||||
soundloop.stop()
|
||||
var/mob/living/owner = parent
|
||||
|
||||
switch(mood_level)
|
||||
if(1)
|
||||
DecreaseSanity(0.2, 0)
|
||||
DecreaseSanity(0.2)
|
||||
if(2)
|
||||
DecreaseSanity(0.125, 25)
|
||||
DecreaseSanity(0.125, SANITY_CRAZY)
|
||||
if(3)
|
||||
DecreaseSanity(0.075, 50)
|
||||
DecreaseSanity(0.075, SANITY_UNSTABLE)
|
||||
if(4)
|
||||
DecreaseSanity(0.025, 75)
|
||||
DecreaseSanity(0.025, SANITY_DISTURBED)
|
||||
if(5)
|
||||
IncreaseSanity(0.1)
|
||||
if(6)
|
||||
@@ -146,42 +140,60 @@
|
||||
if(7)
|
||||
IncreaseSanity(0.20)
|
||||
if(8)
|
||||
IncreaseSanity(0.25, 125)
|
||||
IncreaseSanity(0.25, SANITY_GREAT)
|
||||
if(9)
|
||||
IncreaseSanity(0.4, 125)
|
||||
IncreaseSanity(0.4, SANITY_GREAT)
|
||||
|
||||
if(insanity_effect != holdmyinsanityeffect)
|
||||
if(insanity_effect > holdmyinsanityeffect)
|
||||
owner.crit_threshold += (insanity_effect - holdmyinsanityeffect)
|
||||
else
|
||||
owner.crit_threshold -= (holdmyinsanityeffect - insanity_effect)
|
||||
|
||||
if(owner.has_trait(TRAIT_DEPRESSION))
|
||||
if(prob(0.05))
|
||||
add_event("depression", /datum/mood_event/depression)
|
||||
clear_event("jolly")
|
||||
add_event(null, "depression", /datum/mood_event/depression)
|
||||
clear_event(null, "jolly")
|
||||
if(owner.has_trait(TRAIT_JOLLY))
|
||||
if(prob(0.05))
|
||||
add_event("jolly", /datum/mood_event/jolly)
|
||||
clear_event("depression")
|
||||
add_event(null, "jolly", /datum/mood_event/jolly)
|
||||
clear_event(null, "depression")
|
||||
|
||||
var/area/A = get_area(owner)
|
||||
if(A)
|
||||
update_beauty(A)
|
||||
holdmyinsanityeffect = insanity_effect
|
||||
|
||||
HandleNutrition(owner)
|
||||
|
||||
/datum/component/mood/proc/DecreaseSanity(amount, limit = 0)
|
||||
if(sanity < limit) //This might make KevinZ stop fucking pinging me.
|
||||
/datum/component/mood/proc/DecreaseSanity(amount, minimum = SANITY_INSANE)
|
||||
if(sanity < minimum) //This might make KevinZ stop fucking pinging me.
|
||||
IncreaseSanity(0.5)
|
||||
else
|
||||
sanity = max(0, sanity - amount)
|
||||
sanity = max(minimum, sanity - amount)
|
||||
if(sanity < SANITY_UNSTABLE)
|
||||
if(sanity < SANITY_CRAZY)
|
||||
insanity_effect = (MAJOR_INSANITY_PEN)
|
||||
else
|
||||
insanity_effect = (MINOR_INSANITY_PEN)
|
||||
|
||||
/datum/component/mood/proc/IncreaseSanity(amount, limit = 99)
|
||||
if(sanity > limit)
|
||||
/datum/component/mood/proc/IncreaseSanity(amount, maximum = SANITY_NEUTRAL)
|
||||
if(sanity > maximum)
|
||||
DecreaseSanity(0.5) //Removes some sanity to go back to our current limit.
|
||||
else
|
||||
sanity = min(limit, sanity + amount)
|
||||
sanity = min(maximum, sanity + amount)
|
||||
if(sanity > SANITY_CRAZY)
|
||||
if(sanity > SANITY_UNSTABLE)
|
||||
insanity_effect = 0
|
||||
else
|
||||
insanity_effect = MINOR_INSANITY_PEN
|
||||
|
||||
/datum/component/mood/proc/add_event(category, type, param) //Category will override any events in the same category, should be unique unless the event is based on the same thing like hunger.
|
||||
/datum/component/mood/proc/add_event(datum/source, category, type, param) //Category will override any events in the same category, should be unique unless the event is based on the same thing like hunger.
|
||||
var/datum/mood_event/the_event
|
||||
if(mood_events[category])
|
||||
the_event = mood_events[category]
|
||||
if(the_event.type != type)
|
||||
clear_event(category)
|
||||
clear_event(null, category)
|
||||
else
|
||||
if(the_event.timeout)
|
||||
addtimer(CALLBACK(src, .proc/clear_event, null, category), the_event.timeout, TIMER_UNIQUE|TIMER_OVERRIDE)
|
||||
return 0 //Don't have to update the event.
|
||||
the_event = new type(src, param)
|
||||
|
||||
@@ -189,9 +201,9 @@
|
||||
update_mood()
|
||||
|
||||
if(the_event.timeout)
|
||||
addtimer(CALLBACK(src, .proc/clear_event, category), the_event.timeout)
|
||||
addtimer(CALLBACK(src, .proc/clear_event, null, category), the_event.timeout, TIMER_UNIQUE|TIMER_OVERRIDE)
|
||||
|
||||
/datum/component/mood/proc/clear_event(category)
|
||||
/datum/component/mood/proc/clear_event(datum/source, category)
|
||||
var/datum/mood_event/event = mood_events[category]
|
||||
if(!event)
|
||||
return 0
|
||||
@@ -200,22 +212,41 @@
|
||||
qdel(event)
|
||||
update_mood()
|
||||
|
||||
/datum/component/mood/proc/update_beauty(area/A)
|
||||
if(A.outdoors) //if we're outside, we don't care.
|
||||
clear_event("area_beauty")
|
||||
return FALSE
|
||||
switch(A.beauty)
|
||||
if(-INFINITY to BEAUTY_LEVEL_HORRID)
|
||||
add_event("area_beauty", /datum/mood_event/horridroom)
|
||||
if(BEAUTY_LEVEL_HORRID to BEAUTY_LEVEL_BAD)
|
||||
add_event("area_beauty", /datum/mood_event/badroom)
|
||||
if(BEAUTY_LEVEL_BAD to BEAUTY_LEVEL_MEH)
|
||||
add_event("area_beauty", /datum/mood_event/mehroom)
|
||||
if(BEAUTY_LEVEL_MEH to BEAUTY_LEVEL_DECENT)
|
||||
clear_event("area_beauty")
|
||||
if(BEAUTY_LEVEL_DECENT to BEAUTY_LEVEL_GOOD)
|
||||
add_event("area_beauty", /datum/mood_event/decentroom)
|
||||
if(BEAUTY_LEVEL_GOOD to BEAUTY_LEVEL_GREAT)
|
||||
add_event("area_beauty", /datum/mood_event/goodroom)
|
||||
if(BEAUTY_LEVEL_GREAT to INFINITY)
|
||||
add_event("area_beauty", /datum/mood_event/greatroom)
|
||||
/datum/component/mood/proc/modify_hud(datum/source)
|
||||
var/mob/living/owner = parent
|
||||
var/datum/hud/hud = owner.hud_used
|
||||
screen_obj = new
|
||||
hud.infodisplay += screen_obj
|
||||
RegisterSignal(hud, COMSIG_PARENT_QDELETED, .proc/unmodify_hud)
|
||||
RegisterSignal(screen_obj, COMSIG_CLICK, .proc/hud_click)
|
||||
|
||||
/datum/component/mood/proc/unmodify_hud(datum/source)
|
||||
if(!screen_obj)
|
||||
return
|
||||
var/mob/living/owner = parent
|
||||
var/datum/hud/hud = owner.hud_used
|
||||
if(hud && hud.infodisplay)
|
||||
hud.infodisplay -= screen_obj
|
||||
QDEL_NULL(screen_obj)
|
||||
|
||||
/datum/component/mood/proc/hud_click(datum/source, location, control, params, mob/user)
|
||||
print_mood(user)
|
||||
|
||||
|
||||
/datum/component/mood/proc/HandleNutrition(mob/living/L)
|
||||
switch(L.nutrition)
|
||||
if(NUTRITION_LEVEL_FULL to INFINITY)
|
||||
add_event(null, "nutrition", /datum/mood_event/fat)
|
||||
if(NUTRITION_LEVEL_WELL_FED to NUTRITION_LEVEL_FULL)
|
||||
add_event(null, "nutrition", /datum/mood_event/wellfed)
|
||||
if( NUTRITION_LEVEL_FED to NUTRITION_LEVEL_WELL_FED)
|
||||
add_event(null, "nutrition", /datum/mood_event/fed)
|
||||
if(NUTRITION_LEVEL_HUNGRY to NUTRITION_LEVEL_FED)
|
||||
clear_event(null, "nutrition")
|
||||
if(NUTRITION_LEVEL_STARVING to NUTRITION_LEVEL_HUNGRY)
|
||||
add_event(null, "nutrition", /datum/mood_event/hungry)
|
||||
if(0 to NUTRITION_LEVEL_STARVING)
|
||||
add_event(null, "nutrition", /datum/mood_event/starving)
|
||||
|
||||
#undef MINOR_INSANITY_PEN
|
||||
#undef MAJOR_INSANITY_PEN
|
||||
|
||||
Reference in New Issue
Block a user