diff --git a/code/__DEFINES/skills/skills.dm b/code/__DEFINES/skills/skills.dm new file mode 100644 index 0000000000..b97b921550 --- /dev/null +++ b/code/__DEFINES/skills/skills.dm @@ -0,0 +1,28 @@ +/// true/false +#define SKILL_PROGRESSION_BINARY 1 +/// numerical +#define SKILL_PROGRESSION_NUMERICAL 2 +/// Enum +#define SKILL_PROGRESSION_ENUM 3 + +/// Max value of skill for numerical skills +#define SKILL_NUMERICAL_MAX 100 +/// Min value of skill for numerical skills +#define SKILL_NUMERICAL_MIN 0 + +// Standard values for job starting skills + +#define STARTING_SKILL_SURGERY_MEDICAL 35 //out of SKILL_NUMERICAL_MAX + +// Standard values for job starting skill affinities + +#define STARTING_SKILL_AFFINITY_SURGERY_MEDICAL 1.2 + +// Standard values for skill gain (this is multiplied by affinity) + +#define SKILL_GAIN_SURGERY_PER_STEP 0.25 + +// Misc + +/// 40% speedup at 100 skill +#define SURGERY_SKILL_SPEEDUP_NUMERICAL_SCALE(number) clamp(number / 250, 1, 2) diff --git a/code/controllers/subsystem/ticker.dm b/code/controllers/subsystem/ticker.dm index a7be36abc2..8042631b7b 100755 --- a/code/controllers/subsystem/ticker.dm +++ b/code/controllers/subsystem/ticker.dm @@ -387,6 +387,9 @@ SUBSYSTEM_DEF(ticker) for(var/mob/dead/new_player/N in GLOB.player_list) var/mob/living/carbon/human/player = N.new_character if(istype(player) && player.mind && player.mind.assigned_role) + var/datum/job/J = SSjob.GetJob(player.mind.assigned_role) + if(J) + J.standard_assign_skills(player.mind) if(player.mind.assigned_role == "Captain") captainless=0 if(player.mind.assigned_role != player.mind.special_role) diff --git a/code/datums/mind.dm b/code/datums/mind.dm index 31704d5451..728c4fb51b 100644 --- a/code/datums/mind.dm +++ b/code/datums/mind.dm @@ -63,7 +63,11 @@ var/force_escaped = FALSE // Set by Into The Sunset command of the shuttle manipulator var/list/learned_recipes //List of learned recipe TYPES. + /// Our skill holder. + var/datum/skill_holder/skill_holder + /datum/mind/New(var/key) + skill_holder = new src.key = key soulOwner = src martial_art = default_martial_art diff --git a/code/datums/skills/_check_skills.dm b/code/datums/skills/_check_skills.dm new file mode 100644 index 0000000000..d9dc6dad3d --- /dev/null +++ b/code/datums/skills/_check_skills.dm @@ -0,0 +1,16 @@ +// yeah yeah verbs suck whatever I suck at this fix this someone please - kevinz000 + +/mob/verb/check_skills() + set name = "Check Skills" + set category = "IC" + set desc = "Check your skills (if you have any..)" + + if(!mind) + to_chat(usr, "How do you check the skills of [(usr == src)? "yourself when you are" : "something"] without a mind?") + return + if(!mind.skill_holder) + to_chat(usr, "How do you check the skills of [(usr == src)? "yourself when you are" : "something"] without the capability for skills? (PROBABLY A BUG, PRESS F1.)") + return + var/datum/browser/B = new(usr, "skilldisplay_[REF(src)]", "Skills of [src]") + B.set_content(mind.skill_holder.html_readout()) + B.open() diff --git a/code/datums/skills/_skill.dm b/code/datums/skills/_skill.dm new file mode 100644 index 0000000000..2dd321c4c6 --- /dev/null +++ b/code/datums/skills/_skill.dm @@ -0,0 +1,95 @@ +GLOBAL_LIST_INIT(skill_datums, init_skill_datums()) + +/proc/init_skill_datums() + . = list() + for(var/path in subtypesof(/datum/skill)) + var/datum/skill/S = path + if(initial(S.abstract_type) == path) + continue + S = new path + .[S.type] = S + +/proc/get_skill_datum(path) + return GLOB.skill_datums[path] + +/proc/sanitize_skill_value(path, value) + var/datum/skill/S = get_skill_datum(path) + // don't check, if we runtime let it happen. + return S.sanitize_value(value) + +/proc/is_skill_value_greater(path, existing, new_value) + var/datum/skill/S = get_skill_datum(path) + // don't check, if we runtime let it happen. + return S.is_value_greater(existing, new_value) + +/** + * Skill datums + */ +/datum/skill + /// Our name + var/name + /// Our description + var/desc + /// Our progression type + var/progression_type + /// Abstract type + var/abstract_type = /datum/skill + +/** + * Ensures what someone's setting as a value for this skill is valid. + */ +/datum/skill/proc/sanitize_value(new_value) + return new_value + +/** + * Checks if a value is greater + */ +/datum/skill/proc/is_value_greater(existing, new_value) + if(!existing) + return TRUE + return new_value > existing + +/** + * Standard value "render" + */ +/datum/skill/proc/standard_render_value(value) + return value + +// Just saying, the choice to use different sub-parent-types is to force coders to resolve issues as I won't be implementing custom procs to grab skill levels in a certain context. +// Aka: So people don't forget to change checks if they change a skill's progression type. + +/datum/skill/binary + abstract_type = /datum/skill/binary + progression_type = SKILL_PROGRESSION_BINARY + +/datum/skill/binary/sanitize_value(new_value) + return new_value? TRUE : FALSE + +/datum/skill/binary/standard_render_value(value) + return value? "Yes" : "No" + +/datum/skill/numerical + abstract_type = /datum/skill/numerical + progression_type = SKILL_PROGRESSION_NUMERICAL + /// Max value of this skill + var/max_value = 100 + /// Min value of this skill + var/min_value = 0 + /// Display as a percent in standard_render_value? + var/display_as_percent = FALSE + +/datum/skill/numerical/sanitize_value(new_value) + return clamp(new_value, min_value, max_value) + +/datum/skill/numerical/standard_render_value(value) + return display_as_percent? "[round(value/max_value/100, 0.01)]%" : "[value] / [max_value]" + +/datum/skill/enum + abstract_type = /datum/skill/enum + progression_type = SKILL_PROGRESSION_ENUM + /// Valid values for the skill + var/list/valid_values = list() + +/datum/skill/enum/sanitize_value(new_value) + if(new_value in valid_values) + return new_value diff --git a/code/datums/skills/_skill_holder.dm b/code/datums/skills/_skill_holder.dm new file mode 100644 index 0000000000..352adc46ff --- /dev/null +++ b/code/datums/skills/_skill_holder.dm @@ -0,0 +1,78 @@ +/** + * Skill holder datums + */ +/datum/skill_holder + /// Our list of skills and values. Lazylist. Associative. Keys are datum typepaths to the skill. + var/list/skills + /// Same as [skills] but affinities, which are multiplied to increase amount when gaining skills. + var/list/skill_affinities + +/** + * Grabs the value of a skill. + */ +/datum/skill_holder/proc/get_skill_value(skill) + if(!ispath(skill)) + CRASH("Invalid get_skill_value call. Use typepaths.") //until a time when we somehow need text ids for dynamic skills, I'm enforcing this. + if(!skills) + return null + return skills[skill] + +/** + * Grabs our affinity for a skill. !!This is a multiplier!! + */ +/datum/skill_holder/proc/get_skill_affinity(skill) + if(!ispath(skill)) + CRASH("Invalid get_skill_affinity call. Use typepaths.") //until a time when we somehow need text ids for dynamic skills, I'm enforcing this. + if(!skills) + return 1 + var/affinity = skill_affinities[skill] + if(isnull(affinity)) + return 1 + return affinity + +/** + * Sets the value of a skill. + */ +/datum/skill_holder/proc/set_skill_value(skill, value) + if(!ispath(skill)) + CRASH("Invalid set_skill_value call. Use typepaths.") //until a time when we somehow need text ids for dynamic skills, I'm enforcing this. + LAZYINITLIST(skills) + value = sanitize_skill_value(skill, value) + if(!isnull(value)) + skills[skill] = value + return TRUE + return FALSE + +/** + * Boosts a skill to a value if not aobve + */ +/datum/skill_holder/proc/boost_skill_value_to(skill, value) + var/current = get_skill_value(skill) + if(!is_skill_value_greater(skill, current, value)) + return FALSE + set_skill_value(skill, value) + return TRUE + +/** + * Automatic skill increase, multiplied by skill affinity if existing. + * Only works if skill is numerical. + */ +/datum/skill_holder/proc/auto_gain_experience(skill, value) + if(!ispath(skill, /datum/skill/numerical)) + CRASH("You cannot auto increment a non numerical skill!") + var/current = get_skill_value(skill) + var/affinity = get_skill_affinity(skill) + boost_skill_value_to(skill, current + (value * affinity)) + +/** + * Generates a HTML readout of our skills. + * Port to tgui-next when? + */ +/datum/skill_holder/proc/html_readout() + var/list/out = list("
| Skill | Value |
|---|---|
| [S.name] | [S.standard_render_value(skills[path])] |