1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-02 17:31:55 +08:00

refactor(武器系统): 重构武器冷却和攻击逻辑

- 将CooldownTimer的startCooldown方法重命名为更简洁的start
- 为EntityBase添加weaponStore节点管理武器
- 修改武器攻击逻辑,现在由Weapon类自身处理冷却和攻击
- 调整武器卡片的UI布局和描述居中显示
- 为Rooster角色添加预设武器
This commit is contained in:
2025-09-06 07:40:21 +08:00
parent c16a1ee73c
commit debb450044
8 changed files with 51 additions and 18 deletions
+19 -4
View File
@@ -64,7 +64,6 @@ var inventoryMax = {
@export var dropCounts: Array[Vector2] = []
@export var appleCount: Vector2i = Vector2(0, 2) # 死亡后掉落的苹果数量
@export var level: int = 1
@export var weapons: Array[Weapon] = []
@onready var animatree: AnimationTree = $"%animatree"
@onready var texture: AnimatedSprite2D = $"%texture"
@@ -73,6 +72,7 @@ var inventoryMax = {
@onready var hurtAnimator: AnimationPlayer = $"%hurtAnimator"
@onready var damageAnchor: Node2D = $"%damageAnchor"
@onready var trailParticle: GPUParticles2D = $"%trailParticle"
@onready var weaponStore = $"%weaponStore"
var statebar: EntityStateBar
var health: float = 0
@@ -84,6 +84,7 @@ var lastDirection: int = 1
var currentFocusedBoss: EntityBase = null
var charginup: bool = false
var cooldownTimer = CooldownTimer.new()
var weapons: Array[Weapon] = []
func _ready():
register()
@@ -94,6 +95,9 @@ func _ready():
statebar = selfStatebar
statebar.entity = self
if isPlayer():
for i in weaponStore.get_children():
i.hide()
weapons.append(i)
statebar.levelLabels.hide()
UIState.player = self
energyChanged.connect(
@@ -190,16 +194,27 @@ func useEnergy(value: float):
energyChanged.emit(energy)
return state
func tryAttack(type: int, needChargeUp: bool = false):
var weapon: Weapon
if isPlayer():
weapon = weapons[type]
var state
if !isPlayer():
if isPlayer():
state = weapon.cooldownTimer.start()
else:
cooldownTimer.cooldown = attackCooldownMap.get(type, defaultCooldownUnit)
state = cooldownTimer.startCooldown()
state = cooldownTimer.start()
if state:
if needChargeUp:
charginup = true
await EffectController.create(preload("res://components/Effects/AttackStar.tscn"), damageAnchor.global_position).shot()
charginup = false
if attack(type):
var done
if isPlayer():
done = weapon.attack(self)
print("test", done, weapon.name)
else:
done = attack(type)
if done:
playSound("attack" + str(type))
return state
func trySprint():