FightRoleBPanel.ts 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. // Learn TypeScript:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. import CashOutData from "../datas/CashOutData";
  8. import { HTTP_TYPE } from "../datas/CommonData";
  9. import { FightData, FightRole } from "../datas/FightData";
  10. import AdM from "../manager/AdM";
  11. import { GameController } from "../manager/GameController";
  12. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  13. import GuideMng from "../manager/GuideMng";
  14. import HttpM from "../manager/HttpM";
  15. import BasePanel from "../uiFrames/BasePanel";
  16. import UIMng, { PanelType } from "../uiFrames/UIMng";
  17. import LogUtil from "../utils/LogUtil";
  18. import Random from "../utils/Random";
  19. import { Utils } from "../utils/Utils";
  20. const { ccclass, property } = cc._decorator;
  21. @ccclass
  22. export default class FightRoleBPanel extends BasePanel {
  23. //武将战斗触发选择界面
  24. @property(cc.Node)
  25. panelNode: cc.Node = null;
  26. @property(cc.Node)
  27. title_new: cc.Node = null;
  28. @property(cc.Node)
  29. title_old: cc.Node = null;
  30. @property(cc.Sprite)
  31. roleImg: cc.Sprite = null;
  32. @property(cc.Label)
  33. txtName: cc.Label = null;
  34. @property(cc.Node)
  35. rewards: cc.Node = null;
  36. @property(cc.Label)
  37. rewardTxt: cc.Label = null;
  38. //@property(cc.Widget)
  39. //widget: cc.Widget = null;
  40. //private roleNum = 0;
  41. private fightRole: FightRole = null;
  42. private curRole: any = null;
  43. private curRoleSer: any = null;
  44. private curRoleLv: number = 1;
  45. //private isInit: boolean = false;
  46. OnEnter(param: any) {
  47. this.Init(param);
  48. this.panelNode.scale = 0;
  49. this.node.active = true;
  50. cc.tween(this.panelNode).to(0.2, { scale: 1 }, { easing: "backOut" })
  51. .call(() => {
  52. //this.widget.updateAlignment();
  53. if (this.fightRole.fightType == 1)
  54. GuideMng.Ins.CheckFightGuide4();
  55. })
  56. .start();
  57. this.node.setSiblingIndex(this.node.parent.childrenCount - 1);
  58. if (this.fightRole.fightType == 1) {
  59. // AdM.onSendEvent(`fight_new_open_${this.fightRole.lv}`, `${this.fightRole.name}`, 'fight_new_open')
  60. }
  61. }
  62. OnExit() {
  63. this.roleImg.spriteFrame = null;
  64. this.node.active = false;
  65. }
  66. Init(param: any) {
  67. this.fightRole = param;
  68. this.roleImg.node.scale = 0.8;
  69. this.UpdateRoleInfo();
  70. }
  71. UpdateRoleInfo() {
  72. //console.log("FightRoleCount: " + FightData.Ins.composeFightRoles.length);
  73. this.curRoleLv = this.fightRole.lv;
  74. this.title_new.active = this.fightRole.fightType == 1;
  75. this.title_old.active = this.fightRole.fightType == 2 || this.fightRole.fightType == 3;
  76. this.rewards.active = this.fightRole.fightType == 1;
  77. this.curRole = GameM.commonData.fightRoleCfg[this.curRoleLv.toString()];
  78. cc.loader.loadRes('carPic/side/side_' + this.curRoleLv, cc.SpriteFrame, (err, asset) => {
  79. this.roleImg.spriteFrame = asset;
  80. });
  81. this.txtName.string = "Lv" + this.curRoleLv + this.fightRole.name;
  82. //this.txtLv.string = "Lv" + this.curRoleLv;
  83. let cfg = CashOutData.Instance.cashCft;
  84. let len = cfg.length;
  85. for (var i = 0; i < len; i++) {
  86. if (cfg[i].type_value == this.curRoleLv) {
  87. this.rewardTxt.string = cfg[i].moneyshow.split('~')[1];
  88. break;
  89. }
  90. }
  91. }
  92. async Click_ChallengeBtn() {
  93. console.log("fight type:" + this.fightRole.fightType + " buff bag id:" + this.curRole.buffbag_id + " buff id:" + this.fightRole.buffId);
  94. //let tempDate = new Date();
  95. //let startTime = tempDate.getTime();
  96. //let totalMin = 0;
  97. let cfg = GameM.commonData.fightRoleCfg[this.curRoleLv.toString()];
  98. FightData.Ins.flawTimes = cfg.flawclicktimes;
  99. FightData.Ins.flawDuration = cfg.flawduration;
  100. FightData.Ins.flawRate = cfg.flawrate;
  101. FightData.Ins.flawNum = cfg.flawnum;
  102. await Utils.loadResPromise('prefabs/TransitNode')
  103. GameController.Ins.PlayTransitAniForHttp();
  104. //判断战斗类型 12为请求战斗 3 为大富翁触发战斗(大富翁战斗不需要请求服务器)
  105. if (this.fightRole.fightType == 3) {
  106. GameController.Ins.PlayCloseTransitAniForHttp(() => {
  107. this.fightRole.fightId = "";
  108. this.OnExit();
  109. UIMng.Ins.AsyncGetPanel(PanelType.FightPanel, (panel) => {
  110. panel.OnEnter(this.fightRole);
  111. });
  112. //UIMng.Ins.GetPanel(PanelType.FightPanel).OnEnter(this.fightRole);
  113. });
  114. } else {
  115. HttpM.Instance.SendData(HTTP_TYPE.beginBattle, { battleType: this.fightRole.fightType, bossCode: this.curRoleLv.toString(), version: GameM.commonData.version }, (res) => {
  116. LogUtil.logV("-->BeginBattle:", JSON.stringify(res));
  117. //console.log("-->BeginBattle:"+JSON.stringify(res))
  118. //totalMin = ((new Date()).getTime() - startTime) / 1000;
  119. //console.log("---->BeginTime:" + totalMin);
  120. if (res.data != null) {
  121. GameController.Ins.PlayCloseTransitAniForHttp(() => {
  122. this.fightRole.fightId = res.data;
  123. this.OnExit();
  124. UIMng.Ins.AsyncGetPanel(PanelType.FightPanel, (panel) => {
  125. panel.OnEnter(this.fightRole);
  126. });
  127. //UIMng.Ins.GetPanel(PanelType.FightPanel).OnEnter(this.fightRole);
  128. });
  129. }
  130. });
  131. }
  132. GameM.audioM.playEffect(AUDIO_TYPE.button);
  133. }
  134. Click_CloseBtn() {
  135. this.OnExit();
  136. GameM.audioM.playEffect(AUDIO_TYPE.button);
  137. }
  138. }