90 lines
2.8 KiB
TypeScript
90 lines
2.8 KiB
TypeScript
import type Phaser from 'phaser'
|
|
import { TowerBase } from './TowerBase'
|
|
import { GameManager } from '../GameManager'
|
|
import { AudioEngine } from '../AudioEngine'
|
|
import type { EnemyBase } from '../enemies/EnemyBase'
|
|
|
|
export class InternTower extends TowerBase {
|
|
private selfDestroyTimer: number = 0
|
|
private readonly SELF_DESTROY_INTERVAL = 1000
|
|
private destroyed: boolean = false
|
|
public onSelfDestroy?: (tower: InternTower) => void
|
|
|
|
constructor(scene: Phaser.Scene, gridX: number, gridY: number) {
|
|
// attackRange=1.5:近战覆盖相邻格,避免格子边界浮点漏攻击
|
|
super(scene, gridX, gridY, 50, 1.5, 15, 1.5, 'tower-intern')
|
|
}
|
|
|
|
override update(delta: number, enemies: EnemyBase[]): void {
|
|
if (this.destroyed) return
|
|
super.update(delta, enemies)
|
|
this.selfDestroyTimer += delta
|
|
if (this.selfDestroyTimer >= this.SELF_DESTROY_INTERVAL) {
|
|
this.selfDestroyTimer -= this.SELF_DESTROY_INTERVAL
|
|
if (Math.random() < 0.01) {
|
|
GameManager.getInstance().addHC(25)
|
|
this.showMessage('实习生跑路!+25HC', '#22C55E')
|
|
this.destroyed = true
|
|
this.onSelfDestroy?.(this)
|
|
this.destroy()
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
attack(target: EnemyBase): void {
|
|
AudioEngine.getInstance().playPunch()
|
|
const isInstakill = Math.random() < 0.05 && target.hp < 500
|
|
if (isInstakill) {
|
|
target.takeDamage(9999)
|
|
this.showMessage('整顿职场!秒杀!', '#A3E635')
|
|
} else {
|
|
target.takeDamage(this.attackDamage)
|
|
}
|
|
this.showMeleeEffect(target)
|
|
}
|
|
|
|
private showMeleeEffect(target: EnemyBase): void {
|
|
// 从塔飞向目标的拳头轨迹
|
|
const fist = this.scene.add.text(this.px, this.py, '👊', {
|
|
fontSize: '18px',
|
|
}).setOrigin(0.5, 0.5).setDepth(16)
|
|
|
|
this.scene.tweens.add({
|
|
targets: fist,
|
|
x: target.x,
|
|
y: target.y,
|
|
duration: 120,
|
|
ease: 'Power2',
|
|
onComplete: () => {
|
|
fist.destroy()
|
|
// 命中爆炸圆圈
|
|
const g = this.scene.add.graphics()
|
|
g.lineStyle(3, 0xa3e635, 1)
|
|
g.strokeCircle(target.x, target.y, 16)
|
|
g.fillStyle(0xa3e635, 0.25)
|
|
g.fillCircle(target.x, target.y, 16)
|
|
g.setDepth(15)
|
|
this.scene.tweens.add({
|
|
targets: g,
|
|
scaleX: 1.6, scaleY: 1.6, alpha: 0,
|
|
duration: 250,
|
|
onComplete: () => g.destroy(),
|
|
})
|
|
},
|
|
})
|
|
}
|
|
|
|
private showMessage(msg: string, color: string): void {
|
|
const txt = this.scene.add
|
|
.text(this.px, this.py - 30, msg, {
|
|
fontFamily: 'VT323, monospace', fontSize: '14px',
|
|
color, backgroundColor: '#052e16', padding: { x: 4, y: 2 },
|
|
}).setOrigin(0.5, 1).setDepth(20)
|
|
this.scene.tweens.add({
|
|
targets: txt, y: this.py - 55, alpha: 0,
|
|
duration: 1200, onComplete: () => txt.destroy(),
|
|
})
|
|
}
|
|
}
|