Files
Main/Assets/GameAssets/Resources/Lua/Logic/Present/PresentSystem.lua
2025-01-25 04:38:09 +08:00

160 lines
4.2 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

------------------------------------------------
-- 作者: 陈锡涵
-- 日期: 2020-7-29
-- 文件: PresentSystem.lua
-- 模块: PresentSystem
-- 描述: 礼物赠送系统
------------------------------------------------
local PresentSystem = {
SendData = nil,
RecData = nil
}
function PresentSystem:Initialize()
end
function PresentSystem:UnInitialize()
self.SendData = nil;
self.RecData = nil;
end
-- 是否有可赠送的道具
function PresentSystem:IsHavePresent()
local _isHave = false;
local _func = function(k, v)
if GameCenter.ItemContianerSystem:GetItemCountFromCfgId(v.Id) > 0 then
_isHave = true;
return true;
end
end
DataConfig.DataItemGift:ForeachCanBreak(_func)
return _isHave;
end
function PresentSystem:IsRedpoint()
return self:GetNotReadPresentCount() > 0;
end
function PresentSystem:GetNotReadPresentCount()
local _count = 0;
if self.RecData then
for i = 1, #self.RecData do
if self.RecData[i].readStatus == 0 then
_count = _count + 1;
end
end
end
return _count;
end
-- 赠送好友礼物是否成功返回
function PresentSystem:ReqReadGiftLog(ids)
local _req = ReqMsg.MSG_Player.ReqReadGiftLog:New();
_req.ids = ids;
_req:Send();
end
-- 赠送好友礼物是否成功返回
function PresentSystem:ResSendGift(msg)
if msg.result == 0 then
if not self.SendData then
self.SendData = {}
end
if msg.log and #msg.log > 0 then
for i = 1, #msg.log do
table.insert(self.SendData, msg.log[i])
end
end
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SENDGIFT_RESULT, msg)
end
-- required int32 type = 1; //0发送1接收
-- repeated GiftLog recordList = 2; //日志列表
-- 接收及赠送日志返回
function PresentSystem:ResGetGiftLog(msg)
local _list = msg.recordList or {}
local _cnt = #_list
if msg.type == 0 then
self.SendData = msg.recordList;
elseif msg.type == 1 then
self.RecData = msg.recordList;
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SENDGIFT_LOG_UPDATE)
end
-- 新的接收礼物日志
function PresentSystem:ResNewGiftLog(msg)
if not self.RecData then
self.RecData = {}
end
if msg.log and #msg.log > 0 then
for i = 1, #msg.log do
table.insert(self.RecData, msg.log[i])
end
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SENDGIFT_LOG_UPDATE)
end
-- 读取返回
function PresentSystem:ResReadGiftLog(msg)
if self.RecData and msg.ids and #msg.ids > 0 then
for i = 1, #msg.ids do
for j = 1, #self.RecData do
if msg.ids[i] == self.RecData[j].id then
self.RecData[j].readStatus = 1;
end
end
end
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_SENDGIFT_LOG_UPDATE)
end
return PresentSystem
-- message Gift {
-- required int32 giftId = 1;//item.gift表中的id
-- required int32 giftNumber = 2;
-- }
-- message ReqSendGift {
-- enum MsgID { eMsgID = 105241; };
-- required int32 type = 1;
-- required int64 roleId = 2;//要赠送的玩家id
-- required bool force = 3;//true表示强制赠送false表示不强制赠送
-- repeated Gift gifts = 4;
-- }
-- message ResSendGift {
-- enum MsgID { eMsgID = 105141; };
-- required int32 result = 1;//0表示赠送成功1表示我不是对方好友
-- }
-- message GiftLog {
-- required int64 id = 1; //id
-- required int32 type = 2; //0发送1接收
-- required string sender = 3; //发送者
-- required string receiver = 4; //接收者
-- required int32 itemId = 5; //物品id
-- required int32 num = 6; //数量
-- required int32 time = 7; //发送时间
-- required int32 readStatus = 8; //读取状态
-- }
-- message ReqGetGiftLog {
-- enum MsgID { eMsgID = 105242; };
-- required int32 type = 1; //0发送1接收
-- }
-- message ReqReadGiftLog {
-- enum MsgID { eMsgID = 105245; };
-- repeated int64 ids = 1; //读取接收礼物的id列表
-- }
-- message ResNewGiftLog {
-- enum MsgID { eMsgID = 105146; };
-- required GiftLog log = 1; //新增赠送日志
-- }