import { get } from "http"; import MathUtils from "../ExUtils/MathUtils"; import { Global } from "../Global"; import { IEnemy } from "../Mgr_CSV/CsvEnum"; import { LocalDataMgr } from "./LocalDataMgr"; // import { TRIGGER_MUTATE_OBJTYPE } from "../const/GameEnum"; /**通用的敌人类,config为IEnemy或IMutate接口 */ export default class EnemyData{ private _hp: number = 0; private _totalHP: number = 0; private _reward: number = 0; // 奖励(仅异兽对象有用) private _duration: number = 0; // 时长(仅异兽对象有用) private _tgbyboss: boolean = false; // 是否是打boss触发(仅异兽对象有用) private _tgDesc: string = ""; // 异兽触发者的描述 private _coin: number = 0; // 铜币奖励(仅对异兽有效) private tglvBossConfig: IEnemy = null; // 触发关卡的boss对象配置(仅异兽对象有用) public head: string = ""; public config: any = null; public fighting: boolean = false; constructor(head: string, config: any, fighting: boolean = false, tglvbosscfg: IEnemy = null, triggerbyboss: boolean = false, triggerDesc: string = "", reward: number = 0, coin: number = 0) { this.head = head; this.initInfo(config, tglvbosscfg, fighting, triggerbyboss, triggerDesc, reward, coin); } initInfo(config: any, tglvbosscfg: IEnemy, fighting: boolean = false, triggerbyboss: boolean = false, triggerDesc: string = "", reward: number = 0, coin: number = 0){ this.config = config; this._tgbyboss = triggerbyboss; this._tgDesc = triggerDesc; this.fighting = fighting; this.tglvBossConfig = tglvbosscfg; // 正常怪,非异兽对象 if(tglvbosscfg == null){ this._totalHP = Number(this.config.hp); this._reward = this._duration = 0; }else{ // 异兽对象,boss触发 // const passtime = LocalDataMgr.Pass.passed_times; // const hpex = Math.floor(Number(this.currMTBoss.totalHP) * passtime * 0.05); // this.currMTBoss.totalHP += hpex; let randomhp = Global.CsvMgr.cnf_discretization_csv[4]; let randomreward = Global.CsvMgr.cnf_discretization_csv[6]; if(triggerbyboss){ randomhp = Global.CsvMgr.cnf_discretization_csv[5]; randomreward = Global.CsvMgr.cnf_discretization_csv[7]; this._totalHP = Math.floor(tglvbosscfg.hp * (config.hp_boss + MathUtils.RandomInt(randomhp.num1, randomhp.num2) * 0.01)); this._reward = reward > 0? reward : config.reward_boss + MathUtils.RandomInt(randomreward.num1, randomreward.num2); this._coin = coin > 0? coin : Math.floor(tglvbosscfg.bounty * config.hp_boss / 3); }else{ this._totalHP = Math.floor(tglvbosscfg.hp * (config.hp + MathUtils.RandomInt(randomhp.num1, randomhp.num2) * 0.01)); this._reward = reward > 0? reward : config.reward + MathUtils.RandomInt(randomreward.num1, randomreward.num2); this._coin = coin > 0? coin : Math.floor(tglvbosscfg.bounty * config.hp / 3); } this._duration = tglvbosscfg.duration; } this.reset(); } /** * 重置敌人状态(满血) */ reset(): void { this._hp = this._totalHP; } /** * 获取当前生命值百分比 */ get hpPercent(): number { return this._totalHP > 0 ? this._hp / this._totalHP : 0; } // Getter 和 Setter 方法 /** * 获取当前生命值 */ get hp(): number { return this._hp; } /** * 设置当前生命值(自动限制范围) */ set hp(value: number) { this._hp = Math.max(0, Math.min(value, this._totalHP)); } /** * 获取最大生命值 */ get totalHP(): number { return this._totalHP; } /** * 设置最大生命值(自动调整当前生命值) */ set totalHP(value: number) { const ratio = this.hpPercent; this._totalHP = Math.max(1, value); this._hp = Math.floor(this._totalHP * ratio); } /** * 获取敌人显示名称 */ get displayName(): string { return this.config.name || `敌人_${this.head}`; } /** * 获取敌人显示图标 */ get headIcon(): string { return this.config.headicon || "headicon_11"; } /**spine皮肤 */ get skin(): string { return `${this.config.sp}/${this.config.sp}` || "monster_1/monster_1"; } /**音频 */ get audio(): string { return this.config.audio || ""; } /** * 获取敌人战斗时长 */ get duration(): number { return this._duration; } /** * 获取异兽的真实奖励 */ get realReward(): number { const addpre = LocalDataMgr.Mutate.getRewardAddPre(); const reward = this._reward * (1 + addpre); return Math.floor(reward); } get reward(): number { return this._reward; } /** * 获取异兽的铜币真实奖励 */ get realCoin(): number { const addpre = LocalDataMgr.Mutate.getRewardAddPre(); const coin = this._coin * (1 + addpre); return Math.floor(coin); } get coin(): number { return this._coin; } /** * 获取敌人是否是由关卡boss触发的 */ get tgbyboss(): boolean { return this._tgbyboss; } /** * 获取触发者描述 */ get tgDesc(): string { return this._tgDesc; } /** * 克隆敌人数据 */ clone(): EnemyData { return new EnemyData(this.head, this.config, this.fighting, this.tglvBossConfig); } /** * 序列化敌人数据(用于存档) */ serialize(): any { return { head: this.head, hp: this._hp, totalHP: this._totalHP, fighting: this.fighting, config: this.config, tglvBossConfig: this.tglvBossConfig }; } /** * 从序列化数据恢复 */ deserialize(data: any): void { this.head = data.head; this._hp = data.hp; this._totalHP = data.totalHP; this.fighting = data.fighting; this.config = data.config; this.tglvBossConfig = data.tglvBossConfig; } }