346 lines
16 KiB
Lua
346 lines
16 KiB
Lua
|
|
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 shop = require "Shop"
|
|||
|
|
local json = require "json"
|
|||
|
|
local ClothesShop = oo.class(shop)
|
|||
|
|
|
|||
|
|
function ClothesShop:Init()
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--显示一种类型
|
|||
|
|
function ClothesShop:Show( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SClothesShopShow", c2sData.data ))
|
|||
|
|
local shopType = dataType.ShopType_Clothes
|
|||
|
|
|
|||
|
|
local data = {}
|
|||
|
|
data.shopInfo = {}
|
|||
|
|
|
|||
|
|
--时间超过了,刷新新的一批
|
|||
|
|
if skynet.GetTime() >= player.gameData.shop[ shopType ].nextRefreshTime then
|
|||
|
|
self:RefreshShop( player , shopType )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
skynet.server.msgTips:Reduce( player , 9)
|
|||
|
|
|
|||
|
|
--获取最新的商店数据
|
|||
|
|
data.shopInfo = self:GetShopData(player , shopType )
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ClothesShopShow")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CClothesShopShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--刷新
|
|||
|
|
function ClothesShop:Refresh( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SClothesShopRefresh", c2sData.data ))
|
|||
|
|
local shopType = dataType.ShopType_Clothes
|
|||
|
|
local methodType = c2sData.data.methodType -- 加速类型
|
|||
|
|
local data = {}
|
|||
|
|
data.shopInfo = {}
|
|||
|
|
local isSuc = false
|
|||
|
|
if methodType == dataType.AccelerateType_Volute then
|
|||
|
|
-- 消耗玩家蜗壳币
|
|||
|
|
local refreshPrice = self:GetRefreshShopPrice( player , shopType )
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_4")
|
|||
|
|
if refreshPrice then
|
|||
|
|
if player:MoneyChange( dataType.MoneyType_Volute , -refreshPrice , eventId ) then
|
|||
|
|
--使用蜗壳币进行刷新 修改相关数据
|
|||
|
|
player.gameData.todayGain.updateUseCount = player.gameData.todayGain.updateUseCount + 1
|
|||
|
|
if player.gameData.todayGain.updateUseCount == skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue").triggerUpdatePack[ 1 ] then
|
|||
|
|
skynet.server.store:TriggerPack(player , skynet.server.store.TriggerPack_Update)
|
|||
|
|
end
|
|||
|
|
isSuc = true
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoExistShopType
|
|||
|
|
end
|
|||
|
|
elseif methodType == dataType.AccelerateType_AccTicket and skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Prop, 4) > 0 then
|
|||
|
|
--消耗玩家一个刷新券
|
|||
|
|
skynet.server.bag:RemoveGoods(player , dataType.GoodsType_Prop, 4 , 1)
|
|||
|
|
isSuc = true
|
|||
|
|
elseif methodType == dataType.AccelerateType_ADTicket and skynet.server.ad:CanWatch(player, "AppClothesRefresh") and
|
|||
|
|
skynet.server.ad:PayADTicket(player, "AppClothesRefresh") then
|
|||
|
|
isSuc = true
|
|||
|
|
elseif methodType == dataType.AccelerateType_WatchAD and skynet.server.ad:CanWatch(player, "AppClothesRefresh") then
|
|||
|
|
skynet.server.ad:Update(player, "AppClothesRefresh")
|
|||
|
|
isSuc = true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if isSuc then
|
|||
|
|
self:RefreshShop( player , shopType )
|
|||
|
|
data.shopInfo = self:GetShopData( player , shopType )
|
|||
|
|
skynet.server.achieveTask:Modify( player , 34 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 34 , 1)
|
|||
|
|
|
|||
|
|
--主动刷新优衣服饰触发礼包
|
|||
|
|
--新手实惠礼包
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
if not skynet.server.illustration:CheckClothesAchieve( player , cfgSValue.newplayerClothesPack[1] ) then
|
|||
|
|
--将当前时间存入该礼包的触发时间集合中用于下一步的判断
|
|||
|
|
if not player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]] then
|
|||
|
|
player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]] = {}
|
|||
|
|
table.insert(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]],skynet.GetTime())
|
|||
|
|
else
|
|||
|
|
--将超时的记录清除
|
|||
|
|
for i, v in pairs(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]]) do
|
|||
|
|
if skynet.GetTime() - v > 3600*cfgSValue.newplayerClothesPack[2] then
|
|||
|
|
table.remove(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]] , i)
|
|||
|
|
else
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if not player.gameData.storePack.storePackInfo[ cfgSValue.newplayerClothesPack[4] ] then
|
|||
|
|
table.insert(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]],skynet.GetTime())
|
|||
|
|
else
|
|||
|
|
if player.gameData.storePack.storePackInfo[ cfgSValue.newplayerClothesPack[4] ].failureTime < skynet.GetTime() and player.gameData.storePack.storePackInfo[ cfgSValue.newplayerClothesPack[4] ].buyTimes == 0 then
|
|||
|
|
table.insert(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]],skynet.GetTime())
|
|||
|
|
else
|
|||
|
|
--直接跳过剩下的判断逻辑节约性能
|
|||
|
|
goto continueClothesPack
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
--判断是否满足在X小时内触发Y次的条件
|
|||
|
|
if #player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerClothesPack[4]] >= cfgSValue.newplayerClothesPack[3] then
|
|||
|
|
skynet.server.store:TriggerPack( player , skynet.server.store.TriggerPack_NewPlayerClothesPack )
|
|||
|
|
end
|
|||
|
|
--判断出口防止做多余判断浪费性能
|
|||
|
|
::continueClothesPack::
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
end
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ClothesShopRefresh")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CClothesShopRefresh", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--商店购买
|
|||
|
|
function ClothesShop:Buy( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SClothesShopBuy", c2sData.data ))
|
|||
|
|
local goodsId = c2sData.data.goodsId
|
|||
|
|
local data = {}
|
|||
|
|
local shopType = dataType.ShopType_Clothes
|
|||
|
|
local curShop = player.gameData.shop[ shopType ]
|
|||
|
|
|
|||
|
|
--特殊商品购买
|
|||
|
|
if not goodsId then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
else
|
|||
|
|
--检查是商店中是否存在该商品
|
|||
|
|
local isExistGoods = false
|
|||
|
|
if goodsId == curShop.headWear.id then --头饰
|
|||
|
|
isExistGoods = true
|
|||
|
|
elseif goodsId == curShop.clothes.id then --衣服
|
|||
|
|
isExistGoods = true
|
|||
|
|
elseif goodsId == curShop.trousers.id then --裤子
|
|||
|
|
isExistGoods = true
|
|||
|
|
elseif goodsId == curShop.shoes.id then --鞋子
|
|||
|
|
isExistGoods = true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--检查该商品是否存在背包
|
|||
|
|
local isBagGoods = player:IsBuyGoods( dataType.GoodsType_Clothes , goodsId )
|
|||
|
|
if not isExistGoods then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoGoodsID
|
|||
|
|
elseif isBagGoods then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ExistGoodsInBag
|
|||
|
|
else
|
|||
|
|
--未购买过商品,先扣钱,再发货
|
|||
|
|
local moneyType , moneyCount = skynet.server.gameConfig:GetBuyMoney( player , "Clothes" , goodsId ) --self:GetClothesPrice( goodsId )
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_35")
|
|||
|
|
if moneyType and player:MoneyChange( moneyType , -moneyCount , eventId) then
|
|||
|
|
if goodsId == curShop.headWear.id then --头饰
|
|||
|
|
player.gameData.shop[ shopType ].headWear.buyCount = 1
|
|||
|
|
elseif goodsId == curShop.clothes.id then --衣服
|
|||
|
|
player.gameData.shop[ shopType ].clothes.buyCount = 1
|
|||
|
|
elseif goodsId == curShop.trousers.id then --裤子
|
|||
|
|
player.gameData.shop[ shopType ].trousers.buyCount = 1
|
|||
|
|
elseif goodsId == curShop.shoes.id then --鞋子
|
|||
|
|
player.gameData.shop[ shopType ].shoes.buyCount = 1
|
|||
|
|
end
|
|||
|
|
table.insert( player.gameData.shop[ shopType ].buyGoods , goodsId )
|
|||
|
|
skynet.server.bag:AddGoods( player , dataType.GoodsType_Clothes , goodsId , 1 )
|
|||
|
|
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 5 , moneyCount )
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 6 , 1 )
|
|||
|
|
log.debug(string.format("玩家 %d 服装商店 购买成功 商品 %d 扣除四叶草 %d" , player.basicInfo.userID , goodsId , moneyCount))
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|||
|
|
log.warning(string.format("玩家 %d 服装商店 购买失败 商品 %d " , player.basicInfo.userID , goodsId))
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
data.shopInfo = self:GetShopData(player , shopType )
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_ClothesShopBuy")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CClothesShopBuy", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--刷新商店类型
|
|||
|
|
function ClothesShop:RefreshShop( player , shopType )
|
|||
|
|
local goodsIds= {}
|
|||
|
|
local clothesType = nil
|
|||
|
|
local curShop = player.gameData.shop[ shopType ]
|
|||
|
|
|
|||
|
|
-- --头饰
|
|||
|
|
-- clothesType = dataType.ClothesType_HeadWear
|
|||
|
|
-- goodsId = self:GetRandClothes( player , 1 , clothesType )
|
|||
|
|
-- self:SetShopData( player , shopType , clothesType , goodsId[1] )
|
|||
|
|
|
|||
|
|
-- --衣服
|
|||
|
|
-- clothesType = dataType.ClothesType_Clothes
|
|||
|
|
-- goodsId = self:GetRandClothes( player , 1 , clothesType )
|
|||
|
|
-- self:SetShopData( player , shopType , clothesType , goodsId[1] )
|
|||
|
|
|
|||
|
|
-- --裤子
|
|||
|
|
-- clothesType = dataType.ClothesType_Trousers
|
|||
|
|
-- goodsId = self:GetRandClothes( player , 1 , clothesType )
|
|||
|
|
-- self:SetShopData( player , shopType , clothesType , goodsId[1] )
|
|||
|
|
|
|||
|
|
-- --鞋子
|
|||
|
|
-- clothesType = dataType.ClothesType_Shoes
|
|||
|
|
-- goodsId = self:GetRandClothes( player , 1 , clothesType )
|
|||
|
|
-- self:SetShopData( player , shopType , clothesType , goodsId[1] )
|
|||
|
|
|
|||
|
|
--刷新物品
|
|||
|
|
clothesType = dataType.ClothesType_Suit
|
|||
|
|
goodsIds = self:GetRandClothesNew( player , clothesType )
|
|||
|
|
for goodsId, clothesShopType in pairs(goodsIds) do
|
|||
|
|
|
|||
|
|
--类型特殊处理
|
|||
|
|
-- "服装栏位
|
|||
|
|
-- 1=上衣+连衣裙+套装
|
|||
|
|
-- 2=鞋
|
|||
|
|
-- 3=头饰+耳饰+面饰
|
|||
|
|
-- 4=半身裙+裤子"
|
|||
|
|
|
|||
|
|
--转换成
|
|||
|
|
|
|||
|
|
-- "类型
|
|||
|
|
-- 4=头饰
|
|||
|
|
-- 5=上衣+连衣裙
|
|||
|
|
-- 6=下裤+短裙
|
|||
|
|
-- 8=鞋
|
|||
|
|
-- "
|
|||
|
|
local clothesShopTypeTemp = clothesShopType
|
|||
|
|
if clothesShopTypeTemp==1 then
|
|||
|
|
clothesShopTypeTemp=5
|
|||
|
|
elseif clothesShopTypeTemp==2 then
|
|||
|
|
clothesShopTypeTemp=8
|
|||
|
|
elseif clothesShopTypeTemp==3 then
|
|||
|
|
clothesShopTypeTemp=4
|
|||
|
|
elseif clothesShopTypeTemp==4 then
|
|||
|
|
clothesShopTypeTemp=6
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
self:SetShopData( player , shopType , clothesShopTypeTemp , goodsId )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
--本次刷新已经购买的商品
|
|||
|
|
curShop.buyGoods = {}
|
|||
|
|
--刷新告罄标记
|
|||
|
|
self:SetSoldType(player,shopType)
|
|||
|
|
--刷新时间
|
|||
|
|
local timeCoefficient = skynet.server.store:GetTimeCoefficient(player , 2) --月卡权益 时间系数
|
|||
|
|
curShop.nextRefreshTime = math.ceil(self:GetRefreshTime(player,shopType) * timeCoefficient) + skynet.GetTime()
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--设置商店数据
|
|||
|
|
function ClothesShop:SetShopData( player , shopType , clothesType , goodsId )
|
|||
|
|
if nil == goodsId then
|
|||
|
|
return
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local buCount = 0 --是否购买
|
|||
|
|
if player:IsBuyGoods( dataType.GoodsType_Clothes , goodsId ) then
|
|||
|
|
buCount = 1
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if dataType.ClothesType_HeadWear == clothesType then
|
|||
|
|
player.gameData.shop[ shopType ].headWear.id = goodsId
|
|||
|
|
player.gameData.shop[ shopType ].headWear.buyCount = buCount
|
|||
|
|
log.debug(string.format("玩家 %d 服饰商店 设置商店数据 最新头饰 ID %d 是否购买 %d" , player.basicInfo.userID , goodsId , buCount ))
|
|||
|
|
elseif dataType.ClothesType_Clothes == clothesType then
|
|||
|
|
player.gameData.shop[ shopType ].clothes.id = goodsId
|
|||
|
|
player.gameData.shop[ shopType ].clothes.buyCount = buCount
|
|||
|
|
log.debug(string.format("玩家 %d 服饰商店 设置商店数据 最新衣服 ID %d 是否购买 %d" , player.basicInfo.userID , goodsId , buCount ))
|
|||
|
|
elseif dataType.ClothesType_Trousers == clothesType then
|
|||
|
|
player.gameData.shop[ shopType ].trousers.id = goodsId
|
|||
|
|
player.gameData.shop[ shopType ].trousers.buyCount = buCount
|
|||
|
|
log.debug(string.format("玩家 %d 服饰商店 设置商店数据 最新裤子 ID %d 是否购买 %d" , player.basicInfo.userID , goodsId , buCount ))
|
|||
|
|
elseif dataType.ClothesType_Shoes == clothesType then
|
|||
|
|
player.gameData.shop[ shopType ].shoes.id = goodsId
|
|||
|
|
player.gameData.shop[ shopType ].shoes.buyCount = buCount
|
|||
|
|
log.debug(string.format("玩家 %d 服饰商店 设置商店数据 最新鞋子 ID %d 是否购买 %d" , player.basicInfo.userID , goodsId , buCount ))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
table.insert( player.gameData.shop[ shopType ].historyGoods[ clothesType ] , { id = goodsId })
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取商店数据
|
|||
|
|
function ClothesShop:GetShopData( player , shopType )
|
|||
|
|
local shopInfo = {}
|
|||
|
|
shopInfo.headWear = player.gameData.shop[ shopType ].headWear
|
|||
|
|
shopInfo.clothes = player.gameData.shop[ shopType ].clothes
|
|||
|
|
shopInfo.trousers = player.gameData.shop[ shopType ].trousers
|
|||
|
|
shopInfo.shoes = player.gameData.shop[ shopType ].shoes
|
|||
|
|
shopInfo.buyGoods = player.gameData.shop[ shopType ].buyGoods
|
|||
|
|
shopInfo.nextRefreshTime = player.gameData.shop[ shopType ].nextRefreshTime
|
|||
|
|
shopInfo.isSellOut = player.gameData.shop[ shopType ].isSellOut
|
|||
|
|
-- 老帐号在游戏更新后,如果还未到服装商店刷新时间这个字段会为null,此处做个临时处理,下个版本后可以删掉此处判断逻辑
|
|||
|
|
if shopInfo.isSellOut == nil then
|
|||
|
|
self:SetSoldType(player,shopType)
|
|||
|
|
shopInfo.isSellOut = player.gameData.shop[ shopType ].isSellOut
|
|||
|
|
end
|
|||
|
|
return shopInfo
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--检测玩家背包 设置告罄标记
|
|||
|
|
function ClothesShop:SetSoldType(player , shopType)
|
|||
|
|
local cfgAllClothes = skynet.server.gameConfig:GetPlayerAllCfg( player , "Clothes")
|
|||
|
|
--先将标记全部设置为告罄,遍历服装表如果有未入背包物品则将标记设为未告罄
|
|||
|
|
player.gameData.shop[ shopType ].isSellOut ={true,true,true,true}
|
|||
|
|
local playerSoldTag = player.gameData.shop[ shopType ].isSellOut
|
|||
|
|
local playerLevel = player.gameData.level
|
|||
|
|
for k,v in pairs(cfgAllClothes) do
|
|||
|
|
--目前只服务于线上服装店 ,后期其他地方要用的话可以设置成参数
|
|||
|
|
if v.shopType == 1 and playerLevel >= v.level then
|
|||
|
|
|
|||
|
|
-- "服装栏位
|
|||
|
|
-- 1=上衣+连衣裙+套装
|
|||
|
|
-- 2=鞋
|
|||
|
|
-- 3=头饰+耳饰+面饰
|
|||
|
|
-- 4=半身裙+裤子"
|
|||
|
|
if v.clothesShopType == 3 and playerSoldTag[1] then
|
|||
|
|
if not player:IsBuyGoods( dataType.GoodsType_Clothes , v.id ) then
|
|||
|
|
playerSoldTag[1]=false
|
|||
|
|
end
|
|||
|
|
elseif v.clothesShopType == 1 and playerSoldTag[2] then
|
|||
|
|
if not player:IsBuyGoods( dataType.GoodsType_Clothes , v.id ) then
|
|||
|
|
playerSoldTag[2]=false
|
|||
|
|
end
|
|||
|
|
elseif v.clothesShopType == 4 and playerSoldTag[3] then
|
|||
|
|
if not player:IsBuyGoods( dataType.GoodsType_Clothes , v.id ) then
|
|||
|
|
playerSoldTag[3]=false
|
|||
|
|
end
|
|||
|
|
elseif v.clothesShopType == 2 and playerSoldTag[4] then
|
|||
|
|
if not player:IsBuyGoods( dataType.GoodsType_Clothes , v.id ) then
|
|||
|
|
playerSoldTag[4]=false
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
--当4个标记全为未告罄时提前跳出循环
|
|||
|
|
if not playerSoldTag[1] and not playerSoldTag[2] and not playerSoldTag[3] and not playerSoldTag[4] then
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
skynet.server.clothesShop = ClothesShop
|
|||
|
|
return ClothesShop
|