483 lines
12 KiB
JavaScript
483 lines
12 KiB
JavaScript
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 抽卡召唤动画
|
||
|
|
*
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
const BridgeWindow = require( "bridge.window" );
|
||
|
|
const FxSpine = require( "nx.fx.spine" );
|
||
|
|
const SummonMod = require( "summon.mod" );
|
||
|
|
|
||
|
|
// 超时循环上限
|
||
|
|
const LoopOut = 3;
|
||
|
|
|
||
|
|
// 音效
|
||
|
|
const SFXFolder = "prefab/summon/animation/sfx";
|
||
|
|
const SFXKeys = [
|
||
|
|
// "tv", "light", "cv", "change", "hand",
|
||
|
|
"bgm1", "tv", "light", "cv", "change", "hand",
|
||
|
|
];
|
||
|
|
|
||
|
|
// 翻卡节点
|
||
|
|
const FlipNodes = {
|
||
|
|
"k1": 0, "k2": 1, "k3": 2,
|
||
|
|
"k4": 3, "k5": 4, "k6": 5,
|
||
|
|
"k7": 6, "k8": 7, "k9": 8,
|
||
|
|
"k10": 9,
|
||
|
|
};
|
||
|
|
|
||
|
|
// 阶段定义
|
||
|
|
const Stage = {
|
||
|
|
None: 0,
|
||
|
|
Wait: 1, // 等待循环
|
||
|
|
Anim1: 2, // 动画1
|
||
|
|
Anim2: 3, // 动画2
|
||
|
|
SSR: 4, // SR展示
|
||
|
|
Flip: 5, // 翻卡片
|
||
|
|
Done: 6, // 结束
|
||
|
|
};
|
||
|
|
|
||
|
|
cc.Class( {
|
||
|
|
|
||
|
|
extends: BridgeWindow,
|
||
|
|
|
||
|
|
properties: {
|
||
|
|
nodTouch: { default: null, type: cc.Node },
|
||
|
|
cmpSpine: { default: null, type: FxSpine },
|
||
|
|
cardS: { default: null, type: cc.Node },
|
||
|
|
card10: { default: [], type: cc.Node },
|
||
|
|
nodOps: { default: null, type: cc.Node },
|
||
|
|
},
|
||
|
|
|
||
|
|
// 显示
|
||
|
|
onLoad: function() {
|
||
|
|
|
||
|
|
// 全局支持
|
||
|
|
nx.bridge.summonAnimation = this;
|
||
|
|
|
||
|
|
// 隐藏(因为常驻,不销毁)
|
||
|
|
this.setStage( Stage.Done );
|
||
|
|
this.doStop();
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 关闭
|
||
|
|
onDestroy: function() {
|
||
|
|
|
||
|
|
if( window.nx && nx.bridge ){
|
||
|
|
// 全局支持
|
||
|
|
nx.bridge.summonAnimation = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 开始
|
||
|
|
doStart: function() {
|
||
|
|
|
||
|
|
// 节点隐藏
|
||
|
|
nx.gui.hideAllChildren( this.cardS, "" );
|
||
|
|
this.card10.forEach( card => {
|
||
|
|
nx.gui.hideAllChildren( card, "" );
|
||
|
|
} );
|
||
|
|
|
||
|
|
// UI初始化
|
||
|
|
nx.gui.setActive( this, "panel", true );
|
||
|
|
nx.gui.setActive( this.nodOps, "", false );
|
||
|
|
nx.gui.setActive( this, "panel/closeTip", false );
|
||
|
|
|
||
|
|
this.stepWaiting();
|
||
|
|
},
|
||
|
|
|
||
|
|
// 设置结果
|
||
|
|
setResult: function( _data, _args, _cb ) {
|
||
|
|
this.sumRet = _data || {};
|
||
|
|
this.sumArgs = _args || {};
|
||
|
|
this.sumCB = _cb;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 结束
|
||
|
|
doStop: function() {
|
||
|
|
|
||
|
|
// 通知
|
||
|
|
if( nx.dt.fnGood( this.sumCB ) ) {
|
||
|
|
nx.dt.fnInvoke( this.sumCB, true );
|
||
|
|
this.sumCB = null;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 清理
|
||
|
|
this.sumRet = null;
|
||
|
|
this.sumArgs = null;
|
||
|
|
this.sumCB = null;
|
||
|
|
|
||
|
|
this.cmpSpine.stop( false );
|
||
|
|
nx.gui.setActive( this, "panel", false );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 音效事件
|
||
|
|
trySFX: function( _key ) {
|
||
|
|
|
||
|
|
nx.debug( "$StepEvent:", _key );
|
||
|
|
if( !nx.dt.arrMember( SFXKeys, _key ) ) {
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
let path = cc.path.join( SFXFolder, _key );
|
||
|
|
nx.audio.playSFX( path, false );
|
||
|
|
|
||
|
|
return true;
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段1: 等待
|
||
|
|
stepWaiting: function() {
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
this.setStage( Stage.Wait );
|
||
|
|
|
||
|
|
// 背景
|
||
|
|
let path = cc.path.join( "prefab/summon/animation/bg1" );
|
||
|
|
nx.gui.setSpriteFrame( this, "panel/bg", path );
|
||
|
|
|
||
|
|
// 动画
|
||
|
|
this.loops = 0;
|
||
|
|
this.cmpSpine.action( "action1", true, ( _key ) => {
|
||
|
|
this.trySFX( _key );
|
||
|
|
if( _key == "complete" ) {
|
||
|
|
if( this.sumRet ) {
|
||
|
|
this.stepAnim1();
|
||
|
|
} else {
|
||
|
|
++this.loops;
|
||
|
|
if( this.loops >= LoopOut ) {
|
||
|
|
this.doStop();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段2: 动画1
|
||
|
|
stepAnim1: function() {
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
this.setStage( Stage.Anim1 );
|
||
|
|
|
||
|
|
this.cmpSpine.action( "action2", false, ( _key ) => {
|
||
|
|
this.trySFX( _key );
|
||
|
|
if( _key == "complete" ) {
|
||
|
|
this.stepAnim2();
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段3: 动画2
|
||
|
|
stepAnim2: function() {
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
this.setStage( Stage.Anim2 );
|
||
|
|
|
||
|
|
// 背景
|
||
|
|
let path = cc.path.join( "prefab/summon/animation/bg2" );
|
||
|
|
nx.gui.setSpriteFrame( this, "panel/bg", path );
|
||
|
|
|
||
|
|
// 统计SR&&SSR
|
||
|
|
this.sr = [];
|
||
|
|
this.srs = [];
|
||
|
|
for( let i = 0; i < this.sumRet.partner_bids.length; ++i ) {
|
||
|
|
let pt = this.sumRet.partner_bids[ i ];
|
||
|
|
let base = game.configs.partner_data.data_partner_base[ pt.partner_bid ];
|
||
|
|
if( base && base.quality >= 4 ) {
|
||
|
|
this.srs.push( pt );
|
||
|
|
}
|
||
|
|
if( base && base.quality == 3 ) {
|
||
|
|
this.sr.push( pt );
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 单抽动作: action3_z2, action3_j2, action3_l2
|
||
|
|
// 十连抽动作: action3_z, action3_j
|
||
|
|
let key = "action3_l2";
|
||
|
|
let golden = nx.dt.arrNEmpty( this.srs );
|
||
|
|
if( this.sumRet.partner_bids.length == 1 ) {
|
||
|
|
if( golden ) { key = "action3_j2" }
|
||
|
|
else if( nx.dt.arrNEmpty( this.sr ) ) {
|
||
|
|
key = "action3_z2";
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
key = golden ? "action3_j" : "action3_z";
|
||
|
|
}
|
||
|
|
this.cmpSpine.action( key, false, ( _key ) => {
|
||
|
|
this.trySFX( _key );
|
||
|
|
if( _key == "complete" ) {
|
||
|
|
this.stepSRShow();
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段4: SR&&SSR展示
|
||
|
|
stepSRShow: function() {
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
this.setStage( Stage.SSR );
|
||
|
|
|
||
|
|
// 五星展示
|
||
|
|
const SC = SummonMod.getInstance();
|
||
|
|
if( SC && nx.dt.arrNEmpty( this.srs ) ) {
|
||
|
|
SC.openSummonGainShowWindow( true, this.srs, () => {
|
||
|
|
this.stepFlip();
|
||
|
|
} );
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
this.stepFlip();
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 直达翻卡阶段
|
||
|
|
jumpToFlipCards: function( _data, _args, _cb ) {
|
||
|
|
|
||
|
|
// 节点隐藏
|
||
|
|
nx.gui.hideAllChildren( this.cardS, "" );
|
||
|
|
this.card10.forEach( card => {
|
||
|
|
nx.gui.hideAllChildren( card, "" );
|
||
|
|
} );
|
||
|
|
|
||
|
|
// UI初始化
|
||
|
|
nx.gui.setActive( this, "panel", true );
|
||
|
|
nx.gui.setActive( this.nodOps, "", false );
|
||
|
|
nx.gui.setActive( this, "panel/closeTip", false );
|
||
|
|
|
||
|
|
this.sumRet = _data || {};
|
||
|
|
this.sumArgs = _args || {};
|
||
|
|
this.sumCB = _cb;
|
||
|
|
|
||
|
|
this.stepFlip();
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段5: 翻卡
|
||
|
|
stepFlip: function() {
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
this.setStage( Stage.Flip );
|
||
|
|
|
||
|
|
// 背景
|
||
|
|
let path = cc.path.join( "prefab/summon/animation/bg3" );
|
||
|
|
nx.gui.setSpriteFrame( this, "panel/bg", path );
|
||
|
|
|
||
|
|
// 翻牌处理
|
||
|
|
let self = this;
|
||
|
|
let partners = this.sumRet.partner_bids;
|
||
|
|
let flip = function( _root, _info ) {
|
||
|
|
|
||
|
|
let node = _root.children[ 0 ];
|
||
|
|
if( !node ) {
|
||
|
|
let tmp = nx.gui.find( self, "panel/tmp/cardT" );
|
||
|
|
node = cc.instantiate( tmp );
|
||
|
|
node.parent = _root;
|
||
|
|
}
|
||
|
|
|
||
|
|
node.active = true;
|
||
|
|
node.position = cc.Vec2.ZERO;
|
||
|
|
let card = node.getComponent( "cmp.summon.animation.card" );
|
||
|
|
card.flip( _info );
|
||
|
|
|
||
|
|
let sfx = cc.path.join( SFXFolder, "card" );
|
||
|
|
nx.audio.playSFX( sfx, false );
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
// 单抽
|
||
|
|
let flipS = function() {
|
||
|
|
flip( self.cardS, partners[ 0 ] );
|
||
|
|
};
|
||
|
|
|
||
|
|
// 十连抽
|
||
|
|
let flip10 = function( _key ) {
|
||
|
|
|
||
|
|
let index = FlipNodes[ _key ];
|
||
|
|
if( !nx.dt.numGood( index ) ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let root = self.card10[ index ];
|
||
|
|
if( !root ) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
flip( root, partners[ index ] );
|
||
|
|
|
||
|
|
};
|
||
|
|
|
||
|
|
// 动画
|
||
|
|
let key = ( partners.length == 1 ) ? "action5" : "action4";
|
||
|
|
this.cmpSpine.action( key, false, ( _key ) => {
|
||
|
|
|
||
|
|
this.trySFX( _key );
|
||
|
|
|
||
|
|
// 单抽
|
||
|
|
if( _key == "k0" ) {
|
||
|
|
flipS();
|
||
|
|
} else {
|
||
|
|
flip10( _key );
|
||
|
|
}
|
||
|
|
|
||
|
|
if( _key == "complete" ) {
|
||
|
|
// 阶段更新
|
||
|
|
this.stepOps();
|
||
|
|
}
|
||
|
|
} );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段6: 操作菜单显示
|
||
|
|
stepOps: function() {
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
this.setStage( Stage.Done );
|
||
|
|
|
||
|
|
// 没有特殊操作
|
||
|
|
if( nx.dt.objEmpty( this.sumArgs ) ) {
|
||
|
|
nx.gui.setActive( this, "panel/closeTip", true );
|
||
|
|
nx.tween.fadeIn( this, "panel/closeTip", 0.5 );
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
let op = this.sumArgs.op || "summon";
|
||
|
|
this.nodOps.children.forEach( _node => {
|
||
|
|
_node.active = ( _node.name == op );
|
||
|
|
} );
|
||
|
|
|
||
|
|
switch( op ) {
|
||
|
|
|
||
|
|
// 召唤面板
|
||
|
|
case "summon": {
|
||
|
|
this.freshSummonOps( this.sumArgs );
|
||
|
|
} break;
|
||
|
|
|
||
|
|
// 无限十连抽
|
||
|
|
case "infinite": {
|
||
|
|
this.freshInfiniteOps( this.sumArgs );
|
||
|
|
} break;
|
||
|
|
|
||
|
|
// 无法识别
|
||
|
|
default: {
|
||
|
|
nx.error( "$SumAnimation:无效OP:", op );
|
||
|
|
nx.gui.setActive( this, "panel/closeTip", true );
|
||
|
|
nx.tween.fadeIn( this, "panel/closeTip", 0.5 );
|
||
|
|
return;
|
||
|
|
} break;
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
// 显示
|
||
|
|
nx.gui.setActive( this.nodOps, "", true );
|
||
|
|
nx.tween.fadeIn( this.nodOps, "", 0.5 );
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击背景
|
||
|
|
onTouchBG: function() {
|
||
|
|
|
||
|
|
// 不同阶段处理
|
||
|
|
switch( this.stage ) {
|
||
|
|
|
||
|
|
// 动画阶段
|
||
|
|
case Stage.Anim1:
|
||
|
|
case Stage.Anim2: {
|
||
|
|
this.cmpSpine.stop( false );
|
||
|
|
this.stepFlip();
|
||
|
|
} break;
|
||
|
|
|
||
|
|
// 结束阶段
|
||
|
|
case Stage.Done: {
|
||
|
|
|
||
|
|
// 直接关闭
|
||
|
|
if( !this.nodOps.active ) {
|
||
|
|
this.doStop();
|
||
|
|
}
|
||
|
|
} break;
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 阶段更新
|
||
|
|
setStage: function( _stage ) {
|
||
|
|
nx.debug( "$SumAnimation:阶段改变:", this.stage, _stage );
|
||
|
|
this.stage = _stage;
|
||
|
|
},
|
||
|
|
|
||
|
|
// ======================================================
|
||
|
|
// 二次操作相关
|
||
|
|
// ======================================================
|
||
|
|
|
||
|
|
// 刷新召唤面板
|
||
|
|
/**
|
||
|
|
* 参数结构
|
||
|
|
* op: "summon",
|
||
|
|
* bid: 所需道具编号
|
||
|
|
* need: 所需道具数量
|
||
|
|
* txt: 按钮文本
|
||
|
|
* cb: 点击回调
|
||
|
|
*/
|
||
|
|
freshSummonOps: function( _args ) {
|
||
|
|
|
||
|
|
let node = nx.gui.find( this.nodOps, "summon/draw" );
|
||
|
|
if( node ) {
|
||
|
|
let cfg = gitemdata( _args.bid );
|
||
|
|
nx.bridge.setIcon( node, "need/list/icon", cfg ? cfg.icon : 0 );
|
||
|
|
nx.gui.setString( node, "need/list/num", _args.need );
|
||
|
|
nx.gui.setString( node, "btn/txt", nx.text.getKey( _args.txt ) );
|
||
|
|
}
|
||
|
|
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击召唤取消
|
||
|
|
onTouchSummonCancel: function() {
|
||
|
|
if( this.sumArgs ) {
|
||
|
|
nx.dt.fnInvoke( this.sumArgs.cb, false );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击召唤
|
||
|
|
onTouchSummonConfirm: function() {
|
||
|
|
if( this.sumArgs ) {
|
||
|
|
nx.dt.fnInvoke( this.sumArgs.cb, true );
|
||
|
|
}
|
||
|
|
},
|
||
|
|
|
||
|
|
// 刷新无限十连抽
|
||
|
|
/**
|
||
|
|
* 参数结构
|
||
|
|
* op: "infinite",
|
||
|
|
* cb: 点击回调(0:再抽 1:满意)
|
||
|
|
*/
|
||
|
|
freshInfiniteOps: function( _args ) {
|
||
|
|
|
||
|
|
// 剩餘次數
|
||
|
|
let times = nx.bridge.vget( "INFTimes" ) || 0;
|
||
|
|
nx.gui.setString( this.nodOps, "infinite/times/txt", nx.text.format( "剩余次数", times ) );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击不满意
|
||
|
|
onTouchInfiniteAgain: function() {
|
||
|
|
nx.dt.fnInvoke( this.sumArgs.cb, false );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击满意
|
||
|
|
onTouchInfiniteOK: function() {
|
||
|
|
nx.dt.fnInvoke( this.sumArgs.cb, true );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击方案
|
||
|
|
onTouchInfiniteRecord: function() {
|
||
|
|
nx.bridge.createPanel( "WndSummonInfiniteRecord", { replace: true } );
|
||
|
|
},
|
||
|
|
|
||
|
|
// 点击关闭
|
||
|
|
onTouchInfiniteClose: function() {
|
||
|
|
this.sumCB = null;
|
||
|
|
this.doStop();
|
||
|
|
},
|
||
|
|
|
||
|
|
} );
|