EquipQH.ts 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. import i18n from "../../../i18n/i18n";
  2. import { AudioMgr } from "../../../main/ViewManage";
  3. import ViewObject from "../../../main/ViewObject";
  4. import { HttpStateType, ReveData } from "../../../util/CHttp";
  5. import GoodItem from "../../common/GoodItem";
  6. import PetIcon from "../../common/PetIcon";
  7. import FFCalAttr from "../../data/FFCalAttr";
  8. import { __EquipQHData } from "../../data/sdata/SManage";
  9. import { EquipAttr } from "../../data/udata/Player";
  10. import Equip from "./Equip";
  11. import EquipQHAttrItem from "./EquipQHAttrItem";
  12. import EquipQHMax from "./EquipQHMax";
  13. import EquipStar from "./EquipStar";
  14. /**
  15. * 装备强化
  16. */
  17. const { ccclass, property } = cc._decorator;
  18. @ccclass
  19. export default class EquipQH extends ViewObject {
  20. @property(GoodItem)
  21. mEquipItem: GoodItem = null;
  22. @property(cc.Label)
  23. mEquipName: cc.Label = null;//名字
  24. @property(cc.Node)
  25. mContent: cc.Node = null;//背包容器
  26. @property(cc.Prefab)
  27. mGoodItem: cc.Prefab = null;//道具节点
  28. @property(cc.Label)
  29. mQHLevel: cc.Label = null;//强化等级
  30. @property(cc.Label)
  31. mQHBfbLabel: cc.Label = null;//强化百分比
  32. @property(cc.ProgressBar)
  33. mQHBfbBar: cc.ProgressBar = null;//强化百分比
  34. @property(cc.Label)
  35. mQHMoney: cc.Label = null;//强化消耗的货币
  36. @property(cc.Node)
  37. mXhContent: cc.Node = null;//消耗容器
  38. @property(cc.Node)
  39. mBtSort: cc.Node = null;//排序按钮面板
  40. @property(cc.Node)
  41. mQHFull: cc.Node = null;//强化满级后显示
  42. @property(cc.Node)
  43. mFullWord: cc.Node = null;//满级后文字提示
  44. @property([EquipQHAttrItem])
  45. mQHAttrs: Array<EquipQHAttrItem> = [];//强化前后属性
  46. @property(cc.Node)
  47. mOneKeyBt: cc.Node = null;//一键放入按钮
  48. @property(cc.Node)
  49. QHBtnNode: cc.Node = null;
  50. @property(sp.Skeleton) // 强化动画
  51. spine1: sp.Skeleton = null;
  52. @property(sp.Skeleton)
  53. spine2: sp.Skeleton = null;
  54. /**
  55. * 装备界面
  56. */
  57. private equip: Equip = null;
  58. /**
  59. * 当前选中的伙伴
  60. */
  61. private petIcon: PetIcon = null;
  62. /**
  63. * 当前强化的装备
  64. */
  65. // private goodItem: GoodItem = null;
  66. /**
  67. * 当前选中的道具
  68. */
  69. private curGoodItem: Array<GoodItem> = []
  70. /**
  71. * 一键快捷回调
  72. */
  73. private oneKeyCallback: () => void;
  74. /**
  75. * 排序按钮回调
  76. */
  77. private sortCallback: (type: number) => void;
  78. public inGuide = false;//是否引导中
  79. public guideStep: number = 0; //指引步骤
  80. public qhType: number = 0; // 0 强化装备上的装备 1 强化背包的装备
  81. public equipAttr: EquipAttr = null;
  82. onLoad() {
  83. this.mBtSort.active = false
  84. }
  85. public init(equipAttr: EquipAttr, petIcon: PetIcon, equip: Equip) {
  86. this.qhType = 0;
  87. this.equip = equip
  88. this.petIcon = petIcon
  89. this.equipAttr = equipAttr
  90. this.mEquipItem.initEquip(this.main, equipAttr)
  91. this.mEquipName.string = i18n.t(this.main.sManage.getEquipById(equipAttr.id).name)
  92. for (let i = 0; i < 20; i++) {
  93. let node = cc.instantiate(this.mGoodItem);
  94. node.parent = this.mContent;
  95. }
  96. for (let i = 0; i < 10; i++) {
  97. let node = cc.instantiate(this.mGoodItem);
  98. node.parent = this.mXhContent;
  99. }
  100. this.checkToggle()
  101. this.node.getComponent(EquipQHMax).init(this.equip, petIcon, equipAttr)
  102. this.node.getComponent(EquipStar).init(this.equip, petIcon, equipAttr)
  103. this.scheduleOnce(() => {
  104. if (this.inGuide) {
  105. if (this.guideStep == 1) {
  106. this.onGuide_1();
  107. }
  108. }
  109. }, 0.1);
  110. }
  111. /**
  112. * 选择当前页卡
  113. */
  114. public checkToggle() {
  115. let scrollView = this.mContent.parent.parent.getComponent(cc.ScrollView)
  116. scrollView.stopAutoScroll()
  117. scrollView.scrollToTop()
  118. this.mEquipItem.flushEquip(this.main)
  119. this.curGoodItem = []
  120. this.flushEquipPag();
  121. this.flushXH()
  122. this.setOneKeyCallback(() => {
  123. this.oneKeyPush()
  124. })
  125. this.setSortCallback((type: number) => {
  126. if (type == 0) {//品质排序
  127. EquipQH.sortPag(0, this.mContent)
  128. } else {//战力排序
  129. EquipQH.sortPag(1, this.mContent)
  130. }
  131. })
  132. }
  133. /**
  134. * 刷新属性
  135. */
  136. private flushAttr(PI) {
  137. let equipData = this.main.sManage.getEquipById(this.equipAttr.id);
  138. let __qhList = this.main.sManage.getEquipQHByType(equipData)
  139. //当前等级
  140. let curQHLevel = FFCalAttr.getEquipQHLevel(this.main, this.equipAttr.PI, equipData)
  141. //目标等级
  142. let qhLevel = FFCalAttr.getEquipQHLevel(this.main, PI, equipData)
  143. let maxQH = equipData.level + this.equipAttr.qhMax * 5;
  144. if (qhLevel >= maxQH) {//满级
  145. this.mQHFull.active = true
  146. qhLevel = maxQH
  147. } else {
  148. this.mQHFull.active = false
  149. }
  150. if (curQHLevel >= maxQH) {
  151. this.mOneKeyBt.active = false
  152. } else {
  153. this.mOneKeyBt.active = true
  154. }
  155. if (this.curGoodItem.length >= 10) {
  156. this.mQHFull.active = true
  157. this.mOneKeyBt.children[0].getComponent(cc.Label).string = '一键卸下'
  158. } else {
  159. this.mOneKeyBt.children[0].getComponent(cc.Label).string = '一键放入'
  160. }
  161. let tempAttrExp = 0
  162. let _qhAttr1: __EquipQHData = null //当前属性
  163. let _qhAttr2: __EquipQHData = null //目标属性
  164. let _qhAttr3: __EquipQHData = null //升级属性
  165. if (curQHLevel > 0) {
  166. _qhAttr1 = __qhList[curQHLevel - 1]
  167. tempAttrExp = _qhAttr1.exp
  168. }
  169. if (qhLevel > 0) {
  170. _qhAttr2 = __qhList[qhLevel - 1]
  171. tempAttrExp = _qhAttr2.exp
  172. }
  173. if (qhLevel >= __qhList.length) {
  174. _qhAttr3 = __qhList[qhLevel - 1]
  175. } else {
  176. _qhAttr3 = __qhList[qhLevel]
  177. }
  178. let tmpAdd = qhLevel - curQHLevel
  179. if (tmpAdd > 0) {
  180. this.mQHLevel.string = 'Lv.' + qhLevel + '/' + maxQH + '(+' + (tmpAdd) + ')';
  181. } else {
  182. this.mQHLevel.string = 'Lv.' + qhLevel + '/' + maxQH;
  183. }
  184. let curExp = PI - tempAttrExp
  185. let uplevelExp = _qhAttr3.exp - tempAttrExp
  186. let bfb = curExp / uplevelExp;
  187. if (bfb > 1) {
  188. bfb = 1
  189. }
  190. this.mQHBfbBar.progress = bfb
  191. this.mQHBfbLabel.string = Math.floor(bfb * 100) + '%'
  192. if (curQHLevel >= maxQH) {
  193. this.mFullWord.active = true
  194. } else {
  195. this.mFullWord.active = false
  196. }
  197. let tempEquipAttr = FFCalAttr.getEquipAttr(this.main, this.equipAttr, equipData)
  198. let equipAttr1 = cc.instantiate(this.equipAttr)
  199. equipAttr1.PI = PI
  200. let tempEquipAttr1 = FFCalAttr.getEquipAttr(this.main, equipAttr1, equipData)
  201. let atk1 = tempEquipAttr.atk
  202. let def1 = tempEquipAttr.def
  203. let hp1 = tempEquipAttr.hp
  204. let sd1 = tempEquipAttr.sp
  205. let atk2 = tempEquipAttr1.atk
  206. let def2 = tempEquipAttr1.def
  207. let hp2 = tempEquipAttr1.hp
  208. let sd2 = tempEquipAttr1.sp
  209. let arr1 = [atk1, def1, hp1, sd1]
  210. let arr2 = [atk2, def2, hp2, sd2]
  211. let index = 0
  212. for (let i = 0; i < 4; i++) {
  213. let v1 = arr1[i]
  214. let v2 = arr2[i]
  215. if (v1 > 0) {
  216. const element = this.mQHAttrs[index];
  217. element.setAttr(i, v1, v2)
  218. index++
  219. }
  220. }
  221. for (let i = index; i < this.mQHAttrs.length; i++) {
  222. const element = this.mQHAttrs[i];
  223. element.node.active = false
  224. }
  225. }
  226. /**
  227. * 刷新装备背包
  228. */
  229. public flushEquipPag() {
  230. let equip = this.main.player.equip;
  231. let index = 0;
  232. let content = this.mContent;
  233. for (let i = 0; i < equip.length; i++) {
  234. const element = equip[i];
  235. let equipData = this.main.sManage.getEquipById(element.id);
  236. if (equipData.type != 5 && equipData.type != 6 && equipData.type != 11) {
  237. if (this.mEquipItem.equip.__index != element.__index) {
  238. if (index >= content.children.length) {
  239. this.addGoodItem(content);
  240. }
  241. let node = content.children[index];
  242. node.opacity = 255
  243. let equipItem = node.getComponent(GoodItem);
  244. equipItem.initEquip(this.main, element);
  245. if (element.id >= 10000 && element.id < 20000) {
  246. node.zIndex = 0
  247. } else {
  248. let zdl = FFCalAttr.getZdl(equipItem.equipData)
  249. if (zdl > cc.macro.MAX_ZINDEX - 2) {
  250. zdl = cc.macro.MAX_ZINDEX - 2
  251. }
  252. node.zIndex = zdl
  253. }
  254. equipItem.setCallback((gi) => {
  255. this.main.playerEffectByPath(AudioMgr.qh2);
  256. this.addEquip(gi);
  257. this.guideCallback && this.guideCallback();
  258. });
  259. index++;
  260. } else {
  261. this.qhType = 1;
  262. }
  263. }
  264. }
  265. for (let i = index; i < content.children.length; i++) {
  266. let node = content.children[i];
  267. node.opacity = 255
  268. let equipItem = node.getComponent(GoodItem);
  269. equipItem.setNull();
  270. node.zIndex = cc.macro.MAX_ZINDEX - 1
  271. }
  272. }
  273. private addGoodItem(content: cc.Node) {
  274. for (let i = 0; i < 4; i++) {
  275. let node = cc.instantiate(this.mGoodItem);
  276. node.parent = content;
  277. }
  278. }
  279. public setOneKeyCallback(oneKeyCallback: () => void) {
  280. this.oneKeyCallback = oneKeyCallback
  281. }
  282. /**
  283. * 一键放入
  284. */
  285. private oneKeyPush() {
  286. if (this.curGoodItem.length >= 10) {
  287. for (let i = 0; i < this.curGoodItem.length; i++) {
  288. const element = this.curGoodItem[i]
  289. element.node.opacity = 255
  290. }
  291. this.curGoodItem = []
  292. } else {
  293. for (let i = 0; i < this.curGoodItem.length; i++) {
  294. const element = this.curGoodItem[i]
  295. element.node.opacity = 255
  296. }
  297. this.curGoodItem = []
  298. let exp = 0
  299. for (let i = 0; i < 10; i++) {
  300. if (i >= this.mContent.children.length) {
  301. break
  302. }
  303. const node = this.mContent.children[i];
  304. let equipItem = node.getComponent(GoodItem);
  305. if (equipItem.equip) {
  306. equipItem.node.opacity = 100
  307. exp += equipItem.equipData.qh_exp
  308. exp += equipItem.equip.PI
  309. let PI = this.equipAttr.PI + exp
  310. this.curGoodItem.push(equipItem)
  311. let qhLevel = FFCalAttr.getEquipQHLevel(this.main, PI, this.main.sManage.getEquipById(this.equipAttr.id))
  312. let maxQH = this.main.sManage.getEquipById(this.equipAttr.id).level + this.equipAttr.qhMax * 5
  313. if (qhLevel >= maxQH) {
  314. break
  315. }
  316. }
  317. }
  318. }
  319. this.flushXH()
  320. }
  321. private onclickOneKey() {
  322. if (this.oneKeyCallback) {
  323. this.oneKeyCallback()
  324. }
  325. }
  326. /**
  327. * 背包中的装备添加到消耗材料
  328. * @param goodItem
  329. */
  330. private addEquip(goodItem: GoodItem) {
  331. if (goodItem.node.opacity == 100) {
  332. return
  333. }
  334. if (this.curGoodItem.length >= 10) {
  335. this.main.showTips(i18n.t('消耗材料以满'))
  336. } else {
  337. goodItem.node.opacity = 100
  338. this.curGoodItem.push(goodItem)
  339. this.flushXH()
  340. }
  341. }
  342. private removeEquip(goodItem: GoodItem) {
  343. for (let i = 0; i < this.curGoodItem.length; i++) {
  344. const element = this.curGoodItem[i];
  345. if (element.equip.__index == goodItem.equip.__index) {
  346. element.node.opacity = 255
  347. this.curGoodItem.splice(i, 1)
  348. break
  349. }
  350. }
  351. this.flushXH()
  352. }
  353. private flushXH() {
  354. let exp = 0
  355. for (let i = 0; i < this.mXhContent.children.length; i++) {
  356. const node = this.mXhContent.children[i];
  357. let tmpItem = node.getComponent(GoodItem)
  358. if (i < this.curGoodItem.length) {
  359. let goodItem = this.curGoodItem[i]
  360. tmpItem.initEquip(this.main, goodItem.equip)
  361. tmpItem.setCallback((gItem: GoodItem) => {
  362. this.removeEquip(gItem)
  363. })
  364. exp += goodItem.equipData.qh_exp
  365. exp += goodItem.equip.PI
  366. } else {
  367. tmpItem.setNull()
  368. }
  369. }
  370. this.mQHMoney.string = '' + exp * 5
  371. let PI = this.equipAttr.PI + exp
  372. this.flushAttr(PI)
  373. }
  374. /**
  375. * 排序按钮
  376. */
  377. private onclickSort() {
  378. this.mBtSort.active = !this.mBtSort.active
  379. }
  380. public setSortCallback(sortCallback: (type: number) => void) {
  381. this.sortCallback = sortCallback
  382. }
  383. public static sortPag(type, content: cc.Node) {
  384. for (let i = 0; i < content.children.length; i++) {
  385. let node = content.children[i];
  386. let equipItem = node.getComponent(GoodItem);
  387. if (equipItem.equip) {
  388. if (equipItem.equipData.id == 20001) {
  389. node.zIndex = 0
  390. } else if (equipItem.equipData.id >= 10000 && equipItem.equipData.id < 20000) {
  391. node.zIndex = 0
  392. } else {
  393. if (type == 0) {
  394. node.zIndex = equipItem.equipData.pz
  395. } else {
  396. let zdl = FFCalAttr.getZdl(equipItem.equipData)
  397. if (zdl > cc.macro.MAX_ZINDEX - 2) {
  398. zdl = cc.macro.MAX_ZINDEX - 2
  399. }
  400. node.zIndex = zdl
  401. }
  402. }
  403. } else {
  404. node.zIndex = cc.macro.MAX_ZINDEX - 1
  405. }
  406. }
  407. }
  408. private onclickStarSort() {
  409. this.mBtSort.active = false
  410. this.sortCallback(0)
  411. }
  412. private onclickZdlSort() {
  413. this.mBtSort.active = false
  414. this.sortCallback(1)
  415. }
  416. /**
  417. * 强化按钮
  418. */
  419. private onclickQHSend() {
  420. if (this.qhType == 0) {
  421. this.QHFcun();
  422. } else if (this.qhType == 1) {
  423. this.QHFcun1();
  424. }
  425. }
  426. QHFcun() {
  427. let removeEquips = []
  428. for (let i = 0; i < this.curGoodItem.length; i++) {
  429. const element = this.curGoodItem[i];
  430. removeEquips.push(element.equip.__index)
  431. }
  432. if (removeEquips.length == 0) {
  433. this.main.showTips("没有添加任何材料");
  434. return
  435. }
  436. let msg = {
  437. petId: this.petIcon.id,
  438. equipId: this.equipAttr.id,
  439. equips: removeEquips
  440. }
  441. this.main.gameHttp.sendJson('equip/v1/qh', msg, (state, reve: ReveData) => {
  442. this.main.stopLoad();
  443. if (state == HttpStateType.SUCCESS) {
  444. if (reve.retCode == 0) {
  445. this.playQHSpine();
  446. this.main.playerEffectByPath(AudioMgr.qh);
  447. this.equipAttr.PI = reve.data.PI
  448. this.curGoodItem = []
  449. this.mEquipItem.flushEquip(this.main);
  450. this.flushEquipPag()
  451. this.equip.flushEquip(this.petIcon)
  452. this.equip.flushPagSize()
  453. this.flushXH()
  454. if (this.inGuide) {
  455. if (this.guideStep == 1) {
  456. this.onGuideExit();
  457. }
  458. }
  459. this.main.showTips('强化成功');
  460. } else {
  461. this.main.showTips(reve.message);
  462. if (this.inGuide) {
  463. if (this.guideStep == 1) {
  464. this.onGuideExit();
  465. }
  466. }
  467. }
  468. } else {
  469. this.main.showTips('网络异常');
  470. }
  471. });
  472. }
  473. QHFcun1() {
  474. let removeEquips = []
  475. for (let i = 0; i < this.curGoodItem.length; i++) {
  476. const element = this.curGoodItem[i];
  477. removeEquips.push(element.equip.__index)
  478. }
  479. if (removeEquips.length == 0) {
  480. this.main.showTips("没有添加任何材料");
  481. return
  482. }
  483. let msg = {
  484. equipIndex: this.mEquipItem.equip.__index,
  485. equips: removeEquips
  486. }
  487. this.main.gameHttp.sendJson('equip/v1/qh1', msg, (state, reve: ReveData) => {
  488. this.main.stopLoad();
  489. if (state == HttpStateType.SUCCESS) {
  490. if (reve.retCode == 0) {
  491. this.playQHSpine();
  492. this.main.playerEffectByPath(AudioMgr.qh);
  493. this.equipAttr.PI = reve.data.PI
  494. this.curGoodItem = []
  495. this.mEquipItem.flushEquip(this.main);
  496. this.equip.mEquipPack.setEquipType(this.equip.curPage);
  497. this.flushEquipPag()
  498. this.equip.flushEquip(this.petIcon)
  499. this.equip.flushPagSize()
  500. this.flushXH()
  501. this.main.showTips('强化成功');
  502. } else {
  503. this.main.showTips(reve.message);
  504. }
  505. } else {
  506. this.main.showTips('网络异常');
  507. }
  508. });
  509. }
  510. playQHSpine() {
  511. this.spine1.setAnimation(0, "atk", false);
  512. this.spine1.setCompleteListener(() => {
  513. this.spine1.setAnimation(0, "idle", false);
  514. this.spine2.node.active = true;
  515. this.spine2.setAnimation(0, "animation", false);
  516. this.spine2.setCompleteListener(() => {
  517. this.spine2.node.active = false;
  518. this.spine1.clearTrack(0);
  519. })
  520. })
  521. }
  522. /**
  523. * 引导中的点击回调
  524. */
  525. private guideCallback: () => void
  526. public setGuideCallback(guideCallback: () => void) {
  527. this.guideCallback = guideCallback
  528. }
  529. /**
  530. * 开始引导强化装备
  531. */
  532. private onGuide_1() {
  533. let guideMask = this.main.mGuideMask
  534. let targetNode = this.mContent.children[0];
  535. guideMask.setTargetNode(targetNode);
  536. guideMask.show();
  537. this.setGuideCallback(() => {
  538. targetNode = this.QHBtnNode;
  539. guideMask.setTargetNode(targetNode);
  540. })
  541. }
  542. public onGuideExit() {
  543. let guideMask = this.main.mGuideMask
  544. let targetNode = this.node.getChildByName("top_left").getChildByName("fh");
  545. guideMask.setTargetNode(targetNode)
  546. guideMask.show()
  547. let closeCallback = this.closeCallback
  548. this.setCloseCallback(() => {
  549. guideMask.close();
  550. if (closeCallback) {
  551. closeCallback()
  552. }
  553. })
  554. }
  555. }