525 lines
13 KiB
JavaScript
525 lines
13 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'e4953VgNb5FcJ//cn49opU5', 'act.circle.walk.page');
|
|
// Scripts/mod/acts/circleWalk/act.circle.walk.page.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 大富翁活动
|
|
*
|
|
******************************************************************/
|
|
|
|
var ActPage = require("act.page.base");
|
|
var CircleWalkRole = require("cmp.monopoly.role");
|
|
var TipsController = require("tips_controller");
|
|
var MainuiController = require("mainui_controller");
|
|
var ItemLayout = require("cmp.item.layout");
|
|
var BackPackController = require("backpack_controller");
|
|
var BridgeItemBinder = require("bridge.binder.item.icon.count");
|
|
var FxSpine = require("nx.fx.spine");
|
|
var MAX_DICE = 6; // 最大步长
|
|
var 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 build(_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 onEnable() {
|
|
this.doing = false;
|
|
this.tipCover.active = false;
|
|
nx.gui.setActive(this.spDice, "", false);
|
|
|
|
// 刷新
|
|
if (this.mod) {
|
|
this.mod.reqBaseData();
|
|
}
|
|
},
|
|
// 销毁
|
|
onDestroy: function onDestroy() {
|
|
// 活动监听解除
|
|
if (this.mod) {
|
|
this.mod.vunbind(this);
|
|
}
|
|
this._super();
|
|
},
|
|
// 置空
|
|
setEmpty: function setEmpty() {
|
|
nx.gui.setActive(this, "right", false);
|
|
},
|
|
// 基本信息
|
|
freshBasic: function freshBasic() {
|
|
var _this = this;
|
|
// 骰子货币
|
|
var data = this.mod.queryConfig();
|
|
this.coinId = data ? data.item : 0;
|
|
|
|
// 冒险角色
|
|
this.cmpRole.setModel(data.model, function (_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 onGroupChanged(_gindex) {
|
|
// 格子奖励
|
|
var items = [];
|
|
var DATA = this.mod.queryRoundRewards(_gindex);
|
|
for (var i in DATA) {
|
|
var ifo = DATA[i];
|
|
if (ifo && ifo.item_bid > 0 && ifo.num > 0) {
|
|
items.push(ifo);
|
|
}
|
|
}
|
|
if (items.length == 0) {
|
|
return;
|
|
}
|
|
var chds = this.mapRewards.children;
|
|
nx.gui.gocChildren(this.mapRewards, "", items.length, chds[0]);
|
|
for (var _i = 0; _i < chds.length; ++_i) {
|
|
var node = chds[_i];
|
|
var 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;
|
|
var cfg = gitemdata(info.item_bid);
|
|
nx.bridge.setIcon(node, "icon", cfg ? cfg.icon : "");
|
|
nx.gui.setString(node, "num", cfg ? info.num : "");
|
|
var cmp = nx.gui.getComponent(node, "icon", "nx.actor.suspending", true);
|
|
if (cmp) {
|
|
cmp.start(2, 10);
|
|
}
|
|
}
|
|
},
|
|
// 位置改变
|
|
onPosChanged: function onPosChanged(_pos) {
|
|
var pos = this.queryPosition(_pos);
|
|
this.cmpRole.node.position = pos;
|
|
},
|
|
// 筛子信息改变
|
|
onDiceChanged: function onDiceChanged(_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 onRewardChanged(_info) {
|
|
// 状态转动作
|
|
// status: 0-未完成,1-可领取,2-已领取
|
|
// action1 普通状态
|
|
// action2 可开启状态
|
|
// action3 开启过程,reword事件出获得道具
|
|
// action4 开完状态
|
|
var st2act = function st2act(_st) {
|
|
switch (_st) {
|
|
case 0:
|
|
return 'action1';
|
|
case 1:
|
|
return 'action2';
|
|
case 2:
|
|
return 'action4';
|
|
default:
|
|
return 'action1';
|
|
}
|
|
};
|
|
|
|
// 单设
|
|
var self = this;
|
|
var single = function single(_box, _time, _data) {
|
|
// 宝箱更新
|
|
var act = st2act(_data.status);
|
|
var res = PathTool.getSpinePath(_data.res_id, "action", false);
|
|
var 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-已领取
|
|
var count = 0;
|
|
var list = this.mod.queryBoxes();
|
|
for (var i = 0; i < list.length; ++i) {
|
|
var 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;
|
|
}
|
|
}
|
|
|
|
// 进度
|
|
var prog = nx.gui.getComponent(this.lstRewards, "progress", cc.ProgressBar);
|
|
if (prog) {
|
|
var cfgs = this.mod.queryConfig();
|
|
var times = this.mod.vget('cwSteps');
|
|
prog.progress = times / cfgs.max;
|
|
}
|
|
},
|
|
// 结束时间改变
|
|
onTimeChanged: function onTimeChanged(_time) {
|
|
|
|
// let txt = nx.bridge.time.toNeedTime( time );
|
|
// nx.gui.setString( this.nodDate, "txt", txt );
|
|
},
|
|
// 次數改变
|
|
onStepChanged: function onStepChanged(_times) {
|
|
// let cfgs = this.mod.queryConfig();
|
|
// nx.gui.setString( this.nodTimes, "txt", `${_times}/${cfgs.max}` )
|
|
nx.gui.setString(this.nodTimes, "txt", "" + _times);
|
|
},
|
|
// 获取指定格子坐标
|
|
queryPosition: function queryPosition(_gpos) {
|
|
var node = nx.gui.find(this.mapRefs, "p" + _gpos);
|
|
if (!node) {
|
|
nx.error("CircleWalk:无效位置 ", _gpos);
|
|
return null;
|
|
}
|
|
return node.position;
|
|
},
|
|
// 点击规则
|
|
onTouchRule: function onTouchRule() {
|
|
var rule = this.mod ? this.mod.queryRule() : "";
|
|
if (nx.dt.strNEmpty(rule)) {
|
|
var TC = TipsController.getInstance();
|
|
TC.showTextPanel("tip", rule);
|
|
}
|
|
},
|
|
// 点击商城
|
|
onTouchShop: function onTouchShop() {
|
|
var cfgs = this.mod.queryConfig();
|
|
if (cfgs && this.actRoot) {
|
|
this.actRoot.jumpToMenu(cfgs.shop);
|
|
}
|
|
},
|
|
// 点击商城
|
|
onTouchExchangeShop: function onTouchExchangeShop() {
|
|
nx.bridge.jumper.jump2Window(474);
|
|
},
|
|
// 角色事件
|
|
roleEvent: function roleEvent(_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;
|
|
}
|
|
|
|
// 结束
|
|
var self = this;
|
|
var success = function success(_rewards) {
|
|
if (_rewards === void 0) {
|
|
_rewards = [];
|
|
}
|
|
var lst = [];
|
|
for (var i = 0; i < _rewards.length; ++i) {
|
|
var rt = _rewards[i];
|
|
if (rt) {
|
|
lst.push({
|
|
bid: rt.item_bid,
|
|
num: rt.num
|
|
});
|
|
}
|
|
}
|
|
var auto = self.mod.vget("cwAutoDice");
|
|
var done = function done() {
|
|
if (auto && self.mod.itemHave() > 0) {
|
|
self.onTouchDice();
|
|
}
|
|
};
|
|
|
|
// 无奖励直接判断自动投掷
|
|
if (nx.dt.arrEmpty(lst)) {
|
|
done();
|
|
return;
|
|
}
|
|
var args = {};
|
|
if (auto) {
|
|
args.delay = {
|
|
secs: self.secAuto,
|
|
cb: function cb() {
|
|
done();
|
|
}
|
|
};
|
|
}
|
|
var MC = MainuiController.getInstance();
|
|
MC.openGetItemView(true, lst, args);
|
|
};
|
|
var failed = function failed() {
|
|
// 角色归位
|
|
var cur = self.mod.vget("cwPosition");
|
|
var pos = self.queryPosition(cur);
|
|
if (pos) {
|
|
self.cmpRole.node.position = pos;
|
|
}
|
|
|
|
// 道具数量归位
|
|
var model = BackPackController.getInstance().getModel();
|
|
var count = model.getBackPackItemNumByBid(self.coinId);
|
|
nx.gui.setString(self.nodStart, "need/num", count);
|
|
};
|
|
this.doing = false;
|
|
var rewards = this.mod.vget("cwRewardList");
|
|
success(rewards);
|
|
},
|
|
// 点击格子奖励
|
|
onTouchGridGift: function onTouchGridGift(_node) {
|
|
var info = _node.currentTarget.info;
|
|
if (info && info.item_bid > 0) {
|
|
var TC = TipsController.getInstance();
|
|
if (TC) {
|
|
TC.showItemTips(info.item_bid);
|
|
}
|
|
}
|
|
},
|
|
// 点击宝箱
|
|
onTouchBox: function onTouchBox(_box) {
|
|
var _this2 = this;
|
|
var 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);
|
|
var pos = _box.convertToWorldSpaceAR(cc.Vec2.ZERO);
|
|
pos = this.tipCover.convertToNodeSpaceAR(pos);
|
|
this.tipReward.node.y = pos.y;
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 拆盒
|
|
// action3 开启过程,reword事件出获得道具
|
|
var cmp = nx.gui.getComponent(_box, "", "nx.fx.spine");
|
|
if (cmp) {
|
|
cmp.action("action3", false, function (_event) {
|
|
// 音效
|
|
if (_event == 'reword') {
|
|
nx.audio.playSFX("audios/effects/del", false);
|
|
}
|
|
|
|
// 完成
|
|
if (_event == 'complete') {
|
|
_this2.mod.reqOpenBox();
|
|
}
|
|
});
|
|
}
|
|
},
|
|
// 点击提示覆盖层
|
|
onTouchTipCover: function onTouchTipCover() {
|
|
this.tipCover.active = false;
|
|
},
|
|
// 自动步数
|
|
onAutoDice: function onAutoDice(_ten) {
|
|
nx.gui.setActive(this.nodAuto, "ck/on", _ten);
|
|
},
|
|
// 十连切换
|
|
onTogAuto: function onTogAuto() {
|
|
var ten = this.mod.vget('cwAutoDice');
|
|
this.mod.vset('cwAutoDice', !ten);
|
|
},
|
|
// 扔色子
|
|
onTouchDice: function onTouchDice() {
|
|
this.onTouchOnce();
|
|
// let ten = this.mod.vget( 'cwAutoDice' );
|
|
// if( ten ) {
|
|
// this.onTouchTen();
|
|
// } else {
|
|
// this.onTouchOnce();
|
|
// }
|
|
},
|
|
|
|
// 单抽
|
|
onTouchOnce: function onTouchOnce() {
|
|
var _this3 = this;
|
|
// 进行中
|
|
if (this.doing) {
|
|
nx.tbox("MonoDoing");
|
|
return;
|
|
}
|
|
if (!this.mod.itemHave()) {
|
|
nx.tbox("SummonItemNotEnough");
|
|
this.onTouchShop();
|
|
return;
|
|
}
|
|
this.doing = true;
|
|
this.mod.reqStartRoll(function (_ret, _data) {
|
|
if (!_ret) {
|
|
_this3.doing = false;
|
|
// nx.tbox( _data );
|
|
return;
|
|
}
|
|
|
|
// 过程模拟
|
|
_this3.simProgress(_data.num, _data.next_pos);
|
|
});
|
|
},
|
|
// 十连抽
|
|
onTouchTen: function onTouchTen() {
|
|
this.mod.reqRewardTen();
|
|
},
|
|
// 投掷过程模拟
|
|
simProgress: function simProgress(_dice, _pos) {
|
|
var _this4 = this;
|
|
var self = this;
|
|
|
|
// 移动
|
|
var move = function move() {
|
|
var pts = [];
|
|
var well = false;
|
|
var cur = self.mod.vget("cwPosition");
|
|
for (var i = 0; i < MAX_DICE; ++i) {
|
|
var 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, function (_event) {
|
|
if (_event == "complete") {
|
|
move();
|
|
nx.gui.setActive(_this4.spDice, "", false);
|
|
}
|
|
});
|
|
|
|
// 投掷音效
|
|
if (this.auDice) {
|
|
cc.audioEngine.playEffect(this.auDice, false);
|
|
}
|
|
this.curDice = _dice;
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |