源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

466 lines
13 KiB

  1. ShapeModel = ShapeModel or BaseClass(BaseVo, true)
  2. local ShapeModel = ShapeModel
  3. ShapeModel.REQ_BASE_INFO = 'ShapeModel.REQ_BASE_INFO' -- 基础珍宝信息
  4. ShapeModel.ANS_BASE_INFO = 'ShapeModel.ANS_BASE_INFO' -- 基础珍宝信息
  5. ShapeModel.REQ_UP_OR_ACTIVE = 'ShapeModel.REQ_UP_OR_ACTIVE' -- 进阶or激活
  6. ShapeModel.ANS_UP_OR_ACTIVE = 'ShapeModel.ANS_UP_OR_ACTIVE' -- 进阶or激活
  7. ShapeModel.REQ_CHANGE_SKIN = 'ShapeModel.REQ_CHANGE_SKIN' -- 换肤
  8. ShapeModel.ANS_CHANGE_SKIN = 'ShapeModel.ANS_CHANGE_SKIN' -- 换肤
  9. ShapeModel.RedDotRefresh = 'ShapeModel.RedDotRefresh' -- 红点
  10. ShapeModel.OPEN_BASE_VIEW = 'ShapeModel.OPEN_BASE_VIEW' -- 主界面
  11. ShapeModel.OPEN_SUCCESS_VIEW = 'ShapeModel.OPEN_SUCCESS_VIEW' -- 成功界面
  12. function ShapeModel:__init()
  13. ShapeModel.Instance = self
  14. self:Reset()
  15. end
  16. function ShapeModel:Reset()
  17. self.base_data = {}
  18. self.show_tab_list = {}
  19. self.show_model_resource_list = {}
  20. self.show_tab_type_list = false
  21. self.goods_id_conf_list = false--物品id对照表
  22. -------------------------
  23. self.red_active = {}
  24. self.red_up = {}
  25. end
  26. function ShapeModel:GetInstance()
  27. if ShapeModel.Instance == nil then
  28. ShapeModel.Instance = ShapeModel.New()
  29. end
  30. return ShapeModel.Instance
  31. end
  32. function ShapeModel:getInstance()
  33. if ShapeModel.Instance == nil then
  34. ShapeModel.Instance = ShapeModel.New()
  35. end
  36. return ShapeModel.Instance
  37. end
  38. --基础信息
  39. function ShapeModel:GetBaseData( type_id )
  40. if type_id then
  41. return self.base_data[type_id] or {}
  42. else
  43. return self.base_data
  44. end
  45. end
  46. --获取某类型数据
  47. function ShapeModel:SetBaseData( data )
  48. if data and data.type then
  49. self.base_data[data.type] = data.skins
  50. self:SetFightValData(data.type)
  51. end
  52. end
  53. --获得单条数据
  54. function ShapeModel:GetOneDataById( type_id,id )
  55. if type_id and id and self.base_data[type_id] then
  56. for k,v in pairs(self.base_data[type_id]) do
  57. if v.id == id then
  58. return v
  59. end
  60. end
  61. end
  62. end
  63. --更新单数据
  64. function ShapeModel:RefreshOneData( type_id,id,key,value )
  65. local data = self:GetOneDataById(type_id,id)
  66. if data and key then
  67. data[key] = value
  68. return true
  69. end
  70. return false
  71. end
  72. -- 设置珍宝战力数据
  73. function ShapeModel:SetFightValData(type_id)
  74. self.fightValList = self.fightValList or {}
  75. self.fightValList[type_id] = self.fightValList[type_id] or {}
  76. --属性
  77. for key, value in pairs(self.base_data[type_id]) do
  78. local conf = self:GetConfByStar( type_id, value.id, value.star )
  79. if conf then
  80. local base_attr = SortAttrList(stringtotable(conf.attrs))
  81. --技能
  82. local skill_info = stringtotable(conf.skills)[1]
  83. local _,skill_power = GetSkillAttrBySkill( skill_info[1], skill_info[2], true ,value)
  84. self.fightValList[type_id][value.id] = GetFighting(base_attr,true) + skill_power
  85. end
  86. end
  87. end
  88. -- 获取珍宝战力(默认当前已激活珍宝)
  89. function ShapeModel:GetFightValOneData(type_id, id)
  90. if type_id and self.fightValList and self.fightValList[type_id] then
  91. local res = 0
  92. for key, value in pairs(self.fightValList[type_id]) do
  93. if self:GetIsActive(type_id, key) then
  94. res = res + (self.fightValList[type_id][key] or 0)
  95. end
  96. end
  97. return res
  98. else
  99. return 0
  100. end
  101. end
  102. --更新使用皮肤
  103. function ShapeModel:RefreshSkinUsing( type_id,skin,star )
  104. local bool = false
  105. if self.base_data[type_id] then
  106. for k,v in pairs(self.base_data[type_id]) do
  107. if v.id == skin then
  108. v.display = star
  109. bool = bool or (star > 0)
  110. else
  111. v.display = 0
  112. end
  113. end
  114. end
  115. return bool
  116. end
  117. --获得当前使用中的皮肤
  118. function ShapeModel:GetUsingByType( type_id )
  119. if self.base_data[type_id] then
  120. for k,v in pairs(self.base_data[type_id]) do
  121. if v.display > 0 then
  122. return v.id,v.display
  123. end
  124. end
  125. end
  126. return 0,1
  127. end
  128. --获得配置
  129. function ShapeModel:GetConfByStar( type_id,id,star )
  130. return Config.Fosterskin[type_id .. "@" .. id .. "@" .. star]
  131. end
  132. function ShapeModel:GetModelRes( main_type, id, star )
  133. local conf = self:GetConfByStar(main_type, id ,star)
  134. return conf and conf.model or 0
  135. end
  136. --是否满级
  137. function ShapeModel:GetIsMaxStar( type_id,id )
  138. local base = self:GetOneDataById(type_id,id)
  139. if base then
  140. local conf = self:GetConfByStar(type_id,id,base.star)
  141. return not (base.star > 0 and conf.next_star~=0)
  142. end
  143. return false
  144. end
  145. --是否已激活
  146. function ShapeModel:GetIsActive( type_id,id )
  147. local base = self:GetOneDataById(type_id,id)
  148. return base and base.star > 0
  149. end
  150. -------------------------
  151. --获取已经解锁的珍宝大类
  152. function ShapeModel:GetUnlockType( )
  153. if not self.show_tab_type_list then
  154. self.show_tab_type_list = {}
  155. for k,v in pairs(Config.Fosterskin) do
  156. self.show_tab_type_list[v.type] = true
  157. end
  158. end
  159. return self.show_tab_type_list
  160. end
  161. --获取模型资源列表
  162. function ShapeModel:GetModelList( type_id,id )
  163. self.show_model_resource_list[type_id] = self.show_model_resource_list[type_id] or {}
  164. if not self.show_model_resource_list[type_id][id] then
  165. self.show_model_resource_list[type_id][id] = {}
  166. local temp = {}--资源对应的最小阶数
  167. for k,v in pairs(Config.Fosterskin) do
  168. if v.type == type_id and v.id == id then
  169. if not temp[v.model] then
  170. temp[v.model] = v.star
  171. else
  172. temp[v.model] = temp[v.model] < v.star and temp[v.model] or v.star
  173. end
  174. end
  175. end
  176. for k,v in pairs(temp) do
  177. table.insert( self.show_model_resource_list[type_id][id], {min_star = v, source_id = k} )
  178. end
  179. local function sort_call( a,b )
  180. return a.min_star < b.min_star
  181. end
  182. table.sort( self.show_model_resource_list[type_id][id], sort_call )
  183. end
  184. return self.show_model_resource_list[type_id][id]
  185. end
  186. --是否显示珍宝
  187. function ShapeModel:CanShowSkin( type_id, id )
  188. --增加限制条件,不显示部分条目类型
  189. -- 未激活&限制条件中&无激活道具
  190. local conf = self:GetConfByStar( type_id,id,0 )
  191. if not self:GetIsActive( type_id,id ) then--未激活
  192. if not GoodsModel:getInstance():GetEnough( conf.cost ) then--无激活道具
  193. if (conf.open_day > 0) and conf.open_day > ServerTimeModel:getInstance():GetOpenServerDay() then
  194. --开服条件未符合
  195. return false
  196. end
  197. if (conf.time > 0) and (conf.time > TimeUtil:getServerTime()) then
  198. --开放事件不符合
  199. return false
  200. end
  201. end
  202. end
  203. return true
  204. end
  205. function ShapeModel:GetTabList( type_id )
  206. local need_show = true
  207. local show_tab_list = {}
  208. for k,v in pairs(Config.Fosterskin) do
  209. if v.star == 0 and v.type == type_id then
  210. if self:CanShowSkin( type_id, v.id ) then
  211. table.insert( show_tab_list, v )
  212. end
  213. end
  214. end
  215. -------------------------
  216. local function sort_call( a,b )
  217. return a.order < b.order
  218. end
  219. table.sort( show_tab_list, sort_call )
  220. return show_tab_list
  221. end
  222. function ShapeModel:CheckRedDot( check_new )
  223. local bool = false
  224. local list = self:GetUnlockType()
  225. for k,v in pairs(list) do
  226. bool = self:CheckRedByType(check_new,k) or bool
  227. end
  228. return bool
  229. end
  230. function ShapeModel:CheckRedByType( check_new,type_id )
  231. local bool = false
  232. local list = self:GetTabList( type_id )
  233. for k,v in pairs(list) do
  234. bool = self:CheckRedById(check_new,type_id,v.id) or bool
  235. end
  236. return bool
  237. end
  238. function ShapeModel:CheckRedById( check_new,type_id,id )
  239. if check_new then
  240. self:CheckCanActive( check_new,type_id,id )
  241. self:CheckCanUp( check_new,type_id,id )
  242. end
  243. return (self.red_active[type_id] and self.red_active[type_id][id]) or (self.red_up[type_id] and self.red_up[type_id][id])
  244. end
  245. -- 打开界面或切换页签时默认显示可激活或可进阶的珍宝
  246. function ShapeModel:GetDefaultShowTabIndex(index)
  247. local tab_index = index
  248. local sub_tab_index
  249. local first_can_up = true
  250. if index then
  251. local sub_tab_list = self:GetTabList(index)
  252. for key, value in pairsByKeys(sub_tab_list) do
  253. sub_tab_index = sub_tab_index or value.id
  254. if self:CheckCanActive(true, index, value.id) then
  255. return index, value.id
  256. end
  257. if first_can_up and self:CheckCanUp(true, index, value.id) then
  258. tab_index = index
  259. sub_tab_index = value.id
  260. first_can_up = false
  261. end
  262. end
  263. else
  264. local tab_list = self:GetUnlockType()
  265. for k, v in pairsByKeys(tab_list) do
  266. tab_index = tab_index or k
  267. local sub_tab_list = self:GetTabList(k)
  268. for kk, vv in pairsByKeys(sub_tab_list) do
  269. sub_tab_index = sub_tab_index or vv.id
  270. if self:CheckCanActive(true, k, vv.id) then
  271. return k, vv.id
  272. end
  273. if first_can_up and self:CheckCanUp(true, k, vv.id) then
  274. tab_index = k
  275. sub_tab_index = vv.id
  276. first_can_up = false
  277. end
  278. end
  279. end
  280. end
  281. -- print("Lizhijian:ShapeModel [start:254] tab_index, sub_tab_index ------------------------------------------")
  282. -- print(tab_index, sub_tab_index)
  283. return tab_index, sub_tab_index or 1
  284. end
  285. function ShapeModel:CheckCanActive( check_new,type_id,id )
  286. self.red_active[type_id] = self.red_active[type_id] or {}
  287. if check_new then
  288. self.red_active[type_id][id] = false
  289. local data = self:GetOneDataById( type_id,id )
  290. if self:GetIsActive(type_id,id) then
  291. self.red_active[type_id][id] = false
  292. else
  293. local conf = self:GetConfByStar( type_id,id,0 )
  294. if conf then
  295. self.red_active[type_id][id] = GoodsModel:getInstance():GetEnough( conf.cost )
  296. end
  297. end
  298. end
  299. return self.red_active[type_id][id]
  300. end
  301. function ShapeModel:CheckCanUp( check_new,type_id,id )
  302. self.red_up[type_id] = self.red_up[type_id] or {}
  303. if check_new then
  304. self.red_up[type_id][id] = false
  305. local data = self:GetOneDataById( type_id,id )
  306. if (not self:GetIsActive(type_id,id)) or self:GetIsMaxStar(type_id,id) then
  307. self.red_up[type_id][id] = false
  308. else
  309. local conf = self:GetConfByStar( type_id,id,data.star )
  310. if conf then
  311. self.red_up[type_id][id] = GoodsModel:getInstance():GetEnough( conf.cost )
  312. end
  313. end
  314. end
  315. return self.red_up[type_id][id]
  316. end
  317. --通过物品id获得配置
  318. function ShapeModel:GetConfByGoodsId( goods_id )
  319. self:SetGoodsIdConfList( )
  320. local show_data = self.goods_id_conf_list[goods_id]
  321. if show_data then
  322. local base_data = self:GetOneDataById(show_data.type, show_data.id)
  323. return self:GetConfByStar( show_data.type, show_data.id, base_data and base_data.star or 1 ) or false
  324. end
  325. return false
  326. end
  327. --设置缓存表
  328. function ShapeModel:SetGoodsIdConfList( )
  329. if not self.goods_id_conf_list then
  330. self.goods_id_conf_list = {}
  331. local temp_list = {}
  332. local temp_cost = false
  333. for k,v in pairs(Config.Fosterskin) do
  334. temp_list[v.type] = temp_list[v.type] or {}
  335. if v.star == 0 then
  336. if not temp_list[v.type][v.id] then
  337. temp_list[v.type][v.id] = true
  338. temp_cost = stringtotable(v.cost)
  339. if temp_cost[1] and temp_cost[1][2] then
  340. self.goods_id_conf_list[tonumber(temp_cost[1][2])] = {type = v.type,id = v.id}
  341. end
  342. end
  343. end
  344. end
  345. end
  346. end
  347. --通过物品id获得基础属性
  348. function ShapeModel:GetBaseAttrByGoodsId( goods_id )
  349. self:SetGoodsIdConfList( )
  350. local show_data = self.goods_id_conf_list[goods_id]
  351. if show_data then
  352. local conf = self:GetConfByStar( show_data.type, show_data.id,1 )
  353. return stringtotable(conf.attrs)
  354. else
  355. return {}
  356. end
  357. end
  358. --通过物品id获得是否可以有升级/激活
  359. function ShapeModel:GetRedByGoodsId( goods_id )
  360. self:SetGoodsIdConfList( )
  361. local show_data = self.goods_id_conf_list[goods_id]
  362. if show_data then
  363. return self:CheckRedById(true,show_data.type,show_data.id)
  364. else
  365. return false
  366. end
  367. end
  368. -- 快捷使用判断走这个
  369. function ShapeModel:CheckCanUse(goods_vo)
  370. local goods_id = goods_vo.type_id
  371. local goods_num = goods_vo.goods_num
  372. -- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id)
  373. self:SetGoodsIdConfList( )
  374. local show_data = self.goods_id_conf_list[goods_id]
  375. local type_id = show_data.type
  376. local id = show_data.id
  377. local can_active = false
  378. local can_up = false
  379. -- 激活
  380. if self:GetIsActive(type_id,id) then
  381. can_active = false
  382. else
  383. local conf = self:GetConfByStar( type_id,id,0 )
  384. if conf then
  385. local cost = stringtotable(conf.cost)
  386. if cost[1][3] <= goods_num then
  387. can_active = true
  388. end
  389. end
  390. end
  391. -- 升星
  392. if (not self:GetIsActive(type_id,id)) or self:GetIsMaxStar(type_id,id) then
  393. can_up = false
  394. else
  395. local data = self:GetOneDataById( type_id,id )
  396. local conf = self:GetConfByStar( type_id,id,data.star )
  397. if conf then
  398. local cost = stringtotable(conf.cost)
  399. if cost[1][3] <= goods_num then
  400. can_up = true
  401. end
  402. end
  403. end
  404. return can_up or can_active
  405. end
  406. function ShapeModel:GetPowerById( type_id, id )
  407. local base_data = self:GetOneDataById(type_id, id)
  408. local show_star = base_data and base_data.star or 0
  409. -------------------------
  410. --属性
  411. local conf = self:GetConfByStar(type_id, id,show_star)
  412. if not conf then return 0 end
  413. local base_attr = SortAttrList(stringtotable(conf.attrs))
  414. local next_conf = self:GetConfByStar(type_id, id,conf.next_star)
  415. -------------------------
  416. if not base_data then
  417. local next_attr = next_conf and stringtotable(next_conf.attrs) or {}
  418. base_attr = DeepCopy(next_attr)
  419. end
  420. -------------------------
  421. --技能
  422. local skill_info = stringtotable(conf.skills)[1]
  423. if not base_data then
  424. skill_info = stringtotable(next_conf.skills)[1]
  425. end
  426. -------------------------
  427. local _,skill_power = GetSkillAttrBySkill( skill_info[1], skill_info[2], true ,base_data)
  428. if base_data then
  429. return GetFighting(base_attr,true) + skill_power
  430. else
  431. return GetFighting(base_attr,false) + skill_power
  432. end
  433. end