| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import { HTTP_TYPE } from "../../datas/CommonData";
- import { MateData, TalentItemParam } from "../../datas/MateData";
- import AdM from "../../manager/AdM";
- import GameM, { AUDIO_TYPE } from "../../manager/GameM";
- import HttpM from "../../manager/HttpM";
- import { EventMng } from "../../tools/EventMng";
- import EffectNode from "../../ui/EffectNode";
- import LogUtil from "../../utils/LogUtil";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class TalentItem extends cc.Component {
- @property(cc.Sprite)
- img: cc.Sprite = null;
- @property(cc.Label)
- txtName: cc.Label = null;
- @property(cc.Label)
- txtLv: cc.Label = null;
- @property(cc.RichText)
- txtRichDes: cc.RichText = null;
- @property(cc.Label)
- txtTalent: cc.Label = null;
- @property(cc.Node)
- btnLocked: cc.Node = null;
- @property(cc.Node)
- btnUnlock: cc.Node = null;
- @property(cc.Node)
- btnNoCoin: cc.Node = null;
- @property(cc.Node)
- btnMax: cc.Node = null;
- @property(cc.Label)
- btn_txt: cc.Label = null;
- @property(sp.Skeleton)
- eft: sp.Skeleton = null;
- private talentData: TalentItemParam = null;
- private isLoadImg: boolean = false;
- onDisable() {
- this.eft.node.active = false;
- }
- onEnable() {
- if (this.img.spriteFrame == null && this.talentData != null) {
- cc.loader.loadRes("xiyou/talent/" + this.talentData.mateId + "-" + this.talentData.id, cc.SpriteFrame, (err, res) => {
- if (err) {
- cc.error(err);
- return;
- }
- this.img.spriteFrame = res;
- });
- }
- }
- UpdateTalent(talentParam: TalentItemParam) {
- this.talentData = talentParam;
- if (talentParam.img != null) { }
- this.img.spriteFrame = talentParam.img;
- if (!this.isLoadImg) {
- cc.loader.loadRes("xiyou/talent/" + talentParam.mateId + "-" + talentParam.id, cc.SpriteFrame, (err, res) => {
- if (err) {
- cc.error(err);
- return;
- }
- this.img.spriteFrame = res;
- this.isLoadImg = true;
- });
- }
- this.txtName.string = talentParam.name;
- //this.txtLv.string = talentParam.lv + "";
- this.txtLv.string = "Lv" + talentParam.lv;
- let desStr = "<b><outline color=#4C0404 width=1.8>";
- for (let i = 0; i < talentParam.des.length; i++) {
- if (talentParam.des[i] == "now_value") {
- desStr += talentParam.uplevel_effect[talentParam.lv - 1] + (talentParam.effect_type == 1 ? "" : "%") + ""
- } else if (talentParam.des[i] == "next_value") {
- if (talentParam.lv < talentParam.uplevel_coin.length)
- desStr += "</outline><outline color=#19932F width=0><color=#0C9309>(下一级↑" + talentParam.uplevel_effect[talentParam.lv] + (talentParam.effect_type == 1 ? "" : "%") + ")</color></outline>";
- } else {
- desStr += "<outline color=#4C0404 width=1.8>" + talentParam.des[i] + "</outline>";
- }
- }
- desStr += "</b>";
- this.txtRichDes.string = desStr;
- if (talentParam.lv < talentParam.uplevel_coin.length)
- this.txtTalent.string = talentParam.uplevel_coin[talentParam.lv] + "";
- else
- this.txtTalent.string = "MAX";
- //this.txtRichDes.string = "<outline color=red width=2>"
- // + "对武将进行感化,武将每次产出金币"
- // + "+10"
- // + "</outline><outline color=red width=2>"
- // + "点"
- // + "</outline><color=#00FF00>(↑20)</color>"
- this.UpdateBtnState();
- }
- UpdateTalentSelf() {
- this.UpdateTalent(this.talentData);
- }
- UpdateBtnState() {
- let temp = this.talentData.isUnlock;
- this.btnLocked.active = !temp;
- this.btnUnlock.active = temp;
- this.btnNoCoin.active = temp && this.talentData.lv < this.talentData.uplevel_effect.length && MateData.Ins.talentCoin < this.talentData.uplevel_coin[this.talentData.lv]
- this.btnMax.active = this.talentData.lv >= this.talentData.uplevel_effect.length;
- this.btn_txt.string = temp ? "升级" : this.talentData.unlock_lv + "级解锁";
- }
- Click_UplvBtn() {
- if (this.talentData.isUnlock) {
- if (this.talentData.lv < this.talentData.uplevel_effect.length) {
- if (MateData.Ins.talentCoin >= this.talentData.uplevel_coin[this.talentData.lv]) {
- let param = {
- partnerId: this.talentData.mateId,
- talentId: this.talentData.id
- //version: GameM.commonData.version
- }
- //console.log("-->uplevel talent Param:", param);
- LogUtil.logV("-->uplevel talent p:", param)
- HttpM.Instance.SendData(HTTP_TYPE.upgradePartnerTalent,
- param, (res) => {
- LogUtil.logV("-->uplevel talent:", res)
- //console.log("-->uplevel talent:", res);
- if (res.data != null) {
- MateData.Ins.talentCoin -= this.talentData.uplevel_coin[this.talentData.lv]
- this.UpLevelTalent();
- EventMng.Execute_Event("UpdateCurrency");
- this.eft.clearTrack(0);
- this.eft.node.active = true;
- this.eft.setAnimation(0, "animation", false);
- this.unschedule(this.ScheduleCloseEft);
- this.scheduleOnce(this.ScheduleCloseEft, 1);
- EffectNode.instance.PlayTip(`升级成功`);
- // AdM.onSendEvent(`talant_up_${this.talentData.mateId}_${this.talentData.id}`, `天赋${this.talentData.mateId}_${this.talentData.id}升级成功`, 'talant_up')
- }
- })
- //检查本角色 天赋的解锁情况 弃用
- //EventMng.Execute_Event("CheckMateTalentUnlock", this.talentData.mateId);
- GameM.audioM.playEffect(AUDIO_TYPE.talent);
- } else {
- console.log("天赋石不足");
- EffectNode.instance.PlayTip(`天赋石不足,可在转盘中获得哦!`);
- }
- } else {
- console.log("你已达最高等级");
- EffectNode.instance.PlayTip(`你已达最高等级`);
- }
- } else {
- console.log("你还未解锁该天赋")
- EffectNode.instance.PlayTip(`你还未解锁该天赋`);
- }
- GameM.audioM.playEffect(AUDIO_TYPE.button);
- }
- /**升级天赋*/
- UpLevelTalent() {
- this.talentData.lv++;
- this.txtLv.string = "Lv" + this.talentData.lv;
- let desStr = "<b><outline color=#4C0404 width=1.8>";
- for (let i = 0; i < this.talentData.des.length; i++) {
- if (this.talentData.des[i] == "now_value") {
- desStr += this.talentData.uplevel_effect[this.talentData.lv - 1] + (this.talentData.effect_type == 1 ? "" : "%") + ""
- } else if (this.talentData.des[i] == "next_value") {
- if (this.talentData.lv < this.talentData.uplevel_coin.length)
- desStr += "</outline><outline color=#19932F width=0><color=#0C9309>(下一级↑" + this.talentData.uplevel_effect[this.talentData.lv] + (this.talentData.effect_type == 1 ? "" : "%") + ")</color></outline>";
- } else {
- desStr += "<outline color=#4C0404 width=1.8>" + this.talentData.des[i] + "</outline>";
- }
- }
- desStr += "</b>";
- this.txtRichDes.string = desStr;
- if (this.talentData.lv < this.talentData.uplevel_coin.length)
- this.txtTalent.string = this.talentData.uplevel_coin[this.talentData.lv] + "";
- else
- this.txtTalent.string = "MAX";
- this.UpdateBtnState();
- MateData.Ins.LeveUpTalent(this.talentData.mateId, this.talentData.id);
- MateData.Ins.SaveMateTalent(this.talentData.mateId);
- //更新红点
- MateData.Ins.checkMateRedPoint()
- }
- /**解锁天赋*/
- UnlockTalent() {
- //this.talentData.isUnlock = true;
- //console.log("Unlock Talent:", this.talentData);
- console.log("————>解锁天赋:" + this.talentData.name + " Mate:" + this.talentData.mateId);
- this.talentData.lv = 1;
- this.UpdateTalent(this.talentData);
- MateData.Ins.GetMateTalent(this.talentData.mateId, this.talentData.id).isUnlock = true;
- MateData.Ins.SaveMateTalent(this.talentData.mateId);
- }
- PlayEft() {
- let copy = cc.instantiate(this.eft.node)
- }
- ScheduleCloseEft() {
- this.eft.node.active = false;
- }
- }
|