Module:Skills/Gathering: Difference between revisions

Move functions to Module:Skills; Move Farming functions from Module:Skills
(Use Thieving drop chances from game data instead of hard-coded values)
(Move functions to Module:Skills; Move Farming functions from Module:Skills)
Line 9: Line 9:
local Items = require('Module:Items')
local Items = require('Module:Items')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
 
local Skills = require('Module:Skills')
function p.getConstellationByID(constID)
local ItemSourceTables = require('Module:Items/SourceTables')
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 357: Line 336:
result = result..'\r\n|}'
result = result..'\r\n|}'
return result
return result
end
function p.getThievingNPC(npcName)
local result = nil
for i, npc in Shared.skpairs(SkillData.Thieving.NPCs) do
if npc.name == npcName then
result = Shared.clone(npc)
break
end
end
return result
end
function p.getThievingNPCArea(npc)
if type(npc) == 'string' then
npc = p.getThievingNPC(npc)
end
local result = nil
for i, area in Shared.skpairs(SkillData.Thieving.Areas) do
for j, npcID in pairs(area.npcs) do
if npcID == npc.id then
result = area
break
end
end
end
return result
end
function p._getThievingNPCStat(npc, statName)
local result = nil
if statName == 'level' then
result = Icons._SkillReq('Thieving', npc.level)
elseif statName == 'maxHit' then
result = npc.maxHit * 10
elseif statName == 'area' then
local area = p.getThievingNPCArea(npc)
result = area.name
else
result = npc[statName]
end
if result == nil then
result = ''
end
return result
end
function p.getThievingNPCStat(frame)
local npcName = frame.args ~= nil and frame.args[1] or frame[1]
local statName = frame.args ~= nil and frame.args[2] or frame[2]
local npc = p.getThievingNPC(npcName)
if npc == nil then
return "ERROR: Invalid Thieving NPC "..npcName.."[[Category:Pages with script errors]]"
end
return p._getThievingNPCStat(npc, statName)
end
end


Line 530: Line 449:
areaTxt = areaTxt..'The chance of receiving an Area Unique drop is tripled if the 95% Thieving Mastery Pool checkpoint is active.'
areaTxt = areaTxt..'The chance of receiving an Area Unique drop is tripled if the 95% Thieving Mastery Pool checkpoint is active.'


local area = p.getThievingNPCArea(npc)
local area = Skills.getThievingNPCArea(npc)
areaTxt = areaTxt..'\r\n{|class="wikitable sortable"'
areaTxt = areaTxt..'\r\n{|class="wikitable sortable"'
areaTxt = areaTxt..'\r\n!Item!!Qty'
areaTxt = areaTxt..'\r\n!Item!!Qty'
Line 574: Line 493:
function p.getThievingNPCLootTables(frame)
function p.getThievingNPCLootTables(frame)
local npcName = frame.args ~= nil and frame.args[1] or frame
local npcName = frame.args ~= nil and frame.args[1] or frame
local npc = p.getThievingNPC(npcName)
local npc = Skills.getThievingNPC(npcName)
if npc == nil then
if npc == nil then
return "ERROR: Invalid Thieving NPC "..npcName.."[[Category:Pages with script errors]]"
return "ERROR: Invalid Thieving NPC "..npcName.."[[Category:Pages with script errors]]"
Line 593: Line 512:
result = result..'||'..Icons.Icon({npc.name, type='thieving', noicon=true})
result = result..'||'..Icons.Icon({npc.name, type='thieving', noicon=true})


local area = p.getThievingNPCArea(npc)
local area = Skills.getThievingNPCArea(npc)
result = result..'||'..area.name
result = result..'||'..area.name
result = result..'||'..Icons._SkillReq('Thieving', npc.level)
result = result..'||'..Icons._SkillReq('Thieving', npc.level)
Line 671: Line 590:
end
end


function p.getThievingSourcesForItem(itemID)
function p._getFarmingTable(category)
local resultArray = {}
local seedList = {}
if category == 'Allotment' or category == 'Herb' or category == 'Tree' then
seedList = Items.getItems(function(item) return item.tier == category end)
else
return 'ERROR: Invalid farming category. Please choose Allotment, Herb, or Tree'
end


local areaNPCs = {}
local result = '{|class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan=2|Seeds!!'..Icons.Icon({'Farming', type='skill', notext=true})..' Level'
result = result..'!!XP!!Growth Time!!Seed Value'
if category == 'Allotment' then
result = result..'!!colspan="2"|Crop!!Crop Healing!!Crop Value'
elseif category == 'Herb' then
result = result..'!!colspan="2"|Herb!!Herb Value'
elseif category == 'Tree' then
result = result..'!!colspan="2"|Logs!!Log Value'
end
result = result..'!!Seed Sources'


--First check area unique drops
table.sort(seedList, function(a, b) return a.farmingLevel < b.farmingLevel end)
--If an area drops the item, add all the NPC ids to the list so we can add them later
 
if not result then
for i, seed in pairs(seedList) do
for i, area in pairs(SkillData.Thieving.Areas) do
result = result..'\r\n|-'
for j, drop in pairs(area.uniqueDrops) do
result = result..'\r\n|'..Icons.Icon({seed.name, type='item', size='50', notext=true})..'||[['..seed.name..']]'
if drop.itemID == itemID then
result = result..'||'..seed.farmingLevel..'||'..Shared.formatnum(seed.farmingXP)
for k, npcID in pairs(area.npcs) do
result = result..'||data-sort-value="'..seed.timeToGrow..'"|'..Shared.timeString(seed.timeToGrow, true)
areaNPCs[npcID] = drop.qty
result = result..'||data-sort-value="'..seed.sellsFor..'"|'..Icons.GP(seed.sellsFor)
end
 
break
local crop = Items.getItemByID(seed.grownItemID)
end
result = result..'||'..Icons.Icon({crop.name, type='item', size='50', notext=true})..'||[['..crop.name..']]'
end
if category == 'Allotment' then
result = result..'||'..Icons.Icon({'Hitpoints', type='skill', notext=true})..' '..(crop.healsFor * 10)
end
end
result = result..'||data-sort-value="'..crop.sellsFor..'"|'..Icons.GP(crop.sellsFor)
result = result..'||'..ItemSourceTables._getItemSources(seed)
end
end


--Now go through and get drop chances on each NPC if needed
result = result..'\r\n|}'
for i, npc in pairs(SkillData.Thieving.NPCs) do
return result
local totalWt = 0
end
local dropWt = 0
 
local dropQty = 0
function p.getFarmingTable(frame)
for j, drop in pairs(npc.lootTable) do
local category = frame.args ~= nil and frame.args[1] or frame
totalWt = totalWt + drop[2]
 
if drop[1] == itemID then
return p._getFarmingTable(category)
dropWt = drop[2]
end
dropQty = drop[3]
 
end
function p.getFarmingFoodTable(frame)
end
local result = '{| class="wikitable sortable stickyHeader"'
if dropWt > 0 then
result = result..'\r\n|- class="headerRow-0"'
table.insert(resultArray, {npc = npc.name, minQty = 1, maxQty = dropQty, wt = dropWt * SkillData.Thieving.ItemChance, totalWt = totalWt * 100, level = npc.level})
result = result..'\r\n!colspan="2"|Crop!!'..Icons.Icon({"Farming", type="skill", notext=true})..' Level'
end
result = result..'!!Healing!!Value'
 
local itemArray = Items.getItems(function(item) return item.grownItemID ~= nil end)


--Chance of -1 on unique drops is to indicate variable chance
table.sort(itemArray, function(a, b) return a.farmingLevel < b.farmingLevel end)
if npc.uniqueDrop ~= nil and npc.uniqueDrop.itemID == itemID then
table.insert(resultArray, {npc = npc.name, minQty = npc.uniqueDrop.qty, maxQty = npc.uniqueDrop.qty, wt = -1, totalWt = -1, level = npc.level})
end


if areaNPCs[npc.id] ~= nil then
for i, item in Shared.skpairs(itemArray) do
table.insert(resultArray, {npc = npc.name, minQty = areaNPCs[npc.id], maxQty = areaNPCs[npc.id], wt = SkillData.Thieving.AreaUniqueChance, totalWt = 100, level = npc.level})
local crop = Items.getItemByID(item.grownItemID)
if crop.healsFor ~= nil and crop.healsFor > 0 then
result = result..'\r\n|-'
result = result..'\r\n|'..Icons.Icon({crop.name, type='item', notext='true', size='50'})..'||[['..crop.name..']]'
result = result..'||style="text-align:right;"|'..item.farmingLevel
result = result..'||style="text-align:right" data-sort-value="'..crop.healsFor..'"|'..Icons.Icon({"Hitpoints", type="skill", notext=true})..' '..(crop.healsFor * 10)
result = result..'||style="text-align:right" data-sort-value="'..crop.sellsFor..'"|'..Icons.GP(crop.sellsFor)
end
end
end
end


for i, drop in pairs(SkillData.Thieving.RareItems) do
result = result..'\r\n|}'
if drop.itemID == itemID then
table.insert(resultArray, {npc = 'all', minQty = 1, maxQty = 1, wt = 1, totalWt = Shared.round2(1/(drop.chance/100), 0), level = 1})
end
end


return resultArray
return result
end
end


-- For a given constellation cons and modifier value modValue, generates and returns
function p.getFarmingPlotTable(frame)
-- a table of modifiers, much like any other item/object elsewhere in the game.
local areaName = frame.args ~= nil and frame.args[1] or frame
-- includeStandard: true|false, determines whether standard modifiers are included
local patches = nil
-- includeUnique: true|false, determines whether unique modifiers are included
for i, area in Shared.skpairs(SkillData.Farming.Patches) do
-- isDistinct: true|false, if true, the returned list of modifiers is de-duplicated
if area.areaName == areaName then
-- asKeyValue: true|false, if true, returns key/value pairs like usual modifier objects
patches = area.patches
function p._buildAstrologyModifierArray(cons, modValue, includeStandard, includeUnique, isDistinct, asKeyValue)
break
-- 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
end
local addToArray = function(modArray, modNew)
if not isDistinct or (isDistinct and not containsMod(modArray, modNew)) then
table.insert(modArray, modNew)
end
end
local modTypes = {}
if includeStandard then
table.insert(modTypes, 'standardModifiers')
end
end
if includeUnique then
if patches == nil then
table.insert(modTypes, 'uniqueModifiers')
return "ERROR: Invalid area name.[[Category:Pages with script errors]]"
end
end


local modArray = {}
local result = '{|class="wikitable"'
local isSkillMod = {}
result = result..'\r\n!Plot!!'..Icons.Icon({'Farming', type='skill', notext=true})..' Level!!Cost'
for _, modType in ipairs(modTypes) do
 
for i, skillMods in ipairs(cons[modType]) do
for i, patch in Shared.skpairs(patches) do
local skillID = cons.skills[i]
result = result..'\r\n|-\r\n|'..i
if skillID ~= nil then
result = result..'||style="text-align:right;" data-sort-value="' .. patch.level .. '"|'..patch.level
for j, modName in ipairs(skillMods) do
if patch.cost == 0 then
local modBaseName, modText, sign, isNegative, unsign, modBase = Constants.getModifierDetails(modName)
result = result..'||Free'
-- Check if modifier varies by skill, and amend the modifier value accordingly
else
local modVal = modValue
result = result..'||style="text-align:right;" data-sort-value="'..patch.cost..'"|'..Icons.GP(patch.cost)
if Shared.contains(modText, '{SV0}') then
isSkillMod[modName] = true
modVal = {skillID, modValue}
end
addToArray(modArray, {modName, modVal})
end
end
end
end
end
end


if asKeyValue then
result = result..'\r\n|}'
local modArrayKV = {}
return result
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 822: Line 714:
result = result..'||'..table.concat(skillIconArray, '<br/>')
result = result..'||'..table.concat(skillIconArray, '<br/>')


local standModsRaw = p._buildAstrologyModifierArray(cons, maxModifier, true, false, false, false)
local standModsRaw = Skills._buildAstrologyModifierArray(cons, maxModifier, true, false, false, false)
local standMods = {}
local standMods = {}
--Building the list of Standard modifiers:
--Building the list of Standard modifiers:
Line 831: Line 723:


--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 uModsRaw = Skills._buildAstrologyModifierArray(cons, maxModifier, false, true, false, false)
local uMods = {}
local uMods = {}
for j, modifier in ipairs(uModsRaw) do
for j, modifier in ipairs(uModsRaw) do