TalentItem.ts 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. import { HTTP_TYPE } from "../../datas/CommonData";
  2. import { MateData, TalentItemParam } from "../../datas/MateData";
  3. import AdM from "../../manager/AdM";
  4. import GameM, { AUDIO_TYPE } from "../../manager/GameM";
  5. import HttpM from "../../manager/HttpM";
  6. import { EventMng } from "../../tools/EventMng";
  7. import EffectNode from "../../ui/EffectNode";
  8. import LogUtil from "../../utils/LogUtil";
  9. const { ccclass, property } = cc._decorator;
  10. @ccclass
  11. export default class TalentItem extends cc.Component {
  12. @property(cc.Sprite)
  13. img: cc.Sprite = null;
  14. @property(cc.Label)
  15. txtName: cc.Label = null;
  16. @property(cc.Label)
  17. txtLv: cc.Label = null;
  18. @property(cc.RichText)
  19. txtRichDes: cc.RichText = null;
  20. @property(cc.Label)
  21. txtTalent: cc.Label = null;
  22. @property(cc.Node)
  23. btnLocked: cc.Node = null;
  24. @property(cc.Node)
  25. btnUnlock: cc.Node = null;
  26. @property(cc.Node)
  27. btnNoCoin: cc.Node = null;
  28. @property(cc.Node)
  29. btnMax: cc.Node = null;
  30. @property(cc.Label)
  31. btn_txt: cc.Label = null;
  32. @property(sp.Skeleton)
  33. eft: sp.Skeleton = null;
  34. private talentData: TalentItemParam = null;
  35. private isLoadImg: boolean = false;
  36. onDisable() {
  37. this.eft.node.active = false;
  38. }
  39. onEnable() {
  40. if (this.img.spriteFrame == null && this.talentData != null) {
  41. cc.loader.loadRes("xiyou/talent/" + this.talentData.mateId + "-" + this.talentData.id, cc.SpriteFrame, (err, res) => {
  42. if (err) {
  43. cc.error(err);
  44. return;
  45. }
  46. this.img.spriteFrame = res;
  47. });
  48. }
  49. }
  50. UpdateTalent(talentParam: TalentItemParam) {
  51. this.talentData = talentParam;
  52. if (talentParam.img != null) { }
  53. this.img.spriteFrame = talentParam.img;
  54. if (!this.isLoadImg) {
  55. cc.loader.loadRes("xiyou/talent/" + talentParam.mateId + "-" + talentParam.id, cc.SpriteFrame, (err, res) => {
  56. if (err) {
  57. cc.error(err);
  58. return;
  59. }
  60. this.img.spriteFrame = res;
  61. this.isLoadImg = true;
  62. });
  63. }
  64. this.txtName.string = talentParam.name;
  65. //this.txtLv.string = talentParam.lv + "";
  66. this.txtLv.string = "Lv" + talentParam.lv;
  67. let desStr = "<b><outline color=#4C0404 width=1.8>";
  68. for (let i = 0; i < talentParam.des.length; i++) {
  69. if (talentParam.des[i] == "now_value") {
  70. desStr += talentParam.uplevel_effect[talentParam.lv - 1] + (talentParam.effect_type == 1 ? "" : "%") + ""
  71. } else if (talentParam.des[i] == "next_value") {
  72. if (talentParam.lv < talentParam.uplevel_coin.length)
  73. desStr += "</outline><outline color=#19932F width=0><color=#0C9309>(下一级↑" + talentParam.uplevel_effect[talentParam.lv] + (talentParam.effect_type == 1 ? "" : "%") + ")</color></outline>";
  74. } else {
  75. desStr += "<outline color=#4C0404 width=1.8>" + talentParam.des[i] + "</outline>";
  76. }
  77. }
  78. desStr += "</b>";
  79. this.txtRichDes.string = desStr;
  80. if (talentParam.lv < talentParam.uplevel_coin.length)
  81. this.txtTalent.string = talentParam.uplevel_coin[talentParam.lv] + "";
  82. else
  83. this.txtTalent.string = "MAX";
  84. //this.txtRichDes.string = "<outline color=red width=2>"
  85. // + "对武将进行感化,武将每次产出金币"
  86. // + "+10"
  87. // + "</outline><outline color=red width=2>"
  88. // + "点"
  89. // + "</outline><color=#00FF00>(↑20)</color>"
  90. this.UpdateBtnState();
  91. }
  92. UpdateTalentSelf() {
  93. this.UpdateTalent(this.talentData);
  94. }
  95. UpdateBtnState() {
  96. let temp = this.talentData.isUnlock;
  97. this.btnLocked.active = !temp;
  98. this.btnUnlock.active = temp;
  99. this.btnNoCoin.active = temp && this.talentData.lv < this.talentData.uplevel_effect.length && MateData.Ins.talentCoin < this.talentData.uplevel_coin[this.talentData.lv]
  100. this.btnMax.active = this.talentData.lv >= this.talentData.uplevel_effect.length;
  101. this.btn_txt.string = temp ? "升级" : this.talentData.unlock_lv + "级解锁";
  102. }
  103. Click_UplvBtn() {
  104. if (this.talentData.isUnlock) {
  105. if (this.talentData.lv < this.talentData.uplevel_effect.length) {
  106. if (MateData.Ins.talentCoin >= this.talentData.uplevel_coin[this.talentData.lv]) {
  107. let param = {
  108. partnerId: this.talentData.mateId,
  109. talentId: this.talentData.id
  110. //version: GameM.commonData.version
  111. }
  112. //console.log("-->uplevel talent Param:", param);
  113. LogUtil.logV("-->uplevel talent p:", param)
  114. HttpM.Instance.SendData(HTTP_TYPE.upgradePartnerTalent,
  115. param, (res) => {
  116. LogUtil.logV("-->uplevel talent:", res)
  117. //console.log("-->uplevel talent:", res);
  118. if (res.data != null) {
  119. MateData.Ins.talentCoin -= this.talentData.uplevel_coin[this.talentData.lv]
  120. this.UpLevelTalent();
  121. EventMng.Execute_Event("UpdateCurrency");
  122. this.eft.clearTrack(0);
  123. this.eft.node.active = true;
  124. this.eft.setAnimation(0, "animation", false);
  125. this.unschedule(this.ScheduleCloseEft);
  126. this.scheduleOnce(this.ScheduleCloseEft, 1);
  127. EffectNode.instance.PlayTip(`升级成功`);
  128. // AdM.onSendEvent(`talant_up_${this.talentData.mateId}_${this.talentData.id}`, `天赋${this.talentData.mateId}_${this.talentData.id}升级成功`, 'talant_up')
  129. }
  130. })
  131. //检查本角色 天赋的解锁情况 弃用
  132. //EventMng.Execute_Event("CheckMateTalentUnlock", this.talentData.mateId);
  133. GameM.audioM.playEffect(AUDIO_TYPE.talent);
  134. } else {
  135. console.log("天赋石不足");
  136. EffectNode.instance.PlayTip(`天赋石不足,可在转盘中获得哦!`);
  137. }
  138. } else {
  139. console.log("你已达最高等级");
  140. EffectNode.instance.PlayTip(`你已达最高等级`);
  141. }
  142. } else {
  143. console.log("你还未解锁该天赋")
  144. EffectNode.instance.PlayTip(`你还未解锁该天赋`);
  145. }
  146. GameM.audioM.playEffect(AUDIO_TYPE.button);
  147. }
  148. /**升级天赋*/
  149. UpLevelTalent() {
  150. this.talentData.lv++;
  151. this.txtLv.string = "Lv" + this.talentData.lv;
  152. let desStr = "<b><outline color=#4C0404 width=1.8>";
  153. for (let i = 0; i < this.talentData.des.length; i++) {
  154. if (this.talentData.des[i] == "now_value") {
  155. desStr += this.talentData.uplevel_effect[this.talentData.lv - 1] + (this.talentData.effect_type == 1 ? "" : "%") + ""
  156. } else if (this.talentData.des[i] == "next_value") {
  157. if (this.talentData.lv < this.talentData.uplevel_coin.length)
  158. desStr += "</outline><outline color=#19932F width=0><color=#0C9309>(下一级↑" + this.talentData.uplevel_effect[this.talentData.lv] + (this.talentData.effect_type == 1 ? "" : "%") + ")</color></outline>";
  159. } else {
  160. desStr += "<outline color=#4C0404 width=1.8>" + this.talentData.des[i] + "</outline>";
  161. }
  162. }
  163. desStr += "</b>";
  164. this.txtRichDes.string = desStr;
  165. if (this.talentData.lv < this.talentData.uplevel_coin.length)
  166. this.txtTalent.string = this.talentData.uplevel_coin[this.talentData.lv] + "";
  167. else
  168. this.txtTalent.string = "MAX";
  169. this.UpdateBtnState();
  170. MateData.Ins.LeveUpTalent(this.talentData.mateId, this.talentData.id);
  171. MateData.Ins.SaveMateTalent(this.talentData.mateId);
  172. //更新红点
  173. MateData.Ins.checkMateRedPoint()
  174. }
  175. /**解锁天赋*/
  176. UnlockTalent() {
  177. //this.talentData.isUnlock = true;
  178. //console.log("Unlock Talent:", this.talentData);
  179. console.log("————>解锁天赋:" + this.talentData.name + " Mate:" + this.talentData.mateId);
  180. this.talentData.lv = 1;
  181. this.UpdateTalent(this.talentData);
  182. MateData.Ins.GetMateTalent(this.talentData.mateId, this.talentData.id).isUnlock = true;
  183. MateData.Ins.SaveMateTalent(this.talentData.mateId);
  184. }
  185. PlayEft() {
  186. let copy = cc.instantiate(this.eft.node)
  187. }
  188. ScheduleCloseEft() {
  189. this.eft.node.active = false;
  190. }
  191. }