Anonymous

Module:Skills/Summoning: Difference between revisions

From Melvor Idle
Update for v1.1
mNo edit summary
(Update for v1.1)
Line 1: Line 1:
local p = {}
local p = {}
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')


local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
function p.getFamiliars()
  return Items.getItems(function(item) return item.type == "Familiar" end)
end


function p.getMarkTable(frame)
function p.getMarkTable(frame)
  local result = ''
local result = ''
  result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'{| class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan="2"|Mark!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
result = result..'\r\n!colspan="2"|Mark!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
  result = result..'!!Discovered in'
result = result..'!!Discovered in'


  local Familiars = {}
local Familiars = GameData.getEntities(SkillData.Summoning.recipes, function(recipe) return true end)
  for i, recipe in ipairs(SkillData.Summoning.Marks) do
table.sort(Familiars, function(a, b) return a.level < b.level end)
  table.insert(Familiars, recipe)
  end
  table.sort(Familiars, function(a, b)
                          if a.level == b.level then
                            return a.masteryID < b.masteryID
                          else
                            return a.level < b.level
                          end
                        end)


  local rowArray = {}
local rowArray = {}
  for i, Fam in ipairs(Familiars) do
for i, Fam in ipairs(Familiars) do
local item = Items.getItemByID(Fam.itemID)
local item = Items.getItemByID(Fam.itemID)
if item ~= nil then
if item ~= nil then
    local rowText = '|-'
local rowText = '|-'
    rowText = rowText..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='mark', notext=true, size='50'})
rowText = rowText..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='mark', notext=true, size='50'})
    rowText = rowText..'||'..Icons.Icon({item.name, 'Mark of the ' .. item.name, type='mark', noicon=true})
rowText = rowText..'||'..Icons.Icon({item.name, 'Mark of the ' .. item.name, type='mark', noicon=true})
    rowText = rowText..'||style="text-align:right"|'..Fam.level
rowText = rowText..'||style="text-align:right"|'..Fam.level
    local discoveredArray = {}
local discoveredArray = {}
    for j, SkillID in Shared.skpairs(Fam.skills) do
for j, SkillID in ipairs(Fam.skillIDs) do
      table.insert(discoveredArray, Icons.Icon({Constants.getSkillName(SkillID), type='skill'}))
table.insert(discoveredArray, Icons.Icon({Constants.getSkillName(SkillID), type='skill'}))
    end
end
    rowText = rowText..'||'..table.concat(discoveredArray, '<br/>')
rowText = rowText..'||'..table.concat(discoveredArray, '<br/>')
    table.insert(rowArray, rowText)
table.insert(rowArray, rowText)
end
end
end
  end


  result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n'..table.concat(rowArray, '\r\n')
 
result = result..'\r\n|}'
  result = result..'\r\n|}'
return result
  return result
end
end


function p.getTabletTable(frame)
function p.getTabletTable(frame)
  local result = ''
local result = ''
  result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'{| class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!colspan="2"|Name!!'..Icons.Icon({'Summoning', type='skill', notext=true})..' Level'
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'
result = result..'!!Tier!!Effect!!' .. Icons.Icon({'Melee', notext=true, nolink=true}) .. ' Max Hit!!Shard Cost!!Secondary!!Creation XP'


  local Familiars = {}
local Familiars = GameData.getEntities(SkillData.Summoning.recipes, function(recipe) return true end)
  for i, recipe in ipairs(SkillData.Summoning.Marks) do
table.sort(Familiars, function(a, b) return a.level < b.level end)
  table.insert(Familiars, recipe)
  end
  table.sort(Familiars, function(a, b)
                          if a.level == b.level then
                            return a.masteryID < b.masteryID
                          else
                            return a.level < b.level
                          end
                        end)


  local rowArray = {}
local rowArray = {}
  for i, Fam in ipairs(Familiars) do
for i, Fam in ipairs(Familiars) do
local item = Items.getItemByID(Fam.itemID)
local item = Items.getItemByID(Fam.itemID)
if item ~= nil then
if item ~= nil then
    local maxHit, maxHitText = Items._getItemStat(item, 'summoningMaxhit'), ''
local maxHit, maxHitText = Items._getItemStat(item, 'summoningMaxhit'), ''
    if maxHit ~= nil then
if maxHit ~= nil then
      maxHit = maxHit * 10
maxHit = maxHit * 10
      maxHitText = 'style="text-align:right"; data-sort-value="' .. maxHit .. '"|' .. Shared.formatnum(maxHit)
maxHitText = 'style="text-align:right"; data-sort-value="' .. maxHit .. '"|' .. Shared.formatnum(maxHit)
    end
end
    local rowText = '|-'
local effectDesc = Constants.getModifiersText(Fam.modifiers, false)
    rowText = rowText..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', notext=true, size='50'})
local rowText = '|-'
    rowText = rowText..'||'..Icons.Icon({item.name, type='item', noicon=true})
rowText = rowText..'\r\n|data-sort-value="'..item.name..'"|'..Icons.Icon({item.name, type='item', notext=true, size='50'})
    rowText = rowText..'||style="text-align:right"|'..Fam.level
rowText = rowText..'||'..Icons.Icon({item.name, type='item', noicon=true})
    rowText = rowText..'||style="text-align:right"|'..Fam.tier
rowText = rowText..'||style="text-align:right"|'..Fam.level
    rowText = rowText..'||'..item.description..'||'..maxHitText..'||'..Fam.description
rowText = rowText..'||style="text-align:right"|'..Fam.tier
rowText = rowText..'||'..mw.text.listToText(effectDesc, ', ', ' and ')..'||'..maxHitText


-- Create item requirements text
-- Create item requirements text
local ShardCostArray, OtherCostArray = {}, {}
local ShardCostArray, OtherCostArray = {}, {}
-- Shards
-- Shards
for j, cost in ipairs(Fam.itemCosts) do
for j, cost in ipairs(Fam.itemCosts) do
local shard = Items.getItemByID(cost.id)
local shard = Items.getItemByID(cost.id)
if shard ~= nil then
if shard ~= nil then
table.insert(ShardCostArray, Icons.Icon({shard.name, type='item', notext=true, qty=cost.qty}))
table.insert(ShardCostArray, Icons.Icon({shard.name, type='item', notext=true, qty=cost.quantity}))
end
end
end
end
rowText = rowText..'||style="text-align:right"|'..table.concat(ShardCostArray, ', ')..'&nbsp;'
rowText = rowText..'||style="text-align:right"|'..table.concat(ShardCostArray, ', ')..'&nbsp;'


-- Other costs
-- Other costs
local recipeGPCost = SkillData.Summoning.RecipeGPCost
local recipeGPCost = SkillData.Summoning.RecipeGPCost
if Fam.gpCost > 0 then
if Fam.gpCost > 0 then
table.insert(OtherCostArray, Icons.GP(Fam.gpCost))
table.insert(OtherCostArray, Icons.GP(Fam.gpCost))
end
end
if Fam.scCost > 0 then
if Fam.scCost > 0 then
table.insert(OtherCostArray, Icons.SC(Fam.scCost))
table.insert(OtherCostArray, Icons.SC(Fam.scCost))
end
end
for j, nonShardID in ipairs(Fam.nonShardItemCosts) do
for j, nonShardID in ipairs(Fam.nonShardItemCosts) do
local nonShard = Items.getItemByID(nonShardID)
local nonShard = Items.getItemByID(nonShardID)
if nonShard ~= nil then
if nonShard ~= nil then
local itemValue = math.max(nonShard.sellsFor, 20)
local itemValue = math.max(nonShard.sellsFor, 20)
local nonShardQty = math.max(1, math.floor(recipeGPCost / itemValue))
local nonShardQty = math.max(1, math.floor(recipeGPCost / itemValue))
table.insert(OtherCostArray, Icons.Icon({nonShard.name, type='item', notext=true, qty=nonShardQty}))
table.insert(OtherCostArray, Icons.Icon({nonShard.name, type='item', notext=true, qty=nonShardQty}))
end
end
end
rowText = rowText..'||style="text-align:right"|'..table.concat(OtherCostArray, "<br/>'''OR''' ")
rowText = rowText..'||style="text-align:right"|'..Fam.baseExperience
table.insert(rowArray, rowText)
end
end
rowText = rowText..'||style="text-align:right"|'..table.concat(OtherCostArray, "<br/>'''OR''' ")
rowText = rowText..'||style="text-align:right"|'..Fam.baseXP
    table.insert(rowArray, rowText)
end
end
  end


  result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n'..table.concat(rowArray, '\r\n')


  result = result..'\r\n|}'
result = result..'\r\n|}'
  return result
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 synergyList = {}
  for i, syn in ipairs(SkillData.Summoning.Synergies) do
  table.insert(synergyList, syn)
  end
  table.sort(synergyList, function (a, b) return (a.summons[1] == b.summons[1] and a.summons[2] < b.summons[2]) or a.summons[1] < b.summons[1] end)
 
  local marksByID, famNames = {}, {}
  for i, recipe in ipairs(SkillData.Summoning.Marks) do
  marksByID[recipe.masteryID] = recipe
  local item = Items.getItemByID(recipe.itemID)
  if item ~= nil then
  famNames[recipe.masteryID] = item.name
  end
  end
 
  local rowArray = {}
  for i, syn in ipairs(synergyList) do
local Fam1 = marksByID[syn.summons[1]]
local Fam2 = marksByID[syn.summons[2]]
if Fam1 ~= nil and Fam2 ~= nil then
      local FamName1 = famNames[Fam1.masteryID] or 'Unknown'
  local FamName2 = famNames[Fam2.masteryID] or 'Unknown'
      local rowText = '|-'
      rowText = rowText..'\r\n|data-sort-value="'..FamName1..'"|'..Icons.Icon({FamName1, type='item', notext=true, size='30'})
      rowText = rowText..'||'..Icons.Icon({FamName1, type='item', noicon=true})
      rowText = rowText..'||data-sort-value="'..FamName2..'"|'..Icons.Icon({FamName2, type='item', notext=true, size='30'})
      rowText = rowText..'||'..Icons.Icon({FamName2, type='item', noicon=true})
      rowText = rowText..'||'..syn.description
 
      local reqArray = {}
      local reqLvl = math.max(Fam1.level, Fam2.level)
      table.insert(reqArray, Icons._SkillReq('Summoning', reqLvl))
      table.insert(reqArray, FamName1..' Mark Level '..(Fam2.tier + 1))
      table.insert(reqArray, FamName2..' Mark Level '..(Fam1.tier + 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
end


function p._getFamiliarSynergyTable(familiarID)
function p._getSynergyTable(familiarID)
local result = ''
local result = ''
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'{| class="wikitable sortable stickyHeader"'
Line 190: Line 112:
result = result..'\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect!!Requirements'
result = result..'\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect!!Requirements'


local synergyList = {}
local synergyList = GameData.getEntities(SkillData.Summoning.synergies,
for i, syn in ipairs(SkillData.Summoning.Synergies) do
function(synergy)
if Shared.contains(syn.summons, familiarID) then
return familiarID == nil or Shared.contains(synergy.summonIDs, familiarID)
table.insert(synergyList, syn)
end)
end
table.sort(synergyList, function (a, b) return (a.summonIDs[1] == b.summonIDs[1] and a.summonIDs[2] < b.summonIDs[2]) or a.summonIDs[1] < b.summonIDs[1] end)
end
    table.sort(synergyList, function (a, b) return (a.summons[1] == b.summons[1] and a.summons[2] < b.summons[2]) or a.summons[1] < b.summons[1] end)


local marksByID, famNames = {}, {}
local recipesByID, famNames = {}, {}
for i, recipe in ipairs(SkillData.Summoning.Marks) do
for i, recipe in ipairs(SkillData.Summoning.recipes) do
marksByID[recipe.masteryID] = recipe
recipesByID[recipe.id] = recipe
local item = Items.getItemByID(recipe.itemID)
local item = Items.getItemByID(recipe.productID)
if item ~= nil then
if item ~= nil then
  famNames[recipe.masteryID] = item.name
famNames[recipe.id] = item.name
end
end
end
end
Line 209: Line 129:
local rowArray = {}
local rowArray = {}
for i, syn in ipairs(synergyList) do
for i, syn in ipairs(synergyList) do
local Fam1 = marksByID[syn.summons[1]]
local Fam1 = recipesByID[syn.summonIDs[1]]
local Fam2 = marksByID[syn.summons[2]]
local Fam2 = recipesByID[syn.summonIDs[2]]
if Fam1 ~= nil and Fam2 ~= nil then
if Fam1 ~= nil and Fam2 ~= nil then
local FamName1 = famNames[Fam1.masteryID] or 'Unknown'
local FamName1 = famNames[Fam1.id] or 'Unknown'
local FamName2 = famNames[Fam2.masteryID] or 'Unknown'
local FamName2 = famNames[Fam2.id] or 'Unknown'
local synDesc = syn.customDescription
if synDesc == nil then
-- Generate description from modifiers
synDesc = Constants.getModifiersText(syn.modifiers, false) or ''
end
local rowText = '|-'
local rowText = '|-'
rowText = rowText..'\r\n|data-sort-value="'..FamName1..'"|'..Icons.Icon({FamName1, type='item', notext=true, size='30'})
rowText = rowText..'\r\n|data-sort-value="'..FamName1..'"|'..Icons.Icon({FamName1, type='item', notext=true, size='30'})
Line 219: Line 144:
rowText = rowText..'||data-sort-value="'..FamName2..'"|'..Icons.Icon({FamName2, type='item', notext=true, size='30'})
rowText = rowText..'||data-sort-value="'..FamName2..'"|'..Icons.Icon({FamName2, type='item', notext=true, size='30'})
rowText = rowText..'||'..Icons.Icon({FamName2, type='item', noicon=true})
rowText = rowText..'||'..Icons.Icon({FamName2, type='item', noicon=true})
rowText = rowText..'||'..syn.description
rowText = rowText..'||'..synDesc


local reqArray = {}
local reqArray = {}
Line 226: Line 151:
table.insert(reqArray, FamName1..' Mark Level '..(Fam2.tier + 1))
table.insert(reqArray, FamName1..' Mark Level '..(Fam2.tier + 1))
table.insert(reqArray, FamName2..' Mark Level '..(Fam1.tier + 1))
table.insert(reqArray, FamName2..' Mark Level '..(Fam1.tier + 1))
rowText = rowText..'||data-sort-value="'..reqLvl..'"|'..table.concat(reqArray, '<br/>')
rowText = rowText..'||data-sort-value="'..reqLvl..'"|'..table.concat(reqArray, '<br/>')


Line 233: Line 159:


result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n'..table.concat(rowArray, '\r\n')
result = result..'\r\n|}'
result = result..'\r\n|}'
return result
return result
end
function p.getSynergyTable(frame)
return p._getSynergyTable()
end
end


Line 244: Line 175:
return 'ERROR: Not a valid familiar[[Category:Pages with script errors]]'
return 'ERROR: Not a valid familiar[[Category:Pages with script errors]]'
else
else
for i, recipe in ipairs(SkillData.Summoning.Marks) do
for i, recipe in ipairs(SkillData.Summoning.recipes) do
if recipe.itemID == familiarItem.id then
if recipe.productID == familiarItem.id then
familiarID = recipe.masteryID
familiarID = recipe.id
break
break
end
end
Line 253: Line 184:
return 'ERROR: Not a valid familiar[[Category:Pages with script errors]]'
return 'ERROR: Not a valid familiar[[Category:Pages with script errors]]'
else
else
return p._getFamiliarSynergyTable(familiarID)
return p._getSynergyTable(familiarID)
end
end
end
end
Line 263: Line 194:


-- Familiars
-- Familiars
for i, recipe in ipairs(SkillData.Summoning.Marks) do
for i, recipe in ipairs(SkillData.Summoning.recipes) do
local item = Items.getItemByID(recipe.itemID)
local item = Items.getItemByID(recipe.productID)
if item ~= nil then
if item ~= nil then
famNames[recipe.masteryID] = item.name
famNames[recipe.id] = item.name
if item.modifiers ~= nil then
if item.modifiers ~= nil and not Shared.tableIsEmpty(item.modifiers) then
local famSkills = Constants.getModifierSkills(item.modifiers)
local famSkills = Constants.getModifierSkills(item.modifiers)
if Shared.contains(famSkills, skill) then
if Shared.contains(famSkills, skill) then
Line 277: Line 208:


-- Synergies
-- Synergies
for i, syn in ipairs(SkillData.Summoning.Synergies) do
for i, syn in ipairs(SkillData.Summoning.synergies) do
local synSkills = Constants.getModifierSkills(syn.modifiers)
local synSkills = Constants.getModifierSkills(syn.modifiers)
if Shared.contains(synSkills, skill) then
if Shared.contains(synSkills, skill) then
local FamName1 = famNames[syn.summons[1]] or 'Unknown'
local FamName1 = famNames[syn.summons[1]] or 'Unknown'
local FamName2 = famNames[syn.summons[2]] or 'Unknown'
local FamName2 = famNames[syn.summons[2]] or 'Unknown'
table.insert(rowArray, {Fam1 = FamName1, Fam2 = FamName2, Descrip = syn.description})
local synDesc = syn.customDescription
if synDesc == nil then
-- Generate description from modifiers
synDesc = Constants.getModifiersText(syn.modifiers, false) or ''
end
table.insert(rowArray, {Fam1 = FamName1, Fam2 = FamName2, Descrip = synDesc})
end
end
end
end


if Shared.tableCount(rowArray) == 0 then
if Shared.tableIsEmpty(rowArray) then
return ''
return ''
end
end
Line 295: Line 231:
table.insert(resultPart, '\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect')
table.insert(resultPart, '\r\n!colspan="2"|Familiar 1!!colspan="2"|Familiar 2!!Effect')


for i, rowItem in Shared.skpairs(rowArray) do
for i, rowItem in ipairs(rowArray) do
table.insert(resultPart, '\r\n|-')
table.insert(resultPart, '\r\n|-')
    table.insert(resultPart, '\r\n|data-sort-value="'..rowItem.Fam1..'"|'..Icons.Icon({rowItem.Fam1, type='item', notext=true, size='30'}))
    table.insert(resultPart, '\r\n|data-sort-value="'..rowItem.Fam1..'"|'..Icons.Icon({rowItem.Fam1, type='item', notext=true, size='30'}))