Skip to content

Commit

Permalink
moves available abilities to a global list and separates the one big …
Browse files Browse the repository at this point in the history
…global list of abilities into multiple, and caches stat reqs
  • Loading branch information
Arturlang committed Sep 28, 2024
1 parent 1bf1e23 commit d241fc1
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

/datum/vampire_ability/cloak_of_darkness
name = "Cloak of Darkness"
desc = "The darkness shrouds your form, making you less visibile, \
with visiblity scaling on discretion.\
Requires you to be in the dark. \
If you stay in the dark for more than half a second, you will become visible again. \"
stat_reqs = list(VAMPIRE_STAT_DISCRETION = 1)
granted_action = /datum/action/cooldown/vampire/cloak_of_darkness

Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,6 @@
/// Whether this ability is currently blocked by masquerade.
var/blocked = FALSE

/// Returns whether the given vampire meets the requirements to get this ability.
/datum/vampire_ability/proc/check_reqs(datum/antagonist/vampire/vampire)
if(vampire.vampire_rank < min_rank)
return FALSE

if(clan_req && vampire.clan != clan_req)
return FALSE

if(islist(stat_reqs))
for(var/stat as anything in stat_reqs)
if(vampire.get_stat(stat) < stat_reqs[stat])
return FALSE

return TRUE

/// Actually grants the action to the vampire. Use on_grant for subtypes if possible.
/datum/vampire_ability/proc/grant(datum/antagonist/vampire/new_owner)
SHOULD_NOT_SLEEP(TRUE)
Expand Down
55 changes: 31 additions & 24 deletions monkestation/code/modules/antagonists/vampire/vampire_abilities.dm
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
/// Initializes the list of available vampire abilities.
/datum/antagonist/vampire/proc/init_available_abilities()
if(available_abilities)
return

var/all = subtypesof(/datum/vampire_ability)

available_abilities = list(
VAMPIRE_ABILITIES_ALL = all,
VAMPIRE_ABILITIES_RANK = list()
)
/// Checks if the vampire has any new abilities to unlock.
/datum/antagonist/vampire/proc/check_new_unlocks()
for(var/ability as anything in GLOB.vampire_all_abilities)
check_ability_reqs(ability)

for(var/datum/vampire_ability/ability_type as anything in all)
var/datum/vampire_ability/ability = new ability_type
if(ability.min_rank > 0)
available_abilities[VAMPIRE_ABILITIES_RANK] += ability_type
for(var/stat as anything in ability.stat_reqs)
available_abilities[stat] += list(ability_type)
qdel(ability)
/datum/antagonist/vampire/proc/check_new_unlocks_by_stat(stat_name)
var/abilities = GLOB.vampire_abilities_stat[stat_name]
if(!abilities)
return
for(var/ability as anything in abilities)
check_ability_reqs(ability)

/// Checks ability reqs for a the given available_abilities criteria. Criteria are stat name defines or defines under "VAMPIRE_ABILITIES_".
/datum/antagonist/vampire/proc/check_ability_reqs_of_criteria(criteria)
var/abilities = available_abilities[criteria]
/datum/antagonist/vampire/proc/check_new_unlocks_by_rank(rank)
var/abilities = GLOB.vampire_abilities_rank[rank]
if(!abilities)
return
for(var/ability as anything in abilities)
Expand All @@ -31,12 +23,10 @@
if(current_abilities[ability_type])
return

var/datum/vampire_ability/ability = new ability_type

if(!ability.check_reqs(src))
qdel(ability)
if(!can_unlock_ability(ability_type))
return

var/datum/vampire_ability/ability = new ability_type
current_abilities[ability_type] = ability
ability.grant(src)

Expand All @@ -46,3 +36,20 @@
var/datum/vampire_ability/ability = current_abilities[ability_type]
ability.remove()
current_abilities.Cut()

/// Returns whether the given vampire meets the requirements to get this ability.
/datum/antagonist/vampire/proc/can_unlock_ability(datum/vampire_ability/ability_type)
if(vampire_rank < initial(ability_type.min_rank))
return FALSE

var/clan_req = initial(ability_type.clan_req)
if(clan_req && clan != clan_req)
return FALSE

var/list/stat_reqs = GLOB.vampire_abilities_reqs[ability_type]
if(islist(stat_reqs))
for(var/stat as anything in stat_reqs)
if(get_stat(stat) < stat_reqs[stat])
return FALSE

return TRUE
15 changes: 2 additions & 13 deletions monkestation/code/modules/antagonists/vampire/vampire_datum.dm
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
var/spent_stat_points = 0

/// The stats of the vampire. The cornerstone of progression alongside ranks. Don't modify this directly.
var/list/stats = list(
VAR_PRIVATE/list/stats = list(
VAMPIRE_STAT_BRUTALITY = 12, // DEBUG STATS, REMEMBER TO REVERT THESE LATER
VAMPIRE_STAT_TENACITY = 12,
VAMPIRE_STAT_PURSUIT = 12,
Expand All @@ -77,13 +77,6 @@
/// These are instances sorted by their type.
var/list/current_abilities = list()

/// Associative list of available abilities by their unlock conditions.
/// Abilities that unlock based on a stat use the define of that stat as their key.
/// And ones that have a rank requirement use VAMPIRE_ABILITIES_RANK.
/// There's also VAMPIRE_ABILITIES_ALL if you need it for some reason.
/// The abilities in here are in typepath form.
var/static/list/available_abilities

/// The action that grants us night vision at will.
var/datum/action/adjust_vision/vampire/vision_action

Expand All @@ -101,10 +94,6 @@
/// Associative list of stat modifiers. Applied as multipliers. Don't modify this directly.
var/list/stat_mods = list()

/datum/antagonist/vampire/New()
. = ..()
init_available_abilities()

/datum/antagonist/vampire/on_gain()
vampire_rank = starting_rank
owner.current.playsound_local(get_turf(owner.current), 'monkestation/sound/vampires/vampire_alert.ogg', vol = 100, vary = FALSE, pressure_affected = FALSE, use_reverb = FALSE)
Expand Down Expand Up @@ -136,7 +125,7 @@
else
RegisterSignal(target_mob, COMSIG_MOB_HUD_CREATED, PROC_REF(on_hud_created))

check_ability_reqs_of_criteria(VAMPIRE_ABILITIES_ALL) // we only do it this way once
check_new_unlocks() // we only do it this way once

/datum/antagonist/vampire/remove_innate_effects(mob/living/mob_override)
var/mob/living/carbon/human/target_mob = mob_override || owner.current
Expand Down
36 changes: 36 additions & 0 deletions monkestation/code/modules/antagonists/vampire/vampire_lists.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/// Associative list of available abilities by their unlock conditions.
/// Abilities that unlock based on a stat use the define of that stat as their key.
/// And ones that have a rank requirement use VAMPIRE_ABILITIES_RANK.
/// There's also VAMPIRE_ABILITIES_ALL if you need it for some reason.
/// The abilities in here are in typepath form.

/// list of all possible vampire abilities.
GLOBAL_LIST_INIT(vampire_all_abilities, init_available_vampire_abilities())
/// // Associative list of vampire abilities indexed by stat and then ability type, giving you the stat number that you need
GLOBAL_LIST(vampire_abilities_reqs)
/// Associative list of vampire abilities indexed by ability type containing the stat requirements
GLOBAL_LIST(vampire_abilities_stat)
/// Associative list of vampire abilities indexed by rank containing the abilities that unlock at that rank
GLOBAL_LIST(vampire_abilities_rank)

/// Initializes the list of available vampire abilities.
/proc/init_available_vampire_abilities()
var/list/all = subtypesof(/datum/vampire_ability)
GLOB.vampire_abilities_stat = list()
GLOB.vampire_abilities_reqs = list()
GLOB.vampire_abilities_rank = list()

for(var/datum/vampire_ability/ability_type as anything in all)
var/datum/vampire_ability/ability = new ability_type
if(length(ability.stat_reqs))
GLOB.vampire_abilities_reqs[ability_type] = ability.stat_reqs.Copy()

if(ability.min_rank != 0)
GLOB.vampire_abilities_rank["[ability.min_rank]"] += list(ability_type)

for(var/stat_name in ability.stat_reqs)
GLOB.vampire_abilities_stat[stat_name] += list(ability_type)

qdel(ability)
return all

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
new_stat_points += VAMPIRE_SP_CAITIFF_BONUS * new_rank
set_stat_points(new_stat_points)

check_ability_reqs_of_criteria(VAMPIRE_ABILITIES_RANK)
check_new_unlocks_by_rank()

SEND_SIGNAL(src, COMSIG_VAMPIRE_RANK_CHANGED, old_rank)
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

var/new_modified_amount = get_stat_modified(stat)

check_ability_reqs_of_criteria(stat)
check_new_unlocks_by_stat(stat)

SEND_SIGNAL(src, COMSIG_VAMPIRE_STAT_CHANGED, stat, old_amount, new_amount)

Expand Down
1 change: 1 addition & 0 deletions tgstation.dme
Original file line number Diff line number Diff line change
Expand Up @@ -6191,6 +6191,7 @@
#include "monkestation\code\modules\antagonists\vampire\vampire_datum.dm"
#include "monkestation\code\modules\antagonists\vampire\vampire_hud.dm"
#include "monkestation\code\modules\antagonists\vampire\vampire_lifeforce.dm"
#include "monkestation\code\modules\antagonists\vampire\vampire_lists.dm"
#include "monkestation\code\modules\antagonists\vampire\vampire_masquerade.dm"
#include "monkestation\code\modules\antagonists\vampire\vampire_objectives.dm"
#include "monkestation\code\modules\antagonists\vampire\vampire_outfit.dm"
Expand Down

0 comments on commit d241fc1

Please sign in to comment.