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

1411 lines
54 KiB
JavaScript

import SKUIUtil from "../../ts/gear_2.3.4/util/SKUIUtil";
import SKDataUtil from "../../ts/gear_2.3.4/util/SKDataUtil";
import GameModel from "../../ts/core/GameModel";
import HorseUtil from "../../ts/horse/HorseUtil";
import HorseList from "../../ts/horse/HorseList";
import LiveEntity from "../../ts/core/LiveEntity";
import WingUtil from "../../ts/wing/WingUtil";
import MyModel from "../../ts/core/MyModel";
import GameUtil from "../../ts/core/GameUtil";
import SKLogger from "../../ts/gear_2.3.4/util/SKLogger";
import VIPUtil from "../../ts/game/role/VIPUtil";
import { mainUI } from "../WorldRewardMgr";
import WeaponUtil from "../../ts/weapon/WeaponUtil";
let GameRes = require('../GameRes');
let CPubFunction = require('../PubFunction');
let roleTitleUtil = require('../../utils/RoleTitlesUtil');
cc.Class({
extends: LiveEntity,
properties: {
bodyNode: cc.Node,
roleNode: cc.Node,
maskNode: cc.Node,
zqmaskNode: cc.Node,
roleAddonNode: cc.Node,
roleAddonBehindNode: cc.Node,
roleAddonFrontNode: cc.Node,
roleEffNode: cc.Node,
shadowNode: cc.Node,
RoleshadowNode: cc.Node,
weaponNode: cc.Node,
anotherWeaponNode: cc.Node,
horseNode: cc.Node,
btnPlayerAvatar: cc.Prefab,
footEffPre: cc.Prefab,
addFootEffFunc: null,
isOpenFootTimer: false,
isShane: false,
nameImgTitleNode: cc.Node,
nameImgTitleHorseNode: cc.Node,
name2Node: cc.Node,
name2HorseNode: cc.Node,
},
onLoad() {
this._super();
this.isMy = false;
this.dir = 1;
this.isHidden = false;
this.teamid = 0;
this.obj_type = 0;
this.resid = 0;
this.tResid = 0;
this.run_type = 0;
this.netInfo = {};
this.move_speed = 250;
this.move_tiems = 0;
this.bodyEffid = 0;
this.footEffid = 0;
this.headBorderid = 0;
this.wing_behind_1 = this.bodyNode.getChildByName("wing_behind_1");
this.wing_behind_2 = this.bodyNode.getChildByName("wing_behind_2");
this.wing_front_1 = this.bodyNode.getChildByName("wing_front_1");
this.wing_front_2 = this.bodyNode.getChildByName("wing_front_2");
// this.nameImgTitleNode = this.node.getChildByName('imgTitle');
this.name1Node = this.node.getChildByName('name_1');
// this.name2Node = this.node.getChildByName('name_2');
this.moveAngle = 0;
this.weaponname = '';
this.schedule(this.checkPos, 0.1, cc.macro.REPEAT_FOREVER);
this.movePath = [];
this.isBing = false;
if (this.horseList == null) {
this.horseList = new HorseList();
this.horseList.horseChange = this.horseChange.bind(this);
}
this.wingId = 0;
this.addFootEffFunc = function () {
if (this.footEffid == 0 || this.living_state != 2) return;
let fE = CPubFunction.CreateSubNode(cc.find('Canvas/MapUI'), {
nX: this.node.x,
nY: this.node.y
}, this.footEffPre, 'footEff');
fE.getComponent('footEff').init(this.footEffid, this.dir, this.bodyNode.scaleX);
}
},
// 坐騎改變回調
horseChange() {
// console.log("坐騎回調")
let horseIndex = this.horseList.horseIndex;
if (this.living_state == 0) {
if (this.run_type == 0) {
let horseResId = this.horseList.resId;
if (horseResId == 0) {
this.bodyNode.active = true;
this.horseNode.active = false;
this.loadResThenPlay(`stand_${this.dir}`);
if (this.tResid == 0)
this.addWeaponAnimationByLR("stand");
else {
this.weaponNode.active = false
this.anotherWeaponNode.active = false
}
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, 'stand', this.dir);
if (this.isMy) {
// 下馬
GameModel.send('c2s_get_down', {
horseIndex: horseIndex,
});
}
} else {
this.bodyNode.active = false;
this.horseNode.active = true;
// 騎乘
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
if (this.isMy) {
GameModel.send('c2s_ride', {
horseIndex: horseIndex,
});
}
}
}
}
},
effectChange() {
this.roleEffNode.active = false;
let clips = this.roleEffNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
this.roleEffNode.getComponent(cc.Animation).stop(clip.name);
this.roleEffNode.getComponent(cc.Animation).removeClip(clip, true);
}
this.playEff(this.bodyEffid)
},
changeWing(wingId) {
if (this.wingId == wingId) {
return;
}
this.wingId = wingId;
if (this.living_state == 0) {
if (this.run_type == 0) {
let horseResId = this.horseList.resId;
if (horseResId == 0) {
WingUtil.playAni(this.bodyNode, this.resid, this.dir, "stand", horseResId, this.wingId);
} else {
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
}
}
}
},
clear() {
// var weaponNode1 = this.weaponNode;
// var animation = weaponNode1.getComponent(cc.Animation);
// if (animation) {
// animation.stop()
// var clips = animation.getClips();
// for (const clip of clips) {
// weaponNode1.getComponent(cc.Animation).stop(clip.name);
// weaponNode1.getComponent(cc.Animation).removeClip(clip, true);
// }
// }
// var weaponNode2 = this.anotherWeaponNode;
// var animation = weaponNode2.getComponent(cc.Animation);
// if (animation) {
// animation.stop()
// var clips = animation.getClips();
// for (const clip of clips) {
// weaponNode2.getComponent(cc.Animation).stop(clip.name);
// weaponNode2.getComponent(cc.Animation).removeClip(clip, true);
// }
// }
if (this.roleNode) {
var animation = this.roleNode.getComponent(cc.Animation);
animation.stop()
let clips = animation.getClips();
for (const clip of clips) {
this.roleNode.getComponent(cc.Animation).stop(clip.name);
this.roleNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
if (this.RoleshadowNode) {
var animation = this.RoleshadowNode.getComponent(cc.Animation);
animation.stop()
let clips = animation.getClips();
for (const clip of clips) {
this.RoleshadowNode.getComponent(cc.Animation).stop(clip.name);
this.RoleshadowNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
if (this.maskNode) {
var animation = this.maskNode.getComponent(cc.Animation);
let clips = animation.getClips();
for (const clip of clips) {
this.maskNode.getComponent(cc.Animation).stop(clip.name);
this.maskNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
},
/*
* 顏色轉換
*/
hxcolorTransfrom(color) {
// let num = parseInt(color, 16);
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);
},
showColorMask() {
let color1 = this.netInfo.color1,
color2 = this.netInfo.color2;
if (this.netInfo.roleid == GameModel.player.roleid) {
color1 = GameModel.player.color1;
color2 = GameModel.player.color2;
}
if (color1 == 0 && color2 == 0) {
this.unshowColorMask();
return;
}
this.showColorMask1(this.hxcolorTransfrom(color1), this.hxcolorTransfrom(color2))
},
unshowColorMask() {
// this.maskNode = false;
this.maskNode.active = false;
this.zqmaskNode.active = false;
},
// 設置角色是否隱藏,1.自己永遠不會被隱藏,2.隱藏多餘的自己,3.判斷是不是隊友
resetHidden() {
if (this.isMy) {
return;
}
let myRole = GameModel.player;
// 有重影
if (this.netInfo.roleid == myRole.roleid) {
this.isHidden = true;
this.node.active = false;
cc.warn(`$警告:玩家重複:${this.netInfo.name}`);
return;
}
let isHidden = GameModel.hideNotTeam;
if (isHidden) {
// 是否為隊友
if (this.netInfo.teamid != 0 && this.netInfo.teamid == myRole.teamid) {
this.node.active = true;
} else {
this.node.active = false;
}
} else {
this.node.active = true;
}
},
loadEff(url, loop, x, y, cb) {
var self = this
self.deleteEffNode()
cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) {
if (error) {
cc.warn(`$警告:加載資源錯誤:${url}`);
return;
}
if (!atlas)
return;
if (!SKUIUtil.isValid(self.roleNode)) {
cc.warn(`$警告:角色播放動畫失敗,角色節點無效`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 10);
curClip.name = `eff`;
if (loop)
curClip.wrapMode = cc.WrapMode.Loop;
else
curClip.wrapMode = cc.WrapMode.Normal;
cc.loader.loadRes("Prefabs/EffectFrame", cc.Prefab, (err, prefab) => {
if (err) {
console.log(err)
return;
}
if (!SKUIUtil.isValid(self.roleNode)) {
cc.warn(`$警告:角色播放動畫失敗,角色節點無效`);
return;
}
let effNode = cc.instantiate(prefab);
effNode.name = "AddonEffNode"
effNode.x = x
effNode.y = y
effNode.parent = self.node
effNode.getComponent("Effect").CreateAndPlayAnimation(curClip, cb)
})
})
},
deleteEffNode() {
for (let i = this.node.children.length - 1; i > 0; i--) {
if (this.node.children[i].name == "AddonEffNode")
this.node.children[i].destroy()
}
},
resetRoleTitle() {
let vipLevel = VIPUtil.getVipLevel(this.netInfo.chargesum || 0);
let prefix = vipLevel > 0 ? `<img src='vip_${vipLevel}' width=20 height=20/>` : ``;
console.log("________________________", prefix)
if (this.name1Node) {
this.name1Node.color = GameUtil.getReliveColor(this.netInfo.relive);
let title = this.netInfo.name;
this.name1Node.getComponent(cc.RichText).string = `${prefix}${title}`;
this.name1Node.active = true;
if (this.isShane) {
this.name1Node.getChildByName("zuolao").x = -this.netInfo.name.length * 40 / 2 - 20;
this.name1Node.getChildByName("zuolao").active = true
} else {
this.name1Node.getChildByName("zuolao").active = false
}
}
var postArr = ["", "幫主", "副幫主", "左護法", "右護法", "長老", "堂主", "幫眾"]
this.name2Node.getComponent(cc.Label).string = `${this.netInfo.bangname}${postArr[this.netInfo.bangpost || 0]}`
this.name2HorseNode.getComponent(cc.Label).string = `${this.netInfo.bangname}${postArr[this.netInfo.bangpost || 0]}`
if (this.netInfo.mapid == 3001) {
this.name2Node.active = true
this.name2HorseNode.active = true
this.nameImgTitleNode.active = false;
this.nameImgTitleHorseNode.active = false;
if (this.netInfo.bangname == GameModel.player.bangname) {
this.name2Node.color = new cc.Color(255, 0, 0)
this.name2HorseNode.color = new cc.Color(255, 0, 0)
}
else {
this.name2Node.color = new cc.Color(0, 150, 255)
this.name2HorseNode.color = new cc.Color(0, 150, 255)
}
return
} else {
this.name2Node.active = false
this.name2HorseNode.active = false
}
// return
if (this.netInfo.titleid == 0) {
//不顯示稱謂
if (this.nameImgTitleNode) {
this.nameImgTitleNode.active = false;
this.nameImgTitleHorseNode.active = false;
}
if (this.name2Node) {
this.name2Node.active = false;
this.name2HorseNode.active = false;
}
if (this.name1Node) {
this.name1Node.color = GameUtil.getReliveColor(this.netInfo.relive);
let title = this.netInfo.name;
this.name1Node.getComponent(cc.RichText).string = `${prefix}${title}`;
this.name1Node.active = true;
}
} else if (this.netInfo.titleid <= 112) {
//顯示圖片+名字
this.name2Node && (this.name2Node.active = false);
this.name2HorseNode && (this.name2HorseNode.active = false);
let titleId = this.netInfo.titleid;
SKUIUtil.setSpriteFrame(this.nameImgTitleNode, 'Common/role_title', `roletitle_${titleId}`);
SKUIUtil.setSpriteFrame(this.nameImgTitleHorseNode, 'Common/role_title', `roletitle_${titleId}`);
this.nameImgTitleNode && (this.nameImgTitleNode.active = true);
this.nameImgTitleHorseNode && (this.nameImgTitleHorseNode.active = true);
if (this.name1Node) {
this.name1Node.color = GameUtil.getReliveColor(this.netInfo.relive);
let title = this.netInfo.name;
let rt = this.name1Node.getComponent(cc.RichText);
rt.string = `${prefix}${title}`;
this.name1Node.active = true;
}
} else {
//顯示文字稱謂+名字
this.nameImgTitleNode && (this.nameImgTitleNode.active = false);
this.nameImgTitleHorseNode && (this.nameImgTitleHorseNode.active = false);
let titleShow = roleTitleUtil.getRoleTitle(this.netInfo.titleid, this.netInfo.titleval, this.netInfo.bangname);
if (titleShow != null && this.name2Node) {
this.name2Node.color = new cc.Color(30, 144, 255);
this.name2HorseNode.color = new cc.Color(30, 144, 255);
console.log(`+++++++++++++++++++++++++++${titleShow.name}`)
let title = `${titleShow.name}`;
this.name2Node.getComponent(cc.Label).string = title;
this.name2HorseNode.getComponent(cc.Label).string = title;
this.name2Node.active = true;
this.name2HorseNode.active = true;
}
if (this.name1Node) {
this.name1Node.color = GameUtil.getReliveColor(this.netInfo.relive);
let title = this.netInfo.name;
this.name1Node.getComponent(cc.RichText).string = `${prefix}${title}`;
this.name1Node.active = true;
}
}
},
resetName(name) {
let vipLevel = VIPUtil.getVipLevel(this.netInfo.chargesum || 0);
let prefix = vipLevel > 0 ? `<img src='vip_${vipLevel}' width=20 height=20/>` : ``;
this.netInfo.name = name;
this.name1Node.getComponent(cc.RichText).string = `${prefix}${title}`;
},
resetResid(resid) {
this.tResid = resid;
this.weaponNode.active = false
this.anotherWeaponNode.active = false
this.clear()
let temp = GameModel.conf_res_anchor[resid];
if (temp) {
let anchorY = temp.anchorY;
this.roleNode.anchorY = anchorY;
this.maskNode.anchorY = anchorY;
this.RoleshadowNode.anchorY = anchorY;
}
// else {
// SKLogger.warn(`找不到資源軸心配置:${this.resid}`);
// }
if (this.horseList.resId == 0) {
this.loadResThenPlay(`stand_${this.dir}`);
this.wing_behind_1.active = false
this.wing_behind_2.active = false
this.wing_front_1.active = false
this.wing_front_2.active = false
}
},
clearChange(resid) {
this.tResid = 0;
this.weaponNode.active = false
this.anotherWeaponNode.active = false
this.clear()
let temp = GameModel.conf_res_anchor[resid];
if (temp) {
let anchorY = temp.anchorY;
this.roleNode.anchorY = anchorY;
this.maskNode.anchorY = anchorY;
this.RoleshadowNode.anchorY = anchorY;
}
if (this.horseList.resId == 0) {
this.loadResThenPlay(`stand_${this.dir}`);
this.addWeaponAnimationByLR("stand");
this.wing_behind_1.active = false
this.wing_behind_2.active = false
this.wing_front_1.active = false
this.wing_front_2.active = false
}
},
setInfo(objInfo, loadGame) {
this.netInfo = objInfo;
this.loadGame = loadGame;
this.isShane = objInfo.shane && objInfo.shane > 0;
if (this.netInfo.wingId) {
let wingId = SKDataUtil.findByDict(GameModel.game_conf.wing, "resid", this.netInfo.wingId, "id", 0);
this.wingId = wingId;
}
if (this.netInfo.x < 0 || this.netInfo.y < 0) {
this.netInfo.x = 0;
this.netInfo.y = 0;
}
this.resAtlas = GameRes.getRoleRes(this.netInfo.resid);
this.resid = this.netInfo.resid;
this.tResid = this.netInfo.changeid ? this.netInfo.changeid : 0;
this.resetRoleTitle();
this.resetHidden();
if (this.roleNode.getComponent(cc.Animation)) {
let clips = this.roleNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
this.roleNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
if (this.maskNode.getComponent(cc.Animation)) {
let clips = this.maskNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
this.maskNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
if (this.RoleshadowNode.getComponent(cc.Animation)) {
let clips = this.RoleshadowNode.getComponent(cc.Animation).getClips();
for (const clip of clips) {
this.RoleshadowNode.getComponent(cc.Animation).removeClip(clip, true);
}
}
if (this.isMy) {
MyModel.shared.race = this.netInfo.race;
MyModel.shared.resId = this.netInfo.resid;
}
if (this.netInfo.gameData) {
this.horseList.parse(this.netInfo.gameData.horseList, this.netInfo.race);
} else {
this.horseList.parse(this.netInfo.horseList, this.netInfo.race);
}
if(this.resid == 3005){
this.roleEffNode.position = cc.v3(15, -53, 0);
this.roleEffNode.scale = 1.5;
}else{
this.roleEffNode.position = cc.v3(0, 0, 0);
this.roleEffNode.scale = 1;
}
let horseResId = this.horseList.resId;
if (horseResId == 0) {
this.bodyNode.active = true;
this.horseNode.active = false;
this.loadResThenPlay(`stand_${this.dir}`);
if (this.tResid == 0)
this.addWeaponAnimationByLR("stand")
else {
this.weaponNode.active = false
this.anotherWeaponNode.active = false
}
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, 'stand', this.dir);
} else {
this.bodyNode.active = false;
this.horseNode.active = true;
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
}
let mapConf = GameModel.conf_map;
let nID = mapConf[this.netInfo.mapid].mapid;
let mapinfo = GameModel.conf_map_list[nID];
this.gridInfoArr = mapinfo.mapInfo;
if (mapinfo.baseInfo.rows <= this.netInfo.y || mapinfo.baseInfo.lines <= this.netInfo.x) {
this.netInfo.x = mapinfo.startPos.x;
this.netInfo.y = mapinfo.startPos.y;
}
this.setObjPos(this.netInfo.x, this.netInfo.y);
var resid = this.tResid ? this.tResid : this.resid
let temp = GameModel.conf_res_anchor[resid];
if (temp) {
let anchorY = temp.anchorY;
let anchorX = temp.anchorX;
this.roleNode.anchorY = anchorY;
this.roleNode.anchorX = anchorX;
this.maskNode.anchorY = anchorY;
this.maskNode.anchorX = anchorX;
this.RoleshadowNode.anchorY = anchorY;
this.RoleshadowNode.anchorX = anchorX;
this.roleEffNode.anchorY = anchorY;
this.roleEffNode.anchorX = anchorX;
this.weaponNode.anchorY = anchorY;
this.weaponNode.anchorX = anchorX;
} else {
SKLogger.warn(`找不到資源軸心配置:${this.resid}`);
}
if (this.gridInfoArr[this.netInfo.y][this.netInfo.x] == 2) {
this.node.opacity = 150;
} else {
this.node.opacity = 255;
}
this.showColorMask();
if (objInfo.effectlist) {
var list = SKDataUtil.jsonBy(objInfo.effectlist);
for (let i in list) {
if (list[i] >= 505105 && list[i] <= 505110)
this.footEffid = list[i]
}
}
if (objInfo.effectid)
this.bodyEffid = objInfo.effectid
this.playEff(this.bodyEffid);
if (objInfo.isFrozen == 1) {
this.forzenRole()
} else {
this.deleteEffNode()
}
},
changeHeadBorder(headBorderId) {
if (headBorderId && this.isMy) {
if (this.headBorderid != headBorderId) {
this.headBorderid = headBorderId;
var mainUI = cc.find('Canvas/MainUI');
if (mainUI) {
var lg = mainUI.getComponent("MainUI");
if (lg) lg.changeHeadBorder(this.headBorderid);
}
}
}
},
// 判斷是否為雙武器並添加動畫
addWeaponAnimationByLR(action = "stand") {
var show = GameModel.player.roleid != this.netInfo.roleid
//CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, action, this.dir, show);
WeaponUtil.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, action, this.dir, 2);
},
addHeadStatus(name) { //zhandou:戰鬥 zudui:隊長未滿員 zudui2:隊長滿員
if (this.node.getChildByName(name)) {
return;
}
let url = "";
if (name == 'zhandou') {
url = 'battle/zhandou';
} else if (name == 'zudui' || name == 'zudui2') {
this.delHeadStatus('zudui');
this.delHeadStatus('zudui2');
url = 'team/' + name;
}
if (url.length < 1) {
return;
}
let self = this;
cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) {
if (error) {
cc.warn(`$警告:加載角色頭頂狀態資源錯誤${url}`);
return;
}
if (!SKUIUtil.isValid(self.node)) {
cc.warn(`$警告:加載角色頭頂狀態角色節點無效!`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 10);
curClip.name = name;
curClip.wrapMode = cc.WrapMode.Loop;
let statusNode = new cc.Node();
statusNode.parent = self.node;
let statusAni = statusNode.addComponent(cc.Animation);
let statusSp = statusNode.addComponent(cc.Sprite);
statusSp.spriteFrame = curFrames[0];
statusSp.trim = false;
statusSp.sizeMode = cc.Sprite.SizeMode.RAW;
statusNode.name = name;
statusAni.addClip(curClip);
statusAni.play(name);
statusNode.anchorY = 0;
statusNode.y = 170;
self.scheduleOnce(() => {
if (SKUIUtil.isValid(statusNode) && statusNode.width > 0) {
statusNode.scaleX = 50 / statusNode.width;
statusNode.scaleY = 50 / statusNode.width;
} else {
cc.warn(`$警告:角色[${self.netInfo.roleid}]頭頂狀態節點異常`);
}
}, 0);
});
},
delHeadStatus(name) {
while (this.node.getChildByName(name)) {
let node = this.node.getChildByName(name);
node.parent = null;
node.destroy();
}
},
changeWeapon(weapon) {
this.netInfo.weapon = weapon;
},
loadResThenPlay(name) {
let self = this;
var resid = 0;
if (this.tResid > 0 && this.horseList.resId == 0){
this.wing_behind_1.active = false
this.wing_behind_2.active = false
this.wing_front_1.active = false
this.wing_front_2.active = false
this.RoleshadowNode.active = false
this.shadowNode.active = true
this.maskNode.active = false
resid = this.tResid
}else{
this.wing_behind_1.active = true
this.wing_behind_2.active = true
this.wing_front_1.active = true
this.wing_front_2.active = true
this.RoleshadowNode.active = true
this.shadowNode.active = false
resid = this.resid
}
let url = `shap/${resid}/${name}`;
let url2 = `shape_mask/${this.resid}/${name}`;
let url3 = `shap/${this.resid}/${name}_addon`;
let url4 = `ccbtex/shadow/${this.resid}_${name}_sw`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載資源${url}失敗!`);
return;
}
self.playAnimation(name);
});
// 未變身就查找其他動畫特效
if (this.tResid == 0) {
if (this.resid<=4038){
this.shadowNode.active = false
this.RoleshadowNode.active = true
cc.loader.loadRes(url4, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載影子資源${url4}失敗!`);
self.RoleshadowNode.active = false
return;
}
self.playRoleshadowAnimation(name);
});
}else{
this.shadowNode.active = true
this.RoleshadowNode.active = false
}
cc.loader.loadRes(url2, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載資源${url2}失敗!`);
self.maskNode.active = false
return;
}
self.playMaskAnimation(name);
});
cc.loader.loadRes(url3, cc.SpriteAtlas, (error, atlas) => {
if (error) {
// cc.warn(`$警告:加載資源${url3}失敗!`);
return;
}
self.playAddonAnimation(name + "_addon");
});
}
},
// 播放動畫
playAnimation(name) {
if (!SKUIUtil.isValid(this.roleNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
let anim = this.roleNode.getComponent(cc.Animation);
if (!anim) {
return;
}
var resid = 0;
if (this.tResid > 0 && this.horseList.resId == 0)
resid = this.tResid
else
resid = this.resid
let dir = SKDataUtil.numberByString(name, "_", 1, 1);
let clips = anim.getClips();
for (let clip of clips) {
if (clip.name == name) {
this.roleNode.active = true;
this.roleNode.getComponent(cc.Animation).play(name);
this.scheduleOnce(() => {
if (SKUIUtil.isValid(this.roleNode) && this.roleNode.width > 0) {
this.roleNode.scaleX = 500 / this.roleNode.width;
this.roleNode.scaleY = 500 / this.roleNode.width;
} else {
cc.warn(`$警告:角色[${this.netInfo.roleid}]節點異常`);
}
}, 0);
if (this.tResid == 0)
WingUtil.playAni(this.bodyNode, this.resid, dir, name, 0, this.wingId);
return;
}
}
this.roleNode.active = false;
let self = this;
let url = `shap/${resid}/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載角色動畫資源失敗${url}`);
return;
}
if (!SKUIUtil.isValid(self.roleNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
if (this.netInfo.roleid == GameModel.player.roleid && GameModel.player.tResid != 0 && resid != GameModel.player.tResid) return
let curFrames = atlas.getSpriteFrames();
let fn = 15;
if(this.resid > 4038){
fn = 10;
}
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn);
curClip.name = name;
if (name.substr(0, 5) == 'stand' || name.substr(0, 3) == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
let nodeAni = self.roleNode.getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play(name);
}
self.roleNode.active = true;
if (this.tResid == 0)
WingUtil.playAni(self.bodyNode, self.resid, dir, name, 0, self.wingId);
self.scheduleOnce(() => {
if (SKUIUtil.isValid(self.roleNode) && self.roleNode.width > 0) {
self.roleNode.scaleX = 500 / self.roleNode.width;
self.roleNode.scaleY = 500 / self.roleNode.width;
} else {
cc.warn(`$警告:角色[${self.netInfo.roleid}]節點異常`);
}
}, 0);
});
},
// 播放遮罩
playMaskAnimation(name) {
if (!SKUIUtil.isValid(this.maskNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
let anim = this.maskNode.getComponent(cc.Animation);
if (!anim) {
return;
}
let dir = SKDataUtil.numberByString(name, "_", 1, 1);
let clips = anim.getClips();
for (let clip of clips) {
if (clip.name == name) {
this.maskNode.active = true;
this.maskNode.getComponent(cc.Animation).play(name);
return;
}
}
this.maskNode.active = false;
let self = this;
let url = `shape_mask/${this.resid}/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載角色動畫資源失敗${url}`);
return;
}
if (!SKUIUtil.isValid(self.maskNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
curClip.name = name;
if (name.substr(0, 5) == 'stand' || name.substr(0, 3) == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
let nodeAni = self.maskNode.getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play(name);
}
if (self.tResid > 0 && self.horseList.resId == 0){
self.maskNode.active = false;
}else{
self.maskNode.active = true;
}
});
},
// 播放影子
playRoleshadowAnimation(name) {
if (!SKUIUtil.isValid(this.RoleshadowNode)) {
cc.warn(`$警告:角色影子播放動畫${name}失敗,角色節點無效`);
return;
}
let anim = this.RoleshadowNode.getComponent(cc.Animation);
if (!anim) {
return;
}
let dir = SKDataUtil.numberByString(name, "_", 1, 1);
let clips = anim.getClips();
for (let clip of clips) {
if (clip.name == name) {
this.RoleshadowNode.active = true;
this.RoleshadowNode.getComponent(cc.Animation).play(name);
return;
}
}
this.RoleshadowNode.active = false;
let self = this;
let url = `ccbtex/shadow/${this.resid}_${name}_sw`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載角色影子動畫資源失敗${url}`);
return;
}
if (!SKUIUtil.isValid(self.RoleshadowNode)) {
cc.warn(`$警告:角色影子播放動畫${name}失敗,角色節點無效`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
curClip.name = name;
if (name.substr(0, 5) == 'stand' || name.substr(0, 3) == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
let nodeAni = self.RoleshadowNode.getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play(name);
}
if (self.tResid > 0 && self.horseList.resId == 0){
self.shadowNode.active = true;
self.RoleshadowNode.active = false;
}else{
self.RoleshadowNode.active = true;
self.shadowNode.active = false;
}
});
},
// 播放附加動畫
playAddonAnimation(name) {
let dir = SKDataUtil.numberByString(name, "_", 1, 1);
if (dir == "1") {
this.roleAddonNode = this.roleAddonBehindNode;
this.roleAddonFrontNode.active = false
}
if (dir == "3") {
this.roleAddonNode = this.roleAddonFrontNode;
this.roleAddonBehindNode.active = false
}
if (!SKUIUtil.isValid(this.roleAddonNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
let anim = this.roleAddonNode.getComponent(cc.Animation);
if (!anim) {
return;
}
let clips = anim.getClips();
for (let clip of clips) {
if (clip.name == name) {
this.roleAddonNode.active = true;
this.roleAddonNode.getComponent(cc.Animation).play(name);
return;
}
}
this.roleAddonNode.active = false;
let self = this;
let url = `shap/${this.resid}/${name}`;
cc.loader.loadRes(url, cc.SpriteAtlas, (error, atlas) => {
if (error) {
cc.warn(`$警告:加載角色動畫資源失敗${url}`);
return;
}
if (!SKUIUtil.isValid(self.roleAddonNode)) {
cc.warn(`$警告:角色播放動畫${name}失敗,角色節點無效`);
return;
}
let curFrames = atlas.getSpriteFrames();
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, 15);
curClip.name = name;
if (name.substr(0, 5) == 'stand' || name.substr(0, 3) == 'run') {
curClip.wrapMode = cc.WrapMode.Loop;
} else {
curClip.wrapMode = cc.WrapMode.Normal;
}
let nodeAni = self.roleAddonNode.getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play(name);
}
self.roleAddonNode.active = true;
});
},
playEff(id) {
if (id == 0) {
this.roleEffNode.active = false;
return
}
var name = `${id}`;
let anim = this.roleEffNode.getComponent(cc.Animation);
if (!anim) {
return;
}
let clips = anim.getClips();
for (let clip of clips) {
if (clip.name == name) {
this.roleEffNode.active = true;
this.roleEffNode.getComponent(cc.Animation).play(name);
return;
}
}
this.roleEffNode.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.roleEffNode)) {
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.roleEffNode.getComponent(cc.Animation);
if (nodeAni) {
nodeAni.addClip(curClip);
nodeAni.play(name);
}
self.roleEffNode.active = true;
});
},
addMovePath(pos) {
if (this.onlyid == GameModel.player.onlyid && GameModel.player.teamid > 0 && GameModel.player.isleader) {
this.movePath.push(pos);
this.node.parent.getComponent('GameMapLogic').setTeamPath();
// if (this.movePath.length > 30) {
// this.movePath.splice(0, this.movePath.length - 30);
// }
}
},
objMove(row, line) {
this._super();
let trow = Math.ceil(row);
let tline = Math.ceil(line);
this.node.stopAllActions();
if (this.actlist.length > 0) {
if (!this.isOpenFootTimer) {
this.isOpenFootTimer = true;
this.addFootEffFunc()
this.schedule(this.addFootEffFunc, 0.3, cc.macro.REPEAT_FOREVER, 0);
}
let curpos = this.actlist.shift();
let samerow = trow == Math.ceil(curpos.info.r);
let sameline = tline == Math.ceil(curpos.info.l);
let trowtmp = Math.ceil(curpos.info.r);
let tlinetmp = Math.ceil(curpos.info.l);
this.addMovePath({
r: curpos.info.r,
l: curpos.info.l
});
while (this.actlist.length > 1) {
trowtmp = Math.ceil(curpos.info.r);
tlinetmp = Math.ceil(curpos.info.l);
let nextpos = this.actlist.shift();
if ((samerow && Math.ceil(nextpos.info.r) == trowtmp) || (sameline && Math.ceil(nextpos.info.l) == tlinetmp)) {
curpos = nextpos;
this.addMovePath({
r: curpos.info.r,
l: curpos.info.l
});
continue;
}
if ((!samerow && !sameline && Math.ceil(nextpos.info.r) != trowtmp && Math.ceil(nextpos.info.l) != tlinetmp)) {
curpos = nextpos;
this.addMovePath({
r: curpos.info.r,
l: curpos.info.l
});
continue;
}
this.actlist.unshift(nextpos);
break;
}
line = curpos.info.l;
row = curpos.info.r;
}
let end_pos = cc.v2(this.gridWidth / 2, this.gridHeight / 2).add(this.getMapPos(line, row));
let addspd = 0;
if (this.onlyid != GameModel.player.onlyid && GameModel.player.teamid > 0 && GameModel.player.isleader && this.teamid == GameModel.player.teamid) {
if (this.actlist.length > 5) {
addspd = (this.actlist - 5) * 3;
}
}
let speed = this.move_speed * this.horseList.getMoveSpeedScale();
let moveDelay = SKUIUtil.distanceByVec2(cc.v2(this.node.x, this.node.y), end_pos) / (speed + addspd);
let self = this;
this.node.runAction(cc.sequence(cc.moveTo(moveDelay, end_pos), cc.callFunc(() => {
if (this.actlist.length > 0 && this.actlist[0].type == 2) {
let act = this.actlist.shift();
self.addMovePath({
r: act.info.r,
l: act.info.l
});
self.objMove(act.info.r, act.info.l);
}
})));
let temindex = 0;
if (this.actlist.length > 3) {
temindex = 2;
} else {
temindex = this.actlist.length - 1;
}
let tempos = end_pos;
if (temindex != -1) {
let act = this.actlist[temindex];
tempos = SKUIUtil.add(cc.v2(this.gridWidth / 2, this.gridHeight / 2), this.getMapPos(act.info.l, act.info.r));
}
let moveAngle = Math.atan2((tempos.y - this.node.y), (tempos.x - this.node.x)) * 180 / Math.PI;
let deltaAngle = Math.abs(Math.abs(this.curangle) - Math.abs(moveAngle));
let horseResId = this.horseList.resId;
if ((moveAngle > 5 && moveAngle < 175) || (moveAngle > 0 && (this.run_type == 0 || deltaAngle > 90))) {
if ((moveAngle > 85 && this.bodyNode.scaleX < 0) || (moveAngle < 85 && this.bodyNode.scaleX > 0)) {
this.bodyNode.scaleX *= -1;
this.horseNode.scaleX *= -1;
this.name2HorseNode.scaleX *= -1;
this.name2Node.scaleX *= -1;
this.nameImgTitleNode.scaleX *= -1;
this.nameImgTitleHorseNode.scaleX *= -1;
}
if (this.run_type != 1) {
this.run_type = 1;
this.dir = 3;
if (horseResId == 0) {
this.loadResThenPlay(`run_${this.dir}`);
if (this.tResid == 0) {
this.addWeaponAnimationByLR("run")
} else {
this.weaponNode.active = false
this.anotherWeaponNode.active = false
}
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, 'run', this.dir);
} else {
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "run", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
}
}
this.curangle = moveAngle;
} else if ((moveAngle > -175 && moveAngle < -5) || (moveAngle <= 0 && (this.run_type == 0 || deltaAngle > 90))) {
if ((moveAngle > -85 && this.bodyNode.scaleX < 0) || (moveAngle < -85 && this.bodyNode.scaleX > 0)) {
this.bodyNode.scaleX *= -1;
this.horseNode.scaleX *= -1;
this.name2HorseNode.scaleX *= -1;
this.name2Node.scaleX *= -1;
this.nameImgTitleNode.scaleX *= -1;
this.nameImgTitleHorseNode.scaleX *= -1;
}
if (this.run_type != 2) {
this.run_type = 2;
this.dir = 1;
if (horseResId == 0) {
this.loadResThenPlay(`run_${this.dir}`);
if (this.tResid == 0)
this.addWeaponAnimationByLR("run")
else {
this.weaponNode.active = false
this.anotherWeaponNode.active = false
}
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, 'run', this.dir);
} else {
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "run", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
}
}
this.curangle = moveAngle;
}
},
playStop() {
if (GameModel.player.teamid > 0 && (GameModel.player.tempLeave || GameModel.player.isleader)) {
if (this.onlyid != GameModel.player.onlyid && GameModel.player.getLogic().living_state != 0) {
this.living_state = 0;
return;
}
}
if (this.actlist.length > 0) {
this.actlist = [];
this.node.stopAllActions();
}
if (this.living_state == 0) {
return;
}
if (this.isOpenFootTimer) {
this.unschedule(this.addFootEffFunc);
this.isOpenFootTimer = false;
}
this.move_tiems = 0;
this.living_state = 0;
let horseResId = this.horseList.resId;
if (this.run_type == 1) {
this.dir = 3;
if (horseResId == 0) {
this.loadResThenPlay(`stand_${this.dir}`);
if (this.tResid == 0)
this.addWeaponAnimationByLR("stand")
else {
this.weaponNode.active = false
this.anotherWeaponNode.active = false
}
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, 'stand', this.dir);
} else {
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
}
} else {
this.dir = 1;
if (horseResId == 0) {
this.loadResThenPlay(`stand_${this.dir}`);
if (this.tResid == 0)
this.addWeaponAnimationByLR("stand")
else {
this.weaponNode.active = false
this.anotherWeaponNode.active = false
}
// CPubFunction.addWeaponAnimation(this.netInfo.weapon, this.weaponNode, this.roleNode, this, this.resid, 'stand', this.dir);
} else {
HorseUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId);
WingUtil.playAni(this.horseNode, this.resid, this.dir, "stand", horseResId, this.wingId);
}
}
this.run_type = 0;
if (this.onlyid != GameModel.player.onlyid) {
return;
}
if (GameModel.player.teamid == 0 || GameModel.player.isleader || GameModel.player.tempLeave) {
this.move_tiems = 0;
let pathlist = [];
for (let index = 0; this.movePath.length > index * 5 && pathlist.length < 5; index++) {
let pos = this.movePath[this.movePath.length - 5 * index - 1];
pathlist.push({
x: Math.round(pos.l),
y: Math.round(pos.r)
});
}
GameModel.send('c2s_aoi_stop', {
accountid: this.netInfo.accountid,
roleId: this.netInfo.roleid,
x: this.netInfo.x,
y: this.netInfo.y,
path: SKDataUtil.toJson(pathlist)
});
let gamelogic = cc.find('Canvas').getComponent('GameLogic');
gamelogic.autoNode.active = false;
}
this.node.parent.getComponent('GameMapLogic').RoleStop(); //判斷是否到傳送點
this.OnArrive();
},
OnArrive() {
if (GameUtil.arriveCallback == null) {
return;
}
if (this.onlyid != GameModel.player.onlyid) {
return;
}
if (SKDataUtil.distance({
x: GameUtil.arriveCallback.x,
y: GameUtil.arriveCallback.y
}, {
x: this.netInfo.x,
y: this.netInfo.y
}) <= 2) {
GameUtil.arriveCallback.callback();
GameUtil.arriveCallback = null;
}
},
checkPos() {
let change = false;
let tline = Math.floor(this.node.x / this.gridWidth);
let trow = Math.floor(this.node.y / this.gridHeight);
if (this.netInfo.x != tline || this.netInfo.y != trow) {
this.netInfo.x = tline;
this.netInfo.y = trow;
change = true;
}
if (GameModel.player.accountid == this.netInfo.accountid) {
if (change) {
let flag = SKDataUtil.intOf2Array(this.gridInfoArr, trow, tline, 2);
if (flag == 2) {
this.node.opacity = 150;
} else {
this.node.opacity = 255;
}
this.move_tiems++;
let gamelogic = (cc.find('Canvas')).getComponent('GameLogic');
gamelogic.uiLogic.setPosition(tline, trow);
}
if (this.move_tiems >= 5) {
this.move_tiems = 0;
if (GameModel.player.teamid == 0 || GameModel.player.isleader || GameModel.player.tempLeave) {
GameModel.send('c2s_aoi_move', {
accountid: this.netInfo.accountid,
roleId: this.netInfo.roleid,
x: this.netInfo.x,
y: this.netInfo.y
});
}
}
}
},
checkInTeam() {
if (GameModel.player.teamid == 0 || !GameModel.player.isleader || !GameModel.player.tempLeave) {
return false;
}
if (!GameModel.player.teamInfo.objlist || !Array.isArray(GameModel.player.teamInfo.objlist)) {
return false;
}
for (let index = 1; index < GameModel.player.teamInfo.objlist.length; index++) {
let obj = GameModel.player.teamInfo.objlist[index];
if (obj.livingtype != 1) {
return false;
}
if (obj.onlyid == this.onlyid) {
return true;
}
}
return false;
},
setObjPos(x, y) {
this._super(x, y);
this.netInfo.x = x;
this.netInfo.y = y;
},
OnClick() {
if (!this.node.active) {
return;
}
if (this.onlyid == GameModel.player.onlyid) {
return;
}
let goBtnAvater = CPubFunction.CreateSubNode(cc.find('Canvas/MainUI'), {
nX: 230,
nY: 120
}, this.btnPlayerAvatar, 'btnPlayerAvatar');
goBtnAvater.getComponent('PlayerAvatar').PlayerAvatar_Init(this.netInfo);
},
showLevelUp() {
this.playEffectStr('levelup', 0, 0);
},
playEffectStr(strEffect, x, y) {
let play = () => {
CPubFunction.CreateSubFrame(this.roleNode, {
nX: x,
nY: y
}, this.effect, strEffect);
};
if (this.effect == null) {
let self = this;
cc.loader.loadRes("Prefabs/EffectFrame", function (err, prefab) {
self.effect = prefab;
if (!SKUIUtil.isValid(self.roleNode)) {
cc.warn(`$警告:角色播放特效失敗,角色節點無效`);
return;
}
play();
});
} else {
play();
}
},
getCurAnimateName() {
// let animation = this.roleNode.getComponent(cc.Animation);
// if (animation) {
// return animation.currentClip.name;
// }
// return null;
},
showColorMask1(color1, color2) {
if (color1.r == 0 && color1.g == 0 && color1.b == 0 && color2.r == 0 && color2.g == 0 && color2.b == 0) {
this.unshowColorMask();
} else {
// this.maskNode = true;
this.maskNode.active = true;
this.zqmaskNode.active = true;
}
this.scheduleOnce(() => {
let logic = this.maskNode.getComponent('role_color');
let zqlogic = this.zqmaskNode.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;
zqlogic.dH1 = t;
} else {
logic.dH1 = 0;
zqlogic.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;
zqlogic.dH2 = t;
} else {
logic.dH2 = 0;
zqlogic.dH2 = 0;
}
}, 0);
},
forzenRole() {
this.isBing = true;
this.loadEff("effect/bing", true, 0, 0, null)
}
});