update
This commit is contained in:
@@ -1,16 +1,19 @@
|
||||
extends Node
|
||||
|
||||
@export var max_health := 100.0
|
||||
const HEALTH_REGEN := 1.0
|
||||
@export var stats: EntityStats
|
||||
var max_health: float
|
||||
var health_regen: float
|
||||
var current_health: float
|
||||
|
||||
func _ready() -> void:
|
||||
max_health = stats.max_health
|
||||
health_regen = stats.health_regen
|
||||
current_health = max_health
|
||||
EventBus.damage_requested.connect(_on_damage_requested)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if current_health > 0 and current_health < max_health:
|
||||
current_health = min(current_health + HEALTH_REGEN * delta, max_health)
|
||||
if current_health > 0 and current_health < max_health and health_regen > 0:
|
||||
current_health = min(current_health + health_regen * delta, max_health)
|
||||
EventBus.health_changed.emit(get_parent(), current_health, max_health)
|
||||
|
||||
func _on_damage_requested(attacker: Node, target: Node, amount: float) -> void:
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
extends Node
|
||||
|
||||
@export var max_shield := 50.0
|
||||
const REGEN_DELAY := 3.0
|
||||
const REGEN_TIME := 5.0
|
||||
@export var stats: EntityStats
|
||||
var max_shield: float
|
||||
var regen_delay: float
|
||||
var regen_time: float
|
||||
var current_shield: float
|
||||
var regen_timer := 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
max_shield = stats.max_shield
|
||||
regen_delay = stats.shield_regen_delay
|
||||
regen_time = stats.shield_regen_time
|
||||
current_shield = max_shield
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if max_shield <= 0:
|
||||
return
|
||||
if current_shield < max_shield:
|
||||
regen_timer += delta
|
||||
if regen_timer >= REGEN_DELAY:
|
||||
current_shield += (max_shield / REGEN_TIME) * delta
|
||||
if regen_timer >= regen_delay:
|
||||
current_shield += (max_shield / regen_time) * delta
|
||||
if current_shield >= max_shield:
|
||||
current_shield = max_shield
|
||||
EventBus.shield_regenerated.emit(get_parent())
|
||||
@@ -25,7 +31,6 @@ func absorb(amount: float) -> float:
|
||||
regen_timer = 0.0
|
||||
var absorbed: float = min(amount, current_shield)
|
||||
current_shield -= absorbed
|
||||
print("%s Schild: %s/%s (-%s)" % [get_parent().name, current_shield, max_shield, absorbed])
|
||||
if current_shield <= 0:
|
||||
EventBus.shield_broken.emit(get_parent())
|
||||
EventBus.shield_changed.emit(get_parent(), current_shield, max_shield)
|
||||
|
||||
44
scripts/components/spawner.gd
Normal file
44
scripts/components/spawner.gd
Normal file
@@ -0,0 +1,44 @@
|
||||
extends Node
|
||||
|
||||
@export var spawn_scene: PackedScene
|
||||
@export var spawn_count := 3
|
||||
@export var thresholds: Array[float] = [0.85, 0.70, 0.55, 0.40, 0.25, 0.10]
|
||||
|
||||
var triggered: Array[bool] = []
|
||||
|
||||
@onready var parent: Node3D = get_parent()
|
||||
@onready var health: Node = get_parent().get_node("Health")
|
||||
|
||||
func _ready() -> void:
|
||||
triggered.resize(thresholds.size())
|
||||
triggered.fill(false)
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if not spawn_scene or health.current_health <= 0:
|
||||
return
|
||||
var ratio: float = health.current_health / health.max_health
|
||||
for i in range(thresholds.size()):
|
||||
if not triggered[i] and ratio <= thresholds[i]:
|
||||
triggered[i] = true
|
||||
_spawn()
|
||||
|
||||
func _spawn() -> void:
|
||||
var spawned: Array = []
|
||||
for j in range(spawn_count):
|
||||
var entity: Node = spawn_scene.instantiate()
|
||||
var offset := Vector3(randf_range(-2, 2), 0, randf_range(-2, 2))
|
||||
parent.get_parent().add_child(entity)
|
||||
entity.global_position = parent.global_position + offset
|
||||
if "spawn_position" in entity:
|
||||
entity.spawn_position = parent.global_position
|
||||
if "portal" in entity:
|
||||
entity.portal = parent
|
||||
spawned.append(entity)
|
||||
var player: Node = get_tree().get_first_node_in_group("player")
|
||||
if player:
|
||||
var dist: float = parent.global_position.distance_to(player.global_position)
|
||||
if dist <= 10.0:
|
||||
for entity in spawned:
|
||||
if entity.has_method("_engage"):
|
||||
entity._engage(player)
|
||||
EventBus.portal_spawn.emit(parent, spawned)
|
||||
1
scripts/components/spawner.gd.uid
Normal file
1
scripts/components/spawner.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://cm2s3xkmuesey
|
||||
Reference in New Issue
Block a user