539 lines
15 KiB
JavaScript
539 lines
15 KiB
JavaScript
/******************************************************************
|
|
*
|
|
* 大富翁活动
|
|
*
|
|
******************************************************************/
|
|
|
|
const ActPage = require( "act.page.base" );
|
|
const CircleWalkRole = require( "cmp.monopoly.role" );
|
|
const TipsController = require( "tips_controller" );
|
|
const MainuiController = require( "mainui_controller" );
|
|
const ItemLayout = require( "cmp.item.layout" );
|
|
const BackPackController = require( "backpack_controller" );
|
|
const BridgeItemBinder = require( "bridge.binder.item.icon.count" );
|
|
const FxSpine = require( "nx.fx.spine" );
|
|
|
|
const MAX_DICE = 6; // 最大步长
|
|
const LEN_PATH = 30; // 路径长度
|
|
|
|
cc.Class( {
|
|
|
|
extends: ActPage,
|
|
|
|
properties: {
|
|
|
|
mapRefs: { default: null, type: cc.Node },
|
|
mapRewards: { default: null, type: cc.Node },
|
|
mapWalkable: { default: null, type: cc.Node },
|
|
|
|
lstRewards: { default: null, type: cc.Node },
|
|
cmpRole: { default: null, type: CircleWalkRole },
|
|
tipCover: { default: null, type: cc.Node },
|
|
nodGo: { default: null, type: cc.Node },
|
|
nodAuto: { default: null, type: cc.Node },
|
|
lstMenu: { default: null, type: cc.Node },
|
|
tipReward: { default: null, type: ItemLayout },
|
|
nodScore: { default: null, type: BridgeItemBinder },
|
|
nodScore2: { default: null, type: BridgeItemBinder },
|
|
nodTimes: { default: null, type: cc.Node },
|
|
spDice: { default: null, type: FxSpine },
|
|
|
|
auDice: { default: null, type: cc.AudioClip },
|
|
auFoot: { default: null, type: cc.AudioClip },
|
|
|
|
secAuto: { default: 3 },
|
|
},
|
|
|
|
// 初始化
|
|
build: function( _data ) {
|
|
|
|
this._super( _data );
|
|
|
|
// 置空
|
|
if( !this.mod || nx.dt.objEmpty( this.data ) ) {
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 基本信息
|
|
this.freshBasic();
|
|
|
|
// 活动监听
|
|
this.mod.vbind( this, [
|
|
["cwGroup", this.onGroupChanged.bind( this )],
|
|
["cwPosition", this.onPosChanged.bind( this )],
|
|
["cwDice", this.onDiceChanged.bind( this )],
|
|
["cwRewards", this.onRewardChanged.bind( this )],
|
|
["cwTime", this.onTimeChanged.bind( this )],
|
|
["cwSteps", this.onStepChanged.bind( this )],
|
|
["cwAutoDice", this.onAutoDice.bind( this )],
|
|
] );
|
|
|
|
},
|
|
|
|
// 显示
|
|
onEnable: function() {
|
|
|
|
this.doing = false;
|
|
this.tipCover.active = false;
|
|
nx.gui.setActive( this.spDice, "", false );
|
|
|
|
// 刷新
|
|
if( this.mod ) {
|
|
this.mod.reqBaseData();
|
|
}
|
|
},
|
|
|
|
// 销毁
|
|
onDestroy: function() {
|
|
|
|
// 活动监听解除
|
|
if( this.mod ) {
|
|
this.mod.vunbind( this );
|
|
}
|
|
|
|
this._super();
|
|
},
|
|
|
|
// 置空
|
|
setEmpty: function() {
|
|
nx.gui.setActive( this, "right", false );
|
|
},
|
|
|
|
// 基本信息
|
|
freshBasic: function() {
|
|
|
|
// 骰子货币
|
|
let data = this.mod.queryConfig();
|
|
this.coinId = data ? data.item : 0;
|
|
|
|
// 冒险角色
|
|
this.cmpRole.setModel( data.model, ( _key ) => {
|
|
this.roleEvent( _key );
|
|
} );
|
|
|
|
// 道具绑定
|
|
this.nodScore.setID( data.item1 );
|
|
this.nodScore2.setID( data.item2 );
|
|
|
|
nx.bridge.setIconS( this.nodGo, "list/icon", this.coinId );
|
|
},
|
|
|
|
// 组改变
|
|
onGroupChanged: function( _gindex ) {
|
|
|
|
// 格子奖励
|
|
let items = [];
|
|
let DATA = this.mod.queryRoundRewards( _gindex );
|
|
for( let i in DATA ) {
|
|
let ifo = DATA[i];
|
|
if( ifo && ifo.item_bid > 0 && ifo.num > 0 ) {
|
|
items.push( ifo );
|
|
}
|
|
}
|
|
|
|
if( items.length == 0 ) {
|
|
return;
|
|
}
|
|
|
|
let chds = this.mapRewards.children;
|
|
nx.gui.gocChildren( this.mapRewards, "", items.length, chds[0] );
|
|
for( let i = 0; i < chds.length; ++i ) {
|
|
|
|
let node = chds[i];
|
|
let info = items[i];
|
|
if( !info ) {
|
|
nx.gui.setSpriteFrame( node, "icon", null );
|
|
nx.gui.setString( node, "num", "" );
|
|
continue;
|
|
}
|
|
|
|
node.position = this.queryPosition( info.pos );
|
|
node.info = info;
|
|
let cfg = gitemdata( info.item_bid );
|
|
nx.bridge.setIcon( node, "icon", cfg ? cfg.icon : "" );
|
|
nx.gui.setString( node, "num", cfg ? info.num : "" );
|
|
|
|
let cmp = nx.gui.getComponent( node, "icon", "nx.actor.suspending", true );
|
|
if( cmp ) {
|
|
cmp.start( 2, 10 );
|
|
}
|
|
|
|
}
|
|
},
|
|
|
|
// 位置改变
|
|
onPosChanged: function( _pos ) {
|
|
let pos = this.queryPosition( _pos );
|
|
this.cmpRole.node.position = pos;
|
|
},
|
|
|
|
// 筛子信息改变
|
|
onDiceChanged: function( _info ) {
|
|
|
|
// for( let i = 1; i <= 4; ++i ) {
|
|
// let tog = this.lstMenu.getChildByName( `tog${i}` );
|
|
// let vis = false;
|
|
// for( let id in _info ) {
|
|
// if( _info[id].num == i ) {
|
|
// vis = true;
|
|
// break;
|
|
// }
|
|
// }
|
|
// tog.active = vis;
|
|
// tog.scale = 1.0;
|
|
// }
|
|
},
|
|
|
|
// 奖励改变
|
|
onRewardChanged: function( _info ) {
|
|
|
|
// 状态转动作
|
|
// status: 0-未完成,1-可领取,2-已领取
|
|
// action1 普通状态
|
|
// action2 可开启状态
|
|
// action3 开启过程,reword事件出获得道具
|
|
// action4 开完状态
|
|
let st2act = function( _st ) {
|
|
switch( _st ) {
|
|
case 0: return 'action1';
|
|
case 1: return 'action2';
|
|
case 2: return 'action4';
|
|
default: return 'action1';
|
|
}
|
|
};
|
|
|
|
// 单设
|
|
let self = this;
|
|
let single = function( _box, _time, _data ) {
|
|
|
|
// 宝箱更新
|
|
let act = st2act( _data.status );
|
|
let res = PathTool.getSpinePath( _data.res_id, "action", false );
|
|
let cmp = nx.gui.getComponent( _box, "", "nx.fx.spine" );
|
|
cmp.play( res, act, null, true );
|
|
_box.prayData = _data;
|
|
nx.gui.setActive( _box, "tip", _data.status == 1 );
|
|
|
|
// 次数更新
|
|
nx.gui.setString( _time, "num", _data.limit );
|
|
nx.gui.setActive( _time, "mk/on", _data.status != 0 );
|
|
nx.gui.setActive( _time, "mk/off", _data.status == 0 );
|
|
}
|
|
|
|
// 0-未领取, 1-可领取, 2-已领取
|
|
let count = 0;
|
|
let list = this.mod.queryBoxes();
|
|
for( let i = 0; i < list.length; ++i ) {
|
|
let item = list[i];
|
|
single(
|
|
nx.gui.find( this.lstRewards, `boxes/b${item.index}` ),
|
|
nx.gui.find( this.lstRewards, `times/t${item.index}` ),
|
|
item );
|
|
if( item.status != 0 ) {
|
|
++count;
|
|
}
|
|
}
|
|
|
|
// 进度
|
|
let prog = nx.gui.getComponent( this.lstRewards, "progress", cc.ProgressBar );
|
|
if( prog ) {
|
|
let cfgs = this.mod.queryConfig();
|
|
let times = this.mod.vget( 'cwSteps' );
|
|
prog.progress = times / cfgs.max;
|
|
}
|
|
|
|
},
|
|
|
|
// 结束时间改变
|
|
onTimeChanged: function( _time ) {
|
|
|
|
// let txt = nx.bridge.time.toNeedTime( time );
|
|
// nx.gui.setString( this.nodDate, "txt", txt );
|
|
},
|
|
|
|
// 次數改变
|
|
onStepChanged: function( _times ) {
|
|
// let cfgs = this.mod.queryConfig();
|
|
// nx.gui.setString( this.nodTimes, "txt", `${_times}/${cfgs.max}` )
|
|
nx.gui.setString( this.nodTimes, "txt", `${_times}` )
|
|
},
|
|
|
|
// 获取指定格子坐标
|
|
queryPosition: function( _gpos ) {
|
|
|
|
let node = nx.gui.find( this.mapRefs, "p" + _gpos );
|
|
if( !node ) {
|
|
nx.error( "CircleWalk:无效位置 ", _gpos );
|
|
return null;
|
|
}
|
|
|
|
return node.position;
|
|
},
|
|
|
|
// 点击规则
|
|
onTouchRule: function() {
|
|
|
|
let rule = this.mod ? this.mod.queryRule() : "";
|
|
if( nx.dt.strNEmpty( rule ) ) {
|
|
const TC = TipsController.getInstance();
|
|
TC.showTextPanel( "tip", rule );
|
|
}
|
|
},
|
|
|
|
// 点击商城
|
|
onTouchShop: function() {
|
|
let cfgs = this.mod.queryConfig();
|
|
if( cfgs && this.actRoot ) {
|
|
this.actRoot.jumpToMenu( cfgs.shop );
|
|
}
|
|
},
|
|
|
|
// 点击商城
|
|
onTouchExchangeShop: function() {
|
|
nx.bridge.jumper.jump2Window( 474 );
|
|
},
|
|
|
|
// 角色事件
|
|
roleEvent: function( _key ) {
|
|
|
|
// 音效关闭
|
|
if( this.footHandle > 0 ) {
|
|
cc.audioEngine.stopEffect( this.footHandle );
|
|
this.footHandle = 0;
|
|
}
|
|
|
|
// 开始
|
|
if( _key == "start" ) {
|
|
if( this.auFoot ) {
|
|
this.footHandle = cc.audioEngine.playEffect( this.auFoot, true );
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 结束
|
|
let self = this;
|
|
let success = function( _rewards = [] ) {
|
|
|
|
let lst = [];
|
|
for( let i = 0; i < _rewards.length; ++i ) {
|
|
let rt = _rewards[i];
|
|
if( rt ) {
|
|
lst.push( { bid: rt.item_bid, num: rt.num } );
|
|
}
|
|
}
|
|
|
|
let auto = self.mod.vget( "cwAutoDice" );
|
|
let done = function() {
|
|
if( auto && self.mod.itemHave() > 0 ) {
|
|
self.onTouchDice();
|
|
}
|
|
};
|
|
|
|
// 无奖励直接判断自动投掷
|
|
if( nx.dt.arrEmpty( lst ) ) {
|
|
done();
|
|
return;
|
|
}
|
|
|
|
let args = {};
|
|
if( auto ) {
|
|
args.delay = {
|
|
secs: self.secAuto,
|
|
cb: () => {
|
|
done();
|
|
}
|
|
}
|
|
}
|
|
let MC = MainuiController.getInstance();
|
|
MC.openGetItemView( true, lst, args );
|
|
};
|
|
|
|
let failed = function() {
|
|
|
|
// 角色归位
|
|
let cur = self.mod.vget( "cwPosition" );
|
|
let pos = self.queryPosition( cur );
|
|
if( pos ) {
|
|
self.cmpRole.node.position = pos;
|
|
}
|
|
|
|
// 道具数量归位
|
|
let model = BackPackController.getInstance().getModel();
|
|
let count = model.getBackPackItemNumByBid( self.coinId );
|
|
nx.gui.setString( self.nodStart, "need/num", count );
|
|
|
|
};
|
|
|
|
this.doing = false;
|
|
let rewards = this.mod.vget( "cwRewardList" );
|
|
success( rewards );
|
|
},
|
|
|
|
// 点击格子奖励
|
|
onTouchGridGift: function( _node ) {
|
|
|
|
let info = _node.currentTarget.info;
|
|
if( info && info.item_bid > 0 ) {
|
|
const TC = TipsController.getInstance();
|
|
if( TC ) {
|
|
TC.showItemTips( info.item_bid );
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
// 点击宝箱
|
|
onTouchBox: function( _box ) {
|
|
|
|
let info = _box ? _box.prayData : null;
|
|
if( !info ) {
|
|
return;
|
|
}
|
|
|
|
// 详情
|
|
if( info.status != 1 ) {
|
|
if( nx.dt.arrNEmpty( info.rewards ) ) {
|
|
this.tipCover.active = true;
|
|
this.tipReward.rebuild( info.rewards );
|
|
let pos = _box.convertToWorldSpaceAR( cc.Vec2.ZERO );
|
|
pos = this.tipCover.convertToNodeSpaceAR( pos );
|
|
this.tipReward.node.y = pos.y;
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 拆盒
|
|
// action3 开启过程,reword事件出获得道具
|
|
let cmp = nx.gui.getComponent( _box, "", "nx.fx.spine" );
|
|
if( cmp ) {
|
|
cmp.action( "action3", false, ( _event ) => {
|
|
|
|
// 音效
|
|
if( _event == 'reword' ) {
|
|
nx.audio.playSFX( "audios/effects/del", false );
|
|
}
|
|
|
|
// 完成
|
|
if( _event == 'complete' ) {
|
|
this.mod.reqOpenBox();
|
|
}
|
|
} );
|
|
}
|
|
|
|
},
|
|
|
|
// 点击提示覆盖层
|
|
onTouchTipCover: function() {
|
|
this.tipCover.active = false;
|
|
},
|
|
|
|
// 自动步数
|
|
onAutoDice: function( _ten ) {
|
|
nx.gui.setActive( this.nodAuto, "ck/on", _ten );
|
|
},
|
|
|
|
// 十连切换
|
|
onTogAuto: function() {
|
|
let ten = this.mod.vget( 'cwAutoDice' );
|
|
this.mod.vset( 'cwAutoDice', !ten );
|
|
},
|
|
|
|
// 扔色子
|
|
onTouchDice: function() {
|
|
|
|
this.onTouchOnce();
|
|
// let ten = this.mod.vget( 'cwAutoDice' );
|
|
// if( ten ) {
|
|
// this.onTouchTen();
|
|
// } else {
|
|
// this.onTouchOnce();
|
|
// }
|
|
},
|
|
|
|
// 单抽
|
|
onTouchOnce: function() {
|
|
|
|
// 进行中
|
|
if( this.doing ) {
|
|
nx.tbox( "MonoDoing" );
|
|
return;
|
|
}
|
|
|
|
if( !this.mod.itemHave() ) {
|
|
nx.tbox( "SummonItemNotEnough" );
|
|
this.onTouchShop();
|
|
return;
|
|
}
|
|
|
|
this.doing = true;
|
|
this.mod.reqStartRoll( ( _ret, _data ) => {
|
|
|
|
if( !_ret ) {
|
|
this.doing = false;
|
|
// nx.tbox( _data );
|
|
return;
|
|
}
|
|
|
|
// 过程模拟
|
|
this.simProgress( _data.num, _data.next_pos );
|
|
} );
|
|
},
|
|
|
|
// 十连抽
|
|
onTouchTen: function() {
|
|
this.mod.reqRewardTen();
|
|
},
|
|
|
|
// 投掷过程模拟
|
|
simProgress: function( _dice, _pos ) {
|
|
|
|
let self = this;
|
|
|
|
// 移动
|
|
let move = function() {
|
|
|
|
let pts = [];
|
|
let well = false;
|
|
let cur = self.mod.vget( "cwPosition" );
|
|
for( let i = 0; i < MAX_DICE; ++i ) {
|
|
let pos = cur + i + 1;
|
|
if( pos > LEN_PATH ) {
|
|
pos = pos % LEN_PATH;
|
|
}
|
|
pts.push( self.queryPosition( pos ) );
|
|
if( pos == _pos ) {
|
|
well = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 出错
|
|
if( !well ) {
|
|
nx.error( "Mono:路径模拟失败,无效坐标: %s -> %s", cur, _pos );
|
|
self.doing = false;
|
|
return;
|
|
}
|
|
|
|
self.cmpRole.pushPaths( pts );
|
|
|
|
};
|
|
|
|
// 扔骰子
|
|
nx.gui.setActive( this.spDice, "", true );
|
|
this.spDice.action( "ret" + _dice, false, ( _event ) => {
|
|
if( _event == "complete" ) {
|
|
move();
|
|
nx.gui.setActive( this.spDice, "", false );
|
|
}
|
|
} );
|
|
|
|
// 投掷音效
|
|
if( this.auDice ) {
|
|
cc.audioEngine.playEffect( this.auDice, false );
|
|
}
|
|
|
|
this.curDice = _dice;
|
|
},
|
|
|
|
} ); |