FightPanel.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  1. import { HTTP_TYPE } from "../datas/CommonData";
  2. import { FightData, FightResult, FightRole } from "../datas/FightData";
  3. import { MateData } from "../datas/MateData";
  4. import { RichData } from "../datas/RichData";
  5. import { GameController } from "../manager/GameController";
  6. import GameM, { AUDIO_TYPE } from "../manager/GameM";
  7. import GuideMng from "../manager/GuideMng";
  8. import HttpM from "../manager/HttpM";
  9. import UiM from "../manager/UiM";
  10. import { EventMng } from "../tools/EventMng";
  11. import MyExtends, { EaseType, PlayerPrefs } from "../tools/MyExtends";
  12. import Time from "../tools/Time";
  13. import BasePanel from "../uiFrames/BasePanel";
  14. import UIMng, { PanelType } from "../uiFrames/UIMng";
  15. import LogUtil from "../utils/LogUtil";
  16. import Random from "../utils/Random";
  17. import { Utils } from "../utils/Utils";
  18. import EffectNode from "./EffectNode";
  19. const { ccclass, property } = cc._decorator;
  20. @ccclass
  21. export default class FightPanel extends BasePanel {
  22. //武将战斗界面
  23. @property(cc.Node)
  24. panelNode: cc.Node = null;
  25. @property(cc.Node)
  26. touchNode: cc.Node = null;
  27. @property(cc.Sprite)
  28. blood_white: cc.Sprite = null;
  29. @property(cc.Sprite)
  30. blood: cc.Sprite = null;
  31. @property(cc.Label)
  32. blood_txt: cc.Label = null;
  33. @property(cc.Sprite)
  34. timeSlider: cc.Sprite = null;
  35. @property(cc.Sprite)
  36. headImg: cc.Sprite = null;
  37. @property(cc.Label)
  38. txtHeadLv: cc.Label = null;
  39. @property(cc.Label)
  40. txtTime: cc.Label = null;
  41. @property(cc.Label)
  42. txtName: cc.Label = null;
  43. @property(cc.Label)
  44. txtLv: cc.Label = null;
  45. @property(cc.Node)
  46. stars: cc.Node[] = [];
  47. @property(cc.Sprite)
  48. roleImg: cc.Sprite = null;
  49. @property(cc.Node)
  50. wordsNode: cc.Node = null;
  51. @property(cc.Label)
  52. txtWords: cc.Label = null;
  53. @property(sp.Skeleton)
  54. ani_getblood: sp.Skeleton = null;
  55. @property(sp.Skeleton)
  56. ani_defense: sp.Skeleton = null;
  57. //@property(cc.Node)
  58. //btnClose: cc.Node = null;
  59. @property(cc.Label)
  60. txtDamage: cc.Label = null;
  61. @property(cc.Node)
  62. damageCrit: cc.Node = null;
  63. @property(cc.Node)
  64. damageDodge: cc.Node = null;
  65. @property(cc.Node)
  66. damageResist: cc.Node = null;
  67. @property(sp.Skeleton)
  68. attack: sp.Skeleton = null;
  69. @property(cc.Node)
  70. flawEft: cc.Node = null;
  71. @property(cc.Label)
  72. flawTxt: cc.Label = null;
  73. private canvas: cc.Node = null;
  74. private damageInitPos: cc.Vec2 = null;
  75. private roleInitPos: cc.Vec2 = null;
  76. private fightRole: FightRole = null;
  77. /*
  78. {
  79. curRoleIndex :0,
  80. curRole: any,
  81. curRoleLv: 1,
  82. curRoleStar: 1,
  83. curRoleBlood: 10,
  84. curRoleTime: 30,
  85. curRoleBuffId: 10
  86. }
  87. */
  88. /*
  89. buffType = 1 回春 每秒回复 buff.effect.blood 血量 持续 buff.effect.time 秒
  90. buffType = 2 坚甲 受到的伤害减半 持续 buff.effect.time 秒
  91. buffType = 3 矫健 闪避率提升 buff.effect.rate 持续 buff.effect.time 秒
  92. */
  93. private roleBlood: number = 10;
  94. /**buff库id-武将buff触发时*/
  95. private buffIds: number[] = null;
  96. /**buff触发-武将剩余血量剩余百分比*/
  97. private buffTriggerBloods: number[] = null;
  98. /**当前 buff 触发索引*/
  99. private curBuffTriggerIndex: number = 0;
  100. private buff: any = null;
  101. /**1 回春 2 坚甲 3 矫健*/
  102. private buffType: number = -1;
  103. /**buff效果每秒生效 计时器*/
  104. private buffTimer: number = 0;
  105. /**buff生效 计时器*/
  106. private buffHadTimer: number = 0;
  107. /**buff是否开始生效*/
  108. private buffIsUsed: boolean = false;
  109. /**是否开始战斗*/
  110. private isFighting: boolean = false;
  111. /**战斗计时器*/
  112. private fightTimer: number = 0;
  113. /**战斗攻击CD计时器*/
  114. private attackTimer: number = 0;
  115. /**攻击间隔时间*/
  116. private attackTime: number = 0.1;
  117. /**是否可以攻击*/
  118. private isCanAttack: boolean = false;
  119. private isWordsShowing: boolean = false;
  120. onLoad() {
  121. this.touchNode.on(cc.Node.EventType.TOUCH_START, this.OnTouchAttak, this);
  122. this.damageInitPos = this.txtDamage.node.getPosition();
  123. this.roleInitPos = this.roleImg.node.getPosition();
  124. this.canvas = cc.find("Canvas");
  125. EventMng.Register_Event("UseFlawEffect", this.UseFlawEffect, this);
  126. }
  127. OnEnter(param: any) {
  128. this.node.setPosition(0, 0,);
  129. this.roleImg.node.scale = 1.1;
  130. this.fightRole = param;
  131. this.UpdateRoleInfo();
  132. this.node.active = true;
  133. this.node.setSiblingIndex(this.node.parent.childrenCount - 1);
  134. GameM.audioM.setPauseMusic();
  135. GameM.audioM.playMateEffect(AUDIO_TYPE.fightBgm, true);
  136. if (GuideMng.Ins.CurGuideId == 4 && PlayerPrefs.GetInt("GGuide4", 0) != 1) {
  137. GuideMng.Ins.ResumeGuide();
  138. }
  139. }
  140. OnExit() {
  141. this.roleImg.spriteFrame = null;
  142. this.node.active = false;
  143. if (this.ani_defense.node.active)
  144. this.ani_defense.node.active = false;
  145. if (this.ani_getblood.node.active)
  146. this.ani_getblood.node.active = false;
  147. if (this.wordsNode.active) {
  148. this.wordsNode.stopAllActions();
  149. this.wordsNode.active = false;
  150. }
  151. GameController.Ins.SwitchAudio(1);
  152. //GameM.audioM.setResumeMusic();
  153. //if (GameM.audioM.IsMatePlayingEffect())
  154. // GameM.audioM.stopMateEffect();
  155. }
  156. update(dt) {
  157. this.FightTimerUpdate(dt);
  158. this.ExecuteBuff(dt);
  159. }
  160. UpdateRoleInfo() {
  161. cc.loader.loadRes('carPic/side/side_' + this.fightRole.lv, cc.SpriteFrame, (err, asset) => {
  162. this.roleImg.spriteFrame = asset;
  163. });
  164. //cc.loader.loadRes('carPic/head/head_' + this.fightRole.lv, cc.SpriteFrame, (err, asset) => {
  165. // this.headImg.spriteFrame = asset;
  166. //});
  167. this.roleImg.node.color = cc.Color.WHITE;
  168. this.txtName.string = this.fightRole.name;
  169. this.txtHeadLv.string = this.fightRole.lv + "";
  170. this.txtLv.string = "Lv" + this.fightRole.lv;
  171. //客户端功能 获取buff
  172. let cfg = GameM.commonData.fightRoleCfg[this.fightRole.lv.toString()];
  173. this.buffIds = cfg.buffbag_id;
  174. this.buffTriggerBloods = cfg.bufftrigger_bloods;
  175. this.curBuffTriggerIndex = 0;
  176. this.isWordsShowing = false;
  177. FightData.Ins.flawCurNum = 0;
  178. this.DiaplayLevelInfo();
  179. }
  180. /**显示武将星级相关信息*/
  181. DiaplayLevelInfo() {
  182. //星级
  183. for (let i = 0; i < this.stars.length; i++) {
  184. this.stars[i].active = false;
  185. //星级不显示
  186. //if (i + 1 <= this.fightRole.star) {
  187. // this.stars[i].active = true;
  188. //}
  189. }
  190. this.blood_white.fillRange = 1;
  191. this.blood.fillRange = 1;
  192. this.roleBlood = this.fightRole.blood;
  193. this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
  194. //获取武将buff 弃用 改在战斗中减血 获取并使用buff
  195. this.buff = GameM.commonData.buffCfg[this.fightRole.buffId.toString()];
  196. this.buffType = this.buff.buff_type;
  197. this.buffTimer = 0;
  198. this.buffHadTimer = 0;
  199. this.fightTimer = this.fightRole.fightTime;
  200. this.attackTimer = 0;
  201. this.blood.fillRange = this.roleBlood / this.fightRole.blood;
  202. this.txtTime.string = MyExtends.TimeToFormat(this.fightTimer) + "s";
  203. this.timeSlider.fillRange = 1;
  204. console.log("Role:", this.fightRole);
  205. //改用武将血量较少到相应值时 获取并生效
  206. //this.buffIsUsed = true;
  207. this.isCanAttack = true;
  208. this.isFighting = true;
  209. }
  210. /**buff计时器 或 buff效果执行*/
  211. ExecuteBuff(dt) {
  212. if (!this.isFighting || !this.buffIsUsed) return;
  213. if (this.buffType == 1) {
  214. //buff效果计时 效果执行 回血
  215. this.buffHadTimer += dt;
  216. if (this.roleBlood > 0 && this.roleBlood < this.fightRole.blood) {
  217. if (this.buffHadTimer < this.buff.effect.time) {
  218. this.buffTimer += dt;
  219. if (this.buffTimer >= 1) {
  220. this.buffTimer = 0;
  221. this.roleBlood += this.buff.effect.blood;
  222. if (this.roleBlood >= this.fightRole.blood) this.roleBlood = this.fightRole.blood;
  223. this.blood.fillRange = this.roleBlood / this.fightRole.blood;
  224. this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
  225. cc.Tween.stopAllByTarget(this.blood_white);
  226. this.blood_white.fillRange = this.blood.fillRange;
  227. }
  228. } else {
  229. this.buffIsUsed = false; //buff 回血 效果结束
  230. this.ani_getblood.node.active = false;
  231. //this.ani_getblood.setAnimation(0, "animation2", false);
  232. }
  233. }
  234. } else if (this.buffType == 2) {
  235. //buff效果计时
  236. this.buffHadTimer += dt;
  237. if (this.buffHadTimer > this.buff.effect.time) {
  238. this.buffIsUsed = false; //buff 坚甲 效果结束
  239. this.ani_defense.node.active = false;
  240. //this.ani_defense.setAnimation(0, "animation", false);
  241. }
  242. } else if (this.buffType == 3) {
  243. //buff效果计时
  244. this.buffHadTimer += dt;
  245. if (this.buffHadTimer > this.buff.effect.time) {
  246. this.buffIsUsed = false; //buff 闪避 效果结束
  247. }
  248. }
  249. }
  250. /**检测武将buff*/
  251. CheckRoleBuff() {
  252. if (!this.isFighting && this.curBuffTriggerIndex < this.buffTriggerBloods.length) return;
  253. if (this.roleBlood <= this.buffTriggerBloods[this.curBuffTriggerIndex] * 0.01 * this.fightRole.blood) {
  254. console.log("RoleBlood:" + this.roleBlood + " Trigger:" + this.buffTriggerBloods[this.curBuffTriggerIndex]);
  255. let curRoleBuffId = 1;
  256. let buffrandom = Random.Range(0, 100, false);
  257. let buffbag = GameM.commonData.buffbagCfg[this.buffIds[this.curBuffTriggerIndex].toString()];
  258. let temprate = 0;
  259. for (let i = 0; i < buffbag.buff_rate.length; i++) {
  260. temprate += buffbag.buff_rate[i];
  261. if (buffrandom <= temprate) {
  262. curRoleBuffId = buffbag.id[i];
  263. break;
  264. }
  265. }
  266. this.curBuffTriggerIndex++;
  267. //获取武将buff
  268. this.buff = GameM.commonData.buffCfg[curRoleBuffId.toString()];
  269. //this.buff = GameM.commonData.buffCfg["3"];
  270. this.buffType = this.buff.buff_type;
  271. this.buffTimer = 0;
  272. this.buffHadTimer = 0;
  273. console.log("__GetBuff:" + JSON.stringify(this.buff));
  274. //buff开始生效
  275. this.buffIsUsed = true;
  276. if (this.ani_defense.node.active)
  277. this.ani_defense.node.active = false;
  278. if (this.ani_getblood.node.active)
  279. this.ani_getblood.node.active = false;
  280. if (this.buffType == 1) {
  281. this.ani_getblood.node.active = true;
  282. this.ani_getblood.setAnimation(0, "animation2", true);
  283. } else if (this.buffType == 2) {
  284. this.ani_defense.node.active = true;
  285. this.ani_defense.setAnimation(0, "animation", true);
  286. } else if (this.buffType == 3) {
  287. //左右闪躲表现
  288. }
  289. }
  290. }
  291. /**检测武将遗言*/
  292. CheckRoleWords() {
  293. if (!this.isFighting || this.isWordsShowing) return;
  294. if (this.roleBlood <= 0.8 * this.fightRole.blood) {
  295. if (Random.Range(0, 100, false) <= 5) {
  296. this.ShowWords(1);
  297. }
  298. } else if (this.roleBlood <= 0.3 * this.fightRole.blood) {
  299. if (Random.Range(0, 100, false) <= 5) {
  300. this.ShowWords(2);
  301. }
  302. }
  303. }
  304. ShowWords(type: number) {
  305. this.wordsNode.stopAllActions();
  306. this.wordsNode.scale = 0;
  307. this.wordsNode.active = true;
  308. this.txtWords.string = FightData.Ins.GetWords(type);
  309. this.isWordsShowing = true;
  310. let a1 = cc.scaleTo(0.2, 1).easing(cc.easeBackOut());
  311. let a2 = cc.delayTime(2);
  312. let a3 = cc.callFunc(() => { this.wordsNode.active = false; this.isWordsShowing = false; });
  313. this.wordsNode.runAction(cc.sequence(a1, a2, a3));
  314. }
  315. /**战斗计时器*/
  316. FightTimerUpdate(dt) {
  317. if (this.isFighting) {
  318. this.FightTimer(dt);
  319. if (!this.isCanAttack) {
  320. this.attackTimer += dt;
  321. if (this.attackTimer >= this.attackTime) {
  322. this.isCanAttack = true;
  323. this.attackTimer = 0;
  324. }
  325. }
  326. }
  327. }
  328. FightTimer(time) {
  329. this.fightTimer -= time;
  330. if (this.fightTimer <= 0) this.fightTimer = 0;
  331. //console.log("Timer:" + this.fightTimer);
  332. this.txtTime.string = MyExtends.TimeToFormat(this.fightTimer);
  333. this.timeSlider.fillRange = this.fightTimer / this.fightRole.fightTime;
  334. if (this.fightTimer <= 0) {
  335. this.isFighting = false;
  336. this.txtTime.string = "00:00";
  337. //战斗结束
  338. console.log("战斗结束");
  339. this.FightResult(false);
  340. }
  341. }
  342. /**获取最终伤害 播放boss受击动画 使用buff buffType = 1 自动在update中执行*/
  343. GetDamage(attackDamage: number) {
  344. //buff效果执行
  345. let damage = attackDamage;
  346. //先计算是否受到暴击伤害
  347. //悟空天赋2
  348. //damage = Random.Range(0, 100) < MateData.Ins.Mate2Talent2 ? damage * 2 : damage;
  349. if (Random.Range(0, 100) < MateData.Ins.Mate2Talent2) {
  350. damage *= 2;
  351. this.PlayBuffEffect(1);
  352. this.txtDamage.node.color = cc.color(255, 0, 0);
  353. this.PlayBossAni(1);
  354. } else {
  355. //damage *= 2;
  356. this.txtDamage.node.color = cc.color(255, 230, 0);
  357. //this.PlayBossAni(0);
  358. }
  359. if (this.buffIsUsed) {
  360. if (this.buffType == 2) {
  361. damage *= 0.5; //坚甲 抵抗 伤害减半
  362. this.PlayBuffEffect(2);
  363. GameM.audioM.playEffect(AUDIO_TYPE.resist);
  364. EffectNode.instance.PlayTip("武将防御中,挑战时间-3秒,请暂停攻击!");
  365. this.FightTimer(3);
  366. } else if (this.buffType == 3) { //矫健 闪避 概率触发闪避
  367. if (Random.Range(0, 100, false) <= this.buff.effect.rate) {
  368. damage = 0;
  369. this.PlayBuffEffect(3);
  370. this.PlayBossAni(2);
  371. GameM.audioM.playEffect(AUDIO_TYPE.dodge);
  372. } else {
  373. this.PlayBossAni(0);
  374. }
  375. } else {
  376. this.PlayBossAni(0);
  377. }
  378. } else {
  379. this.PlayBossAni(0);
  380. }
  381. return Math.floor(damage);
  382. //return damage;
  383. }
  384. /**伤害动画*/
  385. PlayDamageAni(num: number) {
  386. this.txtDamage.string = "-" + num;
  387. //this.txtDamage.node.active = true;
  388. this.txtDamage.node.setPosition(this.damageInitPos);
  389. this.txtDamage.node.scale = 0.5;
  390. let copy = cc.instantiate(this.txtDamage.node);
  391. this.canvas.addChild(copy);
  392. copy.active = true;
  393. //this.panelNode.addChild(copy);
  394. let a1 = cc.spawn(cc.scaleTo(0.5, 1.5), cc.moveTo(0.5, cc.v2(this.damageInitPos.x + 110, this.damageInitPos.y + 150)));
  395. let a2 = cc.fadeOut(0.5);
  396. let a3 = cc.callFunc(() => { copy.destroy() });
  397. copy.runAction(cc.sequence(a1, a2, a3));
  398. //this.roleImg.node.color=cc.Color.RED;
  399. //this.roleImg.node.stopAllActions();
  400. //this.roleImg.node.runAction(cc.sequence(cc.tintTo(0.2, 255, 0, 0), cc.tintTo(0.2, 255, 255, 255)));
  401. }
  402. /**Buff效果 1 暴击 2 抵抗 3 闪避*/
  403. async PlayBuffEffect(type: number) {
  404. let temp: cc.Node = null;;
  405. if (type == 1) {
  406. temp = cc.instantiate(this.damageCrit);
  407. }
  408. else if (type == 2) {
  409. temp = cc.instantiate(this.damageResist);
  410. }
  411. else if (type == 3) {
  412. temp = cc.instantiate(this.damageDodge);
  413. }
  414. this.canvas.addChild(temp);
  415. temp.active = true;
  416. await Time.WaitForSeconds(1);
  417. temp.destroy();
  418. }
  419. /**
  420. * 播放Boss反馈动画
  421. * @param type 动画类型 0 普通 1 暴击 2 闪避
  422. */
  423. PlayBossAni(type: number) {
  424. if (type == 0) {
  425. cc.Tween.stopAllByTarget(this.roleImg.node);
  426. this.roleImg.node.setPosition(0, this.roleImg.node.y);
  427. cc.tween(this.roleImg.node)
  428. .to(0.05, { scale: 1.3, color: cc.color(255, 0, 0) })
  429. .to(0.05, { scale: 1.1, color: cc.color(255, 255, 255) })
  430. .start();
  431. } else if (type == 1) {
  432. this.PlayCritAni();
  433. } else if (type == 2) {
  434. this.PlayDodgeAni();
  435. }
  436. }
  437. /**
  438. * 战斗结果
  439. * @param isSuccess 是否战斗胜利
  440. */
  441. FightResult(isSuccess: boolean) {
  442. let result = new FightResult();
  443. result.fightType = this.fightRole.fightType;
  444. result.lv = this.fightRole.lv;
  445. if (isSuccess) {
  446. result.result = 1;
  447. console.log("FinishBattle");
  448. let param = {
  449. battleId: this.fightRole.fightId,
  450. battleResult: result.result,
  451. battleSeconds: this.fightRole.fightTime - this.fightTimer,
  452. battleType: this.fightRole.fightType,
  453. bossCode: this.fightRole.lv,
  454. version: GameM.commonData.version
  455. };
  456. if (this.fightRole.fightType == 1 || this.fightRole.fightType == 2) {
  457. HttpM.Instance.SendData(HTTP_TYPE.finishBattle
  458. , param, (res) => {
  459. //LogUtil.logV("-->FightFinished:", JSON.stringify(res));
  460. console.log("-->FightFinished:", res);
  461. if (res.data != null) {
  462. result.rewards = res.data.awards;
  463. result.talent = res.data.stone != null ? res.data.stone : 0;
  464. result.star = res.data.star_level;
  465. result.unlock_mateid = res.data.partner_id;
  466. result.reward_times = this.fightRole.fightType == 1 ? 0 : res.data.todayTimes;
  467. result.fightId = this.fightRole.fightId;
  468. //FightData.Ins.rewardTimes = res.data.todayTimes;
  469. //if (this.fightRole.fightType)
  470. MyExtends.WaitTimeForCallback(0.5, () => {
  471. this.OnExit();
  472. UIMng.Ins.AsyncGetPanel(PanelType.FightResultPanel, (panel) => {
  473. panel.OnEnter(result);
  474. });
  475. //UIMng.Ins.GetPanel(PanelType.FightResultPanel).OnEnter(result);
  476. //调用结算接口 服务器自动处理
  477. //移除服务器武将队列对应武将数据
  478. //if (this.fightRole.fightType == 1) {
  479. // FightData.Ins.RemoveRole(this.fightRole.arrayIndex);
  480. //}
  481. });
  482. } else {
  483. console.log("error:" + res.errmsg);
  484. }
  485. }, null, null, true);
  486. } else {
  487. //大富翁战斗结果
  488. HttpM.Instance.SendData(HTTP_TYPE.richManBossReward, { type: RichData.Ins.masterType }, (res) => {
  489. console.log("--->boss rewards:", res);
  490. if (res.data != null) {
  491. result.rewards = res.data.rewardsInfo;
  492. result.talent = 0;
  493. //战斗三 大富翁战斗 默认显示最高级宝箱)
  494. result.star = 3;
  495. result.unlock_mateid = "";
  496. result.reward_times = 0;
  497. result.fightId = "";
  498. //FightData.Ins.rewardTimes = res.data.todayTimes;
  499. //if (this.fightRole.fightType)
  500. MyExtends.WaitTimeForCallback(0.5, () => {
  501. this.OnExit();
  502. UIMng.Ins.AsyncGetPanel(PanelType.FightResultPanel, (panel) => {
  503. panel.OnEnter(result);
  504. });
  505. //UIMng.Ins.GetPanel(PanelType.FightResultPanel).OnEnter(result);
  506. //调用结算接口 服务器自动处理
  507. //移除服务器武将队列对应武将数据
  508. //if (this.fightRole.fightType == 1) {
  509. // FightData.Ins.RemoveRole(this.fightRole.arrayIndex);
  510. //}
  511. });
  512. } else {
  513. console.log("error:" + res.errmsg);
  514. }
  515. }, null, null, null, false);
  516. }
  517. //result.rewardId = this.fightRole.rewardId;
  518. } else {
  519. result.result = 0;
  520. result.talent = 0;
  521. result.star = 1;
  522. result.unlock_mateid = null;
  523. result.reward_times = 0;
  524. result.fightId = this.fightRole.fightId;
  525. //result.rewardId = this.fightRole.rewardId;
  526. MyExtends.WaitTimeForCallback(0.5, () => {
  527. this.OnExit();
  528. UIMng.Ins.AsyncGetPanel(PanelType.FightResultPanel, (panel) => {
  529. panel.OnEnter(result);
  530. });
  531. //UIMng.Ins.GetPanel(PanelType.FightResultPanel).OnEnter(result);
  532. //调用结算接口 服务器自动处理
  533. //移除服务器武将队列对应武将数据
  534. //if (this.fightRole.fightType == 1) {
  535. // FightData.Ins.RemoveRole(this.fightRole.arrayIndex);
  536. //}
  537. });
  538. }
  539. }
  540. PlayDodgeAni() {
  541. this.roleImg.node.stopAllActions();
  542. let pos = this.roleInitPos;
  543. this.roleImg.node.runAction(
  544. cc.sequence(
  545. cc.moveTo(0.04, cc.v2(pos.x + -80, pos.y)),
  546. cc.moveTo(0.08, cc.v2(pos.x + 80, pos.y)),
  547. cc.moveTo(0.04, cc.v2(pos.x, pos.y))
  548. )
  549. );
  550. }
  551. PlayCritAni() {
  552. this.roleImg.node.stopAllActions();
  553. let pos = this.roleInitPos;
  554. GameController.Ins.PlayShock(this.roleImg.node, pos);
  555. //this.roleImg.node.runAction(
  556. // //cc.repeatForever(
  557. // cc.sequence(
  558. // cc.moveTo(0.02, cc.v2(pos.x + 5, pos.y + 7)),
  559. // cc.moveTo(0.02, cc.v2(pos.x + -6, pos.y + 7)),
  560. // cc.moveTo(0.02, cc.v2(pos.x + -13, pos.y + 3)),
  561. // cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + -6)),
  562. // cc.moveTo(0.02, cc.v2(pos.x + -5, pos.y + 5)),
  563. // cc.moveTo(0.02, cc.v2(pos.x + 2, pos.y + -8)),
  564. // cc.moveTo(0.02, cc.v2(pos.x + -8, pos.y + -10)),
  565. // cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + 10)),
  566. // cc.moveTo(0.02, cc.v2(pos.x + 0, pos.y + 0))
  567. // )
  568. // //)
  569. //);
  570. }
  571. async CheckTriggerFlaw() {
  572. //let rate=Random.Range(0, 100, false);
  573. //console.log("---Rate:"+rate);
  574. if (Random.Range(0, 100, false) < FightData.Ins.flawRate && FightData.Ins.flawCurNum < FightData.Ins.flawNum) {
  575. FightData.Ins.flawCurNum++;
  576. let copy: cc.Node = cc.instantiate(await Utils.loadResPromise("prefabs/Flaw"));
  577. copy.scale = 0;
  578. copy.parent = this.node;
  579. let dir = cc.v2(Random.Range(-1, 1, false), Random.Range(-1, 1, false));
  580. dir = dir.normalize();
  581. let deltaInit = cc.v2(Random.Range(180, 220, false) * dir.x, Random.Range(180, 220, false) * dir.y);
  582. let initPos = cc.v2(this.roleImg.node.x, this.roleImg.node.y + 200).add(deltaInit);
  583. //let pos=cc.v2(this.roleImg.node.x, this.roleImg.node.y + 200).normalize();
  584. //cc.Vec2.normalize(pos,cc.v2(this.roleImg.node.x, this.roleImg.node.y + 200));
  585. copy.setPosition(this.roleImg.node.x, this.roleImg.node.y + 200);
  586. //copy.setPosition(pos);
  587. //let b = cc.repeatForever(
  588. // cc.sequence(
  589. // cc.moveBy(0.5, cc.v2(0, 20)),
  590. // cc.moveBy(0.5, cc.v2(0, -20))
  591. // )
  592. //);
  593. let a1 = cc.spawn(
  594. //cc.jumpTo(0.2, cc.v2(Random.Range(-280, 280), 320), 200, 1),
  595. cc.jumpTo(0.2, initPos, 200, 1),
  596. cc.scaleTo(0.2, 1)
  597. )
  598. //let a2 = cc.callFunc(() => {
  599. // copy.runAction(b);
  600. //}, this);
  601. //copy.runAction(cc.sequence(a1, a2));
  602. copy.runAction(a1);
  603. //this.transitNode = copy.getComponent(TransitNode);
  604. }
  605. }
  606. /**使用破绽技能
  607. * @param blood 扣除的血量
  608. */
  609. UseFlawEffect(num: number) {
  610. let blood = Math.floor(num * Random.Range(2, 5, false) * (Random.Range(15, 21) + MateData.Ins.Mate2Talent1));
  611. this.roleBlood -= blood;
  612. if (this.roleBlood <= 0) {
  613. this.roleBlood = 0;
  614. console.log("战斗胜利");
  615. this.isFighting = false;
  616. this.FightResult(true);
  617. }
  618. this.blood.fillRange = this.roleBlood / this.fightRole.blood;
  619. this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
  620. cc.tween(this.blood_white).to(0.2, { fillRange: this.blood.fillRange }).start();
  621. GameController.Ins.PlayShock(this.node, cc.v2(0, 0));
  622. this.flawEft.active = false;
  623. this.flawTxt.string = "-" + blood;
  624. let eft = cc.instantiate(this.flawEft);
  625. eft.active = true;
  626. eft.parent = this.node;
  627. eft.setPosition(0, 170);
  628. let a = cc.moveTo(0.5, cc.v2(0, 350));
  629. let b1 = cc.delayTime(1);
  630. let b2 = cc.fadeOut(0.1);
  631. let b3 = cc.callFunc(() => { eft.destroy(); });
  632. let b = cc.sequence(b1, b2, b3);
  633. eft.runAction(cc.spawn(a, b));
  634. GameM.audioM.playEffect(AUDIO_TYPE.flaw);
  635. GameController.Ins.Shock(300);
  636. }
  637. /**点击屏幕攻击武将*/
  638. OnTouchAttak() {
  639. //console.log("attack role");
  640. if (!this.isFighting) return;
  641. if (this.isCanAttack) {
  642. this.isCanAttack = false;
  643. //悟空天赋1
  644. let tempDamage = Random.Range(15, 21) + MateData.Ins.Mate2Talent1;
  645. //let tempDamage = Random.Range(3, 5) + MateData.Ins.Mate2Talent1;
  646. //let damage = this.GetDamage(20);
  647. let damage = this.GetDamage(tempDamage);
  648. if (damage == 0) {
  649. //console.log("闪避");
  650. //this.PlayDodgeAni();
  651. } else {
  652. this.roleBlood -= damage;
  653. this.PlayDamageAni(damage);
  654. if (this.roleBlood <= 0) {
  655. this.roleBlood = 0;
  656. //console.log("战斗胜利");
  657. this.isFighting = false;
  658. this.FightResult(true);
  659. //判断fightRole.fightType = 1 的话 将该武将从队列中移除
  660. } else {
  661. //检测buff
  662. this.CheckRoleBuff();
  663. this.CheckRoleWords();
  664. this.CheckTriggerFlaw();
  665. }
  666. }
  667. this.blood.fillRange = this.roleBlood / this.fightRole.blood;
  668. this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
  669. cc.tween(this.blood_white).to(0.2, { fillRange: this.blood.fillRange }).start();
  670. if (Random.GetBool()) {
  671. GameM.audioM.playEffect(AUDIO_TYPE.attack1);
  672. } else {
  673. GameM.audioM.playEffect(AUDIO_TYPE.attack2);
  674. }
  675. let eftpos = cc.v2(Random.Range(-180, 180), Random.Range(-180, 180));
  676. this.attack.node.setPosition(eftpos);
  677. this.attack.node.scale = Random.Range(0.5, 1.3, false);
  678. this.attack.clearTrack(0);
  679. this.attack.setAnimation(0, "animation", false);
  680. //let type = Random.Range(1, 4);
  681. //if (type == 1) {
  682. // this.attack.setAnimation(0, "animation", false);
  683. //} else if (type == 2) {
  684. // this.attack.setAnimation(0, "animation2", false);
  685. //} else {
  686. // this.attack.setAnimation(0, "animation3", false);
  687. //}
  688. GameController.Ins.Shock(50);
  689. }
  690. }
  691. Click_CloseBtn() {
  692. this.isFighting = false;
  693. this.OnExit();
  694. }
  695. }