12,787
edits
Falterfire (talk | contribs) (changing link reference on constellations) |
(_buildAstrologyModifierArray: Further fixes to key/value pair return value) |
||
(11 intermediate revisions by 2 users 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 549: | Line 572: | ||
local result = '{| class="wikitable sortable stickyHeader"' | local 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!!Area!!'..Icons.Icon({'Thieving', type='skill', notext=true})..' Level!!Experience!!Max Hit!!Perception!!Unique Drop' | result = result..'\r\n!colspan="2"|Name!!Area!!'..Icons.Icon({'Thieving', type='skill', notext=true})..' Level!!Experience!!Max Hit!!Perception!!GP!!Unique Drop' | ||
local npcArray = Shared.clone(SkillData.Thieving.NPCs) | local npcArray = Shared.clone(SkillData.Thieving.NPCs) | ||
table.sort(npcArray, function(a, b) return a.level < b.level end) | table.sort(npcArray, function(a, b) return a.level < b.level end) | ||
Line 563: | Line 586: | ||
result = result..'||style="text-align:right"|'..(npc.maxHit * 10) | result = result..'||style="text-align:right"|'..(npc.maxHit * 10) | ||
result = result..'||style="text-align:right"|'..npc.perception | result = result..'||style="text-align:right"|'..npc.perception | ||
result = result..'||data-sort-value="' .. npc.maxGP .. '"|'..Icons.GP(1, npc.maxGP) | |||
if npc.uniqueDrop ~= nil and npc.uniqueDrop.itemID > -1 then | if npc.uniqueDrop ~= nil and npc.uniqueDrop.itemID > -1 then | ||
local uniqueDrop = Items.getItemByID(npc.uniqueDrop.itemID) | local uniqueDrop = Items.getItemByID(npc.uniqueDrop.itemID) | ||
Line 642: | Line 666: | ||
--If an area drops the item, add all the NPC ids to the list so we can add them later | --If an area drops the item, add all the NPC ids to the list so we can add them later | ||
if not result then | if not result then | ||
for | for i, area in pairs(SkillData.Thieving.Areas) do | ||
for j, drop in pairs(area.uniqueDrops) do | for j, drop in pairs(area.uniqueDrops) do | ||
if drop.itemID == itemID then | if drop.itemID == itemID then | ||
Line 687: | 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 | ||
function p._buildAstrologyConstellationTable() | function p._buildAstrologyConstellationTable() | ||
local maxModifier = 5 | local maxModifier = 5 | ||
local result = '{|class="wikitable stickyHeader"' | local 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"|Constellation!!'..Icons.Icon({"Astrology", type='skill', notext='true'})..' Level' | result = result..'\r\n!colspan="2"|Constellation!!'..Icons.Icon({"Astrology", type='skill', notext='true'})..' Level' | ||
Line 701: | 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 skillIconArray = {} | local skillIconArray = {} | ||
for j, skillID in | for j, skillID in ipairs(cons.skills) do | ||
table.insert(skillIconArray, Icons.Icon({Constants.getSkillName(skillID), type='skill'})) | |||
table.insert(skillIconArray, Icons.Icon({ | |||
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, | for j, modifier in ipairs(uModsRaw) do | ||
table.insert(uMods, Constants._getModifierText(modifier[1], modifier[2], false)) | |||
end | end | ||
result = result..'||'..table.concat(uMods, '<br/>') | result = result..'||'..table.concat(uMods, '<br/>') | ||
end | end | ||
result = result..'\r\n|}' | |||
return result | return result | ||
Line 747: | Line 850: | ||
function p.buildAstrologyConstellationTable(frame) | function p.buildAstrologyConstellationTable(frame) | ||
return p._buildAstrologyConstellationTable() | return p._buildAstrologyConstellationTable() | ||
end | |||
function p.buildAstrologyValueTable() | |||
local result = '{|class="wikitable sortable"' | |||
result = result..'\r\n!rowspan="2"| Value!!colspan="2"| Chance' | |||
result = result..'\r\n|-\r\n! This Value!! This Value or Greater' | |||
local lastChance = 0 | |||
local cumulativeChance = 100 | |||
for i, chance in Shared.skpairs(SkillData.Astrology.Defaults.valueWeight) do | |||
local thisChance = (i == 5 and chance) or chance - lastChance | |||
result = result..'\r\n|-' | |||
result = result..'\r\n|style="text-align:right"| '..i | |||
result = result..'\r\n|style="text-align:right"| ' .. thisChance .. '%' | |||
result = result..'\r\n|style="text-align:right"| ' .. cumulativeChance .. '%' | |||
cumulativeChance = cumulativeChance - thisChance | |||
lastChance = chance | |||
end | |||
result = result..'\r\n|}' | |||
return result | |||
end | end | ||
return p | return p |