FightRolePanel.ts 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 { GameController } from "../manager/GameController";
  11. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  12. import HttpM from "../manager/HttpM";
  13. import BasePanel from "../uiFrames/BasePanel";
  14. import UIMng, { PanelType } from "../uiFrames/UIMng";
  15. import Random from "../utils/Random";
  16. import { Utils } from "../utils/Utils";
  17. import RewardNode from "./RewardNode";
  18. const { ccclass, property } = cc._decorator;
  19. @ccclass
  20. export default class FightRolePanel extends BasePanel {
  21. //武将选择界面
  22. @property(cc.Node)
  23. panelNode: cc.Node = null;
  24. @property(cc.Label)
  25. txtName: cc.Label = null;
  26. @property(cc.Label)
  27. txtLv: cc.Label = null;
  28. @property(cc.Node)
  29. stars: cc.Node[] = [];
  30. @property(cc.Sprite)
  31. roleImg: cc.Sprite = null;
  32. @property(cc.Label)
  33. txtRedbag: cc.Label = null;
  34. @property(cc.Node)
  35. rewardBoxs: cc.Node[] = [];
  36. @property(cc.Sprite)
  37. rewardBoxImgs: cc.Sprite[] = [];
  38. @property(cc.Node)
  39. //rewardRedbag: cc.Node = null;
  40. @property(cc.Label)
  41. //txtRewardRedbag: cc.Label = null;
  42. //@property(cc.Node)
  43. //rewardTianfu: cc.Node = null;
  44. @property(cc.Node)
  45. btnLeft: cc.Node = null;
  46. @property(cc.Node)
  47. btnRight: cc.Node = null;
  48. @property(cc.Widget)
  49. widget: cc.Widget = null;
  50. private roleNum = 0;
  51. private curRoleIndex = 0;
  52. private curRole: any = null;
  53. private curRoleSer: any = null;
  54. private curRoleLv: number = 1;
  55. //private curRoleStar: number = 1;
  56. private curRoleBlood: number = 10;
  57. private curRoleTime: number = 10;
  58. private curRoleBuffId: number = 1;
  59. private isInit: boolean = false;
  60. OnEnter() {
  61. this.Init();
  62. this.panelNode.scale = 0;
  63. this.node.active = true;
  64. cc.tween(this.panelNode).to(0.2, { scale: 1 }, { easing: "backOut" })
  65. .call(() => { this.widget.updateAlignment(); })
  66. .start();
  67. //this.node.setSiblingIndex(this.node.parent.childrenCount - 1);
  68. }
  69. OnExit() {
  70. this.node.active = false;
  71. }
  72. Init() {
  73. if (!this.isInit) {
  74. this.isInit = true;
  75. this.roleImg.node.scale = 1.3;
  76. //获取武将星级配置信息
  77. //FightData.Ins.GetFightRoleStars(() => {
  78. this.roleNum = FightData.Ins.composeFightRoles.length;
  79. this.curRoleIndex = this.roleNum - 1;
  80. this.UpdateRoleInfo();
  81. //});
  82. } else {
  83. //获取武将星级配置信息
  84. //FightData.Ins.GetFightRoleStars(() => {
  85. this.roleNum = FightData.Ins.composeFightRoles.length;
  86. this.curRoleIndex = this.roleNum - 1;
  87. this.UpdateRoleInfo();
  88. //});
  89. }
  90. }
  91. UpdateRoleInfo() {
  92. //console.log("FightRoleCount: " + FightData.Ins.composeFightRoles.length);
  93. this.curRoleLv = FightData.Ins.composeFightRoles[this.curRoleIndex].code;
  94. this.curRole = GameM.commonData.fightRoleCfg[this.curRoleLv.toString()];
  95. //使用服务端角色配置基础属性
  96. this.curRoleSer = GameM.commonData.fightRoleServerCfg[this.curRoleLv.toString()];
  97. cc.loader.loadRes('carPic/side/side_' + this.curRoleLv, cc.SpriteFrame, (err, asset) => {
  98. this.roleImg.spriteFrame = asset;
  99. });
  100. let cfg = CashOutData.Instance.cashCft;
  101. let len = cfg.length;
  102. for (var i = 0; i < len; i++) {
  103. if (cfg[i].type_value == this.curRoleLv) {
  104. this.txtRedbag.string = cfg[i].moneyshow.split('~')[1];
  105. break;
  106. }
  107. }
  108. this.txtName.string = this.curRole.name;
  109. this.txtLv.string = "Lv" + this.curRoleLv;
  110. this.DiaplayLevelInfo();
  111. //this.btnLeft.active = this.curRoleIndex > 0;
  112. //this.btnRight.active = this.curRoleIndex < (this.roleNum - 1);
  113. }
  114. /**显示武将星级相关信息*/
  115. DiaplayLevelInfo() {
  116. let rewardnames = this.curRole.reward_show;
  117. //星级
  118. for (let i = 0; i < this.stars.length; i++) {
  119. this.stars[i].active = false;
  120. //不显示星级
  121. //if (i + 1 <= this.curRoleStar) {
  122. // this.stars[i].active = true;
  123. //}
  124. }
  125. for (let i = 0; i < this.rewardBoxs.length; i++) {
  126. this.rewardBoxs[i].active = false;
  127. if (i < rewardnames.length) {
  128. this.rewardBoxs[i].active = true;
  129. cc.loader.loadRes('xiyou/icon/' + rewardnames[i], cc.SpriteFrame, (err, asset) => {
  130. this.rewardBoxImgs[i].spriteFrame = asset;
  131. });
  132. }
  133. }
  134. }
  135. Click_LeftBtn() {
  136. this.curRoleIndex--;
  137. if (this.curRoleIndex < 0) this.curRoleIndex = this.roleNum - 1;
  138. this.UpdateRoleInfo();
  139. GameM.audioM.playEffect(AUDIO_TYPE.button);
  140. }
  141. Click_RightBtn() {
  142. this.curRoleIndex++;
  143. if (this.curRoleIndex >= this.roleNum) this.curRoleIndex = 0;
  144. this.UpdateRoleInfo();
  145. GameM.audioM.playEffect(AUDIO_TYPE.button);
  146. }
  147. async Click_ChallengeBtn() {
  148. //使用服务端角色基础属性
  149. this.curRoleBlood = this.curRoleSer.bloods;
  150. this.curRoleTime = this.curRoleSer.times;
  151. //let buffrandom = Random.Range(0, this.curRole.buffbag_rate, false);
  152. //弃用 战斗时获取
  153. //let buffrandom = Random.Range(0, 100, false);
  154. //let buffbag = GameM.commonData.buffbagCfg[this.curRole.buffbag_id.toString()];
  155. //let temprate = 0;
  156. //for (let i = 0; i < buffbag.buff_rate.length; i++) {
  157. // temprate += buffbag.buff_rate[i];
  158. // if (buffrandom <= temprate) {
  159. // this.curRoleBuffId = buffbag.id[i];
  160. // break;
  161. // }
  162. //}
  163. //console.log("buff bag id:" + this.curRole.buffbag_id + " buff id:" + this.curRoleBuffId);
  164. let cfg = GameM.commonData.fightRoleCfg[this.curRoleLv.toString()];
  165. FightData.Ins.flawTimes = cfg.flawclicktimes;
  166. FightData.Ins.flawDuration = cfg.flawduration;
  167. FightData.Ins.flawRate = cfg.flawrate;
  168. FightData.Ins.flawNum=cfg.flawnum;
  169. let fightrole = new FightRole();
  170. fightrole.arrayIndex = this.curRoleIndex;
  171. fightrole.blood = this.curRoleBlood;
  172. fightrole.buffId = 1; //无效 战斗时生效
  173. fightrole.fightTime = this.curRoleTime;
  174. fightrole.fightType = 1;
  175. fightrole.lv = this.curRoleLv;
  176. fightrole.name = this.curRoleSer.name;
  177. //弃用 使用接口回调获取结算奖励
  178. fightrole.star = 1; //无效
  179. //弃用 使用接口回调获取结算奖励
  180. fightrole.rewardId = 1;
  181. GameM.audioM.playEffect(AUDIO_TYPE.button);
  182. await Utils.loadResPromise('prefabs/TransitNode')
  183. GameController.Ins.PlayTransitAniForHttp();
  184. HttpM.Instance.SendData(HTTP_TYPE.beginBattle, { battleType: 1, bossCode: this.curRoleLv.toString(), version: GameM.commonData.version }, (res) => {
  185. console.log("-->BeginBattle:", res)
  186. if (res.data != null) {
  187. GameController.Ins.PlayCloseTransitAniForHttp(() => {
  188. fightrole.fightId = res.data;
  189. this.OnExit();
  190. UIMng.Ins.AsyncGetPanel(PanelType.FightPanel, (panel) => {
  191. panel.OnEnter(fightrole);
  192. });
  193. //UIMng.Ins.GetPanel(PanelType.FightPanel).OnEnter(fightrole);
  194. });
  195. }
  196. });
  197. }
  198. Click_CloseBtn() {
  199. this.OnExit();
  200. GameM.audioM.playEffect(AUDIO_TYPE.button);
  201. }
  202. }