SandTableModel = SandTableModel or BaseClass(BaseVo, true) local SandTableModel = SandTableModel function SandTableModel:__init() SandTableModel.Instance = self self:Reset() end function SandTableModel:Reset() ------------------------- self.point_match_temp = false--据点配置里的具体id配置对应的索引 ------------------------- self.act_info = false self.point_date_list = {}--据点信息 self.buff_info = {}--buff信息列表 self.self_rank_info = {}--战功榜 self.dungeon_info = false self.self_active_buff = {}--激活的buff self.fight_rank_data = false self.dungeon_cost_id = 100018--副本体力id ------------------------- self.red_point_reward = {} self.red_can_fight = false end function SandTableModel:getInstance() if SandTableModel.Instance == nil then SandTableModel.Instance = SandTableModel.New() end return SandTableModel.Instance end --获取据点配置 function SandTableModel:GetPointCfg( point_id ) if not point_id then return end if not self.point_match_temp then self.point_match_temp = {} for k,v in pairs(Config.Crosspointfightpoint) do self.point_match_temp[v.point_id] = k end end local conf = false if self.point_match_temp[point_id] then conf = Config.Crosspointfightpoint[self.point_match_temp[point_id]] elseif SandTableConst.PointList[SandTableConst.PointShow.MainCity][point_id] then --主城 elseif SandTableConst.PointList[SandTableConst.PointShow.DoorPoint][point_id] then --关口 end return conf end --根据副本id获得据点类型 function SandTableModel:GetPointTypeByDunId( dun_id ) local dun_id = dun_id or SceneManager.Instance:GetCurrDunId() for k,v in pairs(Config.Crosspointfightpoint) do if v.dun_id == dun_id then return v.type end end end --据点活动状态 function SandTableModel:GetActInfo( ) return self.act_info end function SandTableModel:SetActInfo( value ) self.act_info = value end --获得自己的阵营 function SandTableModel:GetFaction( ) local act_info = self:GetActInfo() return act_info and act_info.faction or 0 end --据点信息 function SandTableModel:GetPointDateList( point_id ) if point_id then return self.point_date_list[point_id] else return self.point_date_list end end function SandTableModel:SetPointDateList( value,is_reset ) if is_reset then self.point_date_list = {} end local function sort_call( a,b ) --从大到小 return a.score > b.score end for k,v in pairs(value) do table.sort( v.attack_info, sort_call ) self.point_date_list[v.point_id] = v end end --buff信息 function SandTableModel:GetBuffInfo( ) return self.buff_info end function SandTableModel:SetBuffInfo( value ) self.buff_info = value or {} end function SandTableModel:GetBuffListByFaction( faction ) if not faction then return {} end local list = {} for k,v in pairs(self:GetBuffInfo( )) do if v.faction == faction then table.insert(list,v) end end return list end --获得buff归属国 function SandTableModel:GetBuffFaction( point_id ) local buff_list = self:GetBuffInfo( ) for k,v in pairs(buff_list or {}) do if point_id == v.point_id then return v.faction end end return 0 end --副本内信息 function SandTableModel:GetDungeonInfo( ) return self.dungeon_info end function SandTableModel:SetDungeonInfo( value ) self.dungeon_info = value end --[[--战功榜 function SandTableModel:GetSelfRankInfo( ) return self.self_rank_info end function SandTableModel:SetSelfRankInfo( value ) self.self_rank_info = value end --]] function SandTableModel:GetRedDot( need_new ) local bool_fight = self:CanFightRed( need_new ) local bool_sandtable = self:CanPointReward( need_new ) local csgwar_red_data = CSGWarModel:getInstance():GetCSGWarRedData() local csgwar_red = csgwar_red_data.one_red or csgwar_red_data.support_red or csgwar_red_data.fight_red or csgwar_red_data.occupy_red return bool_sandtable or csgwar_red or bool_fight end function SandTableModel:CanPointReward( need_new ) if need_new then self.red_point_reward = {} local point_list = self:GetPointDateList() or {} for k,v in pairs(point_list) do self:CanPointRewardByPointId( true, v.point_id ) end end for k,v in pairs(self.red_point_reward) do if v == true then return true end end return false end --是否可以获得节点奖励 function SandTableModel:CanPointRewardByPointId( need_new, point_id ) if not point_id then return false end if need_new then self.red_point_reward[point_id] = false local server_data = self:GetPointDateList( point_id ) local cfg = self:GetPointCfg( point_id ) if server_data and cfg then self.red_point_reward[point_id] = (server_data.award_time > 0) and ((TimeUtil:getServerTime() - server_data.award_time) >= cfg.interval_time) end end return self.red_point_reward[point_id] or false end --可挑战红点 function SandTableModel:CanFightRed( need_new ) if need_new then self.red_can_fight = false local cur_num = CSMainModel:getInstance():GetCSMainArmsNum( ) or 0 local can_fight = false local cost_info = false for k,v in pairs(Config.Crosspointfightpoint) do can_fight = self:GetPointCanFight(v.point_id) if can_fight then cost_info = stringtotable(v.cost)[1] if cur_num >= cost_info[3] then self.red_can_fight = true end end end end return self.red_can_fight end --获得buff下次激活时间 function SandTableModel:GetBuffNextTime( curTime ) local buff_time_conf = self:GetBuffTimeConf( ) local curTime = curTime or TimeUtil:getServerTime() ------------------------- local function check_call( curTime, index ) --index 第几次运算,如果不是第一次,那么就要回到那天的起点 local time_tb = os.date("*t", curTime) if index > 0 then time_tb.hour = 0 time_tb.min = 0 time_tb.sec = 0 end local week_day = time_tb.wday - 1 week_day = week_day == 0 and 7 or week_day if week_day == buff_time_conf[1] then if (time_tb.hour < buff_time_conf[2][1]) or (time_tb.hour == buff_time_conf[2][1] and time_tb.min < buff_time_conf[2][2]) then time_tb.hour = buff_time_conf[2][1] time_tb.min = buff_time_conf[2][2] return os.time(time_tb) end end end local result = false for i=0,7 do result = check_call( curTime + 86400 * i, i ) if result then return result end end end --获得buff上次时间 function SandTableModel:GetBuffLastTime( ) local buff_time_conf = self:GetBuffTimeConf( ) local curTime = TimeUtil:getServerTime() - buff_time_conf[3] return self:GetBuffNextTime( curTime ) end --获得buff时间配置 function SandTableModel:GetBuffTimeConf( ) self.buff_time_conf = self.buff_time_conf or stringtotable(Config.Crosspointfightkv["buff_time"].value_content) return self.buff_time_conf end --获得据点的buff配置 function SandTableModel:GetBuffSkillIdByPoint( point_id ) local point_conf = self:GetPointCfg( point_id ) if not point_conf then return end return point_conf.buff end --根据据点id获得阵营 function SandTableModel:GetFactionByCityPoint( city_point_id ) return math.floor(city_point_id / 1000) end function SandTableModel:GetFactionByPoint( point ) if SandTableConst.PointList[SandTableConst.PointShow.MainCity][point] then return self:GetFactionByCityPoint( point ) else local data = self:GetPointDateList( point ) if data then return data.faction else return 0 end end end --当前本国已激活的buff function SandTableModel:GetSelfActiveBuff( ) return self.self_active_buff or {} end function SandTableModel:SetSelfActiveBuff( value ) self.self_active_buff = value end --战斗对应积分配置 function SandTableModel:GetFightScoreCfg( point_id ) if not self.fight_score_cfg then self.fight_score_cfg = {} for k,v in pairs(Config.Crosspointfightscore) do self.fight_score_cfg[v.dun_id] = self.fight_score_cfg[v.dun_id] or {} self.fight_score_cfg[v.dun_id][#self.fight_score_cfg[v.dun_id]+1] = v end for k,v in pairs(self.fight_score_cfg) do local function sort_call( a,b ) return a.value_max > b.value_max end table.sort( v, sort_call ) end end if point_id then local dun_id = self:GetPointCfg( point_id ).dun_id return self.fight_score_cfg[dun_id] else return self.fight_score_cfg end end function SandTableModel:ResetFightScoreCfg( ) --切场景重置,减少使用 if self.fight_score_cfg then self.fight_score_cfg = false end end --获得战斗对应积分 function SandTableModel:GetFightScoreByKill( point_id,num ) if not point_id then return 0 end num = num or 0 local cfg_list = self:GetFightScoreCfg( point_id ) or {} for i,v in ipairs(cfg_list) do if num >= v.value_max then return v.score end end return 0 end --战斗榜单数据 function SandTableModel:GetFightRankData( ) return self.fight_rank_data end function SandTableModel:SetFightRankData( value ) if value.attact_rank then local function sort_call( a,b ) --从大到小 return a.score > b.score end table.sort( value.attact_rank, sort_call ) end self.fight_rank_data = value end --通过阵营获得据点列表 function SandTableModel:GetPointListByFaction( faction ) faction = faction or self:GetFaction() local list = {} for k,v in pairs(self:GetPointDateList() or {}) do if v.faction == faction then table.insert( list, v ) end end return list end --通过据点获得图标 function SandTableModel:GetIconByPoint( point ,is_big ) local point_list = SandTableConst.PointList local point_show = SandTableConst.PointShow local res_name = false local image_index = 1 if point_list[point_show.SafePoint][point] then res_name = is_big and "kfWorld_sand_point_2" or "sandTable_point_2" image_index = is_big and 2 or 2 elseif point_list[point_show.DoorPoint][point] then res_name = is_big and "kfWorld_sand_point_1" or "sandTable_point_3" image_index = is_big and 1 or 3 elseif point_list[point_show.BuffPoint][point] then res_name = is_big and "kfWorld_sand_point_5" or "sandTable_point_6" image_index = is_big and 5 or 6 elseif point_list[point_show.FightPoint][point] then if (point%2) == 0 then res_name = is_big and "kfWorld_sand_point_4" or "sandTable_point_5" image_index = is_big and 4 or 5 else res_name = is_big and "kfWorld_sand_point_3" or "sandTable_point_4" image_index = is_big and 3 or 4 end else res_name = is_big and "kfWorld_sand_point_1" or "sandTable_point_2" image_index = is_big and 1 or 2 end if is_big then return "/client/assets/icon/kfworld/" .. res_name .. ".png", image_index else return res_name, image_index end end --根据据点判断是否是自己的阵营 function SandTableModel:IsSelfFactionByPoint( point_id ) if not point_id then return false end local sel_id = self:GetFaction() local server_data = self:GetPointDateList( point_id ) if server_data then return server_data.faction == sel_id end return false end --获得据点定时体力奖励 function SandTableModel:GetPointTimeReward( point ) local conf_point = self:GetPointCfg(point) if not conf_point then return 0,{} end local reward_list = stringtotable(conf_point.reward) or {} if #reward_list > 0 then return reward_list[1][3],reward_list end return 0, reward_list end function SandTableModel:GetRewardTimeByPoint( point_id ) if not point_id then return false end if not self:IsSelfFactionByPoint( point_id ) then return false end local data = self:GetPointDateList( point_id ) local cfg = self:GetPointCfg( point_id ) if data and cfg then local curTime = TimeUtil:getServerTime() local tem_time = curTime - data.award_time--间隔时间 tem_time = tem_time % cfg.interval_time if tem_time > 0 then local need_time = cfg.interval_time - tem_time need_time = need_time > 0 and need_time or 0 return need_time else return 0 end end return false end --判断节点是否可以操作 function SandTableModel:GetPointCanFight( point ) if not point then return end local point_list = SandTableConst.PointList local point_show = SandTableConst.PointShow local my_faction = self:GetFaction( ) ------------------------- if point_list[point_show.MainCity][point] then --主城不可操作 return false end if point_list[point_show.SafePoint][point] or point_list[point_show.DoorPoint][point] then --非己方安全据点不可操作 if math.floor(point/1000) ~= my_faction then return false else local data = self:GetPointDateList( point ) --连着线而且(无数据或者阵营不属于自己) return self:GetPointIsLine( point ) and ((not data) or (data.faction~=self:GetFaction( ))) end end -- 判断是否有连接 local data = self:GetPointDateList( point ) return self:GetPointIsLine( point ) and ((not data) or (data.faction~=self:GetFaction( ) or self:GetPointIsFighting( point ))) end --判断据点是否是争夺中 function SandTableModel:GetPointIsFighting( point ) local data = self:GetPointDateList( point ) if data then if #data.attack_info > 0 then local max_score = 0 local conf = self:GetPointCfg( point ) for k,v in pairs(data.attack_info) do max_score = max_score > v.score and max_score or v.score end --最高分小于总分,说明争夺中 return (max_score ~= 0) and (max_score < conf.base_score) end end return false end --是否可扫荡 function SandTableModel:GetPointCanSweep( point ) if self:GetPointCanFight( point ) then local data = self:GetPointDateList( point ) if data and data.is_sweep == 1 then if data.faction ~= self:GetFaction( ) then return true else return #data.attack_info > 0 end end end return false end --据点是否有连接 function SandTableModel:GetPointIsLine( point ) local point_list = self:GetPointListByFaction( ) local cfg,link_conf = false,false local my_faction = self:GetFaction( ) local const_point_list = SandTableConst.PointList local const_point_show = SandTableConst.PointShow for k,v in pairs(point_list) do cfg = self:GetPointCfg( v.point_id ) if cfg then link_conf = stringtotable(cfg.link_point) or {} for kk,vv in pairs(link_conf) do if tonumber(vv) == point then if const_point_list[const_point_show.DoorPoint][tonumber(vv)] then return (math.floor(vv/1000) == my_faction) else return true end end end end end if (point%1000 == 11) and math.floor(point/1000) == my_faction then -- 第一个安全据点 return true elseif (point%1000 == 12) and math.floor(point/1000) == my_faction then if self:GetFactionByPoint( point-1 ) == my_faction then return true end end return false end function SandTableModel:GetShortNameStr( str ) str = str or "" if SubStringGetTotalIndex(str) > 8 then return SubStringUTF8(str, 1, 8) .. "..." else return str end end function SandTableModel:GetFactionName( faction ) faction = faction or 0 return KfWorldModel:GetInstance():GetContrayNameById(faction) or "" end