-
Notifications
You must be signed in to change notification settings - Fork 30
/
patchtable.lua
154 lines (125 loc) · 4.62 KB
/
patchtable.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
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
153
154
local loc = GetLocale()
local dbs = { "items", "quests", "quests-itemreq", "objects", "units", "zones", "professions", "areatrigger", "refloot" }
local noloc = { "items", "quests", "objects", "units" }
-- Patch databases to merge TurtleWoW data
local function patchtable(base, diff)
for k, v in pairs(diff) do
if type(v) == "string" and v == "_" then
base[k] = nil
else
base[k] = v
end
end
end
local loc_core, loc_update
for _, db in pairs(dbs) do
if pfDB[db]["data-turtle"] then
patchtable(pfDB[db]["data"], pfDB[db]["data-turtle"])
end
for loc, _ in pairs(pfDB.locales) do
if pfDB[db][loc] and pfDB[db][loc.."-turtle"] then
loc_update = pfDB[db][loc.."-turtle"] or pfDB[db]["enUS-turtle"]
patchtable(pfDB[db][loc], loc_update)
end
end
end
loc_core = pfDB["professions"][loc] or pfDB["professions"]["enUS"]
loc_update = pfDB["professions"][loc.."-turtle"] or pfDB["professions"]["enUS-turtle"]
if loc_update then patchtable(loc_core, loc_update) end
if pfDB["minimap-turtle"] then patchtable(pfDB["minimap"], pfDB["minimap-turtle"]) end
if pfDB["meta-turtle"] then patchtable(pfDB["meta"], pfDB["meta-turtle"]) end
-- Detect german client patch and switch some databases
if TURTLE_DE_PATCH then
pfDB["zones"]["loc"] = pfDB["zones"]["deDE"] or pfDB["zones"]["enUS"]
pfDB["professions"]["loc"] = pfDB["professions"]["deDE"] or pfDB["professions"]["enUS"]
end
-- Update bitmasks to include custom races
if pfDB.bitraces then
pfDB.bitraces[256] = "Goblin"
pfDB.bitraces[512] = "BloodElf"
end
-- Use turtle-wow database url
pfQuest.dburl = "https://database.turtle-wow.org/?quest="
-- Disable Minimap in custom dungeon maps
function pfMap:HasMinimap(map_id)
-- disable dungeon minimap
local has_minimap = not IsInInstance()
-- enable dungeon minimap if continent is less then 3 (e.g AV)
if IsInInstance() and GetCurrentMapContinent() < 3 then
has_minimap = true
end
return has_minimap
end
-- Reload all pfQuest internal database shortcuts
pfDatabase:Reload()
local function strsplit(delimiter, subject)
if not subject then return nil end
local delimiter, fields = delimiter or ":", {}
local pattern = string.format("([^%s]+)", delimiter)
string.gsub(subject, pattern, function(c) fields[table.getn(fields)+1] = c end)
return unpack(fields)
end
-- Complete quest id including all pre quests
local function complete(history, qid)
-- ignore empty or broken questid
if not qid or not tonumber(qid) then return end
-- mark quest as complete
local time = pfQuest_history[qid] and pfQuest_history[qid][1] or 0
local level = pfQuest_history[qid] and pfQuest_history[qid][2] or 0
history[qid] = { time, level }
end
-- Add function to query for quest completion
local query = CreateFrame("Frame")
query:Hide()
query:SetScript("OnEvent", function()
if arg1 == "TWQUEST" then
for _, qid in pairs({strsplit(" ", arg2)}) do
this.count = this.count + 1
complete(this.history, tonumber(qid))
end
end
end)
query:SetScript("OnShow", function()
this.history = {}
this.count = 0
this.time = GetTime()
this:RegisterEvent("CHAT_MSG_ADDON")
SendChatMessage(".queststatus", "GUILD")
end)
query:SetScript("OnHide", function()
this:UnregisterEvent("CHAT_MSG_ADDON")
local count = 0
for qid in pairs(this.history) do count = count + 1 end
DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccpf|cffffffffQuest|r: A total of " .. count .. " quests have been marked as completed.")
pfQuest_history = this.history
this.history = nil
pfQuest:ResetAll()
end)
query:SetScript("OnUpdate", function()
if GetTime() > this.time + 3 then this:Hide() end
end)
function pfDatabase:QueryServer()
DEFAULT_CHAT_FRAME:AddMessage("|cff33ffccpf|cffffffffQuest|r: Receiving quest data from server...")
query:Show()
end
-- Automatically clear quest cache if new turtle quests have been found
local updatecheck = CreateFrame("Frame")
updatecheck:RegisterEvent("PLAYER_ENTERING_WORLD")
updatecheck:SetScript("OnEvent", function()
if pfDB["quests"]["data-turtle"] then
-- count all known turtle-wow quests
local count = 0
for k, v in pairs(pfDB["quests"]["data-turtle"]) do
count = count + 1
end
pfQuest:Debug("TurtleWoW loaded with |cff33ffcc" .. count .. "|r quests.")
-- check if the last count differs to the current amount of quests
if not pfQuest_turtlecount or pfQuest_turtlecount ~= count then
-- remove quest cache to force reinitialisation of all quests.
pfQuest:Debug("New quests found. Reloading |cff33ffccCache|r")
pfQuest_questcache = {}
end
-- write current count to the saved variable
pfQuest_turtlecount = count
end
end)