"use strict";
|
cc._RF.push(module, '2dffcv8hD1O0I8pPJXBDgcT', 'role_controller');
|
// Scripts/mod/role/role_controller.js
|
|
"use strict";
|
|
/*-----------------------------------------------------+
|
* 角色控制模块
|
* @author whjing2012@163.com
|
+-----------------------------------------------------*/
|
// var MainSceneController = require("mainscene_controller");
|
var RoleEvent = require("role_event");
|
|
var RoleController = cc.Class({
|
"extends": BaseController,
|
ctor: function ctor() {},
|
// 初始化配置数据
|
initConfig: function initConfig() {
|
var RoleModel = require("role_model");
|
|
this.model = new RoleModel();
|
this.model.initConfig();
|
this.is_re_connect = false;
|
this.apk_data = null; // SDK_.get_apk_url(function(data){
|
// cc.log(data)
|
// this.apk_data = data;
|
// }.bind(this))
|
},
|
getModel: function getModel() {
|
return this.model;
|
},
|
getRoleVo: function getRoleVo() {
|
if (this.model) {
|
return this.model.getRoleVo();
|
}
|
},
|
// 注册监听事件
|
registerEvents: function registerEvents() {
|
this.re_link_game_event = gcore.GlobalEvent.bind(EventId.LOADING_FINISH, function () {
|
if (this.need_set_name) this.openRoleSetNameView(true);
|
}.bind(this));
|
},
|
// 注册协议接受事件
|
registerProtocals: function registerProtocals() {
|
this.RegisterProtocal(10301, this.on10301); // 角色基本信息
|
|
this.RegisterProtocal(10302, this.on10302); // 资产信息
|
|
this.RegisterProtocal(10315, this.on10315); // 查看角色信息
|
|
this.RegisterProtocal(10306, this.on10306); // 战力变更推送
|
|
this.RegisterProtocal(10318, this.on10318); // 允许切磋状态
|
|
this.RegisterProtocal(10325, this.on10325); // 头像列表信息
|
|
this.RegisterProtocal(10327, this.on10327); // 头像变更
|
|
this.RegisterProtocal(10345, this.on10345); // 形象信息
|
|
this.RegisterProtocal(10346, this.on10346); // 形象使用
|
|
this.RegisterProtocal(10347, this.on10347); // 形象激活
|
|
this.RegisterProtocal(10342, this.on10342); // 强制改名
|
|
this.RegisterProtocal(10343, this.on10343); // 角色改名
|
|
this.RegisterProtocal(10317, this.on10317); // 形象激活
|
|
this.RegisterProtocal(10316, this.on10316); // 膜拜角色
|
// this.RegisterProtocal(12741, this.on12741); // 能用提示信息
|
|
this.RegisterProtocal(12745, this.on12745); // 道具不足通用协议
|
|
this.RegisterProtocal(10906, this.on10906); // 开服天数
|
|
this.RegisterProtocal(10994, this.on10994); // 服务端通知整点更新
|
|
this.RegisterProtocal(10945, this.on10945); // 媒体卡兑换
|
|
this.RegisterProtocal(21500, this.on21500); // 头像框获取
|
|
this.RegisterProtocal(21501, this.on21501); // 使用头像框
|
|
this.RegisterProtocal(21502, this.on21502); // 更新头像框
|
|
this.RegisterProtocal(21503, this.on21503); // 激活头像框
|
|
this.RegisterProtocal(23300, this.on23300); // 称号信息
|
|
this.RegisterProtocal(23301, this.on23301); // 使用称号
|
|
this.RegisterProtocal(23302, this.on23302); // 更新称号数据
|
|
this.RegisterProtocal(23303, this.on23303); // 激活称号
|
|
this.RegisterProtocal(24500, this.on24500); // 当前特权情况
|
|
this.RegisterProtocal(10350, this.handle10350); //-- 获取活动资产id
|
|
this.RegisterProtocal(10351, this.handle10351); //-- 推送活动资产id
|
|
this.RegisterProtocal(12770, this.handle12770); // -- 发送举报协议
|
|
this.RegisterProtocal(12771, this.handle12771); //-- 获取举报协议信息
|
|
this.RegisterProtocal(10905, this.handle10905); //-- 世界等级
|
//成长之路
|
// this.RegisterProtocal(25830, this.handle25830); //查看成长之路
|
// this.RegisterProtocal(25831, this.handle25831); //成长之路分享
|
// this.RegisterProtocal(25832, this.handle25832); //查看成长之路分享
|
},
|
setReconnect: function setReconnect(status) {
|
this.is_re_connect = status;
|
},
|
//判断别人srv_id是不是与自己是不是同服
|
isTheSameSvr: function isTheSameSvr(srv_id) {
|
var is_same = this.model.isTheSame(srv_id);
|
|
if (srv_id && is_same) {
|
return true;
|
} else {
|
return false;
|
}
|
},
|
// 角色基本信息
|
on10301: function on10301(data) {
|
cc.log("角色基本信息");
|
cc.log(data);
|
|
if (!this.init_role) {
|
this.init_role = true; //先实例化
|
|
this.model.initRoleBaseData(data); // 这里会有很多信息需要请求
|
|
this.requestOpenSrvDay(); // 开服天数
|
|
if (PLATFORM_TYPR == "SH_SDK") {
|
SDK.roleUpLevel(this.getRoleVo().lev);
|
}
|
|
if (data.lev <= 5) {
|
game.addGuideRes();
|
|
if (data.sex == 2) {
|
game.addRenameRes();
|
}
|
}
|
|
game.addChapterRes(data.chapter_id);
|
|
if (data.lev < 10) {
|
window.hide_loading = true;
|
}
|
|
var SysController = require("sys_controller").getInstance();
|
|
game.preloadRes(function () {
|
// this.model.initRoleBaseData(data);
|
SysController.requestLoginProtocals(function () {
|
var MainUiController = require("mainui_controller");
|
|
MainUiController.getInstance().openMainUI(true);
|
|
var MainSceneController = require("mainscene_controller");
|
|
MainSceneController.getInstance().enterMainScene(true);
|
}.bind(this));
|
}.bind(this));
|
gcore.GlobalEvent.fire(EventId.EVT_ROLE_CREATE_SUCCESS); // -- sdk等级计算
|
|
if (IS_SUBMIT) {
|
SDK.sdkSubmitUserData(3);
|
}
|
|
game.initMsgView();
|
} else {
|
this.model.initRoleBaseData(data);
|
} // 断线重连抛出事件
|
|
|
if (this.is_re_connect) {
|
gcore.GlobalEvent.fire(EventId.EVT_RE_LINK_GAME);
|
this.is_re_connect = false;
|
}
|
},
|
// 角色资产信息
|
on10302: function on10302(data) {
|
this.model.initRoleAssetsData(data);
|
},
|
//查看角色信息
|
requestRoleInfo: function requestRoleInfo(rid, srv_id) {
|
if (rid == 0 || !srv_id) return;
|
var protocal = {};
|
protocal.rid = rid;
|
protocal.srv_id = srv_id;
|
this.SendProtocal(10315, protocal);
|
},
|
//查看角色信息
|
on10315: function on10315(data) {
|
gcore.GlobalEvent.fire(RoleEvent.DISPATCH_PLAYER_VO_EVENT, data);
|
},
|
// 膜拜
|
sender10316: function sender10316(rid, srv_id, index, type) {
|
if (!rid) return;
|
index = index || 0;
|
type = type || 0;
|
var protocal = {};
|
protocal.type = type;
|
protocal.rid = rid;
|
protocal.srv_id = srv_id;
|
protocal.idx = index;
|
this.SendProtocal(10316, protocal);
|
},
|
on10316: function on10316(data) {
|
message(data.msg);
|
|
if (data.code == 1) {
|
gcore.GlobalEvent.fire(RoleEvent.WorshipOtherRole, data);
|
}
|
},
|
// 更新切磋状态
|
send10318: function send10318(auto_pk) {
|
this.SendProtocal(10318, {
|
auto_pk: auto_pk
|
});
|
},
|
// 更新切磋状态结果
|
on10318: function on10318(data) {
|
message(data.msg);
|
|
if (data.code == 1) {
|
this.model.setRoleAttribute("auto_pk", data.auto_pk);
|
}
|
},
|
// 请求头像列表信息
|
send10325: function send10325() {
|
this.SendProtocal(10325, {});
|
},
|
on10325: function on10325(data) {
|
this.model.setRoleAttribute("face_list", data.face_list);
|
},
|
// 头像变更
|
send10327: function send10327(face_id) {
|
this.SendProtocal(10327, {
|
face_id: face_id
|
});
|
},
|
on10327: function on10327(data) {
|
message(data.msg);
|
|
if (data.code == 1) {
|
this.model.setRoleAttribute("face_id", data.face_id);
|
}
|
},
|
// 通用提示信息
|
on12741: function on12741(data) {// message(data.msg);
|
},
|
// 道具不足通用提示
|
on12745: function on12745(data) {
|
var item_config = Utils.getItemConfig(data.bid);
|
|
if (item_config) {
|
if (data.bid == Config.item_data.data_assets_label2id.gold || data.bid == Config.item_data.data_assets_label2id.gold) {
|
if (IS_SHOW_CHARGE == false) {
|
message(Utils.TI18N("钻石不足"));
|
} else {
|
var fun = function () {
|
require("vip_controller").getInstance().openVipMainWindow(true, VIPTABCONST.CHARGE);
|
}.bind(this);
|
|
var str = cc.js.formatStr(Utils.TI18N('%s不足,是否前往充值'), item_config.name);
|
|
var CommonAlert = require("commonalert");
|
|
CommonAlert.show(str, Utils.TI18N('确定'), fun, Utils.TI18N('取消'), null, CommonAlert.type.rich, null, null);
|
}
|
} else if (data.bid == Config.item_data.data_assets_label2id.energy) {
|
message(Utils.TI18N("情报不足"));
|
} else {
|
var config = Utils.getItemConfig(data.bid);
|
|
if (config) {
|
var BackpackController = require("backpack_controller");
|
|
BackpackController.getInstance().openTipsSource(true, config.id);
|
}
|
}
|
}
|
},
|
on10994: function on10994(data) {
|
if (data.type == 6 || data.type == 18) {
|
require("mainscene_controller").getInstance().changeMainCityTimeType(data.type);
|
} else if (data.type == 0) {
|
this.requestOpenSrvDay(); // require("primus_controller").getInstance().sender20706() //星河神殿请求红点
|
|
require("action_controller").getInstance().requestActionRedStatus(); //部分活动请求红点
|
|
|
require("startower_controller").getInstance().sender11320();
|
}
|
},
|
// 改名
|
changeRoleName: function changeRoleName(name, sex) {
|
this.SendProtocal(10343, {
|
name: name,
|
sex: sex
|
});
|
},
|
// 改名结果
|
on10343: function on10343(data) {
|
message(data.msg);
|
|
if (data.code == 1) {
|
this.model.setRoleAttribute("name", data.name);
|
this.model.setRoleAttribute("sex", data.sex);
|
this.model.setRoleAttribute("is_first_rename", 0);
|
this.openRoleSetNameView(false);
|
}
|
},
|
// 形象信息请求
|
send10345: function send10345() {
|
this.SendProtocal(10345, {});
|
},
|
on10345: function on10345(data) {
|
gcore.GlobalEvent.fire(RoleEvent.GetModelList, data);
|
},
|
// 形象使用
|
send10346: function send10346(id) {
|
this.SendProtocal(10346, {
|
id: id
|
});
|
},
|
on10346: function on10346(data) {
|
message(data.msg);
|
|
if (data.code == 1) {
|
gcore.GlobalEvent.fire(RoleEvent.UpdateModel, data.id);
|
}
|
},
|
// 形象激活
|
send10347: function send10347(id) {
|
this.SendProtocal(10347, {
|
id: id
|
});
|
},
|
on10347: function on10347(data) {
|
message(data.msg);
|
|
if (data.code == 1) {
|
gcore.GlobalEvent.fire(RoleEvent.ActiveModel, data.id);
|
}
|
},
|
// 媒体卡领取
|
sender10945: function sender10945(card_id) {
|
this.SendProtocal(10945, {
|
card_id: card_id
|
});
|
},
|
on10945: function on10945(data) {
|
message(data.msg);
|
},
|
// 头像框获取
|
send21500: function send21500() {
|
this.SendProtocal(21500);
|
},
|
on21500: function on21500(data) {
|
gcore.GlobalEvent.fire(RoleEvent.GetFaceList, data);
|
},
|
// 使用头像框
|
send21501: function send21501(base_id) {
|
this.SendProtocal(21501, {
|
base_id: base_id
|
});
|
},
|
on21501: function on21501(data) {},
|
// 更新头像框
|
on21502: function on21502(data) {
|
gcore.GlobalEvent.fire(RoleEvent.GetFaceList, data);
|
},
|
// 激活头像框
|
send21503: function send21503(base_id) {
|
this.SendProtocal(21503, {
|
base_id: base_id
|
});
|
},
|
on21503: function on21503(data) {
|
gcore.GlobalEvent.fire(RoleEvent.GetFaceList, data);
|
},
|
// 称号列表信息
|
send23300: function send23300() {
|
this.SendProtocal(23300, {});
|
},
|
on23300: function on23300(data) {
|
this.model.setRoleAttribute("title_id", data.base_id);
|
this.model.setRoleAttribute("title_list", data.honor);
|
gcore.GlobalEvent.fire(RoleEvent.GetTitleList, data);
|
},
|
// 使用称号
|
send23301: function send23301(base_id) {
|
this.SendProtocal(23301, {
|
base_id: base_id
|
});
|
},
|
on23301: function on23301(data) {
|
this.model.setRoleAttribute("title_id", data.base_id);
|
gcore.GlobalEvent.fire(RoleEvent.UseTitle, data.base_id);
|
},
|
// 更新称号
|
on23302: function on23302(data) {
|
this.model.setRoleAttribute("title_list", data.honor);
|
gcore.GlobalEvent.fire(RoleEvent.UpdateTitleList, data);
|
},
|
// 激活称号
|
send23303: function send23303(base_id) {
|
this.SendProtocal(23303, {
|
base_id: base_id
|
});
|
},
|
on23303: function on23303(data) {
|
this.model.setRoleAttribute("title_list", data.honor);
|
gcore.GlobalEvent.fire(RoleEvent.UpdateTitleList, data);
|
},
|
// 打开角色设置面板
|
openRoleInfoView: function openRoleInfoView(status) {
|
if (status == true) {
|
if (!this.role_info_view) {
|
var RoleSetWindow = require("role_set_window");
|
|
this.role_info_view = new RoleSetWindow();
|
}
|
|
this.role_info_view.open();
|
} else {
|
if (this.role_info_view) {
|
this.role_info_view.close();
|
this.role_info_view = null;
|
}
|
}
|
},
|
// 打开更改装饰界面
|
openRoleDecorateView: function openRoleDecorateView(status, index, setting) {
|
if (status) {
|
if (!this.role_decorate_view) {
|
var RoleDecorateWindow = require("role_decorate_window");
|
|
this.role_decorate_view = new RoleDecorateWindow();
|
}
|
|
this.role_decorate_view.open(index, setting);
|
} else {
|
if (this.role_decorate_view) {
|
this.role_decorate_view.close();
|
this.role_decorate_view = null;
|
}
|
}
|
},
|
//判断一个人是否是自己
|
checkIsSelf: function checkIsSelf(srv_id, rid) {
|
var role_vo = this.getRoleVo();
|
if (role_vo == null) return false;else return role_vo.srv_id == srv_id && role_vo.rid == rid;
|
},
|
// 当前特权情况
|
on24500: function on24500(data) {
|
this.model.setPrivilegeData(data.list);
|
},
|
// 请求开服天数
|
requestOpenSrvDay: function requestOpenSrvDay() {
|
this.SendProtocal(10906, {});
|
},
|
// 开服天数返回
|
on10906: function on10906(data) {
|
this.model.setOpenSrvDay(data.open_day);
|
},
|
// 强制改名
|
on10342: function on10342() {
|
if (game.finish_loading) {
|
this.openRoleSetNameView(true);
|
} else {
|
this.need_set_name = true;
|
}
|
},
|
// 点赞数量
|
on10317: function on10317() {},
|
// --打开设置名称界面
|
openRoleSetNameView: function openRoleSetNameView(status) {
|
var self = this;
|
|
if (status == true) {
|
if (self.role_setname_new == null) {
|
var RoleSetNameView = require("role_setname_window");
|
|
self.role_setname_new = new RoleSetNameView();
|
}
|
|
self.role_setname_new.open();
|
} else {
|
if (self.role_setname_new != null) {
|
self.role_setname_new.close();
|
self.role_setname_new = null;
|
}
|
}
|
},
|
getRandomName: function getRandomName(sex) {
|
sex = sex || 1;
|
var randomName = "";
|
|
for (var i in Config.random_name_data.data_list) {
|
var config = Config.random_name_data.data_list[i] || {}; // -- 取出所有符合性别要求的名称
|
|
var temp_data = [];
|
|
for (var k = 0; k < config.length; ++k) {
|
var v = config[k];
|
|
if (v && (v.sex == sex || v.sex == 0)) {
|
temp_data.push(v);
|
}
|
}
|
|
var random_data = temp_data[~~(Math.random() * temp_data.length)] || [];
|
randomName = randomName + (random_data.name || "");
|
}
|
|
return randomName;
|
},
|
// --[[活动资产推送]] --登陆的时候推送
|
handle10350: function handle10350(data) {
|
this.model.initRoleActionAssetsData(data.holiday_assets, false);
|
},
|
handle10351: function handle10351(data) {
|
this.model.initRoleActionAssetsData(data.holiday_assets, true);
|
},
|
// --打开举报界面
|
openRoleReportedPanel: function openRoleReportedPanel(status, rid, srv_id, play_name) {
|
var self = this;
|
|
if (status == true) {
|
if (self.role_reported_panel == null) {
|
var RoleReportedWindow = require("role_reported_window");
|
|
self.role_reported_panel = new RoleReportedWindow();
|
}
|
|
self.role_reported_panel.open({
|
rid: rid,
|
srv_id: srv_id,
|
play_name: play_name
|
});
|
} else {
|
if (self.role_reported_panel != null) {
|
self.role_reported_panel.close();
|
self.role_reported_panel = null;
|
}
|
}
|
},
|
// -----------------------------------------------举报功能协议和打开方法-------------------------
|
send12770: function send12770(rid, srv_id, _type, msg, history) {
|
var protocal = {};
|
protocal.rid = rid;
|
protocal.srv_id = srv_id;
|
protocal.type = _type || 1;
|
protocal.msg = msg || "";
|
protocal.history = history || [];
|
this.SendProtocal(12770, protocal);
|
},
|
send12771: function send12771(rid, srv_id) {
|
var protocal = {};
|
protocal.rid = rid;
|
protocal.srv_id = srv_id;
|
this.SendProtocal(12771, protocal);
|
},
|
handle12770: function handle12770(data) {
|
message(data.msg);
|
},
|
handle12771: function handle12771(data) {
|
gcore.GlobalEvent.fire(RoleEvent.ROLE_REPORTED_EVENT, data);
|
},
|
checkRoleSetNameViewIsOpen: function checkRoleSetNameViewIsOpen() {
|
if (this.role_setname_new) return true;
|
return false;
|
},
|
on10306: function on10306(data) {
|
var role = this.getRoleVo();
|
role.setPower(data.power);
|
role.setMaxPower(data.max_power);
|
},
|
getApkData: function getApkData() {
|
if (this.apk_data) {
|
return this.apk_data;
|
}
|
},
|
handle10905: function handle10905(data) {
|
this.model.setWorldLev(data.world_lev);
|
},
|
//成长之路---------
|
send25830: function send25830(start, num) {
|
var protocal = {};
|
protocal.start = start;
|
protocal.num = num;
|
this.SendProtocal(25830, protocal);
|
},
|
handle25830: function handle25830(data) {
|
cc.log("25830", data); //num等于1是计算红点用途
|
|
if (data.num == 1) {} // data.is_redpoint = this.model.checkGrowthWayRedPoint(data);
|
// this.model.setGrowthWayData(data);
|
|
},
|
//成长之路分享
|
send25831: function send25831(channel) {
|
var protocal = {};
|
protocal.channel = channel;
|
this.SendProtocal(25831, protocal);
|
},
|
handle25831: function handle25831(data) {
|
cc.log("25831", data);
|
},
|
//查看成长之路分享
|
send25832: function send25832(rid, srv_id, start, num) {
|
var protocal = {};
|
protocal.rid = rid;
|
protocal.srv_id = srv_id;
|
protocal.start = start;
|
protocal.num = num;
|
this.SendProtocal(25832, protocal);
|
},
|
handle25832: function handle25832(data) {
|
cc.log("25832", data);
|
},
|
//角色是否第一次创建
|
isfirstRole: function isfirstRole() {
|
var role_vo = this.getRoleVo();
|
if (role_vo && role_vo.sex == 2) return true;
|
return false;
|
}
|
});
|
module.exports = RoleController;
|
|
cc._RF.pop();
|