last init
This commit is contained in:
35
scripts/player/combat.gd
Normal file
35
scripts/player/combat.gd
Normal file
@@ -0,0 +1,35 @@
|
||||
extends Node
|
||||
|
||||
@onready var player: CharacterBody3D = get_parent()
|
||||
@onready var targeting: Node = get_parent().get_node("Targeting")
|
||||
@onready var player_class: Node = get_parent().get_node("PlayerClass")
|
||||
|
||||
var abilities: Array = []
|
||||
|
||||
func _ready() -> void:
|
||||
_load_abilities()
|
||||
EventBus.class_changed.connect(_on_class_changed)
|
||||
|
||||
func _load_abilities() -> void:
|
||||
var ability_set: AbilitySet = player_class.get_ability_set()
|
||||
if ability_set:
|
||||
abilities = ability_set.abilities
|
||||
else:
|
||||
abilities = []
|
||||
|
||||
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
|
||||
abilities[i].execute(player, targeting)
|
||||
return
|
||||
|
||||
func apply_passive(base_damage: float) -> float:
|
||||
for ability in abilities:
|
||||
if ability and ability.type == Ability.Type.PASSIVE:
|
||||
return base_damage * (1.0 + ability.damage / 100.0)
|
||||
return base_damage
|
||||
|
||||
func _on_class_changed(_player: Node, _class_type: int) -> void:
|
||||
_load_abilities()
|
||||
Reference in New Issue
Block a user