-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProcessMatch.lua
More file actions
85 lines (59 loc) · 2.39 KB
/
ProcessMatch.lua
File metadata and controls
85 lines (59 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
--=================================================================================================
--= Process match
--= ===============================================================================================
--= process a match from chat parsing
--=================================================================================================
-- process match ----------------------------------------------------------------------------------
function ProcessMatch(message, log, logIndex)
local logs = _G.Logs[_G.name].logs
-- open or done
if log.type == 1 then
-- upsert log
logs[logIndex] = {
value = "Done",
timeOfDeath = CalculateDeath(log)
}
-- extract value
elseif log.type == 2 then
-- ...
elseif log.type == 3 then
end
SaveLogs()
end
-- calculate death --------------------------------------------------------------------------------
function CalculateDeath(log)
local currentTime = Turbine.Engine.GetLocalTime()
local current = Turbine.Engine.GetDate()
local daysUntilReset = -1
local dayOfWeek = current.DayOfWeek
while true do
if _G.TableContains(log.reset.days, dayOfWeek) then
break
end
if daysUntilReset > 7 then
-- make sure to break the while
PrintAlert("LL: Error: log has no reset day: " .. log.name)
return
end
daysUntilReset = daysUntilReset + 1
dayOfWeek = dayOfWeek % 7
dayOfWeek = dayOfWeek + 1
end
-- round hours up because minutes will be added
local currentHours = current.Hour + 1
-- add timezone
local resetTimeOfDay = log.reset.time + Settings.timezone
if resetTimeOfDay > currentHours then
-- if resetTime > currentHour add a full day and the rest of the hours
daysUntilReset = daysUntilReset + 1
else
-- if restTime is smaller subtract 24 hours
currentHours = currentHours - 24
end
local timeUntilDeath = (daysUntilReset * 24 * 60 * 60) -- days
timeUntilDeath = timeUntilDeath + ((resetTimeOfDay - currentHours) * 60 * 60) -- hours
timeUntilDeath = timeUntilDeath + ((60 - current.Minute + 1) * 60) -- minutes
timeUntilDeath = timeUntilDeath + (60 - current.Second) -- seconds
Turbine.Shell.WriteLine(currentTime + timeUntilDeath)
return currentTime + timeUntilDeath
end