Module:Township: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 204: Line 204:
-- Get the list of convertable items, and calculates each item's exchange rate
-- Get the list of convertable items, and calculates each item's exchange rate
-- 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)
return false
end
local function matchFood(item)
local function matchFood(item)
return item.type == 'Food' and (not string.match(item.id, '_Perfect')) and item.category ~= 'Farming' and (not item.ignoreCompletion)
return item.type == 'Food' and (not string.match(item.id, '_Perfect')) and item.category ~= 'Farming' and (not item.ignoreCompletion)
end
end
for _, resource in ipairs(resources) do
local function matchLogs(item)
resource.itemConversions = {}
return item.type == 'Logs'
if resource.id == 'melvorF:GP' then
end
-- No conversions
local function matchOre(item)
elseif resource.id == 'melvorF:Food' then
return item.type == 'Ore' and item.id ~= 'melvorTotH:Meteorite_Ore'
resource.itemConversions = Shared.clone(GameData.getEntities('items', matchFood))
end
elseif resource.id == 'melvorF:Wood' or resource.id == 'melvorF:Planks' then
local function matchCoal(item)
resource.itemConversions = Data.Item.Match('type', 'Logs')
return item.id ~= 'melvorD:Coal_Ore'
elseif resource.id == 'melvorF:Stone' or resource.id == 'melvorF:Ore' then
end
for _, ore in ipairs(Data.Item.Match('type', 'Ore')) do
local function matchBar(item)
if not string.match(ore.id, 'Meteorite_Ore') then
return item.type == 'Bar' and item.id ~= 'melvorTotH:Meteorite_Bar'
table.insert(resource.itemConversions, ore)
end
end
local function matchHerb(item)
end
return item.type == 'Herb'
elseif resource.id == 'melvorF:Coal' then
end
local coal = 'melvorD:Coal_Ore'
local function matchEssence(item)
table.insert(resource.itemConversions, Data.Item.ByID(coal))
return item.id == 'melvorD:Rune_Essence' or item.id == 'melvorTotH:Pure_Essence'
elseif resource.id == 'melvorF:Bar' then
end
for _, bar in ipairs(Data.Item.Match('type', 'Ore')) do
local function matchLeather(item)
if not string.match(bar.id, 'Meteorite_Bar') then
return item.id == 'melvorD:Leather'
table.insert(resource.itemConversions, bar)
end
end
local function matchPotion(item)
end
return item.type == 'Potion' and string.match(item.id, '_IV')
elseif resource.id == 'melvorF:Herbs' then
end
resource.itemConversions = Data.Item.Match('type', 'Herb')
local function matchClothing(item)
elseif resource.id == 'melvorF:Rune_Essence' then
local valid_tiers = {'Leather', 'Hard Leather', 'Dragonhide', 'Elderwood', 'Revenant', 'Carrion'}
local ressence = 'melvorD:Rune_Essence'
for _, tier in ipairs(valid_tiers) do
local pessence = 'melvorTotH:Pure_Essence'
if item.tier == tier then
table.insert(resource.itemConversions, Data.Item.ByID(ressence))
return true
table.insert(resource.itemConversions, Data.Item.ByID(pessence))
elseif resource.id == 'melvorF:Leather' then
local leather = 'Leather'
table.insert(resource.itemConversions, Data.Item.ByID(leather))
elseif resource.id == 'melvorF:Potions' then
for _, potion in ipairs(Data.Item.Match('type', 'Potion')) do
if string.match(potion.id, '_IV') then
table.insert(resource.itemConversions, potion)
end
end
elseif resource.id == 'melvorF:Clothing' then
local matches = {}
table.insert(matches, Data.Item.Match('tier', 'Leather'))
table.insert(matches, Data.Item.Match('tier', 'Hard Leather'))
table.insert(matches, Data.Item.Match('tier', 'Dragonhide'))
table.insert(matches, Data.Item.Match('tier', 'Elderwood'))
table.insert(matches, Data.Item.Match('tier', 'Revenant'))
table.insert(matches, Data.Item.Match('tier', 'Carrion'))
for _, match in ipairs(matches) do
for _, v in ipairs(match) do
table.insert(resource.itemConversions, v)
end
end
end
end
end
return false
end
local resource_data = {
['melvorF:GP'] = {_tradermatches = matchNone},
['melvorF:Food'] = {_tradermatches = matchFood},
['melvorF:Wood'] = {_tradermatches = matchLogs},
['melvorF:Stone'] = {_tradermatches = matchOre},
['melvorF:Ore'] = {_tradermatches = matchOre},
['melvorF:Coal'] = {_tradermatches = matchCoal},
['melvorF:Bar'] = {_tradermatches = matchBar},
['melvorF:Herbs'] = {_tradermatches = matchHerb},
['melvorF:Rune_Essence'] = {_tradermatches = matchEssence},
['melvorF:Leather'] = {_tradermatches = matchLeather},
['melvorF:Potions'] = {_tradermatches = matchPotion},
['melvorF:Planks'] = {_tradermatches = matchLogs},
['melvorF:Clothing'] = {_tradermatches = matchClothing}
}
for _, resource in ipairs(resources) do
resource.itemConversions = Shared.clone(GameData.getEntities('items', resource_data[resource.id]._tradermatches))
end
end
572

edits