EquipStar.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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 { __EquipData } from "../../data/sdata/SManage";
  8. import { EquipAttr } from "../../data/udata/Player";
  9. import Equip from "./Equip";
  10. import EquipQH from "./EquipQH";
  11. /**
  12. * 装备升星
  13. */
  14. const { ccclass, property } = cc._decorator;
  15. @ccclass
  16. export default class EquipStar extends cc.Component {
  17. @property(GoodItem)
  18. mEquipItem: GoodItem = null;
  19. @property(cc.Node)
  20. mContent: cc.Node = null;//背包容器
  21. @property(cc.Prefab)
  22. mGoodItem: cc.Prefab = null;//道具节点
  23. @property(cc.Label)
  24. mEquipName: cc.Label = null;//装备名字
  25. @property(cc.Label)
  26. mBfbLabel: cc.Label = null;//成功百分比
  27. @property(cc.ProgressBar)
  28. mBfbBar: cc.ProgressBar = null;//成功百分比
  29. @property(cc.Label)
  30. mQHMoney: cc.Label = null;//强化消耗的货币
  31. @property(cc.Node)
  32. mXhContent: cc.Node = null;//消耗容器
  33. @property(cc.Node)
  34. mOneKeyBt: cc.Node = null;//一键放入按钮
  35. @property(cc.Label)
  36. mAttrLabel: cc.Label = null;//基础属性提升
  37. @property(cc.Node)
  38. mFullNode: cc.Node = null;//满星
  39. @property(sp.Skeleton)
  40. spine1: sp.Skeleton = null;
  41. @property(sp.Skeleton)
  42. spine2: sp.Skeleton = null;
  43. /**
  44. * 装备界面
  45. */
  46. public equip: Equip = null;
  47. /**
  48. * 当前选中的伙伴
  49. */
  50. private petIcon: PetIcon = null;
  51. /**
  52. * 当前强化的装备
  53. */
  54. // private goodItem: GoodItem = null;
  55. /**
  56. * 当前选中的道具
  57. */
  58. private curGoodItem: Array<GoodItem> = []
  59. private STAR_GL = [50, 30, 20, 10]
  60. private STAR_MONEY = [5000, 20000, 50000, 120000, 200000]
  61. private main: Main = null;
  62. public starType: number = 0; // 0 人物装备升星 1 背包装备升星
  63. public equipAttr: EquipAttr = null;
  64. public equipData: __EquipData = null;
  65. onLoad() {
  66. this.mFullNode.active = false
  67. this.mBfbLabel.string = '0%'
  68. this.mBfbBar.progress = 0
  69. }
  70. public init(equip: Equip, petIcon: PetIcon, equipAttr: EquipAttr) {
  71. this.starType = 0;
  72. this.main = this.node.getComponent(EquipQH).main
  73. this.equip = equip
  74. this.petIcon = petIcon
  75. this.equipAttr = equipAttr
  76. this.equipData = this.main.sManage.getEquipById(equipAttr.id);
  77. for (let i = 0; i < 10; i++) {
  78. let node = cc.instantiate(this.mGoodItem);
  79. node.parent = this.mXhContent;
  80. }
  81. this.mQHMoney.string = '' + this.STAR_MONEY[this.equipAttr.star]
  82. this.flushEquipPag()
  83. }
  84. /**
  85. * 选择当前页卡
  86. */
  87. public checkToggle() {
  88. let scrollView = this.mContent.parent.parent.getComponent(cc.ScrollView)
  89. scrollView.stopAutoScroll()
  90. scrollView.scrollToTop()
  91. this.mOneKeyBt.active = true
  92. this.mEquipItem.initEquip(this.main, this.equipAttr)
  93. this.mEquipName.string = i18n.t(this.equipData.name)
  94. this.curGoodItem = []
  95. this.flushEquipPag();
  96. this.flushXH()
  97. let equipQH = this.node.getComponent(EquipQH)
  98. equipQH.setOneKeyCallback(() => {
  99. this.oneKeyPush()
  100. })
  101. equipQH.setSortCallback((type: number) => {
  102. if (type == 0) {//品质排序
  103. EquipQH.sortPag(0, this.mContent)
  104. } else {//战力排序
  105. EquipQH.sortPag(1, this.mContent)
  106. }
  107. })
  108. }
  109. /**
  110. * 刷新装备背包
  111. */
  112. public flushEquipPag() {
  113. let equip = this.main.player.equip;
  114. let index = 0;
  115. let content = this.mContent;
  116. for (let i = 0; i < equip.length; i++) {
  117. const element = equip[i];
  118. if (element.star == this.equipAttr.star) {
  119. if (this.equipAttr.__index == element.__index) {
  120. this.starType = 1;
  121. } else {
  122. let temp = this.main.sManage.getEquipById(element.id)
  123. if (temp.type == this.equipData.type
  124. && temp.pz == this.equipData.pz
  125. ) {
  126. if (index >= content.children.length) {
  127. this.addGoodItem(content);
  128. }
  129. let node = content.children[index];
  130. node.opacity = 255
  131. let equipItem = node.getComponent(GoodItem);
  132. equipItem.initEquip(this.main, element);
  133. equipItem.setCallback((gi) => {
  134. this.addEquip(gi);
  135. this.main.playerEffectByPath(AudioMgr.qh2);
  136. });
  137. index++;
  138. }
  139. }
  140. }
  141. }
  142. for (let i = index; i < content.children.length; i++) {
  143. let node = content.children[i];
  144. node.opacity = 255
  145. let equipItem = node.getComponent(GoodItem);
  146. equipItem.setNull();
  147. }
  148. }
  149. private addGoodItem(content: cc.Node) {
  150. for (let i = 0; i < 4; i++) {
  151. let node = cc.instantiate(this.mGoodItem);
  152. node.parent = content;
  153. }
  154. }
  155. /**
  156. * 背包中的装备添加到消耗材料
  157. * @param goodItem
  158. */
  159. private addEquip(goodItem: GoodItem) {
  160. if (goodItem.node.opacity == 100) {
  161. return
  162. }
  163. if (this.curGoodItem.length >= 10) {
  164. this.main.showTips(i18n.t('消耗材料以满'))
  165. } else {
  166. goodItem.node.opacity = 100
  167. this.curGoodItem.push(goodItem)
  168. this.flushXH()
  169. }
  170. }
  171. private removeEquip(goodItem: GoodItem) {
  172. for (let i = 0; i < this.curGoodItem.length; i++) {
  173. const element = this.curGoodItem[i];
  174. if (element.equip.__index == goodItem.equip.__index) {
  175. element.node.opacity = 255
  176. this.curGoodItem.splice(i, 1)
  177. break
  178. }
  179. }
  180. this.flushXH()
  181. }
  182. private flushXH() {
  183. if (this.equipAttr.star >= 5) {
  184. this.mFullNode.active = true
  185. return
  186. }
  187. let exp = 0
  188. for (let i = 0; i < this.mXhContent.children.length; i++) {
  189. const node = this.mXhContent.children[i];
  190. let tmpItem = node.getComponent(GoodItem)
  191. if (i < this.curGoodItem.length) {
  192. let goodItem = this.curGoodItem[i]
  193. tmpItem.initEquip(this.main, goodItem.equip)
  194. tmpItem.setCallback((gItem: GoodItem) => {
  195. this.removeEquip(gItem)
  196. })
  197. exp += this.STAR_GL[this.equipAttr.star]
  198. } else {
  199. tmpItem.setNull()
  200. }
  201. }
  202. if (exp >= 100) {
  203. exp = 100
  204. this.node.getComponent(EquipQH).mQHFull.active = true
  205. this.mAttrLabel.string = '基础属性提升+' + ((this.equipAttr.star + 1) * 10) + '%'
  206. } else {
  207. this.node.getComponent(EquipQH).mQHFull.active = false
  208. this.mAttrLabel.string = '基础属性提升+' + (this.equipAttr.star * 10) + '%'
  209. }
  210. this.mBfbLabel.string = exp + '%'
  211. this.mBfbBar.progress = exp / 100
  212. this.mQHMoney.string = '' + this.STAR_MONEY[this.equipAttr.star]
  213. if (this.curGoodItem.length >= 10) {
  214. this.mOneKeyBt.children[0].getComponent(cc.Label).string = i18n.t('一键卸下')
  215. } else {
  216. this.mOneKeyBt.children[0].getComponent(cc.Label).string = i18n.t('一键放入')
  217. }
  218. }
  219. /**
  220. * 一键放入
  221. */
  222. private oneKeyPush() {
  223. if (this.curGoodItem.length >= 10) {
  224. for (let i = 0; i < this.curGoodItem.length; i++) {
  225. const element = this.curGoodItem[i]
  226. element.node.opacity = 255
  227. }
  228. this.curGoodItem = []
  229. } else {
  230. for (let i = 0; i < this.curGoodItem.length; i++) {
  231. const element = this.curGoodItem[i]
  232. element.node.opacity = 255
  233. }
  234. this.curGoodItem = []
  235. let exp = 0
  236. for (let i = 0; i < 10; i++) {
  237. if (i >= this.mContent.children.length) {
  238. break
  239. }
  240. const node = this.mContent.children[i];
  241. let equipItem = node.getComponent(GoodItem);
  242. if (equipItem.equip) {
  243. equipItem.node.opacity = 100
  244. exp += this.STAR_GL[this.equipAttr.star]
  245. this.curGoodItem.push(equipItem)
  246. if (exp >= 100) {
  247. break
  248. }
  249. }
  250. }
  251. }
  252. this.flushXH()
  253. }
  254. /**
  255. * 升星
  256. */
  257. public onclickStar() {
  258. if (this.starType == 0) {
  259. this.starFunc();
  260. } else if (this.starType == 1) {
  261. this.starFunc1();
  262. }
  263. }
  264. starFunc() {
  265. let removeEquips = []
  266. for (let i = 0; i < this.curGoodItem.length; i++) {
  267. const element = this.curGoodItem[i];
  268. removeEquips.push(element.equip.__index)
  269. }
  270. if(removeEquips.length == 0){
  271. this.main.showTips('没有添加任何材料');
  272. return
  273. }
  274. let msg = {
  275. petId: this.petIcon.id,
  276. equipId: this.equipAttr.id,
  277. equips: removeEquips
  278. }
  279. this.main.gameHttp.sendJson('equip/v1/star', msg, (state, reve: ReveData) => {
  280. this.main.stopLoad();
  281. if (state == HttpStateType.SUCCESS) {
  282. if (reve.retCode == 0) {
  283. if (reve.data.star > 0) {
  284. this.main.playerEffectByPath(AudioMgr.qh);
  285. this.playQHSpine();
  286. this.equipAttr.star = reve.data.star
  287. this.main.showTips('升星成功');
  288. } else {
  289. this.main.showTips('升级失败');
  290. }
  291. this.curGoodItem = []
  292. this.mEquipItem.flushEquip(this.main);
  293. this.flushEquipPag()
  294. this.equip.flushEquip(this.petIcon)
  295. this.equip.flushPagSize()
  296. this.flushXH()
  297. } else {
  298. this.main.showTips(reve.message);
  299. }
  300. } else {
  301. this.main.showTips('网络异常');
  302. }
  303. });
  304. }
  305. starFunc1() {
  306. let removeEquips = []
  307. for (let i = 0; i < this.curGoodItem.length; i++) {
  308. const element = this.curGoodItem[i];
  309. removeEquips.push(element.equip.__index)
  310. }
  311. if(removeEquips.length == 0){
  312. this.main.showTips('没有添加任何材料');
  313. return
  314. }
  315. let msg = {
  316. equipIndex: this.equipAttr.__index,
  317. equips: removeEquips
  318. }
  319. this.main.gameHttp.sendJson('equip/v1/star1', msg, (state, reve: ReveData) => {
  320. this.main.stopLoad();
  321. if (state == HttpStateType.SUCCESS) {
  322. if (reve.retCode == 0) {
  323. if (reve.data.star > 0) {
  324. this.main.playerEffectByPath(AudioMgr.qh);
  325. this.playQHSpine();
  326. this.equipAttr.star = reve.data.star;
  327. } else {
  328. this.main.showTips('升级失败');
  329. }
  330. this.curGoodItem = [];
  331. this.mEquipItem.flushEquip(this.main);
  332. this.flushEquipPag();
  333. this.equip.flushEquip(this.petIcon)
  334. this.equip.flushPagSize()
  335. this.flushXH();
  336. this.equip.mEquipPack.setEquipType(this.equip.curPage);
  337. } else {
  338. this.main.showTips(reve.message);
  339. }
  340. } else {
  341. this.main.showTips('网络异常');
  342. }
  343. });
  344. }
  345. playQHSpine() {
  346. this.spine1.setAnimation(0, "atk", false);
  347. this.spine1.setCompleteListener(() => {
  348. this.spine1.setAnimation(0, "idle", false);
  349. this.spine2.node.active = true;
  350. this.spine2.setAnimation(0, "animation", false);
  351. this.spine2.setCompleteListener(() => {
  352. this.spine2.node.active = false;
  353. this.spine1.clearTrack(0);
  354. })
  355. })
  356. }
  357. }