Files
EasyRoute/tools/test-rewards.js
notforever-ship-it c90aeb1a05 Clearer words in every window, tooltip and chat line
- The first-login notice says what Auto mode looks at (bags and gold, to sell, repair, pick a reward and find the hearthstone) and shows once more.
- Help, the Skip tooltip and the step box say that Skip marks a quest Hard; the "press >" hint says Done.
- Same names everywhere: Notebook, Pick a guide, Ask me how hard each quest was, Tell my party, Sell grey items, difficulty.
- A reward Auto mode takes comes in the same chat line as the hand-in.
- Nothing cut off at big text: the chain popup grows with its text, Help shrinks to fit the screen, shorter lines in the Notebook, the guide name and the guide menu.
- The quest log panel shows Made by stealthzi and the version.
2026-10-10 15:59:45 +01:00

229 lines
10 KiB
JavaScript

// Auto mode at a hand-in with rewards to choose from, in the pretend game (tools/lib/fakegame.js) with a pretend guide.
// None of the rewards fits the character: the one that sells for the most is taken (Data/Prices.lua), or with no price known the best
// quality. One that fits, a tooltip that cannot be read, Shift and the hand-in tick: nothing is taken and the player picks, as before.
// Usage: node tools/test-rewards.js (needs fengari: npm install in this tools folder)
const fs = require("fs");
const path = require("path");
const { lua, lauxlib, lualib, to_luastring, to_jsstring } = require("fengari");
const { PRELUDE } = require("./lib/fakegame.js");
const ROOT = path.resolve(__dirname, "..");
const L = lauxlib.luaL_newstate();
lualib.luaL_openlibs(L);
function run(code, name) {
const buf = typeof code === "string" ? to_luastring(code) : code;
if (lauxlib.luaL_loadbuffer(L, buf, buf.length, to_luastring(name)) !== 0 || lua.lua_pcall(L, 0, 0, 0) !== 0) {
console.error("FAILED in " + name + ": " + to_jsstring(lua.lua_tostring(L, -1)));
process.exit(1);
}
}
run(PRELUDE, "prelude");
run(fs.readFileSync(path.join(ROOT, "Data", "Prices.lua")), "Data/Prices.lua");
// The pretend reward choices: G.items[i] = { id, name, quality, usable, lines = { { left, lc, right, rc } ... } } (lc/rc: { r, g, b }).
// A hidden tooltip shows an item's lines through the global line objects <name>TextLeftN / TextRightN, as GameTooltipTemplate does.
run(`
G.items = {}
GetQuestItemInfo = function(kind, i)
local it = kind == "choice" and G.items[i]
if not it then return nil end
return it.name, "icon", 1, it.quality, it.usable
end
GetQuestItemLink = function(kind, i)
local it = kind == "choice" and G.items[i]
if not it then return nil end
return "|cff1eff00|Hitem:" .. it.id .. ":0:0:0|h[" .. it.name .. "]|h|r"
end
local function Line(name)
local o = { t = nil, c = { 1, 1, 1 } }
o.GetText = function(self) return self.t end
o.GetTextColor = function(self) return self.c[1], self.c[2], self.c[3] end
_G[name] = o
return o
end
local realCreate = CreateFrame
CreateFrame = function(kind, name, parent, template)
if kind ~= "GameTooltip" then return realCreate(kind, name) end
local tip = { n = 0 }
for l = 1, 30 do Line(name .. "TextLeft" .. l) Line(name .. "TextRight" .. l) end
tip.SetOwner = function(self) end
tip.Hide = function(self) end
tip.ClearLines = function(self)
self.n = 0
for l = 1, 30 do _G[name .. "TextLeft" .. l].t, _G[name .. "TextRight" .. l].t = nil, nil end
end
tip.SetQuestItem = function(self, kind, i)
local it = G.items[i]
if not it or it.unread then return end
for l, line in ipairs(it.lines or {}) do
local left, right = _G[name .. "TextLeft" .. l], _G[name .. "TextRight" .. l]
left.t, left.c = line[1], line[2] or { 1, 1, 1 }
right.t, right.c = line[3], line[4] or { 1, 1, 1 }
end
self.n = table.getn(it.lines or {})
end
tip.NumLines = function(self) return self.n end
_G[name] = tip
return tip
end
-- A pretend guide that hands in one quest.
EasyRoute.Steps = {
Running = function() return true end,
NormTitle = function(t) return string.lower(t or "") end,
HandInTitles = function() return { ["the test quest"] = true } end,
WantedAccepts = function() return {} end,
OpenElements = function() return {} end,
Current = function() return nil end,
}
`, "pretend rewards");
run(fs.readFileSync(path.join(ROOT, "Auto.lua")), "Auto.lua");
run(`
local ER = EasyRoute
local A = ER.Auto
local T = "The Test Quest"
local PICK = "Pick your reward for " .. T .. ", then press Complete Quest."
local RED, WHITE = { 1, 0.125, 0.125 }, { 1, 1, 1 }
local function Calls() return table.concat(G.calls, ",") end
local function Has(sub) return string.find(CHAT or "", sub, 1, true) ~= nil end
check(type(EasyRoute_Prices) == "table", "Data/Prices.lua did not load")
local count = 0
for id, copper in pairs(EasyRoute_Prices or {}) do
count = count + 1
if type(id) ~= "number" or type(copper) ~= "number" or copper <= 0 then check(false, "a bad price entry: " .. tostring(id)) break end
end
check(count > 500, "Data/Prices.lua has only " .. count .. " prices")
EasyRoute_Prices[900001] = 150
EasyRoute_Prices[900002] = 2400
EasyRoute_Prices[900003] = 80
-- A priest: plate armour and a mage robe are never for it.
G.class = "PRIEST"
local function Item(id, name, quality, usable, lines)
return { id = id, name = name, quality = quality, usable = usable, lines = lines }
end
local PLATE = { { "Plate Helm", WHITE }, { "Head", WHITE, "Plate", RED } }
local MAGE = { { "Silk Robe", WHITE }, { "Classes: Mage", RED } }
local LEVEL = { { "Fine Sword", WHITE }, { "One-Hand", WHITE, "Sword", WHITE }, { "Requires Level 30", RED } }
local function Close()
QuestFrame:Hide()
QuestFrameRewardPanel:Hide()
Tick(1.2)
Tick(1.2)
end
local function Open(items, shiftLater)
Close()
ER.db.autoOff, ER.db.autoquestOff = nil, nil
G.calls, G.shift, CHAT = {}, false, ""
G.log, G.order = { [T] = { complete = true, objs = {} } }, { T }
G.items = items
G.window = { title = T, choices = table.getn(items) }
QuestFrame:Show()
QuestFrameRewardPanel:Show()
end
local function Go(shiftLater)
Fire("QUEST_COMPLETE")
if shiftLater then G.shift = true end
Tick(0.1)
Tick(0.1)
end
print("1. None of the rewards fits: the one that sells for the most is taken")
Open({ Item(900001, "Plate Helm", 2, nil, PLATE), Item(900002, "Silk Robe", 2, nil, MAGE), Item(900003, "Plate Boots", 3, nil, PLATE) })
local pick, link, why = A.PickUnfit(3)
check(pick == 2 and why == "sells for the most", "PickUnfit answered " .. tostring(pick) .. " " .. tostring(why))
Go()
check(Calls() == "GetQuestReward:2", "none usable made the calls: " .. Calls())
Close()
check(Has("handed in " .. T .. ", took |cff1eff00|Hitem:900002:0:0:0|h[Silk Robe]|h|r (none of the rewards fit you; sells for the most)."),
"the hand-in and the reward are not one line: '" .. tostring(CHAT) .. "'")
check(not Has(PICK), "the pick line was said too: '" .. tostring(CHAT) .. "'")
print("2. One reward fits: nothing is taken, the player picks")
Open({ Item(900001, "Plate Helm", 2, nil, PLATE), Item(900002, "Fine Sword", 2, nil, LEVEL) })
check(A.PickUnfit(2) == nil, "a reward whose only red line is the level counted as not fitting")
Go()
check(table.getn(G.calls) == 0, "one usable reward made the calls: " .. Calls())
check(Has(PICK), "the pick line was not said: '" .. tostring(CHAT) .. "'")
check(QuestFrameRewardPanel:IsVisible(), "the window was closed")
Open({ Item(900001, "Plate Helm", 2, nil, PLATE), Item(900002, "Silk Robe", 2, 1, MAGE) })
Go()
check(table.getn(G.calls) == 0, "a reward the game calls usable was not left to the player: " .. Calls())
check(Has(PICK), "the pick line was not said when the game calls one usable")
print("3. No price known: the best quality, and with no best the player picks")
Open({ Item(800001, "Plate Helm", 2, nil, PLATE), Item(800002, "Silk Robe", 3, nil, MAGE) })
Go()
check(Calls() == "GetQuestReward:2", "no price made the calls: " .. Calls())
Close()
check(Has("took |cff1eff00|Hitem:800002:0:0:0|h[Silk Robe]|h|r (none of the rewards fit you; the best of them)."), "the quality line is '" .. tostring(CHAT) .. "'")
Open({ Item(800001, "Plate Helm", 2, nil, PLATE), Item(800002, "Silk Robe", 2, nil, MAGE) })
Go()
check(table.getn(G.calls) == 0, "no price and the same quality made the calls: " .. Calls())
check(Has(PICK), "the pick line was not said with no price and the same quality")
print("4. Shift, the hand-in tick and a tooltip that cannot be read: nothing is taken")
local NONE = function() return { Item(900001, "Plate Helm", 2, nil, PLATE), Item(900002, "Silk Robe", 2, nil, MAGE) } end
Open(NONE())
G.shift = true
Go()
check(table.getn(G.calls) == 0, "Shift at the window made the calls: " .. Calls())
Open(NONE())
Go(true)
check(table.getn(G.calls) == 0, "Shift before the click made the calls: " .. Calls())
Open(NONE())
ER.db.autoquestOff = true
Go()
check(table.getn(G.calls) == 0, "the hand-in tick off made the calls: " .. Calls())
ER.db.autoquestOff = nil
local unread = NONE()
unread[1].unread = true
Open(unread)
Go()
check(table.getn(G.calls) == 0, "a tooltip with no lines made the calls: " .. Calls())
check(Has(PICK), "the pick line was not said when a tooltip had no lines")
Close()
print("5. Armour or a weapon the class learns later counts as fitting: the player picks")
local POLEARM = { { "Long Spear", WHITE }, { "Two-Hand", WHITE, "Polearm", RED } }
G.class = "WARRIOR"
Open({ Item(900001, "Plate Helm", 2, nil, PLATE), Item(900002, "Silk Robe", 2, nil, MAGE) })
check(A.PickUnfit(2) == nil, "a warrior's red Plate counted as never fitting")
Go()
check(table.getn(G.calls) == 0, "a warrior below 40 with a plate reward made the calls: " .. Calls())
check(Has(PICK), "the pick line was not said for a warrior's plate reward")
Open({ Item(900002, "Silk Robe", 2, nil, MAGE), Item(900003, "Long Spear", 2, nil, POLEARM) })
Go()
check(table.getn(G.calls) == 0, "a warrior with an untrained polearm reward made the calls: " .. Calls())
G.class = "SHAMAN"
Open({ Item(900001, "Plate Helm", 2, nil, PLATE), Item(900002, "Silk Robe", 2, nil, MAGE) })
Go()
check(Calls() == "GetQuestReward:2", "a shaman never wears plate, yet the calls were: " .. Calls())
G.class = "ROGUE"
Open({ Item(900001, "Plate Helm", 2, nil, PLATE), Item(900003, "Long Spear", 2, nil, POLEARM) })
Go()
check(Calls() == "GetQuestReward:1", "a rogue never wears plate or uses a polearm, yet the calls were: " .. Calls())
G.class = "PRIEST"
Close()
print("6. A choice with no price (a Turtle WoW item): the best quality decides, not the price of the others")
Open({ Item(900002, "Silk Robe", 2, nil, MAGE), Item(800001, "Plate Helm", 3, nil, PLATE) })
Go()
check(Calls() == "GetQuestReward:2", "an unpriced blue lost to a priced green: " .. Calls())
Open({ Item(900002, "Silk Robe", 2, nil, MAGE), Item(800001, "Plate Helm", 2, nil, PLATE) })
Go()
check(table.getn(G.calls) == 0, "a priced green beat an unpriced green: " .. Calls())
check(Has(PICK), "the pick line was not said with one price unknown and the same quality")
Close()
if failures > 0 then error(failures .. " check(s) failed") end
print("All reward checks passed.")
`, "reward checks");