local DyeAppearance_Model = {} local DyeAppearanceInfo = require('Modules/DyeAppearance/DyeAppearanceInfo') local private = {} local EventSystem = require('Event/EventSystem') function DyeAppearance_Model.OnStartup() private.dyeAppearanceInfo = DyeAppearanceInfo:new() NetManager.RegisterMsgCB(MessageEnums.MessageSetCurColor, private.OnSetCurColorResp) NetManager.RegisterMsgCB(MessageEnums.MessageDrawColor, private.OnDrawColorResp) end function DyeAppearance_Model.SetDyeAppearanceInfos(dyeAppearanceInfos, isInit) private.dyeAppearanceInfo:SetDyeAppearanceInfos(dyeAppearanceInfos) if isInit == false then EventSystem.Dispatch(EventID.UI_DyeAppearance_UpdateInfo) end end --典藏时装是否激活 function DyeAppearance_Model.GetIsAppearanceActive(appearanceId) return private.dyeAppearanceInfo:GetIsAppearanceActive(appearanceId) end function DyeAppearance_Model.GetCurDyePartColorId(appearanceId, partIndex) if partIndex then return select(partIndex, private.dyeAppearanceInfo:GetCurDyePartColorId(appearanceId)) end return private.dyeAppearanceInfo:GetCurDyePartColorId(appearanceId) end function DyeAppearance_Model.GetDyeAppearancePartList(appearanceId) local color1, color2, color3, color4 = DyeAppearance_Model.GetCurDyePartColorId(appearanceId) if color1 and color2 and color3 and color4 then return table.pack(color1, color2, color3, color4) end return nil end function DyeAppearance_Model.GetDyeAppearanceCount() return private.dyeAppearanceInfo:GetDyeAppearanceCount() end --当前是否用了该色卡 function DyeAppearance_Model.IsColorDye(appearanceId, partIndex, colorId) local color = select(partIndex, DyeAppearance_Model.GetCurDyePartColorId(appearanceId)) return color == colorId end function DyeAppearance_Model.IsColorActive(appearanceId, partIndex, colorId) return private.dyeAppearanceInfo:GetIsColorActive(appearanceId, partIndex, colorId) end function DyeAppearance_Model.GetPartActiveColorList(appearanceId, partIndex) return private.dyeAppearanceInfo:GetPartActiveColorList(appearanceId, partIndex) end function DyeAppearance_Model.GetDyeLibraryLevel(appearanceId) local list = private.dyeAppearanceInfo:GetDyeLibrarySuitList(appearanceId) if list then return #list end return 0 end function DyeAppearance_Model.IsSuitActiveInDyeLibrary(appearanceId, suitId) local list = private.dyeAppearanceInfo:GetDyeLibrarySuitList(appearanceId) if list then return table.containValue(list, suitId) end return false end function DyeAppearance_Model.GetAppearanceLibraryLevel(appearanceId) return private.dyeAppearanceInfo:GetAppearanceLibraryLevel(appearanceId) end function DyeAppearance_Model.SetCurColorReq(appearanceId, colorList, withoutTips) local msg = NetManager.GetPB("dye_appearance_opt_pb").SetCurColorReq() msg.appearanceId = appearanceId for i = 1, CTL.DyeAppearance.PartCount do local color = colorList[i] if color == nil or DyeAppearance_Model.IsColorActive(appearanceId, i, color) == false then --如果该色卡没激活,替换成当前染色的色卡 color = DyeAppearance_Model.GetCurDyePartColorId(appearanceId, i) end local info = NetManager.GetPB("dye_appearance_opt_pb").SetColorInfo() info.partId = i info.curColorId = color table.insert(msg.setColorInfo, info) end private.withoutTips = withoutTips NetManager.SendMessage(MessageEnums.MessageSetCurColor, msg) end function private.OnSetCurColorResp(msgResp) if msgResp.Resp.Code == 0 then if not private.withoutTips then CTL.Tips.AddTipsMsg(Const_IDS.IDS_CollectionAP_Tip6) CTL.Sound.PlayGameSound("UI_equipment_02") end private.dyeAppearanceInfo:UpdateDyeColor(msgResp.appearanceId, msgResp.setColorInfo) CTL.DyeAppearance.RecoverDyeRecord(msgResp.appearanceId) EventSystem.Dispatch(EventID.UI_DyeAppearance_UpdateModelDye) end end function DyeAppearance_Model.DrawColorReq(appearanceId, partId) local msg = NetManager.GetPB("dye_appearance_opt_pb").DrawColorReq() msg.appearanceId = appearanceId msg.partId = partId NetManager.SendMessage(MessageEnums.MessageDrawColor, msg) end function private.OnDrawColorResp(msgResp) if msgResp.Resp.Code == 0 then CTL.DyeAppearance.RecordLastDrawColorId(msgResp.appearanceId, msgResp.partInfo.partId, msgResp.drawColorId) CTL.DyeAppearance.AddNoticeColor(msgResp.drawColorId, msgResp.partInfo.partId, msgResp.appearanceId) --先做完表现再更新数据 EventSystem.Dispatch(EventID.UI_DyeAppearance_OnDrawColorFinish, msgResp.drawColorId) private.dyeAppearanceInfo:UpdatePartInfo(msgResp.appearanceId, msgResp.partInfo) EventSystem.Dispatch(EventID.UI_DyeAppearance_UpdateInfo) else MDL.Player.SetDelayGSExpFlag(false) end end return DyeAppearance_Model