2025-04-24 17:03:28 +08:00

1255 lines
33 KiB
JavaScript

import GameModel from "../../ts/core/GameModel";
import HSL from "../../ts/gear_2.3.4/shader/script/HSL";
import SKTimeUtil from "../../ts/gear_2.3.4/util/SKTimeUtil";
import WingUtil from "../../ts/wing/WingUtil";
import SKDataUtil from "../../ts/gear_2.3.4/util/SKDataUtil";
import SKUIUtil from "../../ts/gear_2.3.4/util/SKUIUtil";
import SkillUtil from "../../ts/game/skill/core/SkillUtil";
import { EffectPos, ESkillType } from "../../ts/game/skill/core/SkillBase";
import AudioUtil from "../../ts/core/AudioUtil";
import { ELivingType } from "../../ts/core/EEnum";
import GameUtil from "../../ts/core/GameUtil";
import VIPUtil from "../../ts/game/role/VIPUtil";
import ShapeUtil from "../../ts/shape/ShapeUtil";
import WeaponUtil from "../../ts/weapon/WeaponUtil";
import Baby from "../../ts/nurture/Baby";
let GameRes = require('../GameRes');
let CPubFunction = require('../PubFunction');
let pNpcMgr = require('../NpcMgr');
cc.Class({
extends: cc.Component,
properties: {
boyPrefab: {
default: [],
type: cc.Prefab
},
girlPrefab: {
default: [],
type: cc.Prefab
},
animationNode: cc.Node,
maskNode: cc.Node,
bodyEffNode: cc.Node,
RoleshadowNode: cc.Node,
shadowNode: cc.Node,
// animation: cc.Animation,
hpPorgress: cc.ProgressBar,
mpPorgress: cc.ProgressBar,
roleSpr: cc.Sprite,
nameRT: cc.Label,
_self: false,
isSelf: {
get() {
return this._self;
},
set(n) {
this._self = n;
this.mpPorgress.node.active = n;
}
},
_dir: 'up',
dir: {
set(n) {
this._dir = n;
}
},
roleAddonNode: cc.Node,//附加
roleAddonBehindNode: cc.Node,//身前附加
roleAddonFrontNode: cc.Node,//身後附加
effectLayer: cc.Node, //身前 buff
effectBg: cc.Node, //身後buff
actionEffect: cc.Node,
effect: cc.Prefab,
bufflayer: cc.Node,
buffprefab: cc.Prefab,
skillTitle: cc.Node,
skillLabel: cc.Label,
numPrefab: cc.Prefab,
selectFlag: cc.Node,
waitFlag: cc.Node,
weaponNode: cc.Node,
weaponNode1: cc.Node,
talkNode: cc.Node,
longChangRound: 0,
isYinShen: false,
iswait: {
get() {
return this.waitFlag ? this.waitFlag.active : false;
},
set(n) {
this.waitFlag && (this.waitFlag.active = n);
}
},
BabyNode: cc.Node
},
ctor() {
this.onlyid = 0;
this.resid = 0;
this.tResid = 0;
this.bodyEffid = 0;
this.hp = 0;
this.mp = 0;
this.maxhp = 0;
this.maxmp = 0;
this.isdead = 0;
this.objType = ELivingType.UNKNOW; //
this._dir = 'up'; // 0 self 1enemy
this.bufflist = {};
this.buffEffectList = {};
this.onSkillTarget = false;
this.stageLogic = null;
this.selectFunc = 0;
this.resUrl = '';
this.effectResList = [];
this.petColor = -1;
this.hpTimer = 0;
this.wingId = 0;
this.isLong = false;
this.isChange = false;
this.longChangRound = 0;
this.originResid = 0;
this.isYinShen = false;
this.weapon = null;
this.isleader = 0
this.starid = -1
},
start() {
if (this.resid == 0) {
this.objType = 1;
this.resid = 1001;
this.resAtlas = GameRes.getRoleRes(this.resid);
// this.initRoleAnimation();
}
let stage = cc.find('Canvas/BattleLayer/BattleStage');
this.stageLogic = stage.getComponent('BattleStage');
let spr = this.actionEffect.getComponent(cc.Sprite);
let ef_animation = this.actionEffect.getComponent(cc.Animation);
ef_animation.on('finished', () => {
// this.actionEffect.active = false;
spr.spriteFrame = null;
}, this);
let anchorinfo = GameModel.conf_res_anchor[this.resid];
if (anchorinfo) {
if (anchorinfo.anchorX) {
this.animationNode.anchorX = anchorinfo.anchorX;
this.maskNode.anchorX = anchorinfo.anchorX;
this.bodyEffNode.anchorX = anchorinfo.anchorX;
}
if (anchorinfo.anchorY) {
this.animationNode.anchorY = anchorinfo.anchorY;
this.maskNode.anchorY = anchorinfo.anchorY;
this.bodyEffNode.anchorY = anchorinfo.anchorY;
}
}
this.hsl = this.animationNode.getComponent(HSL);
if (this.isPet() && this.isYinShen) {
this.animationNode.opacity = 77;
if (this.hsl) {
this.hsl.dA = 0.3;
this.hsl.reset();
}
}
},
playEff(id) {
if (id == 0) {
this.bodyEffNode.active = false;
return
}
var name = `${id}`;
let anim = this.bodyEffNode.getComponent(cc.Animation);
if (!anim) {
return;
}
let clips = anim.getClips();
for (let clip of clips) {
if (clip.name == name) {
this.bodyEffNode.active = true;
this.bodyEffNode.getComponent(cc.Animation).play(name);
return;
}
}
this.bodyEffNode.active = false;
let self = this;
let url = `body_eff/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載角色動畫資源失敗${url}`);
return;
}
if (!SKUIUtil.isValid(self.bodyEffNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 10);
curClip.name = name;
curClip.wrapMode = cc.WrapMode.Loop;
let nodeAni = self.bodyEffNode.getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play(name);
}
self.bodyEffNode.active = true;
this.scheduleOnce(() => {
self.bodyEffNode.scaleX = 450 / self.bodyEffNode.width;
self.bodyEffNode.scaleY = 450 / self.bodyEffNode.height;
}, 0);
});
},
clear() {
this.animationNode.getComponent(cc.Animation).destroy();
},
onDestroy() {
// let deps = cc.loader.getDependsRecursively('Prefabs/Battle/BattleRole');
// cc.loader.release(deps);
// for (const resstr of this.effectResList) {
// cc.loader.releaseRes(resstr);
// }
if (GameUtil.roleName[this.resid] == null && pNpcMgr.CheckNpcRes(0, this.resid) == false) {
// cc.loader.releaseResDir(this.resUrl, cc.Texture2D);
// cc.loader.releaseResDir(this.resUrl, cc.SpriteFrame);
// cc.loader.releaseResDir(this.resUrl, cc.SpriteAtlas);
}
this.hpTimer = SKTimeUtil.cancelDelay(this.hpTimer);
this.checkTimer = SKTimeUtil.cancelDelay(this.checkTimer);
},
clean() {
this.node.destroy();
},
isPlayer() {
return this.objType == ELivingType.PLAYER;
},
isPet() {
return this.objType == ELivingType.PET;
},
isPartner() {
return this.objType == ELivingType.PARTNER;
},
isMonster() {
return this.objType == ELivingType.MONSTER;
},
sethp(hp) {
if (this.hpPorgress) {
this.hpPorgress.progress = hp / this.maxhp;
} else {
cc.log("error");
}
},
setmp(mp) {
if (this.mpPorgress) {
this.mpPorgress.progress = mp / this.maxmp;
} else {
cc.log("error");
}
},
hideHp() {
if (this.hpPorgress && this.hpPorgress.node) {
this.hpPorgress.node.active = false;
} else {
cc.log("error");
}
},
hideMp() {
if (this.mpPorgress && this.mpPorgress.node) {
this.mpPorgress.node.active = false;
} else {
cc.log("error");
}
},
setInfo(objinfo) {
console.log(objinfo)
this.onlyid = objinfo.onlyid;
this.resid = objinfo.resid;
this.tResid = objinfo.tResid;
this.bodyEffid = objinfo.bodyEffid
this.objType = objinfo.type;
this.maxhp = objinfo.maxhp;
this.hp = objinfo.hp;
this.maxmp = objinfo.maxmp;
this.mp = objinfo.mp;
this.sethp(objinfo.hp);
this.setmp(objinfo.mp);
this.ownid = objinfo.ownid;
this.relive = objinfo.relive;
this.weapon = objinfo.weapon;
this.skill_list = objinfo.skilllist;
this.resUrl = `shap/${objinfo.resid}`;
this.petColor = objinfo.petColor;
this.roleColor1 = objinfo.roleColor1;
this.roleColor2 = objinfo.roleColor2;
this.nickname = objinfo.name
this.camp = objinfo.camp
this.babypos = objinfo.babypos
this.babysex = objinfo.babysex
this.isleader = objinfo.isleader
this.starid = objinfo.starid
this.isLong = false;
let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", objinfo.wingId, "id", 0);
this.wingId = wingId;
let title = `<outline color=black width=1>${objinfo.name}1</outline>`;
if (this.isPlayer()) {
let vipLevel = VIPUtil.getVipLevel(objinfo.chargesum);
if (vipLevel > 0) {
title = `<img src='vip_${vipLevel}' />${title}`;
}
}
this.nameRT.string = objinfo.name;
if (this.isPartner()) {
this.hideMp();
}
if (this.isMonster() || objinfo.camp == 2) {
// this.hideHp();
// this.hideMp();
this.nameRT.node.color = cc.Color.WHITE;
} else if (this.isPet()) {
this.nameRT.node.color = GameUtil.getReliveColor(objinfo.relive, 1);
} else if (this.isPlayer() || this.isPartner()) {
this.nameRT.node.color = GameUtil.getReliveColor(objinfo.relive, 0);
}
if (this.hp <= 0) {
this.play('die');
}
if (!this.isPet())
this.playEff(this.bodyEffid)
if (this.isPlayer() && this.BabyNode == null) {
if (this.babysex < 0) return
let list = this.boyPrefab
if (this.babysex == 0) {
list = this.girlPrefab
}
let prefab = list[0]
if (this.camp == 2) {
prefab = list[1]
}
this.BabyNode = cc.instantiate(prefab)
this.BabyNode.name = "baby"
this.BabyNode.parent = this.node.parent
this.BabyNode.x = this.babypos.x
this.BabyNode.y = this.babypos.y
let nickname = this.BabyNode.getChildByName("NickName")
nickname.getComponent(cc.Label).string = `${this.nickname}的寶貝`
nickname.color = SKUIUtil.colorOfString("#09FE00");
cc.find("SkillNode", this.BabyNode).active = false
}
},
playBabySkill(skill_name) {
if (this.BabyNode == null) return
this.BabyNode.zIndex = cc.macro.MAX_ZINDEX;
let skill_node = cc.find("SkillNode", this.BabyNode)
skill_node.stopAllActions()
skill_node.active = true
skill_node.opacity = 255
let skill_text = cc.find("SkillText", skill_node)
skill_text.getComponent(cc.RichText).string = `<color=#FFFFFF>看我的</c><color=#00FF19>${skill_name}</color>`
skill_node.runAction(cc.sequence(cc.delayTime(1), cc.fadeOut(1)))
cc.log("run action.....................")
},
play(action = 'stand', spdrate = 1) {
var resid = this.tResid > 0 ? this.tResid : this.resid
if (this.isChange) resid = this.resid;
if (this.isdead && action != 'die') {
return;
}
let callfun = (curNode, finishfunc = true) => {
if (action == 'hit') {
let t = this._dir == 'up' ? -1 : 1;
let pos = { x: -t * 15, y: t * 8 };
let back = { x: t * 15, y: -t * 8 };
this.animationNode.runAction(cc.sequence(
cc.moveBy(0.4, pos).easing(cc.easeOut(3.0)),
cc.moveBy(0.1, back)
));
}
if (action != 'stand' && action != 'die' && finishfunc) {
curNode.getComponent(cc.Animation).on('finished', () => {
this.play();
}, this);
}
if (action == "die") {
WingUtil.hideWing(curNode.parent)
}
//if(resid == 20058)return
if (resid == 5063) return
if (resid == 5060) return
if (resid == 5071) return
if (resid == 5073) return
this.scheduleOnce(() => {
let temp = GameModel.conf_res_anchor[this.resid];
if (temp) {
let anchorY = temp.anchorY;
let anchorX = temp.anchorX;
this.animationNode.anchorY = anchorY;
this.maskNode.anchorY = anchorY;
this.RoleshadowNode.anchorY = anchorY;
this.weaponNode.anchorY = anchorY;
this.weaponNode1.anchorY = anchorY;
this.animationNode.anchorX = anchorX;
this.maskNode.anchorX = anchorX;
this.RoleshadowNode.anchorX = anchorX;
this.weaponNode.anchorX = anchorX;
this.weaponNode1.anchorX = anchorX;
}
var str = actName.substring(actName.length - 2);
if (this.resid == 1101 || this.resid == 1102) {
if (action == 'magic') {
return
}
}
if (str != 'ef') {
curNode.scaleX = 450 / curNode.width;
curNode.scaleY = 450 / curNode.height;
this.maskNode.scaleX = 450 / this.maskNode.width;
this.maskNode.scaleY = 450 / this.maskNode.height;
}
}, 0);
};
let playfun = (curNode, curName, finishfunc = true) => {
if (SKUIUtil.isValid(curNode)) {
let clips = curNode.getComponent(cc.Animation).getClips();
for (let clip of clips) {
if (clip.name == curName) {
curNode.getComponent(cc.Animation).play(curName);
callfun(curNode, finishfunc);
return;
}
}
}
let self = this;
let url = `shap/${resid}/${curName}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
if (!SKUIUtil.isValid(curNode)) {
return;
}
let curFrames = atlas.getSpriteFrames();
let fn = 12;
if (resid == 20058) {
if (action == "stand") {
fn = 10
}
if (action == "run") {
fn = 5
}
}
if (action == 'hit' && resid != 20058) {
fn = 2;
}
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn);
curClip.name = curName;
if (action == 'stand' || action == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
curClip.speed = spdrate;
let nodeAni = curNode.getComponent(cc.Animation);
nodeAni.addClip(curClip);
nodeAni.play(curName);
// cc.log(`$戰鬥:[${self.roleName}]播放動畫:${curName}`);
if (curNode == this.animationNode) {
if (self.petColor != null && self.petColor != 0 && self.petColor != -1) {
//設置寵物顏色
if (this.hsl) {
if (self.petColor != 0 && self.petColor != -1) {
this.hsl.dH = self.petColor;
} else {
this.hsl.dH = 0;
}
this.hsl.reset();
}
}
}
callfun(curNode, finishfunc);
if (action == "die") {
WingUtil.hideWing(curNode.parent)
}
if (self.wingId != 0 && self.tResid == 0 && action != "die") {
if (curNode == self.animationNode) {
if (this.camp == 1) {
WingUtil.playAni(curNode.parent, self.resid, 3, "stand", 0, self.wingId);
} else {
WingUtil.playAni(curNode.parent, self.resid, 1, "stand", 0, self.wingId);
}
}
}
});
};
let playfun2 = (curNode, curName) => {
if (SKUIUtil.isValid(curNode)) {
let clips = curNode.getComponent(cc.Animation).getClips();
for (let clip of clips) {
if (clip.name == curName) {
curNode.getComponent(cc.Animation).play(curName);
return;
}
}
}
let self = this;
let url = `shape_mask/${resid}/${curName}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
if (!SKUIUtil.isValid(curNode)) {
return;
}
let curFrames = atlas.getSpriteFrames();
let fn = 12;
if (action == 'hit') {
fn = 2;
}
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn);
curClip.name = curName;
if (action == 'stand' || action == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
curClip.speed = spdrate;
let nodeAni = curNode.getComponent(cc.Animation);
nodeAni.addClip(curClip);
nodeAni.play(curName);
self.showColorMask1(self.hxcolorTransfrom(self.roleColor1), self.hxcolorTransfrom(self.roleColor2))
});
};
let playfun3 = (curNode, curName) => {
if (SKUIUtil.isValid(curNode)) {
let clips = curNode.getComponent(cc.Animation).getClips();
for (let clip of clips) {
if (clip.name == curName) {
curNode.getComponent(cc.Animation).play(curName);
this.scheduleOnce(() => {
//var scale = this.animationNode.getComponent(cc.Sprite).spriteFrame._originalSize.width / curNode.getComponent(cc.Sprite).spriteFrame._originalSize.width
curNode.scaleX = this.animationNode.width / curNode.width;
curNode.scaleY = this.animationNode.height / curNode.height;
}, 0);
return;
}
}
}
let self = this;
let url = `shap/${resid}/${curName}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
if (!SKUIUtil.isValid(curNode)) {
return;
}
let curFrames = atlas.getSpriteFrames();
let fn = 12;
if (action == 'hit') {
fn = 2;
}
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn);
curClip.name = curName;
if (action == 'stand' || action == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
curClip.speed = spdrate;
curNode.active = true
let nodeAni = curNode.getComponent(cc.Animation);
nodeAni.addClip(curClip);
nodeAni.play(curName);
this.scheduleOnce(() => {
//var scale = this.animationNode.getComponent(cc.Sprite).spriteFrame._originalSize.width / curFrames[0]._originalSize.width
curNode.scaleX = this.animationNode.width / curNode.width;
curNode.scaleY = this.animationNode.height / curNode.height;
}, 0);
});
};
let actName = action + (this._dir == 'up' ? '_3' : '_1');
let actNode = this.animationNode;
playfun(actNode, actName);
if (resid == 6303) {
this.roleAddonNode = this.roleAddonFrontNode;
this.roleAddonBehindNode.active = false
playfun3(this.roleAddonNode, actName + '_addon');
}
if (resid == 5073) {
this.roleAddonNode = this.roleAddonFrontNode;
this.roleAddonBehindNode.active = false
playfun3(this.roleAddonNode, actName + '_ef');
}
if (resid == 5071) {
this.roleAddonNode = this.roleAddonBehindNode;
this.roleAddonFrontNode.active = false
playfun3(this.roleAddonNode, actName + '_ef');
}
if (this.roleColor2 != 0 || this.roleColor1 != 0) {
let actName2 = action + (this._dir == 'up' ? '_3' : '_1');
let actNode2 = this.maskNode;
playfun2(actNode2, actName2);
}
if (!this.isChange && this.tResid == 0) {
if (this.resid <= 4038) {
this.shadowNode.active = false
this.RoleshadowNode.active = true
ShapeUtil.playshadowAni(this.RoleshadowNode, this.resid, this._dir == 'up' ? 3 : 1, action, this);
} else {
this.shadowNode.active = true
this.RoleshadowNode.active = false
}
//CPubFunction.addWeaponAnimation(this.weapon, this.weaponNode, this.animationNode, this, this.resid, action, this._dir == 'up' ? 3 : 1,true);
WeaponUtil.addWeaponAnimation(this.weapon, this.weaponNode, this.animationNode, this, this.resid, action, this._dir == 'up' ? 3 : 1, 1);
}
if (action == 'magic' || action == 'attack') {
actName = actName + '_ef';
actNode = this.actionEffect;
playfun(actNode, actName, false);
}
},
/*
* 顏色轉換
*/
hxcolorTransfrom(color) {
let num = color;
let r = Math.floor(num / 256 / 256);
let g = Math.floor(num / 256 % 256);
let b = Math.floor(num % 256);
return new cc.Color(r, g, b);
},
showColorMask1(color1, color2) {
if (this.tResid > 0) return;
if (color1.r == 0 && color1.g == 0 && color1.b == 0 && color2.r == 0 && color2.g == 0 && color2.b == 0) {
this.maskNode.active = false;
return
} else {
this.maskNode.active = true;
}
this.scheduleOnce(() => {
let logic = this.maskNode.getComponent('role_color');
if (color1.r != 0 || color1.g != 0 || color1.b != 0) {
let t = Math.floor(color1.r) * 1000000 + Math.floor(color1.g) * 1000 + Math.floor(color1.b);
logic.dH1 = t;
} else {
logic.dH1 = 0;
}
if (color2.r != 0 || color2.g != 0 || color2.b != 0) {
let t = Math.floor(color2.r) * 1000000 + Math.floor(color2.g) * 1000 + Math.floor(color2.b);
logic.dH2 = t;
} else {
logic.dH2 = 0;
}
}, 0);
},
isDoubleWeapon(resid) {
var arr = [1111]
if (this.weapon)
if (SKDataUtil.jsonBy(this.weapon).level == 5) return false
for (let i in arr) {
if (resid == arr[i]) return true
}
return false
},
playEffectStr(strEffect, x, y, callback) {
CPubFunction.CreateSubFrame(this.effectLayer, {
nX: x,
nY: y
}, this.effect, strEffect, callback);
this.scheduleOnce(() => {
this.actionEffect.scaleX = 450 / this.actionEffect.width;
this.actionEffect.scaleY = 450 / this.actionEffect.height;
}, 0);
},
playEffect(skillid, callback) {
let skill = SkillUtil.getSkill(skillid);
if (skill) {
if (skill.effectPos == EffectPos.STAGE) {
return;
}
if (skill.particleEffect == 0) {
return;
}
this.effectResList.push('effect/' + skill.particleEffect);
this.playEffectStr(skill.particleEffect, skill.skillEffectX,
skill.skillEffectY, callback);
}
},
playLianJiEffect() {
this.effectResList.push('effect/62001');
CPubFunction.CreateSubFrameBoom(this.effectLayer, {
nX: 0,
nY: 100
}, this.effect, '62001', null);
this.scheduleOnce(() => {
this.actionEffect.scaleX = 450 / this.actionEffect.width;
this.actionEffect.scaleY = 450 / this.actionEffect.height;
}, 0);
},
playChangeLong() {
// 播放變身特效
var path = this.getLongResid()
this.effectResList.push('buff/' + path + '/status_1');
this.playEffectStr1(path + '/status_1', 0,
0, null);
this.isLong = true
this.isChange = true;
this.weaponNode.active = false;
this.weaponNode1.active = false;
this.longChangRound = 2;
this.animationNode.getComponent(cc.Animation).stop()
var clips = this.animationNode.getComponent(cc.Animation).getClips()
for (let clip of clips) {
this.animationNode.getComponent(cc.Animation).removeClip(clip, true)
}
this.play()
},
playEffectStr1(strEffect, x, y, callback) {
CPubFunction.CreateSubFrame1(this.effectLayer, {
nX: x,
nY: y
}, this.effect, strEffect, callback);
this.scheduleOnce(() => {
this.actionEffect.scaleX = 450 / this.actionEffect.width;
this.actionEffect.scaleY = 450 / this.actionEffect.height;
}, 0);
},
checkLongChangeRound() {
if (this.isLong && this.longChangRound > 0) {
this.longChangRound--;
if (this.longChangRound == 0) {
this.isChange = false;
this.weaponNode.active = true;
this.weaponNode1.active = true;
this.animationNode.getComponent(cc.Animation).stop()
var clips = this.animationNode.getComponent(cc.Animation).getClips()
for (let clip of clips) {
this.animationNode.getComponent(cc.Animation).removeClip(clip, true)
}
this.resid = this.originResid;
this.play()
}
}
},
// 獲得相應的變身resid
getLongResid() {
var dir = this._dir == 'up' ? '_3' : '_1'
var manArr = [1101, 1111, 1131]
var womanArr = [1102, 1112, 1132]
for (let i = 0; i < 3; i++) {
if (this.resid == manArr[i]) {
this.originResid = this.resid;
this.resid = 6144 + i * 2;
return '10051' + dir
}
if (this.resid == womanArr[i]) {
this.originResid = this.resid;
this.resid = 6145 + i * 2;
return '10052' + dir
}
}
},
// 檢查Buff
checkBuff(bufflist) {
if (!bufflist) return
for (const skillid in this.buffEffectList) {
if (SKDataUtil.hasProperty(this.buffEffectList, skillid)) {
let numskill = parseInt(skillid);
if (bufflist.indexOf(numskill) == -1) {
this.delBuff(numskill);
}
}
}
for (const skillid of bufflist) {
if (this.bufflist[skillid] == null) {
this.addBuff(skillid);
}
}
},
// 加入Buff
addBuff(skillid) {
// 如果已在buffer列表中則返回
if (this.buffEffectList[skillid] != null) {
return;
}
if (this._dir == 'up') {
let buff = cc.instantiate(this.buffprefab);
let logic = buff.getComponent('SkillIcon');
logic.width = 28;
logic.height = 28;
logic.icon = skillid;
buff.skillid = skillid;
let index = Object.keys(this.bufflist).length;
let x = -30 + (2 + 30) * index;
let y = 190;
buff.x = x;
buff.y = y;
this.bufflist[skillid] = buff;
buff.parent = this.bufflayer;
}
let skill = SkillUtil.getSkill(skillid);
if (skill == null) {
return;
}
if (skill.buffEffect == 'yinshen') {
cc.log(`$戰鬥:[${this.roleName}]進行隱身`);
this.animationNode.opacity = 77;
if (this.hsl) {
this.hsl.dA = 0.3;
this.hsl.reset();
}
this.isYinShen = true;
this.buffEffectList[skillid] = 0;
} else {
if (skill.buffFront) {
let effect = CPubFunction.CreateSubFrameLoop(this.effectLayer, {
nX: 0,
nY: skill.buffEffectY
}, this.effect, skill.buffEffect);
this.buffEffectList[skillid] = effect;
} else {
let effect = CPubFunction.CreateSubFrameLoop(this.effectBg, {
nX: 0,
nY: skill.buffEffectY
}, this.effect, skill.buffEffect);
this.buffEffectList[skillid] = effect;
}
}
},
// 刪除buffer
delBuff(skillid) {
let buff = this.bufflist[skillid];
if (buff) buff.destroy();
delete this.bufflist[skillid];
let effect = this.buffEffectList[skillid];
if (effect) effect.destroy();
delete this.buffEffectList[skillid];
if (skillid == ESkillType.YinShen || skillid == ESkillType.ZiXuWuYou || skillid == ESkillType.CangFengXuShi) {
cc.log(`$戰鬥:[${this.roleName}]解除隱身效果`);
this.animationNode.opacity = 255;
if (this.hsl) {
this.hsl.dA = 1.0;
this.hsl.reset();
}
this.isYinShen = false;
}
},
// 使用技能
useSkill(skillid) {
//cc.log(`$戰鬥:[${this.roleName}]使用技能[${SkillUtil.getSkillName(skillid)}]`);
// 普通攻擊或防禦則返回
if (skillid == ESkillType.NormalAtkSkill ||
skillid == ESkillType.NormalDefSkill) {
return;
}
if (skillid != 1045)
this.play('magic');
AudioUtil.playMagicAudio(this.resid);
// 播放技能音效
AudioUtil.playSkillAudio(skillid);
// 顯示頭頂技能圖標
this.showSkillTips(skillid);
},
showSkillTips(skillid) {
let stData = SkillUtil.getSkill(skillid);
let skillname = stData.getName();
this.skillLabel.string = skillname;
this.skillTitle.active = true;
let self = this;
this.skillTitle.runAction(cc.sequence(
cc.delayTime(1.5),
cc.callFunc(() => {
self.skillTitle.active = false;
})
));
},
showSelectFlag(selFunc) {
this.selectFlag.stopAllActions();
let act = cc.repeatForever(cc.sequence(cc.moveTo(0.3, 0, 200), cc.moveTo(0.5, 0, 225)));
this.selectFlag.active = true;
this.selectFlag.runAction(act);
this.selectFunc = selFunc;
this.onSkillTarget = true;
},
hideSelectFlag() {
this.selectFlag.stopAllActions();
this.selectFlag.active = false;
},
onSelectSkillTarget() {
if (this.onSkillTarget) {
if (this.selectFunc) {
this.selectFunc(this.onlyid);
}
this.selectFunc = null;
}
},
lianji(hps, lefthp, isdead, style = 0) {
if (hps.length <= 0) {
return;
}
this.isdead = isdead;
let lianjicallback = () => {
let skillid = this.bufflist[ESkillType.BaiRiMian];
if (skillid) {
this.delBuff(skillid);
}
skillid = this.bufflist[ESkillType.MiHunZui];
if (skillid) {
this.delBuff(skillid);
}
this.sethp(lefthp);
if (isdead) {
this.play('die');
} else {
this.play();
}
};
let i = 0;
for (const hp of hps) {
let numlabel = cc.instantiate(this.numPrefab);
let numlogic = numlabel.getComponent('BattleNum');
numlogic.num = hp;
numlogic.subhp = true;
if (style == 1) {
numlogic.baoji = true;
} else if (style == 5) {
numlogic.pofang = true;
}
numlabel.parent = this.node;
numlabel.x = 0;
numlabel.y = 100;
let times = (hps.length - i) > 4 ? 4 : (hps.length - i);
let actlist = [];
actlist[actlist.length] = cc.hide();
actlist[actlist.length] = cc.delayTime(0.15 * i);
actlist[actlist.length] = cc.show();
actlist[actlist.length] = cc.scaleTo(0.01, 1.5);
actlist[actlist.length] = cc.scaleTo(0.02, 1);
actlist[actlist.length] = cc.repeat(cc.sequence(cc.moveBy(0.1, 0, 40), cc.delayTime(0.05)), times);
if (times < 4) {
actlist[actlist.length] = cc.delayTime(0.15 * (4 - times));
}
if (i == hps.length - 1) {
actlist[actlist.length] = cc.callFunc(lianjicallback);
}
actlist[actlist.length] = cc.removeSelf();
numlabel.runAction(cc.sequence(actlist));
// if(i < hps.length - 1){
// numlabel.runAction(cc.repeat(cc.sequence(
// cc.delayTime(0.1 * i),
// cc.moveBy(0.1, 0, 40),
// ), hps.length- i));
// }
i++;
}
},
// 多個目標的連擊
lianjiMoreObj(hps, lefthp, isdead, style = 0) {
if (hps.length <= 0) {
return;
}
this.isdead = isdead;
let lianjicallback = () => {
let skillid = this.bufflist[ESkillType.BaiRiMian];
if (skillid) {
this.delBuff(skillid);
}
skillid = this.bufflist[ESkillType.MiHunZui];
if (skillid) {
this.delBuff(skillid);
}
this.sethp(lefthp);
if (isdead) {
this.play('die');
} else {
this.play();
}
};
let i = 0;
for (const hp of hps) {
let numlabel = cc.instantiate(this.numPrefab);
let numlogic = numlabel.getComponent('BattleNum');
numlogic.num = hp;
numlogic.subhp = true;
if (style == 1) {
numlogic.baoji = true;
} else if (style == 5) {
numlogic.pofang = true;
}
numlabel.parent = this.node;
numlabel.x = 0;
numlabel.y = 100;
let times = (hps.length - i) > 4 ? 4 : (hps.length - i);
let actlist = [];
actlist[actlist.length] = cc.hide();
actlist[actlist.length] = cc.delayTime(0.15 * i);
actlist[actlist.length] = cc.show();
actlist[actlist.length] = cc.scaleTo(0.01, 1.5);
actlist[actlist.length] = cc.scaleTo(0.02, 1);
actlist[actlist.length] = cc.repeat(cc.sequence(cc.moveBy(0.1, 0, 40), cc.delayTime(0.05)), times);
if (times < 4) {
actlist[actlist.length] = cc.delayTime(0.15 * (4 - times));
}
if (i == hps.length - 1) {
actlist[actlist.length] = cc.callFunc(lianjicallback);
}
actlist[actlist.length] = cc.removeSelf();
numlabel.runAction(cc.sequence(actlist));
// if(i < hps.length - 1){
// numlabel.runAction(cc.repeat(cc.sequence(
// cc.delayTime(0.1 * i),
// cc.moveBy(0.1, 0, 40),
// ), hps.length- i));
// }
i++;
}
},
// 是否反擊後死亡
checkDieByFan(lefthp, isdead) {
let left_hp = lefthp;
let is_dead = isdead;
this.isdead = isdead;
this.sethp(left_hp);
if (is_dead) {
this.play('die');
}
},
//style 0 常規 1 暴擊 2 吃藥加血 3 吃藥加血加藍 4 涅槃 5 破防
subHP(hp, lefthp, isdead, style = 0) {
if (hp == 0) {
return;
}
let left_hp = lefthp;
let is_dead = isdead;
this.isdead = isdead;
if (style != 4) {
this.hpTimer = SKTimeUtil.delay(() => {
let lhp = hp + '';
if (hp > 0) {
lhp = '+' + hp;
}
let numlabel = cc.instantiate(this.numPrefab);
let numlogic = numlabel.getComponent('BattleNum');
numlogic.num = lhp;
if (style == 0) {
if (hp > 0) {
numlogic.addhp = true;
} else {
numlogic.subhp = true;
}
} else if (style == 1) {
numlogic.baoji = true;
} else if (style == 2) {
numlogic.addhp = true;
} else if (style == 3) {
numlogic.hpmp = true;
} else if (style == 5) {
numlogic.pofang = true;
}
numlabel.parent = this.node;
numlabel.x = 0;
numlabel.y = 110;
numlabel.runAction(cc.sequence(
cc.moveTo(0.8, 0, 130),
cc.delayTime(0.2),
cc.removeSelf(),
));
},
0.2 * 1000);
}
if (hp < 0) {
let skillid = this.bufflist[ESkillType.BaiRiMian];
if (skillid) {
this.delBuff(skillid);
}
skillid = this.bufflist[ESkillType.MiHunZui];
if (skillid) {
this.delBuff(skillid);
}
}
this.checkTimer = SKTimeUtil.delay(() => {
this.sethp(left_hp);
if (is_dead) {
this.play('die');
} else {
this.play();
}
}, 0.5 * 1000);
},
subMP(mp, recover = false) {
let callback = () => {
// if (mp > 0) {
// mp = '+' + mp;
// }
let numlabel = cc.instantiate(this.numPrefab);
let numlogic = numlabel.getComponent('BattleNum');
numlogic.num = mp;
numlogic.mp = true;
numlabel.parent = this.node;
numlabel.x = 0;
if (!recover) {
numlabel.y = 110;
numlabel.runAction(cc.sequence(
cc.moveTo(0.8, 0, 130),
cc.delayTime(0.2),
cc.removeSelf(),
));
}
else {
numlabel.y = 160;
numlabel.runAction(cc.sequence(
cc.moveBy(0.8, 0, 20),
cc.delayTime(0.2),
cc.removeSelf(),
));
}
};
this.scheduleOnce(callback, 0.1);
},
showDef() {
CPubFunction.CreateSubFrame(this.effectLayer, {
nX: 0,
nY: 40
}, this.effect, 'fangyu');
this.scheduleOnce(() => {
this.actionEffect.scaleX = 500 / this.actionEffect.width;
this.actionEffect.scaleY = 500 / this.actionEffect.height;
}, 0);
},
showShanbi() {
if (this._dir == 'up') {
this.animationNode.runAction(cc.sequence(
cc.moveBy(0.2, cc.v2(50, -20)),
cc.delayTime(0.3),
cc.moveBy(0.2, cc.v2(-50, 20)),
));
} else {
this.animationNode.runAction(cc.sequence(
cc.moveBy(0.2, cc.v2(-50, 20)),
cc.delayTime(0.3),
cc.moveBy(0.2, cc.v2(50, -20)),
));
}
},
playRunAway(success = 0) {
let olddir = this._dir;
if (this._dir == 'down') {
this._dir = 'up';
}
if (this._dir == 'up') {
this._dir = 'down';
}
this.play('run');
let go = () => {
let x = 300,
y = -120;
if (olddir == 'down') {
x = -300;
y = 120;
}
this.node.runAction(cc.moveBy(0.5, cc.v2(x, y)));
};
let retdir = () => {
this._dir = olddir;
this.play();
};
this.node.runAction(cc.sequence(
cc.delayTime(0.5),
cc.callFunc(() => {
if (success) {
go();
} else {
retdir();
}
}),
));
},
objTalk(msg) {
this.talkNode.stopAllActions();
this.talkNode.runAction(cc.sequence(cc.fadeIn(0), cc.delayTime(3), cc.fadeOut(1)));
let msgNode = this.talkNode.getChildByName('msg');
msgNode.getComponent('CustomRichText').string = msg;
this.talkNode.height = msgNode.height + 16;
},
});