Box.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Learn cc.Class:
  2. // - https://docs.cocos.com/creator/manual/en/scripting/class.html
  3. // Learn Attribute:
  4. // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
  5. // Learn life-cycle callbacks:
  6. // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
  7. cc.Class({
  8. extends: require("BaseItemConstroller"),
  9. properties: {
  10. itemName: cc.Label,
  11. itemGrade: cc.Label,
  12. itemMaster: cc.Label,
  13. sprite: cc.Sprite,
  14. mesh: cc.Node,
  15. },
  16. // LIFE-CYCLE CALLBACKS:
  17. onLoad() {
  18. this._super();
  19. this.init();
  20. this.item_attached_nameArr = [];
  21. this.item_Attached_typeArr = [];
  22. this.item_attached_valueArr = [];
  23. this.item_type = this.random_num(0, 9);
  24. this.gradetype = this.random_num(0, 4);
  25. this.generate_properties(this.item_type, this.gradetype);
  26. this.mesh.on(cc.Node.EventType.TOUCH_START, function() {
  27. cc.audioEngine.playEffect(this.UiController.audioArr[0]);
  28. cc.find("Canvas/PanelResult").removeAllChildren();
  29. if (cc.find("Canvas/Interface_Info").active) {
  30. return;
  31. } else {
  32. this.UiController.Panel_Botton.active = true;
  33. cc.find("Canvas/Interface_Against").active = true;
  34. }
  35. }, this)
  36. },
  37. start() {
  38. cc.find("Canvas/PanelResult/interface_Box/GameBg/ProAdd").removeAllChildren();
  39. this.box_table();
  40. //#region
  41. // cc.loader.loadRes("texture/AvatarProps", cc.SpriteFrame, function(err, spriteFrames) {
  42. // console.log("图集:", spriteFrames);
  43. // spriteFrames.forEach(function(element) {
  44. // if (element.name === this.spriteFrame_name) {
  45. // this.sprite.getComponent(cc.Sprite).spriteFrame = element;
  46. // }
  47. // });
  48. // });
  49. //#endregion
  50. },
  51. box_table() {
  52. this.itemName.string = this.item_name; //名字
  53. //#region
  54. // if (this.item_grade < 5) this.itemGrade.node.color = cc.Color.WHITE;
  55. // else if(this.item_grade >= 5&&this.item_grade < 15)this.itemGrade.node.color = cc.Color.BLUE;
  56. // else if(this.item_grade >= 5&&this.item_grade < 15)this.itemGrade.node.color = cc.Color.BLUE;
  57. // else{this.itemGrade.node.color = cc.Color.RED;}
  58. //#endregion
  59. this.itemGrade.string = this.item_grade + "级"; //等级
  60. this.itemMaster.string = this.item_master_type + '+' + this.item_master_value; //主属性+主属性数值
  61. //物品图片
  62. cc.resources.loadDir("texture/AvatarProps", cc.SpriteFrame, (err, spriteFrames) => {
  63. // ...
  64. spriteFrames.forEach((element) => {
  65. if (element.name === this.spriteFrame_name) {
  66. this.sprite.getComponent(cc.Sprite).spriteFrame = element;
  67. }
  68. });
  69. });
  70. // if (this.item_Attached_num == 0) {
  71. // //物品类型 品级 主属性类型 主属性数值
  72. // // 副属性条数 副属性类型 副属性数值
  73. // this.interfaceInfo.creatorItem(this.item_type, this.gradetype, this.item_master_type, this.item_master_value,
  74. // this.item_Attached_num, this._prop_name(this.item_Attached_type), this.gradetype_value(this.gradetype));
  75. // return;
  76. // } else {
  77. for (let i = 0; i < this.item_Attached_num; i++) {
  78. cc.loader.loadRes("prefab/Items/ProBgAdd", (err, prefab) => {
  79. this.item_Attached_type = this.random_num(0, 9);
  80. // console.log(this.item_Attached_num + "++++词条数+");
  81. // console.log(this.item_Attached_type + "+++++++随机值++++");
  82. // console.log(this._prop_name(this.item_Attached_type) + "+++词条名字+");
  83. // console.log(this.gradetype_value(this.gradetype) + "+++++词条数值+");
  84. let _attached = cc.instantiate(prefab);
  85. cc.find("Canvas/PanelResult/interface_Box/GameBg/ProAdd").addChild(_attached);
  86. _attached.children[0].getComponent(cc.Label).string = this._prop_name(this.item_Attached_type) + '+' + this.gradetype_value(this.gradetype);
  87. this.item_Attached_typeArr[i] = this.item_Attached_type;
  88. this.item_attached_nameArr[i] = this._prop_name(this.item_Attached_type);
  89. this.item_attached_valueArr[i] = this.gradetype_value(this.gradetype);
  90. });
  91. }
  92. this.interfaceInfo.creatorItem(this.item_type, this.gradetype, this.item_master_type, this.item_master_value,
  93. this.item_Attached_num, this.item_attached_nameArr, this.item_Attached_typeArr, this.item_attached_valueArr);
  94. // }
  95. },
  96. // update (dt) {},
  97. init() {
  98. this.itemtorScrop = cc.find("Canvas/ItemController").getComponent("ItemController");
  99. this.interfaceInfo = cc.find("Canvas/Interface_Info").getComponent("Interface_Info"); //角色数据界面脚本
  100. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  101. },
  102. _prop_name(propnum) { //属性名字
  103. if (propnum == 0) return "攻击";
  104. if (propnum == 1) return "连击率";
  105. if (propnum == 2) return "防御";
  106. if (propnum == 3) return "血量";
  107. if (propnum == 4) return "蓝量";
  108. if (propnum == 5) return "格挡回血量";
  109. if (propnum == 6) return "暴击率";
  110. if (propnum == 7) return "闪避回蓝量";
  111. if (propnum == 8) return "被动回蓝";
  112. if (propnum == 9) return "被动回血";
  113. },
  114. gradetype_value(gradetype) {
  115. if (gradetype == 0) {
  116. return;
  117. } else {
  118. return this.random_num(1, gradetype);
  119. }
  120. // if (gradetype == 2) {
  121. // return this.random_num(1, 2);
  122. // }
  123. // if (gradetype == 3) {
  124. // return this.random_num(1, 3);
  125. // }
  126. // if (gradetype == 4) {
  127. // return this.random_num(1, 3);
  128. // }
  129. }
  130. });