HomeServer/lualib-src/Server-main/AllServer/GameServer/MsgTips.lua

369 lines
12 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 MsgTips = oo.class()
--检查一下玩家是否有新的消息提示
function MsgTips:CheckNew( player )
player.tmpData.lastRefreshTime = 0 --上一次刷新时间
local cfgTask = skynet.server.gameConfig.PhoneMsg --消息配置
for k, v in pairs( cfgTask ) do
if not player.gameData.msgTips.data[ v.id ] then
player.gameData.msgTips.data[ v.id ] = {}
player.gameData.msgTips.data[ v.id ].id = v.id
player.gameData.msgTips.data[ v.id ].isRefresh = true --是否能刷新
player.gameData.msgTips.data[ v.id ].count = 0 --数量
end
end
end
--消息提示确认
function MsgTips:Confirm( player , c2sData , s2cData )
c2sData.data = assert(pb.decode("C2SMsgTipsConfirm", c2sData.data ))
local data = {}
local id = c2sData.data.tipsInfo.id
local count = c2sData.data.tipsInfo.count
if not id or not count then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
local msgTips = player.gameData.msgTips.data[ id ]
if not msgTips then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
else
msgTips.isRefresh = true
--只种设置面板中领奖的
if id >= 20 and id <= 22 then
msgTips.count = 0
end
--[[
if 15 ~= id then
msgTips.count = msgTips.count - count
if msgTips.count < 0 then
msgTips.count = 0
end
end
]]
data.tipsInfo = self:GetOneTips( player , id )
data.reward = {}
--只有部分可以红点领奖
for k, v in pairs( player.gameData.msgTips.reward ) do
if id == v.id and dataType.Status_CanGain == v.status then
local goodsType = v.goodsType
local goodsId = v.goodsId
local goodsCount = v.goodsCount
data.reward = { goodsType = goodsType , goodsId = goodsId , goodsCount = goodsCount }
skynet.server.bag:AddGoods( player , goodsType , goodsId , goodsCount )
v.status = dataType.Status_AlreadyGain
log.info(string.format("玩家 %d 消息提示 领取奖励 消息ID %d 物品类型 %d 物品ID %d 物品数量 %d" , player.userId , id , goodsType , goodsId , goodsCount))
end
end
end
end
s2cData.cmd = pb.enum("MsgType","CMD_S2C_MsgTipsConfirm")
s2cData.data = assert(pb.encode("S2CMsgTipsConfirm", data))
end
--发送最新的消息提示
function MsgTips:SendLastTips( player , msgId )
local data = {}
data.tipsInfo = self:GetOneTips( player , msgId )
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_MsgTipsNotice" , data )
end
--增加提示
function MsgTips:Add( player , id , count )
count = count or 1
local msgTips = player.gameData.msgTips.data[ id ]
if not msgTips then
return
end
local phoneMsg = skynet.server.gameConfig:GetPhoneMsgCfg( id )
if not phoneMsg then
return
end
--未解锁的不发红点
if 1 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_Gift) or
2 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_Used) or
3 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_Furniture) or
4 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_Clothing) or
5 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_Plant) or
6 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_MoveHome) or
7 == phoneMsg.msgType and not player:IsUnlockSystem( dataType.UnlockSystem_Friend) then
return
end
msgTips.isRefresh = false
msgTips.count = msgTips.count + count
if id >= 20 and id <= 22 then
local goodsId = 0
if 20 == id then
goodsId = 674
elseif 21 == id then
goodsId = 672
elseif 22 == id then
goodsId = 673
end
local isExist = false
for k, v in pairs( player.gameData.msgTips.reward ) do
if id == v.id then
isExist = true
end
end
if not isExist then
local reward = {}
reward.id = id
reward.status = dataType.Status_CanGain
reward.goodsType = pb.enum("EnumGoodsType" ,"Furniture")
reward.goodsId = goodsId
reward.goodsCount = 1
table.insert( player.gameData.msgTips.reward , reward )
end
end
local data = {}
data.tipsInfo = self:GetOneTips( player , id )
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_MsgTipsNotice" , data )
log.info(string.format("玩家 %d 消息提示 发送红点 消息ID %d " , player.userId , id))
end
--重置为0
function MsgTips:Reset( player , id )
local msgTips = player.gameData.msgTips
if msgTips.data[ id ] then
msgTips.data[ id ].count = 0
end
end
--减少
function MsgTips:Reduce( player , id )
local msgTipsData = player.gameData.msgTips.data[ id ]
if msgTipsData and msgTipsData.count > 0 then
msgTipsData.count = msgTipsData.count - 1
if msgTipsData.count < 0 then
msgTipsData.count = 0
end
local data = {}
data.tipsInfo = self:GetOneTips( player , id )
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_MsgTipsNotice" , data )
self:Get(player ,id).isRefresh = true
end
end
--减少所有
function MsgTips:ReduceAll( player , id )
local msgTipsData = player.gameData.msgTips.data[ id ]
if msgTipsData and msgTipsData.count > 0 then
msgTipsData.count = 0
local data = {}
data.tipsInfo = self:GetOneTips( player , id )
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_MsgTipsNotice" , data )
self:Get(player ,id).isRefresh = true
end
end
--增加提示
function MsgTips:AddNoNotice( player , id )
local msgTips = player.gameData.msgTips.data[ id ]
if not msgTips then
return
end
msgTips.count = msgTips.count + 1
end
--获取TIPS信息
function MsgTips:Get( player , id )
return player.gameData.msgTips.data[ id ]
end
--获取当个TIPS信息
function MsgTips:GetOneTips( player , id )
return { id = id , count = player.gameData.msgTips.data[ id ].count }
end
--获取所有TIPS信息
function MsgTips:GetAllTips( player )
local tipsInfo = {}
for id, v in pairs( player.gameData.msgTips.data ) do
table.insert( tipsInfo , { id = id , count = v.count })
end
return tipsInfo
end
--刷新
function MsgTips:Refresh( player )
if skynet.GetTime() < player.tmpData.lastRefreshTime then
return
end
player.tmpData.lastRefreshTime = skynet.GetTime() + 60
local time = skynet.GetTime()
local gameData = player.gameData
if self:Get(player ,3).isRefresh then
--出售的商品有买家来下单啦!
for k, v in pairs( gameData.used.sellInfo ) do
if time >=v.sellTime and skynet.server.used.SellStatus_NoSell == v.status then
self:Add( player , 3 )
break
end
end
end
if self:Get(player ,4).isRefresh then
--快递已送达,快去取件吧
for k, v in pairs( gameData.used.logisticsInfo ) do
if time >= v.reachTime and skynet.server.used.GoodsStatus_AlreadyReach == v.goodsStatus then
self:Add( player , 4 )
--通知客户端
local data = {}
data.logisticsInfo = skynet.server.used:GetLogisticsInfo( player )
skynet.server.gameServer:SendMsgToUser( player.userId , "CMD_S2C_UsedLogisticsShow" , data )
break
end
end
end
if self:Get(player ,5).isRefresh then
--家具换货咯,快来看看
local shopType = dataType.ShopType_Furniture
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 5 )
end
end
if self:Get(player ,6).isRefresh then
--摆件换货咯,快来看看
local shopType = dataType.ShopType_Cinnabar
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 6 )
end
end
if self:Get(player ,7).isRefresh then
--装修换货咯,快来看看
local shopType = dataType.ShopType_Decorate
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 7 )
end
end
if self:Get(player ,8).isRefresh then
--套间展示更换咯,快来看看
local shopType = dataType.ShopType_Suit
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 8 )
end
end
if self:Get(player ,9).isRefresh then
--服饰换货咯,快来看看
local shopType = dataType.ShopType_Clothes
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 9 )
end
end
if self:Get(player ,10).isRefresh then
--装扮换货咯,快来看看
local shopType = dataType.ShopType_Fashion
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 10 )
end
end
if self:Get(player ,11).isRefresh then
--植物种子换货咯,快来看看
local shopType = dataType.ShopType_Seed
if gameData.shop[ shopType ] and time >= gameData.shop[ shopType ].nextRefreshTime then
self:Add( player , 11 )
end
end
if self:Get(player ,12).isRefresh then
--出售的植物被买家买走啦
local shopType = dataType.ShopType_Plant
local curShelf = nil
if gameData.shop[ shopType ] then
for i = 1, skynet.server.plantShop.MaxShelfCount , 1 do
curShelf = gameData.shop[ shopType ].shopShelf[ i ]
if 0 ~= curShelf.goodsId and time >= curShelf.sellTime and not curShelf.isSell then
self:Add( player , 12 )
break
end
end
end
end
if self:Get(player ,13).isRefresh then
--新的花盆解锁了,快来看看
local shopType = dataType.ShopType_Seed
local unlockCount = gameData.plantCount
local flowerpotList = skynet.server.generalShop:GetUnLockFlowerpot( self.FlowerpotType_Seed , unlockCount )
for k1, v1 in pairs( flowerpotList ) do
local isExistFlowerpot = false --是否存在花盆
for k2, v2 in pairs( gameData.shop[ shopType ].specialGoods ) do
if v1 == v2.id then
isExistFlowerpot = true
break
end
end
if not isExistFlowerpot then
self:Add( player , 13 )
break
end
end
end
if self:Get(player ,16).isRefresh then
--闲菜换货咯,快来看看
if time >= gameData.used.buyRefreshTime then
self:Add( player , 16 )
end
end
if self:Get(player ,31).isRefresh then
if time >= gameData.design.advancedFreeTime then
self:Add( player , 31 )
end
end
if self:Get(player ,34).isRefresh then
if time >= gameData.design.basicFreeTime then
self:Add( player , 34 )
end
end
if self:Get(player ,41).isRefresh then
--染色工坊有可领取的 进行添加对应的红点
for k ,v in pairs(gameData.dyeWorkShop.slotData) do
if time >= v.finishTime and v.finishTime>0 then
self:Add( player , 41 )
end
end
end
end
skynet.server.msgTips = MsgTips
return MsgTips