| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import { _decorator, Component, Node, sp } from "cc";
- import { BattleData } from "../battle/BattleData";
- import { DataSystem } from "../core/data/DataSystem";
- import { Http, HttpResponseCode } from "../core/net/Http";
- import { WindowOpenMode } from "../core/ui/window/WindowOpenMode";
- import { WindowSystem } from "../core/ui/window/WindowSystem";
- import { ConfigData } from "../data/ConfigData";
- import { UserData } from "../data/UserData";
- import { Fixbug } from "../FixBug";
- import { FormationData } from "../hero/formation/FormationData";
- import { UserHeroData } from "../hero/UserHeroData";
- import { MarshalData } from "../marshal/MarshalData";
- import { RedPointData } from "./RedPointData";
- const { ccclass, property, requireComponent } = _decorator;
- /**
- * 公共数据处理
- * @description 游戏第一次进入需要拉取一些初始数据、一些数据需要推送给战斗模块
- * @author 袁浩
- */
- @ccclass("PublicData")
- @requireComponent(Http)
- export class PublicData extends Component {
- @property({ tooltip: "界面层", type: Node })
- public mainUI: Node;
- @property({ tooltip: "spine动画列表(修复BUG用)", type: sp.Skeleton })
- public spineList: sp.Skeleton[] = [];
- onLoad() {
- this.mainUI.active = false;
- this.pull();
- }
- private async pull() {
- let http = this.getComponent(Http);
- await DataSystem.getData(UserHeroData).pull(http);
- await DataSystem.getData(FormationData).pull(http);
- await DataSystem.getData(RedPointData).pull(http);
- await DataSystem.getData(MarshalData).init();
- this.mainUI.active = true;
- for (let i = 0; i < this.spineList.length; i++) {
- Fixbug.fixSpine_active(this.spineList[i]);
- }
- let userHero = DataSystem.getData(UserHeroData);
- if (!DataSystem.getData(UserData).receivedNewUserBonus) {
- WindowSystem.open("prefabs/ui/redEnvelopes", WindowOpenMode.NotCloseAndAdd, [{ type: 4, num: DataSystem.getData(ConfigData).get("serverConfig").NewPlayerRedPacket }]);
- } else if (!userHero.haveHeros.length) {//如果用户没有英雄
- WindowSystem.open("prefabs/ui/firstHero/firstHero", WindowOpenMode.NotCloseAndAdd);
- }
- else {//直接开始战斗
- let userData = DataSystem.getData(UserData);
- let battleResult = await http.send("/api/battle/startBattle", { level: userData.level });
- battleResult && battleResult.code == HttpResponseCode.Success && (DataSystem.getData(BattleData).mission = userData.level);
- }
- }
- update() {
- this.watchFormation(1);
- this.watchFormation(2);
- this.watchFormation(3);
- this.watchFormation(4);
- this.watchFormation(5);
- }
- watchFormation(formationID: number) {
- if (DataSystem.watch(FormationData, formationID)) {
- let heroID = DataSystem.getData(FormationData).get(formationID);
- //推送到战斗模块
- if (heroID) {
- let hero_server = DataSystem.getData(UserHeroData).get(heroID).server;
- let battleHeroData = DataSystem.getData(BattleData).heros.get(formationID);
- battleHeroData.id = heroID;
- battleHeroData.lv = hero_server.lv;
- battleHeroData.starLv = hero_server.star;
- battleHeroData.lvProgress = hero_server.percent / 100;
- }
- else {
- let battleHeroData = DataSystem.getData(BattleData).heros.get(formationID);
- battleHeroData.id = 0;
- }
- }
- }
- }
|