fix(game): 修复底部塔面板不可见问题,改用React层实现,并用AI素材替换Graphics像素块

This commit is contained in:
Cloud Bot
2026-03-21 08:32:23 +00:00
parent 66b7776f32
commit 085aa0a407
14 changed files with 405 additions and 469 deletions

View File

@@ -1,45 +1,24 @@
import type Phaser from 'phaser'
import { TowerBase } from './TowerBase'
import type { EnemyBase } from '../enemies/EnemyBase'
import type { TowerBase as TowerBaseType } from './TowerBase'
const BUFF_ATTACK_SPEED_BONUS = 0.2
export class HRBPTower extends TowerBase {
private buffCooldown: number = 0
private readonly BUFF_INTERVAL = 500
private nearbyTowersBuff: Set<TowerBaseType> = new Set()
private nearbyTowersBuff: Set<TowerBase> = new Set()
constructor(scene: Phaser.Scene, gridX: number, gridY: number) {
super(scene, gridX, gridY, 80, 1, 0, 0)
this.drawSprite()
}
drawSprite(): void {
if (!this.sprite) return
this.sprite.clear()
// 菱形(粉色)
this.sprite.fillStyle(0xec4899, 1)
this.sprite.fillTriangle(0, -16, 16, 0, 0, 16)
this.sprite.fillTriangle(0, -16, -16, 0, 0, 16)
this.sprite.setPosition(this.px, this.py)
this.sprite.setDepth(10)
super(scene, gridX, gridY, 80, 1, 0, 0, 'tower-hrbp')
}
override update(delta: number, enemies: EnemyBase[]): void {
// HRBP 没有攻击逻辑,只做 BUFF
void enemies
if (!this.isActive) {
this.stamina = Math.min(
this.maxStamina,
this.stamina + (this.staminaRegen * delta) / 1000
)
this.stamina = Math.min(this.maxStamina, this.stamina + (this.staminaRegen * delta) / 1000)
if (this.stamina > 20) this.isActive = true
this.updateStaminaBar()
return
}
this.buffCooldown -= delta
if (this.buffCooldown <= 0) {
this.buffCooldown = this.BUFF_INTERVAL
@@ -47,44 +26,30 @@ export class HRBPTower extends TowerBase {
}
}
setNearbyTowers(towers: TowerBaseType[]): void {
setNearbyTowers(towers: TowerBase[]): void {
this.nearbyTowersBuff = new Set(towers)
}
private applyBuffToNearby(): void {
if (this.nearbyTowersBuff.size === 0) return
if (this.stamina < 5) {
this.isActive = false
return
}
if (this.stamina < 5) { this.isActive = false; return }
this.stamina -= 5
this.updateStaminaBar()
// BUFF 效果通过 attackSpeedMultiplier 外部读取
// 这里显示一个粉色光圈效果
this.showBuffEffect()
}
private showBuffEffect(): void {
const g = this.scene.add.graphics()
g.lineStyle(2, 0xec4899, 0.6)
g.strokeCircle(this.px, this.py, 90)
g.strokeCircle(this.px, this.py, this.cellW * 1.5)
g.setDepth(8)
this.scene.tweens.add({
targets: g,
alpha: 0,
duration: 400,
targets: g, alpha: 0, duration: 400,
onComplete: () => g.destroy(),
})
}
getBuffedTowers(): Set<TowerBaseType> {
return this.nearbyTowersBuff
}
getAttackSpeedBonus(): number {
return BUFF_ATTACK_SPEED_BONUS
}
// HRBP 无直接攻击
getBuffedTowers(): Set<TowerBase> { return this.nearbyTowersBuff }
getAttackSpeedBonus(): number { return 0.2 }
attack(_target: EnemyBase): void {}
}