This repository has been archived by the owner on Mar 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
MapRotationCategory.lua
127 lines (116 loc) · 2.78 KB
/
MapRotationCategory.lua
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
local maps = {
-- When queue gets a table value, it'll return a random value when processed.
queue = { 1, 2, 3, { 1, 2, 3 } },
[1] = {
queue = { }, -- Maps goes herem
fBefore = function(mapCode)
-- Triggered before the map gets started
end,
fAfter = function(mapCode)
-- Trigered after the map is started
end
},
[2] = {
queue = { }
},
[3] = {
queue = { }
}
}
do
local shuffle = function(list)
local index
for i = #list, 1, -1 do
index = math.random(i)
list[index], list[i] = list[i], list[index]
end
end
local set = function(list)
local out = { }
for _, index in next, list do
out[index] = true
end
return out
end
maps.queue._next = 1
maps.queue._lastCat = nil
maps.queue._len = #maps.queue
for i = 1, #maps do
shuffle(maps[i].queue)
maps[i] = {
_next = 1, -- Don't change
fBefore = maps[i].fBefore,
fAfter = maps[i].fAfter,
queue = maps[i].queue,
_queueLen = #maps[i].queue,
_hashedQueue = set(maps[i].queue)
}
end
maps = setmetatable(maps, {
__call = function(this, category)
category = tonumber(category)
local hasCat = not not category
if not hasCat or not this[category] then
category = this.queue[this.queue._next]
if type(category) == "table" then
category = category[math.random(#category)]
end
this.queue._next = this.queue._next % maps.queue._len + 1
end
this.queue._lastCat = category
local map
if hasCat then
map = this[category].queue[math.random(this[category]._queueLen)]
else
map = this[category].queue[this[category]._next]
if this[category]._next == this[category]._queueLen then
shuffle(this[category].queue)
this[category]._next = 1
else
this[category]._next = this[category]._next + 1
end
end
if this[category].fBefore then
this[category].fBefore(map)
end
return map
end
})
end
local alive, nextMap = 0
eventNewGame = function()
nextMap = nil
do
local category = maps.queue._lastCat
if maps[category].fAfter then
local currentMap = tonumber(tfm.get.room.currentMap)
local isMap = maps[category]._hashedQueue[currentMap]
if not isMap and tfm.get.room.xmlMapInfo then
isMap = maps[category]._hashedQueue[tfm.get.room.xmlMapInfo.mapCode] or maps[category]._hashedQueue[tonumber(tfm.get.room.xmlMapInfo.mapCode)]
end
if isMap then
maps[category].fAfter(currentMap)
end
end
end
alive = 0
for _ in next, tfm.get.room.playerList do
alive = alive + 1
end
end
eventLoop = function(currentTime, remainingTime)
if alive < 1 or remainingTime < 500 then
if not nextMap then
nextMap = maps()
end
tfm.exec.newGame(nextMap)
end
end
eventPlayerDied = function()
alive = alive - 1
end
eventPlayerRespawn = function()
alive = alive + 1
end
tfm.exec.disableAutoNewGame()
tfm.exec.setGameTime(0)