源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

531 linhas
15 KiB

4 semanas atrás
  1. SandTableModel = SandTableModel or BaseClass(BaseVo, true)
  2. local SandTableModel = SandTableModel
  3. function SandTableModel:__init()
  4. SandTableModel.Instance = self
  5. self:Reset()
  6. end
  7. function SandTableModel:Reset()
  8. -------------------------
  9. self.point_match_temp = false--据点配置里的具体id配置对应的索引
  10. -------------------------
  11. self.act_info = false
  12. self.point_date_list = {}--据点信息
  13. self.buff_info = {}--buff信息列表
  14. self.self_rank_info = {}--战功榜
  15. self.dungeon_info = false
  16. self.self_active_buff = {}--激活的buff
  17. self.fight_rank_data = false
  18. self.dungeon_cost_id = 100018--副本体力id
  19. -------------------------
  20. self.red_point_reward = {}
  21. self.red_can_fight = false
  22. end
  23. function SandTableModel:getInstance()
  24. if SandTableModel.Instance == nil then
  25. SandTableModel.Instance = SandTableModel.New()
  26. end
  27. return SandTableModel.Instance
  28. end
  29. --获取据点配置
  30. function SandTableModel:GetPointCfg( point_id )
  31. if not point_id then return end
  32. if not self.point_match_temp then
  33. self.point_match_temp = {}
  34. for k,v in pairs(Config.Crosspointfightpoint) do
  35. self.point_match_temp[v.point_id] = k
  36. end
  37. end
  38. local conf = false
  39. if self.point_match_temp[point_id] then
  40. conf = Config.Crosspointfightpoint[self.point_match_temp[point_id]]
  41. elseif SandTableConst.PointList[SandTableConst.PointShow.MainCity][point_id] then
  42. --主城
  43. elseif SandTableConst.PointList[SandTableConst.PointShow.DoorPoint][point_id] then
  44. --关口
  45. end
  46. return conf
  47. end
  48. --根据副本id获得据点类型
  49. function SandTableModel:GetPointTypeByDunId( dun_id )
  50. local dun_id = dun_id or SceneManager.Instance:GetCurrDunId()
  51. for k,v in pairs(Config.Crosspointfightpoint) do
  52. if v.dun_id == dun_id then
  53. return v.type
  54. end
  55. end
  56. end
  57. --据点活动状态
  58. function SandTableModel:GetActInfo( )
  59. return self.act_info
  60. end
  61. function SandTableModel:SetActInfo( value )
  62. self.act_info = value
  63. end
  64. --获得自己的阵营
  65. function SandTableModel:GetFaction( )
  66. local act_info = self:GetActInfo()
  67. return act_info and act_info.faction or 0
  68. end
  69. --据点信息
  70. function SandTableModel:GetPointDateList( point_id )
  71. if point_id then
  72. return self.point_date_list[point_id]
  73. else
  74. return self.point_date_list
  75. end
  76. end
  77. function SandTableModel:SetPointDateList( value,is_reset )
  78. if is_reset then
  79. self.point_date_list = {}
  80. end
  81. local function sort_call( a,b )
  82. --从大到小
  83. return a.score > b.score
  84. end
  85. for k,v in pairs(value) do
  86. table.sort( v.attack_info, sort_call )
  87. self.point_date_list[v.point_id] = v
  88. end
  89. end
  90. --buff信息
  91. function SandTableModel:GetBuffInfo( )
  92. return self.buff_info
  93. end
  94. function SandTableModel:SetBuffInfo( value )
  95. self.buff_info = value or {}
  96. end
  97. function SandTableModel:GetBuffListByFaction( faction )
  98. if not faction then return {} end
  99. local list = {}
  100. for k,v in pairs(self:GetBuffInfo( )) do
  101. if v.faction == faction then
  102. table.insert(list,v)
  103. end
  104. end
  105. return list
  106. end
  107. --获得buff归属国
  108. function SandTableModel:GetBuffFaction( point_id )
  109. local buff_list = self:GetBuffInfo( )
  110. for k,v in pairs(buff_list or {}) do
  111. if point_id == v.point_id then
  112. return v.faction
  113. end
  114. end
  115. return 0
  116. end
  117. --副本内信息
  118. function SandTableModel:GetDungeonInfo( )
  119. return self.dungeon_info
  120. end
  121. function SandTableModel:SetDungeonInfo( value )
  122. self.dungeon_info = value
  123. end
  124. --[[--战功榜
  125. function SandTableModel:GetSelfRankInfo( )
  126. return self.self_rank_info
  127. end
  128. function SandTableModel:SetSelfRankInfo( value )
  129. self.self_rank_info = value
  130. end
  131. --]]
  132. function SandTableModel:GetRedDot( need_new )
  133. local bool_fight = self:CanFightRed( need_new )
  134. local bool_sandtable = self:CanPointReward( need_new )
  135. local csgwar_red_data = CSGWarModel:getInstance():GetCSGWarRedData()
  136. 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
  137. return bool_sandtable or csgwar_red or bool_fight
  138. end
  139. function SandTableModel:CanPointReward( need_new )
  140. if need_new then
  141. self.red_point_reward = {}
  142. local point_list = self:GetPointDateList() or {}
  143. for k,v in pairs(point_list) do
  144. self:CanPointRewardByPointId( true, v.point_id )
  145. end
  146. end
  147. for k,v in pairs(self.red_point_reward) do
  148. if v == true then
  149. return true
  150. end
  151. end
  152. return false
  153. end
  154. --是否可以获得节点奖励
  155. function SandTableModel:CanPointRewardByPointId( need_new, point_id )
  156. if not point_id then return false end
  157. if need_new then
  158. self.red_point_reward[point_id] = false
  159. local server_data = self:GetPointDateList( point_id )
  160. local cfg = self:GetPointCfg( point_id )
  161. if server_data and cfg then
  162. self.red_point_reward[point_id] = (server_data.award_time > 0) and ((TimeUtil:getServerTime() - server_data.award_time) >= cfg.interval_time)
  163. end
  164. end
  165. return self.red_point_reward[point_id] or false
  166. end
  167. --可挑战红点
  168. function SandTableModel:CanFightRed( need_new )
  169. if need_new then
  170. self.red_can_fight = false
  171. local cur_num = CSMainModel:getInstance():GetCSMainArmsNum( ) or 0
  172. local can_fight = false
  173. local cost_info = false
  174. for k,v in pairs(Config.Crosspointfightpoint) do
  175. can_fight = self:GetPointCanFight(v.point_id)
  176. if can_fight then
  177. cost_info = stringtotable(v.cost)[1]
  178. if cur_num >= cost_info[3] then
  179. self.red_can_fight = true
  180. end
  181. end
  182. end
  183. end
  184. return self.red_can_fight
  185. end
  186. --获得buff下次激活时间
  187. function SandTableModel:GetBuffNextTime( curTime )
  188. local buff_time_conf = self:GetBuffTimeConf( )
  189. local curTime = curTime or TimeUtil:getServerTime()
  190. -------------------------
  191. local function check_call( curTime, index )
  192. --index 第几次运算,如果不是第一次,那么就要回到那天的起点
  193. local time_tb = os.date("*t", curTime)
  194. if index > 0 then
  195. time_tb.hour = 0
  196. time_tb.min = 0
  197. time_tb.sec = 0
  198. end
  199. local week_day = time_tb.wday - 1
  200. week_day = week_day == 0 and 7 or week_day
  201. if week_day == buff_time_conf[1] then
  202. 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
  203. time_tb.hour = buff_time_conf[2][1]
  204. time_tb.min = buff_time_conf[2][2]
  205. return os.time(time_tb)
  206. end
  207. end
  208. end
  209. local result = false
  210. for i=0,7 do
  211. result = check_call( curTime + 86400 * i, i )
  212. if result then
  213. return result
  214. end
  215. end
  216. end
  217. --获得buff上次时间
  218. function SandTableModel:GetBuffLastTime( )
  219. local buff_time_conf = self:GetBuffTimeConf( )
  220. local curTime = TimeUtil:getServerTime() - buff_time_conf[3]
  221. return self:GetBuffNextTime( curTime )
  222. end
  223. --获得buff时间配置
  224. function SandTableModel:GetBuffTimeConf( )
  225. self.buff_time_conf = self.buff_time_conf or stringtotable(Config.Crosspointfightkv["buff_time"].value_content)
  226. return self.buff_time_conf
  227. end
  228. --获得据点的buff配置
  229. function SandTableModel:GetBuffSkillIdByPoint( point_id )
  230. local point_conf = self:GetPointCfg( point_id )
  231. if not point_conf then return end
  232. return point_conf.buff
  233. end
  234. --根据据点id获得阵营
  235. function SandTableModel:GetFactionByCityPoint( city_point_id )
  236. return math.floor(city_point_id / 1000)
  237. end
  238. function SandTableModel:GetFactionByPoint( point )
  239. if SandTableConst.PointList[SandTableConst.PointShow.MainCity][point] then
  240. return self:GetFactionByCityPoint( point )
  241. else
  242. local data = self:GetPointDateList( point )
  243. if data then
  244. return data.faction
  245. else
  246. return 0
  247. end
  248. end
  249. end
  250. --当前本国已激活的buff
  251. function SandTableModel:GetSelfActiveBuff( )
  252. return self.self_active_buff or {}
  253. end
  254. function SandTableModel:SetSelfActiveBuff( value )
  255. self.self_active_buff = value
  256. end
  257. --战斗对应积分配置
  258. function SandTableModel:GetFightScoreCfg( point_id )
  259. if not self.fight_score_cfg then
  260. self.fight_score_cfg = {}
  261. for k,v in pairs(Config.Crosspointfightscore) do
  262. self.fight_score_cfg[v.dun_id] = self.fight_score_cfg[v.dun_id] or {}
  263. self.fight_score_cfg[v.dun_id][#self.fight_score_cfg[v.dun_id]+1] = v
  264. end
  265. for k,v in pairs(self.fight_score_cfg) do
  266. local function sort_call( a,b )
  267. return a.value_max > b.value_max
  268. end
  269. table.sort( v, sort_call )
  270. end
  271. end
  272. if point_id then
  273. local dun_id = self:GetPointCfg( point_id ).dun_id
  274. return self.fight_score_cfg[dun_id]
  275. else
  276. return self.fight_score_cfg
  277. end
  278. end
  279. function SandTableModel:ResetFightScoreCfg( )
  280. --切场景重置,减少使用
  281. if self.fight_score_cfg then
  282. self.fight_score_cfg = false
  283. end
  284. end
  285. --获得战斗对应积分
  286. function SandTableModel:GetFightScoreByKill( point_id,num )
  287. if not point_id then return 0 end
  288. num = num or 0
  289. local cfg_list = self:GetFightScoreCfg( point_id ) or {}
  290. for i,v in ipairs(cfg_list) do
  291. if num >= v.value_max then
  292. return v.score
  293. end
  294. end
  295. return 0
  296. end
  297. --战斗榜单数据
  298. function SandTableModel:GetFightRankData( )
  299. return self.fight_rank_data
  300. end
  301. function SandTableModel:SetFightRankData( value )
  302. if value.attact_rank then
  303. local function sort_call( a,b )
  304. --从大到小
  305. return a.score > b.score
  306. end
  307. table.sort( value.attact_rank, sort_call )
  308. end
  309. self.fight_rank_data = value
  310. end
  311. --通过阵营获得据点列表
  312. function SandTableModel:GetPointListByFaction( faction )
  313. faction = faction or self:GetFaction()
  314. local list = {}
  315. for k,v in pairs(self:GetPointDateList() or {}) do
  316. if v.faction == faction then
  317. table.insert( list, v )
  318. end
  319. end
  320. return list
  321. end
  322. --通过据点获得图标
  323. function SandTableModel:GetIconByPoint( point ,is_big )
  324. local point_list = SandTableConst.PointList
  325. local point_show = SandTableConst.PointShow
  326. local res_name = false
  327. local image_index = 1
  328. if point_list[point_show.SafePoint][point] then
  329. res_name = is_big and "kfWorld_sand_point_2" or "sandTable_point_2"
  330. image_index = is_big and 2 or 2
  331. elseif point_list[point_show.DoorPoint][point] then
  332. res_name = is_big and "kfWorld_sand_point_1" or "sandTable_point_3"
  333. image_index = is_big and 1 or 3
  334. elseif point_list[point_show.BuffPoint][point] then
  335. res_name = is_big and "kfWorld_sand_point_5" or "sandTable_point_6"
  336. image_index = is_big and 5 or 6
  337. elseif point_list[point_show.FightPoint][point] then
  338. if (point%2) == 0 then
  339. res_name = is_big and "kfWorld_sand_point_4" or "sandTable_point_5"
  340. image_index = is_big and 4 or 5
  341. else
  342. res_name = is_big and "kfWorld_sand_point_3" or "sandTable_point_4"
  343. image_index = is_big and 3 or 4
  344. end
  345. else
  346. res_name = is_big and "kfWorld_sand_point_1" or "sandTable_point_2"
  347. image_index = is_big and 1 or 2
  348. end
  349. if is_big then
  350. return "/client/assets/icon/kfworld/" .. res_name .. ".png", image_index
  351. else
  352. return res_name, image_index
  353. end
  354. end
  355. --根据据点判断是否是自己的阵营
  356. function SandTableModel:IsSelfFactionByPoint( point_id )
  357. if not point_id then return false end
  358. local sel_id = self:GetFaction()
  359. local server_data = self:GetPointDateList( point_id )
  360. if server_data then
  361. return server_data.faction == sel_id
  362. end
  363. return false
  364. end
  365. --获得据点定时体力奖励
  366. function SandTableModel:GetPointTimeReward( point )
  367. local conf_point = self:GetPointCfg(point)
  368. if not conf_point then return 0,{} end
  369. local reward_list = stringtotable(conf_point.reward) or {}
  370. if #reward_list > 0 then
  371. return reward_list[1][3],reward_list
  372. end
  373. return 0, reward_list
  374. end
  375. function SandTableModel:GetRewardTimeByPoint( point_id )
  376. if not point_id then return false end
  377. if not self:IsSelfFactionByPoint( point_id ) then
  378. return false
  379. end
  380. local data = self:GetPointDateList( point_id )
  381. local cfg = self:GetPointCfg( point_id )
  382. if data and cfg then
  383. local curTime = TimeUtil:getServerTime()
  384. local tem_time = curTime - data.award_time--间隔时间
  385. tem_time = tem_time % cfg.interval_time
  386. if tem_time > 0 then
  387. local need_time = cfg.interval_time - tem_time
  388. need_time = need_time > 0 and need_time or 0
  389. return need_time
  390. else
  391. return 0
  392. end
  393. end
  394. return false
  395. end
  396. --判断节点是否可以操作
  397. function SandTableModel:GetPointCanFight( point )
  398. if not point then return end
  399. local point_list = SandTableConst.PointList
  400. local point_show = SandTableConst.PointShow
  401. local my_faction = self:GetFaction( )
  402. -------------------------
  403. if point_list[point_show.MainCity][point] then
  404. --主城不可操作
  405. return false
  406. end
  407. if point_list[point_show.SafePoint][point] or point_list[point_show.DoorPoint][point] then
  408. --非己方安全据点不可操作
  409. if math.floor(point/1000) ~= my_faction then
  410. return false
  411. else
  412. local data = self:GetPointDateList( point )
  413. --连着线而且(无数据或者阵营不属于自己)
  414. return self:GetPointIsLine( point ) and ((not data) or (data.faction~=self:GetFaction( )))
  415. end
  416. end
  417. -- 判断是否有连接
  418. local data = self:GetPointDateList( point )
  419. return self:GetPointIsLine( point ) and ((not data) or (data.faction~=self:GetFaction( ) or
  420. self:GetPointIsFighting( point )))
  421. end
  422. --判断据点是否是争夺中
  423. function SandTableModel:GetPointIsFighting( point )
  424. local data = self:GetPointDateList( point )
  425. if data then
  426. if #data.attack_info > 0 then
  427. local max_score = 0
  428. local conf = self:GetPointCfg( point )
  429. for k,v in pairs(data.attack_info) do
  430. max_score = max_score > v.score and max_score or v.score
  431. end
  432. --最高分小于总分,说明争夺中
  433. return (max_score ~= 0) and (max_score < conf.base_score)
  434. end
  435. end
  436. return false
  437. end
  438. --是否可扫荡
  439. function SandTableModel:GetPointCanSweep( point )
  440. if self:GetPointCanFight( point ) then
  441. local data = self:GetPointDateList( point )
  442. if data and data.is_sweep == 1 then
  443. if data.faction ~= self:GetFaction( ) then
  444. return true
  445. else
  446. return #data.attack_info > 0
  447. end
  448. end
  449. end
  450. return false
  451. end
  452. --据点是否有连接
  453. function SandTableModel:GetPointIsLine( point )
  454. local point_list = self:GetPointListByFaction( )
  455. local cfg,link_conf = false,false
  456. local my_faction = self:GetFaction( )
  457. local const_point_list = SandTableConst.PointList
  458. local const_point_show = SandTableConst.PointShow
  459. for k,v in pairs(point_list) do
  460. cfg = self:GetPointCfg( v.point_id )
  461. if cfg then
  462. link_conf = stringtotable(cfg.link_point) or {}
  463. for kk,vv in pairs(link_conf) do
  464. if tonumber(vv) == point then
  465. if const_point_list[const_point_show.DoorPoint][tonumber(vv)] then
  466. return (math.floor(vv/1000) == my_faction)
  467. else
  468. return true
  469. end
  470. end
  471. end
  472. end
  473. end
  474. if (point%1000 == 11) and math.floor(point/1000) == my_faction then
  475. -- 第一个安全据点
  476. return true
  477. elseif (point%1000 == 12) and math.floor(point/1000) == my_faction then
  478. if self:GetFactionByPoint( point-1 ) == my_faction then
  479. return true
  480. end
  481. end
  482. return false
  483. end
  484. function SandTableModel:GetShortNameStr( str )
  485. str = str or ""
  486. if SubStringGetTotalIndex(str) > 8 then
  487. return SubStringUTF8(str, 1, 8) .. "..."
  488. else
  489. return str
  490. end
  491. end
  492. function SandTableModel:GetFactionName( faction )
  493. faction = faction or 0
  494. return KfWorldModel:GetInstance():GetContrayNameById(faction) or ""
  495. end