local skynet = require "skynet" local oo = require "Class" local log = require "Log" local pb = require "pb" local dataType = require "DataType" local json = require "json" local Shop = oo.class() Shop.MaxSpecialGoodsCount = 1 --特殊最大商品数量 Shop.MaxGeneralGoodsCount = 6 --普通最大商品数量 Shop.BuyStatus_Suc = 1 --成功 Shop.BuyStatus_NoMoney = 2 --余额不足 Shop.BuyStatus_NoExistShop = 3 --无法购买该家具 Shop.RefreshStatus_Suc = 1 --成功 Shop.RefreshStatus_NoMoney = 2 --余额不足 Shop.RefreshStatus_NoExistShop = 3 --不存在商店类型 Shop.BuyShopType_Coin = 1 --家具金币购买类型 Shop.BuyShopType_AD = 2 --广告购买类型 Shop.BuyShopType_Clovers = 3 --家具四叶草购买类型 Shop.BuyShopType_Suit = 4 --套装 Shop.BuyShopType_Used = 5 --闲菜 Shop.BuyShopType_Festival = 6 --节日活动 Shop.BuyShopType_GuGuMarket = 9 --咕咕市集 Shop.BuyShopType_Design = 10 --设计间(十连抽) Shop.BuyShopType_Store = 11 --商店 Shop.BuyShopType_DoubleSpace = 12 --双人空间 Shop.DecorateBuyType_Coin = 1 --装修金币购买类型 Shop.DecorateBuyType_Clovers = 2 --装修四叶草购买类型 Shop.DecorateBuyType_Suit = 3 --装修套间 Shop.FurnitureType_FloorDeco = 1 --地饰 Shop.FurnitureType_WallDeco = 2 --墙饰 Shop.FurnitureType_Cinnabar = 3 --摆件 Shop.FurnitureType_Furniture = 4 --家具 Shop.PetClothesType_Clothes = 1 --服装 Shop.PetClothesType_Hat = 2 --帽子 Shop.PetClothesType_Decoration = 3 --尾饰 Shop.PetClothesType_TailDecoration = 4 --面饰 Shop.PetClothesType_Max = 5 --最大值 Shop.FlowerpotType_Seed = 1 --种子商店(植物小铺) Shop.FlowerpotType_Flower = 2 --花店 Shop.FlowerpotShopType_Plant = 1 --植物小铺 Shop.FlowerpotShopType_Flower = 2 --花店商店 Shop.FlowerpotLevel_Common = 1 --植物等级普通 Shop.FlowerpotLevel_Special = 2 --植物等级稀有 Shop.FlowerpotLevel_Rare = 3 --植物等级罕见 Shop.CoffeeType_Coffee = 1 --咖啡 Shop.CoffeeType_Materials = 2 --材料 function Shop:Init() end --获取商店刷新时间 function Shop:GetRefreshTime( player , shopType ) local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue") local refreshTime = 60 if dataType.ShopType_Furniture == shopType then refreshTime = cfgSValue.furnituRefreshTime elseif dataType.ShopType_Cinnabar == shopType then refreshTime = cfgSValue.itemRefreshTime elseif dataType.ShopType_Seed == shopType then refreshTime = cfgSValue.seedRefreshTime elseif dataType.ShopType_Decorate == shopType then refreshTime = cfgSValue.decorationRefreshTime elseif dataType.ShopType_Suit == shopType then refreshTime = cfgSValue.suitRefreshTime elseif dataType.ShopType_Clothes == shopType or dataType.ShopType_PetClothes == shopType then refreshTime = cfgSValue.clothesRefreshTime elseif dataType.ShopType_Fashion == shopType then refreshTime = cfgSValue.clothesRefreshTime end return refreshTime * 60 end --获取刷新商店价格 function Shop:GetRefreshShopPrice( player , shopType ) local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue") local price = nil if dataType.ShopType_Furniture == shopType then price = cfgSValue.furnitureRefreshCost elseif dataType.ShopType_Cinnabar == shopType then price = cfgSValue.itemRefreshCost elseif dataType.ShopType_Decorate == shopType then price = cfgSValue.decorateRefreshCost elseif dataType.ShopType_Clothes == shopType or dataType.ShopType_PetClothes == shopType then price = cfgSValue.clothesRefreshCost elseif dataType.ShopType_Fashion == shopType then price = cfgSValue.accRefreshCost end return price end --是否为有效的门店 function Shop:IsVaildShopType( shopType ) if shopType < dataType.ShopType_Furniture or shopType > dataType.ShopType_Seed then return false end return true end --在当前物品信息中是否存在家具ID function Shop:IsExistGoodsId( goodsId , allGoods ) for k, v in pairs( allGoods ) do if goodsId == v.id then return true end end return false end --获取不重复的商品根据子类型 function Shop:GetNoRepeatGoodsForSubType( randCount , cfgAllGoods ) local randList = {} local randIndex = nil local newGoods = {} local whileCount = 0 local allSubType = {} --目前存在的所有子类型 --是否存在子类型 local function IsExistSubType( subType ) for k, v in pairs( allSubType ) do if subType == v then return true end end return false end while true do if 0 == #cfgAllGoods then break end randIndex = math.random( 1, #cfgAllGoods) local curGoods = cfgAllGoods[ randIndex ] if not randList[ randIndex ] and not IsExistSubType( curGoods.subType ) then --不存在新的列表就添加进去 table.insert( newGoods , curGoods.id ) table.insert( allSubType , curGoods.subType) randList[ randIndex ] = true end --找够了数据或者循环了1000次就退出 if #newGoods >= randCount or whileCount >= 1000 then break end whileCount = whileCount + 1 end return newGoods end --获取不重复的商品 function Shop:GetNoRepeatGoods( randCount , cfgAllGoods ) local randList = {} local randIndex = nil local newGoods = {} local whileCount = 0 while true do if 0 == #cfgAllGoods then break end randIndex = math.random( 1, #cfgAllGoods) if not randList[ randIndex ] then --不存在新的列表就添加进去 table.insert( newGoods , cfgAllGoods[ randIndex ].id ) randList[ randIndex ] = true end --找够了数据或者循环了1000次就退出 if #newGoods >= randCount or whileCount >= 1000 then break end whileCount = whileCount + 1 end return newGoods end --获取所有随机家具 function Shop:GetAllRandFurniture( player , curGoods , level , randCount , buyType ) local cfgFurniture = {} local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture") for k, v in pairs(cfgAllFurniture) do if buyType == v.shopType and level >= v.level and 0 == #v.dyeFurTrans and not self:IsExistGoodsId( v.id , curGoods ) then table.insert( cfgFurniture , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgFurniture ) return newGoods end --获取家具 function Shop:GetRandFurniture( player , curGoods , level , randCount , buyType ) local cfgFurniture = {} local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture") for k, v in pairs(cfgAllFurniture) do if buyType == v.shopType and level >= v.level and self.FurnitureType_Cinnabar ~= v.type and 0 == #v.dyeFurTrans and not self:IsExistGoodsId( v.id , curGoods ) then table.insert( cfgFurniture , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgFurniture ) return newGoods end --获取摆件 function Shop:GetRandCinnabar( player , curGoods , level , randCount , buyType ) local cfgFurniture = {} local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture") for k, v in pairs(cfgAllFurniture) do if buyType == v.shopType and level >= v.level and self.FurnitureType_Cinnabar == v.type and 0 == #v.dyeFurTrans and not self:IsExistGoodsId( v.id , curGoods ) then table.insert( cfgFurniture , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgFurniture ) return newGoods end --获取闲菜二手商品 function Shop:GetRandUsedGoods( player , historyGoods , randCount ) local cfgFurniture = {} local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture") for k, v in pairs( cfgAllFurniture ) do --找出配置中闲菜可以买的数据 if 1 == v.marketType and player.gameData.level >= v.level and not skynet.server.shop:IsExistGoodsId( v.id , historyGoods ) then table.insert( cfgFurniture , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgFurniture ) return newGoods end --获取解锁的花盆 function Shop:GetUnLockFlowerpot( player , shopType , count ) count = count or 0 local cfgAllFlowerpot = skynet.server.gameConfig:GetPlayerAllCfg( player , "Flowerpot") local newGoods = {} -- local filterFlowerpot = {} -- for k, v in pairs(cfgAllFlowerpot) do -- if v.shopType == self.FlowerpotType_Seed then -- table.insert(filterFlowerpot, v) -- end -- end --是否解锁上一个花盆 local function IsUnlockLastFlowerpot( flowerpotId ) -- flowerpotId = flowerpotId - 1 if flowerpotId <= 1 then return true end -- local curCfgPlant = skynet.server.gameConfig:GetPlayerCurCfg( player , "Flowerpot", flowerpotId).id -- if flowerpotId == curCfgPlant then -- return true -- end for k, v in pairs( newGoods ) do if v == cfgAllFlowerpot[flowerpotId].unlockPotBefore then return true end end return false end if self.FlowerpotType_Seed == shopType then for k, v in pairs(cfgAllFlowerpot) do --植物小铺 需要的植物ID是0或者获取该植物数量大于配置中的值都可以买花盆 if shopType == v.shopType and IsUnlockLastFlowerpot( v.id ) and ( 0 == v.seedId or skynet.server.flowerpot:GetPlantCountForSeed( player , v.seedId ) >= v.plantValue ) then table.insert( newGoods , v.id ) end end elseif self.FlowerpotType_Flower == shopType then for k, v in pairs(cfgAllFlowerpot) do if shopType == v.shopType and count >= v.unlockFlowerCount then table.insert( newGoods , v.id ) end end end return newGoods end --获取随机花盆 function Shop:GetRandFlowerpot( shopType , curGoods , randCount ) local cfgAllFlowerpot = skynet.server.gameConfig.Flowerpot local cfgFlowerpot = {} for k, v in pairs(cfgAllFlowerpot) do if shopType == v.shopType and not self:IsExistGoodsId( v.id , curGoods ) then table.insert( cfgFlowerpot , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgFlowerpot ) return newGoods end --获取种子 function Shop:GetRandSeed( player , shopType , curGoods , level , randCount ) local cfgAllSeed = skynet.server.gameConfig:GetPlayerAllCfg( player , "Seed") local cfgSeed = {} for k, v in pairs(cfgAllSeed) do if shopType == v.shopType and level >= v.level and not self:IsExistGoodsId( v.id , curGoods ) and 0 ~= v.ripeId then --if shopType == v.shopType and level >= v.level and 0 ~= v.ripeId then table.insert( cfgSeed , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgSeed ) return newGoods end --获取植物 function Shop:GetRandPlant( player , type , quality , randCount ) if 0 == randCount then return {} end local cfgAllPlant = skynet.server.gameConfig:GetPlayerAllCfg( player , "Plant") local cfgPlant = {} for k, v in pairs( cfgAllPlant ) do if type == v.type and quality == v.quality then table.insert( cfgPlant , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgPlant ) return newGoods end --获取装修间 function Shop:GetRandDecoration( player , curGoods , level , randCount , buyType , type ) type = type or 0 --0表示可以随机任务类型的装修 --送的不再刷出 for i = 23, 27, 1 do table.insert( curGoods , { id = i }) end --已经购买的装修 local alreadyBuy = {} for k, v in pairs( player.gameData.bag ) do if dataType.GoodsType_Decorate == v.type then table.insert( alreadyBuy , { id = v.id } ) end end local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration") local cfgDecoration = {} for k, v in pairs(cfgAllDecoration) do --购买条件,玩家等级大于商品等级 ,物品类型一致,当前商店有的商品不参与,当前玩家已经购买了不参与 if buyType == v.shopType and level >= v.level and ( 0 == type or type == v.type ) and not self:IsExistGoodsId( v.id , curGoods ) and not self:IsExistGoodsId( v.id , alreadyBuy ) then table.insert( cfgDecoration , v ) end end --放宽条件,完全已经购买了所有的东西,就可以按下面条件随机 if 0 == #cfgDecoration then for k, v in pairs(cfgAllDecoration) do --购买条件,玩家等级大于商品等级 ,物品类型一致,当前商店有的商品不参与 if buyType == v.shopType and level >= v.level and type == v.type and not self:IsExistGoodsId( v.id , curGoods ) then table.insert( cfgDecoration , v ) end end end local newGoods = self:GetNoRepeatGoods( randCount , cfgDecoration ) return newGoods end --获取套间家具 function Shop:GetSuitFurniture( player , buyType , curSuitType ) local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture") local newGoods = {} for k, v in pairs( cfgAllFurniture ) do if buyType == v.shopType and curSuitType == v.suitType then table.insert( newGoods , v.id ) end end return newGoods end --获取套间装修 function Shop:GetSuitDecoration( player , buyType , curSuitType ) local cfgAllDecoration = skynet.server.gameConfig:GetPlayerAllCfg( player , "Decoration") local newGoods = {} for k, v in pairs(cfgAllDecoration) do if buyType == v.purchaseType and curSuitType == v.suitType then table.insert( newGoods , v.id ) end end return newGoods end --获取随机服饰 function Shop:GetRandClothes( player , randCount , clothesType ) --已经购买的衣服 local alreadyBuy = {} for k, v in pairs( player.gameData.bag ) do if dataType.GoodsType_Clothes == v.type then table.insert( alreadyBuy , { id = v.id } ) end end local level = player.gameData.level local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( player , "Clothes") local cfgClothes = {} --已购买的不能刷新 local function BuyNoRefresh( isClearHistory ) if isClearHistory then --是否清空历史记录 player.gameData.shop[ dataType.ShopType_Clothes ].historyGoods[ clothesType ] = {} cfgClothes = {} end local historyGoods = player.gameData.shop[ dataType.ShopType_Clothes ].historyGoods[ clothesType ] --历史刷出来的商品 for k, v in pairs(cfgAllClothes) do if level >= v.level and clothesType == v.type and 1 == v.shopType and not self:IsExistGoodsId( v.id , historyGoods ) and not self:IsExistGoodsId( v.id , alreadyBuy ) then table.insert( cfgClothes , v ) end end end --已购买的能刷新 local function BuyCanRefresh() cfgClothes = {} for k, v in pairs(cfgAllClothes) do if level >= v.level and clothesType == v.type and 1 == v.shopType then table.insert( cfgClothes , v ) end end end --正常刷新 BuyNoRefresh( false ) --放宽条件,清理下历史刷新再刷新一次 if 0 == #cfgClothes then BuyNoRefresh( true ) end --如果清空了历史刷新还刷不出来就只能全随机了 if 0 == #cfgClothes then BuyCanRefresh() end local newGoods = self:GetNoRepeatGoods( randCount , cfgClothes ) return newGoods end --获取时尚套装 function Shop:GetSuitFashion( curSuitType ) local cfgAllClothes = skynet.server.gameConfig.Clothes local newGoods = {} for k, v in pairs( cfgAllClothes ) do if curSuitType == v.suitId then table.insert( newGoods , v.id ) end end return newGoods end --获取随机宠物服饰 function Shop:GetRandPetClothes( player , randCount , petType , clothesType ) --已经购买的装修 local alreadyBuy = {} for k, v in pairs( player.gameData.bag ) do if dataType.GoodsType_PetClothes == v.type then table.insert( alreadyBuy , { id = v.id } ) end end local level = player.gameData.level local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( player , "PetClothes") local cfgClothes = {} --获取历史商品 local function GetHistoryGoods() if dataType.PetType_Cat == petType then return player.gameData.shop[ dataType.ShopType_PetClothes ].catHistoryGoods[ clothesType ] elseif dataType.PetType_Dog == petType then return player.gameData.shop[ dataType.ShopType_PetClothes ].dogHistoryGoods[ clothesType ] end end --置空历史商品 local function ResetHistoryGoods() if dataType.PetType_Cat == petType then player.gameData.shop[ dataType.ShopType_PetClothes ].catHistoryGoods[ clothesType ] = {} elseif dataType.PetType_Dog == petType then player.gameData.shop[ dataType.ShopType_PetClothes ].dogHistoryGoods[ clothesType ] = {} end end --已购买的不能刷新 local function BuyNoRefresh( isClearHistory ) if isClearHistory then --是否清空历史记录 ResetHistoryGoods() cfgClothes = {} end local historyGoods = GetHistoryGoods() for k, v in pairs(cfgAllClothes) do if level >= v.level and clothesType == v.type and petType == v.petType and 1 == v.shopType and not self:IsExistGoodsId( v.id , historyGoods ) and not self:IsExistGoodsId( v.id , alreadyBuy ) then table.insert( cfgClothes , v ) end end end --已购买的能刷新 local function BuyCanRefresh() cfgClothes = {} for k, v in pairs(cfgAllClothes) do if level >= v.level and clothesType == v.type and petType == v.petType and 1 == v.shopType then table.insert( cfgClothes , v ) end end end BuyNoRefresh( false ) --放宽条件,完全已经购买了所有的东西,就可以按下面条件随机 if 0 == #cfgClothes then BuyNoRefresh( true ) end --如果清空了历史刷新还刷不出来就只能全随机了 if 0 == #cfgClothes then BuyCanRefresh() end return self:GetNoRepeatGoods( randCount , cfgClothes ) end --获取随机咖啡 function Shop:GetRandCoffee( player , coffeeType ) local cfgAllCoffeeType = skynet.server.gameConfig:GetPlayerAllCfg( player , "CoffeeType") local cfgCoffeeType = {} local coffeeId = 1 local curShop = player.gameData.shop[ self.shopType ] --是否为新咖啡 local function IsNewCoffee( coffeeId ) for k, v in pairs( curShop.coffees ) do if coffeeId == v then return false end end return true end local isGuarantee = false --是否保底 local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue") if curShop.noNewCoffeeCount >= cfgSValue.coffeeMakingPara[5] then for k, v in pairs(cfgAllCoffeeType) do if IsNewCoffee( v.id ) then coffeeId = v.id isGuarantee = true break end end curShop.noNewCoffeeCount = 0 end if not isGuarantee then local totalWeight = 0 --最大权重 local randWeight = 0 --随机权重 --没有保底就随机找,找出最大权重 for k, v in pairs(cfgAllCoffeeType) do totalWeight = totalWeight+ v.weight end --随机权重 randWeight = math.random( 1 , totalWeight ) --已经比较的权重 local compareWeight = 0 for k, v in pairs(cfgAllCoffeeType) do compareWeight=compareWeight+v.weight if coffeeType == v.type and compareWeight >= randWeight then coffeeId= v.id break end end -- local newGoods = self:GetNoRepeatGoods( 1 , cfgCoffeeType ) -- coffeeId = newGoods[1] end return coffeeId ,isGuarantee end --获取花瓶价格 function Shop:GetFlowerpotPrice( id ) local cfg = skynet.server.gameConfig.Flowerpot for k, v in pairs( cfg ) do if id == v.id then return dataType.MoneyType_Coin , v.coin end end return nil end --获取种子价格 function Shop:GetSeedPrice( id ) local cfg = skynet.server.gameConfig.Seed for k, v in pairs( cfg ) do if id == v.id then return v.currencyBuy , v.coin end end return nil end --获取装修价格 function Shop:GetDecoratePrice( id ) local cfg = skynet.server.gameConfig.Decoration for k, v in pairs( cfg ) do if id == v.id then if self.DecorateBuyType_Coin == v.purchaseType then return dataType.MoneyType_Coin , v.coin elseif self.DecorateBuyType_Clovers == v.purchaseType or self.DecorateBuyType_Suit == v.purchaseType then return dataType.MoneyType_Map , v.diomond end end end return nil end --获取服饰价格 function Shop:GetClothesPrice( id ) local cfg = skynet.server.gameConfig.Clothes for k, v in pairs( cfg ) do if id == v.id then return dataType.MoneyType_Map , v.diomond end end return nil end --获取宠物服饰价格 function Shop:GetPetClothesPrice( id ) local cfg = skynet.server.gameConfig.PetClothes for k, v in pairs( cfg ) do if id == v.id then return dataType.MoneyType_Map , v.diomond end end return nil end --获取植物价格 function Shop:GetPlantPrice( id ) local cfg = skynet.server.gameConfig.Plant for k, v in pairs( cfg ) do if id == v.id then return dataType.MoneyType_Map , v.diomond end end return nil end --获取未购买的家具 function Shop:GetNoHistoryFurniture( player , shopType , historyGoods , level , randCount , buyShopType ) local cfgAllFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture" ) local cfgFurniture = {} local newGoods = {} --找到符合的商品 for k, v in pairs(cfgAllFurniture) do if buyShopType == v.shopType and level >= v.level and 0 == #v.dyeFurTrans and not self:IsExistGoodsId( v.id , historyGoods ) and ((dataType.ShopType_Furniture == shopType and self.FurnitureType_Cinnabar ~= v.type) or (dataType.ShopType_Cinnabar == shopType and self.FurnitureType_Cinnabar == v.type)) then table.insert( cfgFurniture , v ) end end if #cfgFurniture < randCount then --配置里的家具已经不够了 return false , newGoods else local newSubTypeGoods = self:GetNoRepeatGoodsForSubType( randCount , cfgFurniture ) local newNoSubTypeGoods = {} local diffCount = randCount - #newSubTypeGoods if diffCount > 0 then --因为目前的配置中的子类型不够了,所以刷不出需要的商品数量 local cfgNewFurniture = {} for k, v in pairs( cfgFurniture ) do if not skynet.server.common:IsExist( v.id , newSubTypeGoods ) then --保存下没有刷新的配置 table.insert( cfgNewFurniture , v ) end end --重新再刷出剩余商品 newNoSubTypeGoods = self:GetNoRepeatGoods( diffCount , cfgNewFurniture ) end --获取最终的商品信息 for k, v in pairs( newSubTypeGoods ) do table.insert( newGoods , v ) end for k, v in pairs( newNoSubTypeGoods ) do table.insert( newGoods , v ) end return true , newGoods end end --是否有效的商品信息 function Shop:IsVaildGoodsInfo( goodsInfo ) if not goodsInfo or goodsInfo.goodsType <= dataType.GoodsType_Init or goodsInfo.goodsType >= dataType.GoodsType_End or 0 ==goodsInfo.goodsId or goodsInfo.goodsCount <= 0 then return false end return true end --获取随机服饰-新 --clothesType =7 套装 function Shop:GetRandClothesNew( player , clothesType ) --返回数据 local retGoods = {} --已经购买的衣服 local alreadyBuy = {} for k, v in pairs( player.gameData.bag ) do if dataType.GoodsType_Clothes == v.type then table.insert( alreadyBuy , { id = v.id } ) end end local level = player.gameData.level local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( player , "Clothes") --查询商店类型是线上服装店的配置 local cfgOnlieClothes={} for _, cfgAllClothe in ipairs(cfgAllClothes) do if cfgAllClothe.shopType == 1 then--线上服装店 table.insert(cfgOnlieClothes,cfgAllClothe) end end if not next(cfgOnlieClothes) then return nil end --刷出商品 local randCountCfgClothess={} for _, cfgOnlieClothe in ipairs(cfgOnlieClothes) do if cfgOnlieClothe.clothesShopType ~= "" and cfgOnlieClothe.clothesShopType ~= 0 and type(cfgOnlieClothe.clothesShopType)== "number" then if randCountCfgClothess[cfgOnlieClothe.clothesShopType]== nil then randCountCfgClothess[cfgOnlieClothe.clothesShopType] = {} end table.insert(randCountCfgClothess[cfgOnlieClothe.clothesShopType],cfgOnlieClothe) end end --循环刷新商品 for clothesShopType, randCountCfgClothes in pairs(randCountCfgClothess) do local cfgClothes = {} --已购买的不能刷新 local function BuyNoRefresh( isClearHistory ) if isClearHistory then --是否清空历史记录 player.gameData.shop[ dataType.ShopType_Clothes ].historyGoods[ clothesType ] = {} cfgClothes = {} end local historyGoods = player.gameData.shop[ dataType.ShopType_Clothes ].historyGoods[ clothesType ] --历史刷出来的商品 for k, v in pairs(randCountCfgClothes) do if level >= v.level and 1 == v.shopType and not self:IsExistGoodsId( v.id , historyGoods ) and not self:IsExistGoodsId( v.id , alreadyBuy ) then table.insert( cfgClothes , v ) end end end --已购买的能刷新 local function BuyCanRefresh() cfgClothes = {} for k, v in pairs(randCountCfgClothes) do if level >= v.level and 1 == v.shopType then table.insert( cfgClothes , v ) end end end --正常刷新 BuyNoRefresh( false ) --放宽条件,清理下历史刷新再刷新一次 if 0 == #cfgClothes then BuyNoRefresh( true ) end --如果清空了历史刷新还刷不出来就只能全随机了 if 0 == #cfgClothes then BuyCanRefresh() end --随机一个服装 local newGoods = self:GetNoRepeatGoods( 1 , cfgClothes ) --添加到返回数据 retGoods[newGoods[1]]=clothesShopType end return retGoods end skynet.server.shop = Shop return Shop