import { Component, _decorator } from "cc"; import { DataSystem } from "../core/data/DataSystem"; import { Http } from "../core/net/Http"; import { WindowOpenMode } from "../core/ui/window/WindowOpenMode"; import { WindowSystem } from "../core/ui/window/WindowSystem"; import { Hero_Client, UserHeroData } from "../hero/UserHeroData"; import { MarshalData, Skill } from "./MarshalData"; const { ccclass } = _decorator; /** * 统帅技能数据处理 * @description 统帅技能数据更新 提示弹窗等操作 * @author 郑聂华 */ @ccclass('MarshalSkillSystem') export class MarshalSkillSystem extends Component { private static thisObject: MarshalSkillSystem; private marshalData: MarshalData; private get MarshalData(): MarshalData { if (!this.marshalData) this.marshalData = DataSystem.getData(MarshalData); return this.marshalData; } private set MarshalData(value: MarshalData) { this.marshalData = value; } start() { MarshalSkillSystem.thisObject = this; } onDestroy() { MarshalSkillSystem.thisObject = null; } /**更新统帅技能和通知队列数据*/ private updateNoticeQueue() { let starNum = 0; let userHeroData = DataSystem.getData(UserHeroData); for (let id of userHeroData.haveHeros) { let tempHero = userHeroData.get(id); starNum += tempHero.server.star; } let tempKeys = this.MarshalData.marshalSkillData.lvNeedStarsMap.keys(); for (let id of tempKeys) { let tempStarAry = this.MarshalData.marshalSkillData.lvNeedStarsMap.get(id); for (let i = 0; i < tempStarAry.length; i++) { if (tempStarAry[i] <= starNum) { let curLv = this.MarshalData.marshalSkillData.lvMarshalSkill.get(id); if (curLv < i + 1) { let param = { type: curLv <= 0 ? 1 : 2, id: id, lv: i + 1, lastLv: curLv }; this.MarshalData.skillNoticeQueue.push(param); this.MarshalData.skillUnlockLvUpQueue.push(param); this.MarshalData.marshalSkillData.lvMarshalSkill.set(id, i + 1); } } } } } /** * 更新统帅技能等级数据 */ private async updateSkillLvData(http: Http) { let numStar = 0; let userHeroData = DataSystem.getData(UserHeroData); //await userHeroData.pull(http); for (let id of userHeroData.haveHeros) { let tempHero = userHeroData.get(id); numStar += tempHero.server.star; } let tempKeys = this.MarshalData.marshalSkillData.lvNeedStarsMap.keys(); for (let id of tempKeys) { let tempStarAry = this.MarshalData.marshalSkillData.lvNeedStarsMap.get(id); for (let i = 0; i < tempStarAry.length; i++) { if (numStar >= tempStarAry[i]) this.MarshalData.marshalSkillData.lvMarshalSkill.set(id, i + 1); } } } /**打开统帅技能通知小弹窗*/ private openMarshalSkillNotice() { if (this.MarshalData.skillNoticeQueue && this.MarshalData.skillNoticeQueue.length > 0) { let param = this.MarshalData.skillNoticeQueue[0]; WindowSystem.open("prefabs/ui/marshalStage/marshalSkillNotice", WindowOpenMode.NotCloseAndCover, [param]); } } /**打开统帅技能信息通知弹窗*/ private openMarshalSkillUnlockLv() { if (this.MarshalData.skillUnlockLvUpQueue && this.MarshalData.skillUnlockLvUpQueue.length > 0) { let param = this.MarshalData.skillUnlockLvUpQueue[0]; WindowSystem.open("prefabs/ui/marshalStage/marshalSkillLvUp", WindowOpenMode.NotCloseAndCover, [param]); } } /**获取技能效果值 * @param skill 技能对象 * @param lv 技能等级 */ private getSkillValue(skill: Skill, lv: number) { switch (skill.attType) { case 1: return; case 2: return; case 3: return (skill.skillValue[lv - 1]) / 10000; case 4: return; case 5: return skill.skillValue[lv - 1]; } } /**获取技能效果值字符串 * @param skill 技能对象 * @param lv 技能等级 */ private getSkillValueStr(skill: Skill, lv: number) { switch (skill.attType) { case 1: return; case 2: return; case 3: return ((skill.skillValue[lv - 1]) / 10000 * 100).toFixed(1) + "%"; case 4: return; case 5: return skill.skillValue[lv - 1] + "秒"; } } /** * 获取技能统帅加成值 * @param hero 统帅 */ private getSkillAddValue(hero: Hero_Client) { return Math.pow(hero.commander / 100, 1.9); } /** * 获取技能统帅加成值字符串 * @param skill 技能 * @param lv 技能等级 * @param hero 武将 */ private getSkillAddValueStr(skill: Skill, lv: number, hero: Hero_Client) { let addcommander = Math.pow(hero.commander / 100, 1.9); switch (skill.attType) { case 1: return; case 2: return; case 3: return (addcommander * skill.skillValue[lv - 1] / 10000 * 100).toFixed(1) + "%"; case 4: return; case 5: return (addcommander * skill.skillValue[lv - 1]).toFixed(1) + "秒"; } } /**更新统帅技能信息并检测打开通知弹窗 * @param id 武将id */ public static updateMarshalSkillInfo(id?: number) { this.thisObject.updateNoticeQueue(); this.thisObject.openMarshalSkillNotice(); } /**打开统帅技能通知小弹窗*/ public static openMarshalSkillNotice() { this.thisObject.openMarshalSkillNotice(); } /**打开统帅技能信息通知弹窗*/ public static openMarshalSkillUnlockLv() { this.thisObject.openMarshalSkillUnlockLv(); } /**更新统帅技能和通知队列数据*/ public static updateNoticeQueue() { this.thisObject.updateNoticeQueue(); } /** 更新统帅技能等级数据*/ public static updateSkillLvData(http: Http) { this.thisObject.updateSkillLvData(http); } /**获取技能效果值 * @param skill 技能对象 * @param lv 技能等级 */ public static getSkillValue(skill: Skill, lv: number) { return this.thisObject.getSkillValue(skill, lv); } /**获取技能效果值字符串 * @param skill 技能对象 * @param lv 技能等级 */ public static getSkillValueStr(skill: Skill, lv: number) { return this.thisObject.getSkillValueStr(skill, lv); } /** * 获取技能统帅加成值 * @param hero 统帅 */ public static getSkillAddValue(hero: Hero_Client) { return this.thisObject.getSkillAddValue(hero); } /** * 获取技能统帅加成值字符串 * @param skill 技能 * @param lv 技能等级 * @param hero 武将 */ public static getSkillAddValueStr(skill: Skill, lv: number, hero: Hero_Client) { return this.thisObject.getSkillAddValueStr(skill, lv, hero); } }