Module:BATTD tower changes: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| (2 intermediate revisions by the same user not shown) | |||
| Line 27: | Line 27: | ||
}) | }) | ||
-- | local upgradePrereqs = cargo.query("battd_upgrades=main, battd_upgrades__previous=prev", "main.id=thisId, prev._value=prevId", { | ||
where=sFormat("main.tower='%s'", towerName), | |||
join="main._ID=prev._RowID" | |||
}) | |||
-- build name:_pageName dictionary | |||
local pagenamesByName = {} | local pagenamesByName = {} | ||
for i, upgrade in ipairs(upgrades) do pagenamesByName[upgrade.name] = upgrade._pageName end | for i, upgrade in ipairs(upgrades) do pagenamesByName[upgrade.name] = upgrade._pageName end | ||
local upgradePrereqsOfById = { -- key:values table - upgrades:upgrades this is a prerequisite of | |||
root = {} | |||
} | |||
-- build upgradePrereqsOfById | |||
for i, upgrade in ipairs(upgradePrereqs) do | |||
-- upgrade:next table | |||
if upgrade.prevId then | |||
if upgradePrereqsOfById[upgrade.prevId] then | |||
upgradePrereqsOfById[upgrade.prevId][#upgradePrereqsOfById[upgrade.prevId]+1] = upgrade.thisId | |||
else | |||
upgradePrereqsOfById[upgrade.prevId] = {upgrade.thisId} | |||
end | |||
else | |||
-- if this upgrade is a root upgrade and is not already purchased | |||
upgradePrereqsOfById["root"][#upgradePrereqsOfById["root"]+1] = upgrade.thisId | |||
end | |||
end | |||
-- helper function for cargo storing | -- helper function for cargo storing | ||
| Line 49: | Line 73: | ||
end | end | ||
local outputTable = {"{|class='wikitable'\n! | local outputTable = {"{|class='wikitable'\n!Tiers!!Changes"} | ||
for i = 1, 20 do | for i = 1, 20 do | ||
local changes = args[sFormat("upgrades %i changes", i)] | local changes = args[sFormat("upgrades %i changes", i)] | ||
local upgradeNames = args[sFormat("upgrades %i", i)] | local upgradeNames = args[sFormat("upgrades %i", i)] | ||
local | |||
local | local before = tonumber(args[sFormat("upgrades %i cost before", i)]) | ||
local after = tonumber(args[sFormat("upgrades %i cost after", i)]) | |||
local baseCostDiff = 0 | |||
-- stop if this set is missing changes/upgrades | -- stop if this set is missing changes/upgrades | ||
if upgradeNames == "" then break end | if upgradeNames == "" then break end | ||
| Line 62: | Line 88: | ||
for upgradeName in sGmatch(upgradeNames, "([^;]+)") do | for upgradeName in sGmatch(upgradeNames, "([^;]+)") do | ||
outputRow[#outputRow+1] = sFormat(" | outputRow[#outputRow+1] = sFormat("[[%s|%s]]", upgradeName, pagenamesByName[upgradeName]) | ||
end | |||
if before ~= 0 and after ~= 0 then | |||
-- list item | |||
changes = sFormat("%s\n%s", getCostListItem(before, after, { | |||
before > after and "Upgrade cost reduced" or "Upgrade cost increased", | |||
sFormat("$%s", lang:formatNum(before)), | |||
sFormat("$%s", lang:formatNum(after)), | |||
undoc=args[sFormat("upgrades %i cost undoc", i)], | |||
fix =args[sFormat("upgrades %i cost fix", i)] | |||
}), changes) | |||
end | end | ||
outputTable[i+1] = sFormat("|-\n|\n%s\n|\n%s", tConcat(outputRow, " | outputTable[i+1] = sFormat("|-\n|\n%s\n|\n%s", tConcat(outputRow, ", "), changes) | ||
end | end | ||