PublicData.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { _decorator, Component, Node, sp } from "cc";
  2. import { BattleData } from "../battle/BattleData";
  3. import { DataSystem } from "../core/data/DataSystem";
  4. import { Http, HttpResponseCode } from "../core/net/Http";
  5. import { WindowOpenMode } from "../core/ui/window/WindowOpenMode";
  6. import { WindowSystem } from "../core/ui/window/WindowSystem";
  7. import { ConfigData } from "../data/ConfigData";
  8. import { UserData } from "../data/UserData";
  9. import { Fixbug } from "../FixBug";
  10. import { FormationData } from "../hero/formation/FormationData";
  11. import { UserHeroData } from "../hero/UserHeroData";
  12. import { MarshalData } from "../marshal/MarshalData";
  13. import { RedPointData } from "./RedPointData";
  14. const { ccclass, property, requireComponent } = _decorator;
  15. /**
  16. * 公共数据处理
  17. * @description 游戏第一次进入需要拉取一些初始数据、一些数据需要推送给战斗模块
  18. * @author 袁浩
  19. */
  20. @ccclass("PublicData")
  21. @requireComponent(Http)
  22. export class PublicData extends Component {
  23. @property({ tooltip: "界面层", type: Node })
  24. public mainUI: Node;
  25. @property({ tooltip: "spine动画列表(修复BUG用)", type: sp.Skeleton })
  26. public spineList: sp.Skeleton[] = [];
  27. onLoad() {
  28. this.mainUI.active = false;
  29. this.pull();
  30. }
  31. private async pull() {
  32. let http = this.getComponent(Http);
  33. await DataSystem.getData(UserHeroData).pull(http);
  34. await DataSystem.getData(FormationData).pull(http);
  35. await DataSystem.getData(RedPointData).pull(http);
  36. await DataSystem.getData(MarshalData).init();
  37. this.mainUI.active = true;
  38. for (let i = 0; i < this.spineList.length; i++) {
  39. Fixbug.fixSpine_active(this.spineList[i]);
  40. }
  41. let userHero = DataSystem.getData(UserHeroData);
  42. if (!DataSystem.getData(UserData).receivedNewUserBonus) {
  43. WindowSystem.open("prefabs/ui/redEnvelopes", WindowOpenMode.NotCloseAndAdd, [{ type: 4, num: DataSystem.getData(ConfigData).get("serverConfig").NewPlayerRedPacket }]);
  44. } else if (!userHero.haveHeros.length) {//如果用户没有英雄
  45. WindowSystem.open("prefabs/ui/firstHero/firstHero", WindowOpenMode.NotCloseAndAdd);
  46. }
  47. else {//直接开始战斗
  48. let userData = DataSystem.getData(UserData);
  49. let battleResult = await http.send("/api/battle/startBattle", { level: userData.level });
  50. battleResult && battleResult.code == HttpResponseCode.Success && (DataSystem.getData(BattleData).mission = userData.level);
  51. }
  52. }
  53. update() {
  54. this.watchFormation(1);
  55. this.watchFormation(2);
  56. this.watchFormation(3);
  57. this.watchFormation(4);
  58. this.watchFormation(5);
  59. }
  60. watchFormation(formationID: number) {
  61. if (DataSystem.watch(FormationData, formationID)) {
  62. let heroID = DataSystem.getData(FormationData).get(formationID);
  63. //推送到战斗模块
  64. if (heroID) {
  65. let hero_server = DataSystem.getData(UserHeroData).get(heroID).server;
  66. let battleHeroData = DataSystem.getData(BattleData).heros.get(formationID);
  67. battleHeroData.id = heroID;
  68. battleHeroData.lv = hero_server.lv;
  69. battleHeroData.starLv = hero_server.star;
  70. battleHeroData.lvProgress = hero_server.percent / 100;
  71. }
  72. else {
  73. let battleHeroData = DataSystem.getData(BattleData).heros.get(formationID);
  74. battleHeroData.id = 0;
  75. }
  76. }
  77. }
  78. }