Module:Skills/Summoning
From Melvor Idle
Documentation for this module may be created at Module:Skills/Summoning/doc
local p = {}
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
function p.getFamiliars()
return Items.getItems(function(item) return item.type == "Familiar" end)
end
function p.getMarkTable(frame)
local result = ''
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Mark!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
result = result..'!!Discovered in'
local Familiars = p.getFamiliars()
table.sort(Familiars, function(a, b)
if a.summoningLevel == b.summoningLevel then
return a.summoningID < b.summoningID
else
return a.summoningLevel < b.summoningLevel
end
end)
local rowArray = {}
for i, Fam in Shared.skpairs(Familiars) do
local rowText = '|-'
rowText = rowText..'\r\n|data-sort-value="'..Fam.name..'"|'..Icons.Icon({Fam.name, type='mark', notext=true, size='50'})
rowText = rowText..'||[['..Fam.name..'|Mark of the '..Fam.name..']]'
rowText = rowText..'||style="text-align:right"|'..Fam.summoningLevel
local discoveredArray = {}
for j, SkillID in Shared.skpairs(Fam.summoningSkills) do
table.insert(discoveredArray, Icons.Icon({Constants.getSkillName(SkillID), type='skill'}))
end
rowText = rowText..'||'..table.concat(discoveredArray, '<br/>')
table.insert(rowArray, rowText)
end
result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n|}'
return result
end
function p.getTabletTable(frame)
local result = ''
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
result = result..'!!Tier!!Effect!!' .. Icons.Icon({'Melee', notext=true, nolink=true}) .. ' Max Hit!!Description!!Shard Cost!!Secondary!!Creation XP'
local Familiars = p.getFamiliars()
table.sort(Familiars, function(a, b)
if a.summoningLevel == b.summoningLevel then
return a.summoningID < b.summoningID
else
return a.summoningLevel < b.summoningLevel
end
end)
local rowArray = {}
for i, Fam in Shared.skpairs(Familiars) do
local maxHit = Fam.summoningMaxHit
local maxHitText = ''
if maxHit ~= nil then maxHitText = 'style="text-align:right"; data-sort-value="' .. maxHit .. '"|' .. Shared.formatnum(maxHit) end
local rowText = '|-'
rowText = rowText..'\r\n|data-sort-value="'..Fam.name..'"|'..Icons.Icon({Fam.name, type='item', notext=true, size='50'})
rowText = rowText..'||[['..Fam.name..']]'
rowText = rowText..'||style="text-align:right"|'..Fam.summoningLevel
rowText = rowText..'||style="text-align:right"|'..Fam.summoningTier
rowText = rowText..'||'..Fam.description..'||'..maxHitText..'||'..Fam.summoningDescription
--Currently assuming the shard cost is the same for all recipe variants
local ShardCostArray = {}
for j, cost in Shared.skpairs(Fam.summoningReq[1]) do
if cost.id >= 0 then
local item = Items.getItemByID(cost.id)
if item.type == 'Shard' then
table.insert(ShardCostArray, Icons.Icon({item.name, type='item', notext=true, qty=cost.qty}))
end
end
end
rowText = rowText..'||style="text-align:right"|'..table.concat(ShardCostArray, ', ')..' '
--Now to get all the other cost options
local OtherCostArray = {}
local recipeGPCost = SkillData.Summoning.Settings.recipeGPCost
for j, altCost in Shared.skpairs(Fam.summoningReq) do
local nonShardArray = {}
for k, cost in Shared.skpairs(altCost) do
if cost.id >= 0 then
local item = Items.getItemByID(cost.id)
if item.type ~= 'Shard' then
local sellPrice = item.sellsFor
if sellPrice < 20 then sellPrice = 20 end
table.insert(nonShardArray, Icons.Icon({item.name, type='item', notext=true, qty=math.max(1, math.floor(recipeGPCost / sellPrice))}))
end
else
if cost.id == -4 then
table.insert(nonShardArray, Icons.GP(recipeGPCost))
elseif cost.id == -5 then
table.insert(nonShardArray, Icons.SC(recipeGPCost))
end
end
end
table.insert(OtherCostArray, table.concat(nonShardArray, ', '))
end
rowText = rowText..'||style="text-align:right"|'..table.concat(OtherCostArray, "<br/>'''OR''' ")
rowText = rowText..'||style="text-align:right"|'..(5 + 2 * math.floor(Fam.summoningLevel / 5))
table.insert(rowArray, rowText)
end
result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n|}'
return result
end
function p.getSynergyTable(frame)
local result = ''
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect!!Requirements'
local Familiars = p.getFamiliars()
local FamArrayByID = {}
for i, Fam in Shared.skpairs(Familiars) do
FamArrayByID[Fam.summoningID + 1] = Fam
end
local rowArray = {}
for i, SynCat in Shared.skpairs(SkillData.Summoning.Synergies) do
local Fam1 = FamArrayByID[i]
for j, Syn in Shared.skpairs(SynCat) do
local Fam2 = FamArrayByID[j]
local rowText = '|-'
rowText = rowText..'\r\n|data-sort-value="'..Fam1.name..'"|'..Icons.Icon({Fam1.name, type='item', notext=true, size='30'})..'||[['..Fam1.name..']]'
rowText = rowText..'||data-sort-value="'..Fam2.name..'"|'..Icons.Icon({Fam2.name, type='item', notext=true, size='30'})..'||[['..Fam2.name..']]'
rowText = rowText..'||'..Syn.description
local reqArray = {}
local reqLvl = math.max(Fam1.summoningLevel, Fam2.summoningLevel)
table.insert(reqArray, Icons._SkillReq('Summoning', reqLvl))
table.insert(reqArray, Fam1.name..' Mark Level '..(Fam2.summoningTier + 1))
table.insert(reqArray, Fam2.name..' Mark Level '..(Fam1.summoningTier + 1))
rowText = rowText..'||data-sort-value="'..reqLvl..'"|'..table.concat(reqArray, '<br/>')
table.insert(rowArray, rowText)
end
end
result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n|}'
return result
end
function p._getFamiliarSynergyTable(familiar)
local result = ''
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect!!Requirements'
local Familiars = p.getFamiliars()
local FamArrayByID = {}
for i, Fam in Shared.skpairs(Familiars) do
FamArrayByID[Fam.summoningID + 1] = Fam
end
local rowArray = {}
for i, SynCat in Shared.skpairs(SkillData.Summoning.Synergies) do
local Fam1 = FamArrayByID[i]
for j, Syn in Shared.skpairs(SynCat) do
local Fam2 = FamArrayByID[j]
if i - 1 == familiar.summoningID or j - 1 == familiar.summoningID then
local rowText = '|-'
rowText = rowText..'\r\n|data-sort-value="'..Fam1.name..'"|'..Icons.Icon({Fam1.name, type='item', notext=true, size='30'})..'||[['..Fam1.name..']]'
rowText = rowText..'||data-sort-value="'..Fam2.name..'"|'..Icons.Icon({Fam2.name, type='item', notext=true, size='30'})..'||[['..Fam2.name..']]'
rowText = rowText..'||'..Syn.description
local reqArray = {}
local reqLvl = math.max(Fam1.summoningLevel, Fam2.summoningLevel)
table.insert(reqArray, Icons._SkillReq('Summoning', reqLvl))
table.insert(reqArray, Fam1.name..' Mark Level '..(Fam2.summoningTier + 1))
table.insert(reqArray, Fam2.name..' Mark Level '..(Fam1.summoningTier + 1))
rowText = rowText..'||data-sort-value="'..reqLvl..'"|'..table.concat(reqArray, '<br/>')
table.insert(rowArray, rowText)
end
end
end
result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n|}'
return result
end
function p.getFamiliarSynergyTable(frame)
local famName = frame.args ~= nil and frame.args[1] or frame
local familiar = Items.getItem(famName)
if familiar == nil or familiar.type ~= 'Familiar' then
return 'ERROR: Not a valid familiar[[Category:Pages with script errors]]'
end
return p._getFamiliarSynergyTable(familiar)
end
function p._getSkillSummoningBonusTable(skill)
local rowArray = {}
local Familiars = p.getFamiliars()
local FamArrayByID = {}
for i, Fam in Shared.skpairs(Familiars) do
FamArrayByID[Fam.summoningID + 1] = Fam
local famSkills = Constants.getModifierSkills(Fam.modifiers)
for k, skillName in Shared.skpairs(famSkills) do
if skillName == skill then
table.insert(rowArray, {Fam1 = Fam.name, Fam2 = nil, Descrip = Constants.getModifiersText(Fam.modifiers, false)})
end
end
end
for i, SynCat in Shared.skpairs(SkillData.Summoning.Synergies) do
local Fam1 = FamArrayByID[i]
for j, Syn in Shared.skpairs(SynCat) do
local Fam2 = FamArrayByID[j]
local skills = Constants.getModifierSkills(Syn.modifiers)
for k, skillName in Shared.skpairs(skills) do
if skillName == skill then
table.insert(rowArray, {Fam1 = Fam1.name, Fam2 = Fam2.name, Descrip = Syn.description})
end
end
end
end
local result = ''
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect!!Requirements'
for i, rowItem in Shared.skpairs(rowArray) do
result = result..'\r\n|-'
result = result..'\r\n|data-sort-value="'..rowItem.Fam1..'"|'..Icons.Icon({rowItem.Fam1, type='item', notext=true, size='30'})..'||[['..rowItem.Fam1..']]'
if rowItem.Fam2 ~= nil then
result = result..'||data-sort-value="'..rowItem.Fam2..'"|'..Icons.Icon({rowItem.Fam2, type='item', notext=true, size='30'})..'||[['..rowItem.Fam2..']]'
else
result = result..'|| || '
end
if rowItem.Descrip == nil then
if rowItem.Fam2 == nil then
mw.log(rowItem.Fam1)
else
mw.log(rowItem.Fam1..' + '..rowItem.Fam2)
end
else
result = result..'||'..rowItem.Descrip
end
end
result = result..'\r\n|}'
return result
end
function p.getSkillSummoningBonusTable(frame)
local skillName = frame.args ~= nil and frame.args[1] or frame
return p._getSkillSummoningBonusTable(skillName)
end
return p