源战役客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 

1091 行
44 KiB

require("game.proto.110.Require110")
require("game.chat.ChatModel")
require("game.chat.TV")
require("game.chat.ChatView")
require("game.chat.ChatItem")
require("game.chat.ChatBarBtn")
require("game.chat.HornView")
require("game.chat.IndividuationView")
require("game.chat.ChannelSettingView")
require("game.chat.VoiceVo")
require("game.chat.ChatVoiceManager")
require("game.chat.CecretView")
require("game.chat.FaceItem")
require("game.chat.TextFaceItem")
require("game.chat.CecretChatItem")
require("game.chat.HistroyItem")
require("game.chat.PartnerShowItem")
require("game.chat.EquipShowItem")
require("game.chat.CecretShowItem")
require("game.chat.ChatBagView")
require("game.chat.ChatCustomTextView")
require("game.chat.HistoryTextItem")
require("game.chat.ChatChannelToggleItem")
ChatController = ChatController or BaseClass(BaseController)
local table_insert = table.insert
function ChatController:__init()
ChatController.Instance = self
self.model = ChatModel:getInstance()
self:RegisterProtocals()
self:InitEvent()
end
function ChatController:RegisterProtocals()
self:RegisterProtocal(11000, "on11000")
self:RegisterProtocal(11001, "on11001")
self:RegisterProtocal(11002, "on11002")
self:RegisterProtocal(11102, "on11102")
self:RegisterProtocal(11003, "on11003")
self:RegisterProtocal(11004, "on11004")
self:RegisterProtocal(11005, "on11005")
self:RegisterProtocal(11010, "on11010")
self:RegisterProtocal(11011, "on11011")
self:RegisterProtocal(11013, "on11013")
self:RegisterProtocal(11016, "on11016")
self:RegisterProtocal(11017, "on11017")
self:RegisterProtocal(11020, "on11020")
self:RegisterProtocal(11021, "on11021")
self:RegisterProtocal(11050, "on11050")
self:RegisterProtocal(11014, "on11014")
self:RegisterProtocal(11060, "on11060")
self:RegisterProtocal(11061, "on11061")
self:RegisterProtocal(11063, "on11063")
self:RegisterProtocal(11022, "on11022") --社团求助
self:RegisterProtocal(11046, "on11046")
self:RegisterProtocal(11064, "on11064")--通用怪物AI警戒传闻
self:RegisterProtocal(11066, "on11066")--屏蔽操作
self:RegisterProtocal(11065, "on11065")--屏蔽列表
self:RegisterProtocal(11067, "on11067")-- 剧情气泡推送
self:RegisterProtocal(11023, "on11023") --模拟聊天缓存
self:RegisterProtocal(11091, "on11091") --更新通知
end
--公告
function ChatController:on11050()
local vo = SCMD11050.New(true)
self.model:StartGongGaoList(vo)
end
--物品不够的错误码
function ChatController:on11000()
local vo = SCMD11000.New(true)
if vo then
ErrorCodeShow(vo.error_code)
end
end
--通用文字聊天
function ChatController:on11001()
local vo = SCMD11001.New(true)
--if vo.result == 2 then return end -- 有些tips各种格式都有,先开出
local is_in_shield_list = SocialityModel:getInstance():IsRelaviveType(vo.player_id,Config.ConfigSocial.RelativeType.black)
if is_in_shield_list then--屏蔽掉
return
end
for k,v in pairs(self.model.limit_way_list) do
if v == ChatModel.LIMIY_WAY.BABY then-- and vo.channel == ChatModel.CHANNEL_CSCITY then
local x_s,x_end = string.find(vo.msg,"@showbaby@")
if x_end and x_end > 0 then
return
end
end
if v == ChatModel.LIMIY_WAY.CHAT then--then--and vo.channel == ChatModel.CHANNEL_CSCITY then
local showbaby_s,showbaby_end = string.find(vo.msg,"@showbaby@")
local team_s,team_end = string.find(vo.msg,"@team@")
if not showbaby_s and not team_s then
return
end
end
if v == ChatModel.LIMIY_WAY.RECRUIT then--and vo.channel == ChatModel.CHANNEL_CSCITY then
local team_s,team_end = string.find(vo.msg,"@team@")
-- print("============>>> YiRan:ChatController [start:95]team_end:", team_end,"team_s:",team_s)
if team_end and team_end > 0 then
return
end
end
end
if vo.channel == ChatModel.CHANNEL_BARRAGE then--弹幕不走聊天框
SpiritWarModel:getInstance():TryAddDanMu(vo)
DiamondFightModel:getInstance():TryAddDanMu(vo)
else
if vo.channel == ChatModel.CHANNEL_GUILDTV then--如果是跑马频道的消息 要先做个拼接
vo.guild_txt = vo.name..""..vo.msg
vo.length = CalStringTrueLength(vo.guild_txt) + 0.5--算出字符长度(固定有个0.5占位的中文冒号,应该当中文字符)
--以下加入弹幕中
if GuildTVModel:GetInstance().can_fire_TV_barrage then--打开了弹幕界面才能开始发弹幕
local data = {
name = vo.name,
id = vo.role_id,
time = vo.time,
}
data.content = vo.msg
GuildTVModel:GetInstance():AddGuildTVBarrageMessage(data)
end
end
vo.iType = ChatModel.MSG_TYPE.TEXT --信息的种类是消息非语音
self.model:AddMsg(vo) --
self.model:Fire(ChatModel.CHANGE_CHANNEL_SEND_INTERVAL, vo)
self.model:Fire(ChatModel.UPDATE_SEND_TIME)
self.model:AddMainRoleChatContent(vo.msg, vo.player_id)
end
end
--通用文字私聊
function ChatController:on11003()
--[[
channel:int8 // 频道
role_id:int64 // 玩家id
figure:rec_figure // 形象数据
auto_id:int32 // 自增id
receive_id:int32 // 接受者id
voice_text:string // 语音文字内容
voice_msg_time:int16 // 语音时间(秒)
]]
local scmd = {}
local channel = self:ReadFmt("c")
local ser_id = UserMsgAdapter.ReadFmt("h")
local ser_num = UserMsgAdapter.ReadFmt("h")
local ser_name = UserMsgAdapter.ReadFmt("s")
-- if role_id == RoleManager:getInstance():GetMainRoleVo().role_id then
-- return
-- end
scmd.player_list = {}
local figure = {}
local alength = self:ReadFmt("h")
for i = 1, alength do
local data = {player_id = self:ReadFmt("l")}
FigureProtoVo.ReadFmt(data)
table.insert(scmd.player_list, data)
end
local data_ver, voice_id, receive_id, voice_text, voice_msg_time, send_time = self:ReadFmt("lllshi")
local lv_rank, combat_rank = self:ReadFmt("cc")
local mainRoleVo = RoleManager:getInstance():GetMainRoleVo()
scmd.iType = ChatModel.MSG_TYPE.VOICE
scmd.voice_id = voice_id
scmd.length = voice_msg_time
scmd.channel = channel
scmd.ser_id = ser_id
scmd.ser_name = ser_name
scmd.player_id = scmd.player_list[1].player_id
scmd.msg = voice_text or ""
scmd.args = ""
scmd.result = 0
scmd.time = send_time
scmd.data_ver = data_ver
scmd.ser_num = ser_num
scmd.lv_rank = lv_rank
scmd.combat_rank = combat_rank
if receive_id == 0 then
setmetatable(scmd, {__index = scmd.player_list[1]})
end
local engine_version = tonumber(AppConst.EnglineVer)
if engine_version < scmd.data_ver and scmd.data_ver < 34 then
return
else
ChatVoiceManager:getInstance():SetVoiceVersion(scmd.voice_id, scmd.data_ver)
end
local is_in_shield_list = SocialityModel:getInstance():IsRelaviveType(scmd.player_id,Config.ConfigSocial.RelativeType.black)
if is_in_shield_list then--黑名单屏蔽掉
return
end
local catch = not self.model:AddMsg(scmd)
self.model:Fire(ChatModel.CHANGE_CHANNEL_SEND_INTERVAL, scmd)
self.model:Fire(ChatModel.UPDATE_SEND_TIME)
self.model:AddMainRoleChatContent(scmd.msg, scmd.player_id)
if catch then return end
local subType = SettingModel.C2T[channel]
local autoPlay = (subType == nil) or (SettingModel:getInstance():GetSettingInfo(SettingModel.TYPE.VOICE, subType) == 1)
-- local key = GameSettingManager.blockChannel[channel]
-- local has_block = GameSettingManager:getInstance():GetBlockProperty(key) -- 检查语音自动播放屏蔽
local has_block = (lua_settingM:GetBlockProperty("chatVoice") == true) -- 检查语音自动播放屏蔽
if autoPlay and not has_block then
if SettingModel:getInstance():GetSettingInfo(SettingModel.TYPE.VOICE, SettingModel.SUBTYPE.AUTOPLAY) == 1 then
local wifiState = Application.internetReachability == UnityEngine.NetworkReachability.IntToEnum(2)
if wifiState then
if not ChatVoiceManager:getInstance():GetVoice(scmd.voice_id) then
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11004, scmd.voice_id, scmd.player_id, scmd.time, "")
else
ChatVoiceManager:getInstance():PlayVoice(scmd.voice_id)
end
end
else
if not ChatVoiceManager:getInstance():GetVoice(scmd.voice_id) then
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11004, scmd.voice_id, scmd.player_id, scmd.time, "")
else
ChatVoiceManager:getInstance():PlayVoice(scmd.voice_id)
end
end
end
-- self.model:AddMsg(scmd)
--print("channel, role_id, voice_msg_time, math.floor(tk_time), ticket =" , channel, role_id, math.floor(voice_msg_time), voice_text, voice_id)
end
--发送语音和语音文字信息
function ChatController:on11004()
--[[
auto_id:int32 // 自增id
data_send:byte32 // 语音内容
]]
local erroCode = self:ReadFmt("i")
local voice_id = self:ReadFmt("l")
local voice_data = self:ReadFmt("B")
if erroCode ~= 1 then
ErrorCodeShow(erroCode)
return
end
ChatVoiceManager:getInstance():AddVoiceData(voice_id, voice_data)
ChatVoiceManager:getInstance():PushPlay(voice_id)
end
function ChatController:on11005()
local scmd = SCMD11005.New(true)
if scmd.error_code ~= 1 then
ErrorCodeShow(scmd.error_code)
end
end
--缓存
function ChatController:on11010()
local vo = SCMD11010.New(true)
if vo and vo.cache_list and vo.cache_list[1] then
self.model.all_chat_list[vo.cache_list[1].channel] = nil
end
if vo and vo.cache_list and #vo.cache_list > 0 then --在这防止多次添加
if vo.cache_list[1].channel == 1 then -- 世界频道的话需要插入缓存的假数据
local list = self.model:GetAiMsgList() --插入模拟对话的
if list then
-- print("============>>> YiRan:ChatController [start:255] #vo.cache_list[1]:",#vo.cache_list,"#lis:t",#list)
for k,v in pairs(list) do
table.insert(vo.cache_list,v)
end
--print("============>>> YiRan:ChatController [start:255] #vo.cache_list[1]:",#vo.cache_list,"#lis:t",#list)
end
end
local function sort_func(a, b)
return a.time > b.time
end
table.sort( vo.cache_list, sort_func )
end
for i = 1, #vo.cache_list do
if vo.cache_list[i].result ~= 2 then
------陌生人离线私聊的特殊处理
if vo.cache_list[i].channel == 6 then
--如果是私聊并且对方不在黑名单中不在最近联系人列表中时候,先把他加到最近联系人列表
if vo.cache_list[i].player_list[1].player_id ~= RoleManager.Instance.mainRoleInfo.role_id and
not SocialityModel:getInstance():IsRelaviveType(vo.cache_list[i].player_list[1].player_id,Config.ConfigSocial.RelativeType.recent) and
not SocialityModel:getInstance():IsRelaviveType(vo.cache_list[i].player_list[1].player_id,Config.ConfigSocial.RelativeType.black) then
SocialityModel:getInstance():Fire(SocialityModel.REQUEST_CCMD_EVENT,14020,vo.cache_list[i].player_list[1].player_id)
end
self.model:SetPriateChatInfo(vo.cache_list[i])--存储私聊对象的消息
end
------
vo.cache_list[i].iType = ChatModel.MSG_TYPE.TEXT
self.model:DealWithCacheMsg(vo.cache_list[i])
end
end
--添加进聊天框的顺序要反过来
if self.cache_msg_list == nil then
self.cache_msg_list = {}
end
for i = #vo.cache_list, 1, -1 do
if vo.cache_list[i].result ~= 2 then
-- self.model:AddMsg(vo.cache_list[i])
local is_in_shield_list = SocialityModel:getInstance():IsRelaviveType(vo.cache_list[i].player_list[1].player_id,Config.ConfigSocial.RelativeType.black)
if not is_in_shield_list then--屏蔽的不需要缓存
self.model:AddMsg(vo.cache_list[i])
end
end
end
self.model.require_11010_times = self.model.require_11010_times - 1
if self.model.require_11010_times <= 0 then
self.model:Fire(ChatModel.INIT_FIRST_GAME_CHAT_DATA)
end
end
function ChatController:on11011()
local vo = SCMD11011.New(true)
self.model:SetCrossChatTime(vo.count)
end
--更新通知
function ChatController:on11091( )
local scmd = SCMD11091.New(true)
self.model:SetClientUpdateInfo(scmd)
local tb = {type = Config.ConfigMainIcon.TipType.client_update}
MsgManager:getInstance():Add(tb)
end
function ChatController:on11022()
local vo = SCMD11022.New(true)
end
--私聊的多加了一个figure,私聊会发送到这里
function ChatController:on11002(vo)
local vo = SCMD11002.New(true)
local is_in_shield_list = SocialityModel:getInstance():IsRelaviveType(vo.player_list[1].player_id,Config.ConfigSocial.RelativeType.black)
if is_in_shield_list then--屏蔽掉
return
end
--不在最近联系人列表中人发来消息时加入最近联系人列表
if vo.player_list[1].player_id ~= RoleManager.Instance.mainRoleInfo.role_id and
not SocialityModel:getInstance():IsRelaviveType(vo.player_list[1].player_id,Config.ConfigSocial.RelativeType.recent) then
SocialityModel:getInstance():Fire(SocialityModel.REQUEST_CCMD_EVENT,14020,vo.player_list[1].player_id)
end
vo.iType = ChatModel.MSG_TYPE.TEXT
self.model:AddMsg(vo)
self.model:Fire(ChatModel.CHANGE_CHANNEL_SEND_INTERVAL, vo)
self.model:Fire(ChatModel.UPDATE_SEND_TIME)
self.model:AddMainRoleChatContent(vo.msg, vo.player_id)
local player_id = vo.player_list[1].player_id --取出私聊对象的id
if player_id ~= RoleManager.Instance.mainRoleInfo.role_id then
--收到私聊消息后更新和该好友的最后私聊时间
SocialityModel:getInstance():UpdateLastChatTime(player_id,vo.time)
self.model:SetChatInfo(true,vo)
self.model:SetPriateChatInfo(vo)--存储私聊对象的消息
SocialityModel:getInstance():Fire(SocialityModel.REFRESH_SUB_BTN_RED)--刷新subBtn红点
GlobalEventSystem:Fire(EventName.REFRESH_SOCIAL_RED_DOT)--更新外部红点
end
end
--½ÓÊÕϵͳÐÅÏ¢
function ChatController:on11060()
local scmd = SCMD11060.New(true)
if scmd.type == 2 then
if EmpowerModel:GetInstance():GetIsShowingGameView() and not EmpowerModel:GetInstance():GetIsShowingShopView() then
return
end
if GoodsModel:getInstance():CheckCanFlyGood() then--检查飞道具图标的条件
MainUIModel:getInstance():AddFloatInfo(scmd.goods_list)
if SceneManager:getInstance():IsExpDun() then--如果是经验副本并且是经验值道具
local goods_list = {}
for i,v in ipairs(scmd.goods_list) do
if v.goods_type_id == 100007 then
goods_list[#goods_list + 1] = v.goods_type_id
end
end
if #goods_list > 0 then
MainUIModel:getInstance():PlayGoodsFlyList(goods_list)
end
end
end
end
local function show(str)
if scmd.type == 1 then
if not GiftModel:getInstance():getIsOpenView() then--and not TreasureHuntModel:getInstance().bool_hunting
-- and not CustomActivityModel:getInstance():getIsThrowEgg() then--礼包界面|寻宝过程|砸蛋过程中不显示提示
-- Message.show(str)
end
elseif scmd.type == 2 then
ChatModel:getInstance():AddInfoToChatView(str, ChatModel.CHANNEL_SYSTEM, self.model:GetGoodsTipNum() or 0)
elseif scmd.type == 3 then
-- Message.show(str)
ChatModel:getInstance():AddInfoToChatView(str, ChatModel.CHANNEL_SYSTEM, self.model:GetGoodsTipNum() or 0)
end
end
local gvo = nil
for i, v in ipairs(scmd.goods_list) do
gvo = GoodsModel:getInstance():GetGoodsBasicByTypeId(v.goods_type_id)
if gvo then
local name = gvo.goods_name
if gvo.type == 11 and (gvo.subtype == 10 or gvo.subtype == 11) then
local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(gvo.type_id, RoleManager.Instance.mainRoleInfo.career, gvo.color)
name = _name
end
-- str = "获得 <color="..WordManager.GetGoodsColor(gvo.color) .. ">" .. name .. "x" .. v.num .. "</color>"
local str = "获得 <color="..WordManager.GetGoodsColor(gvo.color) .. ">" .. name .. "x" .. v.num .. "</color>" --改成用传闻面板特殊的颜色
show(str)
-- Message.show(str)
-- ChatModel:getInstance():AddInfoToChatView(str,ChatModel.CHANNEL_SYSTEM,1)
end
end
-- GoodsModel:getInstance():Fire(GoodsModel.GET_A_GOODS)
end
--获得物品显示信息在右下角提示框内
function ChatController:on11061()
local scmd = SCMD11061.New(true)
local gvo = nil
for i, v in ipairs(scmd.goods_list) do
-- local typeId = v.typeId
-- if v.style ~= 0 then
-- typeId = GoodsModel:getInstance():GetMappingTypeId(v.style)
-- end
local typeId, lock = GoodsModel:getInstance():GetMappingTypeId(tonumber(v.style), tonumber(v.typeId))
gvo = GoodsModel:getInstance():GetGoodsBasicByTypeId(typeId)
if gvo then
local name = gvo.goods_name
if gvo.type == 11 and (gvo.subtype == 10 or gvo.subtype == 11) then
local type_id, _name, icon = EquipModel:getInstance():GetIdentifyGoodsNameAndIcon(gvo.type_id, RoleManager.Instance.mainRoleInfo.career, gvo.color)
name = _name
end
local str = ""
if v.count > 1 then
str = "获得 <color='#"..WordManager.GetGoodsColor(gvo.color) .. "'>" .. name .. "x" .. v.count .. "</color>"
else
str = "获得 <color='#"..WordManager.GetGoodsColor(gvo.color) .. "'>" .. name .. "</color>"
end
Message.show(str)
end
end
-- GoodsModel:getInstance():Fire(GoodsModel.GET_A_GOODS)
end
--获得物品显示信息在右下角提示框内
function ChatController:on11016()
local vo = SCMD11016.New(true)
if vo then
--社团申请列表状态
if vo.module_id == 400 and vo.type == ChatModel.RedPointType.GUILD_APPLY_LIST then
-- vo.num 在社团类型中对应【申请的职位】,0代表入团,其他代表职位
GuildModel:getInstance():SetApplyRedPointState(vo.num)
-- GuildModel:getInstance():CheckGuildRedDot(Config.ConfigGuild.TabId.List, true)
-- GlobalEventSystem:Fire(EventName.SHOW_FUNCTION_RED_POINT, 400, GuildModel:getInstance():CheckGuildRedDot())
-- elseif vo.module_id == 400 and vo.type == 2 then
-- GlobalEventSystem:Fire(EventName.SHOW_FUNCTION_RED_POINT, 400, true)
elseif vo.module_id == 339 and vo.type == 1 then
-- local tb = {}
-- tb.type = Config.ConfigMainIcon.TipType.guild_redpacket
-- tb.zoom = true
-- MsgManager:getInstance():Add(tb)
elseif vo.module_id == 223 and vo.type == 1 then --鲜花
local tb = {}
tb.type = Config.ConfigMainIcon.TipType.flower
MsgManager:getInstance():Add(tb)
GlobalEventSystem:Fire(EventName.REFRESH_SOCIAL_RED_DOT)
elseif vo.module_id == 441 then --激活图鉴
GlobalEventSystem:Fire(EventName.SET_ACTIVE_PIC, vo.type, vo.num)
end
GlobalEventSystem:Fire(EventName.BROADCAST_RED_POINT_STATE, vo)
end
end
--聊天频道的错误码消息
function ChatController:on11017()
local vo = SCMD11017.New(true)
--type 1只飘字 2只聊天框 3飘字加聊天框
-- PrintTable(vo)
local str = self.model:GetErrorCode(vo.error_code, vo.error_code_args)
if vo.type == 1 then
if vo.error_code == 1500098 then --返回礼包模块去处理
GiftModel:getInstance():handleGiftShowAll(vo.error_code_args)
else
Message.show(str)
end
elseif vo.type == 2 then
if vo.error_code == 6100035 then
if SceneManager.Instance:IsOutdoorScene() then
local scene_id = SceneManager.Instance:GetSceneId()
local birth_x, birth_y = SceneManager.Instance:GetSceneBirthPos()
local findVo = {type = FindVo.SCENE, sceneId = scene_id, id = 0, x = math.ceil(birth_x / SceneObj.LogicRealRatio.x), y = math.ceil(birth_y / SceneObj.LogicRealRatio.y)}
local scene_name = SceneManager.Instance:GetSceneName()
local content = string.format("<a@scene2@%s@%s@%s></a>", findVo.sceneId, findVo.x, findVo.y)
str = str .. " " .. content
end
end
self.model:AddInfoToChatView(str, ChatModel.CHANNEL_TEAM)
elseif vo.type == 3 then
Message.show(str)
self.model:AddInfoToChatView(str, ChatModel.CHANNEL_TEAM)
end
end
function ChatController:on11014()
local vo = SCMD11014.New(true)
if vo then
Message.show("发送频率过快,请销后再试...", "fault")
end
end
--广播语音文字
function ChatController:on11013()
local scmd = SCMD11013.New(true)
self.model:UpdateRegText(scmd)
if self.model.curr_channel == scmd.channel then
self.model:Fire(ChatModel.BROADCAST_VOICE_TEXT, scmd)
end
end
function ChatController:on11020()
local scmd = SCMD11020.New(true)
Message.show(scmd.content)
end
function ChatController:on11021()
local scmd = SCMD11021.New(true)
self.model:AddGmHorn(scmd)
end
function ChatController:on11046()
local scmd = SCMD11046.New(true)
for k, v in pairs(scmd.list) do
if RoleManager.Instance.mainRoleInfo.role_id ~= v.role_id then
for channel, _ in pairs(self.model.all_chat_list) do
self.model:DelMsgInChannelById(channel, v.role_id)
end
self.model:Fire(ChatModel.DEL_CHAT_ITEM, v.role_id)
end
end
--更新界面
self.model:Fire(ChatModel.REFRESH_VIEW)
self.model:Fire(ChatModel.SHOW_TAB_RED_POINT, self.model.all_chat_list_count)
SocialityModel:getInstance():Fire(SocialityModel.UPDATE_SOCIALITY_VIEW)
end
--通用播放特效
function ChatController:on11063()
local scmd = SCMD11063.New(true)
local tb = {}
tb.effect = scmd.effect
SocialityModel:getInstance():PlayFlowerEffect(tb)
end
--通用怪物AI警戒传闻
function ChatController:on11064()
local scmd = SCMD11064.New(true)
local config = Config.Languageextra
local key = scmd.module_id .. "@" .. scmd.id
if config[key] and config[key].content then
local str = ChuanWenManager:getInstance():FormatColorTag2(config[key].content, true)
local data =
{
head_type = 1000,
desc = str,
head_name = scmd.name or "",
hide_time = 8,
dalay_time = 1,
is_task_type = true,
}
GlobalEventSystem:Fire(EventName.SHOW_COM_DIALOGUE_SHOW_VIEW,data)
end
end
function ChatController:on11065( )--屏蔽列表
local scmd = SCMD11065.New(true)
for k,v in pairs(scmd.figure_list) do
v.role_name = v.name
v.vip = v.vip_flag
v.lv = v.level
end
SocialityModel:getInstance():SetRelativeInfo(Config.ConfigSocial.RelativeType.black,scmd.figure_list)
-- if not self.model.request_cache then--检测聊天缓存
-- self.model.request_cache = true
-- if RoleManager.Instance.mainRoleInfo.guild_id > 0 then
-- self.model:Fire(ChatModel.REQUEST_CACHE_EVENT, ChatModel.CHANNEL_GUILD)
-- end
-- self.model:Fire(ChatModel.REQUEST_CACHE_EVENT, ChatModel.CHANNEL_WORLD)
-- self.model:Fire(ChatModel.REQUEST_CACHE_EVENT, ChatModel.CHANNEL_CECRET)
-- end
end
function ChatController:on11067( )--屏蔽列表
local scmd = SCMD11067.New(true)
SocialityModel:getInstance():Fire(SocialityModel.BROADCAST_MIDDLE_MESSAGE, scmd.module_id, scmd.id)
end
function ChatController:on11066( )--屏蔽操作
local scmd = SCMD11066.New(true)
if scmd.errcode == 1 then
Message.show("操作成功", "success")
scmd.role_name = scmd.name
scmd.vip = scmd.vip_flag
scmd.lv = scmd.level
SocialityModel:getInstance():UpdateShieldList(scmd.type,scmd)
SocialityModel:getInstance():Fire(SocialityModel.REQUEST_SOCIAL_LIST)
else
ErrorCodeShow(scmd.errcode)
end
end
--########### 模拟聊天缓存 ##############
--protocol=11023
--{
-- s2c{
-- cache_list:array{
-- name:string
-- sex:int8
-- vip:int8
-- picture:int32
-- msg:string // 数据
-- time:int32 // 服务器时间戳
-- }
-- }
--}
function ChatController:on11023( )--
local scmd = SCMD11023.New(true)
-- if scmd.errcode == 1 then
-- print("=============>>> YiRan:ChatController [start:537] SCMD11023------------------------------------------")
-- PrintTable(scmd)
-- print("=============>>> YiRan:ChatController [end] ------------------------------------------")
self.model:SetVo11023(scmd)
-- else
-- ErrorCodeShow(scmd.errcode)
----end
end
function ChatController:InitEvent()
local onChangeAccount = function ()
self.model:ClearGongGaoTimer()
self:StopLearnHorn()
self.model:Fire(ChatModel.CLEAR_DATA)--清除主聊天界面的item
self.model:InitLoginTime()
end
GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT, onChangeAccount)
GlobalEventSystem:Bind(EventName.CHANGE_ROLE, onChangeAccount)
local function onChangeLevel( )
local role_lv = RoleManager.Instance:GetMainRoleLevel2()
--if self.need_reset_lv_list[role_lv] then
-- self:StarPlayTeachingHorn()
--end
end
RoleManager.Instance.mainRoleInfo:Bind(EventName.CHANGE_LEVEL, onChangeLevel)
--切换账号
local gameStartHandler = function ()
self.model:Fire(ChatModel.CLEAR_DATA)--清除主聊天界面的item
if self.ChatView then
self.ChatView:Close()
end
self.model:Clear()
self.cache_msg_list = {}
-- lua_settingM:LoadChatVoiceSetting()
self:SendFmtToGame(11050)--请求11050
self:SendFmtToGame(11065)--请求屏蔽列表
--self:StarPlayTeachingHorn()
self.model:InitLoginTime()
end
GlobalEventSystem:Bind(EventName.GAME_START, gameStartHandler)
local function onSendMsgHandler(channel, content, target_id, args, is_mySelf_send)--is_mySelf_send是否是玩家自己发的如果是就是1
-- print('Cat:ChatController.lua[484] channel, content, target_id, args', channel, content, target_id, args)
is_mySelf_send = is_mySelf_send or ChatModel.CHAT_COMMON_TYPE.COMMON--默认发0告诉服务端是玩家正常发言
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11001, channel, content, target_id, args, is_mySelf_send)
end
self.model:Bind(ChatModel.SEND_MSG, onSendMsgHandler)
local function onShowGonggaoHandler(info)
if info then
local vo = {channel = ChatModel.CHANNEL_SYSTEM, time = Status.NowTime, msg = info.content}
vo.iType = ChatModel.MSG_TYPE.TEXT
self.model:AddMsg(vo)
end
end
GlobalEventSystem:Bind(EventName.SHOW_GONGGAO, onShowGonggaoHandler)
local function onShowChuanwenHandler(content, chuanwen_cfg, scmd)
if chuanwen_cfg.subtype ~= 0 and content then
-- local tmpChannel = Config.ConfigChat.channel_level[chuanwen_cfg.subtype].channel
-- local vo = {channel = ChatModel.CHANNEL_SYSTEM,time = Status.NowTime,msg = content}
-- channel = tmpChannel
-- local vo = {channel=chuanwen_cfg.subtype, time=Status.NowTime, msg=content,showtype=ChatModel.CHANNEL_SYSTEM, tip=chuanwen_cfg.tip}
-- self.model:AddMsg(vo)
scmd.channel = chuanwen_cfg.subtype
-- scmd.time = Status.NowTime
scmd.time = TimeUtil:getServerTime()
scmd.msg = content
if not scmd.type or scmd.type == 11015 then
scmd.showtype = ChatModel.CHANNEL_SYSTEM
end
-- scmd.tip = chuanwen_cfg.tip -- 这会增添了自己的tip
scmd.iType = ChatModel.MSG_TYPE.TEXT
self.model:AddMsg(scmd)
end
end
GlobalEventSystem:Bind(EventName.SHOW_CHUANWEN, onShowChuanwenHandler)
--通用聊天
local function onRequestHandler(...)
local args_list = {...}
if args_list[1] == 11001 then
local channel = args_list[2]
local receiveId = args_list[4] or 0
local data = args_list[3]
local args = args_list[5] or ""
local tk_time = Status.NowTime
local ticket = "ticket"
local is_mySelf_send = args_list[6] or ChatModel.CHAT_COMMON_TYPE.COMMON
self:SendFmtToGame(11001, "clssisc", channel, receiveId, data, args, math.floor(tk_time), ticket, is_mySelf_send)
print("发送聊天:", channel, receiveId, data, args, math.floor(tk_time), ticket, is_mySelf_send)
elseif args_list[1] == 11003 then
--[[
channel:int8 // 频道
receive_id:int64 // 接受者id
voice_msg_time:int32 // 语音时间(秒)
tk_time:int32 // 时间戳
ticket:string // 加密字符
data_send:byte32 // 语音内容
voice_text:string // 语音文字内容
auto_id:int32 // 自增id
is_end:int8 // 是否完成语音信息发送(1:完成,2:未完成)CMD11012返回1后继续发送语音剩余部分
]]
local channel = args_list[2]
local receive_id = args_list[3] or 0
local voice_msg_time = args_list[4]
local tk_time = Status.NowTime
local ticket = "ticket"
local data_send = args_list[5]
local voice_text = args_list[6] or ""
local auto_id = args_list[7]
local is_end = 0
local voiceLength = 0
for i = 0, data_send.Length - 1 do
if i == data_send.Length - 1 then is_end = 1 end
UserMsgAdapter.WriteBegin(11003)
UserMsgAdapter.WriteFMT("cliis", channel, receive_id, math.floor(voice_msg_time), math.floor(tk_time), ticket)
UserMsgAdapter.WriteFMT("B", data_send[i])
UserMsgAdapter.WriteFMT("slc", voice_text, auto_id, is_end)
UserMsgAdapter.SendToGame()
voiceLength = voiceLength + data_send[i].Length
end
Debugger.Log("Voice Data Size is "..voiceLength)
--print("channel, receive_id, voice_msg_time, math.floor(tk_time), ticket =" , channel, receive_id, math.floor(voice_msg_time), math.floor(tk_time), ticket, voice_text, auto_id, is_end, data_send.Length)
elseif args_list[1] == 11004 then
--[[
auto_id:int32 // 自增id
player_id:int64 // 语音信息发送者id
tk_time:int32 // unix时间戳
ticket:string // 加密字符
]]
local auto_id = args_list[2]
local player_id = args_list[3]
local voice_msg_time = args_list[4]
local ticket = "ticket"
UserMsgAdapter.WriteBegin(11004)
UserMsgAdapter.WriteFMT("llis", auto_id, player_id, math.floor(voice_msg_time), ticket)
UserMsgAdapter.SendToGame()
--print("auto_id, player_id, voice_msg_time, ticket =" , auto_id, player_id, math.floor(voice_msg_time),ticket)
elseif args_list[1] == 11005 then
self:SendFmtToGame(11005, "clls", args_list[2], args_list[3], args_list[4], args_list[5])
elseif args_list[1] == 11022 then
self:SendFmtToGame(args_list[1], "cls", args_list[2], args_list[3], args_list[4])
elseif args_list[1] == 11011 then
self:SendFmtToGame(args_list[1], "c", args_list[2])
end
end
self.model:Bind(ChatModel.REQUEST_CCMD_EVENT, onRequestHandler)
local function onOpenChatView(channel)
if self.ChatView == nil then
self.ChatView = ChatView.New()
end
if not self.ChatView:HasOpen() then
self.ChatView:Open(channel)
end
end
GlobalEventSystem:Bind(EventName.OPEN_CHAT_VIEW, onOpenChatView)
local function onCloseChatView()
if self.ChatView and self.ChatView:HasOpen() then
self.ChatView:Close()
end
end
GlobalEventSystem:Bind(EventName.CLOSE_CHAT_VIEW, onCloseChatView)
--打开私聊一对一 用于从其他模块进入聊天
local function onOpenCecretChannel(key_id, name)
if self.ChatView == nil then
self.ChatView = ChatView.New()
local index = self.model:GetTabIndexWithChannel(ChatModel.CHANNEL_CECRET)
self.ChatView:Open(index)
end
if not self.ChatView.is_moving and not self.ChatView:HasOpen() then
local index = self.model:GetTabIndexWithChannel(ChatModel.CHANNEL_CECRET)
self.ChatView:Open(index)
end
self.ChatView:OpenCecretChannel(key_id, name)
end
GlobalEventSystem:Bind(EventName.OPEN_CHAT_CECRET_CHANNEL, onOpenCecretChannel)
local function onOpenHornView()
if self.HornView == nil then
self.HornView = HornView.New()
end
if self.HornView:HasOpen() then
self.HornView:Close()
else
self.HornView:Open()
end
end
GlobalEventSystem:Bind(EventName.OPEN_HORN_VIEW, onOpenHornView)
local function onOpenIndividuationView(bar_index, pos_x, pos_y, is_close_after_sendpos, chating_key_id,is_reset_anchor, scale_num)
if self.IndividuationView == nil then
self.IndividuationView = IndividuationView.New()
end
if self.IndividuationView:HasOpen() then
self.IndividuationView:Close()
else
self.IndividuationView:Open(bar_index, pos_x, pos_y, is_close_after_sendpos, chating_key_id, is_reset_anchor, scale_num)
end
end
GlobalEventSystem:Bind(EventName.OPEN_INDIVIDUATION_VIEW, onOpenIndividuationView)
local function onCloseIndividuationView()
if self.IndividuationView and self.IndividuationView:HasOpen() then
self.IndividuationView:Close()
end
end
GlobalEventSystem:Bind(EventName.CLOSE_INDIVIDUATION_VIEW, onCloseIndividuationView)
local function onOpenChatBagView()
if self.ChatBagView == nil then
self.ChatBagView = ChatBagView.New()
end
self.ChatBagView:Open()
-- if self.ChatBagView:HasOpen() then
-- self.ChatBagView:Close()
-- else
-- self.ChatBagView:Open()
-- end
end
GlobalEventSystem:Bind(EventName.OPEN_CHAT_BAG_VIEW, onOpenChatBagView)
local function onCloseChatBagView()
if self.ChatBagView and self.ChatBagView:HasOpen() then
self.ChatBagView:Close()
end
end
GlobalEventSystem:Bind(EventName.CLOSE_CHAT_BAG_VIEW, onCloseChatBagView)
local function onOpenChatCustomTextView(index)
if self.ChatCustomTextView == nil then
self.ChatCustomTextView = ChatCustomTextView.New()
end
if self.ChatCustomTextView:HasOpen() then
self.ChatCustomTextView:Close()
else
self.ChatCustomTextView:Open(index)
end
end
GlobalEventSystem:Bind(EventName.OPEN_CHAT_CUSTOM_TEXT_VIEW, onOpenChatCustomTextView)
-- local function onOpenChannelSettingView()
-- if self.ChannelSettingView == nil then
-- self.ChannelSettingView = ChannelSettingView.New()
-- end
-- if self.ChannelSettingView:HasOpen() then
-- self.ChannelSettingView:Close()
-- else
-- self.ChannelSettingView:Open()
-- end
-- end
-- GlobalEventSystem:Bind(EventName.OPEN_CHANNELSETTING_VIEW, onOpenChannelSettingView)
local function onRequestCacheMsg(channel)
self:SendFmtToGame(11010, "c", channel)
end
self.model:Bind(ChatModel.REQUEST_CACHE_EVENT, onRequestCacheMsg)
local function onChangeChannelSendStartTime(vo)
self.model:ChangeChannelSendStartTime(vo, Status.NowTime)
end
self.model:Bind(ChatModel.CHANGE_CHANNEL_SEND_INTERVAL, onChangeChannelSendStartTime)
-- local function onRequestWorldChatNum()
-- --请求缓存
-- if not self.model.request_cache then
-- self.model.request_cache = true
-- self.model:Fire(ChatModel.REQUEST_CACHE_EVENT, ChatModel.CHANNEL_WORLD)
-- if RoleManager.Instance.mainRoleInfo.guild_id > 0 then
-- self.model:Fire(ChatModel.REQUEST_CACHE_EVENT, ChatModel.CHANNEL_GUILD)
-- end
-- end
-- end
-- GlobalEventSystem:Bind(EventName.GAME_START, onRequestWorldChatNum)
local function onRequestRedPointState(module_id, type)
self:SendFmtToGame(11016, "hh", module_id, type)
end
GlobalEventSystem:Bind(EventName.REQUEST_RED_POINT_STATE, onRequestRedPointState)
--处理屏蔽功能11066协议的发送
local function ON_SEND_PROTOCAL( ... )
local args = {...}
if args[1] == 11065 then
elseif args[1] == 11066 then
self:SendFmtToGame(args[1], "cl", args[2],args[3])
else
self:SendFmtToGame(args[1])
end
end
self.model:Bind(ChatModel.SEND_PROTOCAL, ON_SEND_PROTOCAL)
GlobalEventSystem:Bind(ChatModel.ON_RESULT_OF_SPEECH, function(reg_txt)
reg_txt = LanguageFilter.FilterMsg(reg_txt)
self.model.reg_txt = reg_txt
if not self.model.loading_voice then
if SettingModel:getInstance():GetSettingInfo(SettingModel.TYPE.VOICE, SettingModel.SUBTYPE.TEXTONLY) == 1 then
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11001, self.model.reg_channel, reg_txt, self.model.chating_key_id or 0, "", nil, "")
else
if self.model.sendAlready then
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11005, self.model.reg_channel, self.model.reg_receive_id, self.model.voice_id, reg_txt)
else
self:SendVoice()
end
end
-- local scmd = {auto_id = self.model.voice_id, channel = self.model.reg_channel, voice_text = reg_txt}
-- self.model:UpdateRegText(scmd)
-- self.model:Fire(ChatModel.BROADCAST_VOICE_TEXT, scmd)
end
end)
GlobalEventSystem:Bind(ChatModel.ON_END_OF_SPEECH, function(data)
if self.model.end_speech_data then
if data ~= "" then
Message.show(data)
end
self.model.end_speech_data = nil
else
self.model.end_speech_data = data
end
if not self.model.loading_voice and not self.model.sendAlready then
print("tanar: ChatController [910] Bind ON_END_OF_SPEECH")
self:SendVoice()
end
end)
GlobalEventSystem:Bind(EventName.CHANGE_ACCOUNT, function()
self.model.voice_id = nil
self.model.reg_channel = nil
self.model.loading_voice = nil
self.model.end_speech_data = nil
ChatVoiceManager:getInstance():Reset()
end)
GlobalEventSystem:Bind(EventName.CHANGE_ROLE, function()
self.model.voice_id = nil
self.model.reg_channel = nil
self.model.loading_voice = nil
self.model.end_speech_data = nil
ChatVoiceManager:getInstance():Reset()
end)
local function onGuildChange()
local guild_id = RoleManager.Instance:GetMainRoleVo().guild_id
if not guild_id or guild_id == 0 then
self.model.all_chat_list[ChatModel.CHANNEL_GUILD] = nil
end
end
RoleManager:getInstance():GetMainRoleVo():BindOne("guild_id", onGuildChange)
local function onOpenLockScreenView( )
--进入省电模式关闭聊天界面
if self.ChatView then
self.ChatView:Close()
end
end
GlobalEventSystem:Bind(SceneEventType.SCREEN_BRIGHT_DEL_EVENT, onOpenLockScreenView)
end
function ChatController:SendVoice()
print("tanar: ChatController [949] =========== SendVoice")
print("tanar: [ChatController 950]=> self.model.voice_id: ",self.model.voice_id)
if self.model.voice_id and SettingModel:getInstance():GetSettingInfo(SettingModel.TYPE.VOICE, SettingModel.SUBTYPE.TEXTONLY) == 0 then
ChatVoiceManager:getInstance():AddMainRoleVoicePath(self.model.voice_id, self.model.voice_path)
local sendId = self.model.voice_id
local function onLoadCallback(voice_data, time_len)
print("tanar: [ChatController 956]=> onLoadCallback: ",self.model.reg_channel)
print("tanar: [ChatController 957]=> self.model.voice_id == sendId: ",self.model.voice_id == sendId)
if self.model.voice_id == sendId and self.model.reg_channel then
local channel = self.model.reg_channel
local receive_id = self.model.chating_key_id or 0
local voice_msg_time = math.max(1, math.floor(time_len + 0.5))
local data_send = voice_data
local voice_text
local auto_id = self.model.voice_id
if self.model.reg_txt then
voice_text = self.model.reg_txt
self.model.reg_txt = nil
else
voice_text = ""
self.model.reg_receive_id = receive_id
end
self.model.reg_txt = nil
self.model:Fire(ChatModel.REQUEST_CCMD_EVENT, 11003, channel, receive_id, voice_msg_time, data_send, voice_text, auto_id)
self.model.sendAlready = true
end
end
self.model.loading_voice = true
self.model.sendAlready = nil
ChatVoiceManager:getInstance():LoadMainRoleVoiceData(self.model.voice_id, onLoadCallback)
end
end
function ChatController:StopLearnHorn( )
if self.play_learn_id then
GlobalTimerQuest:CancelQuest(self.play_learn_id)
self.play_learn_id = nil
end
SysInfoCtrl.Instance:HideHornView(true)
end
function ChatController:StarPlayTeachingHorn( )
self.need_reset_lv_list = {} --到特定等级需要刷新
if self.play_learn_id then
GlobalTimerQuest:CancelQuest(self.play_learn_id)
self.play_learn_id = nil
end
local chuanwen_list = {}
local role_lv = RoleManager.Instance:GetMainRoleLevel2()
for _,v in pairs(Config.ConfigChat.teaching) do
if role_lv < v.start_lv then
self.need_reset_lv_list[v.start_lv] = true
end
if role_lv < v.end_lv + 1 then
self.need_reset_lv_list[v.end_lv+1] = true
end
if role_lv >= v.start_lv and role_lv <= v.end_lv then
for _,vo in pairs(v.msg_list) do
table_insert(chuanwen_list,vo)
end
end
end
local index = 1
local chuanwen_len = #chuanwen_list
if chuanwen_len > 0 then
local function onTimer( )
local cfg, scmd = {subtype = ChatModel.CHANNEL_SYSTEM} ,{}
if index > chuanwen_len then
index = 1
end
local msg = chuanwen_list[index].msg or ""
msg = Trim(msg)
index = index + 1
if msg ~= "" then
ChatModel:getInstance():DealWithHornSystemMsg({name = "系统", msg = msg,is_teaching = true}, true,true)
GlobalEventSystem:Fire(EventName.SHOW_CHUANWEN, msg, cfg, scmd)
end
end
self.play_learn_id = GlobalTimerQuest:AddPeriodQuest(onTimer,Config.ConfigChat.teachingTime)
setTimeout(onTimer,5)
end
end