396 lines
11 KiB
JavaScript
396 lines
11 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, '9b7c9dz6YRBqKRdbezWiyyI', 'cmp.summon.standard');
|
||
|
|
// Scripts/mod/summon/standard/cmp.summon.standard.js
|
||
|
|
|
||
|
|
"use strict";
|
||
|
|
|
||
|
|
/******************************************************************
|
||
|
|
* Copyright(C) 2019 - 2020 Nx Studio
|
||
|
|
*
|
||
|
|
* 常规召唤页
|
||
|
|
*
|
||
|
|
* 2018.05.18
|
||
|
|
******************************************************************/
|
||
|
|
|
||
|
|
var MenuPage = require("cmp.com.menu.page");
|
||
|
|
var SummonDefine = require("summon.define");
|
||
|
|
var SummonMod = require("summon.mod");
|
||
|
|
var HeroController = require("hero_controller");
|
||
|
|
var RoleController = require("role_controller");
|
||
|
|
var BackPackController = require("backpack_controller");
|
||
|
|
var BridgeItemBinder = require("bridge.binder.item.icon.count");
|
||
|
|
var FID = require("bridge.function.ids");
|
||
|
|
var SCRK = SummonDefine.Recruit_Key;
|
||
|
|
var SCST = SummonDefine.Summon_Type;
|
||
|
|
var SCRT = SummonDefine.Status;
|
||
|
|
var EmptyBG = "";
|
||
|
|
cc.Class({
|
||
|
|
"extends": MenuPage,
|
||
|
|
properties: {
|
||
|
|
sumId: {
|
||
|
|
"default": 0
|
||
|
|
},
|
||
|
|
nodOps: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node
|
||
|
|
},
|
||
|
|
nodCoin: {
|
||
|
|
"default": null,
|
||
|
|
type: BridgeItemBinder
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 载入
|
||
|
|
onLoad: function onLoad() {
|
||
|
|
this._super();
|
||
|
|
this.bindId(this.sumId);
|
||
|
|
},
|
||
|
|
// 显示
|
||
|
|
onEnable: function onEnable() {
|
||
|
|
// 事件监听
|
||
|
|
this.bindGEvent(SummonDefine.UpdateSummonDataEvent, this.updateSummonData.bind(this));
|
||
|
|
|
||
|
|
// 主动更新
|
||
|
|
this.updateSummonData();
|
||
|
|
},
|
||
|
|
// 关闭
|
||
|
|
onDisable: function onDisable() {
|
||
|
|
this.setFreeCD();
|
||
|
|
this.unbindGEvents();
|
||
|
|
},
|
||
|
|
// 置空
|
||
|
|
setEmpty: function setEmpty() {
|
||
|
|
// nx.gui.setSpriteFrame( this, "bg", EmptyBG );
|
||
|
|
|
||
|
|
this.costId = 0;
|
||
|
|
this.setFreeCD();
|
||
|
|
this.nodCoin.active = false;
|
||
|
|
this.nodOps.active = false;
|
||
|
|
},
|
||
|
|
// 设置召唤库编号
|
||
|
|
bindId: function bindId(_id) {
|
||
|
|
this.sumId = _id;
|
||
|
|
|
||
|
|
// 召唤配置
|
||
|
|
var DATA = game.configs.recruit_data.data_partnersummon_data;
|
||
|
|
var info = DATA ? DATA[_id] : null;
|
||
|
|
if (nx.dt.objEmpty(info)) {
|
||
|
|
nx.error("无效召唤配置:", _id);
|
||
|
|
this.setEmpty();
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 背景图
|
||
|
|
// let path = cc.path.join( "resDB/bigs", info.call_bg );
|
||
|
|
// nx.gui.setSpriteFrame( this, "bg", path );
|
||
|
|
|
||
|
|
// // 看板娘
|
||
|
|
// path = cc.path.join( "resDB/bigs", info.card_bg_res );
|
||
|
|
// nx.gui.setSpriteFrame( this, "panel/role", path );
|
||
|
|
|
||
|
|
// 广告语
|
||
|
|
var path = cc.path.join("locals", nx.getLocLanguage(), "images/summon", info.word_art);
|
||
|
|
nx.gui.setSpriteFrame(this, "panel/word", path);
|
||
|
|
|
||
|
|
// 货币更新
|
||
|
|
var tid = 0;
|
||
|
|
if (nx.dt.arrNEmpty(info.item_once) && nx.dt.arrNEmpty(info.item_once[0])) {
|
||
|
|
tid = info.item_once[0][0];
|
||
|
|
}
|
||
|
|
|
||
|
|
// 货币图标设置
|
||
|
|
var tinfo = gitemdata(tid);
|
||
|
|
if (nx.dt.objEmpty(tinfo)) {
|
||
|
|
nx.error("无效召唤货币:", tid);
|
||
|
|
} else {
|
||
|
|
this.costId = tid;
|
||
|
|
this.nodCoin.active = true;
|
||
|
|
this.nodCoin.setID(tid);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
},
|
||
|
|
// 召唤数据刷新
|
||
|
|
updateSummonData: function updateSummonData() {
|
||
|
|
var _this = this;
|
||
|
|
var SC = SummonMod.getInstance();
|
||
|
|
var SM = SC.getModel();
|
||
|
|
var data = SM.getSummonGroupData();
|
||
|
|
|
||
|
|
// 数据无效,重新请求
|
||
|
|
if (nx.dt.arrEmpty(data)) {
|
||
|
|
SC.send23200(function (_data) {
|
||
|
|
_this.updateSummonData();
|
||
|
|
});
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 获取当前页数据
|
||
|
|
var info = null;
|
||
|
|
for (var i in data) {
|
||
|
|
var t = data[i];
|
||
|
|
if (t && t.group_id == this.sumId) {
|
||
|
|
info = t;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// 更新
|
||
|
|
this.updateData(info);
|
||
|
|
},
|
||
|
|
// 更新数据
|
||
|
|
updateData: function updateData(_data) {
|
||
|
|
// 置空
|
||
|
|
if (nx.dt.objEmpty(_data)) {
|
||
|
|
this.setEmpty();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 参数配置缺失
|
||
|
|
var rdata = _data.recruit_data;
|
||
|
|
var cfgs = _data.config_data;
|
||
|
|
if (nx.dt.objEmpty(rdata) || nx.dt.objEmpty(cfgs)) {
|
||
|
|
nx.error("召唤更新失败,配置缺失!");
|
||
|
|
this.setEmpty();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var BC = BackPackController.getInstance();
|
||
|
|
var BM = BC.getModel();
|
||
|
|
|
||
|
|
// 更新当前货币
|
||
|
|
// 消耗修正
|
||
|
|
var count = this.updateCoin();
|
||
|
|
var autoOp = function autoOp(_node, _freeDt, _item, _exchange, _exchangeInfo) {
|
||
|
|
var ret = {
|
||
|
|
enough: false,
|
||
|
|
type: SCRT.Item,
|
||
|
|
time: _freeDt,
|
||
|
|
item: _item[0] || [],
|
||
|
|
exc: _exchange[0] || [],
|
||
|
|
excInfo: _exchangeInfo[0] || []
|
||
|
|
};
|
||
|
|
|
||
|
|
// 所需道具不足 && 但是有替代品
|
||
|
|
var bid = ret.item[0];
|
||
|
|
var need = ret.item[1];
|
||
|
|
if (count < need && nx.dt.arrNEmpty(ret.exc)) {
|
||
|
|
bid = ret.exc[0];
|
||
|
|
need = ret.exc[1];
|
||
|
|
var cnt = BM.getBackPackItemNumByBid(bid);
|
||
|
|
ret.enough = cnt >= need;
|
||
|
|
ret.type = SCRT.Diamond;
|
||
|
|
} else {
|
||
|
|
ret.enough = count >= need;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 参数补充
|
||
|
|
ret.bid = bid;
|
||
|
|
ret.need = need;
|
||
|
|
|
||
|
|
// 免费
|
||
|
|
if (_freeDt == 0) {
|
||
|
|
ret.enough = true;
|
||
|
|
ret.type = SCRT.Free;
|
||
|
|
nx.gui.setActive(_node, "need/list", false);
|
||
|
|
nx.gui.setActive(_node, "need/free", true);
|
||
|
|
nx.gui.setActive(_node, "freeCD", false);
|
||
|
|
return ret;
|
||
|
|
}
|
||
|
|
nx.gui.setActive(_node, "need/list", true);
|
||
|
|
nx.gui.setActive(_node, "need/free", false);
|
||
|
|
|
||
|
|
// 货币刷新
|
||
|
|
var tinfo = gitemdata(bid);
|
||
|
|
nx.bridge.setIcon(_node, "need/list/icon", tinfo.icon);
|
||
|
|
nx.gui.setString(_node, "need/list/num", need);
|
||
|
|
|
||
|
|
// 免费倒计时
|
||
|
|
nx.gui.setActive(_node, "freeCD", _freeDt > 0);
|
||
|
|
return ret;
|
||
|
|
};
|
||
|
|
this.nodOps.active = true;
|
||
|
|
var once = nx.gui.find(this.nodOps, "once");
|
||
|
|
var ten = nx.gui.find(this.nodOps, "ten");
|
||
|
|
var dtFree = this.evalFreeOnce(rdata.draw_list);
|
||
|
|
this.onceArgs = autoOp(once, dtFree, cfgs.item_once, cfgs.exchange_once, cfgs.exchange_once_gain);
|
||
|
|
this.tenArgs = autoOp(ten, -1, cfgs.item_five, cfgs.exchange_five, cfgs.exchange_five_gain);
|
||
|
|
|
||
|
|
// 免费倒计时
|
||
|
|
this.setFreeCD(dtFree);
|
||
|
|
},
|
||
|
|
// 更新当前货币
|
||
|
|
updateCoin: function updateCoin() {
|
||
|
|
// 友情点
|
||
|
|
var count = 0;
|
||
|
|
if (this.sumId == SCST.Friend) {
|
||
|
|
var RC = RoleController.getInstance();
|
||
|
|
var role = RC.getRoleVo();
|
||
|
|
if (role) {
|
||
|
|
count = role.friend_point;
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
var BC = BackPackController.getInstance();
|
||
|
|
count = BC.getModel().getBackPackItemNumByBid(this.costId);
|
||
|
|
}
|
||
|
|
|
||
|
|
// nx.gui.setString( this.nodCoin, "txt", nx.dt.shortCount( count ) );
|
||
|
|
|
||
|
|
return count;
|
||
|
|
},
|
||
|
|
// 免费倒计时
|
||
|
|
setFreeCD: function setFreeCD(_dtFree) {
|
||
|
|
this.unscheduleAllCallbacks();
|
||
|
|
if (!nx.dt.numPositive(_dtFree, false)) {
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var self = this;
|
||
|
|
var node = nx.gui.find(this.nodOps, "once/freeCD");
|
||
|
|
var tick = function tick() {
|
||
|
|
var interval = Utils.getTimeInterval(_dtFree);
|
||
|
|
if (interval <= 0) {
|
||
|
|
self.unscheduleAllCallbacks();
|
||
|
|
nx.gui.setString(node, "", "");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
var time = Utils.changeIntevalToDate(interval);
|
||
|
|
var txt = time.H + ":" + time.M + ":" + time.S;
|
||
|
|
nx.gui.setString(node, "", nx.text.format("FreeCD", txt));
|
||
|
|
};
|
||
|
|
this.schedule(tick, 1, cc.macro.REPEAT_FOREVER);
|
||
|
|
tick();
|
||
|
|
},
|
||
|
|
// 单次免费评估
|
||
|
|
evalFreeOnce: function evalFreeOnce(_draws) {
|
||
|
|
var dtFree = -1; // -1不免费 0免费 >0下次时间
|
||
|
|
if (nx.dt.arrEmpty(_draws)) {
|
||
|
|
return dtFree;
|
||
|
|
}
|
||
|
|
var ifo = null;
|
||
|
|
for (var i in _draws) {
|
||
|
|
if (_draws[i] && _draws[i].times == 1) {
|
||
|
|
ifo = _draws[i];
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if (ifo && nx.dt.arrNEmpty(ifo.kv_list)) {
|
||
|
|
for (var k in ifo.kv_list) {
|
||
|
|
var kt = ifo.kv_list[k];
|
||
|
|
if (!kt || !nx.dt.numPositive(kt.val, false)) {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 有免费次数
|
||
|
|
if (kt.key == SCRK.Free_Count) {
|
||
|
|
dtFree = 0;
|
||
|
|
break;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 下次免费时间
|
||
|
|
if (kt.key == SCRK.Free_Time) {
|
||
|
|
dtFree = kt.val;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return dtFree;
|
||
|
|
},
|
||
|
|
// 点击货币
|
||
|
|
onTouchCoin: function onTouchCoin() {},
|
||
|
|
// 点击单次召唤
|
||
|
|
onTouchOnce: function onTouchOnce(_ret) {
|
||
|
|
// 关闭召唤动画界面
|
||
|
|
if (_ret == false) {
|
||
|
|
nx.bridge.summonAnimation.doStop();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.onceArgs.txt = "SummonOnce";
|
||
|
|
this.onceArgs.cb = this.onTouchOnce.bind(this);
|
||
|
|
this.doSummon(1, this.onceArgs);
|
||
|
|
},
|
||
|
|
// 点击十次召唤
|
||
|
|
onTouchTen: function onTouchTen(_ret) {
|
||
|
|
// 关闭召唤动画界面
|
||
|
|
if (_ret == false) {
|
||
|
|
nx.bridge.summonAnimation.doStop();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
this.tenArgs.txt = "SummonTen";
|
||
|
|
this.tenArgs.cb = this.onTouchTen.bind(this);
|
||
|
|
this.doSummon(10, this.tenArgs);
|
||
|
|
},
|
||
|
|
// 召唤请求
|
||
|
|
doSummon: function doSummon(_times, _args) {
|
||
|
|
var _this2 = this;
|
||
|
|
// 容量检查
|
||
|
|
if (!this.checkVolume(_times)) {
|
||
|
|
nx.tbox("PartnerBagFull");
|
||
|
|
nx.bridge.jumper.jump2Window(FID.Recycle);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 不够召唤处理
|
||
|
|
if (!_args.enough) {
|
||
|
|
// 道具不足
|
||
|
|
if (_args.type == SCRT.Item) {
|
||
|
|
nx.tbox("SummonItemNotEnough");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 替代不足
|
||
|
|
if (_args.type == SCRT.Diamond) {
|
||
|
|
var good_res_path = "3";
|
||
|
|
var need_num = _args.exc[1];
|
||
|
|
var hvae_num = RoleController.getInstance().getRoleVo().gold;
|
||
|
|
var val_str = Utils.getItemConfig(_args.excInfo[0]).name;
|
||
|
|
var val_num = _args.excInfo[1];
|
||
|
|
var call_num = _times;
|
||
|
|
var buy_ori = nx.text.format("tip_diamondConsume", good_res_path, need_num, hvae_num);
|
||
|
|
var get_ori = nx.text.format("tip_buyDesc", val_num, val_str, call_num);
|
||
|
|
var des_str = buy_ori + get_ori;
|
||
|
|
nx.mbox(des_str, ['cancel', 'confirm'], function (_key, _box) {
|
||
|
|
_box.close();
|
||
|
|
if (_key == "confirm") {
|
||
|
|
_this2.reqSummon(_args.type, _times, _args);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 召唤
|
||
|
|
this.reqSummon(_args.type, _times, _args);
|
||
|
|
},
|
||
|
|
// 召唤
|
||
|
|
reqSummon: function reqSummon(_type, _times, _args) {
|
||
|
|
var self = this;
|
||
|
|
var SC = SummonMod.getInstance();
|
||
|
|
SC.send23201(this.sumId, _times, _type, function (_ok, _data) {
|
||
|
|
// 失败
|
||
|
|
if (!_ok) {
|
||
|
|
nx.tbox(_data);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 判空
|
||
|
|
if (nx.dt.arrEmpty(_data.partner_bids)) {
|
||
|
|
nx.warn("$Summon:空召唤跳过!");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
// 动画
|
||
|
|
nx.bridge.summonAnimation.doStart();
|
||
|
|
nx.bridge.summonAnimation.setResult(_data, _args, function () {
|
||
|
|
self.updateSummonData();
|
||
|
|
});
|
||
|
|
});
|
||
|
|
},
|
||
|
|
// 背包容量检查
|
||
|
|
checkVolume: function checkVolume(_count) {
|
||
|
|
var HC = HeroController.getInstance();
|
||
|
|
var HM = HC.getModel();
|
||
|
|
|
||
|
|
// 背包容量判断
|
||
|
|
var bagInfo = HM.getHeroMaxCount();
|
||
|
|
var remains = bagInfo.max_count - bagInfo.have_coutn;
|
||
|
|
return _count <= remains;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
cc._RF.pop();
|