| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import { _decorator, Component, Node, sp, color, director } from 'cc';
- import { DataSystem } from '../core/data/DataSystem';
- import { Http, HttpResponseCode } from '../core/net/Http';
- import { WindowSystem } from '../core/ui/window/WindowSystem';
- import { ConfigData } from '../data/ConfigData';
- import { DeviceData } from '../data/jsb/DeviceData';
- import { UserData } from '../data/UserData';
- import { UserHeroData } from '../hero/UserHeroData';
- import { GM } from '../launch/GM';
- import { ReportThinking } from '../ReportThinking';
- import { BattleData, BattleState } from './BattleData';
- import { MissionData } from './MissionData';
- import { BattleResult } from './ui/BattleResult';
- import { BattleUIData } from './ui/BattleUIData';
- const { ccclass, property } = _decorator;
- @ccclass('Mission')
- export class Mission extends Component {
- @property({ type: Http, tooltip: "Http组件" }) http: Http;
- @property({ type: Node, tooltip: "完成窗口" }) openComplete: Node;
- @property({ type: Node, tooltip: "失败窗口" }) openFail: Node;
- @property({ type: Node, tooltip: "挑战boss按钮" }) fightBossButton: Node;
- private data: BattleData;
- /**boss关卡是否失败过 */
- private isfailed = false;
- /**过关奖励 */
- private resultData: any;
- /**下一关数值 */
- private nextMission = 0;
- async start() {
- DataSystem.createData(MissionData);
- this.data = DataSystem.getData(BattleData);
- }
- update() {
- DataSystem.watch(BattleUIData, "_bannerRunOver") && this.missionChange();
- DataSystem.watch(MissionData, "_missionOver") && this.missionComplete();
- DataSystem.watch(MissionData, "_isResultWindowClose") && this.resultWindowClose();
- }
- private missionChange(): void {
- if (DataSystem.getData(BattleUIData)._bannerRunOver) {
- if (this.isfailed && this.fightBossButton.getComponent(sp.Skeleton).color.a == 0) {
- this.fightBossButton.getComponent(sp.Skeleton).color = color(255, 255, 255, 255);
- }
- if (!this.isfailed && this.fightBossButton.getComponent(sp.Skeleton).color.a == 255) {
- this.fightBossButton.getComponent(sp.Skeleton).color = color(255, 255, 255, 0);
- }
- }
- }
- /**关卡完成 */
- private async missionComplete() {
- if (this.data.battleState == BattleState.inBattle && DataSystem.getData(MissionData)._missionOver) {
- this.fightBossButton.getComponent(sp.Skeleton).color = color(255, 255, 255, 0);
- DataSystem.getData(BattleUIData)._bannerRunOver = false;
- DataSystem.getData(MissionData)._missionOver = false;
- this.data.battleState = BattleState.outBattle;
- let result = await this.http.send("/api/battle/endBattle", { isWin: this.data._moveEndCount == 0, monsters: this.data._monsterKilled, addLevel: !this.isfailed });
- if (result && result.code == HttpResponseCode.Success) {
- this.resultData = result.data;
- this.nextMission = result.data.level;
- this.addResult();
- if (DataSystem.getData(ConfigData)["mission"][this.data.mission]["type"] == "2") {
- this.isfailed = !result.data.isWin;
- if (result.data.isWin) {
- DataSystem.getData(UserData).level = this.nextMission;
- DataSystem.getData(UserData).lv = this.nextMission - 1;
- if (DataSystem.getData(MissionData).isInPvp) {
- this.next();
- } else {
- // GM.addBattleLog(`打开胜利窗口`);
- this.openComplete.active = true;
- this.openComplete.getComponent(BattleResult).setData(result.data);
- }
- } else {
- DataSystem.getData(UserData).lv = DataSystem.getData(UserData).level = this.nextMission;
- if (DataSystem.getData(MissionData).isInPvp) {
- this.next();
- } else {
- // GM.addBattleLog(`打开失败窗口`);
- this.openFail.active = true;
- this.openFail.getComponent(BattleResult).setData(result.data);
- }
- }
- } else {
- if (result.data.isWin) {
- DataSystem.getData(UserData).level = this.nextMission;
- DataSystem.getData(UserData).lv = this.nextMission - 1;
- } else {
- DataSystem.getData(UserData).lv = DataSystem.getData(UserData).level = this.nextMission;
- }
- this.next();
- }
- }
- else {
- localStorage.removeItem("account");
- DataSystem.getData(DeviceData).needlogin = true;
- director.loadScene("launch");
- WindowSystem.showTips("网络异常,请重新登录");
- }
- this.data._moveEndCount = 0;
- this.data._monsterKilled = [];
- this.data._monsterKilledNode = [];
- // GM.addBattleLog(`===============================关卡:${this.data.mission},关卡完成===============================`);
- }
- }
- private resultWindowClose(): void {
- if (DataSystem.getData(MissionData)._isResultWindowClose) {
- DataSystem.getData(MissionData)._isResultWindowClose = false;
- this.next();
- }
- }
- /**添加奖励 */
- private addResult(): void {
- if (!this.resultData) {
- // GM.addBattleLog("关卡出错,关卡暂停,resultData:" + JSON.stringify(this.resultData));
- return;
- }
- let userData = DataSystem.getData(UserData);
- this.resultData.prestige && ReportThinking.currency_increase('prestige', userData.prestige, this.resultData.prestige, this.resultData.prestige + userData.prestige, 'endBattle');
- this.resultData.money && ReportThinking.currency_increase('money', userData.money, this.resultData.money, this.resultData.money + userData.money, 'endBattle');
- this.resultData.diamond && ReportThinking.currency_increase('diamond', userData.diamond, this.resultData.diamond, this.resultData.diamond + userData.diamond, 'endBattle');
- this.resultData.bonus && ReportThinking.currency_increase('bonus', userData.bonus, this.resultData.bonus, this.resultData.bonus + userData.bonus, 'endBattle');
- userData.prestige += this.resultData.prestige;
- userData.money += this.resultData.autoMoney;
- userData.money += this.resultData.money;
- userData.diamond += this.resultData.diamond;
- userData.bonus += this.resultData.bonus;
- for (let i = 0; i < this.resultData.heros.length; i++) {
- DataSystem.getData(UserHeroData).addHero(this.resultData.heros[i]);
- }
- for (let k in this.resultData.chips) {
- DataSystem.getData(UserHeroData).addChip(parseInt(k), this.resultData.chips[k]);
- }
- }
- /**开始下一关 */
- private async next() {
- let battleResult = await this.http.send("/api/battle/startBattle", { level: this.nextMission });
- battleResult && battleResult.code == HttpResponseCode.Success && (this.data.mission = this.nextMission);
- if (!battleResult) {
- localStorage.removeItem("account");
- DataSystem.getData(DeviceData).needlogin = true;
- director.loadScene("launch");
- WindowSystem.showTips("网络异常,请重新登录");
- }
- // GM.addBattleLog(`===============================开始关卡:${this.nextMission}===============================`);
- }
- public async fightBoss() {
- if (this.fightBossButton.getComponent(sp.Skeleton).color.a == 255) {
- this.fightBossButton.getComponent(sp.Skeleton).color = color(255, 255, 255, 0);
- let battleResult = await this.http.send("/api/battle/startBattle", { level: this.nextMission + 1 })
- battleResult && battleResult.code == HttpResponseCode.Success && (this.data.mission = this.nextMission + 1);
- this.isfailed = false;
- if (!battleResult) {
- localStorage.removeItem("account");
- DataSystem.getData(DeviceData).needlogin = true;
- director.loadScene("launch");
- WindowSystem.showTips("网络异常,请重新登录");
- }
- }
- }
- }
|