Files
fc/dev/project/library/imports/66/664e8ae4-6d8e-4071-b383-85adda2f4e65.js
T
2026-05-24 10:21:26 +08:00

473 lines
12 KiB
JavaScript

"use strict";
cc._RF.push(module, '664e8rkbY5AcbODha3aL05l', 'cmp.monopoly.wnd');
// Scripts/mod/sgames/monopoly/cmp.monopoly.wnd.js
"use strict";
/******************************************************************
*
* 大富翁场景
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var Mono = require("monopoly.mod");
var MonoRole = require("cmp.monopoly.role");
var TipsController = require("tips_controller");
var RoleController = require("role_controller");
var BackPackController = require("backpack_controller");
var FxSpine = require("nx.fx.spine");
var MainuiController = require("mainui_controller");
var MAX_DICE = 6; // 最大步长
var LEN_PATH = 30; // 路径长度
cc.Class({
"extends": BridgeWindow,
properties: {
mapRefs: {
"default": null,
type: cc.Node
},
mapRewards: {
"default": null,
type: cc.Node
},
mapWalkable: {
"default": null,
type: cc.Node
},
nodAuto: {
"default": null,
type: cc.Node
},
nodDate: {
"default": null,
type: cc.Node
},
nodStart: {
"default": null,
type: cc.Node
},
nodRound: {
"default": null,
type: cc.Node
},
lstRewards: {
"default": null,
type: cc.Node
},
spDice: {
"default": null,
type: FxSpine
},
cmpRole: {
"default": null,
type: MonoRole
},
auDice: {
"default": null,
type: cc.AudioClip
},
auFoot: {
"default": null,
type: cc.AudioClip
},
secAuto: {
"default": 3
}
},
// 显示
onEnable: function onEnable() {
var _this = this;
// 过程归零
this.doing = false;
this.footHandle = 0;
nx.gui.setActive(this.spDice, "", false);
// 骰子货币
var DATA = game.configs.monopoly_data.data_const.item_bid;
this.coinId = DATA.val;
// 地图重建
this.rebuildMap();
// 冒险角色
var role = RoleController.getInstance().getRoleVo();
var cfgs = game.configs.looks_data.data_data[role.look_id];
this.cmpRole.setModel(cfgs ? cfgs.model : "", function (_key) {
_this.roleEvent(_key);
});
// 奖励格子
this.buildRewardGrids();
// 初始化列表
this.initRoundRewards();
// 视图绑定
nx.bridge.vbind(this, [["MonoRewards", this.onFreshRoundRewards.bind(this)]]);
},
// 关闭
onDisable: function onDisable() {
this.unscheduleAllCallbacks();
// 视图监听解除
nx.bridge.vunbind(this);
},
// 数据重置
rebuildMap: function rebuildMap() {
var _this2 = this;
// 初始位置
var cur = nx.bridge.vget("MonoPos");
var pos = this.queryPosition(cur);
if (pos) {
this.cmpRole.node.position = pos;
}
nx.gui.setActive(this.nodDate, "", false);
// 结束时间
this.unscheduleAllCallbacks();
this.schedule(function () {
var time = nx.bridge.vget("MonoEndTime");
var txt = nx.bridge.time.toNeedTime(time);
nx.gui.setString(_this2.nodDate, "txt", txt);
});
},
// 奖励格子
buildRewardGrids: function buildRewardGrids() {
// 格子奖励
var items = [];
var DATA = game.configs.monopoly_data.data_get_reward;
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) {
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];
node.position = this.queryPosition(info.pos);
node.info = info;
var cfg = gitemdata(info.item_bid);
nx.bridge.setIcon(node, "icon", cfg ? cfg.icon : "");
var cmp = nx.gui.getComponent(node, "icon", "nx.actor.suspending", true);
if (cmp) {
cmp.start(2, 10);
}
}
}
},
// ============================================================
// 扔骰子相关
// ============================================================
// 点击投掷
onTouchStart: function onTouchStart() {
var _this3 = this;
// 进行中
if (this.doing) {
nx.tbox("MonoDoing");
return;
}
var model = BackPackController.getInstance().getModel();
var count = model.getBackPackItemNumByBid(this.coinId);
if (count < 1) {
nx.tbox("SummonItemNotEnough");
return;
}
this.doing = true;
Mono.getInstance().reqRoll(function (_ret, _data) {
if (!_ret) {
_this3.doing = false;
nx.tbox(_data);
return;
}
// 本地道具-1
nx.gui.setString(_this3.nodStart, "need/num", count - 1);
// 过程模拟
_this3.simProgress(_data.num, _data.next_pos);
});
},
// 投掷过程模拟
simProgress: function simProgress(_dice, _pos) {
var _this4 = this;
var self = this;
// 移动
var move = function move() {
var pts = [];
var well = false;
var cur = nx.bridge.vget("MonoPos");
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;
},
// 角色事件
roleEvent: function roleEvent(_key) {
var _this5 = this;
// 音效关闭
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 open = nx.bridge.vget("MonoAutoDice");
var done = function done() {
if (open) {
self.onTouchStart();
}
};
// 无奖励直接判断自动投掷
if (nx.dt.arrEmpty(lst)) {
done();
return;
}
var args = {};
if (open) {
args.delay = {
secs: self.secAuto,
cb: function cb() {
done();
}
};
}
var MC = MainuiController.getInstance();
MC.openGetItemView(true, lst, args);
};
var failed = function failed() {
// 角色归位
var cur = nx.bridge.vget("MonoPos");
var pos = self.queryPosition(cur);
if (pos) {
self.cmpRole.node.position = pos;
}
// 道具数量归位
var count = model.getBackPackItemNumByBid(self.coinId);
nx.gui.setString(self.nodStart, "need/num", count);
};
Mono.getInstance().reqRollMoveEnd(this.curDice, function (_ret, _data) {
_this5.doing = false;
if (_ret) {
success(_data.reward_list);
return;
}
// 移动失败
nx.tbox(_data);
failed();
});
},
// 点击格子奖励
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);
}
}
},
// ============================================================
// 轮次礼物相关
// ============================================================
// 初始化列表
initRoundRewards: function initRoundRewards() {
var chds = this.lstRewards.children;
var cfg = game.configs.monopoly_data.data_get_schedule_reward;
for (var i = 0; i < chds.length; ++i) {
var node = chds[i];
node.index = i + 1;
var info = cfg[i + 1];
var cmp = nx.gui.getComponent(node, "rewards/nod", "cmp.item.layout");
if (cmp) {
cmp.rebuild(info.rewards);
}
nx.gui.setString(node, "txt", nx.text.format("MonoRoundF", i + 1));
nx.gui.setActive(node, "on", false);
nx.gui.setActive(node, "got", false);
nx.gui.setActive(node, "rewards", false);
nx.gui.setActive(node, "off", true);
}
},
// 刷新列表
onFreshRoundRewards: function onFreshRoundRewards() {
var rewards = nx.bridge.vget("MonoRewards");
if (nx.dt.arrEmpty(rewards)) {
return;
}
for (var i in rewards) {
var info = rewards[i];
var node = nx.gui.find(this.lstRewards, "item" + info.turn);
if (node) {
nx.gui.setActive(node, "on", info.is_get_reward == 0);
nx.gui.setActive(node, "touch", info.is_get_reward != 0);
nx.gui.setActive(node, "got", info.is_get_reward == 1);
}
}
},
// 查看圈数 奖励
onLookRoundRewards: function onLookRoundRewards(_idx) {
var nodhide = nx.gui.find(this, "ui/hideitems");
for (var i = 0; i < this.lstRewards.children.length; i++) {
var _nod = this.lstRewards.children[i];
var nodReward = nx.gui.find(_nod, "rewards");
if (i != _idx) {
nx.gui.setActive(nodReward, "", false);
}
}
var nod = nx.gui.find(this.lstRewards.children[_idx], "rewards");
// let cfg = game.configs.monopoly_data.data_get_schedule_reward;
nx.gui.setActive(this.lstRewards.children[_idx], "rewards", !nod.active);
nx.gui.setActive(nodhide, "", nod.active == true);
},
onTouchHideAllDesc: function onTouchHideAllDesc() {
var nodhide = nx.gui.find(this, "ui/hideitems");
for (var i = 0; i < this.lstRewards.children.length; i++) {
var nod = this.lstRewards.children[i];
var nodReward = nx.gui.find(nod, "rewards");
nx.gui.setActive(nodReward, "", false);
}
nx.gui.setActive(nodhide, "", false);
},
// 点击礼物
onTouchReward: function onTouchReward(_item) {
var idx = _item ? _item.parent.index : 0;
if (idx < 1) {
return;
}
Mono.getInstance().reqReward(idx, function (_ret, _data) {
if (!_ret) {
nx.tbox(_data);
return;
}
});
},
// 点击购买骰子
onTouchBuyDice: function onTouchBuyDice() {
var num = nx.bridge.vget("MonoBuyNum");
if (num <= 0) {
nx.tbox("MonoBuyNoTime");
return;
}
var total = game.configs.monopoly_data.data_const.buy_time.val;
var prices = game.configs.monopoly_data.data_const.item_price.val;
var times = total - num;
if (times < 0 || times >= prices.length) {
nx.tbox("MonoBuyNoTime");
return;
}
// 购买
var buy = function buy() {
Mono.getInstance().reqBuyDice(1, function (_ret, _data) {
if (!_ret) {
nx.tbox(_data);
return;
}
});
};
var price = prices[times];
nx.bridge.createPanel("WndItemBuy", {
item: {
bid: this.coinId,
num: 1
},
price: {
bid: price[0],
num: price[1]
},
cb: function cb(_ret) {
if (_ret) {
buy();
}
}
});
},
// 自动投掷切换
onTouchAutoTog: function onTouchAutoTog() {
Mono.getInstance().togAutoRoll();
},
// 帮助
onTouchHelp: function onTouchHelp() {
var DATA = game.configs.monopoly_data.data_const.monopoly_rule;
if (DATA) {
var TC = TipsController.getInstance();
TC.showTextPanel("tip", nx.text.getKey(DATA.desc));
}
},
// 获取指定格子坐标
queryPosition: function queryPosition(_gpos) {
var node = nx.gui.find(this.mapRefs, "p" + _gpos);
if (!node) {
nx.error("Mono:无效位置 ", _gpos);
return null;
}
return node.position;
}
});
cc._RF.pop();