EquipQHMax.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. import i18n from "../../../i18n/i18n";
  2. import Main from "../../../main/Main";
  3. import { AudioMgr } from "../../../main/ViewManage";
  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 { __EquipData, __EquipQHData } from "../../data/sdata/SManage";
  9. import { EquipAttr } from "../../data/udata/Player";
  10. import Equip from "./Equip";
  11. import EquipQH from "./EquipQH";
  12. /**
  13. * 强化上限
  14. */
  15. const { ccclass, property } = cc._decorator;
  16. @ccclass
  17. export default class EquipQHMax extends cc.Component {
  18. @property(GoodItem)
  19. mEquipItem: GoodItem = null;
  20. @property(cc.Label)
  21. mEquipName: cc.Label = null;//装备名字
  22. @property(cc.Label)
  23. mEquipName1: 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. mQHLevel1: cc.Label = null;//当前强化等级
  30. @property(cc.Label)
  31. mQHLevel2: cc.Label = null;//目标强化等级
  32. @property(cc.Label)
  33. mQHLevel: cc.Label = null;//强化等级
  34. @property(cc.Label)
  35. mQHBfbLabel: cc.Label = null;//强化百分比
  36. @property(cc.ProgressBar)
  37. mQHBfbBar: cc.ProgressBar = null;//强化百分比
  38. @property(cc.Label)
  39. mQHMoney: cc.Label = null;//强化消耗的货币
  40. @property(cc.Label)
  41. mQHMaxLabel: cc.Label = null;//上限突破次数
  42. @property(GoodItem)
  43. mXHEquipItem: GoodItem = null;
  44. @property(cc.Node)
  45. mOneKeyBt: cc.Node = null;//一键放入按钮
  46. @property(cc.Node)
  47. mFullNode: cc.Node = null;//满星
  48. @property(sp.Skeleton)
  49. spine1: sp.Skeleton = null;
  50. @property(sp.Skeleton)
  51. spine2: sp.Skeleton = null;
  52. /**
  53. * 装备界面
  54. */
  55. public equip: Equip = null;
  56. /**
  57. * 当前选中的伙伴
  58. */
  59. private petIcon: PetIcon = null;
  60. /**
  61. * 当前强化的装备
  62. */
  63. // private goodItem: GoodItem = null;
  64. /**
  65. * 当前选中的装备
  66. */
  67. private curGoodItem: GoodItem = null
  68. private main: Main = null;
  69. private MAX_MONEY = [5000, 10000, 15000, 20000, 25000, 0];
  70. public tpType: number = 0; // 0 突破人物装备 1 突破背包装备
  71. public equipAttr: EquipAttr = null;
  72. public equipData: __EquipData = null;
  73. onLoad() {
  74. }
  75. public init(equip: Equip, petIcon: PetIcon, equipAttr: EquipAttr) {
  76. this.tpType = 0;
  77. this.main = this.node.getComponent(EquipQH).main
  78. this.equip = equip
  79. this.petIcon = petIcon
  80. this.equipAttr = equipAttr
  81. this.equipData = this.main.sManage.getEquipById(equipAttr.id);
  82. this.flushEquipPag()
  83. }
  84. /**
  85. * 选择当前页卡
  86. */
  87. private checkToggle() {
  88. let scrollView = this.mContent.parent.parent.getComponent(cc.ScrollView)
  89. scrollView.stopAutoScroll()
  90. scrollView.scrollToTop()
  91. this.curGoodItem = null
  92. this.mXHEquipItem.setNull()
  93. this.flushToggle()
  94. }
  95. private flushToggle() {
  96. this.flushEquipPag()
  97. let equipQH = this.node.getComponent(EquipQH)
  98. equipQH.mQHFull.active = false
  99. this.mOneKeyBt.active = false
  100. this.mEquipItem.initEquip(this.main, this.equipAttr)
  101. this.mEquipName.string = i18n.t(this.equipData.name)
  102. this.mEquipName1.string = i18n.t(this.equipData.name)
  103. let qhMax = this.equipAttr.qhMax
  104. if (qhMax >= this.equipData.qh_max) {
  105. this.mFullNode.active = true
  106. } else {
  107. this.mFullNode.active = false
  108. }
  109. this.mQHLevel1.string = (this.equipData.level + qhMax * 5) + ''
  110. this.mQHMoney.string = '' + this.MAX_MONEY[this.equipAttr.qhMax]
  111. this.flushLevel2()
  112. this.flushAttr(this.equipAttr.PI)
  113. equipQH.setSortCallback((type: number) => {
  114. if (type == 0) {//品质排序
  115. EquipQH.sortPag(0, this.mContent)
  116. } else {//战力排序
  117. EquipQH.sortPag(1, this.mContent)
  118. }
  119. })
  120. }
  121. private flushLevel2() {
  122. let max = this.equipAttr.qhMax
  123. if (this.curGoodItem) {
  124. max += 1
  125. }
  126. if (max > 5) {
  127. max = 5
  128. }
  129. this.mQHLevel2.string = (this.equipData.level + max * 5) + ''
  130. }
  131. /**
  132. * 刷新装备背包
  133. */
  134. public flushEquipPag() {
  135. let equip = this.main.player.equip;
  136. let index = 0;
  137. let content = this.mContent;
  138. for (let i = 0; i < equip.length; i++) {
  139. const element = equip[i];
  140. if (element.id == 20001 || element.id == this.equipAttr.id) {
  141. if (this.equipAttr.__index == element.__index) {
  142. this.tpType = 1;
  143. } else {
  144. if (index >= content.children.length) {
  145. this.addGoodItem(content);
  146. }
  147. let node = content.children[index];
  148. node.opacity = 255
  149. let equipItem = node.getComponent(GoodItem);
  150. equipItem.initEquip(this.main, element);
  151. if (element.id == 20001) {
  152. node.zIndex = 0
  153. } else {
  154. node.zIndex = equipItem.equipData.pz
  155. }
  156. equipItem.setCallback((gi) => {
  157. this.addEquip(gi);
  158. this.main.playerEffectByPath(AudioMgr.qh2);
  159. });
  160. index++;
  161. }
  162. }
  163. }
  164. for (let i = index; i < content.children.length; i++) {
  165. let node = content.children[i];
  166. node.opacity = 255
  167. let equipItem = node.getComponent(GoodItem);
  168. equipItem.setNull();
  169. node.zIndex = cc.macro.MAX_ZINDEX - 1
  170. }
  171. }
  172. /**
  173. * 刷新属性
  174. */
  175. private flushAttr(PI) {
  176. let equipData = this.equipData
  177. let __qhList = this.main.sManage.getEquipQHByType(equipData)
  178. let qhLevel = FFCalAttr.getEquipQHLevel(this.main, PI, equipData)
  179. let tempAttrExp = 0
  180. let _qhAttr1: __EquipQHData = null
  181. let _qhAttr2: __EquipQHData = null
  182. if (qhLevel > 0) {
  183. _qhAttr1 = __qhList[qhLevel - 1]
  184. }
  185. if (qhLevel >= __qhList.length) {
  186. _qhAttr2 = __qhList[qhLevel - 1]
  187. } else {
  188. _qhAttr2 = __qhList[qhLevel]
  189. }
  190. let maxQH = equipData.level + this.equipAttr.qhMax * 5;
  191. if (qhLevel > maxQH) {
  192. qhLevel = maxQH
  193. }
  194. this.mQHLevel.string = 'Lv.' + qhLevel + '/' + maxQH;
  195. let curExp = PI - tempAttrExp
  196. let uplevelExp = _qhAttr2.exp - tempAttrExp
  197. let bfb = curExp / uplevelExp;
  198. if (bfb > 1) {
  199. bfb = 1
  200. }
  201. this.mQHBfbBar.progress = bfb
  202. this.mQHBfbLabel.string = Math.floor(bfb * 100) + '%'
  203. this.mQHMaxLabel.string = i18n.t('上限突破次数') + this.equipAttr.qhMax + '/5'
  204. }
  205. private addGoodItem(content: cc.Node) {
  206. for (let i = 0; i < 4; i++) {
  207. let node = cc.instantiate(this.mGoodItem);
  208. node.parent = content;
  209. }
  210. }
  211. /**
  212. * 背包中的装备添加到消耗材料
  213. * @param goodItem
  214. */
  215. private addEquip(goodItem: GoodItem) {
  216. if (this.curGoodItem) {
  217. this.curGoodItem.node.opacity = 255
  218. }
  219. this.curGoodItem = goodItem
  220. this.curGoodItem.node.opacity = 100
  221. this.mXHEquipItem.initEquip(this.main, goodItem.equip)
  222. this.flushLevel2()
  223. }
  224. /**
  225. * 突破
  226. */
  227. public onclickTP() {
  228. if (this.tpType == 0) {
  229. this.tpFunc();
  230. } else if (this.tpType == 1) {
  231. this.tpFunc1();
  232. }
  233. }
  234. tpFunc() {
  235. if (!this.curGoodItem) {
  236. this.main.showTips('没有添加任何材料')
  237. return
  238. }
  239. let msg = {
  240. petId: this.petIcon.id,
  241. equipId: this.equipAttr.id,
  242. equipIndex: this.curGoodItem.equip.__index
  243. }
  244. this.main.gameHttp.sendJson('equip/v1/qhMax', msg, (state, reve: ReveData) => {
  245. this.main.stopLoad();
  246. if (state == HttpStateType.SUCCESS) {
  247. if (reve.retCode == 0) {
  248. this.main.playerEffectByPath(AudioMgr.qh);
  249. this.playQHSpine();
  250. this.equipAttr.qhMax += 1
  251. this.curGoodItem = null
  252. this.mXHEquipItem.setNull()
  253. this.flushToggle()
  254. this.equip.flushEquip(this.petIcon)
  255. this.equip.flushPagSize()
  256. this.main.showTips("强化上限成功");
  257. } else {
  258. this.main.showTips(reve.message);
  259. }
  260. } else {
  261. this.main.showTips('网络异常');
  262. }
  263. });
  264. }
  265. tpFunc1() {
  266. if (!this.curGoodItem) {
  267. this.main.showTips('没有添加任何材料')
  268. return
  269. }
  270. let msg = {
  271. equipIndex1: this.equipAttr.__index,
  272. equipIndex2: this.curGoodItem.equip.__index
  273. }
  274. this.main.gameHttp.sendJson('equip/v1/qhMax1', msg, (state, reve: ReveData) => {
  275. this.main.stopLoad();
  276. if (state == HttpStateType.SUCCESS) {
  277. if (reve.retCode == 0) {
  278. this.main.playerEffectByPath(AudioMgr.qh);
  279. this.playQHSpine();
  280. this.equipAttr.qhMax += 1
  281. this.curGoodItem = null
  282. this.mXHEquipItem.setNull()
  283. this.flushToggle()
  284. this.equip.mEquipPack.setEquipType(this.equip.curPage);
  285. this.equip.flushEquip(this.petIcon)
  286. this.equip.flushPagSize()
  287. } else {
  288. this.main.showTips(reve.message);
  289. }
  290. } else {
  291. this.main.showTips('网络异常');
  292. }
  293. });
  294. }
  295. playQHSpine() {
  296. this.spine1.setAnimation(0, "atk", false);
  297. this.spine1.setCompleteListener(() => {
  298. this.spine1.setAnimation(0, "idle", false);
  299. this.spine2.node.active = true;
  300. this.spine2.setAnimation(0, "animation", false);
  301. this.spine2.setCompleteListener(() => {
  302. this.spine2.node.active = false;
  303. this.spine1.clearTrack(0);
  304. })
  305. })
  306. }
  307. }