You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

61 lines
1.9 KiB

import type { MapRegion } from 'db://assets/mx/module/battle/battlefield/MapRegion';
import type { EntityId } from 'db://assets/mx/module/battle/ecs/EntityId';
import type { BattleEventBus } from 'db://assets/mx/module/battle/events/BattleEventBus';
import { BattleEventFactory } from 'db://assets/mx/module/battle/events/BattleEvents';
/** 单玩家槽:经济、城墙、已部署单位 */
export class PlayerSlot {
/** 玩家 ID */
readonly id: number;
/** 当前金币 */
gold: number;
/** 城墙当前血量 */
wallHp: number;
/** 城墙最大血量 */
wallMaxHp: number;
/** 已部署单位实体 ID 列表 */
deployedUnits: EntityId[] = [];
/** 可部署区域 */
region: MapRegion;
/** 城墙免伤(GM 营地不掉血) */
immuneWall = false;
/**
* @param id 玩家 ID
* @param wallMaxHp 城墙最大血量
* @param startGold 初始金币
* @param region 可部署区域
*/
constructor(id: number, wallMaxHp: number, startGold: number, region: MapRegion) {
this.id = id;
this.wallMaxHp = wallMaxHp;
this.wallHp = wallMaxHp;
this.gold = startGold;
this.region = region;
}
/**
* @param amount 消费金额
* @returns 金币是否足够并已扣除
*/
spendGold(amount: number): boolean {
if (this.gold < amount) return false;
this.gold -= amount;
return true;
}
/** @param amount 增加金币 */
addGold(amount: number): void {
this.gold += amount;
}
/**
* @param amount 伤害量
* @param events 战斗事件总线
*/
damageWall(amount: number, events: BattleEventBus): void {
if (this.immuneWall) return;
this.wallHp = Math.max(0, this.wallHp - amount);
events.emit(BattleEventFactory.wallDamaged(this.id, amount, this.wallHp));
}
}