Anonymous

Module:Skills/Gathering: Difference between revisions

From Melvor Idle
_buildAstrologyModifierArray: Further fixes to key/value pair return value
(getThievingNPCTable: Add GP column)
(_buildAstrologyModifierArray: Further fixes to key/value pair return value)
(4 intermediate revisions by the same user not shown)
Line 12: Line 12:
local thievingNormalLootChance = 75
local thievingNormalLootChance = 75
local thievingAreaLootChance = 0.2
local thievingAreaLootChance = 0.2
function p.getConstellationByID(constID)
return SkillData.Astrology.Constellations[constID]
end
function p.getConstellation(constName)
for i, const in ipairs(SkillData.Astrology.Constellations) do
if const.name == constName then
return const
end
end
return nil
end
function p.getConstellations(checkFunc)
local result = {}
for i, const in ipairs(SkillData.Astrology.Constellations) do
if checkFunc(const) then
table.insert(result, const)
end
end
return result
end


function p.getAxeTable(frame)
function p.getAxeTable(frame)
Line 688: Line 711:
return resultArray
return resultArray
end
-- For a given constellation cons and modifier value modValue, generates and returns
-- a table of modifiers, much like any other item/object elsewhere in the game.
-- includeStandard: true|false, determines whether standard modifiers are included
-- includeUnique: true|false, determines whether unique modifiers are included
-- isDistinct: true|false, if true, the returned list of modifiers is de-duplicated
-- asKeyValue: true|false, if true, returns key/value pairs like usual modifier objects
function p._buildAstrologyModifierArray(cons, modValue, includeStandard, includeUnique, isDistinct, asKeyValue)
-- Temporary function to determine if the table already contains a given modifier
local containsMod = function(modList, modNew)
for i, modItem in ipairs(modList) do
-- Check mod names & value data types both equal
if modItem[1] == modNew[1] and type(modItem[2]) == type(modNew[2]) then
if type(modItem[2]) == 'table' then
if Shared.tablesEqual(modItem[2], modNew[2]) then
return true
end
elseif modItem[2] == modNew[2] then
return true
end
end
end
return false
end
local addToArray = function(modArray, modNew)
if not isDistinct or (isDistinct and not containsMod(modArray, modNew)) then
table.insert(modArray, modNew)
end
end
local modArray = {}
local isSkillMod = {}
-- Standard modifiers
if includeStandard then
for i, skillMods in ipairs(cons.standardModifiers) do
local skillID = cons.skills[i]
if skillID ~= nil then
for j, modName in ipairs(skillMods) do
local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName)
-- Check if modifier varies by skill, and amend the modifier value accordingly
local modVal = modValue
if Shared.contains(modText, '{SV0}') then
isSkillMod[modName] = true
modVal = {skillID, modValue}
end
addToArray(modArray, {modName, modVal})
end
end
end
end
-- Unique modifiers
if includeUnique then
local skillArray = {}
for i, skillID in ipairs(cons.skills) do
table.insert(skillArray, SkillData.Skills[skillID + 1])
end
for i, modName in ipairs(cons.uniqueModifiers) do
-- The most important thing we're getting here is the modText and modBase
-- modText lets us check if this is a per-skill modifier or not
-- modBase lets us check .isSkill, which are modifiers that we only use for skills with Mastery
local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName)
if Shared.contains(modText, '{SV0}') then
isSkillMod[modName] = true
-- Check which skills the current modifier can be used for
for j, skillID in ipairs(cons.skills) do
if not modBase.isSkill or (modBase.isSkill and skillArray[j].hasMastery) then
addToArray(modArray, {modName, {skillID, modValue}})
end
end
else
addToArray(modArray, {modName, modValue})
end
end
end
if asKeyValue then
local modArrayKV = {}
for i, modDefn in ipairs(modArray) do
local modName, modVal = modDefn[1], modDefn[2]
local isSkill = isSkillMod[modName]
if modArrayKV[modName] == nil then
modArrayKV[modName] = (isSkill and { modVal } or modVal)
elseif isSkill then
table.insert(modArrayKV[modName], modVal)
else
modArrayKV[modName] = modArrayKV[modName] + modVal
end
end
return modArrayKV
else
return modArray
end
end
end


Line 702: Line 820:
result = result..'\r\n|data-sort-value="'..name..'"|'..Icons.Icon({name, type='constellation', size='50', notext=true})..'||'..name
result = result..'\r\n|data-sort-value="'..name..'"|'..Icons.Icon({name, type='constellation', size='50', notext=true})..'||'..name
result = result..'||'..cons.level..'||'..cons.provides.xp
result = result..'||'..cons.level..'||'..cons.provides.xp
local standMods = {}
local skillArray = {}
local skillIconArray = {}
local skillIconArray = {}
for j, skillID in pairs(cons.skills) do
for j, skillID in ipairs(cons.skills) do
local skill = SkillData.Skills[skillID + 1]
table.insert(skillIconArray, Icons.Icon({Constants.getSkillName(skillID), type='skill'}))
table.insert(skillArray, skill)
table.insert(skillIconArray, Icons.Icon({skill.name, type='skill'}))
--Building the list of Standard modifiers:
for k, modName in pairs(cons.standardModifiers[j]) do
table.insert(standMods, Constants._getModifierText(modName, {skillID, maxModifier}, false))
end
end
end
result = result..'||'..table.concat(skillIconArray, '<br/>')
result = result..'||'..table.concat(skillIconArray, '<br/>')
local standModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, true, false, false, false)
local standMods = {}
--Building the list of Standard modifiers:
for j, modifier in ipairs(standModsRaw) do
table.insert(standMods, Constants._getModifierText(modifier[1], modifier[2], false))
end
result = result..'|| '..table.concat(standMods, '<br/>')
result = result..'|| '..table.concat(standMods, '<br/>')
--Building the list of all Unique Modifiers
--Building the list of all Unique Modifiers
local uModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, false, true, false, false)
local uMods = {}
local uMods = {}
for j, modName in pairs(cons.uniqueModifiers) do
for j, modifier in ipairs(uModsRaw) do
--The most important thing we're getting here is the modText and modBase
table.insert(uMods, Constants._getModifierText(modifier[1], modifier[2], false))
--modText lets us check if this is a per-skill modifier or not
--modBase lets us check .isSkill, which are modifiers that we only use for skills with Mastery
local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName)
if Shared.contains(modText, '{SV0}') then
for k, skill in pairs(skillArray) do
local skillID = cons.skills[k]
local useMod = true
if modBase.isSkill then
useMod = skill.hasMastery
end
if useMod then
table.insert(uMods, Constants._getModifierText(modName, {skillID, maxModifier}, false))
end
end
else
table.insert(uMods, Constants._getModifierText(modName, maxModifier, false))
end
end
end
result = result..'||'..table.concat(uMods, '<br/>')
result = result..'||'..table.concat(uMods, '<br/>')