BeachModel = BeachModel or BaseClass(BaseVo, true)
|
|
local BeachModel = BeachModel
|
|
|
|
BeachModel.VoiceType = { -- 喊话类型
|
|
RankOne = 1,
|
|
Vote = 2,
|
|
}
|
|
|
|
function BeachModel:__init()
|
|
BeachModel.Instance = self
|
|
self:Reset()
|
|
end
|
|
|
|
function BeachModel:Reset()
|
|
self.show_scene_left_tip = nil
|
|
self.activity_info = false
|
|
self.my_info = false
|
|
self.vote_rank_info = false
|
|
self.exp_info = 0
|
|
self.top_info = false
|
|
self.my_vote_list = {}
|
|
self.scene_friend_list = {}
|
|
-------------------------
|
|
self.talk_red_dot = false--聊天红点
|
|
self.vote_red_dot = false--投票红点
|
|
-------------------------
|
|
self.need_show_activity_tip = true
|
|
self.message_break_time = 5
|
|
self.vote_break_time = 2
|
|
self:InitRankPage( )
|
|
self:InitBeachVoiceCfg( )
|
|
end
|
|
|
|
function BeachModel:GetInstance()
|
|
if BeachModel.Instance == nil then
|
|
BeachModel.Instance = BeachModel.New()
|
|
end
|
|
return BeachModel.Instance
|
|
end
|
|
|
|
function BeachModel:getInstance()
|
|
return self:GetInstance()
|
|
end
|
|
|
|
function BeachModel:GetKeyValue( tag )
|
|
if not self.kv_conf then
|
|
self.kv_conf = {}
|
|
for k,v in pairs(Config.Beachkv) do
|
|
self.kv_conf[Trim(v.key)] = v
|
|
end
|
|
end
|
|
return tag and self.kv_conf[tag].value or false
|
|
end
|
|
|
|
--活动状态
|
|
function BeachModel:GetActivityInfo( )
|
|
return self.activity_info
|
|
end
|
|
function BeachModel:SetActivityInfo( value )
|
|
self.activity_info = value
|
|
end
|
|
function BeachModel:GetActivityIsGoing( )
|
|
local act_info = self:GetActivityInfo()
|
|
if act_info and act_info.status ~= 0 and act_info.end_time then
|
|
return act_info.end_time > TimeUtil:getServerTime()
|
|
end
|
|
return false
|
|
end
|
|
|
|
--个人信息
|
|
function BeachModel:GetMyInfo( )
|
|
return self.my_info
|
|
end
|
|
function BeachModel:SetMyInfo( value )
|
|
self.my_info = value
|
|
if not self.last_rank then -- 默认没有排名
|
|
self.last_rank = 0
|
|
end
|
|
if self.my_info.rank and self.my_info.rank == 1 and self.last_rank ~= 1 then
|
|
self:BeachSendMsg(BeachModel.VoiceType.RankOne)
|
|
end
|
|
self.last_rank = self.my_info.rank
|
|
end
|
|
function BeachModel:RefreshMyVoteNum( vote_times,has_buy_times,vote_other_time )
|
|
if self:GetMyInfo( ) then
|
|
self:GetMyInfo( ).vote_times = vote_times or self:GetMyInfo( ).vote_times
|
|
self:GetMyInfo( ).has_buy_times = has_buy_times or self:GetMyInfo( ).has_buy_times
|
|
self:GetMyInfo( ).vote_other_time = vote_other_time or self:GetMyInfo( ).vote_other_time
|
|
end
|
|
end
|
|
function BeachModel:RefreshMyExp( add_exp )
|
|
if self:GetMyInfo( ) then
|
|
self:GetMyInfo( ).acc_exp = self:GetMyInfo( ).acc_exp + add_exp
|
|
end
|
|
end
|
|
|
|
--投票排行榜
|
|
function BeachModel:GetVoteRankInfo( )
|
|
return self.vote_rank_info
|
|
end
|
|
function BeachModel:SetVoteRankInfo( value )
|
|
self.vote_rank_info = value
|
|
self.vote_rank_info.new_list = self.vote_rank_info.new_list or {}
|
|
for k,v in pairs(value.rank_list) do
|
|
self.vote_rank_info.new_list[v.rank] = v
|
|
end
|
|
for k,v in pairs(value.left_rank) do
|
|
self.vote_rank_info.new_list[v.rank] = v
|
|
end
|
|
|
|
if not self.last_rank then -- 默认没有排名
|
|
self.last_rank = 0
|
|
end
|
|
if self.vote_rank_info.self_rank and self.vote_rank_info.self_rank == 1 and self.last_rank ~= 1 then
|
|
self:BeachSendMsg(BeachModel.VoiceType.RankOne)
|
|
end
|
|
self.last_rank = self.vote_rank_info.self_rank
|
|
end
|
|
|
|
--魅力第一(舞台solo者)
|
|
function BeachModel:GetTopInfo( )
|
|
return self.top_info
|
|
end
|
|
function BeachModel:SetTopInfo( value )
|
|
self.top_info = value
|
|
end
|
|
|
|
--我的投票列表(谁投了我)
|
|
function BeachModel:GetMyVoteList( )
|
|
return self.my_vote_list or {}
|
|
end
|
|
function BeachModel:SetMyVoteList( value )
|
|
self.my_vote_list = value
|
|
end
|
|
|
|
--获取现场的好友/公会成员列表
|
|
function BeachModel:GetSceneFriendList( type_id )
|
|
return self.scene_friend_list[type_id] or {}
|
|
end
|
|
function BeachModel:SetSceneFriendList( type_id, value )
|
|
self.scene_friend_list[type_id] = value
|
|
end
|
|
|
|
function BeachModel:GetRewardConfByRank( rank )
|
|
rank = rank or 0
|
|
for k,v in pairs(Config.Beachreward) do
|
|
if rank >= v.rank_ll and rank <= v. rank_ul then
|
|
return stringtotable(v.reward)
|
|
end
|
|
end
|
|
return {}
|
|
end
|
|
|
|
function BeachModel:GetRankShowList( page)
|
|
local page = page or self:GetCurRankPage()
|
|
local start_rank = (page - 1) * BeachConst.SingleRankLength + 1
|
|
local end_rank = start_rank + 19
|
|
local rank_data = self:GetVoteRankInfo()
|
|
-------------------------
|
|
local show_data = {}
|
|
if rank_data then
|
|
-- for k,v in pairs(rank_data.rank_list) do
|
|
-- table.insert( show_data, v )
|
|
-- end
|
|
-- for k,v in pairs(rank_data.left_rank) do
|
|
-- table.insert( show_data, v )
|
|
-- end
|
|
for i=start_rank, end_rank do
|
|
if rank_data.new_list[i] then
|
|
table.insert( show_data, rank_data.new_list[i] )
|
|
end
|
|
end
|
|
if #show_data > 1 then
|
|
local function sort_call( a,b )
|
|
--从大到小
|
|
return a.rank < b.rank
|
|
end
|
|
table.sort( show_data, sort_call )
|
|
end
|
|
end
|
|
-------------------------
|
|
return show_data
|
|
end
|
|
|
|
function BeachModel:SetTalkClock()
|
|
if not self.talk_clock_Id then
|
|
self.talk_clock = self.message_break_time
|
|
local function step_method( ... )
|
|
self.talk_clock = self.talk_clock -1
|
|
if self.talk_clock <= 0 then
|
|
--倒计时结束
|
|
self:CloseTalkClock()
|
|
end
|
|
end
|
|
self.talk_clock_Id = GlobalTimerQuest:AddPeriodQuest(step_method, 1, -1)
|
|
else
|
|
-- local str = string.format("剩余CD %d 秒",self.talk_clock or 0)
|
|
local str = "发送频率过快,请稍后再试..."
|
|
Message.show(str)
|
|
end
|
|
end
|
|
|
|
function BeachModel:CloseTalkClock()
|
|
self.talk_clock = 0
|
|
if self.talk_clock_Id then
|
|
GlobalTimerQuest:CancelQuest(self.talk_clock_Id)
|
|
self.talk_clock_Id = nil
|
|
end
|
|
end
|
|
|
|
function BeachModel:SetVoteClock()
|
|
if not self.vote_clock_Id then
|
|
self.vote_clock = TimeUtil:getServerTimeMs() + self.vote_break_time * 1000
|
|
local function step_method( ... )
|
|
local a = TimeUtil:getServerTimeMs() - self.vote_clock
|
|
if TimeUtil:getServerTimeMs() >= self.vote_clock then
|
|
--倒计时结束
|
|
self:CloseVoteClock()
|
|
end
|
|
end
|
|
self.vote_clock_Id = GlobalTimerQuest:AddPeriodQuest(step_method, 1, -1)
|
|
self:Fire(BeachConst.REFRESH_VOTE_CLOCK)
|
|
else
|
|
return self.vote_clock
|
|
end
|
|
end
|
|
|
|
function BeachModel:CloseVoteClock()
|
|
self.vote_clock = nil
|
|
if self.vote_clock_Id then
|
|
GlobalTimerQuest:CancelQuest(self.vote_clock_Id)
|
|
self.vote_clock_Id = nil
|
|
end
|
|
end
|
|
|
|
function BeachModel:IsShowDynamicInfo( )
|
|
return SceneManager.Instance:IsBeachScene() and self.show_scene_left_tip
|
|
end
|
|
|
|
function BeachModel:GetReleaseExpTime( )
|
|
local base_info = self:GetMyInfo( )
|
|
if not base_info then return 0 end
|
|
-------------------------
|
|
local max_can_get = self:GetKeyValue("buy_vote_times")--最大可获得经验的次数
|
|
local can_exp_num = max_can_get - base_info.vote_other_time
|
|
return can_exp_num > 0 and can_exp_num or 0
|
|
end
|
|
|
|
function BeachModel:VoteToOher( name,role_id )
|
|
local data = {name = name, role_id = role_id}
|
|
self:Fire(BeachConst.OPEN_VOTE_VIEW,data)
|
|
end
|
|
|
|
-- 初始化排行榜页数
|
|
function BeachModel:InitRankPage( )
|
|
self.cur_rank_show_page = 1
|
|
end
|
|
|
|
-- 变更页数
|
|
function BeachModel:SetBeachRankCurShowPage( change_page )
|
|
self.cur_rank_show_page = self.cur_rank_show_page + change_page
|
|
self.cur_rank_show_page = Mathf.Clamp(self.cur_rank_show_page, 1, BeachConst.MAX_RANK_SHOW_PAGE )
|
|
end
|
|
|
|
-- 获取当前页数
|
|
function BeachModel:GetCurRankPage( )
|
|
return self.cur_rank_show_page
|
|
end
|
|
|
|
-- 获取当前应该请求的页数 1-20发0 21-40发1 以此类推
|
|
function BeachModel:GetCurRankSetSCMDLength( )
|
|
return (self:GetCurRankPage() - 1) * BeachConst.SingleRankLength
|
|
end
|
|
|
|
----------喊话-start---------
|
|
function BeachModel:InitBeachVoiceCfg( )
|
|
self.cfg_beach_voice = {}
|
|
self.cfg_beach_voice_content = {}
|
|
self.last_send_msg_time_cache = {}
|
|
for i,v in pairs(Config.Beachvoice) do
|
|
self.cfg_beach_voice[v.type] = v
|
|
end
|
|
for k,v in pairs(Config.Beachvoicecontent) do
|
|
self.cfg_beach_voice_content[v.base_id] = self.cfg_beach_voice_content[v.base_id] or {}
|
|
table.insert(self.cfg_beach_voice_content[v.base_id], v)
|
|
end
|
|
end
|
|
|
|
|
|
-- 发送喊话
|
|
function BeachModel:BeachSendMsg( voice_type, extra_param )
|
|
--print('=======Msh:BeachModel.lua[284] =======', voice_type)
|
|
local voice_cfg = self.cfg_beach_voice[voice_type]
|
|
if not voice_cfg then return end
|
|
local cur_time = TimeUtil:getServerTime( )
|
|
-- 发送间隔
|
|
if self.last_send_msg_time_cache[voice_type]
|
|
and cur_time - self.last_send_msg_time_cache[voice_type] < voice_cfg.cd
|
|
then
|
|
return
|
|
end
|
|
local base_id = voice_cfg.base_id
|
|
local random_index = math.random(1, #self.cfg_beach_voice_content[base_id])
|
|
local content = ChuanWenManager:getInstance():FormatColorTag2(self.cfg_beach_voice_content[base_id][random_index].content, true)
|
|
if extra_param then
|
|
content = string.gsub(content, "<@player>", extra_param)
|
|
end
|
|
-- print('=======Msh:BeachModel.lua[299] =======', content)
|
|
if content and content ~= "" then
|
|
self.last_send_msg_time_cache[voice_type] = cur_time
|
|
local tmpArgs = ChatModel:getInstance():GetAllArgsText(content)
|
|
content = ChatModel:getInstance():GetHyperlinkText(content)
|
|
ChatModel:getInstance():Fire(ChatModel.SEND_MSG, ChatModel.CHANNEL_BEACH, content, nil, tmpArgs, ChatModel.CHAT_COMMON_TYPE.SYSTEM)
|
|
end
|
|
end
|
|
----------喊话-end-----------
|