ShapeModel = ShapeModel or BaseClass(BaseVo, true) local ShapeModel = ShapeModel ShapeModel.REQ_BASE_INFO = 'ShapeModel.REQ_BASE_INFO' -- 基础珍宝信息 ShapeModel.ANS_BASE_INFO = 'ShapeModel.ANS_BASE_INFO' -- 基础珍宝信息 ShapeModel.REQ_UP_OR_ACTIVE = 'ShapeModel.REQ_UP_OR_ACTIVE' -- 进阶or激活 ShapeModel.ANS_UP_OR_ACTIVE = 'ShapeModel.ANS_UP_OR_ACTIVE' -- 进阶or激活 ShapeModel.REQ_CHANGE_SKIN = 'ShapeModel.REQ_CHANGE_SKIN' -- 换肤 ShapeModel.ANS_CHANGE_SKIN = 'ShapeModel.ANS_CHANGE_SKIN' -- 换肤 ShapeModel.RedDotRefresh = 'ShapeModel.RedDotRefresh' -- 红点 ShapeModel.OPEN_BASE_VIEW = 'ShapeModel.OPEN_BASE_VIEW' -- 主界面 ShapeModel.OPEN_SUCCESS_VIEW = 'ShapeModel.OPEN_SUCCESS_VIEW' -- 成功界面 function ShapeModel:__init() ShapeModel.Instance = self self:Reset() end function ShapeModel:Reset() self.base_data = {} self.show_tab_list = {} self.show_model_resource_list = {} self.show_tab_type_list = false self.goods_id_conf_list = false--物品id对照表 ------------------------- self.red_active = {} self.red_up = {} end function ShapeModel:GetInstance() if ShapeModel.Instance == nil then ShapeModel.Instance = ShapeModel.New() end return ShapeModel.Instance end function ShapeModel:getInstance() if ShapeModel.Instance == nil then ShapeModel.Instance = ShapeModel.New() end return ShapeModel.Instance end --基础信息 function ShapeModel:GetBaseData( type_id ) if type_id then return self.base_data[type_id] or {} else return self.base_data end end --获取某类型数据 function ShapeModel:SetBaseData( data ) if data and data.type then self.base_data[data.type] = data.skins self:SetFightValData(data.type) end end --获得单条数据 function ShapeModel:GetOneDataById( type_id,id ) if type_id and id and self.base_data[type_id] then for k,v in pairs(self.base_data[type_id]) do if v.id == id then return v end end end end --更新单数据 function ShapeModel:RefreshOneData( type_id,id,key,value ) local data = self:GetOneDataById(type_id,id) if data and key then data[key] = value return true end return false end -- 设置珍宝战力数据 function ShapeModel:SetFightValData(type_id) self.fightValList = self.fightValList or {} self.fightValList[type_id] = self.fightValList[type_id] or {} --属性 for key, value in pairs(self.base_data[type_id]) do local conf = self:GetConfByStar( type_id, value.id, value.star ) if conf then local base_attr = SortAttrList(stringtotable(conf.attrs)) --技能 local skill_info = stringtotable(conf.skills)[1] local _,skill_power = GetSkillAttrBySkill( skill_info[1], skill_info[2], true ,value) self.fightValList[type_id][value.id] = GetFighting(base_attr,true) + skill_power end end end -- 获取珍宝战力(默认当前已激活珍宝) function ShapeModel:GetFightValOneData(type_id, id) if type_id and self.fightValList and self.fightValList[type_id] then local res = 0 for key, value in pairs(self.fightValList[type_id]) do if self:GetIsActive(type_id, key) then res = res + (self.fightValList[type_id][key] or 0) end end return res else return 0 end end --更新使用皮肤 function ShapeModel:RefreshSkinUsing( type_id,skin,star ) local bool = false if self.base_data[type_id] then for k,v in pairs(self.base_data[type_id]) do if v.id == skin then v.display = star bool = bool or (star > 0) else v.display = 0 end end end return bool end --获得当前使用中的皮肤 function ShapeModel:GetUsingByType( type_id ) if self.base_data[type_id] then for k,v in pairs(self.base_data[type_id]) do if v.display > 0 then return v.id,v.display end end end return 0,1 end --获得配置 function ShapeModel:GetConfByStar( type_id,id,star ) return Config.Fosterskin[type_id .. "@" .. id .. "@" .. star] end function ShapeModel:GetModelRes( main_type, id, star ) local conf = self:GetConfByStar(main_type, id ,star) return conf and conf.model or 0 end --是否满级 function ShapeModel:GetIsMaxStar( type_id,id ) local base = self:GetOneDataById(type_id,id) if base then local conf = self:GetConfByStar(type_id,id,base.star) return not (base.star > 0 and conf.next_star~=0) end return false end --是否已激活 function ShapeModel:GetIsActive( type_id,id ) local base = self:GetOneDataById(type_id,id) return base and base.star > 0 end ------------------------- --获取已经解锁的珍宝大类 function ShapeModel:GetUnlockType( ) if not self.show_tab_type_list then self.show_tab_type_list = {} for k,v in pairs(Config.Fosterskin) do self.show_tab_type_list[v.type] = true end end return self.show_tab_type_list end --获取模型资源列表 function ShapeModel:GetModelList( type_id,id ) self.show_model_resource_list[type_id] = self.show_model_resource_list[type_id] or {} if not self.show_model_resource_list[type_id][id] then self.show_model_resource_list[type_id][id] = {} local temp = {}--资源对应的最小阶数 for k,v in pairs(Config.Fosterskin) do if v.type == type_id and v.id == id then if not temp[v.model] then temp[v.model] = v.star else temp[v.model] = temp[v.model] < v.star and temp[v.model] or v.star end end end for k,v in pairs(temp) do table.insert( self.show_model_resource_list[type_id][id], {min_star = v, source_id = k} ) end local function sort_call( a,b ) return a.min_star < b.min_star end table.sort( self.show_model_resource_list[type_id][id], sort_call ) end return self.show_model_resource_list[type_id][id] end --是否显示珍宝 function ShapeModel:CanShowSkin( type_id, id ) --增加限制条件,不显示部分条目类型 -- 未激活&限制条件中&无激活道具 local conf = self:GetConfByStar( type_id,id,0 ) if not self:GetIsActive( type_id,id ) then--未激活 if not GoodsModel:getInstance():GetEnough( conf.cost ) then--无激活道具 if (conf.open_day > 0) and conf.open_day > ServerTimeModel:getInstance():GetOpenServerDay() then --开服条件未符合 return false end if (conf.time > 0) and (conf.time > TimeUtil:getServerTime()) then --开放事件不符合 return false end end end return true end function ShapeModel:GetTabList( type_id ) local need_show = true local show_tab_list = {} for k,v in pairs(Config.Fosterskin) do if v.star == 0 and v.type == type_id then if self:CanShowSkin( type_id, v.id ) then table.insert( show_tab_list, v ) end end end ------------------------- local function sort_call( a,b ) return a.order < b.order end table.sort( show_tab_list, sort_call ) return show_tab_list end function ShapeModel:CheckRedDot( check_new ) local bool = false local list = self:GetUnlockType() for k,v in pairs(list) do bool = self:CheckRedByType(check_new,k) or bool end return bool end function ShapeModel:CheckRedByType( check_new,type_id ) local bool = false local list = self:GetTabList( type_id ) for k,v in pairs(list) do bool = self:CheckRedById(check_new,type_id,v.id) or bool end return bool end function ShapeModel:CheckRedById( check_new,type_id,id ) if check_new then self:CheckCanActive( check_new,type_id,id ) self:CheckCanUp( check_new,type_id,id ) end 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]) end -- 打开界面或切换页签时默认显示可激活或可进阶的珍宝 function ShapeModel:GetDefaultShowTabIndex(index) local tab_index = index local sub_tab_index local first_can_up = true if index then local sub_tab_list = self:GetTabList(index) for key, value in pairsByKeys(sub_tab_list) do sub_tab_index = sub_tab_index or value.id if self:CheckCanActive(true, index, value.id) then return index, value.id end if first_can_up and self:CheckCanUp(true, index, value.id) then tab_index = index sub_tab_index = value.id first_can_up = false end end else local tab_list = self:GetUnlockType() for k, v in pairsByKeys(tab_list) do tab_index = tab_index or k local sub_tab_list = self:GetTabList(k) for kk, vv in pairsByKeys(sub_tab_list) do sub_tab_index = sub_tab_index or vv.id if self:CheckCanActive(true, k, vv.id) then return k, vv.id end if first_can_up and self:CheckCanUp(true, k, vv.id) then tab_index = k sub_tab_index = vv.id first_can_up = false end end end end -- print("Lizhijian:ShapeModel [start:254] tab_index, sub_tab_index ------------------------------------------") -- print(tab_index, sub_tab_index) return tab_index, sub_tab_index or 1 end function ShapeModel:CheckCanActive( check_new,type_id,id ) self.red_active[type_id] = self.red_active[type_id] or {} if check_new then self.red_active[type_id][id] = false local data = self:GetOneDataById( type_id,id ) if self:GetIsActive(type_id,id) then self.red_active[type_id][id] = false else local conf = self:GetConfByStar( type_id,id,0 ) if conf then self.red_active[type_id][id] = GoodsModel:getInstance():GetEnough( conf.cost ) end end end return self.red_active[type_id][id] end function ShapeModel:CheckCanUp( check_new,type_id,id ) self.red_up[type_id] = self.red_up[type_id] or {} if check_new then self.red_up[type_id][id] = false local data = self:GetOneDataById( type_id,id ) if (not self:GetIsActive(type_id,id)) or self:GetIsMaxStar(type_id,id) then self.red_up[type_id][id] = false else local conf = self:GetConfByStar( type_id,id,data.star ) if conf then self.red_up[type_id][id] = GoodsModel:getInstance():GetEnough( conf.cost ) end end end return self.red_up[type_id][id] end --通过物品id获得配置 function ShapeModel:GetConfByGoodsId( goods_id ) self:SetGoodsIdConfList( ) local show_data = self.goods_id_conf_list[goods_id] if show_data then local base_data = self:GetOneDataById(show_data.type, show_data.id) return self:GetConfByStar( show_data.type, show_data.id, base_data and base_data.star or 1 ) or false end return false end --设置缓存表 function ShapeModel:SetGoodsIdConfList( ) if not self.goods_id_conf_list then self.goods_id_conf_list = {} local temp_list = {} local temp_cost = false for k,v in pairs(Config.Fosterskin) do temp_list[v.type] = temp_list[v.type] or {} if v.star == 0 then if not temp_list[v.type][v.id] then temp_list[v.type][v.id] = true temp_cost = stringtotable(v.cost) if temp_cost[1] and temp_cost[1][2] then self.goods_id_conf_list[tonumber(temp_cost[1][2])] = {type = v.type,id = v.id} end end end end end end --通过物品id获得基础属性 function ShapeModel:GetBaseAttrByGoodsId( goods_id ) self:SetGoodsIdConfList( ) local show_data = self.goods_id_conf_list[goods_id] if show_data then local conf = self:GetConfByStar( show_data.type, show_data.id,1 ) return stringtotable(conf.attrs) else return {} end end --通过物品id获得是否可以有升级/激活 function ShapeModel:GetRedByGoodsId( goods_id ) self:SetGoodsIdConfList( ) local show_data = self.goods_id_conf_list[goods_id] if show_data then return self:CheckRedById(true,show_data.type,show_data.id) else return false end end -- 快捷使用判断走这个 function ShapeModel:CheckCanUse(goods_vo) local goods_id = goods_vo.type_id local goods_num = goods_vo.goods_num -- local goods_num = GoodsModel:getInstance():GetTypeGoodsNum(goods_id) self:SetGoodsIdConfList( ) local show_data = self.goods_id_conf_list[goods_id] local type_id = show_data.type local id = show_data.id local can_active = false local can_up = false -- 激活 if self:GetIsActive(type_id,id) then can_active = false else local conf = self:GetConfByStar( type_id,id,0 ) if conf then local cost = stringtotable(conf.cost) if cost[1][3] <= goods_num then can_active = true end end end -- 升星 if (not self:GetIsActive(type_id,id)) or self:GetIsMaxStar(type_id,id) then can_up = false else local data = self:GetOneDataById( type_id,id ) local conf = self:GetConfByStar( type_id,id,data.star ) if conf then local cost = stringtotable(conf.cost) if cost[1][3] <= goods_num then can_up = true end end end return can_up or can_active end function ShapeModel:GetPowerById( type_id, id ) local base_data = self:GetOneDataById(type_id, id) local show_star = base_data and base_data.star or 0 ------------------------- --属性 local conf = self:GetConfByStar(type_id, id,show_star) if not conf then return 0 end local base_attr = SortAttrList(stringtotable(conf.attrs)) local next_conf = self:GetConfByStar(type_id, id,conf.next_star) ------------------------- if not base_data then local next_attr = next_conf and stringtotable(next_conf.attrs) or {} base_attr = DeepCopy(next_attr) end ------------------------- --技能 local skill_info = stringtotable(conf.skills)[1] if not base_data then skill_info = stringtotable(next_conf.skills)[1] end ------------------------- local _,skill_power = GetSkillAttrBySkill( skill_info[1], skill_info[2], true ,base_data) if base_data then return GetFighting(base_attr,true) + skill_power else return GetFighting(base_attr,false) + skill_power end end