Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 5: Line 5:




local resource_data = {
['melvorF:GP'] = {skill = nil},
['melvorF:Food'] = {skill = 'melvorD:Cooking'},
['melvorF:Wood'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Stone'] = {skill = 'melvorD:Mining'},
['melvorF:Ore'] = {skill = 'melvorD:Mining'},
['melvorF:Coal'] = {skill = 'melvorD:Mining'},
['melvorF:Bar'] = {skill = 'melvorD:Smithing'},
['melvorF:Herbs'] = {skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {skill = 'melvorD:Mining'},
['melvorF:Leather'] = {skill = nil},
['melvorF:Potions'] = {skill = 'melvorD:Herblore'},
['melvorF:Planks'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Clothing'] = {skill = 'melvorD:Crafting'}
}


local Township = GameData.getSkillData('melvorD:Township')
local Township = GameData.getSkillData('melvorD:Township')
Line 297: Line 282:


-- Gets the associated skill of a resource by id
-- Gets the associated skill of a resource by id
local resource_skill = {
['melvorF:GP'] = {skill = nil},
['melvorF:Food'] = {skill = 'melvorD:Cooking'},
['melvorF:Wood'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Stone'] = {skill = 'melvorD:Mining'},
['melvorF:Ore'] = {skill = 'melvorD:Mining'},
['melvorF:Coal'] = {skill = 'melvorD:Mining'},
['melvorF:Bar'] = {skill = 'melvorD:Smithing'},
['melvorF:Herbs'] = {skill = 'melvorD:Farming'},
['melvorF:Rune_Essence'] = {skill = 'melvorD:Mining'},
['melvorF:Leather'] = {skill = nil},
['melvorF:Potions'] = {skill = 'melvorD:Herblore'},
['melvorF:Planks'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Clothing'] = {skill = 'melvorD:Crafting'}
}
function p._GetResourceSkill(id)
function p._GetResourceSkill(id)
return resource_data[id].skill
return resource_skill[id].skill
end
end


Line 387: Line 387:


-- Production
-- Production
local production = Shared.clone(building.provides.resources)
local production = p._GetBuildingBaseProduction(building)
if #production > 0 then
if production ~= nil then
table.insert(ret, '\r\n|-\r\n| <b>Base Production:</b><br>')
table.insert(ret, '\r\n|-\r\n| <b>Base Production:</b><br>')
local retResources = {}
table.insert(ret, production)
for _, resource in ipairs(production) do
local retProduction = {}
local job = p._GetJobFromResource(resource.id)
local workers = GameData.getEntityByID(building.provides.workers, job).quantity
-- Sourced from township.js -> Township.computeTownResourceGain()
local production = resource.quantity*100*(Township.tickLength/10)
local resource_data = GameData.getEntityByID(resources, resource.id)
table.insert(retProduction, '<span style="color:green">'..Icons.Icon({resource_data.name, type='resource', notext=true})..'&nbsp;+'..production..'</span>')
if resource_data.requires ~= nil and #resource_data.requires > 0 then
for _, required_resource in ipairs(resource_data.requires) do
local demand = production*required_resource.quantity*100
local required_resource_data = GameData.getEntityByID(resources, resource.id)
table.insert(retProduction, '<span style="color:red">'..Icons.Icon({required_resource_data.name, type='resource', notext=true})..'&nbsp;-'..demand..'</span>')
end
end
retProduction = table.concat(retProduction, ', ')..'/t ('..Icons.Icon({'Workers', type='township', notext=true})..'&nbsp;'..workers..')'
table.insert(retResources, retProduction)
end
table.insert(ret, table.concat(retResources, '<br>'))
end
end


Line 447: Line 428:
end
end


-- Gets a string displaying the base production of a building
function p._GetBuildingBaseProduction(building)
local production = Shared.clone(building.provides.resources)
local resources = p._ResourcesData()
if #production == 0 then
return nil
end
local retResources = {}
for _, resource in ipairs(production) do
local retProduction = {}
local job = p._GetJobFromResource(resource.id)
local workers = GameData.getEntityByID(building.provides.workers, job).quantity
-- Sourced from township.js -> Township.computeTownResourceGain()
local production = resource.quantity*100*(Township.tickLength/10)
local resource_data = GameData.getEntityByID(resources, resource.id)
table.insert(retProduction, '<span style="color:green">'..Icons.Icon({resource_data.name, type='resource', notext=true})..'&nbsp;+'..production..'</span>')
if resource_data.requires ~= nil and #resource_data.requires > 0 then
for _, required_resource in ipairs(resource_data.requires) do
local demand = production*required_resource.quantity*100
local required_resource_data = GameData.getEntityByID(resources, resource.id)
table.insert(retProduction, '<span style="color:red">'..Icons.Icon({required_resource_data.name, type='resource', notext=true})..'&nbsp;-'..demand..'</span>')
end
end
retProduction = table.concat(retProduction, ', ')..'/t ('..Icons.Icon({'Workers', type='township', notext=true})..'&nbsp;'..workers..')'
table.insert(retResources, retProduction)
end
return table.concat(retResources, '<br>')
end


-- Testing
-- Testing
572

edits