update
This commit is contained in:
53
autoload/stats.gd
Normal file
53
autoload/stats.gd
Normal file
@@ -0,0 +1,53 @@
|
||||
extends Node
|
||||
|
||||
var entities: Dictionary = {}
|
||||
var player_cache: Dictionary = {}
|
||||
|
||||
func register(entity: Node, base: BaseStats) -> void:
|
||||
if entity.is_in_group("player") and not player_cache.is_empty():
|
||||
entities[entity] = player_cache.duplicate()
|
||||
entities[entity]["base_stats"] = base
|
||||
player_cache.clear()
|
||||
else:
|
||||
entities[entity] = {
|
||||
"base_stats": base,
|
||||
"health": base.max_health,
|
||||
"max_health": base.max_health,
|
||||
"health_regen": base.health_regen,
|
||||
"shield": base.max_shield,
|
||||
"max_shield": base.max_shield,
|
||||
"shield_regen_delay": base.shield_regen_delay,
|
||||
"shield_regen_time": base.shield_regen_time,
|
||||
"shield_regen_timer": 0.0,
|
||||
"alive": true,
|
||||
"buff_damage": 1.0,
|
||||
"buff_heal": 1.0,
|
||||
"buff_shield": 1.0,
|
||||
}
|
||||
|
||||
func deregister(entity: Node) -> void:
|
||||
if entity.is_in_group("player") and entity in entities:
|
||||
player_cache = entities[entity].duplicate()
|
||||
entities.erase(entity)
|
||||
|
||||
func clear_player_cache() -> void:
|
||||
player_cache.clear()
|
||||
|
||||
func get_stat(entity: Node, key: String) -> Variant:
|
||||
if entity in entities:
|
||||
return entities[entity].get(key)
|
||||
return null
|
||||
|
||||
func set_stat(entity: Node, key: String, value: Variant) -> void:
|
||||
if entity in entities:
|
||||
entities[entity][key] = value
|
||||
|
||||
func get_base(entity: Node) -> BaseStats:
|
||||
if entity in entities:
|
||||
return entities[entity]["base_stats"]
|
||||
return null
|
||||
|
||||
func is_alive(entity: Node) -> bool:
|
||||
if entity in entities:
|
||||
return entities[entity]["alive"]
|
||||
return false
|
||||
Reference in New Issue
Block a user