大侠
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.
 
 
 

263 lines
8.3 KiB

import { BOUNTY_PARAMS } from "../const/GameEnum";
import { LevelData } from "../const/GameInterface";
import { SOUL_PARAMS, TREASURE_TYPE } from "../const/GGameData";
import { Global } from "../Global";
import CsvMgr from "../Mgr_CSV/CsvMgr";
import EnemyData from "./EnemyData";
import { LocalDataMgr } from "./LocalDataMgr";
export default class LevelDataPoxy{
private archive: LevelData;
public monster: EnemyData;
public boss: EnemyData;
public exp: number = 0;
public config: any = undefined;
public index: number = 0;
public headIndex: number = 1;
public bossConfig: any = undefined;
public monsterConfig: any = undefined;
constructor(archive: LevelData) {
this.archive = archive;
this.refreshConfig();
this.reset();
}
/**
* 刷新关卡配置数据
*/
refreshConfig(): void {
const levelConfigs = CsvMgr.Level_csv;
const levelKeys = Object.keys(levelConfigs);
const firstLevelId = Number(levelKeys[0]);
const lastLevelId = Number(levelKeys[levelKeys.length - 1]);
const currentLevelId = (Number(this.id) > lastLevelId)? lastLevelId : this.id + LocalDataMgr.Pass.restart_times * 21;//Math.min(Number(this.id), lastLevelId);
const enemyConfigs = CsvMgr.Enemy_csv;
// 处理超出最大等级的关卡(动态生成配置)
if (currentLevelId > lastLevelId) {
const levelOffset = currentLevelId - lastLevelId;
this.headIndex = (levelOffset - 1) % levelKeys.length + 1;
this.config = levelConfigs[levelKeys[this.headIndex - 1]];
// 动态生成Boss配置(基于模板和等级偏移)
const templateBoss = enemyConfigs[this.config.boss];
const templateMonster = enemyConfigs[this.config.monster];
const lastLevelBoss = enemyConfigs[levelConfigs[lastLevelId].boss];
const lastLevelMonster = enemyConfigs[levelConfigs[lastLevelId].monster];
const passedTimes = LocalDataMgr.Pass.passed_times;
const hpmul = Global.CsvMgr.cnf_discretization_csv[8].num1;
const hppasstime = Math.min(Global.CsvMgr.cnf_discretization_csv[8].num2, passedTimes);
const coinmul = Global.CsvMgr.cnf_discretization_csv[9].num1;
const coinpasstime = Math.min(Global.CsvMgr.cnf_discretization_csv[9].num2, passedTimes);
this.bossConfig = {
id: templateBoss.id,
name: templateBoss.name,
sp: templateBoss.sp,
scale: templateBoss.scale,
headicon: templateBoss.headicon,
identity: templateBoss.identity,
boss: templateBoss.boss,
duration: templateBoss.duration,
hp: Math.floor(Number(templateBoss.hp) * (hppasstime * hpmul + 1)),
bounty: Math.floor(Number(templateBoss.bounty) * (coinpasstime * coinmul + 1)),
reward: templateBoss.reward,
defense_1: templateBoss.defense_1,
defense_2: templateBoss.defense_2,
defense_3: templateBoss.defense_3,
desc: templateBoss.desc,
story: templateBoss.story,
percent: templateBoss.percent
};
this.monsterConfig = {
id: templateMonster.id,
name: templateMonster.name,
sp: templateMonster.sp,
scale: templateMonster.scale,
headicon: templateMonster.headicon,
identity: templateMonster.identity,
boss: templateMonster.boss,
duration: templateMonster.duration,
hp: Math.floor(Number(templateMonster.hp) * (hppasstime * hpmul + 1)),
bounty: Math.floor(Number(templateMonster.bounty) * (coinpasstime * coinmul + 1)),
reward: templateMonster.reward,
defense_1: templateMonster.defense_1,
defense_2: templateMonster.defense_2,
defense_3: templateMonster.defense_3,
desc: templateMonster.desc,
story: templateMonster.story,
percent: templateMonster.percent
};
} else {
// 使用预设的关卡配置
this.config = levelConfigs[currentLevelId.toString()];
this.headIndex = this.config.index;
this.bossConfig = enemyConfigs[this.config.boss];
this.monsterConfig = enemyConfigs[this.config.monster];
}
this.index = currentLevelId - firstLevelId;
}
/**
* 重置关卡状态(创建新的敌人实例)
*/
reset(): void {
if(this.monster){
this.monster.initInfo(this.monsterConfig, null, true);
}else{
this.monster = new EnemyData(`${this.headIndex}-1`, this.monsterConfig, true);
}
if(this.boss){
this.boss.initInfo(this.bossConfig, null);
}else{
this.boss = new EnemyData(`${this.headIndex}-2`, this.bossConfig);
}
this.resetEXP();
}
/**
* 重置关卡经验值(考虑灵魂加成)
*/
resetEXP(): void {
const soulBonus = 1 + 0.01 * LocalDataMgr.Treasure.getProp2(TREASURE_TYPE.SOUL);
this.exp = Math.floor(this.headIndex * SOUL_PARAMS.PER_EXP * soulBonus);
}
// Getter 和 Setter 属性
/**
* 获取关卡ID
*/
get id(): number {
return this.archive.id;
}
/**
* 设置关卡ID(会自动刷新配置)
*/
set id(value: number) {
this.archive.id = value;
this.archive.enter_time = Date.now();
this.archive.ad_cnt = 0;
LocalDataMgr.Game.Save();
this.refreshConfig();
}
/**
* 获取关卡是否已通过
*/
get passed(): boolean {
return this.archive.passed;
}
/**
* 设置关卡通过状态
*/
set passed(value: boolean) {
this.archive.passed = value;
LocalDataMgr.Pass.passed_times += value ? 1 : 0;
LocalDataMgr.Game.Save();
}
/**
* 获取任务计数
*/
get task_count(): number {
return this.archive.task_count;
}
/**
* 设置任务计数
*/
set task_count(value: number) {
this.archive.task_count = value;
LocalDataMgr.Game.Save();
}
/**
* 获取本关卡的持续时间
*/
get duration(): number {
return Date.now() - this.archive.enter_time;
}
get ad_cnt(): number {
return this.archive.ad_cnt;
}
set ad_cnt(value: number) {
this.archive.ad_cnt = value;
LocalDataMgr.Game.Save();
}
/**
* 获取当前目标(怪物或Boss)
*/
get target(): EnemyData {
return this.monster.fighting ? this.monster : this.boss;
}
/**
* 获取任务金币奖励
*/
get task_money(): number {
return Number(this.monster.config.bounty) * (BOUNTY_PARAMS.TARGET + this.id - 1);
}
/**
* 检查Boss是否正在战斗
*/
get isBossFighting(): boolean {
return this.boss?.fighting || false;
}
/**
* 检查怪物是否正在战斗
*/
get isMonsterFighting(): boolean {
return this.monster?.fighting || false;
}
/**
* 获取关卡显示名称
*/
get displayName(): string {
return this.config?.name || `关卡 ${this.id}`;
}
/**
* 获取关卡显示名称
*/
get displayDesc(): string {
return this.config?.desc || `关卡 ${this.id} 暂无描述信息`;
}
get displayLevelBg():string{
return this.config?.img||"level_bg";
}
/**
* 获取推荐战斗力
*/
get recommendedFighting(): number {
const baseFighting = Number(this.monsterConfig?.hp || 100);
return Math.floor(baseFighting * (1 + this.index * 0.1));
}
/**
* 检查关卡是否可以挑战(已通过或前一关已通过)
*/
get canChallenge(): boolean {
if (this.index === 0) return true; // 第一关总是可挑战
const previousLevelId = (Number(this.id) - 1).toString();
const levelConfigs = CsvMgr.Level_csv;
const previousLevel = levelConfigs[previousLevelId];
return !previousLevel || this.passed || previousLevel.passed;
}
}