forked from McChew/Root-TTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobal.ttslua
152 lines (141 loc) · 4.43 KB
/
global.ttslua
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
available = {
Marquise = 1,
Eyrie = 1,
Woodland = 1,
Vagabond = 2,
Riverfolk = 1,
Lizard = 1,
Duchy = 1,
Corvid = 1,
Fangus = 1,
VagaThief = 1,
VagaTinker = 1,
VagaScoundrel = 1,
VagaArbiter = 1,
VagaRanger = 1,
VagaVagrant = 1,
VagaAdventurer = 1,
VagaHarrier = 1,
VagaRonin = 1,
Arachnid = 1,
WeeklyCroak = 1,
Boars = 1,
Aviators = 1,
Republic = 1,
Necropossums = 1,
Shrewd = 1,
}
colors = {Blue=true, Orange=true, Teal=true, Yellow=true, Green=true,
Purple=true, White=true, Red=true, Brown=true, Pink=true}
BUTTONS =
{
"Marquise1", "Eyrie1", "Woodland1", "Vagabond2", "Vagabond1", "Riverfolk1", "Lizard1", "Corvid1", "Duchy1",
"rBotMarquise1", "rBotEyrie1", "rBotWoodland1", "rBotVagabond2", "rBotVagabond1",
"VagaArbiter", "VagaRanger", "VagaScoundrel", "VagaThief", "VagaTinker", "VagaVagrant", "VagaAdventurer", "VagaHarrier", "VagaRonin",
"OverRiverfolk1", "ClocLizard1", "CybeCorvid1", "bbdcMarquise1", "bbdcEyrie1", "bbdcWoodland1", "bbdcVagabond1", "bbdcVagabond2",
"Arachnid1", "WeeklyCroak1", "Boars1", "Fangus1", "Aviators1", "Republic1", "Necropossums1", "Shrewd1",
}
factionboards = {}
bot = false
XML_UPDATED = false
-- par = {factionboard instance}
function ImHere(par)
factionboards[#factionboards+1] = par[1]
end
-- par = {factionboard instance}
function ImGone(par)
local where = 0
for x=1, #factionboards do
if factionboards[x] == par[1] then
where = x
end
end
table.remove(factionboards, where)
end
-- par = {faction}
function FactionChosen(par)
local faction = par[1]
available[faction] = available[faction] -1
ShowAllButtons()
end
function ShowAllButtons()
for _, x in ipairs(factionboards) do
x.call('showButtons', {})
end
end
function update_faction_data()
local TEXT = ""
log("Global: Finding keeper of faction info")
KEEPER = find_object_by_name("The keeper of information")
log("Requesting latest Faction data")
function transfer()
TMP = find_object_by_name("TMP")
local everything = TMP.getTable("EVERYTHING")
KEEPER.setTable("EVERYTHING", everything)
local buttons = TMP.getTable("BUTTONS")
if buttons ~= nil then
BUTTONS = buttons
end
log("Newest data received")
TMP.destruct()
available = {Vagabond=2}
for faction, _ in pairs(everything.factions) do
available[faction] = 1
end
for faction, _ in pairs(everything.fanfactions) do
available[faction] = 1
end
-- print(logString(available))
end
function spawned(o)
o.setLock(true)
o.setLuaScript(TEXT)
o.setName("TMP")
o.reload()
Wait.condition(transfer,||not o.spawning)
end
function callback(wr)
repeat
--
until wr.is_done
if wr.is_error then
log("Something went wrong retreiving newest data")
log(wr.error)
else
log("Faction Data received.")
TEXT = wr.text
local TMP = spawnObject({type='backgammon_piece_white', position={5.00, -24.22, 0.00}, sound=false, callback_function=spawned})
end
end
WebRequest.get("https://raw.githubusercontent.com/McChew/Root-TTS/master/factionsv3.ttslua", callback)
end
function update_xml_data()
log("Global: Finding keeper of XML")
XMLKEEPER = find_object_by_name("The keeper of XML")
log("Requesting latest XML data")
function callback(wr)
repeat
--
until wr.is_done
if wr.is_error then
log("Something went wrong retreiving XML")
log(wr.error)
else
log("XML Data received.")
XMLKEEPER.setLuaScript(wr.text)
XMLKEEPER.reload()
Wait.time(function() XML_UPDATED = true; log("flag set") end, 0.5)
end
end
WebRequest.get("https://raw.githubusercontent.com/McChew/Root-TTS/master/factionboardxml.ttslua", callback)
end
function onLoad(save_state)
update_xml_data()
update_faction_data()
end
function find_object_by_name(name)
for _, obj in ipairs(getAllObjects()) do
if obj.getName() == name then return obj end
end
return nil
end