import Main from "../Main"; import AdM from "../manager/AdM"; import GameM from "../manager/GameM"; import HttpM from "../manager/HttpM"; import UiM from "../manager/UiM"; import { PlayerPrefs } from "../tools/MyExtends"; import EffectNode from "../ui/EffectNode"; import UIMng, { PanelType } from "../uiFrames/UIMng"; import LogUtil from "../utils/LogUtil"; import Random from "../utils/Random"; import { HTTP_TYPE } from "./CommonData"; import { MateData } from "./MateData"; export class FightData { //战斗模块数据管理类 private static _ins: FightData = null; public static get Ins(): FightData { if (this._ins == null) { this._ins = new FightData(); } return this._ins; } /**触发已解锁武将战斗 武将的最低等级*/ triggerFightRoleMinLv: number = 7; fightTriggerTimes: number = 3; curFightTime: number = 0; isTriggerFight: boolean = false; /**破绽点击次数*/ flawTimes: number = 3; /**破绽生命时长*/ flawDuration: number = 3; /**破绽触发概率*/ flawRate: number = 10; /**破绽同时存在的数量*/ flawNum: number = 1; /**破绽当前存在的数量*/ flawCurNum: number = 0; /**今日剩余奖励次数 战斗2*/ rewardTimes: number = 0; //存到服务器 /**第一次合成需要战斗的武将 武将id 存到服务器*/ composeFightRoles: any[] = []; /* [ {code: "5", battleStatus: 0, battleResult: 0}, {code: "6", battleStatus: 0, battleResult: 0} ] */ /**需要战斗的武将的星级 存到服务器*/ fightRolesStars: number[] = []; /**触发2 战斗触发概率*/ triggerFightRates: number[] = [10, 20, 30, 40, 40]; fightWordsCfg: any = null; private isInit: boolean = false; constructor() { this.composeFightRoles = PlayerPrefs.GetObject("fightRoles", []); //this.triggerFightRoleMinLv=GameM.commonData.fightCfg.unlock_lv; console.log("ComposeFightRoles:", this.composeFightRoles); } //战斗模块 战斗触发机制 //1 首次合成的怪物 且该怪物配置的是 需要战斗的 //2 非首次合成的怪物 合成的怪物等级 往下5级内怪物 概率触发与该怪物战斗 //战斗 有奖励: /* 1星宝箱 2件物品 少量天赋点 2星宝箱 3件物品 中量天赋点 3星宝箱 4件物品 大量天赋点 */ Init() { //服务器获取数据 this.isInit = true; } /**是否触发第一次合成战斗 */ CheckComposeFight() { //三国战戟 战斗弃用 return; let maxLv = GameM.commonData.maxCarLevel; if (GameM.commonData.fightRoleServerCfg[maxLv.toString()].is_fight == 1) { //this.EnterFight(); //console.log("--->FightCfg:",GameM.commonData.fightRoleServerCfg); //console.log("--->FightCfg lv:",GameM.commonData.fightRoleServerCfg[maxLv.toString()]); let cfg = GameM.commonData.fightRoleCfg[maxLv.toString()]; this.flawTimes = cfg.flawclicktimes; this.flawDuration = cfg.flawduration; this.flawRate = cfg.flawrate; this.flawNum = cfg.flawnum; let serCfg = GameM.commonData.fightRoleServerCfg[maxLv.toString()]; let fightrole = new FightRole(); fightrole.arrayIndex = -1; fightrole.blood = serCfg.bloods; fightrole.buffId = 1; //无效 在战斗时生效 fightrole.fightTime = serCfg.times; fightrole.fightType = 1; fightrole.lv = maxLv; fightrole.name = serCfg.name; fightrole.star = 1; //弃用 fightrole.rewardId = 1//弃用; console.log("Trigger Fight 1"); UIMng.Ins.AsyncGetPanel(PanelType.FightRoleBPanel, (panel) => { panel.OnEnter(fightrole); }); //UIMng.Ins.GetPanel(PanelType.FightRoleBPanel).OnEnter(fightrole); } } /** * 检查是否概率触发已解锁武将的战斗 */ CheckTriggerFight(rolelv: number) { //弃用 奇遇 老武将战斗功能取消 return; if (this.isTriggerFight) { this.curFightTime++; if (this.curFightTime <= this.fightTriggerTimes) return; this.curFightTime = 0; this.isTriggerFight = false; } let deltaNum = GameM.commonData.maxCarLevel - rolelv; //this.triggerFightRoleMinLv = 7; //TEST //console.log("----Max: " + GameM.commonData.maxCarLevel + " Min: " + this.triggerFightRoleMinLv + " delta: " + deltaNum); if (GameM.commonData.maxCarLevel >= this.triggerFightRoleMinLv && deltaNum >= 0 && deltaNum <= 4) { //let fightCfg = GameM.commonData.fightCfg; let cfg = GameM.commonData.fightRoleCfg[rolelv.toString()]; //战斗触发触发概率 fightRoleCfg---id---fight_rate let rate = Random.Range(0, 100); //console.log("--->rate: " + rate + " targetRate:" + this.triggerFightRates[deltaNum]); LogUtil.logV("-->Tri Rate:", rate) LogUtil.logV("-->Tri Rate2:", this.triggerFightRates[deltaNum]) //console.log("----->Trigger Rate:" + rate + " T:" + this.triggerFightRates[deltaNum]); if (rate < this.triggerFightRates[deltaNum]) { this.isTriggerFight = true; let cfg = GameM.commonData.fightRoleCfg[rolelv.toString()]; this.flawTimes = cfg.flawclicktimes; this.flawDuration = cfg.flawduration; this.flawRate = cfg.flawrate; this.flawNum = cfg.flawnum; //使用服务端角色配置基础属性 let serCfg = GameM.commonData.fightRoleServerCfg[rolelv.toString()]; let fightrole = new FightRole(); let star = Random.Range(1, 4); fightrole.arrayIndex = -1; fightrole.blood = serCfg.bloods; fightrole.buffId = 1; //无效 在战斗时生效 fightrole.fightTime = serCfg.times; fightrole.fightType = 2; fightrole.lv = rolelv; fightrole.name = serCfg.name; fightrole.star = star; fightrole.rewardId = cfg.fight_box[star - 1]; console.log("Trigger Fight 2"); UIMng.Ins.AsyncGetPanel(PanelType.FightRoleBPanel, (panel) => { panel.OnEnter(fightrole); }); //UIMng.Ins.GetPanel(PanelType.FightRoleBPanel).OnEnter(fightrole); // AdM.onSendEvent(`fight_old_open`, `旧怪触发战斗`, 'fight_old_open'); //AdM.onSendEvent(`guide_${this.curGuideId}`, `引导${this.curGuideId}`, 'guide'); } } } /** * 检查是否触发大富翁BOSS战 * @param rolelv 武将等级 */ CheckRichFight(rolelv: number) { //if (GameM.commonData.fightRoleServerCfg[rolelv.toString()].is_fight == 1) { let cfg = GameM.commonData.fightRoleCfg[rolelv.toString()]; this.flawTimes = cfg.flawclicktimes; this.flawDuration = cfg.flawduration; this.flawRate = cfg.flawrate; this.flawNum = cfg.flawnum; let serCfg = GameM.commonData.fightRoleServerCfg[rolelv.toString()]; let fightrole = new FightRole(); fightrole.arrayIndex = -1; fightrole.blood = serCfg.bloods; fightrole.buffId = 1; //无效 在战斗时生效 fightrole.fightTime = serCfg.times; fightrole.fightType = 3; fightrole.lv = rolelv; fightrole.name = serCfg.name; fightrole.star = 1; //弃用 fightrole.rewardId = 1//弃用; console.log("Trigger Fight 3", fightrole); UIMng.Ins.AsyncGetPanel(PanelType.FightRoleBPanel, (panel) => { panel.OnEnter(fightrole); }); //UIMng.Ins.GetPanel(PanelType.FightRoleBPanel).OnEnter(fightrole); //} } EnterFight() { //console.log("EnterFight:", this.composeFightRoles); HttpM.Instance.SendData(HTTP_TYPE.getMyBossRecords, { version: GameM.commonData.version }, (res) => { LogUtil.logV("-->get boss:", res); //console.log("-->res getboss:", res); if (res.data != null) { if (res.data.length > 0) { this.composeFightRoles = res.data; console.log("select role panel"); UIMng.Ins.AsyncGetPanel(PanelType.FightRolePanel, (panel) => { panel.OnEnter(); }); //UIMng.Ins.GetPanel(PanelType.FightRolePanel).OnEnter(); } else { console.log("no master"); EffectNode.instance.PlayTip(`达到指定等级可招来武将`); } } }, null, null, true); } /**获取 更新武将的星级 服务器获取*/ GetFightRoleStars(callback: Function) { this.fightRolesStars = []; //第一次解锁的武将都是3星 for (let i = 0; i < this.composeFightRoles.length; i++) { //this.fightRolesStars[i]=Random.Range(1,4); this.fightRolesStars[i] = 3; console.log("Star:" + this.fightRolesStars[i]); } callback(); //HttpM.Instance.SendData(); } /**解锁伙伴 * @param mateid 伙伴id * @param name 图片id */ UnlockMate(mateid: number, name: number) { MateData.Ins.UnlockMate(mateid); // UIMng.Ins.GetPanel(PanelType.MateUnlockPanel).OnEnter({ lv: name }); //主界面 师徒5人坐标更新 UiM.Instance.hallNode.getComponent(Main).DisplayMate(); } /** * 三国战戟 解锁伙伴 * @param data 解锁的伙伴数据 */ UnLockMateSanGuo(data: any) { for (let i = 0; i < data.length; i++) { MateData.Ins.UnlockMate(data[i]); } //主界面 师徒5人坐标更新 UiM.Instance.hallNode.getComponent(Main).DisplayMate(); } /**更新触发2 战斗概率数据*/ UpdateTriggerFightRate() { let cfg = GameM.commonData.fightCfg; this.triggerFightRoleMinLv = cfg.unlock_lv; this.fightTriggerTimes = cfg.fight_trigger_times; //"unlock_lv":14, //this.triggerFightRoleMinLv = 7; //max 40 40 39 38 37 36 百分制 this.triggerFightRates[0] = Number((GameM.commonData.maxCarLevel - cfg.nor_lv) / cfg.delta_lv) * cfg.rate_add_delta * 0.01 + cfg.nor_rate; this.triggerFightRates[1] = this.triggerFightRates[0] * cfg.rates[1] * 0.01; this.triggerFightRates[2] = this.triggerFightRates[0] * cfg.rates[2] * 0.01; this.triggerFightRates[3] = this.triggerFightRates[0] * cfg.rates[3] * 0.01; this.triggerFightRates[4] = this.triggerFightRates[0] * cfg.rates[4] * 0.01; //this.triggerFightRates[0] = 80; //this.triggerFightRates[1] = 80; //this.triggerFightRates[2] = 80; //this.triggerFightRates[3] = 80; //this.triggerFightRates[4] = 80; // console.log("-->UpdateRate:", this.triggerFightRates); } /**获取武将遗言 * @param type 类型 1 words1 2 words2 */ GetWords(type: number) { if (this.fightWordsCfg == null) { this.fightWordsCfg = cc.loader.getRes("configs/fightWordsCfg").json; } if (type == 1) { return this.fightWordsCfg.words1[Random.Range(0, this.fightWordsCfg.words1.length)]; } else { return this.fightWordsCfg.words2[Random.Range(0, this.fightWordsCfg.words2.length)]; } } } /**战斗武将*/ export class FightRole { /**战斗id 该战斗存在的唯一标志*/ fightId: string = null; /**战斗类型 1 第一次合成解锁战斗 2 合成已解锁的武将战斗 3 大富翁BOSS战*/ fightType: number = 1; /**战斗类型为1 时 在武将队列中的索引 -1 表示没有*/ arrayIndex: number = 0; /**武将名称*/ name: string = null; /**武将等级*/ lv: number = 1; /**武将星级*/ star: number = 1; /**武将血量*/ blood: number = 10; /**击败需要的时间*/ fightTime: number = 30; /**buff id 弃用 buff改用 武将血量减少时获取 并 生效*/ buffId: number = 1; /**奖励宝箱id*/ rewardId: number = 1001; } /**战斗结果*/ export class FightResult { /**战斗id 该战斗存在的唯一标志*/ fightId: string = null; /**战斗结果 1 战斗胜利 其他 战斗失败*/ result: number = 1; /**战斗类型 1 第一次合成解锁战斗 2 合成已解锁的武将战斗 3 大富翁BOSS战*/ fightType: number = 1; /**武将等级*/ lv: number = 1; /**武将星级*/ star: number = 1; /**奖励 等*/ rewards: any[] = null; /**奖励 天赋石*/ talent: number = 0; /**解锁的伙伴id*/ unlock_mateid: string = null; /**今日剩余奖励次数 只用于战斗触发2*/ reward_times: number = 0; }