Anonymous

Module:Sandbox/GauTest/Township: Difference between revisions

From Melvor Idle
Reset for STATUE fix
(End of modifiers test)
(Reset for STATUE fix)
Line 3: Line 3:
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
 


local p = {}
local p = {}
Line 281: Line 281:
end
end


-- modifiers associated with specific biomes
-- Gets the associated skill of a resource by id
local biome_data = {
local resource_skill = {
['melvorF:Grasslands'] = {modifiers = {'increasedTownshipGrasslandsProduction', 'decreasedTownshipGrasslandsProduction'}},
['melvorF:GP'] = {skill = nil},
['melvorF:Forest'] = {modifiers = {'increasedTownshipForestProduction', 'decreasedTownshipForestProduction'}},
['melvorF:Food'] = {skill = 'melvorD:Cooking'},
['melvorF:Desert'] = {modifiers = {'increasedTownshipDesertProduction', 'decreasedTownshipDesertProduction'}},
['melvorF:Wood'] = {skill = 'melvorD:Woodcutting'},
['melvorF:Water'] = {modifiers = {'increasedTownshipWaterProduction', 'decreasedTownshipWaterProduction'}},
['melvorF:Stone'] = {skill = 'melvorD:Mining'},
['melvorF:Swamp'] = {modifiers = {'increasedTownshipSwampProduction', 'decreasedTownshipSwampProduction'}},
['melvorF:Ore'] = {skill = 'melvorD:Mining'},
['melvorF:Arid_Plains'] = {modifiers = {'increasedTownshipAridPlainsProduction', 'decreasedTownshipAridPlainsProduction'}},
['melvorF:Coal'] = {skill = 'melvorD:Mining'},
['melvorF:Mountains'] = {modifiers = {'increasedTownshipMountainsProduction', 'decreasedTownshipMountainsProduction'}},
['melvorF:Bar'] = {skill = 'melvorD:Smithing'},
['melvorF:Valley'] = {modifiers = {'increasedTownshipValleyProduction', 'decreasedTownshipValleyProduction'}},
['melvorF:Herbs'] = {skill = 'melvorD:Farming'},
['melvorF:Jungle'] = {modifiers = {'increasedTownshipJungleProduction', 'decreasedTownshipJungleProduction'}},
['melvorF:Rune_Essence'] = {skill = 'melvorD:Mining'},
['melvorF:Snowlands'] = {modifiers = {'increasedTownshipSnowlandsProduction', 'decreasedTownshipSnowlandsProduction', 'increasedTownshipCoalUsage', 'decreasedTownshipCoalUsage'}},
['melvorF:Leather'] = {skill = nil},
}
['melvorF:Potions'] = {skill = 'melvorD:Herblore'},
 
['melvorF:Planks'] = {skill = 'melvorD:Woodcutting'},
-- modifiers associated with specific buildings or resources
['melvorF:Clothing'] = {skill = 'melvorD:Crafting'}
local unique_modifiers = {
['melvorF:Fishermans_Dock'] = {modifiers = {'increasedTownshipFishingDockProduction', 'decreasedTownshipFishingDockProduction'}},
['melvorF:Fishermans_Pier'] = {modifiers = {'increasedTownshipFishingDockProduction', 'decreasedTownshipFishingDockProduction'}},
['melvorF:Fishermans_Port'] = {modifiers = {'increasedTownshipFishingDockProduction', 'decreasedTownshipFishingDockProduction'}},
['melvorTotH:Fishermans_Estate'] = {modifiers = {'increasedTownshipFishingDockProduction', 'decreasedTownshipFishingDockProduction'}},
['melvorF:Magic_Emporium'] = {modifiers = {'increasedTownshipMagicEmporiumProduction', 'decreasedTownshipMagicEmporiumProduction'}},
['melvorF:Orchard'] = {modifiers = {'increasedTownshipOrchardProduction', 'decreasedTownshipOrchardProduction'}},
['melvorF:Farmland'] = {modifiers = {'increasedTownshipFarmProduction', 'decreasedTownshipFarmProduction'}},
['melvorF:Mill'] = {modifiers = {'increasedTownshipFarmProduction', 'decreasedTownshipFarmProduction'}},
['melvorF:Plantation'] = {modifiers = {'increasedTownshipFarmProduction', 'decreasedTownshipFarmProduction'}},
['melvorTotH:Farming_Estate'] = {modifiers = {'increasedTownshipFarmProduction', 'decreasedTownshipFarmProduction'}},
['melvorF:Woodcutters_Camp'] = {modifiers = {'increasedTownshipWoodcuttingProduction', 'decreasedTownshipWoodcuttingProduction'}},
['melvorF:Logging_Camp'] = {modifiers = {'increasedTownshipWoodcuttingProduction', 'decreasedTownshipWoodcuttingProduction'}},
['melvorF:Forestry_Camp'] = {modifiers = {'increasedTownshipWoodcuttingProduction', 'decreasedTownshipWoodcuttingProduction'}},
['melvorTotH:Forestry_Estate'] = {modifiers = {'increasedTownshipWoodcuttingProduction', 'decreasedTownshipWoodcuttingProduction'}},
['melvorF:Blacksmiths_Smithy'] = {modifiers = {'increasedTownshipBlacksmithProduction', 'decreasedTownshipBlacksmithProduction'}},
['melvorF:Blacksmiths_Forge'] = {modifiers = {'increasedTownshipBlacksmithProduction', 'decreasedTownshipBlacksmithProduction'}},
['melvorF:Blacksmiths_Workshop'] = {modifiers = {'increasedTownshipBlacksmithProduction', 'decreasedTownshipBlacksmithProduction'}},
['melvorTotH:Blacksmiths_Estate'] = {modifiers = {'increasedTownshipBlacksmithProduction', 'decreasedTownshipBlacksmithProduction'}},
['melvorF:Food'] = {modifiers = {'increasedTownshipFoodUsage', 'decreasedTownshipFoodUsage'}},
-- Absolute delta so doesn't apply to buildings
population = {modifiers = {'increasedTownshipPopulationCap', 'decreasedTownshipPopulationCap'}},
-- technically this should go in p.stats, but we don't want to bloat the main modifier table
happiness = {name='Happiness', modifiers = {'increasedTownshipHappiness', 'decreasedTownshipHappiness', 'increasedTownshipBuildingHappinessPenalties', 'decreasedTownshipBuildingHappinessPenalties'}},
}
 
p.stats = {
happiness = {name='Happiness', modifiers = {}}, -- technically there are happiness modifiers that apply to all buildings, but we don't want it to bloat the table
education = {name='Education', modifiers = {'increasedTownshipEducation', 'decreasedTownshipEducation'}},
health = {name='Health', modifiers = {'increasedTownshipHealth', 'decreasedTownshipHealth'}},
storage = {name='Storage', modifiers = {'increasedTownshipMaxStorage', 'decreasedTownshipMaxStorage'}},
deadStorage = {name='Dead Storage', modifiers = {'increasedTownshipDeadStorage', 'decreasedTownshipDeadStorage'}},
population = {name='Population', modifiers = {}}, -- see unique_modifiers
}
 
-- Special modifiers
local special_modifiers = {
-- We split this off into its own table
-- ['all_buildings'] = {modifiers={'increasedTownshipBuildingCost', 'decreasedTownshipBuildingCost'}},
['all_production'] = {modifiers={'increasedTownshipResourceProduction', 'decreasedTownshipResourceProduction'}}, --Includes GP production as well
['unused'] = {modifiers = {'townshipDisableHunting'}},
}
 
-- skill -> The Skill used to produce the Trader's tradeable items
-- modifiers -> For buildings that produce this resource, the modifiers to search for.
local resource_info = {
['melvorF:GP'] = {skill = nil, modifiers={'increasedTownshipGPProduction', 'decreasedTownshipGPProduction', 'increasedTownshipTaxPerCitizen', 'decreasedTownshipTaxPerCitizen'}},
['melvorF:Food'] = {skill = 'melvorD:Cooking', modifiers={'increasedTownshipFoodProduction', 'decreasedTownshipFoodProduction'}},
['melvorF:Wood'] = {skill = 'melvorD:Woodcutting', modifiers={'increasedTownshipWoodProduction', 'decreasedTownshipWoodProduction'}},
['melvorF:Stone'] = {skill = 'melvorD:Mining', modifiers={'increasedTownshipStoneProduction', 'decreasedTownshipStoneProduction'}},
['melvorF:Ore'] = {skill = 'melvorD:Mining', modifiers={'increasedTownshipOreProduction', 'decreasedTownshipOreProduction'}},
['melvorF:Coal'] = {skill = 'melvorD:Mining', modifiers={'increasedTownshipCoalProduction', 'decreasedTownshipCoalProduction', 'TownshipCoalUsage'}},
['melvorF:Bar'] = {skill = 'melvorD:Smithing', modifiers={'increasedTownshipBarProduction', 'decreasedTownshipBarProduction'}},
['melvorF:Herbs'] = {skill = 'melvorD:Farming', modifiers={'increasedTownshipHerbProduction', 'decreasedTownshipHerbProduction'}},
['melvorF:Rune_Essence'] = {skill = 'melvorD:Mining', modifiers={'increasedTownshipRuneEssenceProduction', 'decreasedTownshipRuneEssenceProduction'}},
['melvorF:Leather'] = {skill = nil, modifiers={'increasedTownshipLeatherProduction', 'decreasedTownshipLeatherProduction'}},
['melvorF:Potions'] = {skill = 'melvorD:Herblore', modifiers={'increasedTownshipPotionProduction', 'decreasedTownshipPotionProduction'}},
['melvorF:Planks'] = {skill = 'melvorD:Woodcutting', modifiers={'increasedTownshipPlankProduction', 'decreasedTownshipPlankProduction'}},
['melvorF:Clothing'] = {skill = 'melvorD:Crafting', modifiers={'increasedTownshipClothingProduction', 'decreasedTownshipClothingProduction'}},
}
}
-- Gets a list of target modifiers based on the building name
function p._GetBuildingModifiers(building)
local modifiers = {}
local newModifiers = nil
local function addModifiers(_newModifiers)
if newModifiers ~= nil then
for _, newModifier in pairs(_newModifiers.modifiers) do
table.insert(modifiers, newModifier)
end
end
end
-- Unique ID modifiers
newModifiers = unique_modifiers[building.id]
addModifiers(newModifiers)
-- Building modifiers
-- newModifiers = special_modifiers.all_buildings
-- addModifiers(newModifiers)
-- Production modifiers
local anyProduction = false
for _, resource in ipairs(building.provides.resources) do
anyProduction = true
newModifiers = resource_info[resource.id]
addModifiers(newModifiers)
end
if anyProduction == true then
newModifiers = special_modifiers.all_production
addModifiers(newModifiers)
end
-- Benefit modifiers
for statid, stat in pairs(p.stats) do
if building.provides[statid] ~= nil and building.provides[statid] ~= 0 then
addModifiers(stat)
end
end
return modifiers
end
-- Gets a list of target modifiers based on a resource id
function p._GetResourceModifiers(resource_id)
local modifiers = {}
local newModifiers = nil
local function addModifiers(_newModifiers)
if newModifiers ~= nil then
for _, newModifier in pairs(_newModifiers.modifiers) do
table.insert(modifiers, newModifier)
end
end
end
-- Unique ID modifiers
newModifiers = unique_modifiers[resource_id]
addModifiers(newModifiers)
-- Production
newModifiers = special_modifiers.all_production
addModifiers(newModifiers)
-- Resource modifiers
newModifiers = resource_info[resource_id]
addModifiers(newModifiers)
return modifiers
end
-- Gets a list of target modifiers based on a stat id
function p._GetStatModifiers(stat_id)
local modifiers = {}
local newModifiers = nil
local function addModifiers(_newModifiers)
if newModifiers ~= nil then
for _, newModifier in pairs(_newModifiers.modifiers) do
table.insert(modifiers, newModifier)
end
end
end
-- Unique ID modifiers
newModifiers = unique_modifiers[stat_id]
addModifiers(newModifiers)
-- Production
newModifiers = p.stats[stat_id]
addModifiers(newModifiers)
return modifiers
end
-- Gets a list of target modifiers based on a biome id. Does not include buildings' biomeModifiers
function p._GetBiomeModifiers(biome_id)
local modifiers = {}
local newModifiers = nil
local function addModifiers(_newModifiers)
if newModifiers ~= nil then
for _, newModifier in pairs(_newModifiers.modifiers) do
table.insert(modifiers, newModifier)
end
end
end
-- Unique ID modifiers
newModifiers = biome_data[biome_id]
addModifiers(newModifiers)
return modifiers
end
-- Gets the modifiers for the specified entity
function p.GetModifiers(name, type)
if type == 'building' then
return p._GetBuildingModifiers(p._GetBuildingByName(name))
end
if type == 'resource' then
return p._GetResourceModifiers(p._GetResourceByName(name).id)
end
if type == 'stat' then
for key, stat in pairs(p.stats) do
if stat.name == name then
return p._GetStatModifiers(key)
end
end
end
if type == 'biome' then
local biome = GameData.getEntityByName(Township.biomes, name)
return p._GetBiomeModifiers(biome.id)
end
end
function p._GetResourceSkill(id)
function p._GetResourceSkill(id)
return resource_info[id].skill
return resource_skill[id].skill
end
end


Line 649: Line 445:
function p._GetBuildingBenefits(building)
function p._GetBuildingBenefits(building)
local benefits = {}
local benefits = {}
for statid, stat in pairs(p.stats) do
local stats = {
if building.provides[statid] ~= nil and building.provides[statid] ~= 0 then
population = 'Population',
local quantity = building.provides[statid]
happiness = 'Happiness',
education = 'Education',
storage = 'Storage',
deadStorage = 'Dead Storage'
}
for key, stat in pairs(stats) do
if building.provides[key] ~= nil and building.provides[key] ~= 0 then
local quantity = building.provides[key]
if quantity < 0 then
if quantity < 0 then
quantity = '<span style="color:red">'..quantity..'</span>'
quantity = '<span style="color:red">'..quantity..'</span>'
Line 657: Line 460:
quantity = Shared.numStrWithSign(quantity)
quantity = Shared.numStrWithSign(quantity)
end
end
table.insert(benefits, Icons.Icon({stat.name, type='township', notext=true})..'&nbsp;'..quantity)
table.insert(benefits, Icons.Icon({stat, type='township', notext=true})..'&nbsp;'..quantity)
end
end
end
end
Line 700: Line 503:
function p._GetResourceByID(id)
function p._GetResourceByID(id)
return GameData.getEntityByID(p.resources, id)
return GameData.getEntityByID(p.resources, id)
end
-- Gets a resource from name
function p._GetResourceByName(name)
return GameData.getEntityByName(p.resources, name)
end
end


-- Gets text for only the biomes that have a modifier for a building
-- Gets text for only the biomes that have a modifier for a building
function p._GetBuildingBiomeModifiers(building)
function p._GetBiomeModifiers(building)
local biomeRet = {}
local biomeRet = {}
for _, biome in ipairs(building.biomeModifiers) do
for _, biome in ipairs(building.biomeModifiers) do
Line 797: Line 595:
BuildOptionalRow('\r\n|-\r\n! Benefits\r\n|', p._GetBuildingBenefits)
BuildOptionalRow('\r\n|-\r\n! Benefits\r\n|', p._GetBuildingBenefits)
BuildOptionalRow('\r\n|-\r\n! Base Production per '..Icons.Icon({'Workers', type='township', notext=true})..'\r\n|', p._GetBuildingBaseProduction)
BuildOptionalRow('\r\n|-\r\n! Base Production per '..Icons.Icon({'Workers', type='township', notext=true})..'\r\n|', p._GetBuildingBaseProduction)
BuildOptionalRow('\r\n|-\r\n! Biome Production Modifiers\r\n|', p._GetBuildingBiomeModifiers)
BuildOptionalRow('\r\n|-\r\n! Biome Production Modifiers\r\n|', p._GetBiomeModifiers)


-- End
-- End
Line 848: Line 646:
table.insert(ret, '\r\n|}')
table.insert(ret, '\r\n|}')
return table.concat(ret)
return table.concat(ret)
end
-- Splits each worship formatted each tier separately to check modifiers more easily
function p.GetSplitWorship()
local out = {}
for _, _worship in ipairs(Township.worships) do
local worship = Shared.clone(_worship)
worship.namePercent = worship.name..' (0%)'
table.insert(out, worship)
for i, checkpoint in ipairs(worship.checkpoints) do
worship = Shared.clone(_worship)
worship.namePercent = worship.name..' ('..Township.worshipCheckpoints[i]..'%)'
worship.modifiers = checkpoint
table.insert(out, worship)
end
end
return out
end
end


return p
return p
572

edits