604 lines
27 KiB
Lua
604 lines
27 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 Used = oo.class()
|
|||
|
|
|
|||
|
|
Used.SellOPType_StartSell = 1 --开始出售
|
|||
|
|
Used.SellOPType_StopSell = 2 --停止出售
|
|||
|
|
Used.SellOPType_ConfirmSell = 3 --确定出售
|
|||
|
|
Used.SellOPType_AllConfirmSell = 4 --一键所有确定出售
|
|||
|
|
|
|||
|
|
Used.SellStatus_NoSell = 1 --未卖出
|
|||
|
|
Used.SellStatus_SomeoneWant = 2 --有人购买
|
|||
|
|
Used.SellStatus_AlreadySell = 3 --已经出售
|
|||
|
|
|
|||
|
|
|
|||
|
|
Used.GoodsStatus_NoReach = 1 --未到达
|
|||
|
|
Used.GoodsStatus_AlreadyReach = 2 --已到达
|
|||
|
|
Used.GoodsStatus_AlreadyGet = 3 --已领取
|
|||
|
|
|
|||
|
|
Used.CopyType_Seller = 1 --卖家
|
|||
|
|
Used.CopyType_Buyer = 2 --买家
|
|||
|
|
|
|||
|
|
function Used:Init()
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜展示
|
|||
|
|
function Used:Show( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedShow", c2sData.data ))
|
|||
|
|
local data = {}
|
|||
|
|
self:CheckRefreshGoods( player )
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 展示操作" , player.basicInfo.userID))
|
|||
|
|
|
|||
|
|
local count = 0
|
|||
|
|
--多出的20个已签收物流就删除前面的
|
|||
|
|
for k, v in pairs(player.gameData.used.logisticsInfo ) do
|
|||
|
|
if self.GoodsStatus_AlreadyGet == v.goodsStatus then
|
|||
|
|
count = count + 1
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if count > 20 then
|
|||
|
|
for k, v in pairs(player.gameData.used.logisticsInfo ) do
|
|||
|
|
if self.GoodsStatus_AlreadyGet == v.goodsStatus then
|
|||
|
|
player.gameData.used.logisticsInfo[ k ] = nil
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--多出的15个卖出记录就删除前面的
|
|||
|
|
count = 0
|
|||
|
|
for k, v in pairs(player.gameData.used.sellInfo ) do
|
|||
|
|
if self.SellStatus_AlreadySell == v.status then
|
|||
|
|
count = count + 1
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if count >= 15 then
|
|||
|
|
local deleteCount = count - 15
|
|||
|
|
local tmpCount = 0
|
|||
|
|
for k, v in pairs(player.gameData.used.sellInfo ) do
|
|||
|
|
if tmpCount >= deleteCount then
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
if self.SellStatus_AlreadySell == v.status then
|
|||
|
|
player.gameData.used.sellInfo[ k ] = nil
|
|||
|
|
tmpCount = tmpCount + 1
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
skynet.server.msgTips:Get(player ,3).isRefresh = true
|
|||
|
|
skynet.server.msgTips:Get(player ,4).isRefresh = true
|
|||
|
|
skynet.server.msgTips:Get(player ,16).isRefresh = true
|
|||
|
|
data.buyRefreshTime = player.gameData.used.buyRefreshTime
|
|||
|
|
data.buyInfo = player.gameData.used.buyInfo
|
|||
|
|
data.sellInfo = self:GetSellInfo( player )
|
|||
|
|
data.logisticsInfo = self:GetLogisticsInfo( player )
|
|||
|
|
--skynet.server.msgTips:Reduce( player , 3)
|
|||
|
|
--skynet.server.msgTips:Reduce( player , 4)
|
|||
|
|
skynet.server.msgTips:Reduce( player , 16)
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedShow")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜购买
|
|||
|
|
function Used:Buy( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedBuy", c2sData.data ))
|
|||
|
|
local data = {}
|
|||
|
|
local goodsId = c2sData.data.goodsId
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_28")
|
|||
|
|
if not goodsId then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
else
|
|||
|
|
for k, v in pairs( player.gameData.used.buyInfo ) do
|
|||
|
|
if goodsId == v.goodsId then
|
|||
|
|
--找到对应的商品,扣除金额
|
|||
|
|
if player:MoneyChange( dataType.GoodsType_Coin , -v.coin , eventId) then
|
|||
|
|
player.gameData.used.buyInfo[ k ].isBuy = true
|
|||
|
|
|
|||
|
|
--计算物流到达时间
|
|||
|
|
local cfgGoods = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture", v.goodsId )
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
local discount = cfgSValue.picklesSellDiscount
|
|||
|
|
local calcDeliverTime = math.floor(cfgSValue.picklesDeliveryTime * discount * cfgGoods.coin ) * 60
|
|||
|
|
local reachTime = skynet.GetTime() + calcDeliverTime
|
|||
|
|
table.insert( player.gameData.used.logisticsInfo , { goodsId = v.goodsId , npcNameId = v.npcNameId , copyId = v.copyId , goodsStatus = self.GoodsStatus_NoReach , reachTime = reachTime , deliverTime = calcDeliverTime } )
|
|||
|
|
skynet.server.levelTask:Modify( player , 4 , 1)
|
|||
|
|
skynet.server.dailyTask:Modify( player , 4 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 4 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 3 , v.coin )
|
|||
|
|
skynet.server.achieveTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 21 , 1 )
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 9 , 1)
|
|||
|
|
|
|||
|
|
--在逸家家居使用金币
|
|||
|
|
skynet.server.taskListEvent:Modify( player ,123, v.coin)
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 购买商品 商品ID %d NPC名字ID %d 对白ID %d 购买金币 %d 到达时间 %d" , player.basicInfo.userID , goodsId , v.npcNameId , v.copyId , v.coin , reachTime))
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|||
|
|
end
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
self:CheckRefreshGoods( player )
|
|||
|
|
|
|||
|
|
data.buyInfo = player.gameData.used.buyInfo
|
|||
|
|
data.logisticsInfo = self:GetLogisticsInfo( player )
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedBuy")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedBuy", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜刷新
|
|||
|
|
function Used:Refresh( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedRefresh", c2sData.data ))
|
|||
|
|
local methodType = c2sData.data.methodType -- 加速类型
|
|||
|
|
local data = {}
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
|
|||
|
|
local isSuc = false
|
|||
|
|
if methodType == dataType.AccelerateType_Volute then
|
|||
|
|
-- 消耗玩家蜗壳币
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_6")
|
|||
|
|
if player:MoneyChange(dataType.GoodsType_Volute , -cfgSValue.sellRefreshCost ,eventId) then
|
|||
|
|
--使用蜗壳币进行刷新 修改相关数据
|
|||
|
|
player.gameData.todayGain.updateUseCount = player.gameData.todayGain.updateUseCount + 1
|
|||
|
|
if player.gameData.todayGain.updateUseCount == cfgSValue.triggerUpdatePack[ 1 ] then
|
|||
|
|
skynet.server.store:TriggerPack(player , skynet.server.store.TriggerPack_Update)
|
|||
|
|
end
|
|||
|
|
isSuc = true
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|||
|
|
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, "AppSecondhandRefresh") and
|
|||
|
|
skynet.server.ad:PayADTicket(player, "AppSecondhandRefresh") then
|
|||
|
|
isSuc = true
|
|||
|
|
elseif methodType == dataType.AccelerateType_WatchAD and skynet.server.ad:CanWatch(player, "AppSecondhandRefresh") then
|
|||
|
|
skynet.server.ad:Update(player, "AppSecondhandRefresh")
|
|||
|
|
isSuc = true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if isSuc then
|
|||
|
|
player.gameData.used.buyRefreshTime = skynet.GetTime() + cfgSValue.picklesRefreshTime * 60
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 刷新操作 下一次刷新时间 %d" , player.basicInfo.userID , player.gameData.used.buyRefreshTime))
|
|||
|
|
|
|||
|
|
player.gameData.used.buyInfo = self:RefreshGoods( player )
|
|||
|
|
skynet.server.achieveTask:Modify( player , 34 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 34 , 1)
|
|||
|
|
|
|||
|
|
--闲菜刷新触发礼包
|
|||
|
|
--新手实惠礼包
|
|||
|
|
if player.gameData.level <= cfgSValue.newplayerNormalPack[1] then
|
|||
|
|
--将当前时间存入该礼包的触发时间集合中用于下一步的判断
|
|||
|
|
if not player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]] then
|
|||
|
|
player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]] = {}
|
|||
|
|
table.insert(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]],skynet.GetTime())
|
|||
|
|
else
|
|||
|
|
--将超时的记录清除
|
|||
|
|
for i, v in pairs(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]]) do
|
|||
|
|
if skynet.GetTime() - v > 3600*cfgSValue.newplayerNormalPack[2] then
|
|||
|
|
table.remove(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]] , i)
|
|||
|
|
else
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if not player.gameData.storePack.storePackInfo[ cfgSValue.newplayerNormalPack[4] ] then
|
|||
|
|
table.insert(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]],skynet.GetTime())
|
|||
|
|
else
|
|||
|
|
if player.gameData.storePack.storePackInfo[ cfgSValue.newplayerNormalPack[4] ].failureTime < skynet.GetTime() and player.gameData.storePack.storePackInfo[ cfgSValue.newplayerNormalPack[4] ].buyTimes == 0 then
|
|||
|
|
table.insert(player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]],skynet.GetTime())
|
|||
|
|
else
|
|||
|
|
--直接跳过剩下的判断逻辑节约性能
|
|||
|
|
goto continueNormalPack
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
--判断是否满足在X小时内触发Y次的条件
|
|||
|
|
if #player.gameData.storePack.triggerPackTimeField[cfgSValue.newplayerNormalPack[4]] >= cfgSValue.newplayerNormalPack[3] then
|
|||
|
|
skynet.server.store:TriggerPack( player , skynet.server.store.TriggerPack_NewPlayerNormal )
|
|||
|
|
end
|
|||
|
|
--判断出口防止做多余判断浪费性能
|
|||
|
|
::continueNormalPack::
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
data.buyRefreshTime = player.gameData.used.buyRefreshTime
|
|||
|
|
data.buyInfo = player.gameData.used.buyInfo
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedRefresh")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedRefresh", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜出售
|
|||
|
|
function Used:Sell( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedSell", c2sData.data ))
|
|||
|
|
local data = {}
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
local opType = c2sData.data.opType
|
|||
|
|
local goodsType = c2sData.data.goodsType
|
|||
|
|
local goodsId = c2sData.data.goodsId
|
|||
|
|
if not opType or not goodsType or not goodsId then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
else
|
|||
|
|
local sellInfo = player.gameData.used.sellInfo
|
|||
|
|
|
|||
|
|
if self.SellOPType_StartSell == opType then --开始出售
|
|||
|
|
local isSell = false
|
|||
|
|
if goodsType >= dataType.GoodsType_Furniture and goodsType < dataType.GoodsType_End and
|
|||
|
|
goodsType ~= dataType.GoodsType_Decorate and goodsType ~= dataType.GoodsType_Flowerpot then
|
|||
|
|
isSell = true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if player:IsBuyGoods( goodsType , goodsId ) then
|
|||
|
|
if isSell then
|
|||
|
|
--从背包中移出该商品
|
|||
|
|
skynet.server.bag:RemoveGoods( player , dataType.GoodsType_Furniture , goodsId , 1 )
|
|||
|
|
--加入闲菜卖家数据
|
|||
|
|
local cfgGoods = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture", goodsId )
|
|||
|
|
local discount = cfgSValue.picklesSellDiscount
|
|||
|
|
local sellTime = skynet.GetTime() + (math.floor(cfgSValue.picklesDeliveryTime * discount * cfgGoods.coin ) * 60) --计算售卖时间
|
|||
|
|
--sellTime = skynet.GetTime() + 20
|
|||
|
|
|
|||
|
|
table.insert( sellInfo , { goodsId = goodsId , status = self.SellStatus_NoSell , npcNameId = 0 , copyId = 0 , coin = math.floor(cfgGoods.coin * discount) , sellTime = sellTime })
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 售卖操作 开始售卖 商品ID %d" , player.basicInfo.userID , goodsId))
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoGoodsID
|
|||
|
|
end
|
|||
|
|
elseif self.SellOPType_StopSell == opType then --停止出售
|
|||
|
|
for k, v in pairs( sellInfo ) do
|
|||
|
|
if self.SellStatus_NoSell == v.status and goodsId == v.goodsId then
|
|||
|
|
--未卖出并且找到对应的商品ID
|
|||
|
|
local cfgGoods = skynet.server.gameConfig:GetPlayerCurCfg( player , "Furniture", goodsId )
|
|||
|
|
skynet.server.bag:AddGoodsNoExp( player , dataType.GoodsType_Furniture , goodsId , 1 )
|
|||
|
|
sellInfo[ k ] = nil
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 售卖操作 停止售卖 商品ID %d" , player.basicInfo.userID , goodsId))
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
elseif self.SellOPType_ConfirmSell == opType then --确定出售
|
|||
|
|
for k, v in pairs( sellInfo ) do
|
|||
|
|
if self.SellStatus_SomeoneWant == v.status and goodsId == v.goodsId then
|
|||
|
|
sellInfo[ k ].status = self.SellStatus_AlreadySell
|
|||
|
|
|
|||
|
|
--领取金币
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_29")
|
|||
|
|
player:MoneyChange( dataType.MoneyType_Coin , v.coin , eventId)
|
|||
|
|
|
|||
|
|
skynet.server.msgTips:Reduce( player , 3)
|
|||
|
|
skynet.server.levelTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.dailyTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.npcTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 4 , v.coin )
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 22 , 1 )
|
|||
|
|
--在闲菜二手收入金币
|
|||
|
|
skynet.server.taskListEvent:Modify( player ,124, v.coin)
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 售卖操作 领取奖励 商品ID %d" , player.basicInfo.userID , goodsId))
|
|||
|
|
break
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
elseif self.SellOPType_AllConfirmSell == opType then
|
|||
|
|
for k, v in pairs( sellInfo ) do
|
|||
|
|
if self.SellStatus_SomeoneWant == v.status then
|
|||
|
|
sellInfo[ k ].status = self.SellStatus_AlreadySell
|
|||
|
|
|
|||
|
|
--领取金币
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_29")
|
|||
|
|
player:MoneyChange( dataType.MoneyType_Coin , v.coin , eventId)
|
|||
|
|
|
|||
|
|
skynet.server.msgTips:ReduceAll( player , 3)
|
|||
|
|
skynet.server.levelTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.dailyTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.npcTask:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 9 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 4 , v.coin )
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 22 , 1 )
|
|||
|
|
--在闲菜二手收入金币
|
|||
|
|
skynet.server.taskListEvent:Modify( player ,124, v.coin)
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 一键售卖操作 领取奖励 商品ID %d" , player.basicInfo.userID , goodsId))
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
self:CheckRefreshGoods( player )
|
|||
|
|
data.sellInfo = self:GetSellInfo( player )
|
|||
|
|
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedSell")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedSell", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜物流
|
|||
|
|
function Used:Logistics( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedLogistics", c2sData.data ))
|
|||
|
|
local data = {}
|
|||
|
|
data.goodsId = {}
|
|||
|
|
|
|||
|
|
local goodsId = c2sData.data.goodsId
|
|||
|
|
if 0 == #goodsId then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
for k, oneGoodsId in pairs( goodsId ) do
|
|||
|
|
if not oneGoodsId then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
else
|
|||
|
|
for k, v in pairs( player.gameData.used.logisticsInfo ) do
|
|||
|
|
if self.GoodsStatus_AlreadyReach == v.goodsStatus and oneGoodsId == v.goodsId then
|
|||
|
|
--签收物流中商品
|
|||
|
|
skynet.server.bag:AddGoods( player , dataType.GoodsType_Furniture , oneGoodsId , 1 )
|
|||
|
|
v.goodsStatus = self.GoodsStatus_AlreadyGet
|
|||
|
|
skynet.server.levelTask:Modify( player , 10 , 1)
|
|||
|
|
skynet.server.levelTask:Modify( player , 95 , 1)
|
|||
|
|
skynet.server.dailyTask:Modify( player , 10 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 95 , 1)
|
|||
|
|
skynet.server.taskListEvent:Modify( player , 10 , 1)
|
|||
|
|
table.insert( data.goodsId , oneGoodsId )
|
|||
|
|
skynet.server.msgTips:Reduce( player , 4)
|
|||
|
|
player:AddExpForType( 4 )
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 物流签收 领取奖励 商品ID %d" , player.basicInfo.userID , oneGoodsId))
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
self:CheckRefreshGoods( player )
|
|||
|
|
data.logisticsInfo = self:GetLogisticsInfo( player )
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedLogistics")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedLogistics", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜物流展示
|
|||
|
|
function Used:LogisticsShow( player , c2sData , s2cData )
|
|||
|
|
local data = {}
|
|||
|
|
data.logisticsInfo =self:GetLogisticsInfo( player )
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedLogisticsShow")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedLogisticsShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜查看仓库
|
|||
|
|
function Used:StorageShow( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedStorageShow", c2sData.data ))
|
|||
|
|
local data = {}
|
|||
|
|
local goodsType = c2sData.data.goodsType
|
|||
|
|
if not goodsType then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
else
|
|||
|
|
data.goodsType = goodsType
|
|||
|
|
data.goodsInfo = skynet.server.bag:GetUnusedGoodsInfo( player , goodsType )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
self:CheckRefreshGoods( player )
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedStorageShow")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedStorageShow", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--闲菜出售加速
|
|||
|
|
function Used:SellAccelerate( player , c2sData , s2cData )
|
|||
|
|
c2sData.data = assert(pb.decode("C2SUsedSellAccelerate", c2sData.data ))
|
|||
|
|
local data = {}
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
local eventId = pb.enum("EnumMoneyChangeEventID","EventID_7")
|
|||
|
|
|
|||
|
|
local methodType = c2sData.data.methodType
|
|||
|
|
|
|||
|
|
local isSuc = false
|
|||
|
|
if dataType.AccelerateType_Volute == methodType and player:MoneyChange( dataType.MoneyType_Volute , -cfgSValue.pickleCustomerCost, eventId ) then
|
|||
|
|
isSuc = true
|
|||
|
|
elseif dataType.AccelerateType_ADTicket == methodType and skynet.server.ad:CanWatch(player, "UsedSellAcc") and
|
|||
|
|
skynet.server.ad:PayADTicket(player, "UsedSellAcc") then --扣除广告券
|
|||
|
|
isSuc = true
|
|||
|
|
elseif dataType.AccelerateType_WatchAD == methodType and skynet.server.ad:CanWatch(player, "UsedSellAcc") then --观看广告
|
|||
|
|
skynet.server.ad:Update(player, "UsedSellAcc")
|
|||
|
|
isSuc = true
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if not isSuc then
|
|||
|
|
if dataType.AccelerateType_Volute == methodType then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
|
|||
|
|
elseif dataType.AccelerateType_ADTicket == methodType then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.NoEnoughProp
|
|||
|
|
elseif dataType.AccelerateType_WatchAD == methodType then
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.TodayMaxLimit
|
|||
|
|
else
|
|||
|
|
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
self:AccSell( player ) --加速
|
|||
|
|
data.sellInfo = self:GetSellInfo( player )
|
|||
|
|
end
|
|||
|
|
s2cData.cmd = pb.enum("MsgType","CMD_S2C_UsedSellAccelerate")
|
|||
|
|
s2cData.data = assert(pb.encode("S2CUsedSellAccelerate", data))
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--检查商品是否能刷新
|
|||
|
|
function Used:CheckRefreshGoods( player )
|
|||
|
|
--刷新商店购买时间
|
|||
|
|
if skynet.GetTime() >= player.gameData.used.buyRefreshTime then
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
player.gameData.used.buyRefreshTime = skynet.GetTime() + cfgSValue.picklesRefreshTime * 60
|
|||
|
|
player.gameData.used.buyInfo = self:RefreshGoods( player )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--刷新已经卖出的商品
|
|||
|
|
for k, v in pairs( player.gameData.used.sellInfo ) do
|
|||
|
|
if skynet.GetTime() >= v.sellTime and self.SellStatus_NoSell == v.status then
|
|||
|
|
--成功售卖
|
|||
|
|
player.gameData.used.sellInfo[ k ].status = self.SellStatus_SomeoneWant
|
|||
|
|
|
|||
|
|
--随机NPC名字ID
|
|||
|
|
local cfgNPCName = skynet.server.gameConfig:GetPlayerAllCfg( player , "NPCName")
|
|||
|
|
local npcNameList = skynet.server.common:RandNoRepeatItemForCfg( 1 , cfgNPCName )
|
|||
|
|
if not npcNameList then
|
|||
|
|
log.warning("闲菜随机的NPC名字异常 ", npcNameList )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--随机文案ID
|
|||
|
|
local cfgAllCopy = skynet.server.gameConfig:GetPlayerAllCfg( player , "Copy")
|
|||
|
|
local cfgCopy = {}
|
|||
|
|
for k, v in pairs( cfgAllCopy ) do
|
|||
|
|
if self.CopyType_Buyer == v.type then
|
|||
|
|
table.insert( cfgCopy , v)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
local copyList = skynet.server.common:RandNoRepeatItemForCfg( 1 , cfgCopy )
|
|||
|
|
if not copyList then
|
|||
|
|
log.warning("闲菜随机的文案ID异常 ", copyList , #copyList)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
player.gameData.used.sellInfo[ k ].npcNameId = npcNameList[1]
|
|||
|
|
player.gameData.used.sellInfo[ k ].copyId = copyList[1]
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--刷新物流是否到了
|
|||
|
|
for k, v in pairs( player.gameData.used.logisticsInfo ) do
|
|||
|
|
if skynet.GetTime() >= v.reachTime and self.GoodsStatus_NoReach == v.goodsStatus then
|
|||
|
|
--商品已到达
|
|||
|
|
player.gameData.used.logisticsInfo[ k ].goodsStatus = self.GoodsStatus_AlreadyReach
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
--刷新购买商品
|
|||
|
|
function Used:RefreshGoods( player )
|
|||
|
|
local count = 0
|
|||
|
|
local buyInfo = {}
|
|||
|
|
local maxItem = 6 --最大生成
|
|||
|
|
local used = player.gameData.used
|
|||
|
|
|
|||
|
|
local goodsList = skynet.server.shop:GetRandUsedGoods( player , used.historyRefreshGoods , maxItem )
|
|||
|
|
if not goodsList or maxItem ~= #goodsList then
|
|||
|
|
used.historyRefreshGoods = {}
|
|||
|
|
goodsList = skynet.server.shop:GetRandUsedGoods( player , used.historyRefreshGoods , maxItem )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
if used.isFirstRefresh then
|
|||
|
|
--第一次刷新,给指定商品
|
|||
|
|
used.isFirstRefresh = false
|
|||
|
|
goodsList = {}
|
|||
|
|
table.insert( goodsList , 206)
|
|||
|
|
table.insert( goodsList , 209)
|
|||
|
|
table.insert( goodsList , 99)
|
|||
|
|
table.insert( goodsList , 106)
|
|||
|
|
table.insert( goodsList , 7)
|
|||
|
|
table.insert( goodsList , 205)
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = 206 })
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = 209 })
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = 99 })
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = 106 })
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = 7 })
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = 205 })
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--随机NPC名字ID
|
|||
|
|
local cfgNPCName = skynet.server.gameConfig:GetPlayerAllCfg( player , "NPCName")
|
|||
|
|
local npcNameList = skynet.server.common:RandNoRepeatItemForCfg( maxItem , cfgNPCName )
|
|||
|
|
if not npcNameList or maxItem ~= #npcNameList then
|
|||
|
|
log.warning("闲菜随机的NPC名字异常 ", npcNameList , #npcNameList)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--随机文案ID
|
|||
|
|
local cfgAllCopy = skynet.server.gameConfig:GetPlayerAllCfg( player , "Copy")
|
|||
|
|
local cfgCopy = {}
|
|||
|
|
for k, v in pairs( cfgAllCopy ) do
|
|||
|
|
if self.CopyType_Seller == v.type then
|
|||
|
|
table.insert( cfgCopy , v)
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
local copyList = skynet.server.common:RandNoRepeatItemForCfg( maxItem , cfgCopy )
|
|||
|
|
if not copyList or maxItem ~= #copyList then
|
|||
|
|
log.warning("闲菜随机的文案ID异常 ", copyList , #copyList)
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--从3个配置中去随机,万一哪个配置被动了,可能会遇到没有随机到指定数量的配置,那么在3个中找一个数量最少的去生成
|
|||
|
|
local count1 = #goodsList
|
|||
|
|
local count2 = #npcNameList
|
|||
|
|
local count3 = #copyList
|
|||
|
|
|
|||
|
|
if maxItem < count1 then
|
|||
|
|
maxItem = count1
|
|||
|
|
end
|
|||
|
|
if maxItem < count2 then
|
|||
|
|
maxItem = count2
|
|||
|
|
end
|
|||
|
|
if maxItem < count3 then
|
|||
|
|
maxItem = count3
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取最终商品
|
|||
|
|
local discountCoin = 0
|
|||
|
|
for i = 1, maxItem, 1 do
|
|||
|
|
discountCoin = self:GetDiscountPrice( player , goodsList[i] )
|
|||
|
|
local buyCount = skynet.server.bag:GetGoodsCount(player, dataType.GoodsType_Furniture, goodsList[i] ) --看看背包有多少个
|
|||
|
|
table.insert( buyInfo , { goodsId = goodsList[i] , npcNameId = npcNameList[i] , copyId = copyList[i] , isBuy = false , coin = discountCoin , buyCount = buyCount })
|
|||
|
|
table.insert( used.historyRefreshGoods , { id = goodsList[i] })
|
|||
|
|
log.debug(string.format("玩家 %d 闲菜 刷新商品 商品ID %d NPC名字ID %d 对白ID %d 金币 %d 数量 %d" , player.userId , goodsList[i] , npcNameList[i] , copyList[i] , discountCoin , buyCount))
|
|||
|
|
end
|
|||
|
|
return buyInfo
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--广告加速卖出
|
|||
|
|
function Used:AccSell( player )
|
|||
|
|
for k, v in pairs( player.gameData.used.sellInfo ) do
|
|||
|
|
--所有未卖出商品全部可以卖出
|
|||
|
|
if self.SellStatus_NoSell == v.status then
|
|||
|
|
v.sellTime = 0
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--刷新一下
|
|||
|
|
self:CheckRefreshGoods( player )
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取折扣价格
|
|||
|
|
function Used:GetDiscountPrice( player , id )
|
|||
|
|
local cfgFurniture = skynet.server.gameConfig:GetPlayerAllCfg( player , "Furniture")
|
|||
|
|
local cfgSValue = skynet.server.gameConfig:GetPlayerAllCfg( player , "SValue")
|
|||
|
|
local picklesBuyDiscount = cfgSValue.picklesBuyDiscount
|
|||
|
|
local ratio = math.random( picklesBuyDiscount[1] , picklesBuyDiscount[2]) / 100
|
|||
|
|
for k, v in pairs( cfgFurniture ) do
|
|||
|
|
if id == v.id then
|
|||
|
|
local price = math.ceil(ratio * v.coin)
|
|||
|
|
log.debug(string.format("闲菜计算商品折扣 最终金币数价格 %d 折扣率 %f 原需要金币数 %d" , price , ratio , v.coin))
|
|||
|
|
return price
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取售卖数据
|
|||
|
|
function Used:GetSellInfo( player )
|
|||
|
|
local data = {}
|
|||
|
|
for k, v in pairs( player.gameData.used.sellInfo ) do
|
|||
|
|
table.insert( data , v)
|
|||
|
|
end
|
|||
|
|
return data
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
--获取物流数据
|
|||
|
|
function Used:GetLogisticsInfo( player )
|
|||
|
|
local data = {}
|
|||
|
|
for k, v in pairs( player.gameData.used.logisticsInfo ) do
|
|||
|
|
table.insert( data , v)
|
|||
|
|
end
|
|||
|
|
return data
|
|||
|
|
end
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
skynet.server.used = Used
|
|||
|
|
return Used
|