update
This commit is contained in:
@@ -1,93 +1,9 @@
|
||||
extends Node
|
||||
|
||||
const GCD_TIME := 0.5
|
||||
const AA_COOLDOWN := 0.5
|
||||
|
||||
@onready var player: CharacterBody3D = get_parent()
|
||||
@onready var targeting: Node = get_parent().get_node("Targeting")
|
||||
@onready var role: Node = get_parent().get_node("Role")
|
||||
|
||||
var abilities: Array = []
|
||||
var cooldowns: Array[float] = [0.0, 0.0, 0.0, 0.0, 0.0]
|
||||
var max_cooldowns: Array[float] = [0.0, 0.0, 0.0, 0.0, 0.0]
|
||||
var gcd_timer := 0.0
|
||||
var aa_timer := 0.0
|
||||
|
||||
func _ready() -> void:
|
||||
_load_abilities()
|
||||
EventBus.role_changed.connect(_on_role_changed)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if gcd_timer > 0:
|
||||
gcd_timer -= delta
|
||||
for i in range(cooldowns.size()):
|
||||
if cooldowns[i] > 0:
|
||||
cooldowns[i] -= delta
|
||||
EventBus.cooldown_tick.emit(cooldowns, max_cooldowns, gcd_timer)
|
||||
_auto_attack(delta)
|
||||
|
||||
func _auto_attack(delta: float) -> void:
|
||||
aa_timer -= delta
|
||||
if aa_timer > 0:
|
||||
return
|
||||
if not targeting.in_combat or not targeting.current_target:
|
||||
return
|
||||
if not is_instance_valid(targeting.current_target):
|
||||
return
|
||||
var ability_set: AbilitySet = role.get_ability_set()
|
||||
if not ability_set:
|
||||
return
|
||||
var aa_damage: float = ability_set.aa_damage
|
||||
var aa_range: float = ability_set.aa_range
|
||||
var aa_is_heal: bool = ability_set.aa_is_heal
|
||||
var dmg: float = apply_passive(aa_damage, "heal" if aa_is_heal else "damage")
|
||||
if aa_is_heal:
|
||||
EventBus.heal_requested.emit(player, player, dmg)
|
||||
print("AA Heal: %s an %s" % [dmg, player.name])
|
||||
else:
|
||||
var dist := player.global_position.distance_to(targeting.current_target.global_position)
|
||||
if dist > aa_range:
|
||||
return
|
||||
var target_name: String = targeting.current_target.name
|
||||
EventBus.damage_requested.emit(player, targeting.current_target, dmg)
|
||||
print("AA: %s Schaden an %s" % [dmg, target_name])
|
||||
aa_timer = AA_COOLDOWN
|
||||
|
||||
func _load_abilities() -> void:
|
||||
var ability_set: AbilitySet = role.get_ability_set()
|
||||
if ability_set:
|
||||
abilities = ability_set.abilities
|
||||
else:
|
||||
abilities = []
|
||||
cooldowns = [0.0, 0.0, 0.0, 0.0, 0.0]
|
||||
max_cooldowns = [0.0, 0.0, 0.0, 0.0, 0.0]
|
||||
gcd_timer = 0.0
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
for i in range(min(abilities.size(), 5)):
|
||||
if event.is_action_pressed("ability_%s" % (i + 1)) and abilities[i]:
|
||||
if abilities[i].type == Ability.Type.PASSIVE:
|
||||
return
|
||||
if cooldowns[i] > 0:
|
||||
return
|
||||
if abilities[i].uses_gcd and gcd_timer > 0:
|
||||
return
|
||||
var success: bool = abilities[i].execute(player, targeting)
|
||||
if not success:
|
||||
return
|
||||
var ability_cd: float = abilities[i].cooldown
|
||||
var gcd_cd: float = GCD_TIME if abilities[i].uses_gcd else 0.0
|
||||
cooldowns[i] = ability_cd
|
||||
max_cooldowns[i] = max(ability_cd, gcd_cd)
|
||||
if abilities[i].uses_gcd:
|
||||
gcd_timer = GCD_TIME
|
||||
for i in range(5):
|
||||
if event.is_action_pressed("ability_%s" % (i + 1)):
|
||||
EventBus.ability_use_requested.emit(player, i)
|
||||
return
|
||||
|
||||
func apply_passive(base: float, stat: String = "damage") -> float:
|
||||
for ability in abilities:
|
||||
if ability and ability.type == Ability.Type.PASSIVE and ability.passive_stat == stat:
|
||||
return base * (1.0 + ability.damage / 100.0)
|
||||
return base
|
||||
|
||||
func _on_role_changed(_player: Node, _role_type: int) -> void:
|
||||
_load_abilities()
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
extends Node
|
||||
|
||||
const SPEED := 5.0
|
||||
const JUMP_VELOCITY := 4.5
|
||||
|
||||
var gravity: float = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||
|
||||
@onready var player: CharacterBody3D = get_parent()
|
||||
@@ -11,8 +8,12 @@ func _physics_process(delta: float) -> void:
|
||||
if not player.is_on_floor():
|
||||
player.velocity.y -= gravity * delta
|
||||
|
||||
var base: BaseStats = Stats.get_base(player)
|
||||
var speed: float = base.speed if base is PlayerStats else 5.0
|
||||
var jump_velocity: float = base.jump_velocity if base is PlayerStats else 4.5
|
||||
|
||||
if Input.is_action_just_pressed("ui_accept") and player.is_on_floor():
|
||||
player.velocity.y = JUMP_VELOCITY
|
||||
player.velocity.y = jump_velocity
|
||||
|
||||
var input_dir := Input.get_vector("move_left", "move_right", "move_forward", "move_back")
|
||||
var camera_pivot := player.get_node("CameraPivot") as Node3D
|
||||
@@ -26,10 +27,10 @@ func _physics_process(delta: float) -> void:
|
||||
var direction := (forward * -input_dir.y + right * input_dir.x).normalized()
|
||||
|
||||
if direction:
|
||||
player.velocity.x = direction.x * SPEED
|
||||
player.velocity.z = direction.z * SPEED
|
||||
player.velocity.x = direction.x * speed
|
||||
player.velocity.z = direction.z * speed
|
||||
else:
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, SPEED)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, SPEED)
|
||||
player.velocity.x = move_toward(player.velocity.x, 0, speed)
|
||||
player.velocity.z = move_toward(player.velocity.z, 0, speed)
|
||||
|
||||
player.move_and_slide()
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
extends CharacterBody3D
|
||||
|
||||
@export var stats: BaseStats
|
||||
|
||||
func _ready() -> void:
|
||||
add_to_group("player")
|
||||
Stats.register(self, stats)
|
||||
var cooldown_system: Node = get_tree().get_first_node_in_group("cooldown_system")
|
||||
if cooldown_system:
|
||||
cooldown_system.register(self, 5)
|
||||
if GameState.returning_from_dungeon:
|
||||
GameState.restore_player(self)
|
||||
global_position = GameState.portal_position + Vector3(0, 1, -5)
|
||||
GameState.returning_from_dungeon = false
|
||||
elif GameState.dungeon_cleared:
|
||||
GameState.clear()
|
||||
var health: float = Stats.get_stat(self, "health")
|
||||
var max_health: float = Stats.get_stat(self, "max_health")
|
||||
var shield: float = Stats.get_stat(self, "shield")
|
||||
var max_shield: float = Stats.get_stat(self, "max_shield")
|
||||
EventBus.health_changed.emit(self, health, max_health)
|
||||
EventBus.shield_changed.emit(self, shield, max_shield)
|
||||
|
||||
func _exit_tree() -> void:
|
||||
Stats.deregister(self)
|
||||
var cooldown_system: Node = get_tree().get_first_node_in_group("cooldown_system")
|
||||
if cooldown_system:
|
||||
cooldown_system.deregister(self)
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
extends Node
|
||||
|
||||
const RESPAWN_TIME := 3.0
|
||||
var respawn_timer := 0.0
|
||||
var is_dead := false
|
||||
var spawn_position: Vector3
|
||||
|
||||
@onready var player: CharacterBody3D = get_parent()
|
||||
|
||||
func _ready() -> void:
|
||||
spawn_position = Vector3(0, 1, -5)
|
||||
EventBus.entity_died.connect(_on_entity_died)
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if is_dead:
|
||||
respawn_timer -= delta
|
||||
EventBus.respawn_tick.emit(respawn_timer)
|
||||
if respawn_timer <= 0:
|
||||
_respawn()
|
||||
|
||||
func _on_entity_died(entity: Node) -> void:
|
||||
if entity == player and not is_dead:
|
||||
is_dead = true
|
||||
respawn_timer = RESPAWN_TIME
|
||||
player.velocity = Vector3.ZERO
|
||||
player.get_node("Mesh").visible = false
|
||||
player.get_node("CollisionShape3D").disabled = true
|
||||
player.get_node("Movement").set_physics_process(false)
|
||||
player.get_node("Combat").set_process_unhandled_input(false)
|
||||
player.get_node("Targeting").set_process_unhandled_input(false)
|
||||
|
||||
func _respawn() -> void:
|
||||
is_dead = false
|
||||
player.global_position = spawn_position
|
||||
player.get_node("Mesh").visible = true
|
||||
player.get_node("CollisionShape3D").disabled = false
|
||||
player.get_node("Movement").set_physics_process(true)
|
||||
player.get_node("Combat").set_process_unhandled_input(true)
|
||||
player.get_node("Targeting").set_process_unhandled_input(true)
|
||||
var health_node: Node = player.get_node("Health")
|
||||
var shield_node: Node = player.get_node("Shield")
|
||||
health_node.current_health = health_node.max_health
|
||||
shield_node.current_shield = shield_node.max_shield
|
||||
EventBus.health_changed.emit(player, health_node.current_health, health_node.max_health)
|
||||
EventBus.shield_changed.emit(player, shield_node.current_shield, shield_node.max_shield)
|
||||
EventBus.player_respawned.emit(player)
|
||||
@@ -1 +0,0 @@
|
||||
uid://dw3dtax5bx0of
|
||||
Reference in New Issue
Block a user