Files
DungeonCrawlerWorld/scripts/domain/entities/attributes.gd

45 lines
1.5 KiB
GDScript

class_name Attributes
extends RefCounted
const ATTRIBUTE_KEYS: Array[StringName] = [&"str_", &"agi", &"end", &"per", &"int_", &"wil", &"cha", &"luc"]
const SKILL_KEYS: Array[StringName] = [
&"melee", &"ranged", &"heavy", &"dodge", &"block", &"medicine", &"lockpicking",
&"traps", &"survival", &"engineering", &"persuasion", &"intimidation", &"bargaining",
&"observation", &"stealth", &"occultism", &"regeneration",
]
const BASE_ATTRIBUTE := 4
const BASE_SKILL := 1
var values: Dictionary[StringName, int] = {}
func _init(initial_values: Dictionary = {}) -> void:
for key in ATTRIBUTE_KEYS:
values[key] = int(initial_values.get(key, BASE_ATTRIBUTE))
func get_attribute(key: StringName) -> int:
return values.get(key, BASE_ATTRIBUTE)
func set_attribute(key: StringName, value: int) -> void:
if not ATTRIBUTE_KEYS.has(key):
push_warning("Unknown attribute key: %s" % key)
return
values[key] = value
func modify_attribute(key: StringName, delta: int) -> void:
set_attribute(key, get_attribute(key) + delta)
func to_dictionary() -> Dictionary[StringName, int]:
return values.duplicate()
static func default_skills(initial_values: Dictionary = {}) -> Dictionary[StringName, int]:
var skills: Dictionary[StringName, int] = {}
for key in SKILL_KEYS:
skills[key] = int(initial_values.get(key, BASE_SKILL))
return skills
static func is_attribute(key: StringName) -> bool:
return ATTRIBUTE_KEYS.has(key)
static func is_skill(key: StringName) -> bool:
return SKILL_KEYS.has(key)