1
1
mirror of https://github.com/Rundll86/Dog-Lynx-And-HCN.git synced 2026-06-05 19:27:15 +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
@@ -7,3 +7,5 @@ func update(to: int, origin: Dictionary, _entity: EntityBase):
func attack(entity: EntityBase):
var weaponPos = entity.findWeaponAnchor("normal")
BulletBase.generate(preload("res://components/Bullets/PurpleCrystal.tscn"), entity, weaponPos, (get_global_mouse_position() - weaponPos).angle())
print("test2")
return true
+1 -1
View File
@@ -5,7 +5,7 @@ var lastStart: int = 0
func isCooldowned():
return WorldManager.getTime() - lastStart >= cooldown
func startCooldown():
func start():
var state = isCooldowned()
if state:
lastStart = WorldManager.getTime()
+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():
+4 -1
View File
@@ -24,11 +24,14 @@ signal selected(applied: bool)
@onready var costsBox: GridContainer = $"%costs"
@onready var selectButton: Button = $"%selectBtn"
var cooldownTimer = CooldownTimer.new()
func _ready():
selectButton.pressed.connect(
func():
apply(UIState.player)
)
cooldownTimer.cooldown = cooldown
rebuildInfo()
func _physics_process(_delta: float):
descriptionLabel.text = buildDescription()
@@ -76,7 +79,7 @@ func buildDescription():
var result = descriptionTemplate
for key in store.keys():
result = result.replace("$" + key, "[color=cyan]%.1f[/color]" % readStore(key))
return result
return "[center]%s[/center]" % result
func readStore(key: String, default: Variant = null):
return store.get(key, default)