Module:BATTD costs: Difference between revisions
yes i know this is broken i will fix it l8r |
mNo edit summary |
||
| Line 10: | Line 10: | ||
local headerRow = {"{|class=\"wikitable sortable\" style=\"text-align:center\"\n!Total cost!!Sell value"} | local headerRow = {"{|class=\"wikitable sortable\" style=\"text-align:center\"\n!Total cost!!Sell value"} | ||
for i, upgrade in ipairs( | for i, upgrade in ipairs(accessibleUpgrades) do | ||
headerRow[i+1] = sFormat("!![[%s|%s]]", upgrade._pageName, upgrade.name) | headerRow[i+1] = sFormat("!![[%s|%s]]", upgradesById[upgrade]._pageName, upgradesById[upgrade].name) | ||
end | end | ||
| Line 35: | Line 35: | ||
mw.logObject(availableUpgrades) | mw.logObject(availableUpgrades) | ||
for i, upgrade in ipairs( | for i, upgrade in ipairs(accessibleUpgrades) do | ||
row[i+1] = sFormat("||%s", purchasedUpgrades[upgrade.id] and Y or N) | row[i+1] = sFormat("||%s", purchasedUpgrades[upgrade.id] and Y or N) | ||
end | end | ||
| Line 41: | Line 41: | ||
outputTable[#outputTable+1] = tConcat(row, "") | outputTable[#outputTable+1] = tConcat(row, "") | ||
for availableUpgradeId | for _, availableUpgradeId in ipairs(availableUpgrades) do | ||
-- shallow copy purchasedUpgrades and availableUpgrades | -- shallow copy purchasedUpgrades and availableUpgrades | ||
local purchasedUpgradesNext = {} | local purchasedUpgradesNext = {} | ||
| Line 47: | Line 47: | ||
local doNext = true | local doNext = true | ||
for purchasedUpgradeId | for _, purchasedUpgradeId in ipairs(purchasedUpgrades) do | ||
if upgradeLocksById[ | if upgradeLocksById[purchasedUpgradeId] and upgradeLocksById[purchasedUpgradeId][availableUpgradeId] then | ||
doNext = false | doNext = false | ||
break | break | ||
end | end | ||
purchasedUpgradesNext[purchasedUpgradeId] | purchasedUpgradesNext[#purchasedUpgradesNext+1] = upgradesById[purchasedUpgradeId] | ||
for _, | for _, nextUpgradeId in ipairs(upgradePrereqsOfById[purchasedUpgradeId]) do | ||
if not upgradeLocksById[purchasedUpgradeId] and upgradeLocksById[purchasedUpgradeId][ | if not upgradeLocksById[purchasedUpgradeId] and not upgradeLocksById[purchasedUpgradeId][nextUpgradeId] then | ||
availableUpgradesNext[ | availableUpgradesNext[#availableUpgradesNext+1] = nextUpgradeId | ||
end | end | ||
end | end | ||
| Line 63: | Line 63: | ||
if doNext then | if doNext then | ||
purchasedUpgradesNext[ | purchasedUpgradesNext[#purchasedUpgradesNext+1] = availableUpgradeId | ||
RecursiveGetTotalCosts(currentCost + | RecursiveGetTotalCosts(currentCost + upgradesById[availableUpgradeId].cost, purchasedUpgradesNext, availableUpgradesNext) | ||
end | end | ||
end | end | ||
| Line 120: | Line 120: | ||
local sFormat = string.format | local sFormat = string.format | ||
local query = mw.ext.cargo.query | local query = mw.ext.cargo.query | ||
local outputTable = {} | local outputTable = {} | ||
| Line 174: | Line 173: | ||
else | else | ||
upgradePrereqsById[upgrade.thisId] = {upgrade.prevId} | upgradePrereqsById[upgrade.thisId] = {upgrade.prevId} | ||
end | |||
end | |||
-- build upgradeLocksById | |||
for i, upgrade in ipairs(upgradeLocks) do | |||
if upgrade.lockId then | |||
if upgradeLocksById[upgrade.thisId] then | |||
upgradeLocksById[upgrade.thisId][upgrade.lockId] = true | |||
else | |||
upgradeLocksById[upgrade.thisId] = {[upgrade.lockId] = true} | |||
end | |||
end | end | ||
end | end | ||
| Line 187: | Line 197: | ||
return cost | return cost | ||
end | end | ||
-- tower cost + total cost of this upgrade and all its prereqs | |||
local baseCost = getAlreadyPurchasedUpgrades(upgradeId) + query("battd_characters", "cost", { | |||
where=sFormat("name='%s'", towerName) | |||
})[1].cost | |||
local function getAccessibleUpgrades(myUpgradeId) | local function getAccessibleUpgrades(myUpgradeId) | ||
for _, upgrade in ipairs(upgradePrereqsOfById[myUpgradeId]) do | for _, upgrade in ipairs(upgradePrereqsOfById[myUpgradeId]) do | ||
if not purchasedUpgrades[upgrade] then | |||
if | |||
if upgradeLocksById[upgrade] then | if upgradeLocksById[upgrade] then | ||
for _, upgradeLock in ipairs(upgradeLocksById[upgrade]) do | for _, upgradeLock in ipairs(upgradeLocksById[upgrade]) do | ||
| Line 199: | Line 212: | ||
end | end | ||
end | end | ||
getAccessibleUpgrades(upgrade) | |||
accessibleUpgrades[#accessibleUpgrades+1] = upgrade | |||
if upgradePrereqsOfById[upgrade] then | |||
getAccessibleUpgrades(upgrade) | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
getAccessibleUpgrades("root") | getAccessibleUpgrades("root") | ||
--return "" | |||
-- | return GetTotalCosts(baseCost, accessibleUpgrades, upgradesById, upgradeLocksById, upgradePrereqsOfById, Y, N) | ||
return GetTotalCosts(baseCost, | |||
end | end | ||