mirror of
https://github.com/yogstation13/Yogstation.git
synced 2025-02-26 09:04:50 +00:00
[Ready]Moves traits to datums (#38505)
I've been in a few situations where traits would be handy to track certain object or datum flags, and there's no particular reason that ties them to living mobs aside from being initially a disability rework.
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
var/gc_destroyed //Time when this object was destroyed.
|
var/gc_destroyed //Time when this object was destroyed.
|
||||||
var/list/active_timers //for SStimer
|
var/list/active_timers //for SStimer
|
||||||
var/list/datum_components //for /datum/components
|
var/list/datum_components //for /datum/components
|
||||||
|
var/list/status_traits
|
||||||
var/list/comp_lookup //it used to be for looking up components which had registered a signal but now anything can register
|
var/list/comp_lookup //it used to be for looking up components which had registered a signal but now anything can register
|
||||||
var/list/signal_procs
|
var/list/signal_procs
|
||||||
var/signal_enabled = FALSE
|
var/signal_enabled = FALSE
|
||||||
|
|||||||
75
code/datums/traits.dm
Normal file
75
code/datums/traits.dm
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/datum/proc/add_trait(trait, source)
|
||||||
|
LAZYINITLIST(status_traits)
|
||||||
|
|
||||||
|
if(!status_traits[trait])
|
||||||
|
status_traits[trait] = list(source)
|
||||||
|
else
|
||||||
|
status_traits[trait] |= list(source)
|
||||||
|
|
||||||
|
|
||||||
|
/datum/proc/remove_trait(trait, list/sources, force)
|
||||||
|
if(!status_traits)
|
||||||
|
return //nothing to remove
|
||||||
|
|
||||||
|
if(!status_traits[trait])
|
||||||
|
return
|
||||||
|
|
||||||
|
if(locate(ROUNDSTART_TRAIT) in status_traits[trait] && !force) //mob traits applied through roundstart cannot normally be removed
|
||||||
|
return
|
||||||
|
|
||||||
|
if(!sources) // No defined source cures the trait entirely.
|
||||||
|
status_traits -= trait
|
||||||
|
return
|
||||||
|
|
||||||
|
if(!islist(sources))
|
||||||
|
sources = list(sources)
|
||||||
|
|
||||||
|
if(LAZYLEN(sources))
|
||||||
|
for(var/S in sources)
|
||||||
|
if(S in status_traits[trait])
|
||||||
|
status_traits[trait] -= S
|
||||||
|
else
|
||||||
|
status_traits[trait] = list()
|
||||||
|
|
||||||
|
if(!LAZYLEN(status_traits[trait]))
|
||||||
|
status_traits -= trait
|
||||||
|
|
||||||
|
/datum/proc/has_trait(trait, list/sources)
|
||||||
|
if(!status_traits)
|
||||||
|
return FALSE //well of course it doesn't have the trait
|
||||||
|
|
||||||
|
if(!status_traits[trait])
|
||||||
|
return FALSE
|
||||||
|
|
||||||
|
. = FALSE
|
||||||
|
|
||||||
|
if(sources && !islist(sources))
|
||||||
|
sources = list(sources)
|
||||||
|
if(LAZYLEN(sources))
|
||||||
|
for(var/S in sources)
|
||||||
|
if(S in status_traits[trait])
|
||||||
|
return TRUE
|
||||||
|
else if(LAZYLEN(status_traits[trait]))
|
||||||
|
return TRUE
|
||||||
|
|
||||||
|
/datum/proc/remove_all_traits(remove_species_traits = FALSE, remove_organ_traits = FALSE, remove_quirks = FALSE)
|
||||||
|
if(!status_traits)
|
||||||
|
return //nothing to remove
|
||||||
|
|
||||||
|
var/list/blacklisted_sources = list()
|
||||||
|
if(!remove_species_traits)
|
||||||
|
blacklisted_sources += SPECIES_TRAIT
|
||||||
|
if(!remove_organ_traits)
|
||||||
|
blacklisted_sources += ORGAN_TRAIT
|
||||||
|
if(!remove_quirks)
|
||||||
|
blacklisted_sources += ROUNDSTART_TRAIT
|
||||||
|
|
||||||
|
for(var/kebab in status_traits)
|
||||||
|
var/skip
|
||||||
|
for(var/S in blacklisted_sources)
|
||||||
|
if(S in status_traits[kebab])
|
||||||
|
skip = TRUE
|
||||||
|
break
|
||||||
|
if(!skip)
|
||||||
|
remove_trait(kebab, null, TRUE)
|
||||||
|
CHECK_TICK
|
||||||
@@ -114,10 +114,10 @@ for further reading, please see: https://github.com/tgstation/tgstation/pull/301
|
|||||||
/obj/item/claymore/highlander/pickup(mob/living/user)
|
/obj/item/claymore/highlander/pickup(mob/living/user)
|
||||||
to_chat(user, "<span class='notice'>The power of Scotland protects you! You are shielded from all stuns and knockdowns.</span>")
|
to_chat(user, "<span class='notice'>The power of Scotland protects you! You are shielded from all stuns and knockdowns.</span>")
|
||||||
user.add_stun_absorption("highlander", INFINITY, 1, " is protected by the power of Scotland!", "The power of Scotland absorbs the stun!", " is protected by the power of Scotland!")
|
user.add_stun_absorption("highlander", INFINITY, 1, " is protected by the power of Scotland!", "The power of Scotland absorbs the stun!", " is protected by the power of Scotland!")
|
||||||
user.add_trait(TRAIT_IGNORESLOWDOWN, HIGHLANDER)
|
user.ignore_slowdown(HIGHLANDER)
|
||||||
|
|
||||||
/obj/item/claymore/highlander/dropped(mob/living/user)
|
/obj/item/claymore/highlander/dropped(mob/living/user)
|
||||||
user.remove_trait(TRAIT_IGNORESLOWDOWN, HIGHLANDER)
|
user.unignore_slowdown(HIGHLANDER)
|
||||||
if(!QDELETED(src))
|
if(!QDELETED(src))
|
||||||
qdel(src) //If this ever happens, it's because you lost an arm
|
qdel(src) //If this ever happens, it's because you lost an arm
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,6 @@
|
|||||||
var/incorporeal_move = FALSE //FALSE is off, INCORPOREAL_MOVE_BASIC is normal, INCORPOREAL_MOVE_SHADOW is for ninjas
|
var/incorporeal_move = FALSE //FALSE is off, INCORPOREAL_MOVE_BASIC is normal, INCORPOREAL_MOVE_SHADOW is for ninjas
|
||||||
//and INCORPOREAL_MOVE_JAUNT is blocked by holy water/salt
|
//and INCORPOREAL_MOVE_JAUNT is blocked by holy water/salt
|
||||||
|
|
||||||
var/list/status_traits = list()
|
|
||||||
|
|
||||||
var/list/roundstart_quirks = list()
|
var/list/roundstart_quirks = list()
|
||||||
|
|
||||||
var/list/surgeries = list() //a list of surgery datums. generally empty, they're added when the player wants them.
|
var/list/surgeries = list() //a list of surgery datums. generally empty, they're added when the player wants them.
|
||||||
|
|||||||
@@ -139,18 +139,6 @@
|
|||||||
return TRUE
|
return TRUE
|
||||||
|
|
||||||
/////////////////////////////////// DISABILITIES ////////////////////////////////////
|
/////////////////////////////////// DISABILITIES ////////////////////////////////////
|
||||||
|
|
||||||
/mob/living/proc/add_trait(trait, source)
|
|
||||||
if(!status_traits[trait])
|
|
||||||
status_traits[trait] = list(source)
|
|
||||||
on_add_trait(trait, source)
|
|
||||||
else
|
|
||||||
status_traits[trait] |= list(source)
|
|
||||||
|
|
||||||
/mob/living/proc/on_add_trait(trait, source)
|
|
||||||
if(trait == TRAIT_IGNORESLOWDOWN)
|
|
||||||
update_movespeed(FALSE)
|
|
||||||
|
|
||||||
/mob/living/proc/add_quirk(quirk, spawn_effects) //separate proc due to the way these ones are handled
|
/mob/living/proc/add_quirk(quirk, spawn_effects) //separate proc due to the way these ones are handled
|
||||||
if(has_trait(quirk))
|
if(has_trait(quirk))
|
||||||
return
|
return
|
||||||
@@ -160,80 +148,15 @@
|
|||||||
new T (src, spawn_effects)
|
new T (src, spawn_effects)
|
||||||
return TRUE
|
return TRUE
|
||||||
|
|
||||||
/mob/living/proc/remove_trait(trait, list/sources, force)
|
|
||||||
if(!status_traits[trait])
|
|
||||||
return
|
|
||||||
|
|
||||||
if(locate(ROUNDSTART_TRAIT) in status_traits[trait] && !force) //mob traits applied through roundstart cannot normally be removed
|
|
||||||
return
|
|
||||||
|
|
||||||
if(!sources) // No defined source cures the trait entirely.
|
|
||||||
status_traits -= trait
|
|
||||||
on_remove_trait(trait, sources, force)
|
|
||||||
return
|
|
||||||
|
|
||||||
if(!islist(sources))
|
|
||||||
sources = list(sources)
|
|
||||||
|
|
||||||
if(LAZYLEN(sources))
|
|
||||||
for(var/S in sources)
|
|
||||||
if(S in status_traits[trait])
|
|
||||||
status_traits[trait] -= S
|
|
||||||
else
|
|
||||||
status_traits[trait] = list()
|
|
||||||
|
|
||||||
if(!LAZYLEN(status_traits[trait]))
|
|
||||||
status_traits -= trait
|
|
||||||
on_remove_trait(trait, sources, force)
|
|
||||||
|
|
||||||
/mob/living/proc/on_remove_trait(trait, list/sources, force)
|
|
||||||
if(trait == TRAIT_IGNORESLOWDOWN)
|
|
||||||
update_movespeed(FALSE)
|
|
||||||
|
|
||||||
/mob/living/proc/remove_quirk(quirk)
|
/mob/living/proc/remove_quirk(quirk)
|
||||||
var/datum/quirk/T = roundstart_quirks[quirk]
|
var/datum/quirk/T = roundstart_quirks[quirk]
|
||||||
if(T)
|
if(T)
|
||||||
qdel(T)
|
qdel(T)
|
||||||
return TRUE
|
return TRUE
|
||||||
|
|
||||||
/mob/living/proc/has_trait(trait, list/sources)
|
|
||||||
if(!status_traits[trait])
|
|
||||||
return FALSE
|
|
||||||
|
|
||||||
. = FALSE
|
|
||||||
|
|
||||||
if(sources && !islist(sources))
|
|
||||||
sources = list(sources)
|
|
||||||
if(LAZYLEN(sources))
|
|
||||||
for(var/S in sources)
|
|
||||||
if(S in status_traits[trait])
|
|
||||||
return TRUE
|
|
||||||
else if(LAZYLEN(status_traits[trait]))
|
|
||||||
return TRUE
|
|
||||||
|
|
||||||
/mob/living/proc/has_quirk(quirk)
|
/mob/living/proc/has_quirk(quirk)
|
||||||
return roundstart_quirks[quirk]
|
return roundstart_quirks[quirk]
|
||||||
|
|
||||||
/mob/living/proc/remove_all_traits(remove_species_traits = FALSE, remove_organ_traits = FALSE, remove_quirks = FALSE)
|
|
||||||
|
|
||||||
var/list/blacklisted_sources = list()
|
|
||||||
if(!remove_species_traits)
|
|
||||||
blacklisted_sources += SPECIES_TRAIT
|
|
||||||
if(!remove_organ_traits)
|
|
||||||
blacklisted_sources += ORGAN_TRAIT
|
|
||||||
if(!remove_quirks)
|
|
||||||
blacklisted_sources += ROUNDSTART_TRAIT
|
|
||||||
|
|
||||||
for(var/kebab in status_traits)
|
|
||||||
var/skip
|
|
||||||
for(var/S in blacklisted_sources)
|
|
||||||
if(S in status_traits[kebab])
|
|
||||||
skip = TRUE
|
|
||||||
break
|
|
||||||
if(!skip)
|
|
||||||
remove_trait(kebab, null, TRUE)
|
|
||||||
CHECK_TICK
|
|
||||||
|
|
||||||
/////////////////////////////////// TRAIT PROCS ////////////////////////////////////
|
/////////////////////////////////// TRAIT PROCS ////////////////////////////////////
|
||||||
|
|
||||||
/mob/living/proc/cure_blind(list/sources)
|
/mob/living/proc/cure_blind(list/sources)
|
||||||
@@ -284,3 +207,11 @@
|
|||||||
add_trait(TRAIT_DEATHCOMA, source)
|
add_trait(TRAIT_DEATHCOMA, source)
|
||||||
tod = station_time_timestamp()
|
tod = station_time_timestamp()
|
||||||
update_stat()
|
update_stat()
|
||||||
|
|
||||||
|
/mob/living/proc/unignore_slowdown(list/sources)
|
||||||
|
remove_trait(TRAIT_IGNORESLOWDOWN, sources)
|
||||||
|
update_movespeed(FALSE)
|
||||||
|
|
||||||
|
/mob/living/proc/ignore_slowdown(source)
|
||||||
|
add_trait(TRAIT_IGNORESLOWDOWN, source)
|
||||||
|
update_movespeed(FALSE)
|
||||||
@@ -623,10 +623,10 @@
|
|||||||
|
|
||||||
/datum/reagent/medicine/morphine/on_mob_add(mob/living/L)
|
/datum/reagent/medicine/morphine/on_mob_add(mob/living/L)
|
||||||
..()
|
..()
|
||||||
L.add_trait(TRAIT_IGNORESLOWDOWN, id)
|
L.ignore_slowdown(id)
|
||||||
|
|
||||||
/datum/reagent/medicine/morphine/on_mob_delete(mob/living/L)
|
/datum/reagent/medicine/morphine/on_mob_delete(mob/living/L)
|
||||||
L.remove_trait(TRAIT_IGNORESLOWDOWN, id)
|
L.unignore_slowdown(id)
|
||||||
..()
|
..()
|
||||||
|
|
||||||
/datum/reagent/medicine/morphine/on_mob_life(mob/living/carbon/M)
|
/datum/reagent/medicine/morphine/on_mob_life(mob/living/carbon/M)
|
||||||
@@ -1189,11 +1189,11 @@
|
|||||||
|
|
||||||
/datum/reagent/medicine/muscle_stimulant/on_mob_add(mob/living/M)
|
/datum/reagent/medicine/muscle_stimulant/on_mob_add(mob/living/M)
|
||||||
. = ..()
|
. = ..()
|
||||||
M.add_trait(TRAIT_IGNORESLOWDOWN, id)
|
M.ignore_slowdown(id)
|
||||||
|
|
||||||
/datum/reagent/medicine/muscle_stimulant/on_mob_delete(mob/living/M)
|
/datum/reagent/medicine/muscle_stimulant/on_mob_delete(mob/living/M)
|
||||||
. = ..()
|
. = ..()
|
||||||
M.remove_trait(TRAIT_IGNORESLOWDOWN, id)
|
M.unignore_slowdown(id)
|
||||||
|
|
||||||
/datum/reagent/medicine/modafinil
|
/datum/reagent/medicine/modafinil
|
||||||
name = "Modafinil"
|
name = "Modafinil"
|
||||||
|
|||||||
@@ -588,11 +588,11 @@ datum/status_effect/stabilized/blue/on_remove()
|
|||||||
colour = "red"
|
colour = "red"
|
||||||
|
|
||||||
/datum/status_effect/stabilized/red/on_apply()
|
/datum/status_effect/stabilized/red/on_apply()
|
||||||
owner.add_trait(TRAIT_IGNORESLOWDOWN,"slimestatus")
|
owner.ignore_slowdown("slimestatus")
|
||||||
return ..()
|
return ..()
|
||||||
|
|
||||||
/datum/status_effect/stabilized/red/on_remove()
|
/datum/status_effect/stabilized/red/on_remove()
|
||||||
owner.remove_trait(TRAIT_IGNORESLOWDOWN,"slimestatus")
|
owner.unignore_slowdown("slimestatus")
|
||||||
|
|
||||||
/datum/status_effect/stabilized/green
|
/datum/status_effect/stabilized/green
|
||||||
id = "stabilizedgreen"
|
id = "stabilizedgreen"
|
||||||
|
|||||||
@@ -309,6 +309,7 @@
|
|||||||
#include "code\datums\shuttles.dm"
|
#include "code\datums\shuttles.dm"
|
||||||
#include "code\datums\soullink.dm"
|
#include "code\datums\soullink.dm"
|
||||||
#include "code\datums\spawners_menu.dm"
|
#include "code\datums\spawners_menu.dm"
|
||||||
|
#include "code\datums\traits.dm"
|
||||||
#include "code\datums\verbs.dm"
|
#include "code\datums\verbs.dm"
|
||||||
#include "code\datums\weakrefs.dm"
|
#include "code\datums\weakrefs.dm"
|
||||||
#include "code\datums\world_topic.dm"
|
#include "code\datums\world_topic.dm"
|
||||||
|
|||||||
Reference in New Issue
Block a user