710 lines
23 KiB
JavaScript
710 lines
23 KiB
JavaScript
var Utils = require("Utils");
|
|
var gameConfig = require("gameConfig");
|
|
var NetManage = require("NetManage");
|
|
var SDKManage = require("SDKManage");
|
|
var Main = require("Main");
|
|
var jcshare = require("jcfw").share;
|
|
var playerData = function () {
|
|
this.init = function () {
|
|
this.itemtype = {
|
|
hero: 3,
|
|
heroskin: 4,
|
|
};
|
|
this.node_id = 1;
|
|
this.worldtime = 0;
|
|
this.skinmap = {};
|
|
|
|
this.gold = 0;
|
|
this.diamond = 0;
|
|
this.hero_id = 0;
|
|
this.head_id = "0";
|
|
this.head_frame = 0;
|
|
this.level = 1;
|
|
this.exp = 0;
|
|
this.max_exp = 100;
|
|
this.name = "guest";
|
|
this.head_list = [];
|
|
this.head_frame_list = [];
|
|
|
|
this.goods_list = [];
|
|
this.hero_list = [];
|
|
this.skin_list = [];
|
|
this.item_list = [];
|
|
this.talent_list = [];
|
|
this.season = {};
|
|
this.rank = 1;
|
|
this.m_friendApplyArr = [];
|
|
this.getopenhero();
|
|
};
|
|
this.property = function (obj) {
|
|
if (obj.user_info) {
|
|
this.refreshInfo(obj.user_info);
|
|
|
|
if (
|
|
obj.user_info.head_id ||
|
|
obj.user_info.name ||
|
|
obj.user_info.head_frame
|
|
) {
|
|
cc.chatMgr.sendmsg("CMUpdateUserInfo", {
|
|
nickname: this.name,
|
|
avatar_url: this.head_id,
|
|
head: Number(this.head_frame),
|
|
});
|
|
}
|
|
|
|
cc.Notifier.emit("refreshBaseInfo");
|
|
}
|
|
if (obj.container_chg) {
|
|
for (var i = 0; i < obj.container_chg.length; i++) {
|
|
var bd = obj.container_chg[i];
|
|
if (bd == "bag") {
|
|
NetManage.getItemList();
|
|
} else if (bd == "hero") {
|
|
NetManage.getHeroList();
|
|
} else if (bd == "heroSkin") {
|
|
NetManage.getSkinList();
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
this.AddfriendApplyArr = function (_uid) {
|
|
let isHave = 0;
|
|
for (let i = 0; i < this.m_friendApplyArr.length; i++) {
|
|
let tmpUID = this.m_friendApplyArr[i];
|
|
if (tmpUID == _uid) {
|
|
isHave = 1;
|
|
break;
|
|
}
|
|
}
|
|
if (isHave == 0) {
|
|
this.m_friendApplyArr.push(_uid);
|
|
}
|
|
};
|
|
|
|
this.deleteFriendApplyArr = function (_uid) {
|
|
for (let i = 0; i < this.m_friendApplyArr.length; i++) {
|
|
let tmpUID = this.m_friendApplyArr[i];
|
|
if (tmpUID == _uid) {
|
|
this.m_friendApplyArr.splice(i, 1);
|
|
break;
|
|
}
|
|
}
|
|
};
|
|
this.checkAtFriendApplyArr = function (_uid) {
|
|
let isHave = 0;
|
|
for (let i = 0; i < this.m_friendApplyArr.length; i++) {
|
|
let tmpUID = this.m_friendApplyArr[i];
|
|
if (tmpUID == _uid) {
|
|
isHave = 1;
|
|
break;
|
|
}
|
|
}
|
|
return isHave;
|
|
};
|
|
|
|
this.refreshInfo = function (obj) {
|
|
for (var k in obj) {
|
|
this[k] = obj[k];
|
|
}
|
|
};
|
|
|
|
this.getRankList = function (obj) {
|
|
this.ranking_list = obj.ranking_list;
|
|
};
|
|
|
|
this.getSeasonInfo = function (obj) {
|
|
this.season = obj.info;
|
|
cc.Notifier.emit("ongetSeasonInfo");
|
|
};
|
|
this.getDiscountList = function (obj) {
|
|
this.this.goods_list = obj.goods_list;
|
|
};
|
|
this.getHeroList = function (obj) {
|
|
this.hero_list = obj.hero_list;
|
|
cc.Notifier.emit("ongetHeroList");
|
|
};
|
|
this.getSkinList = function (obj) {
|
|
this.skin_list = obj.skin_list;
|
|
cc.Notifier.emit("ongetSkinList");
|
|
};
|
|
this.getItemList = function (obj) {
|
|
this.item_list = obj.item_list;
|
|
cc.Notifier.emit("ongetItemList");
|
|
};
|
|
this.gettalentList = function (obj) {
|
|
this.talent_list = obj.talent_list;
|
|
cc.Notifier.emit("ontalent_list");
|
|
};
|
|
|
|
this.getDrop = function (dropid) {
|
|
var cfg = gameConfig.dropConfig[dropid];
|
|
if (!cfg.itemdata) {
|
|
cfg.itemdata = [];
|
|
var itemarr = (cfg.item_id + "").split("|");
|
|
var numarr = (cfg.num + "").split("|");
|
|
for (var i = 0; i < itemarr.length; i++) {
|
|
cfg.itemdata.push({
|
|
id: itemarr[i],
|
|
num: numarr[i],
|
|
});
|
|
}
|
|
}
|
|
return cfg.itemdata;
|
|
};
|
|
|
|
this.getItemsByType = function (type) {
|
|
var arr = [];
|
|
for (var i = 0; i < this.item_list.length; i++) {
|
|
if (
|
|
gameConfig.all_ItemConfig[this.item_list[i].item_id].tab ==
|
|
type ||
|
|
type == 0
|
|
) {
|
|
arr.push(this.item_list[i]);
|
|
}
|
|
}
|
|
return arr;
|
|
};
|
|
|
|
this.getItemCount = function (id) {
|
|
if (id == 10001) {
|
|
return this.gold;
|
|
} else if (id == 10002) {
|
|
return this.diamond;
|
|
} else {
|
|
for (var i = 0; i < this.item_list.length; i++) {
|
|
if (this.item_list[i].item_id == id) {
|
|
return this.item_list[i].item_num;
|
|
}
|
|
}
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
this.checkItemEnough = function (id, v) {
|
|
v = Number(v);
|
|
id = Number(id);
|
|
if (id == 10001) {
|
|
return this.gold >= v;
|
|
} else if (id == 10002) {
|
|
return this.diamond >= v;
|
|
} else {
|
|
for (var i = 0; i < this.item_list.length; i++) {
|
|
if (this.item_list[i].item_id == id) {
|
|
return this.item_list[i].item_num >= v;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
this.getLearnedTalent = function (id) {
|
|
for (var i = 0; i < this.talent_list.length; i++) {
|
|
if (this.talent_list[i].talent_id == id) {
|
|
return this.talent_list[i];
|
|
}
|
|
}
|
|
if (this.level >= this.xinpian[id][0].need_user_level) {
|
|
return {
|
|
talent_id: id,
|
|
talent_lv: 1,
|
|
};
|
|
}
|
|
|
|
return null;
|
|
};
|
|
this.getDiscount = function (id) {
|
|
for (var i = this.goods_list.length - 1; i >= 0; i--) {
|
|
if (this.goods_list[i].item_id == id) {
|
|
return [
|
|
this.goods_list[i].gold_discount,
|
|
this.goods_list[i].diamond_discount,
|
|
];
|
|
}
|
|
}
|
|
return [100, 100];
|
|
};
|
|
this.getshowhero = function () {
|
|
return this.getheroSkinbyId(this.hero_id, 0);
|
|
};
|
|
this.getskinarrbyId = function (id) {
|
|
return this.skinmap[id].skins;
|
|
};
|
|
this.getheroSkinbyId = function (hid, idx) {
|
|
var skinArr = this.skinmap[hid].skins;
|
|
var skinid = skinArr[idx];
|
|
var skincfg = gameConfig.all_ItemConfig[skinid];
|
|
var skinres = skincfg.skinid;
|
|
return skinres;
|
|
};
|
|
|
|
this.getheroSkinidbyId = function (hid, idx) {
|
|
var skinArr = this.skinmap[hid].skins;
|
|
var skinid = skinArr[idx];
|
|
return Number(skinid);
|
|
};
|
|
this.checkhasgetskin = function (sid) {
|
|
if (gameConfig.all_ItemConfig[sid].isdefaultskin) {
|
|
return true;
|
|
}
|
|
|
|
for (var i = this.skin_list.length - 1; i >= 0; i--) {
|
|
if (this.skin_list[i].skin_id == sid) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
this.checkhasgethero = function (hid) {
|
|
for (var i = this.hero_list.length - 1; i >= 0; i--) {
|
|
if (this.hero_list[i].hero_id == hid) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
this.getopenhero = function () {
|
|
if (!this.openherolist) {
|
|
this.openherolist = [];
|
|
for (var k in gameConfig.all_ItemConfig) {
|
|
var cfg = gameConfig.all_ItemConfig[k];
|
|
if (cfg.type == this.itemtype.hero && cfg.getway) {
|
|
this.openherolist.push(cfg.id);
|
|
}
|
|
if (cfg.type == this.itemtype.heroskin && cfg.getway) {
|
|
if (!this.skinmap[cfg.playerid]) {
|
|
this.skinmap[cfg.playerid] = {
|
|
skins: [],
|
|
};
|
|
}
|
|
this.skinmap[cfg.playerid].skins.push(cfg.id);
|
|
if (cfg.isdefaultskin) {
|
|
this.skinmap[cfg.playerid].defaultskin = cfg.id;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
for (var k in this.skinmap) {
|
|
this.skinmap[k].skins = this.skinmap[k].skins.sort((a, b) => {
|
|
var c = 0;
|
|
if (a == this.skinmap[k].defaultskin) {
|
|
c = -99999;
|
|
}
|
|
if (b == this.skinmap[k].defaultskin) {
|
|
c = 99999;
|
|
}
|
|
return a - b + c;
|
|
});
|
|
}
|
|
|
|
return this.openherolist;
|
|
};
|
|
this.getheroskill = function (hid) {
|
|
var cfg = gameConfig.playerConfig[hid];
|
|
var skill1 = Number(cfg.skill1list.split("|")[0]);
|
|
var skill2 = Number(cfg.skill2list.split("|")[0]);
|
|
var skill3 = cfg.skill3list;
|
|
return [skill1, skill2, skill3];
|
|
};
|
|
this.changeHero = function (hid) {
|
|
this.nowheroid = hid;
|
|
this.nowherocfg = gameConfig.playerConfig[hid];
|
|
this.skinArr = (this.nowherocfg.skinlist + "").split("|");
|
|
this.skinid = this.skinmap[hid].defaultskin; //this.skinArr[0]
|
|
|
|
this.skill1 = Number(this.nowherocfg.skill1list.split("|")[0]);
|
|
this.skill2 = Number(this.nowherocfg.skill2list.split("|")[0]);
|
|
this.skill3 = this.nowherocfg.skill3list;
|
|
|
|
this.changeSkin(this.skinid);
|
|
};
|
|
this.changeSkin = function (v) {
|
|
this.skinid = v;
|
|
this.skincfg = gameConfig.all_ItemConfig[v];
|
|
this.skinres = this.skincfg.skinid;
|
|
};
|
|
|
|
this.getTime = function (obj) {
|
|
var date = new Date();
|
|
this.sertime = obj.time - date.getTime() / 1000;
|
|
this.sertimestr = obj.time;
|
|
};
|
|
|
|
this.getNodeID = function (obj) {
|
|
if (obj.errcode == 0) {
|
|
this.node_id = obj.node_id;
|
|
cc.SDKManage.NodeId = obj.node_id;
|
|
console.log("NodeID====", cc.SDKManage.NodeId);
|
|
}
|
|
};
|
|
|
|
this.dirtyWordCheck = function (obj) {
|
|
cc.Notifier.emit("dirtywordcheck", obj);
|
|
};
|
|
this.getbattleskilllist = function () {
|
|
return [
|
|
{
|
|
key: this.skill1,
|
|
value: 0,
|
|
},
|
|
{
|
|
key: this.skill2,
|
|
value: 0,
|
|
},
|
|
{
|
|
key: this.skill3,
|
|
value: 0,
|
|
},
|
|
];
|
|
};
|
|
|
|
this.getbattleopt = function () {
|
|
return {
|
|
account_id: SDKManage.account_id, // account_id
|
|
player_count: 4, //(
|
|
energy_shield: 0, //
|
|
baseskin: [this.skinres, 0, 0, 0],
|
|
team_uuid: "", // ()
|
|
team_mode: 1, // 0:
|
|
auto_fill: true, //
|
|
|
|
// team_members: _teamMembers,
|
|
weapons: [],
|
|
first_game: false,
|
|
skins: [],
|
|
prepare_items: [], // 12809
|
|
prepare_items2: [],
|
|
atk_add: 0,
|
|
battlecount: 1,
|
|
pre_settlement_info: "",
|
|
emojis: ["1", "2", "3", "4", "5", "6"],
|
|
show_team_ui: 1,
|
|
//offline: true,
|
|
newbiemode: false,
|
|
mapid: 1008,
|
|
sex: 2,
|
|
skill_list: [
|
|
{
|
|
key: this.skill1,
|
|
value: 0,
|
|
},
|
|
{
|
|
key: this.skill2,
|
|
value: 0,
|
|
},
|
|
{
|
|
key: this.skill3,
|
|
value: 0,
|
|
},
|
|
],
|
|
hero_id: this.nowheroid,
|
|
};
|
|
};
|
|
|
|
this.init2 = function () {
|
|
var cfg = gameConfig.gunTalentGrow;
|
|
this.xinpian = {};
|
|
for (var k in cfg) {
|
|
var onecfg = cfg[k];
|
|
if (!this.xinpian[onecfg.talent_id]) {
|
|
this.xinpian[onecfg.talent_id] = [];
|
|
}
|
|
this.xinpian[onecfg.talent_id].push(onecfg);
|
|
}
|
|
|
|
for (var kk in this.xinpian) {
|
|
this.xinpian[kk] = this.xinpian[kk].sort((a, b) => {
|
|
var aa = a.talent_lv;
|
|
var bb = b.talent_lv;
|
|
return aa - bb;
|
|
});
|
|
}
|
|
|
|
var cfg2 = gameConfig.all_ItemConfig;
|
|
gameConfig.skintohero = {};
|
|
for (var k in cfg2) {
|
|
var onecfg = cfg2[k];
|
|
if (onecfg.skinid) {
|
|
gameConfig.skintohero[onecfg.skinid] = onecfg.playerid;
|
|
}
|
|
}
|
|
};
|
|
|
|
this.debug = function (tp, v, v2) {
|
|
if (tp == 1) {
|
|
var itemcfg = gameConfig.all_ItemConfig[v];
|
|
if (itemcfg.type == this.itemtype.hero) {
|
|
if (!this.checkhasgethero(v)) {
|
|
this.hero_list.push({
|
|
hero_id: v,
|
|
});
|
|
}
|
|
} else if (itemcfg.type == this.itemtype.heroskin) {
|
|
if (!this.checkhasgetskin(v)) {
|
|
this.skin_list.push({
|
|
skin_id: v,
|
|
});
|
|
}
|
|
}
|
|
|
|
cc.Notifier.emit("herochange");
|
|
} else if (tp == 2) {
|
|
var hasfind = false;
|
|
for (var i = 0; i < this.talent_list.length; i++) {
|
|
if (this.talent_list[i].talent_id == v) {
|
|
this.talent_list[i].talent_lv++;
|
|
hasfind = true;
|
|
}
|
|
}
|
|
if (!hasfind) {
|
|
this.talent_list.push({
|
|
talent_id: v,
|
|
talent_lv: 2,
|
|
});
|
|
}
|
|
|
|
cc.Notifier.emit("talent_lvup", v);
|
|
} else if (tp == 3) {
|
|
for (var i = this.item_list.length - 1; i >= 0; i--) {
|
|
if (this.item_list[i].item_id == v) {
|
|
this.item_list[i].item_num -= v2;
|
|
if (this.item_list[i].item_num == 0) {
|
|
this.item_list.splice(i, 1);
|
|
}
|
|
}
|
|
if (v2) {
|
|
this.nickname = v2;
|
|
}
|
|
}
|
|
|
|
cc.Notifier.emit("refreshitem");
|
|
} else if (tp == 4) {
|
|
v();
|
|
} else if (tp == 5) {
|
|
this.ranking_list = {
|
|
//
|
|
type: 0, //
|
|
ranking_list: [
|
|
//
|
|
{
|
|
ranked: 1, //
|
|
account_id: "1122", //
|
|
name: "aaa", //
|
|
head_id: 50003, //
|
|
head_frame: 60001, //
|
|
level: 10, //
|
|
exp: 0, //
|
|
gold: 0, //
|
|
diamond: 0, //
|
|
hero_id: 30100, //
|
|
rank: 11, //
|
|
score: 220, //
|
|
},
|
|
{
|
|
ranked: 2, //
|
|
account_id: "3344", //
|
|
name: "aaa", //
|
|
head_id: 50003, //
|
|
head_frame: 60001, //
|
|
level: 10, //
|
|
exp: 0, //
|
|
gold: 0, //
|
|
diamond: 0, //
|
|
hero_id: 30300, //
|
|
rank: 11, //
|
|
score: 220, //
|
|
},
|
|
],
|
|
my_ranked: {
|
|
//(<)
|
|
ranked: 0, //
|
|
account_id: "", //
|
|
name: "ssss", //
|
|
head_id: 0, //
|
|
head_frame: 0, //
|
|
level: 20,
|
|
exp: 0, //
|
|
gold: 0, //
|
|
diamond: 0, //
|
|
hero_id: 30200, //
|
|
rank: 12, //
|
|
score: 110, //
|
|
},
|
|
};
|
|
v();
|
|
} else if (tp == 6) {
|
|
v();
|
|
} else if (tp == 7) {
|
|
v({
|
|
errcode: 0, //
|
|
errmsg: "", //
|
|
info: {
|
|
//()
|
|
activate: 0, //
|
|
account_id: "", //
|
|
name: "name", //
|
|
head_id: 50003, //
|
|
head_frame: 60001, //
|
|
level: 10, //
|
|
exp: 30, //
|
|
max_exp: 90, //()
|
|
gold: 0, //
|
|
diamond: 0, //
|
|
hero_id: 30200, //
|
|
current_rank: 10, //
|
|
history_best_rank: 11, //
|
|
history_seasons: [
|
|
//
|
|
{
|
|
season_id: 22, //
|
|
total_kills: 10, //()
|
|
game_times: 20, //()
|
|
win_times: 30, //()
|
|
win_rate: 40, //(,)
|
|
max_kills: 50, //()
|
|
avg_kills: 60, //()
|
|
max_damage_out: 70, //()
|
|
avg_damage_out: 80, //()
|
|
star_kills: 50, //(-, )
|
|
star_damage: 60, //(-, )
|
|
star_alive: 70, //(-,)
|
|
star_recover: 80, //(-, )
|
|
star_win: 100, //(-,)
|
|
},
|
|
],
|
|
},
|
|
});
|
|
} else if (tp == 8) {
|
|
var tdata = {
|
|
errcode: 0, //
|
|
errmsg: "", //
|
|
current_active_value: 30, //
|
|
max_active_value: 100, //
|
|
mission_list1: [
|
|
//
|
|
{
|
|
mission_id: 71001,
|
|
current: 0,
|
|
target: 0,
|
|
state: 0,
|
|
show_progress: 0,
|
|
},
|
|
{
|
|
mission_id: 71003,
|
|
current: 5,
|
|
target: 5,
|
|
state: 1,
|
|
show_progress: 1,
|
|
},
|
|
{
|
|
mission_id: 71006,
|
|
current: 2,
|
|
target: 5,
|
|
state: 2,
|
|
show_progress: 1,
|
|
},
|
|
{
|
|
mission_id: 71006,
|
|
current: 2,
|
|
target: 5,
|
|
state: 2,
|
|
show_progress: 2,
|
|
},
|
|
{
|
|
mission_id: 71006,
|
|
current: 2,
|
|
target: 5,
|
|
state: 2,
|
|
show_progress: 2,
|
|
},
|
|
],
|
|
mission_list2: [
|
|
|
|
{
|
|
mission_id: 71001,
|
|
current: 0,
|
|
target: 0,
|
|
state: 0,
|
|
show_progress: 0,
|
|
},
|
|
{
|
|
mission_id: 71003,
|
|
current: 5,
|
|
target: 5,
|
|
state: 1,
|
|
show_progress: 1,
|
|
},
|
|
{
|
|
mission_id: 71006,
|
|
current: 2,
|
|
target: 5,
|
|
state: 2,
|
|
show_progress: 1,
|
|
},
|
|
],
|
|
};
|
|
v(tdata);
|
|
} else if (tp == 9) {
|
|
var tdata = {
|
|
errcode: 0,
|
|
errmsg: "",
|
|
info: {
|
|
|
|
season_id: 5,
|
|
card_lv: 11,
|
|
card_exp: 10,
|
|
card_max_exp: 100,
|
|
season_begin_time: 1638951964,
|
|
season_end_time: 1638951964,
|
|
gift_packages: [
|
|
|
|
//struct SeasonCardGiftPackage
|
|
{
|
|
package_id: 0,
|
|
state: 0,
|
|
price_info: {
|
|
//struct PriceInfo,
|
|
cost_list: [
|
|
|
|
//struct CostInfo
|
|
{
|
|
cost_group: [
|
|
|
|
{
|
|
item_id: 0,
|
|
item_num: 0,
|
|
discount: 0,
|
|
},
|
|
],
|
|
},
|
|
],
|
|
discount_begin_time: 0,
|
|
discount_end_time: 0,
|
|
},
|
|
},
|
|
],
|
|
received_level_rewards1: [
|
|
|
|
1, 2, 3,
|
|
],
|
|
received_level_rewards2: [
|
|
|
|
1, 2, 3, 4,
|
|
],
|
|
},
|
|
};
|
|
v(tdata.info);
|
|
} else if (tp == 10) {
|
|
v();
|
|
}
|
|
};
|
|
};
|
|
var instance = new playerData();
|
|
instance.init();
|
|
instance.init2();
|
|
cc.playerData = instance;
|
|
module.exports = instance;
|