// // JiangHuController.js - 转换后的 Cocos Creator JavaScript 版本 // import { cclegacy, _decorator } from 'cc'; // import { Command } from './Decorator'; // import { Types } from './Types'; // import { ViewAction } from './ViewAction'; // import { JiangHuModel } from './JiangHuModel'; // import { IController } from './IController'; // import { AudioNames } from './AudioNames'; // import { GameState, AssetType, CurrencyType } from './GameDefine'; // import { ResourcesService } from './ResourcesService'; // import { MathUtil } from './MathUtil'; // import { ToastManager, TOAST_STYLE } from './ToastManager'; // const { ccclass, property } = _decorator; // // 定义枚举类型 // export const WUGONG_TYPE = { // QUAN: 1, // JIAN: 2, // DAO: 3, // QING: 4, // NEI: 5 // }; // export const ITEM_CATALOG = { // ALL: 0, // EQUIP: 2, // PAPER: 3, // SPECIAL: 5, // MATERIAL: 6, // FOOD: 8 // }; // export const ITEM_TYPE = { // NONE: 0, // WUGONG: 1, // WUGONG_PAGE: 3, // GLOVE: 21, // SWORD: 22, // KNIFE: 23, // ARMOR: 26, // PAINTING_PAGE: 32, // TOOL: 51, // TALISMAN: 52, // CLOTH: 61, // WENJV: 62, // CHAJV: 63, // JIAJV: 64, // JIUJV: 65, // PAINTING: 71, // FOOD: 81, // JIU: 82, // DRUG: 83, // CARD: 85, // EXP: 86 // }; // export const NEED_TYPE = { // NONE: 0, // WUXUE: 1, // CRAFT: 11, // QUANFA: 21, // JIANFA: 22, // DAOFA: 23, // SHENSHOU: 32, // GONGFA: 33 // }; // export const TRIGGER_TYPE = { // MANUALLY: 0, // AUTO: 1 // }; // export const REWARD_TYPE = { // ITEM: 1, // UNLOCK: 3, // COIN: 5, // TOKEN: 6 // }; // export const BUILDING_TYPE = { // TEAHOUSE: 1, // TAVERN: 2, // BANK: 3, // SHOP: 6, // BAG: 7 // }; // export const TASK_TYPE = { // NONE: 0, // BOSS: 1, // UPGRADE_WUGONG: 2, // UPGRADE_BUILDING: 3, // ATTAINMENT: 4, // XIAOGUAI: 5, // EQUIP: 6, // ADD_WUGONG: 7 // }; // export const MOUDLE_TYPE = { // WUGONG: 0, // INVEST: 1, // FIGHT: 2, // SHOP: 3, // BAG: 4 // }; // export const TREASURE_TYPE = { // CAPACITY: 1, // CRAFT: 2, // LUCKY: 3, // SPEED: 4, // VIP: 5, // MATERIAL: 6, // CRIT: 7, // SOUL: 8, // INVEST: 9, // OFFLINE: 10, // SHOP: 11 // }; // export const QUALITY = { // NONE: 0, // GRAY: 1, // GREEN: 2, // BLUE: 3, // PURPLE: 4, // ORANGE: 5 // }; // export const WUGONG_NAME = { // [WUGONG_TYPE.QUAN]: "拳法", // [WUGONG_TYPE.JIAN]: "剑法", // [WUGONG_TYPE.DAO]: "刀法", // [WUGONG_TYPE.QING]: "轻功", // [WUGONG_TYPE.NEI]: "内功" // }; // // 定义配置参数 // export const ROLE_PARAMS = { // STAGE_CHECK_INTERVAL: 50, // STAGE_UPGRADE_WEIGHT: 5, // STAGE_TOTAL_WEIGHT: (level) => 100 + level * level // }; // export const BOUNTY_PARAMS = { // LEVEL_START: 1, // TARGET: 20 // }; // export const BAG_PARAMS = { // CAPACITY: 20, // CAPACITY_ADD: 3, // MAX_LEVEL: 16, // MATERIAL_BASE: 4001, // MATERIAL_SENIOR: 4003, // ICON: (item) => { // return ResourcesService.checkAsset({ // name: item.name, // type: AssetType.SPRITE // }) ? item.name : item.typeName === "秘籍" ? // `i${item.typeName}${WUGONG_TYPE[Number(item.id[1])]}` : // `i${item.typeName}`; // } // }; // export const SOUL_PARAMS = { // PER_EXP: 50, // UNLOCK_LEVEL: 3, // CRIT_SPEED: 10.8, // CRIT_DURATION: 60, // SPEED: 3.8, // SPEED_ADD: 0.7, // MAX_LEVEL: 10, // MAX_SPEED: 10.8 // }; // export const QUALITY_COLORS = [ // "#000000", "#000000", "#005910", "#0E4287", "#92039A", "#C44C01" // ]; // export const NEED_TYPE_PARAMS = { // WUXUE: { // tag: "基础武学", // check: (value) => app.service.game.model.role.wuxue >= value // }, // CRAFT: { // tag: "铁匠技能", // check: (value) => app.service.game.model.bag.craft >= value // }, // QUANFA: { // tag: "拳法造诣", // check: (value) => app.service.game.model.role.attainments[WUGONG_TYPE.QUAN] >= value // }, // JIANFA: { // tag: "剑法造诣", // check: (value) => app.service.game.model.role.attainments[WUGONG_TYPE.JIAN] >= value // }, // DAOFA: { // tag: "刀法造诣", // check: (value) => app.service.game.model.role.attainments[WUGONG_TYPE.DAO] >= value // }, // SHENSHOU: { // tag: "身手", // check: (value) => app.service.game.model.role.attainments[WUGONG_TYPE.QING] >= value // }, // GONGFA: { // tag: "功法", // check: (value) => app.service.game.model.role.attainments[WUGONG_TYPE.NEI] >= value // } // }; // export const SHOP_PARAMS = { // DEFAULT_TIMES: 5, // TOP_LIMIT: 10, // RECOVERY_CD: 20, // VIDEO_TIMES: 20, // REFRESH_GOODS: 5, // LOCK_LIMIT: 4, // MAX_LEVEL: 25, // MAX_TIMES: 200, // VIP_SHOW: 8, // VIP_UNLOCK: 11, // VIP_MAX: 10, // VIP_TIMES: 3 // }; // export const MOUDLE_UNLOCK = { // WUGONG: 1, // BAG: 2, // SHOP: 5, // INVEST: 12 // }; // export const INVEST_PARAMS = { // [BUILDING_TYPE.TEAHOUSE]: { // cost: 5000, // name: "茶馆", // quality: 2, // interval: 1, // MATERIAL_BASE: 4111, // MATERIAL_SENIOR: 4113 // }, // [BUILDING_TYPE.TAVERN]: { // cost: 10000, // name: "酒楼", // quality: 3, // interval: 1, // MATERIAL_BASE: 4111, // MATERIAL_SENIOR: 4123 // }, // [BUILDING_TYPE.BANK]: { // cost: 15000, // name: "钱庄", // quality: 4, // interval: 1, // MATERIAL_BASE: 4111, // MATERIAL_SENIOR: 4133 // } // }; // export const OFFLINE_PARAMS = { // MAX_TIME: 7200, // REWARD_TIME: 1200, // MAX_REFRESH_TIMES: 40, // REWARD_SCALE: 0.3 // }; // export const REDEEM_CODES = { // xinshoulibao888: { // code: "xinshoulibao888", // reward: 200000 // } // }; // // 主控制器类 // @ccclass("JiangHuController") // export class JiangHuController extends IController { // constructor(...args) { // super(...args); // this.model = null; // this.autoCD = 0; // this.timeStart = 0; // } // /** // * 控制器注册初始化 // */ // onRegister() { // this.model = app.model.get(JiangHuModel); // } // /** // * 游戏开始 // */ // start() { // this.model.state = GameState.Playing; // this.resetAutoCD(); // this.schedule(this.updateOnce, 1); // // 初始化商店解锁状态 // if (!this.model.shop.unlock) { // this.model.shop.unlock = true; // } // this.onLevelStart(); // } // /** // * 关卡开始 // */ // onLevelStart() { // this.timeStart = app.service.time.seconds; // app.service.server.reqRecords(-1, app.service.game.runningLevel.index, 0, 0, false); // } // /** // * 关卡成功 // */ // onLevelSuccess() { // app.service.server.reqRecords(-1, app.service.game.runningLevel.index, 2, // app.service.time.seconds - this.timeStart, false); // } // /** // * 关卡失败 // */ // onLevelFail() { // app.service.server.reqRecords(-1, app.service.game.runningLevel.index, 1, // app.service.time.seconds - this.timeStart, false); // } // /** // * 单次更新(用于暴击检查) // */ // updateOnce() { // if (this.model.state === GameState.Playing && this.model.soul.crit) { // this.model.soul.checkCrit(); // } // } // /** // * 每帧更新 // * @param {number} deltaTime - 时间增量 // */ // update(deltaTime) { // if (this.model.state !== GameState.Playing) return; // // 自动攻击冷却 // if (this.autoCD > 0) { // this.autoCD -= deltaTime; // if (this.autoCD <= 0) { // const remainingTime = this.autoCD; // this.autoCD += this.model.soul.attackInterval; // if (this.autoCD <= 0) { // this.autoCD = this.model.soul.attackInterval; // } // this.onAttackOnce(TRIGGER_TYPE.AUTO, remainingTime); // } // } // // Boss战斗冷却 // if (this.model.bossCD > 0) { // this.model.bossCD -= deltaTime; // if (this.model.bossCD <= 0) { // this.model.bossCD = 0; // this.fightBossFail(); // } // } // // 商店冷却 // if (this.model.shop.cd > 0) { // this.model.shop.cd -= deltaTime; // if (this.model.shop.cd <= 0) { // this.model.shop.times++; // } // } // // 投资建筑收益计算 // const buildings = this.model.invest.buildings; // for (const buildingId in buildings) { // const building = buildings[buildingId]; // if (building.cd > 0) { // building.cd -= deltaTime; // if (building.cd <= 0) { // building.earnOnce(); // app.view.doAction(ViewAction.EARN_ONCE, building); // } // } // } // } // /** // * 重置自动攻击冷却 // */ // resetAutoCD() { // if (this.model.soul.unlock) { // this.autoCD = this.model.soul.attackInterval; // } // } // /** // * Boss战斗失败处理 // */ // fightBossFail() { // this.autoCD = 0; // this.model.bossCD = 0; // app.view.doAction(ViewAction.BOSS_FAIL); // this.onLevelFail(); // } // /** // * 游戏暂停 // */ // onGamePause() { // this.model.state = GameState.Pausing; // } // /** // * 游戏恢复 // */ // onGameResume() { // this.model.state = GameState.Playing; // } // /** // * 执行一次攻击 // * @param {number} triggerType - 触发类型 // * @param {number} remainingTime - 剩余时间 // */ // onAttackOnce(triggerType, remainingTime = 0) { // // 手动攻击时重置自动攻击冷却 // if (this.model.soul.unlock && triggerType === TRIGGER_TYPE.MANUALLY) { // this.autoCD = 1.5; // } // const currentTime = performance.now() / 1000 + remainingTime; // const lastAttackTime = this.model.lastAttack; // // 攻击频率限制检查 // if (currentTime - lastAttackTime < 1 / SOUL_PARAMS.MAX_SPEED) { // if (this.model.soul.unlock && triggerType === TRIGGER_TYPE.AUTO) { // this.autoCD = 1 / SOUL_PARAMS.MAX_SPEED - (currentTime - lastAttackTime); // } // return; // } // const level = this.level; // // 记录攻击时间 // this.model.lastAttack = currentTime; // // 维护攻击记录队列 // if (lastAttackTime) { // if (this.model.attackRecords.length >= 20) { // this.model.attackRecords.shift(); // } // const attackInterval = triggerType === TRIGGER_TYPE.AUTO ? // this.model.soul.attackInterval : // Math.max(1 / SOUL_PARAMS.MAX_SPEED, Math.min(0.3, currentTime - lastAttackTime)); // this.model.attackRecords.push(attackInterval); // // 计算实时攻击速度 // let totalInterval = 0; // for (const interval of this.model.attackRecords) { // totalInterval += interval; // } // this.model.realSpeed = this.model.attackRecords.length / totalInterval; // app.view.doAction(ViewAction.REFRESH_SPEED); // } // // 增加攻击次数 // this.model.role.addAttackTimes(); // const target = level.target; // let damage = this.model.role.fighting; // // 自动攻击加成 // if (triggerType === TRIGGER_TYPE.AUTO) { // const soulBonus = this.model.cabinet.getProp1(TREASURE_TYPE.SOUL); // damage += Math.floor(damage * soulBonus * 0.01); // } // let finalDamage = damage; // // Boss防御减免 // if (target.config.boss) { // const defenseType = `defense_${this.model.role.attack_type}`; // const defenseReduction = 1 - 0.01 * target.config[defenseType]; // finalDamage *= defenseReduction; // } // // 暴击判断 // const isCritical = this.model.role.isCrit; // if (isCritical) { // finalDamage *= 2; // } // // 测试模式伤害设置 // if (app.service.game.testFighting) { // finalDamage = target.hp; // } // // 应用伤害 // target.hp = Math.max(0, target.hp - finalDamage); // app.view.doAction(ViewAction.ATTACK_ONCE, triggerType, finalDamage, isCritical); // // 目标死亡处理 // if (target.hp <= 0) { // const taskConfig = this.model.task.config; // if (target.config.boss) { // this._handleBossDefeat(level, taskConfig); // } else { // this._handleNormalEnemyDefeat(currentTime, level, taskConfig); // } // } // } // /** // * 处理Boss击败 // * @private // */ // _handleBossDefeat(level, taskConfig) { // // 奖励发放 // app.service.item.addCurrency(CurrencyType.Coin, level.target.config.bounty, false, false); // const levelKeys = Object.keys(app.service.config.data.level); // const currentIndex = level.index; // this.onLevelSuccess(); // let newIndex = currentIndex; // if (currentIndex < levelKeys.length - 1) { // // 进入下一关 // newIndex++; // level.task_count = 0; // level.id = levelKeys[newIndex]; // app.service.game.runningLevel.id = Number(level.id); // app.service.game.runningLevel.index = levelKeys.indexOf(level.id); // } else { // // 生成新关卡 // newIndex++; // level.task_count = 0; // const newId = Number(level.id) + 1; // level.id = newId.toString(); // app.service.game.runningLevel.id = newId; // app.service.game.runningLevel.index = levelKeys.length + newId - Number(levelKeys[levelKeys.length - 1]) - 1; // } // // 灵魂解锁检查 // if (!this.model.soul.unlock && newIndex + 1 === SOUL_PARAMS.UNLOCK_LEVEL) { // this.onUnlockSoul(); // } // this.autoCD = 0; // this.model.bossCD = 0; // // 灵魂经验奖励 // const expBonus = 1 + 0.01 * this.model.cabinet.getProp2(TREASURE_TYPE.SOUL); // this.model.soul.exp += Math.floor(level.exp * expBonus); // app.view.doAction(ViewAction.BOSS_SUCCESS, newIndex, level.config, level.target); // app.service.game.onPassLevel(); // // 任务进度更新 // if (taskConfig && (taskConfig.condition === TASK_TYPE.BOSS || taskConfig.condition === TASK_TYPE.XIAOGUAI)) { // this.refreshTaskProgress(); // } // app.service.archive.checkRemote(); // } // /** // * 处理普通敌人击败 // * @private // */ // _handleNormalEnemyDefeat(currentTime, level, taskConfig) { // app.service.item.addCurrency(CurrencyType.Coin, level.target.config.bounty, false); // // 自动攻击冷却调整 // if (this.model.soul.unlock) { // this.autoCD += 0.2; // this.model.lastAttack = currentTime + 0.2; // } // level.target.reset(); // level.task_count++; // // 任务完成奖励 // if (level.task_count >= BOUNTY_PARAMS.TARGET) { // level.task_count = 0; // app.service.item.addCurrency(CurrencyType.Coin, level.task_money, false); // } // app.view.doAction(ViewAction.REFRESH_XIAOGUAI); // // 小怪任务进度更新 // if (taskConfig && taskConfig.condition === TASK_TYPE.XIAOGUAI) { // this.refreshTaskProgress(1); // } // } // /** // * 攻击Boss // */ // onAttackBoss() { // const level = this.model.level; // level.monster.fighting = false; // level.boss.fighting = true; // level.boss.reset(); // this.model.bossCD = level.boss.config.duration; // this.resetAutoCD(); // app.view.doAction(ViewAction.REFRESH_FIGHT); // } // /** // * 战斗撤退 // */ // onFightRetreat() { // const level = this.model.level; // level.monster.fighting = true; // level.boss.fighting = false; // this.model.bossCD = 0; // this.resetAutoCD(); // this.onGameResume(); // app.view.doAction(ViewAction.REFRESH_FIGHT); // this.onLevelStart(); // } // /** // * 战斗总结完成 // */ // onSummaryComplete(resetLevel = false) { // const level = this.model.level; // if (resetLevel) { // level.reset(); // } // level.monster.fighting = true; // level.boss.fighting = false; // this.resetAutoCD(); // app.view.doAction(ViewAction.REFRESH_FIGHT); // this.onLevelStart(); // } // /** // * 解锁灵魂系统 // */ // onUnlockSoul() { // this.model.soul.unlock = true; // this.resetAutoCD(); // app.view.doAction(ViewAction.UNLOCK_SOUL); // } // /** // * 灵魂暴击 // */ // onSoulCrit() { // this.model.soul.setCrit(); // } // /** // * 刷新任务进度 // */ // refreshTaskProgress(increment = 0) { // if (increment) { // this.model.task.addProgress(increment); // } // app.view.doAction(ViewAction.REFRESH_TASK); // if (this.model.task.completeDirty && this.model.task.complete) { // this.model.task.completeDirty = false; // app.manager.toast.pop(TOAST_STYLE.TASK, "任务已完成,可领取奖励"); // } // } // } // export default JiangHuController;