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

182 lines
5.6 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.

------------------------------------------------
--作者: cy
--日期: 2019-04-16
--文件: OfflineOnHookSystem.lua
--模块: OfflineOnHookSystem
--描述: 离线挂机系统
------------------------------------------------
local RedPointCustomCondition = CS.Thousandto.Code.Logic.RedPointCustomCondition
local OfflineOnHookSystem = {
AddExpItemID = {1003, 1002, 1001},
GoToShopItemID = 1002,
AddOnHookTimeItemID = {1031, 1004},
RemainOnHookTime = 0, --精确到秒
OfflineHookResult = {},
CurWorldLevel = 0, --当前世界等级
ExpAddRateDic = Dictionary:New(), --经验加成字典key = typevalue = 加成值
--药品剩余时间
ItemRemainTime = 0,
--药品同步的时间,用于计算剩余时间
ItemSyncTime = 0,
TimerEventID = 0,
--可找回的时间
CanFindTime = 0,
--可找回的经验值
CanFindExpValue = 0,
}
function OfflineOnHookSystem:Initialize()
self.TimerEventID = GameCenter.TimerEventSystem:AddTimeStampHourEvent(10, 1,
true, nil, function(id, remainTime, param)
self:ReqHookSetInfo()
end)
end
function OfflineOnHookSystem:UnInitialize()
GameCenter.TimerEventSystem:RemoveTimerEvent(self.TimerEventID)
end
function OfflineOnHookSystem:ReqHookSetInfo()
GameCenter.Network.Send("MSG_Hook.ReqHookSetInfo", {})
end
function OfflineOnHookSystem:GS2U_ResHookSetInfo(result)
self.RemainOnHookTime = result.hookRemainTime
self.CurWorldLevel = result.worldlevel
self.ExpAddRateDic = Dictionary:New()
for i=1,#result.expAddRateList do
local _type = result.expAddRateList[i].type
local _rate = result.expAddRateList[i].rate
local _cfg = DataConfig.DataOnHookC[_type]
if _cfg ~= nil then
self.ExpAddRateDic:Add(_type, _rate)
end
end
self.ItemRemainTime = result.curExpItemRamineTime
self.ItemSyncTime = Time.GetRealtimeSinceStartup()
--self.ExpAddRateList = List:New(result.expAddRateList)
self:CheckTimeRedPoint()
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UPDATE_HOOKSITTING, result)
end
function OfflineOnHookSystem:GS2U_ResOfflineHookResult(result)
self.RemainOnHookTime = result.hookRemainTime
self.OfflineHookResult = result
self:CheckTimeRedPoint()
GameCenter.PushFixEvent(UIEventDefine.UIOnHookForm_OPEN)
end
--经验加成改变
function OfflineOnHookSystem:GS2U_ResExpRateChange(result)
if self.ExpAddRateDic == nil then
self.ExpAddRateDic = Dictionary:New()
end
local _type = result.info.type
local _rate = result.info.rate
local _cfg = DataConfig.DataOnHookC[_type]
if _cfg ~= nil then
self.ExpAddRateDic[_type] = _rate
end
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UPDATE_HOOKSITTING, result)
end
--返回的是整数
function OfflineOnHookSystem:GetHourAndMinuteBySecond(second)
local h = second / 3600
second = second % 3600
local m = second / 60
--返回整数
return math.modf( h ), math.modf( m )
end
--获取经验加成百分制type = OnHookExpAddType
function OfflineOnHookSystem:GetMainFormShowExpRate(expAddType)
local _retValue = 0
self.ExpAddRateDic:Foreach(
function(key, value)
if key == expAddType then
_retValue = _retValue + value
end
end
)
return _retValue
end
--获取总的经验加成,百分制
function OfflineOnHookSystem:GetTotalExpAddRate()
local _retValue = 0
self.ExpAddRateDic:Foreach(
function(key, value)
if key == OnHookExpAddType.WorldLevel and GameCenter.VipSystem.CurRecharge <= 0 then
else
_retValue = _retValue + value
end
end
)
return _retValue
end
--获取其他的经验加成,百分制
function OfflineOnHookSystem:GetOtherExpAddRate()
local _lp = GameCenter.GameSceneSystem:GetLocalPlayer()
if _lp == nil then
return 0
end
local _result = (_lp.PropMoudle.KillMonsterExpPercent // 100) - self:GetTotalExpAddRate()
if _result < 0 then
_result = 0
end
return _result
end
--获取当前经验药品加成倍率,百分制
function OfflineOnHookSystem:GetCurItemAddRate()
return self:GetMainFormShowExpRate(OnHookExpAddType.Drug)
end
--获取当前世界等级
function OfflineOnHookSystem:GetCurWorldLevel()
return self.CurWorldLevel
end
--获取经验药剩余时间
function OfflineOnHookSystem:GetItemExpRemainTime()
local _time = self.ItemRemainTime - (Time.GetRealtimeSinceStartup() - self.ItemSyncTime)
if _time < 0 then
_time = 0
end
return _time
end
--检测红点
function OfflineOnHookSystem:CheckTimeRedPoint()
--剩余时间小于5消失展示红点
GameCenter.RedPointSystem:CleraFuncCondition(FunctionStartIdCode.OnHookSettingForm)
GameCenter.RedPointSystem:AddFuncCondition(FunctionStartIdCode.OnHookSettingForm, 0, RedPointCustomCondition(self.RemainOnHookTime <= (5 * 60 * 60)))
end
--判断是否是离线经验道具
function OfflineOnHookSystem:IsOffLineTimeItem(itemId)
for i = 1, #self.AddOnHookTimeItemID do
if self.AddOnHookTimeItemID[i] == itemId then
return true
end
end
return false
end
--离线找回经验
function OfflineOnHookSystem:ResOfflineHookFindTime(msg)
--可找回的时间
self.CanFindTime = msg.offlineTime
--可找回的经验值
self.CanFindExpValue = msg.exp
GameCenter.MainFunctionSystem:SetFunctionVisible(FunctionStartIdCode.OfflineFind, self.CanFindTime > 0 and self.CanFindExpValue > 0)
GameCenter.PushFixEvent(LogicLuaEventDefine.EID_EVENT_UPDATE_OFFLINEFINDTIME)
end
return OfflineOnHookSystem