39 lines
1.0 KiB
GDScript
39 lines
1.0 KiB
GDScript
extends Node
|
|
|
|
var entities: Dictionary = {}
|
|
|
|
func register(entity: Node, base: Resource) -> void:
|
|
entities[entity] = {
|
|
"base": base,
|
|
"health": base.max_health,
|
|
"max_health": base.max_health,
|
|
"alive": true,
|
|
}
|
|
|
|
func deregister(entity: Node) -> void:
|
|
entities.erase(entity)
|
|
|
|
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 is_alive(entity: Node) -> bool:
|
|
if entity in entities:
|
|
return entities[entity]["alive"]
|
|
return false
|
|
|
|
func set_health(entity: Node, value: float) -> void:
|
|
if entity not in entities:
|
|
return
|
|
entities[entity]["health"] = value
|
|
var max_health: float = entities[entity]["max_health"]
|
|
EventBus.tavern_damaged.emit(value, max_health)
|
|
if value <= 0 and entities[entity]["alive"]:
|
|
entities[entity]["alive"] = false
|
|
EventBus.tavern_destroyed.emit()
|