import { BUILDING_TYPE, EGongFaType, NEED_TYPE, GameTotalType, TASK_TYPE, PropType } from "../const/GameEnum"; import { ITaskArchive } from "../const/GameInterface"; import { MAINPAGE_UNLOCK_PARAMS } from "../const/GGameData"; import { EUIForms } from "../const/UIFormCnf"; import { EGlobalEvent } from "../MesEvent/EGlobalEvent"; import MesMgr from "../MesEvent/MesMgr"; import { ITask } from "../Mgr_CSV/CsvEnum"; import CsvMgr from "../Mgr_CSV/CsvMgr"; import { GEData } from "../Mgr_Ge/GeDifine"; import { TDAnalyticsMgr } from "../Mgr_Ge/TDAnalyticsMgr"; import { GuideConfigType } from "../Mgr_Guide/GuideConfig"; import GuideDataMgr from "../Mgr_Guide/GuideDataMgr"; import { HomeUIRedEnum, MainRedEnum } from "../Mgr_RedPoint/RedEnumType"; import { RedNotice } from "../Mgr_RedPoint/RedNotice"; import UIMgr from "../Mgr_UI/UIMgr"; import { BagDataProxy } from "./DataTypeProxy/BagDataProxy"; import { BuildsDataProxy } from "./DataTypeProxy/BuildsDataProxy"; import { ShopDataProxy } from "./DataTypeProxy/ShopDataProxy"; import { TaskDataProxy } from "./DataTypeProxy/TaskDataProxy"; import { TokenDataProxy } from "./DataTypeProxy/TokenDataProxy"; import LocalStorage from "./LocalStorage"; import RoleDataMgr from "./RoleDataMgr"; import SceneDataMgr from "./SceneDataMgr"; export default class TaskArchivePoxy{ private archive: ITaskArchive; private _config: ITask = null; public completeDirty: boolean = true; constructor(archive: ITaskArchive) { this.archive = archive; this.refreshConfig(); } /** * 刷新任务配置 */ refreshConfig(): void { if (this.archive.id) { this._config = CsvMgr.tasks_csv[this.archive.id]; } else { this.generateDefaultConfig(); } } /** * 生成默认任务配置(当任务ID不存在时) */ private generateDefaultConfig(): void { const levelKeys = Object.keys(CsvMgr.Level_csv); const taskIndex = this.archive.index % 100000; const levelIndex = (taskIndex - 1) % levelKeys.length; const targetLevel = CsvMgr.Level_csv[levelKeys[levelIndex]]; const bossConfig = CsvMgr.Enemy_csv[targetLevel.boss]; this._config = { id: this.archive.index, name: "", quality: 5, condition: TASK_TYPE.XIAOGUAI, conditionId: taskIndex, conditionValue: 1, conditionDesc: `击败${bossConfig.name}`, rewardType: GameTotalType.TOKEN, rewardId: 1, rewardValue: 1, desc: "测试" }; } /** * 增加任务进度 * @param increment 进度增量 */ addProgress(increment: number): void { if (this.progress < this.config.conditionValue) { this.archive.progress += increment; this.completeDirty = true; TaskDataProxy.Ins.Save(); } } /** * 重置任务进度 */ resetProgress(): void { this.archive.progress = 0; this.archive.completed = false; this.archive.getreward = false; this.completeDirty = true; // TaskDataProxy.Ins.Save(); } // 任务完成后的领奖 public getReward(): boolean { if(this.complete && !this.archive.getreward){ this.archive.getreward = true; // 处理不同类型的任务奖励 switch (this.config.rewardType) { case GameTotalType.ITEM: // 物品奖励 BagDataProxy.Ins.addItem(this.config.rewardId, this.config.rewardValue); break; case GameTotalType.BUILD: // 建筑类奖励(投资,商店升级等) BuildsDataProxy.Ins.addBuilding(this.config.rewardId); break; case GameTotalType.TOKEN: // 获得银两或玄武符 TokenDataProxy.Ins.addToken(this.config.rewardId, this.config.rewardValue) break; case GameTotalType.UNLOCK: // 解锁类奖励(投资、商店等) ShopDataProxy.Ins.unlockShop(); break; } this.nextTask(); return this.checkMainPageUnlock(); } return false; } // 是否有可解锁的主功能 checkMainPageUnlock(): boolean{ for (let i = 0; i < MAINPAGE_UNLOCK_PARAMS.length; i++) { const unlockParam = MAINPAGE_UNLOCK_PARAMS[i]; if (unlockParam.taskid === Number(this.id)) { if(unlockParam.unlockpage){ UIMgr.Ins.ShowUI(EUIForms.UnlockUI, { param: unlockParam }); }else if(unlockParam.guideid){ GuideDataMgr.ins.setExecuteGuide(unlockParam.guideid); } return true; } } return false; } nextTask(): void { const curid = Number(this.archive.id) + 1; if(CsvMgr.tasks_csv[curid]){ this.resetProgress(); ++this.archive.index; this.id = "" + curid; }else{ TaskDataProxy.Ins.compoleteAllTask(); // 仅通关任务执行的特殊逻辑 } MesMgr.event(EGlobalEvent.REFRESH_TASK); MesMgr.event(EGlobalEvent.FINISH_TASK); RedNotice.emit(EGlobalEvent.E_RED_UPDATE,[MainRedEnum.游历, HomeUIRedEnum.任务完成]); TDAnalyticsMgr.ins.TrySendtrack(GEData.GEeventName.Main_quest,{details: curid - 1}); LocalStorage.CheckSaveServerData(); } /** * 获取当前任务进度(根据任务类型动态计算) */ get progress(): number { if (!this.config) return 0; switch (this.config.condition) { case TASK_TYPE.XIAOGUAI: return this.calculateXiaoguaiProgress(); case TASK_TYPE.BOSS: return this.calculateBossProgress(); case TASK_TYPE.UPGRADE_WUGONG: return RoleDataMgr.Ins.getWuGongLevel(this.config.conditionId); case TASK_TYPE.UPGRADE_BUILDING: return this.calculateBuildingProgress(); case TASK_TYPE.ATTAINMENT: return this.calculateAttainmentProgress(); case TASK_TYPE.EQUIP: return this.calculateEquipProgress(); case TASK_TYPE.ADD_WUGONG: return RoleDataMgr.Ins.getWuGongLevel(this.config.conditionId) ? 1 : 0; default: return this.archive.progress; } } /** * 设置任务进度 */ set progress(value: number) { this.archive.progress = value; this.completeDirty = true; TaskDataProxy.Ins.Save(); } /** * 计算小怪任务进度 */ private calculateXiaoguaiProgress(): number { const conditionLevel = Number(this.config!.conditionId); const currentLevel = SceneDataMgr.Ins.level.id; if (currentLevel > conditionLevel || SceneDataMgr.Ins.level.passed) { return this.config!.conditionValue; } if (currentLevel < conditionLevel) { return 0; } return this.archive.progress; } /** * 计算Boss任务进度 */ private calculateBossProgress(): number { const conditionLevel = Number(this.config!.conditionId); const currentLevel = SceneDataMgr.Ins.level.id; if (currentLevel > conditionLevel || SceneDataMgr.Ins.level.passed) { return this.config!.conditionValue; } return this.archive.progress; } /** * 计算建筑升级进度 */ private calculateBuildingProgress(): number { const buildingType = Number(this.config!.conditionId); switch (buildingType) { case BUILDING_TYPE.SHOP: return ShopDataProxy.Ins.data.level; case BUILDING_TYPE.BAG: return BagDataProxy.Ins.data.level;//gameModel.bag.level; case BUILDING_TYPE.TEAHOUSE: case BUILDING_TYPE.TAVERN: case BUILDING_TYPE.BANK: const building = BuildsDataProxy.Ins.buildings[buildingType]; return (building && building.running) ? building.level : 0; default: return 0; } } /** * 计算武学造诣进度 */ private calculateAttainmentProgress(): number { const wugongMapping: { [key: string]: EGongFaType } = { [NEED_TYPE.QUANFA]: EGongFaType.剑法, [NEED_TYPE.JIANFA]: EGongFaType.刀法, [NEED_TYPE.DAOFA]: EGongFaType.枪法, [NEED_TYPE.SHENSHOU]: EGongFaType.轻功, [NEED_TYPE.GONGFA]: EGongFaType.内功 }; const wugongType = wugongMapping[this.config!.conditionId]; return wugongType ? RoleDataMgr.Ins.attainments[wugongType] : 0; } /** * 计算装备任务进度 */ private calculateEquipProgress(): number { const role = RoleDataMgr.Ins; const targetEquipId = this.config!.conditionId; if ((role.weapon && role.weapon.id === targetEquipId) || (role.armor && role.armor.id === targetEquipId)) { return 1; } return 0; } // Getter 和 Setter 属性 /** * 获取任务ID */ get id(): string { return this.archive.id; } /** * 设置任务ID */ set id(value: string) { this.archive.id = value; this.completeDirty = true; TaskDataProxy.Ins.Save(); if (value) { this._config = CsvMgr.tasks_csv[value]; } } /** * 获取任务索引 */ get index(): number { return this.archive.index; } /** * 设置任务索引 */ set index(value: number) { this.archive.index = value; TaskDataProxy.Ins.Save(); this.refreshConfig(); } /** * 获取任务配置 */ get config(): ITask { if (!this._config) { this.refreshConfig(); } return this._config!; } /** * 检查任务是否完成 */ get complete(): boolean { return this.progress >= this.config.conditionValue; } /** * 获取任务完成百分比 */ get completionPercent(): number { if (this.config.conditionValue === 0) return 0; return Math.min(100, Math.floor((this.progress / this.config.conditionValue) * 100)); } /** * 获取任务显示名称 */ get displayName(): string { return this.config.name || `任务 ${this.id}`; } /** * 获取任务条件描述 */ get conditionDescription(): string { return this.config.conditionDesc; } /** * 获取奖励描述 */ get rewardDescription(): string { return `奖励: ${this.config.rewardValue} ${this.config.desc}`; } /** * 序列化任务数据(用于存档) */ serialize(): ITaskArchive { return { id: this.archive.id, index: this.archive.index, progress: this.archive.progress, completed: this.complete, getreward: this.archive.getreward, }; } /** * 克隆任务数据 */ clone(): TaskArchivePoxy { return new TaskArchivePoxy(this.serialize()); } }