------------------------------------------------ --作者: 王圣 --日期: 2020-03-23 --文件: NewFashionSystem.lua --模块: NewFashionSystem --描述: 新时装系统类 ------------------------------------------------ --引用 --图鉴数据 local L_TuJianData = require "Logic.NewFashion.FashionTuJianData" local L_FashionData = require "Logic.NewFashion.FashionData" local L_ListTuJianData = List:New() local L_ListFashionData = List:New() local L_DicFashionData = Dictionary:New() local L_DicTotalFashionData = Dictionary:New() local L_RedPointItemCondition = CS.Thousandto.Code.Logic.RedPointItemCondition local NewFashionSystem = { DefaultList = List:New(), IsShowActive = false, --玩家穿戴时装字典 WearDic = Dictionary:New(), } function NewFashionSystem:Initialize() end function NewFashionSystem:UnInitialize() -- L_ListTuJianData:Clear() -- L_ListFashionData:Clear() end --更新玩家穿戴列表 function NewFashionSystem:UpdateWearList(wearList) if wearList == nil then return end --更新时装的穿戴 self:UpdateWearFashion(wearList) --更新衣柜的穿戴 self:UpdateTotalWear(wearList) end --添加进穿戴字典 function NewFashionSystem:SetWearData(data, type) self.WearDic[type] = data end --改时装是否穿戴 function NewFashionSystem:IsWear(data) if data == nil then return false end local type = data:GetType() local wearData = self.WearDic[type] return data:GetCfgId() == wearData:GetCfgId() end --时装激活升星红点更新 function NewFashionSystem:UpdateFashionRedPoint() GameCenter.RedPointSystem:CleraFuncCondition(FunctionStartIdCode.Fashion) local dic = self:GetFashionDataDic() if dic == nil then return end local keys = dic:GetKeys() if keys == nil then return end local isShow = false local occ = GameCenter.GameSceneSystem:GetLocalPlayer().IntOcc for i = 1, #keys do local dataList = dic[keys[i]] if dataList ~= nil then for m = 1, #dataList do local data = dataList[m] if data.IsActive then --如果时装激活了 就判断是否可以升星 if not isShow then isShow = data:CanUpStar(occ) end if data.StarNum < 5 then local itemId = data:GetItemId(occ) local needNum = data:GetNeedItemNum(data.StarNum) GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.Fashion, data:GetCfgId(), L_RedPointItemCondition(itemId, needNum)) end else --如果没有激活 判断是否可以激活 if not isShow then isShow = data:CanActive(occ) end local itemId = data:GetItemId(occ) local needNum = data:GetNeedItemNum(0) GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.Fashion, data:GetCfgId(), L_RedPointItemCondition(itemId, needNum)) end end end end --GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.Fashion,isShow) end --时装图鉴红点更新 function NewFashionSystem:UpdateTjRedPoint() local dataList = self:GetTuJianDatas() if dataList == nil then return end local isShow = false for i = 1, #dataList do local data = dataList[i] if data.IsActive then --如果激活了 local lowStarNum = self:GetLowStarLv(i) if data.StarNum < lowStarNum and not isShow then isShow = true break end else --没有激活 local allActive = GameCenter.NewFashionSystem:IsCollectAll(i) if allActive and not isShow then isShow = true break end end end GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.FashionTj,isShow) end --时装衣柜红点更新 function NewFashionSystem:UpdateTotalRedPoint() local dic = self:GetTotalDataDic() if dic == nil then return end local keys = dic:GetKeys() if keys == nil then return end local isShow = false for i = 1, #keys do local dataList = dic[keys[i]] if dataList ~= nil then for m = 1 ,#dataList do local data = dataList[m] if data.IsNew and not isShow and data:GetType() <= 10 then isShow = true end end end end GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.Wardrobe,isShow) end -----------------------------------------------------消息----------------------------------------------------- --请求激活时装 function NewFashionSystem:ReqActiveFashion(id) GameCenter.Network.Send("MSG_NewFashion.ReqActiveFashion", {fashionID = id}) end --请求穿戴时装 function NewFashionSystem:ReqSaveFashion(ids) GameCenter.Network.Send("MSG_NewFashion.ReqSaveFashion", {wearIds = ids}) end --请求激活图鉴 function NewFashionSystem:ReqActiveTj(id) GameCenter.Network.Send("MSG_NewFashion.ReqActiveTj", {tjID = id}) end --请求时装升星 function NewFashionSystem:ReqTjStar(id) GameCenter.Network.Send("MSG_NewFashion.ReqTjStar", {tjID = id}) end --请求图鉴升星 function NewFashionSystem:ReqFashionStar(id) GameCenter.Network.Send("MSG_NewFashion.ReqFashionStar", {fashionID = id}) end --上线发送的激活了的时装列表 function NewFashionSystem:ResOnlineInitFashionInfo(msg) if msg == nil then return end self:UpdateActiveFashion(msg.activeIds) self:UpdateTotalActive(msg.activeIds) self:UpdateWearList(msg.wearData) self:UpdateTjDatas(msg.activeTjs) --更新红点 self:UpdateFashionRedPoint() self:UpdateTjRedPoint() self:UpdateTotalRedPoint() end --穿戴(激活)时装后的返回 function NewFashionSystem:ResSaveFashionResult(msg) if msg == nil then return end if msg.isActivate then --有新的时装激活 local list = List:New() list:Add(msg.activateID) self:UpdateActiveFashion(list) self:UpdateTotalActive(list) --展示新时装模型 if msg.activateID ~= nil then local data = self:GetFashionData(msg.activateID.fashionID) if data ~= nil then data.IsNew = true end data = self:GetTotalData(msg.activateID.fashionID) if data ~= nil then if data:GetCfg().IfNew == 0 then data.IsNew = true end local _iswear = true local type = data:GetType() if type == FashionType.Body then type = ShowModelType.Player elseif type == FashionType.Weapon then type = ShowModelType.LpWeapon elseif type == FashionType.Wing then type = ShowModelType.Wing elseif type == FashionType.Mount then type = ShowModelType.Mount _iswear = false elseif type == FashionType.Pet then type = ShowModelType.Pet _iswear = false elseif type == FashionType.FaBao then type = ShowModelType.FaBao _iswear = false elseif type == FashionType.HunJia then type = ShowModelType.SoulEquip end local occ = GameCenter.GameSceneSystem:GetLocalPlayer().IntOcc -- if type == ShowModelType.Player or type == ShowModelType.LpWeapon then -- GameCenter.ModelViewSystem:ShowModel(type, data:GetModelId(occ), 200, 0 , data:GetName(), true, msg.activateID.fashionID) -- end if data.Cfg.IsShow == 1 then GameCenter.ModelViewSystem.IsStartTaskOnHide = data.Cfg.IsTask == 1 GameCenter.ModelViewSystem:ShowModel(type, data:GetModelId(occ), data.Cfg.ShowCameraSize, data.Cfg.ShowModelYPos/100 , data:GetName(), _iswear, msg.activateID.fashionID) end end self:UpdateTjData(msg.activateID.fashionID) end end --没有时装激活只是穿戴更新 self:UpdateWearList(msg.retData) if msg.retData ~= nil then --更新图鉴数据 for i = 1, #msg.retData do local acData = msg.retData[i] self:UpdateTjData(acData.fashionID) end end GameCenter.PushFixEvent(LogicLuaEventDefine.EID_FASHION_ACTIVE_RESULT) GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_NEWFASHION_CHANGE) --更新红点 self:UpdateFashionRedPoint() self:UpdateTjRedPoint() self:UpdateTotalRedPoint() end --时装升星返回 function NewFashionSystem:ResFashionStarResult(msg) if msg == nil then return end self:UpdateFashion(msg.retData) self:UpdateTjData(msg.retData.fashionID) GameCenter.PushFixEvent(LogicLuaEventDefine.EID_FASHION_UPSTAR_RESULT) self:UpdateFashionRedPoint() self:UpdateTjRedPoint() end --图鉴激活返回 function NewFashionSystem:ResActiveTjResult(msg) if msg == nil then return end local data = self:GetTuJianData(msg.tjData.tjID) if data ~= nil then data.IsActive = true end GameCenter.PushFixEvent(LogicLuaEventDefine.EID_FASHION_TUJIAN_ACTIVE) self:UpdateTjRedPoint() end --图鉴升星返回 function NewFashionSystem:ResTjStarResult(msg) if msg == nil then return end local data = self:GetTuJianData(msg.tjData.tjID) if data ~= nil then data.StarNum = msg.tjData.star end GameCenter.PushFixEvent(LogicLuaEventDefine.EID_FASHION_TUJIAN_UPSTAR) self:UpdateTjRedPoint() end --广播装备新时装,,发生改变后广播 当前地图 范围内玩家 function NewFashionSystem:ResNewFashionBodyBroadcast(msg) local player = GameCenter.GameSceneSystem:FindPlayer(msg.playerId) if player == nil then return end if msg.retData ~= nil then for i = 1, #msg.retData do local ret = msg.retData[i] if ret.type == FashionType.Body then player.FashionBodyID = ret.fashionID elseif ret.type == FashionType.Weapon then player.FashionWeaponID = ret.fashionID elseif ret.type == FashionType.Wing then player.WingID = ret.fashionID player:EquipWithType(FSkinPartCode.Wing, RoleVEquipTool.GetLPWingModel()) end GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_FASHION_UPDATECHANGE) end end end --=======================================衣柜处理--======================================= --获取衣柜的所有数据 function NewFashionSystem:GetTotalDataDic() if L_DicTotalFashionData:Count() == 0 then DataConfig.DataFashionTotal:Foreach(function(k, v) local data = L_FashionData:New(k,v) local list = nil if L_DicTotalFashionData:ContainsKey(v.Type) then list = L_DicTotalFashionData[v.Type] list:Add(data) else list = List:New() list:Add(data) L_DicTotalFashionData:Add(v.Type, list) end end) end return L_DicTotalFashionData end --获取衣柜中激活的时装列表 function NewFashionSystem:GetTotalActiveList(type) local dic = self:GetTotalDataDic() if dic == nil then return nil end local activeList = List:New() local list = dic[type] if list == nil then return nil end for i = 1, #list do local data = list[i] if data.IsActive and data:GetType() <= 10 then activeList:Add(data) end end return activeList end --获取衣柜中的时装数据 function NewFashionSystem:GetTotalData(fashionId) local dic = self:GetTotalDataDic() if dic == nil then return nil end local keys = dic:GetKeys() if keys == nil then return nil end for i = 1, #keys do local key = keys[i] local dataList = dic[key] if dataList ~= nil then for m = 1, #dataList do local data = dataList[m] if data:GetCfgId() == fashionId then return data end end end end return nil end --判断是否有新激活的时装 function NewFashionSystem:HaveNewByType(type) local list = self:GetTotalActiveList(type) if list == nil then return false end local ret = false for i = 1, #list do local data = list[i] if not ret and data.IsNew then ret = true end end return ret end --是否激活 function NewFashionSystem:IsActive(fashionId) local data = self:GetTotalData(fashionId) if data == nil then return false end return data.IsActive end function NewFashionSystem:GetTotalDataByModelId(id, occ) local dic = self:GetTotalDataDic() --IsEquialWithModelId if dic == nil then return nil end local keys = dic:GetKeys() if keys == nil then return end for i = 1, #keys do local key = keys[i] local dataList = dic[key] if dataList ~= nil then for m = 1, #dataList do local data = dataList[m] if data:IsEquialWithModelId(id, occ) then return data end end end end return nil end function NewFashionSystem:UpdateTotalActive(dataList) local dic = self:GetTotalDataDic() if dic == nil then return end if dataList == nil then return end for i = 1, #dataList do local acData = dataList[i] local list = dic[acData.type] if list ~= nil then for m = 1, #list do local data = list[m] if data:GetCfgId() == acData.fashionID then data.IsActive = true end end end end end --更新衣柜的穿戴 function NewFashionSystem:UpdateTotalWear(dataList) local dic = self:GetTotalDataDic() if dic == nil then return end if dataList == nil then return end for i = 1, #dataList do local acData = dataList[i] local list = dic[acData.type] if list ~= nil then for m = 1, #list do local data = list[m] data.IsWear = false if data:GetCfgId() == acData.fashionID then data.IsWear = true self:SetWearData(data, acData.type) end end end end end --=======================================图鉴处理--======================================= --获取图鉴数据 function NewFashionSystem:GetTuJianDatas() if #L_ListTuJianData == 0 then --初始化图鉴数据 DataConfig.DataFashionLink:Foreach(function(k, v) local data = L_TuJianData:New(k,v) L_ListTuJianData:Add(data) end) end return L_ListTuJianData end --根据index获取图鉴数据 function NewFashionSystem:GetTuJianData(index) local dataList = self:GetTuJianDatas() if dataList ~= nil and index <= #dataList then return dataList[index] end return nil end --获取index对应图鉴里时装的最低星级 function NewFashionSystem:GetLowStarLv(index) local ret = 999 local data = nil local dataList = self:GetTuJianDatas() if dataList ~= nil and index <= #dataList then data = dataList[index] local fashionList = data:GetNeedDataList() if fashionList == nil then return ret end for i = 1, #fashionList do local id = fashionList[i].FashionId local fashionData = self:GetFashionData(id) local num = fashionData:GetStarNum() if ret > num then ret = num end end end return ret end --判断index对应图鉴需要的时装是否都收集齐了 function NewFashionSystem:IsCollectAll(index) local data = nil local dataList = self:GetTuJianDatas() if dataList ~= nil and index <= #dataList then data = dataList[index] local fashionList = data:GetNeedDataList() if fashionList == nil then return false end for i = 1, #fashionList do local isActive = fashionList[i].IsActive if not isActive then return false end end end return true end --更新图鉴数据 function NewFashionSystem:UpdateTjDatas(activeTjs) local dataList = self:GetTuJianDatas() if dataList == nil then return end for i = 1, #dataList do local data = dataList[i] data:UpdateNeedDataList() end if activeTjs ~= nil then for i = 1, #dataList do dataList[i].IsActive = false end for i = 1, #activeTjs do for m = 1, #dataList do if dataList[m]:GetCfgId() == activeTjs[i].tjID then dataList[m].IsActive = true dataList[m].StarNum = activeTjs[i].star end end end end end --更新图鉴数据 function NewFashionSystem:UpdateTjData(fashionId) local fashionData = self:GetFashionData(fashionId) local dataList = self:GetTuJianDatas() if dataList == nil then return end for i = 1, #dataList do local data = dataList[i] data:SetNeedData(fashionData) end end --=======================================时装处理--======================================= --获取时装的所有数据 function NewFashionSystem:GetFashionDatas() if #L_ListFashionData == 0 then --初始化图鉴数据 DataConfig.DataFashion:Foreach(function(k, v) local data = L_FashionData:New(k,v) L_ListFashionData:Add(data) end) end return L_ListFashionData end --获取时装所有数据 function NewFashionSystem:GetFashionDataDic() if L_DicFashionData:Count() == 0 then DataConfig.DataFashion:Foreach(function(k, v) local data = L_FashionData:New(k,v) local list = nil if L_DicFashionData:ContainsKey(v.Type) then list = L_DicFashionData[v.Type] list:Add(data) else list = List:New() list:Add(data) L_DicFashionData:Add(v.Type, list) end end) end return L_DicFashionData end --获取type对应的时装列表 function NewFashionSystem:GetFashionList(type) local retList = List:New() local dic = self:GetFashionDataDic() if dic ~= nil then local list = dic[type] if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfg().IsHide ~= 1 then retList:Add(data) end end end end return retList end function NewFashionSystem:GetAllFashionList(type) local retList = nil local dic = self:GetFashionDataDic() if dic ~= nil then retList = dic[type] end return retList end --获取时装数据 function NewFashionSystem:GetFashionData(fashionId) local dic = self:GetFashionDataDic() if dic == nil then return nil end local keys = dic:GetKeys() if #keys == 0 then return nil end for i = 1,#keys do local list = dic[keys[i]] for m = 1,#list do local data = list[m] if data:GetCfgId() == fashionId then return data end end end return nil end --更新时装 function NewFashionSystem:UpdateFashion(data) local dic = self:GetFashionDataDic() if dic == nil then return end if data == nil then return end local list = dic[data.type] if list ~= nil then for m = 1, #list do if list[m]:GetCfgId() == data.fashionID then list[m].StarNum = data.star end end end end --更新时装激活数据 function NewFashionSystem:UpdateActiveFashion(dataList) local dic = self:GetFashionDataDic() if dic == nil then return end if dataList == nil then return end for i = 1, #dataList do local acData = dataList[i] local list = dic[acData.type] if list ~= nil then for m = 1, #list do local data = list[m] if data:GetCfgId() == acData.fashionID then data.IsActive = true data.StarNum = acData.star end end end end end --更新时装穿戴数据 function NewFashionSystem:UpdateWearFashion(dataList) local dic = self:GetFashionDataDic() if dic == nil then return end if dataList == nil then return end for i = 1, #dataList do local acData = dataList[i] local list = dic[acData.type] if list ~= nil then for m = 1, #list do local data = list[m] data.IsWear = false if data:GetCfgId() == acData.fashionID then data.IsWear = true data.StarNum = acData.star self:SetWearData(data, acData.type) end end end end end --获取头像数据 function NewFashionSystem:GetPlayerHeadData() local ret = nil local list = self:GetAllFashionList(ShowModelType.Head) if list ~= nil then for i = 1, #list do local data = list[i] if data.IsActive and data.IsWear then ret = data break end end end return ret end --获取头像框数据 function NewFashionSystem:GetPlayerHeadFrameData() local ret = nil local list = self:GetAllFashionList(ShowModelType.Frame) if list ~= nil then for i = 1, #list do local data = list[i] if data.IsActive and data.IsWear then ret = data break end end end return ret end --获取聊天泡泡数据 function NewFashionSystem:GetPlayerPaoPaoData() local ret = nil local list = self:GetAllFashionList(ShowModelType.PaoPao) if list ~= nil then for i = 1, #list do local data = list[i] if data.IsActive and data.IsWear then ret = data break end end end return ret end function NewFashionSystem:GetPlayerHeadDataById(id) local ret = nil local list = self:GetAllFashionList(ShowModelType.Head) if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfgId() == id then ret = data break end end end return ret end function NewFashionSystem:GetPlayerHeadFrameDataById(id) local ret = nil local list = self:GetAllFashionList(ShowModelType.Frame) if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfgId() == id then ret = data break end end end return ret end function NewFashionSystem:GetPlayerPaoPaoDataById(id) local ret = nil local list = self:GetAllFashionList(ShowModelType.PaoPao) if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfgId() == id then ret = data break end end end return ret end --获取默认头像数据 function NewFashionSystem:GetPlayerHeadDefaultData() local ret = nil local list = self:GetAllFashionList(ShowModelType.Head) if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfg().IsHide == 1 then ret = data break end end end return ret end --获取默认头像框数据 function NewFashionSystem:GetPlayerHeadFrameDefaultData() local ret = nil local list = self:GetAllFashionList(ShowModelType.Frame) if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfg().IsHide == 1 then ret = data break end end end return ret end --获取默认聊天泡泡数据 function NewFashionSystem:GetPlayerPaoPaoDefaultData() local ret = nil local list = self:GetAllFashionList(ShowModelType.PaoPao) if list ~= nil then for i = 1, #list do local data = list[i] if data:GetCfg().IsHide == 1 then ret = data break end end end return ret end return NewFashionSystem