Anonymous

Module:CombatAreas: Difference between revisions

From Melvor Idle
_getAreaRequirements: Support requirement types ItemFound, CartographyPOIDiscovery
(Use printError function)
(_getAreaRequirements: Support requirement types ItemFound, CartographyPOIDiscovery)
Line 10: Line 10:


local areaMap = {
local areaMap = {
    ["combat"] = 'combatAreas',
["combat"] = 'combatAreas',
    ["dungeon"] = 'dungeons',
["dungeon"] = 'dungeons',
    ["slayer"] = 'slayerAreas'
["slayer"] = 'slayerAreas'
}
}


function p.getArea(name)
function p.getArea(name)
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
    for k, areaType in pairs(areaMap) do
for k, areaType in pairs(areaMap) do
        local area = GameData.getEntityByName(areaType, name)
local area = GameData.getEntityByName(areaType, name)
        if area ~= nil then
if area ~= nil then
            return area
return area
        end
end
    end
end
end
end


function p.getAreaByID(id, type)
function p.getAreaByID(id, type)
    local areaType = areaMap[type]
local areaType = areaMap[type]
    if areaType ~= nil then
if areaType ~= nil then
        return GameData.getEntityByID(areaType, id)
return GameData.getEntityByID(areaType, id)
    end
end
end
end


function p.getAreaFilterType(name, type)
function p.getAreaFilterType(name, type)
    local areaType = areaMap[type]
local areaType = areaMap[type]
    if areaType ~= nil then
if areaType ~= nil then
        return GameData.getEntityByName(areaType, name)
return GameData.getEntityByName(areaType, name)
    end
end
end
end


Line 42: Line 42:
local resultArray = nil
local resultArray = nil


    for i, areaType in pairs(areaMap) do
for i, areaType in pairs(areaMap) do
        local areas = GameData.getEntities(areaType, checkFunc)
local areas = GameData.getEntities(areaType, checkFunc)
        if resultArray == nil then
if resultArray == nil then
            resultArray = areas
resultArray = areas
        else
else
            for k, area in ipairs(areas) do
for k, area in ipairs(areas) do
                table.insert(resultArray, area)
table.insert(resultArray, area)
            end
end
        end
end
    end
end
    if resultArray == nil then
if resultArray == nil then
        resultArray = {}
resultArray = {}
    end
end


    return resultArray
return resultArray
end
end


Line 75: Line 75:
for i, reqDetails in ipairs(requirements) do
for i, reqDetails in ipairs(requirements) do
if reqDetails.type == 'SkillLevel' then
if reqDetails.type == 'SkillLevel' then
                local skillName = Constants.getSkillName(reqDetails.skillID)
local skillName = Constants.getSkillName(reqDetails.skillID)
                if skillName ~= nil then
if skillName ~= nil then
                    table.insert(reqArray, Icons._SkillReq(skillName, reqDetails.level))
table.insert(reqArray, Icons._SkillReq(skillName, reqDetails.level))
                end
end
elseif reqDetails.type == 'SlayerItem' then
elseif reqDetails.type == 'SlayerItem' then
local item = Items.getItemByID(reqDetails.itemID)
local item = Items.getItemByID(reqDetails.itemID)
table.insert(reqArray, Icons.Icon({item.name, type='item'}) .. ' Equipped')
table.insert(reqArray, Icons.Icon({item.name, type='item'}) .. ' Equipped')
elseif reqDetails.type == 'DungeonCompletion' then
elseif reqDetails.type == 'DungeonCompletion' then
                local dung = p.getAreaByID(reqDetails.dungeonID, 'dungeon')
local dung = p.getAreaByID(reqDetails.dungeonID, 'dungeon')
                if dung ~= nil then
if dung ~= nil then
                    if reqDetails.count > 1 then
if reqDetails.count > 1 then
                        table.insert(reqArray, Shared.formatnum(reqDetails.count) .. 'x ' .. Icons.Icon({dung.name, type='dungeon'}) .. ' Completions')
table.insert(reqArray, Shared.formatnum(reqDetails.count) .. 'x ' .. Icons.Icon({dung.name, type='dungeon'}) .. ' Completions')
                    else
else
                        table.insert(reqArray, Icons.Icon({dung.name, type='dungeon'}) .. ' Completed')
table.insert(reqArray, Icons.Icon({dung.name, type='dungeon'}) .. ' Completed')
                    end
end
                end
end
elseif reqDetails.type == 'ShopPurchase' then
elseif reqDetails.type == 'ShopPurchase' then
                local shopPurchase = GameData.getEntityByID('shopPurchases', reqDetails.purchaseID)
local shopPurchase = GameData.getEntityByID('shopPurchases', reqDetails.purchaseID)
if shopPurchase ~= nil then
if shopPurchase ~= nil then
table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased')
table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased')
end
elseif reqDetails.type == 'ItemFound' then
local item = Items.getItemByID(reqDetails.itemID)
table.insert(reqArray, 'Find ' .. Icons.Icon({item.name, type='item'}))
elseif reqDetails.type == 'CartographyPOIDiscovery' then
-- TODO Amend when Cartography module with helper functions exists
local map = GameData.getEntityByID(GameData.skillData.Cartography.worldMaps, reqDetails.worldMapID)
if map ~= nil then
local poiPart = {}
for j, poiID in ipairs(reqDetails.poiIDs) do
local poi = GameData.getEntityByID(map.pointsOfInterest, poiID)
if poi ~= nil then
table.insert(poiPart, Icons.Icon({poi.name, type='poi'}))
else
table.insert(poiPart, Shared.printError('Could not find POI with ID ' .. poiID))
end
end
table.insert(reqArray, 'Discover ' .. table.concat(poiPart, ', '))
end
end
else
else
Line 109: Line 127:
-- Avoid repeating the same requirements twice, can happen for some dungeons e.g. Impending Darkness
-- Avoid repeating the same requirements twice, can happen for some dungeons e.g. Impending Darkness
if area.entryRequirements == nil or mw.dumpObject(area.unlockRequirement) ~= mw.dumpObject(area.entryRequirements) then
if area.entryRequirements == nil or mw.dumpObject(area.unlockRequirement) ~= mw.dumpObject(area.entryRequirements) then
        addReqsToArray(resultArray, area.unlockRequirement)
addReqsToArray(resultArray, area.unlockRequirement)
        end
end
end
end