local skynet = require "skynet" local oo = require "Class" local log = require "Log" local pb = require "pb" local dataType = require "DataType" 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.FurnitureBuyType_Coin = 1 --家具金币购买类型 Shop.FurnitureBuyType_AD = 2 --广告购买类型 Shop.FurnitureBuyType_Clovers = 3 --家具四叶草购买类型 Shop.FurnitureBuyType_Suit = 4 --套装 Shop.FurnitureBuyType_Used = 5 --闲菜 Shop.FurnitureBuyType_Festival = 6 --节日活动 Shop.FurnitureBuyType_GuGuMarket = 9 --咕咕市集 Shop.FurnitureBuyType_Design = 10 --设计间(十连抽) 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.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( shopType ) local refreshTime = 60 if dataType.ShopType_Furniture == shopType then refreshTime = skynet.server.gameConfig.SValue.furnituRefreshTime elseif dataType.ShopType_Cinnabar == shopType then refreshTime = skynet.server.gameConfig.SValue.itemRefreshTime elseif dataType.ShopType_Seed == shopType then refreshTime = skynet.server.gameConfig.SValue.seedRefreshTime elseif dataType.ShopType_Decorate == shopType then refreshTime = skynet.server.gameConfig.SValue.decorationRefreshTime elseif dataType.ShopType_Suit == shopType then refreshTime = skynet.server.gameConfig.SValue.suitRefreshTime elseif dataType.ShopType_Clothes == shopType or dataType.ShopType_PetClothes == shopType then refreshTime = skynet.server.gameConfig.SValue.clothesRefreshTime elseif dataType.ShopType_Fashion == shopType then refreshTime = skynet.server.gameConfig.SValue.clothesRefreshTime end return refreshTime * 60 end --获取刷新商店价格 function Shop:GetRefreshShopPrice( shopType ) local price = nil if dataType.ShopType_Furniture == shopType then price = skynet.server.gameConfig.SValue.furnitureRefreshCost elseif dataType.ShopType_Cinnabar == shopType then price = skynet.server.gameConfig.SValue.itemRefreshCost elseif dataType.ShopType_Decorate == shopType then price = skynet.server.gameConfig.SValue.decorateRefreshCost elseif dataType.ShopType_Clothes == shopType or dataType.ShopType_PetClothes == shopType then price = skynet.server.gameConfig.SValue.clothesRefreshCost elseif dataType.ShopType_Fashion == shopType then price = skynet.server.gameConfig.SValue.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: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:GetRandFurniture( curGoods , level , randCount , buyType ) local cfgAllFurniture = skynet.server.gameConfig.Furniture local cfgFurniture = {} 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( curGoods , level , randCount , buyType ) local cfgAllFurniture = skynet.server.gameConfig.Furniture local cfgFurniture = {} 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:GetUnLockFlowerpot( shopType , count ) local cfgAllFlowerpot = skynet.server.gameConfig.Flowerpot local newGoods = {} for k, v in pairs(cfgAllFlowerpot) do if shopType == v.shopType and count >= v.unlockFlowerCount then table.insert( newGoods , v.id ) 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( shopType , curGoods , level , randCount ) local cfgAllSeed = skynet.server.gameConfig.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( type , quality , randCount ) if 0 == randCount then return {} end local cfgAllPlant = skynet.server.gameConfig.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 ) --送的不再刷出 for i = 23, 27, 1 do table.insert( curGoods , { id = i }) end --已经购买的装修 local alreadyBuy = {} for k, v in pairs( player.gameData.decorate) do table.insert( alreadyBuy , { id = v.id } ) end local cfgAllDecoration = skynet.server.gameConfig.Decoration local cfgDecoration = {} 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 ) 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( buyType , curSuitType ) local cfgAllFurniture = skynet.server.gameConfig.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( buyType , curSuitType ) local cfgAllDecoration = skynet.server.gameConfig.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 , curGoods , randCount , type ) --已经购买的衣服 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.Clothes local cfgClothes = {} for k, v in pairs(cfgAllClothes) do if level >= v.level and type == v.type and 1 == v.shopType and not self:IsExistGoodsId( v.id , curGoods ) and not self:IsExistGoodsId( v.id , alreadyBuy ) then table.insert( cfgClothes , v ) end end --放宽条件,完全已经购买了所有的东西,就可以按下面条件随机 if 0 == #cfgClothes then for k, v in pairs(cfgAllClothes) do --购买条件,玩家等级大于商品等级 ,物品类型一致,当前商店有的商品不参与 if level >= v.level and type == v.type and 1 == v.shopType and not self:IsExistGoodsId( v.id , curGoods ) then table.insert( cfgClothes , v ) end end end local newGoods = self:GetNoRepeatGoods( randCount , cfgClothes ) return newGoods[1] 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 , curGoods , randCount , petType , clothesType ) --已经购买的装修 local alreadyBuy = {} for k, v in pairs( player.gameData.petClothes) do table.insert( alreadyBuy , { id = v.id } ) end local level = player.gameData.level local cfgAllClothes = skynet.server.gameConfig.PetClothes local cfgClothes = {} 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 , curGoods ) and not self:IsExistGoodsId( v.id , alreadyBuy ) then table.insert( cfgClothes , v ) end end --放宽条件,完全已经购买了所有的东西,就可以按下面条件随机 if 0 == #cfgClothes then 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 , curGoods ) then table.insert( cfgClothes , v ) end end end local newGoods = self:GetNoRepeatGoods( randCount , cfgClothes ) return newGoods[1] end --获取随机宠物服饰 function Shop:GetRandCoffee( player , coffeeType , randCount ) local cfgAllCoffeeType= skynet.server.gameConfig.CoffeeType local cfgCoffeeType = {} for k, v in pairs(cfgAllCoffeeType) do if coffeeType == v.type then table.insert( cfgCoffeeType , v ) end end local newGoods = self:GetNoRepeatGoods( randCount , cfgCoffeeType ) return newGoods 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:GetNoBuyFurniture( player , curGoods , level , randCount , buyType ) local cfgAllFurniture = skynet.server.gameConfig.Furniture local cfgFurniture = {} local newGoods = {} for k, v in pairs(cfgAllFurniture) do if buyType == v.purchaseType and level >= v.level and self.FurnitureType_Cinnabar ~= v.type and 0 == #v.dyeFurTrans and not self:IsExistGoodsId( v.id , curGoods ) and not player:IsBuyGoods( dataType.GoodsType_Furniture , v.id ) then table.insert( cfgFurniture , v ) end end if 0 == #cfgFurniture then return false,newGoods else newGoods = self:GetNoRepeatGoods( randCount , cfgFurniture ) return true,newGoods end end ---获取未购买的摆件 function Shop:GetNoBuyCinnabar( player , curGoods , level , randCount , buyType ) local cfgAllFurniture = skynet.server.gameConfig.Furniture local cfgFurniture = {} local newGoods = {} for k, v in pairs(cfgAllFurniture) do if buyType == v.purchaseType and level >= v.level and self.FurnitureType_Cinnabar == v.type and 0 == #v.dyeFurTrans and not self:IsExistGoodsId( v.id , curGoods ) and not player:IsBuyGoods( dataType.GoodsType_Furniture , v.id ) then table.insert( cfgFurniture , v ) end end if 0 == #cfgFurniture then return false,newGoods else newGoods = self:GetNoRepeatGoods( randCount , cfgFurniture ) return true,newGoods end end skynet.server.shop = Shop return Shop