Module:Mazunki/Monsters

Revision as of 02:07, 31 January 2022 by Mazunki (talk | contribs) (bosses are weird)

Documentation for this module may be created at Module:Mazunki/Monsters/doc

--local Shared = require('Module:Shared')
local MonsterData = mw.loadData('Module:Monsters/data')
local Monsters = require('Module:Monsters')
local Items = require('Module:Items')
local Constants = require('Module:Constants')
-- local SourceTables = require('Module:Monsters/SourceTables')
-- local UseTables = require('Module:Monsters/UseTables')

local p = {}

function p.getRawTable(frame)
	local result = '{|\r\n'
	local rows = {}
	local headers = {
		'ID',
		'Name',
		'CombatLevel',
		'Hitpoints',
		'Interval',
		'NormalMaxHit',
		'NormalType',
		'HasSpecial',
		'SpecialAttacksNames',
		'SpecialAttacksChance',
		'Accuracy',
		'MeleeEvasion',
		'RangedEvasion',
		'MagicEvasion',
		'GoldDropMin',
		'GoldDropMax',
		'BoneType',
		'BonePrayerValue',
		'BonesObtainable',
		'Fragments',
		'FragmentsAmount',
		'Location',
		'SlayerTier', 'SlayerTierName', 'SlayerTierCost',
		'SlayerTierPlayerLevel', 'SlayerTierQtyMin', 'SlayerTierQtyMax', 'SlayerCoinReward',
		'ItemsID', 'ItemsWeight', 'ItemsDenominators', 'ItemsTotalWeight', 'ItemsQtyMin', 'ItemsQtyMax'
	}
	result = result.."!"..table.concat(headers, "!!")

	local monsterID = 0
	local monster = Monsters.getMonsterByID(monsterID)
	while monster ~= nil and monsterID < 2000 do -- as of writing this, there are [0..163] monsters
		local rowTxt = {}
		table.insert(rowTxt, '|-\r\n')
	
		table.insert(rowTxt, monsterID)
		table.insert(rowTxt, monster.name)
		local combatLevel = Monsters._getMonsterCombatLevel(monster)
		table.insert(rowTxt, combatLevel)

		local hitpoints = Monsters._getMonsterHP(monster)
		
		table.insert(rowTxt, hitpoints)
		table.insert(rowTxt, Monsters._getMonsterAttackSpeed(monster))
		table.insert(rowTxt, Monsters._getMonsterMaxHit(monster))
		table.insert(rowTxt, monster.attackType)
		local hasSpecialAttack = false
		local spAtks = {}
		local spAtksChance = {}
		for _, spAtk in pairs(monster.specialAttacks or {}) do
			hasSpecialAttack = true
			table.insert(spAtks, spAtk.name)
			table.insert(spAtksChance, spAtk.defaultChance/100)
		end
		table.insert(rowTxt, tostring(hasSpecialAttack))
		table.insert(rowTxt, table.concat(spAtks, ";"))
		table.insert(rowTxt, table.concat(spAtksChance, ";"))
		
		table.insert(rowTxt, Monsters._getMonsterAR(monster))
		table.insert(rowTxt, Monsters._getMonsterER(monster, 'Melee'))
		table.insert(rowTxt, Monsters._getMonsterER(monster, 'Ranged'))
		table.insert(rowTxt, Monsters._getMonsterER(monster, 'Magic'))
		table.insert(rowTxt, monster.dropCoins[1])
		table.insert(rowTxt, monster.dropCoins[2])
		
		local bones = Items.getItemByID(monster.bones) 
		if bones ~= nil and bones.prayerPoints then
			table.insert(rowTxt, bones.name)
			table.insert(rowTxt, bones.prayerPoints)
			table.insert(rowTxt, tostring(not(monster.isBoss)))
			
			table.insert(rowTxt, "")
			table.insert(rowTxt, tostring(0))
		elseif bones ~= nil and monster.boneQty then
			table.insert(rowTxt, "")
			table.insert(rowTxt, tostring(0))
			table.insert(rowTxt, tostring(false))
			
			table.insert(rowTxt, bones.name) -- actually a fragment, not bone
			table.insert(rowTxt, monster.boneQty) -- actually a fragment
		else
			table.insert(rowTxt, "")
			table.insert(rowTxt, tostring(0))
			table.insert(rowTxt, tostring(false))

			table.insert(rowTxt, "")
			table.insert(rowTxt, tostring(0))
		end

		table.insert(rowTxt, Monsters._getMonsterAreas(monster, false)) --args[2] is excludeDungeons

		local slayer = nil
		if monster.canSlayer then
			slayer = Constants.getSlayerTierByLevel(combatLevel)
			slayer.reward = math.floor(hitpoints/10)
		else
			slayer = {
				["display"] = "None",
				["reward"] = 0
			}
			rowTxt = rowTxt
		end
		
		table.insert(rowTxt, slayer.id)
		table.insert(rowTxt, slayer.display)
		table.insert(rowTxt, slayer.cost)
		table.insert(rowTxt, slayer.slayerLevel)
		table.insert(rowTxt, slayer.minQuantity)
		table.insert(rowTxt, slayer.maxQuantity)
		table.insert(rowTxt, slayer.reward)

		local itemIds = {}
		local itemWeights = {}
		local itemDenominators = {}
		local itemQtyMins = {}
		local itemQtyMaxs = {}
		local totalWeight = 0
		for _, droppable in pairs(monster.lootTable) do
			totalWeight = totalWeight + droppable[2]
		end

		for _, droppable in pairs(monster.lootTable) do
			table.insert(itemIds, droppable[1])
			table.insert(itemWeights, droppable[2]*monster.lootChance)
			table.insert(itemDenominators, totalWeight*100)
			table.insert(itemQtyMins, 1)
			table.insert(itemQtyMaxs, droppable[3])
		end
		table.insert(rowTxt, table.concat(itemIds, ";"))
		table.insert(rowTxt, table.concat(itemWeights, ";"))
		table.insert(rowTxt, table.concat(itemDenominators, ";"))
		table.insert(rowTxt, totalWeight)
		table.insert(rowTxt, table.concat(itemQtyMins, ";"))
		table.insert(rowTxt, table.concat(itemQtyMaxs, ";"))

		table.insert(rows, table.concat(rowTxt, '||'))
		monsterID = monsterID + 1
		monster = Monsters.getMonsterByID(monsterID)
	end
	
	result = result..'\r\n'..table.concat(rows, '\r\n')..'\r\n|}'
	return result
end



function p.getDRValueForMonsterIdForHP(frame)
	local monsterid = frame.args[1]
	local hp = frame.args[2]
	local autoeatlvl = frame.args[3] or 3

	return 100
end

return p