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

174 lines
5.8 KiB
Lua

------------------------------------------------
--作者: 杨全福
--日期: 2020-08-24
--文件: MarryDatingWallSystem.lua
--模块: MarryDatingWallSystem
--描述: 相亲墙系统
------------------------------------------------
local TimeUtils = CS.Thousandto.Core.Base.TimeUtils
local RedPointCustomCondition = CS.Thousandto.Code.Logic.RedPointCustomCondition
local RedPointLevelCondition = CS.Thousandto.Code.Logic.RedPointLevelCondition
local MarryDatingWallSystem = {
--计时器ID
TimerID = nil,
--活动开始天数
BeginDay = 0,
--活动结束天数
EndDay = 0,
--开服时间
ServerOpenTime = 0,
--是否已经领取等级奖励
IsGetLevelAward = false,
--发送宣言的CD时间
CDTime = 0,
CDSyncTime = 0,
--领奖的等级
GetAwardLevel = 0,
--奖励物品
AwardItems = nil,
--活动结束秒数
EndSec = 0,
--CD计时器
CDTimerID = nil,
}
function MarryDatingWallSystem:Initialize()
local _gCfg = DataConfig.DataGlobal[GlobalName.Marry_Wall_OpenTime]
if _gCfg ~= nil then
local _params = Utils.SplitNumber(_gCfg.Params, '_')
self.BeginDay = _params[1]
self.EndDay = _params[2]
end
_gCfg = DataConfig.DataGlobal[GlobalName.Marry_Wall_Award_Level]
if _gCfg ~= nil then
self.GetAwardLevel = tonumber(_gCfg.Params)
end
_gCfg = DataConfig.DataGlobal[GlobalName.Marry_Wall_Award_Items]
if _gCfg ~= nil then
self.AwardItems = Utils.SplitStrByTableS(_gCfg.Params, {';', '_'})
end
end
function MarryDatingWallSystem:UnInitialize()
if self.TimerID ~= nil then
GameCenter.TimerEventSystem:RemoveTimerEvent(self.TimerID)
end
self.TimerID = nil
if self.CDTimerID ~= nil then
GameCenter.TimerEventSystem:RemoveTimerEvent(self.CDTimerID)
end
self.CDTimerID = nil
end
--获取宣言CD
function MarryDatingWallSystem:GetXuanYanCDTime()
local _result = self.CDTime - (Time.GetRealtimeSinceStartup() - self.CDSyncTime)
if _result <= 0 then
_result = 0
end
return _result
end
--设置开服时间
function MarryDatingWallSystem:SetOpenServerTime(time)
self.ServerOpenTime = math.floor(time / 1000) + GameCenter.HeartSystem.ServerZoneOffset
if self.TimerID ~= nil then
GameCenter.TimerEventSystem:RemoveTimerEvent(self.TimerID)
end
--每天凌晨1秒执行
self.TimerID = GameCenter.TimerEventSystem:AddTimeStampDayEvent(1, 86400,
true, nil, function(id, remainTime, param)
self:CheckFuncOpenState()
end)
local _h, _m, _s = TimeUtils.GetStampTimeHHMMSSNotZone(self.ServerOpenTime)
self.EndSec = self.ServerOpenTime - (_h * 3600 + _m * 60 + _s) + self.EndDay * 86400
--默认显示好友红点
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.MarryWallLevel, 0, RedPointCustomCondition(true))
end
function MarryDatingWallSystem:CheckFuncOpenState()
local _day = TimeUtils.GetDayOffsetNotZone(self.ServerOpenTime, math.floor(GameCenter.HeartSystem.ServerZoneTime)) + 1
if _day >= self.BeginDay and _day <= self.EndDay then
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.MarryWall, true)
else
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.MarryWall, false)
end
end
function MarryDatingWallSystem:CheckCDRedPoint()
local _cdTime = self:GetXuanYanCDTime()
if self.CDTimerID ~= nil then
GameCenter.TimerEventSystem:RemoveTimerEvent(self.CDTimerID)
end
if _cdTime <= 0 then
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.MarryWallXuanYan, true)
else
GameCenter.MainFunctionSystem:SetAlertFlag(FunctionStartIdCode.MarryWallXuanYan, false)
self.CDTimerID = GameCenter.TimerEventSystem:AddCountDownEvent(_cdTime + 3,
true, nil, function(id, remainTime, param)
self:CheckCDRedPoint()
end)
end
end
--请求领取等级奖励
function MarryDatingWallSystem:ReqMarryWallReward()
GameCenter.Network.Send("MSG_Marriage.ReqMarryWallReward", {})
end
--发送宣言
function MarryDatingWallSystem:ReqPushMarryDeclaration(id)
GameCenter.Network.Send("MSG_Marriage.ReqPushMarryDeclaration", {declarationId = id})
end
--请求宣言列表
function MarryDatingWallSystem:ReqMarryWallDeclaration()
GameCenter.Network.Send("MSG_Marriage.ReqMarryWallDeclaration", {})
end
--请求发展关系
function MarryDatingWallSystem:ReqMarryAddFriend(id)
GameCenter.Network.Send("MSG_Marriage.ReqMarryAddFriend", {roleId = id})
end
--等级奖励领取返回
function MarryDatingWallSystem:ResMarryWallRewardInfo(msg)
self.IsGetLevelAward = msg.haveReward == 0
self.CDTime = msg.cd
self.CDSyncTime = Time.GetRealtimeSinceStartup()
self:CheckCDRedPoint()
--领奖红点
GameCenter.RedPointSystem:RemoveFuncCondition(FunctionStartIdCode.MarryWallLevel, 1)
if not self.IsGetLevelAward then
--没有领取奖励的话,增加等级领取红点
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.MarryWallLevel, 1, RedPointLevelCondition(self.GetAwardLevel))
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_MARRY_WALL_GETREWARD)
end
--爱情宣言列表
function MarryDatingWallSystem:ResMarryWallInfo(msg)
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_MARRY_WALL_XUANYAN_LIST, msg)
end
--发展关系通知
function MarryDatingWallSystem:ResMarryAddFriendNotify(msg)
local _roleId = msg.roleId
Utils.ShowMsgBox(function(code)
if code == MsgBoxResultCode.Button2 then
GameCenter.Network.Send("MSG_Marriage.ReqMarryAddFriendOpt", {roleId = _roleId, opt = 1})
else
GameCenter.Network.Send("MSG_Marriage.ReqMarryAddFriendOpt", {roleId = _roleId, opt = 0})
end
end, "C_MARRY_FRIEND_ASK", msg.roleName)
end
return MarryDatingWallSystem