EquipInfo.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. import i18n from "../../../i18n/i18n";
  2. import Main from "../../../main/Main";
  3. import GoodItem from "../../common/GoodItem";
  4. import EquipViewAttr from "../../common/EquipViewAttr";
  5. import MainAtterItem from "./MainAtterItem";
  6. import { __EquipData } from "../../data/sdata/SManage";
  7. import FFCalAttr from "../../data/FFCalAttr";
  8. const {ccclass, property} = cc._decorator;
  9. @ccclass
  10. export default class EquipInfo extends cc.Component {
  11. @property(GoodItem)
  12. mEquipItem: GoodItem = null;
  13. @property(cc.Label)
  14. mName: cc.Label = null;
  15. @property([MainAtterItem])
  16. mMainNode: Array<MainAtterItem> = [];//主属性节点
  17. @property(cc.Node)
  18. mFAttrNode: cc.Node = null;//副属性节点
  19. @property(cc.Prefab)
  20. mFAttrItem: cc.Prefab = null;
  21. @property(cc.Node)
  22. mSkillNode: cc.Node = null;//技能节点
  23. @property(cc.Label)
  24. mSkillName: cc.Label = null;
  25. @property(cc.Label)
  26. mSkillAbout: cc.Label = null;
  27. @property(cc.Sprite)
  28. mSkillIcon: cc.Sprite = null;
  29. public main:Main;
  30. public equipItem:GoodItem;
  31. /**
  32. *
  33. * @param main
  34. * @param equip 主装备
  35. * @param equip1 对比的装备
  36. */
  37. public init(main:Main,equipItem:GoodItem,equipItem1:GoodItem){
  38. if(!equipItem.equip){
  39. this.node.active = false
  40. return
  41. }
  42. this.node.active = true;
  43. this.main = main;
  44. this.equipItem = equipItem;
  45. this.mName.string = i18n.t(equipItem.equipData.name)
  46. this.mEquipItem.equip = equipItem.equip;
  47. this.mEquipItem.equipData = equipItem.equipData;
  48. this.mEquipItem.flushEquip(main);
  49. let equipData = equipItem.equipData
  50. let atkNode = this.mMainNode[0]
  51. let fAttr = FFCalAttr.getEquipAttr(this.main,this.mEquipItem.equip,equipData)
  52. let fAttr1 = null
  53. if(equipItem1 && equipItem1.equipData){
  54. fAttr1 = FFCalAttr.getEquipAttr(this.main,equipItem1.equip,equipItem1.equipData)
  55. atkNode.setContrase(fAttr.zdl,fAttr1.zdl)
  56. }else{
  57. atkNode.setValue(fAttr.zdl);
  58. }
  59. atkNode = this.mMainNode[1]
  60. if(fAttr.atk > 0){
  61. atkNode.node.active = true;
  62. if(fAttr1){
  63. atkNode.setContrase(fAttr.atk,fAttr1.atk)
  64. }else{
  65. atkNode.setValue(fAttr.atk);
  66. }
  67. }else{
  68. atkNode.node.active = false;
  69. }
  70. atkNode = this.mMainNode[2]
  71. if(equipData.def > 0){
  72. atkNode.node.active = true;
  73. if(fAttr1){
  74. atkNode.setContrase(fAttr.def,fAttr1.def)
  75. }else{
  76. atkNode.setValue(fAttr.def);
  77. }
  78. }else{
  79. atkNode.node.active = false;
  80. }
  81. atkNode = this.mMainNode[3]
  82. if(equipData.hp > 0){
  83. atkNode.node.active = true;
  84. if(fAttr1){
  85. atkNode.setContrase(fAttr.hp,fAttr1.hp)
  86. }else{
  87. atkNode.setValue(fAttr.hp);
  88. }
  89. }else{
  90. atkNode.node.active = false;
  91. }
  92. atkNode = this.mMainNode[4]
  93. if(equipData.sp > 0){
  94. atkNode.node.active = true;
  95. if(fAttr1){
  96. atkNode.setContrase(fAttr.sp,fAttr1.sp)
  97. }else{
  98. atkNode.setValue(fAttr.sp);
  99. }
  100. }else{
  101. atkNode.node.active = false;
  102. }
  103. let equip = equipItem.equip
  104. if(equip.attr.length <= 0){
  105. this.mFAttrNode.active = false;
  106. }else{
  107. this.mFAttrNode.destroyAllChildren();
  108. this.mFAttrNode.active = true;
  109. for (let i = 0; i < equip.attr.length; i++) {
  110. const element = equip.attr[i];
  111. let node = cc.instantiate(this.mFAttrItem);
  112. let eAttr = node.getComponent(EquipViewAttr);
  113. eAttr.init(this.main,element);
  114. node.parent = this.mFAttrNode;
  115. }
  116. }
  117. if(equipData.skill > 0){
  118. this.mSkillNode.active = true;
  119. let skillData = this.main.sManage.getSkillById(equipData.skill);
  120. this.mSkillName.string = i18n.t(skillData.name);
  121. this.mSkillAbout.string = i18n.t(skillData.about,
  122. {
  123. 'VAL1':skillData.value1,
  124. 'VAL2':skillData.value2,
  125. 'VAL3':skillData.value3,
  126. }
  127. );
  128. cc.resources.load('icon/skill/'+skillData.icon, cc.SpriteFrame, (err, spriteFrame:cc.SpriteFrame) =>{
  129. if(err){
  130. cc.error(err);
  131. }else{
  132. this.mSkillIcon.spriteFrame = spriteFrame;
  133. }
  134. } );
  135. }else{
  136. this.mSkillNode.active = false;
  137. }
  138. }
  139. }