572
edits
No edit summary |
No edit summary |
||
Line 202: | Line 202: | ||
local resources = Data.Township.Resources() | local resources = Data.Township.Resources() | ||
-- Get the list of | -- 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'] = { | ['melvorF:GP'] = {traderMatches = matchNone}, | ||
['melvorF:Food'] = { | ['melvorF:Food'] = {traderMatches = matchFood}, | ||
['melvorF:Wood'] = { | ['melvorF:Wood'] = {traderMatches = matchLogs}, | ||
['melvorF:Stone'] = { | ['melvorF:Stone'] = {traderMatches = matchOre}, | ||
['melvorF:Ore'] = { | ['melvorF:Ore'] = {traderMatches = matchOre}, | ||
['melvorF:Coal'] = { | ['melvorF:Coal'] = {traderMatches = matchCoal}, | ||
['melvorF:Bar'] = { | ['melvorF:Bar'] = {traderMatches = matchBar}, | ||
['melvorF:Herbs'] = { | ['melvorF:Herbs'] = {traderMatches = matchHerb}, | ||
['melvorF:Rune_Essence'] = { | ['melvorF:Rune_Essence'] = {traderMatches = matchEssence}, | ||
['melvorF:Leather'] = { | ['melvorF:Leather'] = {traderMatches = matchLeather}, | ||
['melvorF:Potions'] = { | ['melvorF:Potions'] = {traderMatches = matchPotion}, | ||
['melvorF:Planks'] = { | ['melvorF:Planks'] = {traderMatches = matchLogs}, | ||
['melvorF:Clothing'] = { | ['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]. | 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. | item.toTownship = math.max(math.floor(1000/(item.healsFor*10)), 2) | ||
item. | 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. | item.toTownship = math.max(math.floor(3000/math.max(item.sellsFor, 1)), 2) | ||
item. | 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. | item.toTownship = 5 | ||
item. | 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. | item.toTownship = 20 | ||
item. | item.fromTownship = 20*6 | ||
end | end | ||
else | else | ||
for _, item in ipairs(resource.itemConversions) do | for _, item in ipairs(resource.itemConversions) do | ||
item. | item.toTownship = math.max(math.floor(1000/math.max(item.sellsFor, 1)), 2) | ||
item. | 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. | 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. | 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. | 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. | 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 |
edits