| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795 |
- import { HTTP_TYPE } from "../datas/CommonData";
- import { FightData, FightResult, FightRole } from "../datas/FightData";
- import { MateData } from "../datas/MateData";
- import { RichData } from "../datas/RichData";
- import { GameController } from "../manager/GameController";
- import GameM, { AUDIO_TYPE } from "../manager/GameM";
- import GuideMng from "../manager/GuideMng";
- import HttpM from "../manager/HttpM";
- import UiM from "../manager/UiM";
- import { EventMng } from "../tools/EventMng";
- import MyExtends, { EaseType, PlayerPrefs } from "../tools/MyExtends";
- import Time from "../tools/Time";
- import BasePanel from "../uiFrames/BasePanel";
- import UIMng, { PanelType } from "../uiFrames/UIMng";
- import LogUtil from "../utils/LogUtil";
- import Random from "../utils/Random";
- import { Utils } from "../utils/Utils";
- import EffectNode from "./EffectNode";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class FightPanel extends BasePanel {
- //武将战斗界面
- @property(cc.Node)
- panelNode: cc.Node = null;
- @property(cc.Node)
- touchNode: cc.Node = null;
- @property(cc.Sprite)
- blood_white: cc.Sprite = null;
- @property(cc.Sprite)
- blood: cc.Sprite = null;
- @property(cc.Label)
- blood_txt: cc.Label = null;
- @property(cc.Sprite)
- timeSlider: cc.Sprite = null;
- @property(cc.Sprite)
- headImg: cc.Sprite = null;
- @property(cc.Label)
- txtHeadLv: cc.Label = null;
- @property(cc.Label)
- txtTime: cc.Label = null;
- @property(cc.Label)
- txtName: cc.Label = null;
- @property(cc.Label)
- txtLv: cc.Label = null;
- @property(cc.Node)
- stars: cc.Node[] = [];
- @property(cc.Sprite)
- roleImg: cc.Sprite = null;
- @property(cc.Node)
- wordsNode: cc.Node = null;
- @property(cc.Label)
- txtWords: cc.Label = null;
- @property(sp.Skeleton)
- ani_getblood: sp.Skeleton = null;
- @property(sp.Skeleton)
- ani_defense: sp.Skeleton = null;
- //@property(cc.Node)
- //btnClose: cc.Node = null;
- @property(cc.Label)
- txtDamage: cc.Label = null;
- @property(cc.Node)
- damageCrit: cc.Node = null;
- @property(cc.Node)
- damageDodge: cc.Node = null;
- @property(cc.Node)
- damageResist: cc.Node = null;
- @property(sp.Skeleton)
- attack: sp.Skeleton = null;
- @property(cc.Node)
- flawEft: cc.Node = null;
- @property(cc.Label)
- flawTxt: cc.Label = null;
- private canvas: cc.Node = null;
- private damageInitPos: cc.Vec2 = null;
- private roleInitPos: cc.Vec2 = null;
- private fightRole: FightRole = null;
- /*
- {
- curRoleIndex :0,
- curRole: any,
- curRoleLv: 1,
- curRoleStar: 1,
- curRoleBlood: 10,
- curRoleTime: 30,
- curRoleBuffId: 10
- }
- */
- /*
- buffType = 1 回春 每秒回复 buff.effect.blood 血量 持续 buff.effect.time 秒
- buffType = 2 坚甲 受到的伤害减半 持续 buff.effect.time 秒
- buffType = 3 矫健 闪避率提升 buff.effect.rate 持续 buff.effect.time 秒
-
- */
- private roleBlood: number = 10;
- /**buff库id-武将buff触发时*/
- private buffIds: number[] = null;
- /**buff触发-武将剩余血量剩余百分比*/
- private buffTriggerBloods: number[] = null;
- /**当前 buff 触发索引*/
- private curBuffTriggerIndex: number = 0;
- private buff: any = null;
- /**1 回春 2 坚甲 3 矫健*/
- private buffType: number = -1;
- /**buff效果每秒生效 计时器*/
- private buffTimer: number = 0;
- /**buff生效 计时器*/
- private buffHadTimer: number = 0;
- /**buff是否开始生效*/
- private buffIsUsed: boolean = false;
- /**是否开始战斗*/
- private isFighting: boolean = false;
- /**战斗计时器*/
- private fightTimer: number = 0;
- /**战斗攻击CD计时器*/
- private attackTimer: number = 0;
- /**攻击间隔时间*/
- private attackTime: number = 0.1;
- /**是否可以攻击*/
- private isCanAttack: boolean = false;
- private isWordsShowing: boolean = false;
- onLoad() {
- this.touchNode.on(cc.Node.EventType.TOUCH_START, this.OnTouchAttak, this);
- this.damageInitPos = this.txtDamage.node.getPosition();
- this.roleInitPos = this.roleImg.node.getPosition();
- this.canvas = cc.find("Canvas");
- EventMng.Register_Event("UseFlawEffect", this.UseFlawEffect, this);
- }
- OnEnter(param: any) {
- this.node.setPosition(0, 0,);
- this.roleImg.node.scale = 1.1;
- this.fightRole = param;
- this.UpdateRoleInfo();
- this.node.active = true;
- this.node.setSiblingIndex(this.node.parent.childrenCount - 1);
- GameM.audioM.setPauseMusic();
- GameM.audioM.playMateEffect(AUDIO_TYPE.fightBgm, true);
- if (GuideMng.Ins.CurGuideId == 4 && PlayerPrefs.GetInt("GGuide4", 0) != 1) {
- GuideMng.Ins.ResumeGuide();
- }
- }
- OnExit() {
- this.roleImg.spriteFrame = null;
- this.node.active = false;
- if (this.ani_defense.node.active)
- this.ani_defense.node.active = false;
- if (this.ani_getblood.node.active)
- this.ani_getblood.node.active = false;
- if (this.wordsNode.active) {
- this.wordsNode.stopAllActions();
- this.wordsNode.active = false;
- }
- GameController.Ins.SwitchAudio(1);
- //GameM.audioM.setResumeMusic();
- //if (GameM.audioM.IsMatePlayingEffect())
- // GameM.audioM.stopMateEffect();
- }
- update(dt) {
- this.FightTimerUpdate(dt);
- this.ExecuteBuff(dt);
- }
- UpdateRoleInfo() {
- cc.loader.loadRes('carPic/side/side_' + this.fightRole.lv, cc.SpriteFrame, (err, asset) => {
- this.roleImg.spriteFrame = asset;
- });
- //cc.loader.loadRes('carPic/head/head_' + this.fightRole.lv, cc.SpriteFrame, (err, asset) => {
- // this.headImg.spriteFrame = asset;
- //});
- this.roleImg.node.color = cc.Color.WHITE;
- this.txtName.string = this.fightRole.name;
- this.txtHeadLv.string = this.fightRole.lv + "";
- this.txtLv.string = "Lv" + this.fightRole.lv;
- //客户端功能 获取buff
- let cfg = GameM.commonData.fightRoleCfg[this.fightRole.lv.toString()];
- this.buffIds = cfg.buffbag_id;
- this.buffTriggerBloods = cfg.bufftrigger_bloods;
- this.curBuffTriggerIndex = 0;
- this.isWordsShowing = false;
- FightData.Ins.flawCurNum = 0;
- this.DiaplayLevelInfo();
- }
- /**显示武将星级相关信息*/
- DiaplayLevelInfo() {
- //星级
- for (let i = 0; i < this.stars.length; i++) {
- this.stars[i].active = false;
- //星级不显示
- //if (i + 1 <= this.fightRole.star) {
- // this.stars[i].active = true;
- //}
- }
- this.blood_white.fillRange = 1;
- this.blood.fillRange = 1;
- this.roleBlood = this.fightRole.blood;
- this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
- //获取武将buff 弃用 改在战斗中减血 获取并使用buff
- this.buff = GameM.commonData.buffCfg[this.fightRole.buffId.toString()];
- this.buffType = this.buff.buff_type;
- this.buffTimer = 0;
- this.buffHadTimer = 0;
- this.fightTimer = this.fightRole.fightTime;
- this.attackTimer = 0;
- this.blood.fillRange = this.roleBlood / this.fightRole.blood;
- this.txtTime.string = MyExtends.TimeToFormat(this.fightTimer) + "s";
- this.timeSlider.fillRange = 1;
- console.log("Role:", this.fightRole);
- //改用武将血量较少到相应值时 获取并生效
- //this.buffIsUsed = true;
- this.isCanAttack = true;
- this.isFighting = true;
- }
- /**buff计时器 或 buff效果执行*/
- ExecuteBuff(dt) {
- if (!this.isFighting || !this.buffIsUsed) return;
- if (this.buffType == 1) {
- //buff效果计时 效果执行 回血
- this.buffHadTimer += dt;
- if (this.roleBlood > 0 && this.roleBlood < this.fightRole.blood) {
- if (this.buffHadTimer < this.buff.effect.time) {
- this.buffTimer += dt;
- if (this.buffTimer >= 1) {
- this.buffTimer = 0;
- this.roleBlood += this.buff.effect.blood;
- if (this.roleBlood >= this.fightRole.blood) this.roleBlood = this.fightRole.blood;
- this.blood.fillRange = this.roleBlood / this.fightRole.blood;
- this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
- cc.Tween.stopAllByTarget(this.blood_white);
- this.blood_white.fillRange = this.blood.fillRange;
- }
- } else {
- this.buffIsUsed = false; //buff 回血 效果结束
- this.ani_getblood.node.active = false;
- //this.ani_getblood.setAnimation(0, "animation2", false);
- }
- }
- } else if (this.buffType == 2) {
- //buff效果计时
- this.buffHadTimer += dt;
- if (this.buffHadTimer > this.buff.effect.time) {
- this.buffIsUsed = false; //buff 坚甲 效果结束
- this.ani_defense.node.active = false;
- //this.ani_defense.setAnimation(0, "animation", false);
- }
- } else if (this.buffType == 3) {
- //buff效果计时
- this.buffHadTimer += dt;
- if (this.buffHadTimer > this.buff.effect.time) {
- this.buffIsUsed = false; //buff 闪避 效果结束
- }
- }
- }
- /**检测武将buff*/
- CheckRoleBuff() {
- if (!this.isFighting && this.curBuffTriggerIndex < this.buffTriggerBloods.length) return;
- if (this.roleBlood <= this.buffTriggerBloods[this.curBuffTriggerIndex] * 0.01 * this.fightRole.blood) {
- console.log("RoleBlood:" + this.roleBlood + " Trigger:" + this.buffTriggerBloods[this.curBuffTriggerIndex]);
- let curRoleBuffId = 1;
- let buffrandom = Random.Range(0, 100, false);
- let buffbag = GameM.commonData.buffbagCfg[this.buffIds[this.curBuffTriggerIndex].toString()];
- let temprate = 0;
- for (let i = 0; i < buffbag.buff_rate.length; i++) {
- temprate += buffbag.buff_rate[i];
- if (buffrandom <= temprate) {
- curRoleBuffId = buffbag.id[i];
- break;
- }
- }
- this.curBuffTriggerIndex++;
- //获取武将buff
- this.buff = GameM.commonData.buffCfg[curRoleBuffId.toString()];
- //this.buff = GameM.commonData.buffCfg["3"];
- this.buffType = this.buff.buff_type;
- this.buffTimer = 0;
- this.buffHadTimer = 0;
- console.log("__GetBuff:" + JSON.stringify(this.buff));
- //buff开始生效
- this.buffIsUsed = true;
- if (this.ani_defense.node.active)
- this.ani_defense.node.active = false;
- if (this.ani_getblood.node.active)
- this.ani_getblood.node.active = false;
- if (this.buffType == 1) {
- this.ani_getblood.node.active = true;
- this.ani_getblood.setAnimation(0, "animation2", true);
- } else if (this.buffType == 2) {
- this.ani_defense.node.active = true;
- this.ani_defense.setAnimation(0, "animation", true);
- } else if (this.buffType == 3) {
- //左右闪躲表现
- }
- }
- }
- /**检测武将遗言*/
- CheckRoleWords() {
- if (!this.isFighting || this.isWordsShowing) return;
- if (this.roleBlood <= 0.8 * this.fightRole.blood) {
- if (Random.Range(0, 100, false) <= 5) {
- this.ShowWords(1);
- }
- } else if (this.roleBlood <= 0.3 * this.fightRole.blood) {
- if (Random.Range(0, 100, false) <= 5) {
- this.ShowWords(2);
- }
- }
- }
- ShowWords(type: number) {
- this.wordsNode.stopAllActions();
- this.wordsNode.scale = 0;
- this.wordsNode.active = true;
- this.txtWords.string = FightData.Ins.GetWords(type);
- this.isWordsShowing = true;
- let a1 = cc.scaleTo(0.2, 1).easing(cc.easeBackOut());
- let a2 = cc.delayTime(2);
- let a3 = cc.callFunc(() => { this.wordsNode.active = false; this.isWordsShowing = false; });
- this.wordsNode.runAction(cc.sequence(a1, a2, a3));
- }
- /**战斗计时器*/
- FightTimerUpdate(dt) {
- if (this.isFighting) {
- this.FightTimer(dt);
- if (!this.isCanAttack) {
- this.attackTimer += dt;
- if (this.attackTimer >= this.attackTime) {
- this.isCanAttack = true;
- this.attackTimer = 0;
- }
- }
- }
- }
- FightTimer(time) {
- this.fightTimer -= time;
- if (this.fightTimer <= 0) this.fightTimer = 0;
- //console.log("Timer:" + this.fightTimer);
- this.txtTime.string = MyExtends.TimeToFormat(this.fightTimer);
- this.timeSlider.fillRange = this.fightTimer / this.fightRole.fightTime;
- if (this.fightTimer <= 0) {
- this.isFighting = false;
- this.txtTime.string = "00:00";
- //战斗结束
- console.log("战斗结束");
- this.FightResult(false);
- }
- }
- /**获取最终伤害 播放boss受击动画 使用buff buffType = 1 自动在update中执行*/
- GetDamage(attackDamage: number) {
- //buff效果执行
- let damage = attackDamage;
- //先计算是否受到暴击伤害
- //悟空天赋2
- //damage = Random.Range(0, 100) < MateData.Ins.Mate2Talent2 ? damage * 2 : damage;
- if (Random.Range(0, 100) < MateData.Ins.Mate2Talent2) {
- damage *= 2;
- this.PlayBuffEffect(1);
- this.txtDamage.node.color = cc.color(255, 0, 0);
- this.PlayBossAni(1);
- } else {
- //damage *= 2;
- this.txtDamage.node.color = cc.color(255, 230, 0);
- //this.PlayBossAni(0);
- }
- if (this.buffIsUsed) {
- if (this.buffType == 2) {
- damage *= 0.5; //坚甲 抵抗 伤害减半
- this.PlayBuffEffect(2);
- GameM.audioM.playEffect(AUDIO_TYPE.resist);
- EffectNode.instance.PlayTip("武将防御中,挑战时间-3秒,请暂停攻击!");
- this.FightTimer(3);
- } else if (this.buffType == 3) { //矫健 闪避 概率触发闪避
- if (Random.Range(0, 100, false) <= this.buff.effect.rate) {
- damage = 0;
- this.PlayBuffEffect(3);
- this.PlayBossAni(2);
- GameM.audioM.playEffect(AUDIO_TYPE.dodge);
- } else {
- this.PlayBossAni(0);
- }
- } else {
- this.PlayBossAni(0);
- }
- } else {
- this.PlayBossAni(0);
- }
- return Math.floor(damage);
- //return damage;
- }
- /**伤害动画*/
- PlayDamageAni(num: number) {
- this.txtDamage.string = "-" + num;
- //this.txtDamage.node.active = true;
- this.txtDamage.node.setPosition(this.damageInitPos);
- this.txtDamage.node.scale = 0.5;
- let copy = cc.instantiate(this.txtDamage.node);
- this.canvas.addChild(copy);
- copy.active = true;
- //this.panelNode.addChild(copy);
- let a1 = cc.spawn(cc.scaleTo(0.5, 1.5), cc.moveTo(0.5, cc.v2(this.damageInitPos.x + 110, this.damageInitPos.y + 150)));
- let a2 = cc.fadeOut(0.5);
- let a3 = cc.callFunc(() => { copy.destroy() });
- copy.runAction(cc.sequence(a1, a2, a3));
- //this.roleImg.node.color=cc.Color.RED;
- //this.roleImg.node.stopAllActions();
- //this.roleImg.node.runAction(cc.sequence(cc.tintTo(0.2, 255, 0, 0), cc.tintTo(0.2, 255, 255, 255)));
- }
- /**Buff效果 1 暴击 2 抵抗 3 闪避*/
- async PlayBuffEffect(type: number) {
- let temp: cc.Node = null;;
- if (type == 1) {
- temp = cc.instantiate(this.damageCrit);
- }
- else if (type == 2) {
- temp = cc.instantiate(this.damageResist);
- }
- else if (type == 3) {
- temp = cc.instantiate(this.damageDodge);
- }
- this.canvas.addChild(temp);
- temp.active = true;
- await Time.WaitForSeconds(1);
- temp.destroy();
- }
- /**
- * 播放Boss反馈动画
- * @param type 动画类型 0 普通 1 暴击 2 闪避
- */
- PlayBossAni(type: number) {
- if (type == 0) {
- cc.Tween.stopAllByTarget(this.roleImg.node);
- this.roleImg.node.setPosition(0, this.roleImg.node.y);
- cc.tween(this.roleImg.node)
- .to(0.05, { scale: 1.3, color: cc.color(255, 0, 0) })
- .to(0.05, { scale: 1.1, color: cc.color(255, 255, 255) })
- .start();
- } else if (type == 1) {
- this.PlayCritAni();
- } else if (type == 2) {
- this.PlayDodgeAni();
- }
- }
- /**
- * 战斗结果
- * @param isSuccess 是否战斗胜利
- */
- FightResult(isSuccess: boolean) {
- let result = new FightResult();
- result.fightType = this.fightRole.fightType;
- result.lv = this.fightRole.lv;
- if (isSuccess) {
- result.result = 1;
- console.log("FinishBattle");
- let param = {
- battleId: this.fightRole.fightId,
- battleResult: result.result,
- battleSeconds: this.fightRole.fightTime - this.fightTimer,
- battleType: this.fightRole.fightType,
- bossCode: this.fightRole.lv,
- version: GameM.commonData.version
- };
- if (this.fightRole.fightType == 1 || this.fightRole.fightType == 2) {
- HttpM.Instance.SendData(HTTP_TYPE.finishBattle
- , param, (res) => {
- //LogUtil.logV("-->FightFinished:", JSON.stringify(res));
- console.log("-->FightFinished:", res);
- if (res.data != null) {
- result.rewards = res.data.awards;
- result.talent = res.data.stone != null ? res.data.stone : 0;
- result.star = res.data.star_level;
- result.unlock_mateid = res.data.partner_id;
- result.reward_times = this.fightRole.fightType == 1 ? 0 : res.data.todayTimes;
- result.fightId = this.fightRole.fightId;
- //FightData.Ins.rewardTimes = res.data.todayTimes;
- //if (this.fightRole.fightType)
- MyExtends.WaitTimeForCallback(0.5, () => {
- this.OnExit();
- UIMng.Ins.AsyncGetPanel(PanelType.FightResultPanel, (panel) => {
- panel.OnEnter(result);
- });
- //UIMng.Ins.GetPanel(PanelType.FightResultPanel).OnEnter(result);
- //调用结算接口 服务器自动处理
- //移除服务器武将队列对应武将数据
- //if (this.fightRole.fightType == 1) {
- // FightData.Ins.RemoveRole(this.fightRole.arrayIndex);
- //}
- });
- } else {
- console.log("error:" + res.errmsg);
- }
- }, null, null, true);
- } else {
- //大富翁战斗结果
- HttpM.Instance.SendData(HTTP_TYPE.richManBossReward, { type: RichData.Ins.masterType }, (res) => {
- console.log("--->boss rewards:", res);
- if (res.data != null) {
- result.rewards = res.data.rewardsInfo;
- result.talent = 0;
- //战斗三 大富翁战斗 默认显示最高级宝箱)
- result.star = 3;
- result.unlock_mateid = "";
- result.reward_times = 0;
- result.fightId = "";
- //FightData.Ins.rewardTimes = res.data.todayTimes;
- //if (this.fightRole.fightType)
- MyExtends.WaitTimeForCallback(0.5, () => {
- this.OnExit();
- UIMng.Ins.AsyncGetPanel(PanelType.FightResultPanel, (panel) => {
- panel.OnEnter(result);
- });
- //UIMng.Ins.GetPanel(PanelType.FightResultPanel).OnEnter(result);
- //调用结算接口 服务器自动处理
- //移除服务器武将队列对应武将数据
- //if (this.fightRole.fightType == 1) {
- // FightData.Ins.RemoveRole(this.fightRole.arrayIndex);
- //}
- });
- } else {
- console.log("error:" + res.errmsg);
- }
- }, null, null, null, false);
- }
- //result.rewardId = this.fightRole.rewardId;
- } else {
- result.result = 0;
- result.talent = 0;
- result.star = 1;
- result.unlock_mateid = null;
- result.reward_times = 0;
- result.fightId = this.fightRole.fightId;
- //result.rewardId = this.fightRole.rewardId;
- MyExtends.WaitTimeForCallback(0.5, () => {
- this.OnExit();
- UIMng.Ins.AsyncGetPanel(PanelType.FightResultPanel, (panel) => {
- panel.OnEnter(result);
- });
- //UIMng.Ins.GetPanel(PanelType.FightResultPanel).OnEnter(result);
- //调用结算接口 服务器自动处理
- //移除服务器武将队列对应武将数据
- //if (this.fightRole.fightType == 1) {
- // FightData.Ins.RemoveRole(this.fightRole.arrayIndex);
- //}
- });
- }
- }
- PlayDodgeAni() {
- this.roleImg.node.stopAllActions();
- let pos = this.roleInitPos;
- this.roleImg.node.runAction(
- cc.sequence(
- cc.moveTo(0.04, cc.v2(pos.x + -80, pos.y)),
- cc.moveTo(0.08, cc.v2(pos.x + 80, pos.y)),
- cc.moveTo(0.04, cc.v2(pos.x, pos.y))
- )
- );
- }
- PlayCritAni() {
- this.roleImg.node.stopAllActions();
- let pos = this.roleInitPos;
- GameController.Ins.PlayShock(this.roleImg.node, pos);
- //this.roleImg.node.runAction(
- // //cc.repeatForever(
- // cc.sequence(
- // cc.moveTo(0.02, cc.v2(pos.x + 5, pos.y + 7)),
- // cc.moveTo(0.02, cc.v2(pos.x + -6, pos.y + 7)),
- // cc.moveTo(0.02, cc.v2(pos.x + -13, pos.y + 3)),
- // cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + -6)),
- // cc.moveTo(0.02, cc.v2(pos.x + -5, pos.y + 5)),
- // cc.moveTo(0.02, cc.v2(pos.x + 2, pos.y + -8)),
- // cc.moveTo(0.02, cc.v2(pos.x + -8, pos.y + -10)),
- // cc.moveTo(0.02, cc.v2(pos.x + 3, pos.y + 10)),
- // cc.moveTo(0.02, cc.v2(pos.x + 0, pos.y + 0))
- // )
- // //)
- //);
- }
- async CheckTriggerFlaw() {
- //let rate=Random.Range(0, 100, false);
- //console.log("---Rate:"+rate);
- if (Random.Range(0, 100, false) < FightData.Ins.flawRate && FightData.Ins.flawCurNum < FightData.Ins.flawNum) {
- FightData.Ins.flawCurNum++;
- let copy: cc.Node = cc.instantiate(await Utils.loadResPromise("prefabs/Flaw"));
- copy.scale = 0;
- copy.parent = this.node;
- let dir = cc.v2(Random.Range(-1, 1, false), Random.Range(-1, 1, false));
- dir = dir.normalize();
- let deltaInit = cc.v2(Random.Range(180, 220, false) * dir.x, Random.Range(180, 220, false) * dir.y);
- let initPos = cc.v2(this.roleImg.node.x, this.roleImg.node.y + 200).add(deltaInit);
- //let pos=cc.v2(this.roleImg.node.x, this.roleImg.node.y + 200).normalize();
- //cc.Vec2.normalize(pos,cc.v2(this.roleImg.node.x, this.roleImg.node.y + 200));
- copy.setPosition(this.roleImg.node.x, this.roleImg.node.y + 200);
- //copy.setPosition(pos);
- //let b = cc.repeatForever(
- // cc.sequence(
- // cc.moveBy(0.5, cc.v2(0, 20)),
- // cc.moveBy(0.5, cc.v2(0, -20))
- // )
- //);
- let a1 = cc.spawn(
- //cc.jumpTo(0.2, cc.v2(Random.Range(-280, 280), 320), 200, 1),
- cc.jumpTo(0.2, initPos, 200, 1),
- cc.scaleTo(0.2, 1)
- )
- //let a2 = cc.callFunc(() => {
- // copy.runAction(b);
- //}, this);
- //copy.runAction(cc.sequence(a1, a2));
- copy.runAction(a1);
- //this.transitNode = copy.getComponent(TransitNode);
- }
- }
- /**使用破绽技能
- * @param blood 扣除的血量
- */
- UseFlawEffect(num: number) {
- let blood = Math.floor(num * Random.Range(2, 5, false) * (Random.Range(15, 21) + MateData.Ins.Mate2Talent1));
- this.roleBlood -= blood;
- if (this.roleBlood <= 0) {
- this.roleBlood = 0;
- console.log("战斗胜利");
- this.isFighting = false;
- this.FightResult(true);
- }
- this.blood.fillRange = this.roleBlood / this.fightRole.blood;
- this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
- cc.tween(this.blood_white).to(0.2, { fillRange: this.blood.fillRange }).start();
- GameController.Ins.PlayShock(this.node, cc.v2(0, 0));
- this.flawEft.active = false;
- this.flawTxt.string = "-" + blood;
- let eft = cc.instantiate(this.flawEft);
- eft.active = true;
- eft.parent = this.node;
- eft.setPosition(0, 170);
- let a = cc.moveTo(0.5, cc.v2(0, 350));
- let b1 = cc.delayTime(1);
- let b2 = cc.fadeOut(0.1);
- let b3 = cc.callFunc(() => { eft.destroy(); });
- let b = cc.sequence(b1, b2, b3);
- eft.runAction(cc.spawn(a, b));
- GameM.audioM.playEffect(AUDIO_TYPE.flaw);
- GameController.Ins.Shock(300);
- }
- /**点击屏幕攻击武将*/
- OnTouchAttak() {
- //console.log("attack role");
- if (!this.isFighting) return;
- if (this.isCanAttack) {
- this.isCanAttack = false;
- //悟空天赋1
- let tempDamage = Random.Range(15, 21) + MateData.Ins.Mate2Talent1;
- //let tempDamage = Random.Range(3, 5) + MateData.Ins.Mate2Talent1;
- //let damage = this.GetDamage(20);
- let damage = this.GetDamage(tempDamage);
- if (damage == 0) {
- //console.log("闪避");
- //this.PlayDodgeAni();
- } else {
- this.roleBlood -= damage;
- this.PlayDamageAni(damage);
- if (this.roleBlood <= 0) {
- this.roleBlood = 0;
- //console.log("战斗胜利");
- this.isFighting = false;
- this.FightResult(true);
- //判断fightRole.fightType = 1 的话 将该武将从队列中移除
- } else {
- //检测buff
- this.CheckRoleBuff();
- this.CheckRoleWords();
- this.CheckTriggerFlaw();
- }
- }
- this.blood.fillRange = this.roleBlood / this.fightRole.blood;
- this.blood_txt.string = this.roleBlood + "/" + this.fightRole.blood;
- cc.tween(this.blood_white).to(0.2, { fillRange: this.blood.fillRange }).start();
- if (Random.GetBool()) {
- GameM.audioM.playEffect(AUDIO_TYPE.attack1);
- } else {
- GameM.audioM.playEffect(AUDIO_TYPE.attack2);
- }
- let eftpos = cc.v2(Random.Range(-180, 180), Random.Range(-180, 180));
- this.attack.node.setPosition(eftpos);
- this.attack.node.scale = Random.Range(0.5, 1.3, false);
- this.attack.clearTrack(0);
- this.attack.setAnimation(0, "animation", false);
- //let type = Random.Range(1, 4);
- //if (type == 1) {
- // this.attack.setAnimation(0, "animation", false);
- //} else if (type == 2) {
- // this.attack.setAnimation(0, "animation2", false);
- //} else {
- // this.attack.setAnimation(0, "animation3", false);
- //}
- GameController.Ins.Shock(50);
- }
- }
- Click_CloseBtn() {
- this.isFighting = false;
- this.OnExit();
- }
- }
|