Module:Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 202: Line 202:
local resources = Data.Township.Resources()
local resources = Data.Township.Resources()
-- Get the list of convertable items, and calculates each item's exchange rate
-- Get the list of tradeable items
-- See township.js -> TownshipResource.buildResourceItemConversions for the calculation of valid items
-- See township.js -> TownshipResource.buildResourceItemConversions for the calculation of valid items
local function matchNone(item)
local function matchNone(item)
Line 245: Line 245:


local resource_data = {
local resource_data = {
['melvorF:GP'] = {_tradermatches = matchNone},
['melvorF:GP'] = {traderMatches = matchNone},
['melvorF:Food'] = {_tradermatches = matchFood},
['melvorF:Food'] = {traderMatches = matchFood},
['melvorF:Wood'] = {_tradermatches = matchLogs},
['melvorF:Wood'] = {traderMatches = matchLogs},
['melvorF:Stone'] = {_tradermatches = matchOre},
['melvorF:Stone'] = {traderMatches = matchOre},
['melvorF:Ore'] = {_tradermatches = matchOre},
['melvorF:Ore'] = {traderMatches = matchOre},
['melvorF:Coal'] = {_tradermatches = matchCoal},
['melvorF:Coal'] = {traderMatches = matchCoal},
['melvorF:Bar'] = {_tradermatches = matchBar},
['melvorF:Bar'] = {traderMatches = matchBar},
['melvorF:Herbs'] = {_tradermatches = matchHerb},
['melvorF:Herbs'] = {traderMatches = matchHerb},
['melvorF:Rune_Essence'] = {_tradermatches = matchEssence},
['melvorF:Rune_Essence'] = {traderMatches = matchEssence},
['melvorF:Leather'] = {_tradermatches = matchLeather},
['melvorF:Leather'] = {traderMatches = matchLeather},
['melvorF:Potions'] = {_tradermatches = matchPotion},
['melvorF:Potions'] = {traderMatches = matchPotion},
['melvorF:Planks'] = {_tradermatches = matchLogs},
['melvorF:Planks'] = {traderMatches = matchLogs},
['melvorF:Clothing'] = {_tradermatches = matchClothing}
['melvorF:Clothing'] = {traderMatches = matchClothing}
}
}
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
resource.itemConversions = Shared.clone(GameData.getEntities('items', resource_data[resource.id]._tradermatches))
resource.itemConversions = Shared.clone(GameData.getEntities('items', resource_data[resource.id].traderMatches))
end
end
-- Calculate the conversion ratios
-- Calculate the conversion ratios
-- See TownshipResource.getBaseConvertToTownshipRatio and TownshipResource.getBaseConvertFromTownshipRatio for the conversion prices
-- See township.js TownshipResource.getBaseConvertToTownshipRatio and TownshipResource.getBaseConvertFromTownshipRatio for the conversion prices
for _, resource in ipairs(resources) do
for _, resource in ipairs(resources) do
if resource.id == 'Food' then
if resource.id == 'melvorF:Food' then
for _, item in ipairs(resource.itemConversions) do
for _, item in ipairs(resource.itemConversions) do
item.to = math.max(math.floor(1000/(item.healsFor*10)), 2)
item.toTownship = math.max(math.floor(1000/(item.healsFor*10)), 2)
item.from = item.healsFor*5*6
item.fromTownship = item.healsFor*5*6
end
end
elseif resource.id == 'Planks' then
elseif resource.id == 'melvorF:Planks' then
for _, item in ipairs(resource.itemConversions) do
for _, item in ipairs(resource.itemConversions) do
item.to = math.max(math.floor(3000/math.max(item.sellsFor, 1)), 2)
item.toTownship = math.max(math.floor(3000/math.max(item.sellsFor, 1)), 2)
item.from = math.max(math.ceil(item.sellsFor/2)*6, 1);
item.fromTownship = math.max(math.ceil(item.sellsFor/2)*6, 1);
end
end
elseif resource.id == 'Rune_Essence' then
elseif resource.id == 'melvorF:Rune_Essence' then
for _, item in ipairs(resource.itemConversions) do
for _, item in ipairs(resource.itemConversions) do
item.to = 5
item.toTownship = 5
item.from = (item.sellsFor+1)*10*6
item.fromTownship = (item.sellsFor+1)*10*6
end
end
elseif resource.id == 'Leather' then
elseif resource.id == 'melvorF:Leather' then
for _, item in ipairs(resource.itemConversions) do
for _, item in ipairs(resource.itemConversions) do
item.to = 20
item.toTownship = 20
item.from = 20*6
item.fromTownship = 20*6
end
end
else
else
for _, item in ipairs(resource.itemConversions) do
for _, item in ipairs(resource.itemConversions) do
        item.to = math.max(math.floor(1000/math.max(item.sellsFor, 1)), 2)
        item.toTownship = math.max(math.floor(1000/math.max(item.sellsFor, 1)), 2)
    item.from = math.max(item.sellsFor * 6, 1)
    item.fromTownship = math.max(item.sellsFor*6, 1)
end
end
end
end
Line 355: Line 355:
end
end
-- Give To
-- Give To
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.to .. '"|'..Icons.Icon({item.name, type='item', notext=true})..' '..Shared.formatnum(item.to))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.toTownship .. '"|'..Icons.Icon({item.name, type='item', notext=true})..' '..Shared.formatnum(item.toTownship))
-- Take From
-- Take From
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.from .. '"|'..Icons.Icon(resource._icon)..' '..Shared.formatnum(item.from))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.fromTownship .. '"|'..Icons.Icon(resource._icon)..' '..Shared.formatnum(item.fromTownship))
-- Value
-- Value
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor .. '"|'..Icons.GP(item.sellsFor))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor .. '"|'..Icons.GP(item.sellsFor))
-- Value/Resource
-- Value/Resource
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor/item.from .. '"|'..Icons.GP(Shared.round(item.sellsFor/item.from, 2, 2)))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.sellsFor/item.fromTownship .. '"|'..Icons.GP(Shared.round(item.sellsFor/item.fromTownship, 2, 2)))
if resource.id =='Food' then
if resource.id =='Food' then
-- Heals
-- Heals
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.healsFor*10 .. '"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..Shared.formatnum(item.healsFor*10))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.healsFor*10 .. '"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..Shared.formatnum(item.healsFor*10))
-- Heals/Resource
-- Heals/Resource
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.healsFor*10/item.from .. '"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..Shared.round(item.healsFor*10/item.from, 2, 2))
table.insert(ret_resource, '\r\n|style="text-align:center" data-sort-value="' .. item.healsFor*10/item.fromTownship .. '"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..Shared.round(item.healsFor*10/item.fromTownship, 2, 2))
end
end
end
end
572

edits