fix(game): 修复召唤按钮第二次失效和实习生不攻击的Bug

This commit is contained in:
Cloud Bot
2026-03-21 09:00:43 +00:00
parent caf9c698c9
commit 27ba03260f
3 changed files with 11 additions and 2 deletions

View File

@@ -10,7 +10,8 @@ export class InternTower extends TowerBase {
public onSelfDestroy?: (tower: InternTower) => void public onSelfDestroy?: (tower: InternTower) => void
constructor(scene: Phaser.Scene, gridX: number, gridY: number) { constructor(scene: Phaser.Scene, gridX: number, gridY: number) {
super(scene, gridX, gridY, 50, 1, 15, 1.5, 'tower-intern') // attackRange=1.5:近战覆盖相邻格,避免格子边界浮点漏攻击
super(scene, gridX, gridY, 50, 1.5, 15, 1.5, 'tower-intern')
} }
override update(delta: number, enemies: EnemyBase[]): void { override update(delta: number, enemies: EnemyBase[]): void {

View File

@@ -100,7 +100,8 @@ export abstract class TowerBase {
} }
protected findTarget(enemies: EnemyBase[]): EnemyBase | null { protected findTarget(enemies: EnemyBase[]): EnemyBase | null {
const rangePx = this.attackRange * this.cellW // +0.5格容忍量,避免怪物恰好在射程边界时因浮点误差漏判
const rangePx = (this.attackRange + 0.5) * this.cellW
let best: EnemyBase | null = null let best: EnemyBase | null = null
let bestProgress = -1 let bestProgress = -1
for (const e of enemies) { for (const e of enemies) {

View File

@@ -11,6 +11,7 @@ export class HUD {
private scene: Phaser.Scene private scene: Phaser.Scene
private waveBtn: Phaser.GameObjects.Text | null = null private waveBtn: Phaser.GameObjects.Text | null = null
private waveBannerTimeout: (() => void) | null = null private waveBannerTimeout: (() => void) | null = null
private _onClick: (() => void) | null = null
constructor(scene: Phaser.Scene) { constructor(scene: Phaser.Scene) {
this.scene = scene this.scene = scene
@@ -22,6 +23,7 @@ export class HUD {
*/ */
createWaveButton(onClick: () => void): void { createWaveButton(onClick: () => void): void {
if (this.waveBtn) this.waveBtn.destroy() if (this.waveBtn) this.waveBtn.destroy()
this._onClick = onClick // 保存引用,供 enableWaveButton 重新绑定
this.waveBtn = this.scene.add this.waveBtn = this.scene.add
.text(GAME_WIDTH - 160, HUD_HEIGHT + 20, '▶ 召唤下一波', { .text(GAME_WIDTH - 160, HUD_HEIGHT + 20, '▶ 召唤下一波', {
@@ -58,6 +60,11 @@ export class HUD {
enableWaveButton(): void { enableWaveButton(): void {
if (!this.waveBtn) return if (!this.waveBtn) return
this.waveBtn.setStyle({ color: '#A78BFA', backgroundColor: '#1e3a5f' }) this.waveBtn.setStyle({ color: '#A78BFA', backgroundColor: '#1e3a5f' })
// 重新绑定点击事件disableWaveButton 会 removeAllListeners
this.waveBtn.removeAllListeners('pointerdown')
if (this._onClick) {
this.waveBtn.on('pointerdown', () => this._onClick!())
}
} }
/** /**