224 lines
8.6 KiB
TypeScript
224 lines
8.6 KiB
TypeScript
import SKUIUtil from "../../ts/gear_2.3.4/util/SKUIUtil";
|
|
import GameModel from "../../ts/core/GameModel";
|
|
import GameUtil from "../../ts/core/GameUtil";
|
|
|
|
//人物武器相關
|
|
export default class WeaponUtil {
|
|
static shared: WeaponUtil = new WeaponUtil();
|
|
static debug: boolean = false;
|
|
|
|
constructor() {
|
|
}
|
|
|
|
static getWeaponName(equip: any): string {
|
|
let weaponname = '';
|
|
if (equip.type == 0) {
|
|
weaponname = '0000';
|
|
} //新手裝備
|
|
if (equip.type == 1) { //高級裝備
|
|
weaponname = '0100';
|
|
if (equip.level == 100 && equip.gemcnt >= 10) { //100級打滿寶石
|
|
weaponname = '0101';
|
|
} else if (equip.level == 120) { //120級
|
|
weaponname = '0200';
|
|
if (equip.gemcnt >= 12) { //打滿寶石
|
|
weaponname = '0202';
|
|
}
|
|
}
|
|
} else if (equip.type == 2) {
|
|
weaponname = '0300';
|
|
if (equip.gemcnt >= 13) {
|
|
weaponname = '0302';
|
|
} else if (equip.gemcnt >= 10) {
|
|
weaponname = '0301';
|
|
}
|
|
} else if (equip.type == 3) {
|
|
weaponname = '0400';
|
|
if (equip.level == 5) {
|
|
weaponname = '0601';
|
|
} else if (equip.gemcnt >= 16) {
|
|
weaponname = '0501';
|
|
} else if (equip.gemcnt >= 13) {
|
|
weaponname = '0403';
|
|
} else if (equip.gemcnt >= 10) {
|
|
weaponname = '0401';
|
|
}
|
|
}
|
|
return weaponname;
|
|
}
|
|
|
|
static getWeaponURL(act: string, dir: number, weaponname: string, resid: number): string {
|
|
return '/weapon/' + resid + "/" + weaponname + "_" + act + "_" + dir + "_" + "wp";
|
|
}
|
|
|
|
static addWeaponAnimation(weaponInfo: any, weaponNode: cc.Node, animationNode: cc.Node, logic: any, resid: number, act: string, dir: number, open: number) {
|
|
if (animationNode.name.length < 1) {
|
|
cc.log("?");
|
|
}
|
|
if (!animationNode || !weaponNode || GameUtil.roleName[resid] == null || animationNode.active == false) {
|
|
return;
|
|
}
|
|
let clips = weaponNode.getComponent(cc.Animation).getClips();
|
|
for (const clip of clips) {
|
|
if (clip.name == act) {
|
|
weaponNode.getComponent(cc.Animation).stop(act);
|
|
weaponNode.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
}
|
|
let z = animationNode.getSiblingIndex();
|
|
if (dir == 5 && resid == 2033) {
|
|
weaponNode.setSiblingIndex(z - 1);
|
|
} else if (dir == 7 && resid == 4017) {
|
|
weaponNode.setSiblingIndex(z - 1);
|
|
}
|
|
else {
|
|
weaponNode.setSiblingIndex(z + 1);
|
|
}
|
|
weaponNode.active = false;
|
|
let weaponname = '0000';
|
|
if (weaponInfo && weaponInfo.length > 0) {
|
|
weaponname = this.getWeaponName(JSON.parse(weaponInfo));
|
|
}
|
|
let url = `weapon/${resid}/${weaponname}_${act}_${dir}_wp`;
|
|
if (resid == 1111 && weaponname != '0601') {
|
|
url = `weapon/${resid}/${weaponname}_${act}_${dir}_wp_l`;
|
|
}
|
|
if (resid == 1131 && weaponname == '0601') {
|
|
if (dir == 3 && act == 'run') {
|
|
weaponNode.x = -17;
|
|
} else {
|
|
weaponNode.x = 0;
|
|
}
|
|
// } else if (resid == 1001 && open == 2 && weaponname == '0601') {
|
|
// weaponNode.y = -4;
|
|
// weaponNode.scale = 0.95;
|
|
} else if (resid == 2034 && weaponname == '0601') {
|
|
if (dir == 5 && act == 'run') {
|
|
weaponNode.x = -17;
|
|
} else {
|
|
weaponNode.x = 0;
|
|
}
|
|
} else if (resid == 4017 && weaponname == '0601') {
|
|
if (dir == 5 || dir == 1 && act == 'stand') {
|
|
weaponNode.x = -17;
|
|
} else if (dir == 8 && act == 'stand') {
|
|
weaponNode.y = -8;
|
|
}
|
|
else {
|
|
weaponNode.x = 0;
|
|
}
|
|
}
|
|
cc.loader.loadRes(url, cc.SpriteAtlas, function (error, atlas) {
|
|
if (error) {
|
|
cc.warn("加載武器資源錯誤", url, error.message);
|
|
return;
|
|
}
|
|
if (!animationNode || !animationNode.parent || animationNode.parent.parent == null) return;
|
|
if (Array.isArray(atlas)) {
|
|
return;
|
|
}
|
|
let curFrames = [];
|
|
for (let i = 1; ; i++) {
|
|
let frame = atlas.getSpriteFrame(i);
|
|
if (frame) curFrames.push(frame);
|
|
else break;
|
|
}
|
|
let fn = 15;
|
|
// if(weaponname == '0601'){
|
|
// fn = 10;
|
|
// }
|
|
let curClip = cc.AnimationClip.createWithSpriteFrames(curFrames, fn);
|
|
curClip.name = act;
|
|
if (act == 'stand' || act == 'run') {
|
|
curClip.wrapMode = cc.WrapMode.Loop;
|
|
} else {
|
|
curClip.wrapMode = cc.WrapMode.Normal;
|
|
}
|
|
let nodeAni = weaponNode.getComponent(cc.Animation);
|
|
nodeAni.addClip(curClip);
|
|
nodeAni.play(act);
|
|
logic.scheduleOnce(() => {
|
|
weaponNode.anchorY = GameModel.conf_res_anchor[resid].anchorY;
|
|
weaponNode.anchorX = GameModel.conf_res_anchor[resid].anchorX;
|
|
if (open == undefined||open == 2) {
|
|
//weaponNode.scaleX = 500 / weaponNode.width;
|
|
//weaponNode.scaleY = 500 / weaponNode.height;
|
|
weaponNode.scaleX = animationNode.width / weaponNode.width;
|
|
weaponNode.scaleY = animationNode.height / weaponNode.height;
|
|
} else {
|
|
weaponNode.scaleX = 450 / weaponNode.width;
|
|
weaponNode.scaleY = 450 / weaponNode.height;
|
|
}
|
|
}, 0);
|
|
weaponNode.active = true;
|
|
});
|
|
|
|
if (!animationNode.getChildByName('addon')) {
|
|
let addon = new cc.Node();
|
|
addon.parent = animationNode;
|
|
addon.addComponent(cc.Animation);
|
|
let addonsp = addon.addComponent(cc.Sprite);
|
|
addonsp.trim = false;
|
|
addonsp.sizeMode = cc.Sprite.SizeMode.RAW;
|
|
addon.name = 'addon';
|
|
}
|
|
let addonNode = animationNode.getChildByName('addon');
|
|
let addonclips = addonNode.getComponent(cc.Animation).getClips();
|
|
for (const clip of addonclips) {
|
|
if (clip.name == act) {
|
|
addonNode.getComponent(cc.Animation).stop(act);
|
|
addonNode.getComponent(cc.Animation).removeClip(clip, true);
|
|
}
|
|
}
|
|
addonNode.active = false;
|
|
let addonname = weaponname.substr(0, 3) + '0';
|
|
let urls = `weapon/${resid}/${weaponname}_${act}_${dir}_wp_addon`;
|
|
if (resid == 1111 && weaponname != '0601') {
|
|
urls = `weapon/${resid}/${weaponname}_${act}_${dir}_wp_r`;
|
|
}
|
|
if (resid == 3006 && weaponname != '0601') {
|
|
urls = `weapon/${resid}/${weaponname}_${act}_${dir}_addon`;
|
|
}
|
|
cc.loader.loadRes(urls, cc.SpriteAtlas, function (err, atlas) {
|
|
if (!animationNode || !animationNode.parent || !animationNode.parent.parent == null) return;
|
|
if (Array.isArray(atlas)) {
|
|
return;
|
|
}
|
|
let addonani = addonNode.getComponent(cc.Animation);
|
|
let addonsp = addonNode.getComponent(cc.Sprite);
|
|
addonsp.spriteFrame = atlas.getSpriteFrame(0);
|
|
let addonFrames = [];
|
|
for (let i = 1; ; i++) {
|
|
let frame = atlas.getSpriteFrame(i);
|
|
if (frame) addonFrames.push(frame);
|
|
else break;
|
|
}
|
|
let fn = 15;
|
|
if(weaponname == '0601'&&act == 'stand'){
|
|
fn = 10;
|
|
}
|
|
let curClip = cc.AnimationClip.createWithSpriteFrames(addonFrames, fn);
|
|
curClip.name = act;
|
|
if (act == 'stand' || act == 'run') {
|
|
curClip.wrapMode = cc.WrapMode.Loop;
|
|
} else {
|
|
curClip.wrapMode = cc.WrapMode.Normal;
|
|
}
|
|
addonani.addClip(curClip);
|
|
addonani.play(act);
|
|
logic.scheduleOnce(() => {
|
|
addonNode.scaleX = animationNode.width / addonNode.width;
|
|
addonNode.scaleY = animationNode.height / addonNode.height;
|
|
addonNode.anchorY = weaponNode.anchorY;
|
|
addonNode.anchorX = weaponNode.anchorX;
|
|
}, 0);
|
|
if(weaponNode.active == true){
|
|
addonNode.active = true;
|
|
}else{
|
|
addonNode.active = false;
|
|
}
|
|
|
|
});
|
|
}
|
|
}
|