EquipUpdate.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import { _decorator, instantiate, Label, Node, Prefab, ProgressBar, tween, UIOpacity } from 'cc';
  2. import { BaseView } from '../../../framework/layer/BaseView';
  3. import { StringUtil } from '../../../framework/util/StringUtil';
  4. import { CommonItem } from '../common/CommonItem';
  5. import List from '../../../framework/list/List';
  6. import { Equip } from '../../data/EquipData';
  7. import { EquipManager } from '../../manager/EquipManager';
  8. import { AttrAddTypeEnum, AttrConf } from '../../common/InterfaceAddEnum';
  9. import { Framework } from '../../../framework/Framework';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('EquipUpdate')
  12. export class EquipUpdate extends BaseView {
  13. @property({ type: Label, tooltip: "关闭提示" })
  14. closeTips: Label = null;
  15. @property({ type: Label, tooltip: "标题" })
  16. titieTx: Label = null;
  17. @property({ type: Label, tooltip: "装备名" })
  18. equipNameTx: Label = null;
  19. @property({ type: Node, tooltip: "装备节点" })
  20. equipNode: Node = null;
  21. @property({ type: Label, tooltip: "当前等级" })
  22. equipNowLevel: Label = null;
  23. @property({ type: Label, tooltip: "目标等级" })
  24. equipNextLevel: Label = null;
  25. @property({ type: Label, tooltip: "当前属性" })
  26. equipNowAttr: Label = null;
  27. @property({ type: Label, tooltip: "目标属性" })
  28. equipNextAttr: Label = null;
  29. @property({ type: Label, tooltip: "目标属性加成" })
  30. equipNextAttrAdd: Label = null;
  31. @property({ type: Node, tooltip: "等级箭头" })
  32. levelArrow: Label = null;
  33. @property({ type: Node, tooltip: "属性箭头" })
  34. attrArrow: Node = null;
  35. @property({ type: Label, tooltip: "经验值标题" })
  36. expTitle: Label = null;
  37. @property({ type: ProgressBar, tooltip: "经验值进度" })
  38. expBar: ProgressBar = null;
  39. @property({ type: Label, tooltip: "经验值文字" })
  40. expBarTx: Label = null;
  41. @property({ type: List, tooltip: "材料列表" })
  42. itemSv: List = null;
  43. @property({ type: Label, tooltip: "升级按钮文字" })
  44. updateBtnTx: Label = null;
  45. @property({ type: Label, tooltip: "一键按钮文字" })
  46. autoBtnTx: Label = null;
  47. private _curRace: number = 0;
  48. private _curSlot: number = 0;
  49. private _curEquip: Equip = null;
  50. private _curExp: number = 0;
  51. private _otherExp: number = 0;
  52. private _equipsData = [];
  53. private _selectEquip = {};
  54. protected onLoad() {
  55. super.onLoad();
  56. this.closeTips.string = StringUtil.getLanguageData('点击空白关闭');
  57. this.titieTx.string = StringUtil.getLanguageData('装备升级');
  58. this.updateBtnTx.string = StringUtil.getLanguageData('升级');
  59. this.autoBtnTx.string = StringUtil.getLanguageData('一键选择');
  60. this.closeTips.node.getComponent(UIOpacity).opacity = 0;
  61. }
  62. protected onDestroy() {
  63. }
  64. //UI开打时会调用,如果有初始化代码应该放到此函数
  65. onOpen(data) {
  66. tween(this.closeTips.node.getComponent(UIOpacity))
  67. .to(1, { opacity: 255 })
  68. .to(1.2, { opacity: 10 })
  69. .union()
  70. .repeatForever()
  71. .start()
  72. this._curRace = data.race;
  73. this._curSlot = data.slot;
  74. this._curEquip = data.equip;
  75. this.load('common', `prefab/CommonItem`, Prefab, (pre: Prefab) => {
  76. let item = instantiate(pre);
  77. this.equipNode.addChild(item);
  78. item.getComponent(CommonItem).setClickEnable(false);
  79. item.getComponent(CommonItem).setNumShow(false);
  80. item.getComponent(CommonItem).refreshItem(this._curEquip);
  81. })
  82. this.equipNameTx.string = StringUtil.getLanguageData(this._curEquip.conf['Name']);
  83. this._curExp = this._curEquip.exp;
  84. this._equipsData = EquipManager.getEquipRaceSlotAllGroup(data.race);
  85. this.itemSv.numItems = this._equipsData.length;
  86. this.initUI();
  87. }
  88. //UI关闭时会调用,该函数在onDestroy前调用
  89. onClose() {
  90. }
  91. //框架管理UI层级时会调用,可根据UI情况修改
  92. onShow() {
  93. super.onShow();
  94. }
  95. //框架管理UI层级时会调用,可根据UI情况修改
  96. onHide() {
  97. super.onHide();
  98. }
  99. //UI事件处理
  100. private onTouchButton(event: Event) {
  101. //Framework.audio.playEffect(AudioID.Click);
  102. let target: any = event.target;
  103. if (target.name == 'mask') {
  104. Framework.layer.close(this);
  105. } else if (target.name == 'update_btn') {
  106. if (Object.keys(this._selectEquip).length <= 0) {
  107. Framework.tips.setTips(StringUtil.getLanguageData('请选择吞噬的装备'));
  108. return;
  109. }
  110. let args = {
  111. race: this._curRace,
  112. slot: this._curSlot,
  113. eat_eids: {}
  114. }
  115. for (const key in this._selectEquip) {
  116. if (Object.prototype.hasOwnProperty.call(this._selectEquip, key)) {
  117. const element = this._selectEquip[key];
  118. args.eat_eids[key] = element.count;
  119. }
  120. }
  121. EquipManager.sendUpdateMsg(args, () => {
  122. Framework.tips.setTips(StringUtil.getLanguageData('升级成功!'));
  123. Framework.layer.close(this);
  124. })
  125. } else if (target.name == 'auto_btn') {
  126. }
  127. }
  128. onEventList(item, idx) {
  129. item.getComponent(CommonItem).refreshItem(this._equipsData[idx]);
  130. item.getComponent(CommonItem).setClick((data, isSelect) => {
  131. item.getComponent(CommonItem).setSelectEnable(isSelect);
  132. if (isSelect) {
  133. this._selectEquip[data.id] = data;
  134. this._otherExp = this._otherExp + ((data.conf.EatExp + data.exp) * data.count);
  135. } else {
  136. if (this._selectEquip.hasOwnProperty(data.id)) {
  137. delete this._selectEquip[data.id];
  138. this._otherExp = this._otherExp - ((data.conf.EatExp + data.exp) * data.count);
  139. }
  140. }
  141. this.updateByExp();
  142. });
  143. }
  144. initUI() {
  145. let curLvConf = EquipManager.getEquipLevelByExp(this._curExp);
  146. this.equipNowLevel.string = 'Lv.' + curLvConf.Id;
  147. let attr = this._curEquip.conf['Stat1'].split(':');
  148. let attrConf = AttrConf[attr[0]]
  149. let attrStr = StringUtil.getLanguageData(attrConf.name);
  150. let nowAdd = null;
  151. let value = null;
  152. if (attrConf.type == AttrAddTypeEnum.reality) {
  153. nowAdd = attr[1] * (1 + curLvConf.AttackMod);
  154. value = " +" + parseFloat((attr[1] * (1 + curLvConf.AttackMod)).toFixed(2));
  155. } else {
  156. nowAdd = 100 * Number(attr[1]) * (1 + curLvConf.AttackMod);
  157. value = " +" + parseFloat((100 * Number(attr[1]) * (1 + curLvConf.AttackMod)).toFixed(2)) + "%";
  158. }
  159. attrStr = attrStr + value;
  160. this.equipNowAttr.string = attrStr;
  161. let nextLvConf = EquipManager.getEquipNextLevel(this._curExp);
  162. this.equipNextLevel.string = 'Lv.' + nextLvConf.Id;
  163. let attrNextConf = AttrConf[attr[0]]
  164. let attrNextStr = StringUtil.getLanguageData(attrNextConf.name);
  165. let nextAdd = null;
  166. let valueNext = null;
  167. if (attrConf.type == AttrAddTypeEnum.reality) {
  168. nextAdd = attr[1] * (1 + nextLvConf.AttackMod);
  169. valueNext = " +" + parseFloat((attr[1] * (1 + nextLvConf.AttackMod)).toFixed(2));
  170. } else {
  171. nextAdd = 100 * Number(attr[1]) * (1 + nextLvConf.AttackMod);
  172. valueNext = " +" + parseFloat((100 * Number(attr[1]) * (1 + nextLvConf.AttackMod)).toFixed(2)) + "%";
  173. }
  174. attrNextStr = attrNextStr + valueNext;
  175. this.equipNextAttr.string = attrNextStr;
  176. this.equipNextAttrAdd.string = attrConf.type == AttrAddTypeEnum.reality ? (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + ")") :
  177. (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + "%)");
  178. this.expBar.progress = this._curExp / curLvConf.NeedExp;
  179. this.expBarTx.string = this._curExp + '/' + curLvConf.NeedExp;
  180. }
  181. updateByExp() {
  182. if (Object.keys(this._selectEquip).length <= 0) {
  183. this.initUI()
  184. } else {
  185. let curLvConf = EquipManager.getEquipLevelByExp(this._curExp);
  186. let attr = this._curEquip.conf['Stat1'].split(':');
  187. let attrConf = AttrConf[attr[0]]
  188. let nowAdd = null;
  189. if (attrConf.type == AttrAddTypeEnum.reality) {
  190. nowAdd = attr[1] * (1 + curLvConf.AttackMod);
  191. } else {
  192. nowAdd = 100 * Number(attr[1]) * (1 + curLvConf.AttackMod);
  193. }
  194. let nextLvConf = EquipManager.getEquipLevelByExp(this._curExp + this._otherExp);
  195. if (nextLvConf.Id <= curLvConf.Id) {
  196. nextLvConf = EquipManager.getEquipNextLevel(this._curExp + this._otherExp);
  197. }
  198. this.equipNextLevel.string = 'Lv.' + nextLvConf.Id;
  199. let attrNextConf = AttrConf[attr[0]]
  200. let attrNextStr = StringUtil.getLanguageData(attrNextConf.name);
  201. let nextAdd = null;
  202. let valueNext = null;
  203. if (attrConf.type == AttrAddTypeEnum.reality) {
  204. nextAdd = attr[1] * (1 + nextLvConf.AttackMod);
  205. valueNext = " +" + parseFloat((attr[1] * (1 + nextLvConf.AttackMod)).toFixed(2));
  206. } else {
  207. nextAdd = 100 * Number(attr[1]) * (1 + nextLvConf.AttackMod);
  208. valueNext = " +" + parseFloat((100 * Number(attr[1]) * (1 + nextLvConf.AttackMod)).toFixed(2)) + "%";
  209. }
  210. attrNextStr = attrNextStr + valueNext;
  211. this.equipNextAttr.string = attrNextStr;
  212. this.equipNextAttrAdd.string = attrConf.type == AttrAddTypeEnum.reality ? (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + ")") :
  213. (" (+" + parseFloat((nextAdd - nowAdd).toFixed(2)) + "%)");
  214. this.expBar.progress = (this._curExp + this._otherExp) / curLvConf.NeedExp;
  215. this.expBarTx.string = (this._curExp + this._otherExp) + '/' + curLvConf.NeedExp;
  216. }
  217. }
  218. }