Module:BATTD costs: Difference between revisions

mNo edit summary
mNo edit summary
Line 30: Line 30:
local function GetPurchasedAndAvailableUpgrades(purchasedUpgrades, availableUpgradeId)
local function GetPurchasedAndAvailableUpgrades(purchasedUpgrades, availableUpgradeId)
-- skip this upgrade if it is a leaf
if not upgradePrereqsOfById[availableUpgradeId] then return nil, nil end
-- skip this upgrade if we don't have all the prereqs
-- skip this upgrade if we don't have all the prereqs
if upgradePrereqsById[availableUpgradeId] then
if upgradePrereqsById[availableUpgradeId] then
for _, prereqId in ipairs(upgradePrereqsById[availableUpgradeId]) do
for _, prereqId in ipairs(upgradePrereqsById[availableUpgradeId]) do
if not purchasedUpgrades[prereqId] then
if prereqId ~= "root" and not purchasedUpgrades[prereqId] then
return nil, nil
return nil, nil
end
end
Line 53: Line 50:
purchasedUpgradesNext[purchasedUpgradeId] = true
purchasedUpgradesNext[purchasedUpgradeId] = true
for nextUpgradeId, _ in pairs(upgradePrereqsOfById[purchasedUpgradeId]) do
for _, nextUpgradeId in ipairs(upgradePrereqsOfById[purchasedUpgradeId]) do
if not upgradeLocksById[purchasedUpgradeId] or not upgradeLocksById[purchasedUpgradeId][nextUpgradeId] then
if not purchasedUpgrades[nextUpgradeId] then availableUpgradesNext[nextUpgradeId] = true end
availableUpgradesNext[nextUpgradeId] = true
end
end
end
end
end
Line 68: Line 63:
row = {sFormat("\n|-\n|$%s||$%s", FormatNum(currentCost), FormatNum(currentCost*0.7))}
row = {sFormat("\n|-\n|$%s||$%s", FormatNum(currentCost), FormatNum(currentCost*0.7))}
--mw.logObject(purchasedUpgrades)
mw.logObject(purchasedUpgrades)
--mw.logObject(availableUpgrades)
mw.logObject(availableUpgrades)
for upgradeId, _ in pairs(accessibleUpgrades) do
for upgradeId, _ in pairs(accessibleUpgrades) do
Line 78: Line 73:
for availableUpgradeId, _ in pairs(availableUpgrades) do
for availableUpgradeId, _ in pairs(availableUpgrades) do
local purchasedUpgradesNext, availableUpgradesNext = GetPurchasedAndAvailableUpgrades(purchasedUpgrades, availableUpgradeId)
if upgradePrereqsOfById[availableUpgradeId] then
local purchasedUpgradesNext, availableUpgradesNext = GetPurchasedAndAvailableUpgrades(purchasedUpgrades, availableUpgradeId)
if purchasedUpgradesNext and availableUpgradesNext then
purchasedUpgradesNext[availableUpgradeId] = true
if purchasedUpgradesNext and availableUpgradesNext then
RecursiveGetTotalCosts(currentCost + upgradesById[availableUpgradeId].cost, purchasedUpgradesNext, availableUpgradesNext)
purchasedUpgradesNext[availableUpgradeId] = true
if #outputTable == 10 then return end
RecursiveGetTotalCosts(currentCost + upgradesById[availableUpgradeId].cost, purchasedUpgradesNext, availableUpgradesNext)
end
end
end
end
end
Line 89: Line 88:
local rootUpgrades = {}
local rootUpgrades = {}
for _, upgradeId in ipairs(upgradePrereqsOfById.root) do
for _, upgradeId in ipairs(upgradePrereqsOfById.root) do
rootUpgrades[upgradeId] = true
if not initialPurchasedUpgrades[upgradeId] then rootUpgrades[upgradeId] = true end
end
end
Line 122: Line 121:
}),
}),
query("battd_upgrades=main, battd_upgrades__previous=prev", "main.id=thisId, prev._value=prevId", {
query("battd_upgrades=main, battd_upgrades__previous=prev", "main.id=thisId, prev._value=prevId", {
where=sFormat("main.tower='%s'", towerName),
where=sFormat("main.tower='%s' AND NOT unused", towerName),
join="main._ID=prev._RowID"
join="main._ID=prev._RowID"
}),
}),
query("battd_upgrades=main, battd_upgrades__locked_by_upgrades=lock", "main.id=thisId, lock._value=lockId", {
query("battd_upgrades=main, battd_upgrades__locked_by_upgrades=lock", "main.id=thisId, lock._value=lockId", {
where=sFormat("main.tower='%s'", towerName),
where=sFormat("main.tower='%s' AND NOT unused", towerName),
join="main._ID=lock._RowID"
join="main._ID=lock._RowID"
})
})