HomeServer/lualib-src/Server-main/AllServer/GameServer/Shop/FashionShop.lua

120 lines
4.7 KiB
Lua
Raw Normal View History

2024-11-20 15:41:09 +08:00
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 FashionShop = oo.class(shop)
FashionShop.PurchaseType_1 = 1 --服装商店购买
FashionShop.PurchaseType_2 = 2 --活动获取
function FashionShop:Init()
end
--显示一种类型
function FashionShop:Show( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SFashionShopShow", c2sData.data ))
local shopType = dataType.ShopType_Fashion
local data = {}
data.shopInfo = {}
--时间超过了,刷新新的一批
if skynet.GetTime() >= player.gameData.shop[ shopType ].nextRefreshTime then
self:RefreshShop( player , shopType )
end
--获取最新的商店数据
data.shopInfo = self:GetShopData(player , shopType )
s2cData.cmd = pb.enum("MsgType","CMD_S2C_FashionShopShow")
s2cData.data = assert(pb.encode("S2CFashionShopShow", data))
end
--商店购买
function FashionShop:Buy( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SFashionShopBuy", c2sData.data ))
local goodsId = c2sData.data.goodsId
local data = {}
local shopType = dataType.ShopType_Fashion
local curShop = player.gameData.shop[ shopType ]
--特殊商品购买
if not goodsId then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
for k, v in pairs( player.gameData.shop[ shopType ].suitGoods ) do
if goodsId == v.id then
--先扣钱,再发货
local cfgClothes = skynet.server.gameConfig:GetCurCfg("Clothes" , goodsId)
--local moneyType , moneyCount = self:GetClothesPrice( goodsId )
local clothesType = cfgClothes.type
local moneyType , moneyCount = skynet.server.gameConfig:GetBuyMoney("Clothes" , goodsId ) --dataType.MoneyType_Map , cfgClothes.diomond
if moneyType and player:MoneyChange( moneyType , -moneyCount ) then
player.gameData.shop[ shopType ].suitGoods[ k ].buyCount = 1
skynet.server.bag:AddGoods( player , dataType.GoodsType_Clothes , goodsId , 1 )
log.info(string.format("玩家 %d 每日时尚商店 购买成功 商品 %d 扣除四叶草 %d" , player.basicInfo.userID , goodsId , moneyCount))
else
log.info(string.format("玩家 %d 每日时尚商店 购买失败 商品 %d " , player.basicInfo.userID , goodsId))
s2cData.code = errorInfo.ErrorCode.NoEnoughMoney
end
break
end
end
end
data.shopInfo = self:GetShopData(player , shopType )
s2cData.cmd = pb.enum("MsgType","CMD_S2C_FashionShopBuy")
s2cData.data = assert(pb.encode("S2CFashionShopBuy", data))
end
--刷新商店类型
function FashionShop:RefreshShop( player , shopType )
local suitCount = 0 --#skynet.server.gameConfig.ClothesSuit --套间总数量
local cfgClothesSuit = skynet.server.gameConfig.ClothesSuit
for k, v in pairs( cfgClothesSuit ) do
if self.PurchaseType_1 == v.purchaseType then
suitCount = suitCount + 1
end
end
player.gameData.shop[ shopType ].curSuitType = player.gameData.shop[ shopType ].curSuitType + 1
--套装ID超过套间数量时又从第一套开始
if player.gameData.shop[ shopType ].curSuitType > suitCount then
player.gameData.shop[ shopType ].curSuitType = 1
end
local curSuitType = player.gameData.shop[ shopType ].curSuitType
local newGoods = self:GetSuitFashion( curSuitType )
self:SetShopData( player , shopType , newGoods )
--刷新时间
player.gameData.shop[ shopType ].nextRefreshTime = skynet.server.common:GetAfterSomeDay(1)
end
--设置商店数据
function FashionShop:SetShopData( player , shopType , newGoods )
player.gameData.shop[ shopType ].suitGoods = {}
for k, v in pairs( newGoods ) do
local buyCount = 0 --是否购买
if player:IsBuyGoods( dataType.GoodsType_Clothes , v ) then
buyCount = 1
end
table.insert( player.gameData.shop[ shopType ].suitGoods , { id = v , buyCount = buyCount} )
log.info(string.format("玩家 %d 每日时尚商店 设置商店数据 最新套装商品 ID %d 是否购买 %d" , player.basicInfo.userID , v , buyCount ))
end
end
--获取商店数据
function FashionShop:GetShopData( player , shopType )
local shopInfo = {}
shopInfo.suitGoods = player.gameData.shop[ shopType ].suitGoods
shopInfo.nextRefreshTime = player.gameData.shop[ shopType ].nextRefreshTime
return shopInfo
end
skynet.server.fashionShop = FashionShop
return FashionShop