local skynet = require "skynet" local oo = require "Class" local log = require "Log" local pb = require "pb" local dataType = require "DataType" local errorInfo = require "ErrorInfo" local Illustration = oo.class() Illustration.IllustrationType_Furniture = 1 --家具图鉴 Illustration.IllustrationType_Clothes = 2 --服装图鉴 Illustration.IllustrationType_Plant = 3 --植物图鉴 Illustration.IllustrationType_Special = 4 --特殊图鉴 Illustration.IllustrationSubType_Furniture = 1 --家具套间 Illustration.IllustrationSubType_Clothes = 2 --服装套装 Illustration.IllustrationSubType_Flower = 3 --花卉 Illustration.IllustrationSubType_Gashapon = 4 --扭蛋 Illustration.IllustrationStatus_Achieve = 1 --已经完成 Illustration.IllustrationStatus_GainAward = 2 --领取奖励 function Illustration:Init() end --图鉴展示 function Illustration:Show( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SIllustrationShow", c2sData.data )) local data = {} local type = c2sData.data.type if not type then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else data.type = type data.illustrationId = self:GetAwardInfo( player ) data.item = {} if self.IllustrationType_Furniture == type then self:Get( player , dataType.GoodsType_Furniture , data.item ) --将家具的图鉴发给客户端 self:Get( player , dataType.GoodsType_Decorate , data.item ) --将装修的图鉴发给客户端 skynet.server.msgTips:Reduce( player , 17) elseif self.IllustrationType_Clothes == type then self:Get( player , dataType.GoodsType_Clothes , data.item ) self:Get( player , dataType.GoodsType_PetClothes, data.item ) skynet.server.msgTips:Reduce( player , 2) elseif self.IllustrationType_Plant == type then self:Get( player , dataType.GoodsType_Plant , data.item ) --将植物的图鉴发给客户端 skynet.server.msgTips:Reduce( player , 18) elseif self.IllustrationType_Special == type then self:Get( player , dataType.GoodsType_Plant , data.item ) skynet.server.msgTips:Reduce( player , 1) end end s2cData.cmd = pb.enum("MsgType","CMD_S2C_IllustrationShow") s2cData.data = assert(pb.encode("S2CIllustrationShow", data)) end --图鉴奖励 function Illustration:Award( player , c2sData , s2cData ) c2sData.data = assert(pb.decode("C2SIllustrationAward", c2sData.data )) local data = {} local IllustrationId = c2sData.data.id if not IllustrationId then s2cData.code = errorInfo.ErrorCode.ErrRequestParam else for k, v in pairs( player.gameData.illustration.awardInfo ) do if IllustrationId == v.id and self.IllustrationStatus_Achieve == v.status then --获取当前图鉴ID的配置 local cfgAllIllustration = skynet.server.gameConfig.Illustration local cfgCurIllustration = {} for k, v in pairs( cfgAllIllustration ) do if IllustrationId == v.id then cfgCurIllustration = v break end end --发放奖励 player:GiveReward( cfgCurIllustration.rewardId) v.status = self.IllustrationStatus_GainAward --消除红点 if self.IllustrationType_Furniture == cfgCurIllustration.type then skynet.server.msgTips:Reduce( player , 17 ) elseif self.IllustrationType_Clothes == cfgCurIllustration.type then skynet.server.msgTips:Reduce( player , 2 ) elseif self.IllustrationType_Plant == cfgCurIllustration.type then skynet.server.msgTips:Reduce( player , 18 ) elseif self.IllustrationType_Special == cfgCurIllustration.type then skynet.server.msgTips:Reduce( player , 1 ) end skynet.server.achieveTask:Modify( player , 40 , 1) log.info(string.format("玩家 %d 图鉴 发放奖励 图鉴ID %d" , player.userId , IllustrationId )) break end end end data.illustrationId = self:GetAwardInfo( player ) s2cData.cmd = pb.enum("MsgType","CMD_S2C_IllustrationAward") s2cData.data = assert(pb.encode("S2CIllustrationAward", data)) end --新增图鉴 function Illustration:Add( player , goodsType , goodsId ) local IllustrationType = nil local msgId = 0 if dataType.GoodsType_Furniture == goodsType then if skynet.server.gashapon:IsGashapon( goodsId ) then IllustrationType = self.IllustrationType_Special msgId = 1 else IllustrationType = self.IllustrationType_Furniture msgId = 17 end elseif dataType.GoodsType_Decorate == goodsType then IllustrationType = self.IllustrationType_Furniture msgId = 17 elseif dataType.GoodsType_Clothes == goodsType or dataType.GoodsType_PetClothes == goodsType then IllustrationType = self.IllustrationType_Clothes msgId = 2 elseif dataType.GoodsType_Plant == goodsType then IllustrationType = self.IllustrationType_Plant msgId = 18 end --非图鉴类型不处理 if nil == IllustrationType then return end --不存在就插入图鉴 if not self:IsExistGoods( player , goodsType , goodsId ) then table.insert( player.gameData.illustration.goodsInfo , { type = goodsType , id = goodsId } ) local data = {} data.item = { type = goodsType , id = goodsId } data.illustrationId = 0 --检查是否完成图鉴,完成了就通知客户端 local isAchieve,illustrationId = self:IsNewAchieve( player , IllustrationType ) if isAchieve then data.illustrationId = illustrationId skynet.server.msgTips:Add( player , msgId ) end skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_IllustrationUpdate" , data ) log.info(string.format("玩家 %d 图鉴 新增图鉴 图鉴类型 %d 商品类型 %d 商品ID %d" , player.userId , IllustrationType , goodsType , goodsId )) end end --是否存在图鉴商品 function Illustration:IsExistGoods( player , type , id ) for k, v in pairs( player.gameData.illustration.goodsInfo ) do if type == v.type and id == v.id then return true end end return false end --是否领取图鉴礼包 function Illustration:IsGainAward( player , id ) for k, v in pairs( player.gameData.illustration.awardInfo ) do if id == v.id and self.IllustrationStatus_Achieve == v.status then return true end end return false end --是否有新完成的图鉴 function Illustration:IsNewAchieve( player , IllustrationType ) local IsAchieve = false local IllustrationId = nil --获取当前图鉴类型的配置 local cfgAllIllustration = skynet.server.gameConfig.Illustration local cfgIllustration = {} for k, v in pairs( cfgAllIllustration ) do if IllustrationType == v.type then table.insert( cfgIllustration , v ) end end if self.IllustrationType_Furniture == IllustrationType then --家具和装修 for k, v in pairs( cfgIllustration ) do if not self:IsExistAchieve( player , v.id ) then IsAchieve = self:CheckFurnitureAchieve( player , v.suitId ) if IsAchieve then IllustrationId = v.id break end end end elseif self.IllustrationType_Clothes == IllustrationType then --套装和宠物衣服 for k, v in pairs( cfgIllustration ) do if not self:IsExistAchieve( player , v.id ) then IsAchieve = self:CheckClothesAchieve( player , v.suitId ) if IsAchieve then IllustrationId = v.id break end end end elseif self.IllustrationType_Plant == IllustrationType then --植物 for k, v in pairs( cfgIllustration ) do if not self:IsExistAchieve( player , v.id ) then IsAchieve = self:CheckPlantAchieve( player , v.suitId ) if IsAchieve then IllustrationId = v.id break end end end elseif self.IllustrationType_Special== IllustrationType then --特殊扭蛋 for k, v in pairs( cfgIllustration ) do if not self:IsExistAchieve( player , v.id ) then IsAchieve = self:CheckSpecialAchieve( player , v.suitId ) if IsAchieve then IllustrationId = v.id break end end end end --完成了就添加 if IsAchieve then self:AddAchieve( player , IllustrationId ) log.info(string.format("玩家 %d 图鉴 图鉴类型 %d 图鉴ID %d 完成" , player.userId , IllustrationType , IllustrationId )) end return IsAchieve,IllustrationId end --检查完成图鉴便没有领取的发消息提示 function Illustration:IsSendTips( player ) local cfgBook = skynet.server.gameConfig.FurnitureBook for k, v in pairs( cfgBook ) do --找到完成的图鉴ID,但又没有领取的 local IsAchieve = self:CheckAchieve( player , v.furnitrueId , v.decorateId ) if IsAchieve then if not self:IsGainAward( player , self.IllustrationType_Furniture , v.id ) then skynet.server.msgTips:Reset( player , 17 ) skynet.server.msgTips:Add( player , 17 ) return end end end end --检查套间完成图鉴 function Illustration:CheckFurnitureAchieve( player , suitId ) local IsAchieve1 = true local IsAchieve2 = true --找出套装家具 local cfgAllFurniture = skynet.server.gameConfig.Furniture local cfgFurniture = {} for k, v in pairs( cfgAllFurniture ) do if suitId== v.suitType then table.insert( cfgFurniture , v ) end end --家具 for k, v in pairs( cfgFurniture ) do IsAchieve1 = self:IsExistGoods( player , dataType.GoodsType_Furniture , v.id ) if not IsAchieve1 then break end end --找出套装装修 local cfgAllDecoration = skynet.server.gameConfig.Decoration local cfgDecoration = {} for k, v in pairs( cfgAllDecoration ) do if suitId== v.suitType then table.insert( cfgDecoration , v ) end end --装修 for k, v in pairs( cfgDecoration ) do IsAchieve2 = self:IsExistGoods( player , dataType.GoodsType_Decorate , v.id ) if not IsAchieve2 then break end end if IsAchieve1 and IsAchieve2 then return true else return false end end --检查衣服完成图鉴 function Illustration:CheckClothesAchieve( player , suitId ) local IsAchieve = true --找出衣服类型 local cfgAllClothes = {} local goodsType = nil local cfgClothesSuit = skynet.server.gameConfig.ClothesSuit for k, v in pairs(cfgClothesSuit) do if suitId == v.id then if 1 == v.type then --人物 goodsType = dataType.GoodsType_Clothes cfgAllClothes = skynet.server.gameConfig.Clothes elseif 2 == v.type then --宠物 goodsType = dataType.GoodsType_PetClothes cfgAllClothes = skynet.server.gameConfig.PetClothes end break end end --找出套装家具 --local cfgAllClothes = skynet.server.gameConfig.Clothes local cfgClothes = {} for k, v in pairs( cfgAllClothes ) do if suitId== v.suitId then table.insert( cfgClothes , v ) end end --是否存在商品 for k, v in pairs( cfgClothes ) do IsAchieve = self:IsExistGoods( player , goodsType , v.id ) if not IsAchieve then break end end if IsAchieve then return true else return false end end --检查植物完成图鉴 function Illustration:CheckPlantAchieve( player , suitId ) local isAchieve = true --找出套装家具 local cfgPlant = skynet.server.gameConfig.Plant local cfgAllPlant = {} for k, v in pairs( cfgPlant ) do if suitId== v.subType then table.insert( cfgAllPlant , v ) end end --是否存在商品 for k, v in pairs( cfgAllPlant ) do isAchieve = self:IsExistGoods( player , dataType.GoodsType_Plant , v.id ) if not isAchieve then break end end return isAchieve end --检查特殊完成图鉴 function Illustration:CheckSpecialAchieve( player , suitId ) local IsAchieve = true --找出套装家具 local cfgAllGashapon = skynet.server.gameConfig.Gashapon local cfgGashapon = {} for k, v in pairs( cfgAllGashapon ) do if suitId== v.id then cfgGashapon = v break end end --扭蛋 IsAchieve = self:IsExistGoods( player , dataType.GoodsType_Furniture , cfgGashapon.id ) if IsAchieve then return true else return false end end --获取图鉴 function Illustration:Get( player , goodsType , Illustration ) for k, v in pairs( player.gameData.illustration.goodsInfo ) do if goodsType == v.type then table.insert( Illustration , { type = v.type , id = v.id } ) end end end --获取所有的奖励信息 function Illustration:GetAwardInfo( player ) local awardId = {} for k, v in pairs( player.gameData.illustration.awardInfo ) do if self.IllustrationStatus_GainAward == v.status then table.insert( awardId , v.id) end end return awardId end --添加完成的图鉴 function Illustration:AddAchieve( player , IllustrationId ) local isExist = false for k, v in pairs( player.gameData.illustration.awardInfo ) do if IllustrationId == v.id then isExist = true break end end if not isExist then table.insert( player.gameData.illustration.awardInfo , { id = IllustrationId , status = self.IllustrationStatus_Achieve }) end end --是否存在完成的图鉴 function Illustration:IsExistAchieve( player , IllustrationId ) local isExist = false for k, v in pairs( player.gameData.illustration.awardInfo ) do if IllustrationId == v.id then isExist = true break end end return isExist end skynet.server.illustration = Illustration return Illustration