Repository navigation
Expand file tree
/
Copy pathNames.lua
More file actions
221 lines (202 loc) · 10.2 KB
/
Copy pathNames.lua
File metadata and controls
221 lines (202 loc) · 10.2 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
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
-- Name lists: the kind of node from its name (English, and for other clients the
-- names in Locales), which objects are chests, and the skill each herb and ore needs.
--
-- In order: NodeKind, TooHard, NodeSkill, SkillLevel, HasProfession, towns.
local _, ns = ...
local ipairs = ipairs
-- Herbs are matched by the end of the name, ore by "vein" or "deposit" (or ORE_OTHER).
-- Names with digits, ":" or "/" are quest progress ("Peacebloom 3/8"), not nodes.
local ORE_OTHER = { "chunk of amber", "obsidian chunk", "moonstone formation" } -- no vein or deposit
-- Chests, by the end of the name (crates and sacks are quest things too).
local TREASURE = { "chest", "footlocker", "strongbox", "lockbox", "coffer" }
local MAX_WORDS = 5
-- Lowercase, with curly apostrophes made straight.
local function Plain(name)
return (name:lower():gsub("\226\128\153", "'"))
end
-- This client's names (each Locales\*.lua loads only on its client), in one lookup.
local LOCALE = ns.LOCALE
local ENGLISH = {}
if LOCALE then
for _, kind in ipairs({ "HERBS", "ITEM_HERBS", "ORE", "TREASURE" }) do
for name, english in pairs(LOCALE[kind] or {}) do ENGLISH[name] = english end
end
end
-- Plain() of the English name, if this client's name is known.
local function Key(name)
local plain = Plain(name)
return ENGLISH[plain] or plain
end
local function EndsWith(text, ending)
return text:sub(-#ending) == ending
end
-- Herbs by the end of their name (from Wowhead).
local HERBS = {
"silverleaf", "mageroyal", "peacebloom", "earthroot", "briarthorn", "swiftthistle", "bruiseweed", "steelbloom",
"kingsblood", "liferoot", "khadgar's whisker", "grave moss", "fadeleaf", "wintersbite", "stranglekelp",
"goldthorn", "firebloom", "purple lotus", "arthas' tears", "sungrass", "blindweed", "ghost mushroom",
"gromsblood", "dreamfoil", "golden sansam", "mountain silversage", "plaguebloom", "icecap", "black lotus",
"hive thistle", "demonsage", "death lotus", "marefoil", "stranglevine", "frilled lichen", "rosecap",
"doom weed", "gloom weed", "moonroot", "nightmare moss", "dreamroot", "star lotus",
}
-- "herbs", "ore", "treasure" or nil.
local function NodeKind(name)
name = Key(name)
if name:find("[%d:/]") then return nil end
local words = 0
for _ in name:gmatch("%S+") do words = words + 1 end
if words > MAX_WORDS then return nil end
if EndsWith(name, " vein") or EndsWith(name, " deposit") then return "ore" end
for _, other in ipairs(ORE_OTHER) do
if EndsWith(name, other) then return "ore" end
end
for _, herb in ipairs(HERBS) do
if EndsWith(name, herb) then return "herbs" end
end
for _, ending in ipairs(TREASURE) do
if EndsWith(name, ending) then return "treasure" end
end
-- This client's chests, by the end of any word ("Truhe der Horde").
if LOCALE and LOCALE.TREASURE_ENDINGS then
for word in name:gmatch("%S+") do
for _, ending in ipairs(LOCALE.TREASURE_ENDINGS) do
if EndsWith(word, ending) then return "treasure" end
end
end
end
return nil
end
-- Skill needed per node (Wowhead). Unlisted nodes are never too hard.
local SKILL_LINE = { herbs = 182, ore = 186 } -- Herbalism and Mining
-- Forever lists each gathering skill twice (the second under the first); either may hold it.
local SECOND_LINE = { [182] = 2944, [186] = 2946, [393] = 2947 }
local function SkillLineInfo(get, id)
local info = get(id)
if issecretvalue(info) or info ~= nil or not SECOND_LINE[id] then return info end
return get(SECOND_LINE[id])
end
local NEEDED = {
herbs = {
["earthroot"] = 15, ["mageroyal"] = 50, ["briarthorn"] = 70, ["stranglekelp"] = 85,
["bruiseweed"] = 100, ["wild steelbloom"] = 115, ["grave moss"] = 120, ["kingsblood"] = 125,
["nightmare moss"] = 125, ["liferoot"] = 150, ["fadeleaf"] = 160, ["goldthorn"] = 170,
["khadgar's whisker"] = 185, ["wintersbite"] = 195, ["dreamroot"] = 205, ["firebloom"] = 205,
["purple lotus"] = 210, ["arthas' tears"] = 220, ["sungrass"] = 230, ["blindweed"] = 235,
["ghost mushroom"] = 245, ["gromsblood"] = 250, ["moonroot"] = 250, ["star lotus"] = 250,
["golden sansam"] = 260, ["dreamfoil"] = 270, ["mountain silversage"] = 280, ["plaguebloom"] = 285,
["icecap"] = 290, ["black lotus"] = 300,
},
ore = {
["tin vein"] = 65, ["incendicite mineral vein"] = 65, ["silver vein"] = 75,
["ooze covered silver vein"] = 75, ["lesser bloodstone deposit"] = 75, ["iron deposit"] = 125,
["cold iron deposit"] = 125, ["indurium mineral vein"] = 150, ["gold vein"] = 155,
["ooze covered gold vein"] = 155, ["mithril deposit"] = 175, ["ooze covered mithril deposit"] = 175,
["fool's gold vein"] = 175, ["truesilver deposit"] = 230, ["ooze covered truesilver deposit"] = 230,
["dark iron deposit"] = 230, ["small thorium vein"] = 245, ["ooze covered thorium vein"] = 245,
["starsilver vein"] = 245, ["greater moonstone formation"] = 245, ["rich thorium vein"] = 275,
["ooze covered rich thorium vein"] = 275, ["hakkari thorium vein"] = 275, ["heavy thorium vein"] = 300,
["small obsidian chunk"] = 305, ["large obsidian chunk"] = 305,
},
}
local skills = {} -- cached skill levels with bonuses (false = unknown)
local bases, caps = {}, {} -- and without bonuses, and the trained cap; read with skills
local professions = {} -- localized profession names
local has, hasAt = {}, {} -- whether you have each kind's profession, and when a "no" was read
local RECHECK = 5 -- seconds a "no" is kept (the skill list may still be loading at login)
-- Herbalism or Mining skill including bonuses, or nil. Retail has no such call.
local function GatherSkill(kind)
local get = C_SkillInfo and C_SkillInfo.GetSkillLineInfoByID
local info = get and SkillLineInfo(get, SKILL_LINE[kind])
if issecretvalue(info) then
has[kind] = true
return nil
end
if not info then
has[kind], hasAt[kind] = false, GetTime()
return nil
end
has[kind] = true
local rank, bonus, cap = info.rank, info.modifier, info.maxRank
if issecretvalue(rank) or issecretvalue(bonus) or not rank then return nil end
local name = info.name
if not issecretvalue(name) then professions[kind] = name end
bases[kind] = rank
caps[kind] = not issecretvalue(cap) and cap or nil
return rank + (bonus or 0)
end
-- true if the node needs more skill than you have.
local function TooHard(name, kind)
local need = NEEDED[kind] and NEEDED[kind][Key(name)]
if not need then return false end
if skills[kind] == nil then skills[kind] = GatherSkill(kind) or false end
local skill = skills[kind]
return skill ~= false and need > skill
end
-- What a herb or ore needs (1 for one known by name but not listed, nil for other
-- kinds), and your skill (false if unknown).
local function NodeSkill(name, kind)
local list = NEEDED[kind]
local need = list and (list[Key(name)] or (NodeKind(name) == kind and 1))
if not need then return nil end
if skills[kind] == nil then skills[kind] = GatherSkill(kind) or false end
return need, skills[kind]
end
-- Your chance of a skill-up from a herb or ore, as the profession window colors it:
-- 1 too hard, then 2 to 5 at 25, 50 and 100 points over what it needs, and 5 at
-- your trained cap. Bonuses count for gathering, not for skill-ups. Also returns
-- what it needs. nil if either isn't known.
local function SkillLevel(name, kind)
local need, skill = NodeSkill(name, kind)
if not skill then return nil end
-- Learned at 0, you can still gather what needs 1.
if math.max(skill, 1) < need then return 1, need end
local base, cap = bases[kind], caps[kind]
if cap and cap > 0 and base >= cap then return 5, need end
-- Level-1 nodes count from 0: yellow at 25, green at 50, gray at 100.
local over = base - (need > 1 and need or 0)
return over < 25 and 2 or over < 50 and 3 or over < 100 and 4 or 5, need
end
-- Whether you have the profession that gathers a kind (Herbalism, Mining, Skinning): false
-- only when the game says you don't; true for other kinds, or when it can't be read (Retail).
-- Read with the skill (one call for both), kept until the skills change.
local SKINNING_LINE = 393
local function HasProfession(kind)
local get = C_SkillInfo and C_SkillInfo.GetSkillLineInfoByID
if not (get and (SKILL_LINE[kind] or kind == "skinning")) then return true end
if has[kind] ~= nil and (has[kind] or GetTime() - hasAt[kind] < RECHECK) then return has[kind] end
if SKILL_LINE[kind] then
skills[kind] = GatherSkill(kind) or false
else
local info = SkillLineInfo(get, SKINNING_LINE)
if issecretvalue(info) or info ~= nil then has[kind] = true else has[kind], hasAt[kind] = false, GetTime() end
end
return has[kind] ~= false
end
-- Towns and camps (the game marks none as a town, and only an inn is a rest area there).
-- Forever's area IDs: Alliance, Horde, neutral, Zephras Isle's villages.
local TOWN_AREAS = {
87, 24, 108, 69, 42, 144, 150, 271, 320, 348, 1438, 131, 77, 186, 442, 415, 467, 608, 489, 1116, 513, 1998, 2418, 3197, 99,
362, 380, 378, 222, 159, 228, 272, 321, 340, 117, 75, 431, 2897, 460, 484, 2408, 1099, 3317, 496, 367, 221, 154, 1997,
35, 392, 976, 2255, 3425, 541, 1446, 2268, 977, 2479,
16624, 16635, 16636, 16638,
}
local townNames -- this client's names for them (some end in a space)
local function Trim(text) return (text:match("^%s*(.-)%s*$")) end
-- Are you in one of those towns (by the sub-zone's name)?
local function InTownArea()
local sub = GetSubZoneText()
if issecretvalue(sub) or not sub then return false end
if not townNames then
townNames = {}
for _, id in ipairs(TOWN_AREAS) do
local name = C_Map.GetAreaInfo(id)
if name then townNames[Trim(name)] = true end
end
end
return townNames[Trim(sub)] == true
end
-- Used by the other files.
ns.InTownArea = InTownArea
ns.HasProfession, ns.hasProfession = HasProfession, has
ns.Plain, ns.NodeKind, ns.NodeKey = Plain, NodeKind, Key
ns.skills, ns.professions, ns.TooHard, ns.SkillLevel, ns.NodeSkill = skills, professions, TooHard, SkillLevel, NodeSkill