459 lines
16 KiB
JavaScript
459 lines
16 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, '45db275SQVGLYz1VNs3b22D', 'mall_model');
|
|
// Scripts/mod/shop/mall/mall_model.js
|
|
|
|
"use strict";
|
|
|
|
// --------------------------------------------------------------------
|
|
// @author: xxx@syg.com(必填, 创建模块的人员)
|
|
// @description:
|
|
// 商城的model
|
|
// <br/>Create: 2018-12-18 17:12:27
|
|
// --------------------------------------------------------------------
|
|
// var HeroController = require("hero_controller");
|
|
var BridgeClass = require("bridge.class");
|
|
var RoleController = require("role_controller");
|
|
var BackpackController = require("backpack_controller");
|
|
var MallModel = cc.Class({
|
|
"extends": BridgeClass,
|
|
ctor: function ctor() {
|
|
var MailController = require("mall_controller");
|
|
this.ctrl = MailController.getInstance();
|
|
},
|
|
properties: {},
|
|
initConfig: function initConfig() {
|
|
this.buy_list = {};
|
|
this.shop_list = {};
|
|
},
|
|
setBuyList: function setBuyList(data) {
|
|
this.buy_list = data;
|
|
},
|
|
getBuyList: function getBuyList() {
|
|
return this.buy_list;
|
|
},
|
|
getScoreBuyList: function getScoreBuyList(shop_type) {
|
|
if (this.shop_list[shop_type] && Utils.next(this.shop_list[shop_type]) != null) {
|
|
return this.shop_list[shop_type];
|
|
}
|
|
return null;
|
|
},
|
|
//检查当前神格商店中是否存在上阵的的伙伴碎片
|
|
checkHeroChips: function checkHeroChips(item_id) {
|
|
var is_has = false;
|
|
var pos_list = [];
|
|
// var pos_list = HeroController.getInstance().getModel().getMyPosList();
|
|
if (pos_list != null && Utils.next(pos_list || {}) != null) {
|
|
for (var k in pos_list) {
|
|
var v = pos_list[k];
|
|
var partner_data = PartnerController.getInstance().getModel().getPartnerById(v.id);
|
|
if (partner_data && partner_data.chips_id == item_id) {
|
|
is_has = true;
|
|
}
|
|
}
|
|
return is_has;
|
|
}
|
|
return false;
|
|
},
|
|
//根据商店类型以及支付类型和单价来判断能够买多少个
|
|
checkMoenyByType: function checkMoenyByType(pay_type, price) {
|
|
var role_vo = RoleController.getInstance().getRoleVo();
|
|
var is_can_buy_num = 0;
|
|
if (role_vo != null) {
|
|
var config = nx.dt.objClone(game.configs.item_data.data_assets_label2id);
|
|
if (typeof pay_type == "number") {
|
|
if (pay_type == config.hero_soul) {
|
|
//神格
|
|
var hero_soul = role_vo.hero_soul;
|
|
is_can_buy_num = Math.floor(hero_soul / price);
|
|
} else if (pay_type == config.silver_coin) {
|
|
var silver_coin = role_vo.silver_coin;
|
|
is_can_buy_num = Math.floor(silver_coin / price);
|
|
} else if (pay_type == config.red_gold_or_gold) {
|
|
var sum_gold = role_vo.red_gold + role_vo.gold;
|
|
is_can_buy_num = Math.floor(sum_gold / price);
|
|
} else if (pay_type == config.arena_guesscent) {
|
|
var arena_guesscent = role_vo.arena_guesscent;
|
|
is_can_buy_num = Math.floor(arena_guesscent / price);
|
|
} else if (pay_type == config.star_point) {
|
|
var star_point = role_vo.star_point;
|
|
is_can_buy_num = Math.floor(star_point / price);
|
|
} else if (pay_type == config.gold) {
|
|
var sum_gold = role_vo.gold;
|
|
is_can_buy_num = Math.floor(sum_gold / price);
|
|
} else if (pay_type == config.coin) {
|
|
var coin = role_vo.coin;
|
|
is_can_buy_num = Math.floor(coin / price);
|
|
} else {
|
|
var count = BackpackController.getInstance().getModel().getItemNumByBid(pay_type);
|
|
is_can_buy_num = Math.floor(count / price);
|
|
}
|
|
} else {
|
|
if (pay_type == "gold") {
|
|
var gold = role_vo.gold;
|
|
is_can_buy_num = Math.floor(gold / price);
|
|
} else if (pay_type == "red_gold_or_gold") {
|
|
var sum_gold = role_vo.red_gold + role_vo.gold;
|
|
is_can_buy_num = Math.floor(sum_gold / price);
|
|
} else if (pay_type == "arena_cent") {
|
|
var arena_cent = role_vo.arena_cent;
|
|
is_can_buy_num = Math.floor(arena_cent / price);
|
|
} else if (pay_type == "friend_point") {
|
|
var friend_point = role_vo.friend_point;
|
|
is_can_buy_num = Math.floor(friend_point / price);
|
|
} else if (pay_type == "guild") {
|
|
var guild = role_vo.guild;
|
|
is_can_buy_num = Math.floor(guild / price);
|
|
} else if (pay_type == "boss_point") {
|
|
var boss_point = role_vo.boss_point;
|
|
is_can_buy_num = Math.floor(boss_point / price);
|
|
} else if (pay_type == "arena_guesscent") {
|
|
var arena_guesscent = role_vo.arena_guesscent;
|
|
is_can_buy_num = Math.floor(arena_guesscent / price);
|
|
} else if (pay_type == "star_point") {
|
|
var star_point = role_vo.star_point;
|
|
is_can_buy_num = Math.floor(star_point / price);
|
|
} else if (pay_type == "sky_coin") {
|
|
var sky_coin = role_vo.sky_coin;
|
|
is_can_buy_num = Math.floor(sky_coin / price);
|
|
} else if (pay_type == "recruithigh_hero") {
|
|
var recruithigh_hero = role_vo.recruithigh_hero;
|
|
is_can_buy_num = Math.floor(recruithigh_hero / price);
|
|
} else if (pay_type == "expedition_medal") {
|
|
var expedition_medal = role_vo.expedition_medal;
|
|
is_can_buy_num = Math.floor(expedition_medal / price);
|
|
} else if (pay_type == "coin") {
|
|
var coin = role_vo.coin;
|
|
is_can_buy_num = Math.floor(coin / price);
|
|
} else if (pay_type == "silver_coin") {
|
|
var silver_coin = role_vo.silver_coin;
|
|
is_can_buy_num = Math.floor(silver_coin / price);
|
|
} else if (pay_type == "cluster_guess_cent") {
|
|
var cluster_guess_cent = role_vo.cluster_guess_cent;
|
|
is_can_buy_num = Math.floor(cluster_guess_cent / price);
|
|
} else if (pay_type == "elite_coin") {
|
|
var elite_coin = role_vo.elite_coin;
|
|
is_can_buy_num = Math.floor(elite_coin / price);
|
|
}
|
|
}
|
|
}
|
|
return is_can_buy_num;
|
|
},
|
|
checkActionMoenyByType: function checkActionMoenyByType(pay_type, price) {
|
|
var role_vo = RoleController.getInstance().getRoleVo();
|
|
var is_can_buy_num = 0;
|
|
if (role_vo) {
|
|
var count = role_vo.getActionAssetsNumByBid(pay_type);
|
|
is_can_buy_num = Math.floor(count / price);
|
|
}
|
|
return is_can_buy_num;
|
|
},
|
|
getItemShopData: function getItemShopData() {
|
|
return this.shopLst;
|
|
},
|
|
getItemShopDataLst: function getItemShopDataLst() {
|
|
var lst = [];
|
|
var data = game.configs.exchange_data.data_shop_exchage_gold;
|
|
var limit = this.getLimitInfo();
|
|
for (var i in data) {
|
|
var item = data[i];
|
|
var dataItem = {};
|
|
dataItem.id = item.item_bid;
|
|
lst.push(dataItem);
|
|
}
|
|
return lst;
|
|
},
|
|
setHolyType: function setHolyType(_type) {
|
|
this.HolyType = _type;
|
|
},
|
|
setLimitInfoD: function setLimitInfoD(_data) {
|
|
/**********
|
|
* {"code":1,"msg":"","type":1,"is_half":0,
|
|
* "item_list":[{"item_id":1013,"ext":[{"key":1,"val":1}]}]}
|
|
*/
|
|
// 注意 存储的数据若要改变 需要存储的是克隆的配置数据
|
|
this.limitInfoPoint = _data.item_list;
|
|
this.shopLstPoint = [];
|
|
this.ArenaShoplst = [];
|
|
this.RankShoplst = [];
|
|
this.ThemeShoplst = [];
|
|
this.SsetShoplst = [];
|
|
this.SetShoplst = [];
|
|
this.GuildShoplst = [];
|
|
this.LadderShoplst = [];
|
|
this.CrossChampionlst = [];
|
|
this.HolySuitlst = [];
|
|
this.HolySuitlsts = [];
|
|
this.Crystallst = [];
|
|
this.Partnerlst = [];
|
|
this.CampFightlst = [];
|
|
this.Praylst = [];
|
|
this.CollectCardStore = [];
|
|
this.WingsStoreLst = [];
|
|
this.LimitTimeEx = [];
|
|
var data = {};
|
|
var role = RoleController.getInstance().getRoleVo();
|
|
var dealData = function dealData(_datas) {
|
|
var list = [];
|
|
for (var i in _datas) {
|
|
var item = nx.dt.objClone(_datas[i]);
|
|
if (item.start_time) {
|
|
if (cc.sys.now() / 1000 - item.start_time[0] >= 0 && item.end_time[0] - cc.sys.now() / 1000 >= 0) {
|
|
list.push(item);
|
|
lstcopy.push(item);
|
|
}
|
|
} else {
|
|
if (role.lev >= item.lev[0] && role.lev <= item.lev[1] || item.lev[1] == 0) {
|
|
list.push(item);
|
|
lstcopy.push(item);
|
|
}
|
|
}
|
|
}
|
|
return list;
|
|
};
|
|
var self = this;
|
|
var dealLimit = function dealLimit(_lst) {
|
|
for (var i = 0; i < _lst.length; i++) {
|
|
var sl = _lst[i];
|
|
for (var j = 0; j < self.limitInfoPoint.length; j++) {
|
|
var item = self.limitInfoPoint[j];
|
|
if (item.item_id == sl.id) {
|
|
// console.log( "sl处理数据" + JSON.stringify( sl ) );
|
|
if (item.ext[0]) {
|
|
if (item.ext[0].key == 1) {
|
|
sl.has_buy = item.ext[0].val;
|
|
}
|
|
if (item.ext[0].key == 5) {
|
|
sl.has_buy = item.ext[0].val;
|
|
}
|
|
if (item.ext[0].key == 2) {
|
|
sl.has_buy = item.ext[0].val;
|
|
}
|
|
if (item.ext[0].key == 3) {
|
|
sl.has_buy = item.ext[0].val;
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
};
|
|
var lstcopy = [];
|
|
if (_data.type == 8) {
|
|
data = game.configs.exchange_data.data_shop_exchage_expediton;
|
|
this.shopLstPoint = dealData(data);
|
|
dealLimit(this.shopLstPoint);
|
|
}
|
|
if (_data.type == 6) {
|
|
data = game.configs.exchange_data.data_shop_exchage_arena;
|
|
this.ArenaShoplst = dealData(data);
|
|
dealLimit(this.ArenaShoplst);
|
|
}
|
|
if (_data.type == 5) {
|
|
data = game.configs.exchange_data.data_shop_exchage_guild;
|
|
this.GuildShoplst = dealData(data);
|
|
dealLimit(this.GuildShoplst);
|
|
}
|
|
if (_data.type == 17) {
|
|
data = game.configs.exchange_data.data_shop_exchage_elite;
|
|
this.RankShoplst = dealData(data);
|
|
dealLimit(this.RankShoplst);
|
|
}
|
|
if (_data.type == 30) {
|
|
data = game.configs.exchange_data.data_shop_exchage_ladder;
|
|
this.LadderShoplst = dealData(data);
|
|
dealLimit(this.LadderShoplst);
|
|
}
|
|
if (_data.type == 36) {
|
|
data = game.configs.exchange_data.data_shop_exchage_crosschampion;
|
|
this.CrossChampionlst = dealData(data);
|
|
dealLimit(this.CrossChampionlst);
|
|
}
|
|
if (_data.type == 28) {
|
|
data = game.configs.exchange_data.data_shop_exchage_suit;
|
|
// let len = Object.keys( data );
|
|
for (var i in data) {
|
|
var dataOne = data[i];
|
|
var HolySuitlst = dealData(dataOne);
|
|
dealLimit(HolySuitlst);
|
|
// let holyslst = dealLimit( HolySuitlst );
|
|
this.HolySuitlst.push(HolySuitlst);
|
|
}
|
|
}
|
|
if (_data.type == 31) {
|
|
data = game.configs.exchange_data.data_shop_exchage_seer;
|
|
// let len = Object.keys( data );
|
|
|
|
for (var _i in data) {
|
|
var _dataOne = data[_i];
|
|
this.Crystallst.push(_dataOne);
|
|
}
|
|
}
|
|
if (_data.type == 54) {
|
|
data = game.configs.exchange_data.data_shop_exchage_step_up;
|
|
this.SetShoplst = dealData(data);
|
|
dealLimit(this.SetShoplst);
|
|
}
|
|
if (_data.type == 55) {
|
|
data = game.configs.exchange_data.data_shop_exchage_elite_recruit;
|
|
this.SsetShoplst = dealData(data);
|
|
dealLimit(this.SsetShoplst);
|
|
}
|
|
if (_data.type == 56) {
|
|
data = game.configs.exchange_data.data_shop_exchage_theme;
|
|
this.ThemeShoplst = dealData(data);
|
|
dealLimit(this.ThemeShoplst);
|
|
}
|
|
if (_data.type == 57) {
|
|
data = game.configs.exchange_data.data_shop_exchage_limit;
|
|
this.Partnerlst = dealData(data);
|
|
dealLimit(this.Partnerlst);
|
|
}
|
|
if (_data.type == 58) {
|
|
data = game.configs.exchange_data.data_shop_exchage_prayer;
|
|
this.Praylst = dealData(data);
|
|
dealLimit(this.Praylst);
|
|
}
|
|
if (_data.type == 59) {
|
|
data = game.configs.exchange_data.data_shop_exchage_star_card;
|
|
this.CollectCardStore = dealData(data);
|
|
dealLimit(this.CollectCardStore);
|
|
}
|
|
if (_data.type == 61) {
|
|
data = game.configs.exchange_data.data_shop_exchage_camp_arena;
|
|
this.CampFightlst = dealData(data);
|
|
dealLimit(this.CampFightlst);
|
|
}
|
|
if (_data.type == 62) {
|
|
data = game.configs.exchange_data.data_shop_exchage_sprite_party;
|
|
this.WingsStoreLst = dealData(data);
|
|
dealLimit(this.WingsStoreLst);
|
|
}
|
|
if (_data.type == 71) {
|
|
data = game.configs.exchange_data.data_shop_exchage_happy;
|
|
this.LimitTimeEx = dealData(data);
|
|
dealLimit(this.LimitTimeEx);
|
|
}
|
|
|
|
/******
|
|
* [13401]:{"code":1,"msg":"","type":8,"is_half":0,
|
|
*
|
|
* "item_list":[{"item_id":8012,"ext":[{"key":2,"val":1}]},{"item_id":8011,"ext":[{"key":3,"val":1}]},{"item_id":8008,"ext":[{"key":3,"val":1}]},{"item_id":8013,"ext":[{"key":2,"val":5}]}]}
|
|
*/
|
|
// nx.debug( JSON.stringify( this.SetShoplst ) + "商城数据" );
|
|
|
|
// console.log( JSON.stringify( lstcopy ) + "可以显示的相关数据" + JSON.stringify( this.shopLst ) );
|
|
},
|
|
|
|
getPointShopData: function getPointShopData() {
|
|
return this.shopLstPoint;
|
|
},
|
|
getGuildShopData: function getGuildShopData() {
|
|
return this.GuildShoplst;
|
|
},
|
|
getArenaShopData: function getArenaShopData() {
|
|
return this.ArenaShoplst;
|
|
},
|
|
getRankShopData: function getRankShopData() {
|
|
return this.RankShoplst;
|
|
},
|
|
getThemeShoplst: function getThemeShoplst() {
|
|
return this.ThemeShoplst;
|
|
},
|
|
getSetShoplst: function getSetShoplst() {
|
|
return this.SetShoplst;
|
|
},
|
|
getSsetShoplst: function getSsetShoplst() {
|
|
return this.SsetShoplst;
|
|
},
|
|
getLadderShoplst: function getLadderShoplst() {
|
|
return this.LadderShoplst;
|
|
},
|
|
getCrossChampionShoplst: function getCrossChampionShoplst() {
|
|
return this.CrossChampionlst;
|
|
},
|
|
getHolyShoplst: function getHolyShoplst() {
|
|
return this.HolySuitlst;
|
|
},
|
|
getAllCrystal: function getAllCrystal() {
|
|
return this.Crystallst;
|
|
},
|
|
getPrayLst: function getPrayLst() {
|
|
return this.Praylst;
|
|
},
|
|
getCampFightLst: function getCampFightLst() {
|
|
return this.CampFightlst;
|
|
},
|
|
getPartnerLst: function getPartnerLst() {
|
|
return this.Partnerlst;
|
|
},
|
|
getCollectCardStoreLst: function getCollectCardStoreLst() {
|
|
return this.CollectCardStore;
|
|
},
|
|
getWingsStoreLst: function getWingsStoreLst() {
|
|
return this.WingsStoreLst;
|
|
},
|
|
getLimitTimeEx: function getLimitTimeEx() {
|
|
return this.LimitTimeEx;
|
|
},
|
|
getCrystalLstByCamp: function getCrystalLstByCamp(_camp) {
|
|
var lst = [];
|
|
this.Crystallst.forEach(function (crystal) {
|
|
if (crystal.camp == _camp) {
|
|
lst.push(crystal);
|
|
}
|
|
});
|
|
return lst;
|
|
},
|
|
setLimitInfo: function setLimitInfo(_data) {
|
|
/**********
|
|
* {"code":1,"msg":"","type":1,"is_half":0,
|
|
* "item_list":[{"item_id":1013,"ext":[{"key":1,"val":1}]}]}
|
|
*/
|
|
// 注意 存储的数据若要改变 需要存储的是克隆的配置数据
|
|
this.limitInfo = _data.item_list;
|
|
this.shopLst = [];
|
|
var lstcopy = nx.dt.objClone(this.getAllDefault());
|
|
var data = gdata("exchange_data", "data_shop_exchage_gold");
|
|
for (var i in data) {
|
|
var item = nx.dt.objClone(data[i]);
|
|
item.has_buy = 0;
|
|
this.shopLst.push(item);
|
|
}
|
|
for (var _i2 = 0; _i2 < this.shopLst.length; _i2++) {
|
|
var sl = this.shopLst[_i2];
|
|
for (var j = 0; j < this.limitInfo.length; j++) {
|
|
var _item = this.limitInfo[j];
|
|
var limt = lstcopy[_i2];
|
|
if (_item.item_id == sl.id) {
|
|
if (_item.ext[0].key == 1) {
|
|
sl.has_buy = _item.ext[0].val;
|
|
}
|
|
if (_item.ext[0].key == 2) {
|
|
sl.has_buy = _item.ext[0].val;
|
|
}
|
|
if (_item.ext[0].key == 3) {
|
|
sl.sl.has_buy = _item.ext[0].val;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
// console.log( JSON.stringify( lstcopy ) + "可以显示的相关数据" + JSON.stringify( this.shopLst ) );
|
|
},
|
|
|
|
getAllDefault: function getAllDefault() {
|
|
this.lstcopy = [];
|
|
var data = gdata("exchange_data", "data_shop_exchage_gold");
|
|
for (var i in data) {
|
|
var item = data[i];
|
|
this.lstcopy.push(item);
|
|
}
|
|
return this.lstcopy;
|
|
},
|
|
getLimitInfo: function getLimitInfo() {
|
|
return this.limitInfo;
|
|
}
|
|
});
|
|
module.exports = MallModel;
|
|
|
|
cc._RF.pop(); |