626 lines
19 KiB
JavaScript
626 lines
19 KiB
JavaScript
// Learn cc.Class:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
|
|
// Learn Attribute:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
|
|
var httpclient = require("httpclient");
|
|
var urlbuilder = require("urlbuilder");
|
|
const BaseNet = require("../BaseNet");
|
|
|
|
module.exports = {
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
init(account_id, session_id, name, avatar_url) {
|
|
this.account_id = account_id;
|
|
|
|
this.session_id = session_id;
|
|
this.name = name;
|
|
this.avatar_url = avatar_url;
|
|
this.urlbd = new urlbuilder(BaseNet.getNormalApiUrl("gameapi"));
|
|
},
|
|
|
|
getResponce(cb, urlbd, cb2) {
|
|
var self = this;
|
|
|
|
httpclient.httpGet(
|
|
urlbd.baseurl,
|
|
function (restext) {
|
|
var obj;
|
|
try {
|
|
obj = httpclient.JSON_parse(restext);
|
|
} catch (e) {
|
|
cc.uiHelper.showTips("Request failed");
|
|
}
|
|
var obj = httpclient.JSON_parse(restext);
|
|
if (obj.property_chg) {
|
|
cc.playerData.property(obj.property_chg);
|
|
}
|
|
if (obj.award) {
|
|
cc.Notifier.emit("getreward", obj.award);
|
|
}
|
|
|
|
if (obj.errmsg) {
|
|
cc.uiHelper.showTips(obj.errmsg);
|
|
}
|
|
if (obj.errcode == 0) {
|
|
if (cb) {
|
|
cb(obj);
|
|
}
|
|
if (cb2) {
|
|
cb2(obj);
|
|
}
|
|
}
|
|
},
|
|
function (errcode, errmsg) {
|
|
setTimeout(() => {
|
|
self.getResponce(cb, urlbd, cb2);
|
|
}, 1000);
|
|
}
|
|
);
|
|
},
|
|
|
|
clientBattleReport(
|
|
rank_score,
|
|
gold,
|
|
kills,
|
|
damage_amount,
|
|
time_alive,
|
|
rank,
|
|
team_status
|
|
) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Role")
|
|
.addKV("a", "clientBattleReport")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("rank_score", rank_score)
|
|
.addKV("coin_num", gold)
|
|
.addKV("kills", kills)
|
|
.addKV("harm", damage_amount)
|
|
.addKV("alive_time", time_alive)
|
|
.addKV("rank", rank)
|
|
.addKV("team_status", team_status);
|
|
this.getResponce(
|
|
cc.playerData.clientBattleReport.bind(cc.playerData),
|
|
this.urlbd
|
|
);
|
|
},
|
|
|
|
//获取服务器时间
|
|
getTime(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Hang")
|
|
.addKV("a", "getTime")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.getTime.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
//创建队伍
|
|
createTeam(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Team")
|
|
.addKV("a", "createTeam")
|
|
.addKV("node_id", cc.playerData.node_id)
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
//获取队伍信息
|
|
getTeamInfo(team_uuid, cb) {
|
|
var teamid = "";
|
|
if (typeof team_uuid == "string") {
|
|
teamid = team_uuid;
|
|
} else {
|
|
teamid = team_uuid.team_uuid;
|
|
}
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Team")
|
|
.addKV("a", "teamInfo")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("team_uuid", teamid);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
//加入队伍
|
|
joinTeam(team_uuid, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Team")
|
|
.addKV("a", "joinTeam")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("team_uuid", team_uuid);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
//退出队伍
|
|
leaveTeam(team_uuid, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Team")
|
|
.addKV("a", "leaveTeam")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("team_uuid", team_uuid);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
//开始游戏
|
|
teamStartGame(team_uuid) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Team")
|
|
.addKV("a", "startGame")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("team_uuid", team_uuid);
|
|
this.getResponce(null, this.urlbd);
|
|
},
|
|
|
|
//保存新手引导流程
|
|
saveNewbie(newbieid) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Role")
|
|
.addKV("a", "saveNewbie")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("id", newbieid);
|
|
this.getResponce(
|
|
cc.playerData.saveNewbie.bind(cc.playerData),
|
|
this.urlbd
|
|
);
|
|
},
|
|
|
|
//获取城市ID
|
|
getNodeID(cb) {
|
|
var urlbd = new urlbuilder(BaseNet.getNodeUrl());
|
|
urlbd.clear();
|
|
urlbd.addKV("c", "Ops").addKV("a", "getNodeId");
|
|
this.getResponce(
|
|
cc.playerData.getNodeID.bind(cc.playerData),
|
|
urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
//查询屏蔽字
|
|
dirtyWordCheck(text) {
|
|
var urlbd;
|
|
urlbd = new urlbuilder(BaseNet.getNormalApiUrl("service"));
|
|
urlbd.clear();
|
|
urlbd
|
|
.addKV("c", "TextService")
|
|
.addKV("a", "dirtyWordCheck")
|
|
.addKV("text", text);
|
|
this.getResponce(
|
|
cc.playerData.dirtyWordCheck.bind(cc.playerData),
|
|
urlbd
|
|
);
|
|
},
|
|
|
|
/////new
|
|
|
|
logingame(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "User")
|
|
.addKV("a", "login")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
getDiscountList() {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Shop")
|
|
.addKV("a", "buyGoods")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.getDiscountList.bind(cc.playerData),
|
|
this.urlbd
|
|
);
|
|
},
|
|
getHeroList(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Hero")
|
|
.addKV("a", "heroList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.getHeroList.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
getSkinList(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Hero")
|
|
.addKV("a", "skinList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.getSkinList.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
getItemList(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Bag")
|
|
.addKV("a", "itemList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.getItemList.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
getShopGoodsInfo(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Shop")
|
|
.addKV("a", "info")
|
|
.addKV("shop_id", 100)
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
(res) => {
|
|
cc.Notifier.emit("shopItem", res);
|
|
},
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
buyGood(goods_id, cost_item_id, shop_id, goods_num) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Shop")
|
|
.addKV("a", "buyGoods")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("shop_id", shop_id)
|
|
.addKV("goods_id", goods_id)
|
|
.addKV("goods_num", goods_num)
|
|
.addKV("cost_item_id", cost_item_id);
|
|
this.getResponce(() => {
|
|
cc.uiHelper.showTips("successful purchase");
|
|
}, this.urlbd);
|
|
},
|
|
|
|
gettalentList(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Gun")
|
|
.addKV("a", "talentList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.gettalentList.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
upgradeTalentLv(talent_id) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Gun")
|
|
.addKV("a", "upgradeTalentLv")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("talent_id", talent_id);
|
|
this.getResponce(() => {
|
|
cc.uiHelper.showTips("update successed");
|
|
this.gettalentList(() => {
|
|
cc.Notifier.emit("talent_lvup", talent_id);
|
|
});
|
|
}, this.urlbd);
|
|
},
|
|
|
|
useitem(item_id, item_num, param1, param2, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Bag")
|
|
.addKV("a", "useItem")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("item_id", item_id)
|
|
.addKV("item_num", item_num);
|
|
if (param1) {
|
|
this.urlbd.addKV("param1", param1);
|
|
}
|
|
if (param2) {
|
|
this.urlbd.addKV("param2", param2);
|
|
}
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
getSeasonInfo(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Season")
|
|
.addKV("a", "info")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(
|
|
cc.playerData.getSeasonInfo.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
getSeasonReward(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Season")
|
|
.addKV("a", "getMissionReward")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
checkName(v, cb) {
|
|
var url = BaseNet.getNormalApiUrl("service");
|
|
var urlbd = new urlbuilder(url);
|
|
urlbd
|
|
.addKV("c", "TextService")
|
|
.addKV("a", "isValidName")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("name", v);
|
|
|
|
this.getResponce(cb, urlbd);
|
|
},
|
|
|
|
getRankList(type, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Ranking")
|
|
.addKV("a", "rankingList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("type", type);
|
|
|
|
this.getResponce(
|
|
cc.playerData.getRankList.bind(cc.playerData),
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
getactivityRankingList(type, cb) {
|
|
console.log("GET RANK DATA");
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Ranking")
|
|
.addKV("a", "activityRankingList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("type", type);
|
|
this.getResponce(
|
|
(res) => {
|
|
// cc.Notifier.emit('missionList', res);
|
|
},
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
getUeserInfo(target_id, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "User")
|
|
.addKV("a", "detailInfo")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("target_id", target_id);
|
|
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
missionList(type, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Mission")
|
|
.addKV("a", "missionList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("type", type);
|
|
|
|
this.getResponce(
|
|
(res) => {
|
|
cc.Notifier.emit("missionList", res);
|
|
},
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
commitMission(mission_id, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Mission")
|
|
.addKV("a", "commitMission")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("mission_id", mission_id);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
gunList(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Gun")
|
|
.addKV("a", "gunList")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
|
|
this.getResponce(
|
|
(res) => {
|
|
cc.Notifier.emit("gunList", res);
|
|
},
|
|
this.urlbd,
|
|
cb
|
|
);
|
|
},
|
|
|
|
getSeasonAllReward() {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "SeasonCard")
|
|
.addKV("a", "getAllReward")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
this.getResponce(() => {
|
|
this.seasonCard((res) => {
|
|
cc.Notifier.emit("onSeasonCardInfo", res);
|
|
});
|
|
}, this.urlbd);
|
|
},
|
|
seasonCard(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "SeasonCard")
|
|
.addKV("a", "info")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
seasonCardReward(type, level, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "SeasonCard")
|
|
.addKV("a", "getReward")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("type", type)
|
|
.addKV("level", level);
|
|
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
buyseadonlevel(add_level) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "SeasonCard")
|
|
.addKV("a", "buyLevel")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("add_level", add_level);
|
|
this.getResponce(() => {
|
|
this.seasonCard((res) => {
|
|
cc.Notifier.emit("onSeasonCardInfo", res);
|
|
});
|
|
}, this.urlbd);
|
|
},
|
|
|
|
updateuseinfo(v) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "User")
|
|
.addKV("a", "update")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id);
|
|
|
|
if (v.head_id) {
|
|
this.urlbd.addKV("head_id", v.head_id);
|
|
}
|
|
if (v.head_frame) {
|
|
this.urlbd.addKV("head_frame", v.head_frame);
|
|
}
|
|
if (v.hero_id) {
|
|
this.urlbd.addKV("hero_id", v.hero_id);
|
|
}
|
|
if (v.first_fight) {
|
|
this.urlbd.addKV("first_fight", v.first_fight);
|
|
}
|
|
|
|
this.getResponce(null, this.urlbd);
|
|
},
|
|
|
|
buybook(cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "SeasonCard")
|
|
.addKV("a", "buyGiftPackage")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("package_id", 2)
|
|
.addKV("cost_item_id", 10002);
|
|
this.getResponce(() => {
|
|
this.seasonCard((res) => {
|
|
cc.Notifier.emit("onSeasonCardInfo", res);
|
|
cb();
|
|
});
|
|
}, this.urlbd);
|
|
},
|
|
sendWantedMission(mission, object, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Mission")
|
|
.addKV("a", "sendOfferRewardMission")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("mission_id", mission)
|
|
.addKV("objects", object);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
boostOfferRewardMission(mission, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "Mission")
|
|
.addKV("a", "boostOfferRewardMission")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("mission_id", mission);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
searchUserByAccountid(account, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "User")
|
|
.addKV("a", "info")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("target_id", account);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
|
|
searchUserByName(name, cb) {
|
|
this.urlbd.clear();
|
|
this.urlbd
|
|
.addKV("c", "User")
|
|
.addKV("a", "query")
|
|
.addKV("account_id", this.account_id)
|
|
.addKV("session_id", this.session_id)
|
|
.addKV("name", name);
|
|
this.getResponce(cb, this.urlbd);
|
|
},
|
|
};
|