Module:CombatAreas: Difference between revisions

From Melvor Idle
(Added p.getMonsterAreas)
(getAreaPassives now works for dungeons and strongholds)
 
(39 intermediate revisions by 5 users not shown)
Line 1: Line 1:
--NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
local p = {}
local p = {}


local Constants = mw.loadData('Module:Constants/data')
local Constants = require('Module:Constants')
local AreaData = mw.loadData('Module:CombatAreas/data')
 
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Monsters = require('Module:Monsters')
 
local areaMap = {
["combat"] = 'combatAreas',
["dungeon"] = 'dungeons',
["slayer"] = 'slayerAreas',
["depth"] = 'abyssDepths',
["stronghold"] = 'strongholds'
}


function p.getArea(name)
function p.getArea(name)
  local result = nil
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
  mw.log(name)
for k, areaType in pairs(areaMap) do
  --There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
local area = GameData.getEntityByName(areaType, name)
  for i, area in pairs(AreaData.combatAreas) do
if area ~= nil then
    if area.areaName == name then
return area
      result = Shared.clone(area)
end
      result.id = i - 1
end
      return result
end
    end
 
  end
function p.getAreaByID(id, areaType)
for aType, areaKey in pairs(areaMap) do
if areaType == nil or areaType == aType then
local area = GameData.getEntityByID(areaKey, id)
if area ~= nil then
return area
end
end
end
end
 
function p.getAreaFilterType(name, type)
local areaType = areaMap[type]
if areaType ~= nil then
return GameData.getEntityByName(areaType, name)
end
end
 
function p.getAreas(checkFunc)
local resultArray = nil
 
for i, areaType in pairs(areaMap) do
local areas = GameData.getEntities(areaType, checkFunc)
if resultArray == nil then
resultArray = areas
else
for k, area in ipairs(areas) do
table.insert(resultArray, area)
end
end
end
if resultArray == nil then
resultArray = {}
end
 
return resultArray
end
 
--Returns the expansion icon for the area if it has one
function p.getExpansionIcon(frame)
local areaName = frame.args ~= nil and frame.args[1] or frame
local area = p.getArea(areaName)
if area == nil then
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end
return Icons.getExpansionIcon(area.id)
end
 
function p._getAreaRequirements(area)
local resultArray = {}
if area.entryRequirements ~= nil then
local reqText = Common.getRequirementString(area.entryRequirements)
if reqText ~= nil then
table.insert(resultArray, reqText)
end
end
 
if area.unlockRequirement ~= nil then
-- 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
local reqText = Common.getRequirementString(area.unlockRequirement)
if reqText ~= nil then
table.insert(resultArray, reqText)
end
end
end
 
return table.concat(resultArray, '<br/>')
end
 
function p.getAreaRequirementsForBox(frame)
--Returns infobox formatting for requirements, or returns nothing if there are none.
local areaName = frame.args ~= nil and frame.args[1] or frame
local area = p.getArea(areaName)
if area == nil then
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end


  for i, area in pairs(AreaData.slayerAreas) do
local reqs = p._getAreaRequirements(area)
    if area.areaName == name then
if reqs ~= '' then
      result = Shared.clone(area)
reqs = "|-\r\n|'''Requirements:'''\r\n"..reqs
      result.id = i - 1
end
      return result
return reqs
    end
end
  end


  for i, area in pairs(AreaData.dungeons) do
function p._getAreaStat(area, statName)
    if area.name == name then
if statName == 'requirements' then
      result = Shared.clone(area)
return p._getAreaRequirements(area)
      result.type = 'dungeon'
elseif statName == 'areaEffectDesc' then
      result.id = i - 1
if area.areaEffect ~= nil then
      return result
local descText, subIdx = string.gsub(area.areaEffectDescription, '${effectValue}', area.areaEffect.magnitude or 0)
    end
return descText
  end
else
return 'None'
end
elseif statName == 'difficulty' then
local result = Constants.getDifficultyString(area.difficulty[1])
if area.difficulty[2] ~= nil then
result = result..' - '..Constants.getDifficultyString(area.difficulty[2])
end
return result
end


  return nil
return area[statName]
end
end


function p.getMonsterAreas(monsterID)
function p.getAreaStat(frame)
  local areaArray = {}
local areaName = frame.args ~= nil and frame.args[1] or frame[1]
  --There are three types of areas but the lists are pretty short so looping all of them isn't a real issue
local statName = frame.args ~= nil and frame.args[2] or frame[2]
  for i, area in pairs(AreaData.combatAreas) do
local area = p.getArea(areaName)
    if Shared.contains(area.monsters, monsterID) then
if area == nil then
      result = Shared.clone(area)
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
      result.id = i - 1
end
      table.insert(areaArray, result)
    end
  end


  for i, area in pairs(AreaData.slayerAreas) do
return p._getAreaStat(area, statName)
    if Shared.contains(area.monsters, monsterID) then
end
      result = Shared.clone(area)
      result.id = i - 1
      table.insert(areaArray, result)
    end
  end


  for i, area in pairs(AreaData.dungeons) do
function p._isMonsterInArea(monster, area)
    if Shared.contains(area.monsters, monsterID) then
return (
      result = Shared.clone(area)
Shared.contains(area.monsterIDs, monster.id)
      result.type = 'dungeon'
-- Check for Lair of the Spider Queen random spiders
      result.id = i - 1
or (
      table.insert(areaArray, result)
Shared.contains(area.monsterIDs, 'melvorTotH:RandomSpiderLair')
    end
and Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
  end
)
  return areaArray
)
end
end


function p.getAreaMonsterTable(frame)
function p._getMonsterAreas(monster)
  local areaName = frame.args ~= nil and frame.args[1] or frame
-- Special handling for Lair of the Spider Queen, which has a random list of enemies
  local area = p.getArea(areaName)
local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
  if area == nil then
return p.getAreas(
    return "ERROR: Could not find an area named "..areaName
function(area)
  end
return p._isMonsterInArea(monster, area)
end)
end


  if area.type == 'dungeon' then
function p.getDungeonRequirements(frame)
    return p.getDungeonMonsterTable(frame)
local areaName = frame.args ~= nil and frame.args[1] or frame
  end
local area = p.getArea(areaName)
if area == nil then
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
end


  local tableTxt = '{| class="wikitable sortable"'
local result = p._getAreaStat(area, 'requirements')
  tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'
if result ~= '' then
  for i, monsterID in pairs(area.monsters) do
result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result
    local monster = Monsters.getMonsterByID(monsterID)
end
    tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})
return result
    tableTxt = tableTxt..'||'..Monsters.getMonsterCombatLevel(monster.name)
    tableTxt = tableTxt..'||'..Shared.formatnum(Monsters.getMonsterHP(monster.name))
    tableTxt = tableTxt..'||'..Shared.formatnum(Monsters.getMonsterMaxHit(monster.name))
    tableTxt = tableTxt..'||'..Monsters.getMonsterStyleIcon({monster.name, nolink='true'})
  end
  tableTxt = tableTxt..'\r\n|}'
  return tableTxt
end
end


function p.getDungeonMonsterTable(frame)
function p.getAreaPassives(frame)
  local areaName = frame.args ~= nil and frame.args[1] or frame
local areaName = frame.args ~= nil and frame.args[1] or frame
  local area = p.getArea(areaName)
local area = p.getArea(areaName)
  if area == nil then
if area == nil then
    return "ERROR: Could not find a dungeon named "..areaName
return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
  end
end
 
local bossPassives = nil
local nonBossPassives = nil
if area.eventID ~= nil and area.eventID ~= '' then -- currently just Impending Darkness Event
local event = GameData.getEntityByID('combatEvents', area.eventID)
bossPassives = event.bossPassives
-- nonBossPassives = event.enemyPassives -- melvorF:ControlledAffliction is missing from GameData
else
bossPassives = area.bossOnlyPassives -- Strongholds only
nonBossPassives = area.nonBossPassives -- Dungeons only
end
 
local result = ''
 
    if type(nonBossPassives) == 'table' and not Shared.tableIsEmpty(nonBossPassives) then
    result = result .. '\r\n===Non-Boss Monster Passives==='
for i, passiveID in ipairs(nonBossPassives) do
local passive = p.getPassiveByID(passiveID)
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
end
    end


  --For Dungeons, go through and count how many of each monster are in the dungeon first
    if type(bossPassives) == 'table' and not Shared.tableIsEmpty(bossPassives) then
  local monsterCounts = {}
    result = result .. '\r\n===Boss Monster Passives==='
  for i, monsterID in pairs(area.monsters) do
for i, passiveID in ipairs(bossPassives) do
    if monsterCounts[monsterID] == nil then
local passive = p.getPassiveByID(passiveID)
      monsterCounts[monsterID] = 1
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
    else
end
      monsterCounts[monsterID] = monsterCounts[monsterID] + 1
     end
     end
  end


  local usedMonsters = {}
if type(area.tiers) == 'table' and not Shared.tableIsEmpty(area.tiers) then
result = result .. '\r\n===Stronghold Tier Passives==='
for tierName, tierData in pairs(area.tiers) do
result = result .. '\r\n* ' .. tierName .. ' Tier'
for i, passiveID in ipairs(tierData.passives) do
local passive = p.getPassiveByID(passiveID)
result = result .. '\r\n** ' .. passive.name .. '\r\n*** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
end
end
end
 
return result
end


  local tableTxt = '{| class="wikitable sortable"'
function p.getPassiveByID(ID)
  tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count'
     return GameData.getEntityByID('combatPassives', ID)
  for i, monsterID in pairs(area.monsters) do
     if not Shared.contains(usedMonsters, monsterID) then
      local monster = Monsters.getMonsterByID(monsterID)
      local name = monster.name
      if monsterID == 51 then name = 'Spider2' end
      tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({name, type='monster'})
      tableTxt = tableTxt..'||'..Monsters.getMonsterCombatLevel(name)
      tableTxt = tableTxt..'||'..Shared.formatnum(Monsters.getMonsterHP(name))
      tableTxt = tableTxt..'||'..Shared.formatnum(Monsters.getMonsterMaxHit(name))
      tableTxt = tableTxt..'||'..Monsters.getMonsterStyleIcon({name, nolink='true'})
      tableTxt = tableTxt..'||'..monsterCounts[monsterID]
      table.insert(usedMonsters, monsterID)
    end
  end
  tableTxt = tableTxt..'\r\n|}'
  return tableTxt
end
end


return p
return p

Latest revision as of 00:35, 2 November 2024

Data is pulled from Module:GameData/data

NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters


--NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters
local p = {}

local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Common = require('Module:Common')
local Icons = require('Module:Icons')

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

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
	for k, areaType in pairs(areaMap) do
		local area = GameData.getEntityByName(areaType, name)
		if area ~= nil then
			return area
		end
	end
end

function p.getAreaByID(id, areaType)
	for aType, areaKey in pairs(areaMap) do
		if areaType == nil or areaType == aType then
			local area = GameData.getEntityByID(areaKey, id)
			if area ~= nil then
				return area
			end
		end
	end
end

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

function p.getAreas(checkFunc)
	local resultArray = nil

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

	return resultArray
end

--Returns the expansion icon for the area if it has one
function p.getExpansionIcon(frame)
	local areaName = frame.args ~= nil and frame.args[1] or frame
	local area = p.getArea(areaName)
	if area == nil then
		return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
	end
	
	return Icons.getExpansionIcon(area.id)
end

function p._getAreaRequirements(area)
	local resultArray = {}
	if area.entryRequirements ~= nil then
		local reqText = Common.getRequirementString(area.entryRequirements)
		if reqText ~= nil then
			table.insert(resultArray, reqText)
		end
	end

	if area.unlockRequirement ~= nil then
		-- 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
			local reqText = Common.getRequirementString(area.unlockRequirement)
			if reqText ~= nil then
				table.insert(resultArray, reqText)
			end
		end
	end

	return table.concat(resultArray, '<br/>')
end

function p.getAreaRequirementsForBox(frame)
	--Returns infobox formatting for requirements, or returns nothing if there are none.
	local areaName = frame.args ~= nil and frame.args[1] or frame
	local area = p.getArea(areaName)
	if area == nil then
		return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
	end

	local reqs = p._getAreaRequirements(area)
	if reqs ~= '' then
		reqs = "|-\r\n|'''Requirements:'''\r\n"..reqs
	end
	return reqs
end

function p._getAreaStat(area, statName)
	if statName == 'requirements' then
		return p._getAreaRequirements(area)
	elseif statName == 'areaEffectDesc' then
		if area.areaEffect ~= nil then
			local descText, subIdx = string.gsub(area.areaEffectDescription, '${effectValue}', area.areaEffect.magnitude or 0)
			return descText
		else
			return 'None'
		end
	elseif statName == 'difficulty' then
		local result = Constants.getDifficultyString(area.difficulty[1])
		if area.difficulty[2] ~= nil then
			result = result..' - '..Constants.getDifficultyString(area.difficulty[2])
		end
		return result
	end

	return area[statName]
end

function p.getAreaStat(frame)
	local areaName = frame.args ~= nil and frame.args[1] or frame[1]
	local statName = frame.args ~= nil and frame.args[2] or frame[2]
	local area = p.getArea(areaName)
	if area == nil then
		return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
	end

	return p._getAreaStat(area, statName)
end

function p._isMonsterInArea(monster, area)
	return (
		Shared.contains(area.monsterIDs, monster.id)
		-- Check for Lair of the Spider Queen random spiders
		or (
			Shared.contains(area.monsterIDs, 'melvorTotH:RandomSpiderLair')
			and Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
		)
	)
end

function p._getMonsterAreas(monster)
	-- Special handling for Lair of the Spider Queen, which has a random list of enemies
	local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
	return p.getAreas(
		function(area)
			return p._isMonsterInArea(monster, area)
		end)
end

function p.getDungeonRequirements(frame)
	local areaName = frame.args ~= nil and frame.args[1] or frame
	local area = p.getArea(areaName)
	if area == nil then
		return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
	end

	local result = p._getAreaStat(area, 'requirements')
	if result ~= '' then
		result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result
	end
	return result
end

function p.getAreaPassives(frame)
	local areaName = frame.args ~= nil and frame.args[1] or frame
	local area = p.getArea(areaName)
	if area == nil then
		return Shared.printError('No area named "' .. areaName .. '" exists in the data module')
	end

	local bossPassives = nil
	local nonBossPassives = nil
	if area.eventID ~= nil and area.eventID ~= '' then -- currently just Impending Darkness Event
		local event = GameData.getEntityByID('combatEvents', area.eventID)
		bossPassives = event.bossPassives
		-- nonBossPassives = event.enemyPassives -- melvorF:ControlledAffliction is missing from GameData
	else
		bossPassives = area.bossOnlyPassives -- Strongholds only
		nonBossPassives = area.nonBossPassives -- Dungeons only
	end

	local result = ''

    if type(nonBossPassives) == 'table' and not Shared.tableIsEmpty(nonBossPassives) then
    	result = result .. '\r\n===Non-Boss Monster Passives==='
		for i, passiveID in ipairs(nonBossPassives) do
			local passive = p.getPassiveByID(passiveID)
			result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
		end
    end

    if type(bossPassives) == 'table' and not Shared.tableIsEmpty(bossPassives) then
    	result = result .. '\r\n===Boss Monster Passives==='
		for i, passiveID in ipairs(bossPassives) do
			local passive = p.getPassiveByID(passiveID)
			result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
		end
    end

	if type(area.tiers) == 'table' and not Shared.tableIsEmpty(area.tiers) then
		result = result .. '\r\n===Stronghold Tier Passives==='
		for tierName, tierData in pairs(area.tiers) do
			result = result .. '\r\n* ' .. tierName .. ' Tier'
			for i, passiveID in ipairs(tierData.passives) do
				local passive = p.getPassiveByID(passiveID)
				result = result .. '\r\n** ' .. passive.name .. '\r\n*** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
			end
		end
	end

	return result
end

function p.getPassiveByID(ID)
    return GameData.getEntityByID('combatPassives', ID)
end

return p