Module:Mazunki/Monsters: Difference between revisions

From Melvor Idle
m (rename function)
m (let's hope)
Line 1: Line 1:


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


local p = {}
local p = {}


function p.getRawTable(frame)
function p.getRawTable(frame)
--Generates a plaintext table for Mazunki's use for spreadsheet generation
local result = '{|\r\n'
local result = '{|'
result = result..'\r\n!ID!!Name!!Price!!Combat Obtainable!!Monster Drop Chances'
local rows = {}
local rows = {}
 
local itemList = Items.getItems(function(item) return true end)
local monsterList = Monsters.getMonsters(function(item) return true end)
table.sort(itemList, function(a, b) return a.id < b.id end)
table.sort(monsterList, function(a, b) return a.id < b.id end)
 
local monsterSourceColumns = { 'id', 'dropWt', 'totalWt', 'minQty', 'maxQty' }
local monsterID = 0
local monster = Monsters.getMonsterByID(monsterID)
local itemID = 0
while monster ~= nil and monsterID < 2000 do -- as of writing this, there are [0..163] monsters
local item = Items.getItemByID(itemID)
while item ~= nil and itemID < 2000 do
local rowTxt = '|-\r\n'
local rowTxt = '|-\r\n'
rowTxt = rowTxt..'|'..item.id..'||'..item.name..'||'..item.sellsFor
 
local monsterData = SourceTables._getItemMonsterSources(item)
result = result..result..'!!ID'
if(Shared.tableCount(monsterData) > 0) then
rowTxt = rowTxt..'|'..monsterID
local monsterColData = {}
 
for i, colName in pairs(monsterSourceColumns) do
result = result..'!!Name'
monsterColData[colName] = {}
rowTxt = rowTxt..'|'..monster.name
end
 
result = result..'!!CombatLevel'
rowTxt = rowTxt..'||true||'
local combatlevel = Monsters._getMonsterCombatLevel(monster) -- used for slayer
for j, mData in pairs(monsterData) do
rowTxt = rowTxt..'|'..combatlevel
for k, colName in pairs(monsterSourceColumns) do
 
table.insert(monsterColData[colName], mData[colName])
result = result..'!!HP'
end
rowTxt = rowTxt..'|'..Monsters._getMonsterHP(monter)
end
 
local colTxtArray = {}
result = result..'!!Interval'
for j, colName in pairs(monsterSourceColumns) do
rowTxt = rowTxt..'|'..Monsters._getMonsterAttackSpeed(monster)
table.insert(colTxtArray, 'monster_'..colName..' = '..table.concat(monsterColData[colName], ','))
 
end
result = result..'!!NormalAttackMaxHit'
rowTxt = rowTxt..table.concat(colTxtArray, '<br/>')
rowTxt = rowTxt..'|'..Monsters._getMonsterMaxHit(monster)
 
result = result..'!!NormalAttackType'
rowTxt = rowTxt..'|'..monster.attackType
 
result = result..'!!HasSpecial'
rowTxt = rowTxt..'|'..tostring(not #(monster.specialAttack))
 
result = result..'!!Accuracy'
rowTxt = rowTxt..'|'..Monsters._getMonsterAR(monster)
 
result = result..'!!MeleeEvasion'
rowTxt = rowTxt..'|'..Monsters.__getMonsterER(monster, 'Melee')
 
result = result..'!!RangedEvasion'
rowTxt = rowTxt..'|'..Monsters.__getMonsterER(monster, 'Ranged')
 
result = result..'!!MagicEvasion'
rowTxt = rowTxt..'|'..Monsters.__getMonsterER(monster, 'Magic')
 
result = result..'!!GoldDropMin'
rowTxt = rowTxt..'|'..monster.dropCoins[0]
 
result = result..'!!GoldDropMax'
rowTxt = rowTxt..'|'..monster.dropCoins[1]
 
result = result..'!!BoneType'
result = result..'!!BonePrayerValue'
local bones = Items.getItemByID(monster.bones)  
if bones.prayerPoints then
rowTxt = rowTxt..'|'..bones.name
rowTxt = rowTxt..'|'..bones.prayerPoints
else
else
rowTxt = rowTxt..'||false||'
rowTxt = rowTxt..'|'..tostring(false)
rowTxt = rowTxt..'|'..tostring(0)
end
 
result = result..'!!Location'
rowTxt = rowTxt..'|'..Monsters._getMonsterAreas(monster, false) --args[2] is excludeDungeons
 
result = result..'!!SlayerTier'
rowTxt = rowTxt..'|'..Constants.getSlayerTierByLevel(combatlevel)
result = result..'!!SlayerTierName'
rowTxt = rowTxt..'|'..Constants.getSlayerTierNameByLevel(combatlevel)
 
result = result..'!!ItemsID'
result = result..'!!ItemsWeight'
result = result..'!!ItemsDenominators'
result = result..'!!ItemsTotalWeight'
result = result..'!!ItemsQtyMin'
result = result..'!!ItemsQtyMax'
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
end
rowTxt = rowTxt..'|'..table.concat(itemIds, ",")
rowTxt = rowTxt..'|'..table.concat(itemWeights, ",")
rowTxt = rowTxt..'|'..table.concat(itemDenominators, ",")
rowTxt = rowTxt..'|'..table.concat(totalWeight, ",")
rowTxt = rowTxt..'|'..table.concat(itemQtyMins, ",")
rowTxt = rowTxt..'|'..table.concat(itemQtyMaxs, ",")
table.insert(rows, rowTxt)
table.insert(rows, rowTxt)
itemID = itemID + 1
monsterId = monsterId + 1
item = Items.getItemByID(itemID)
monster = Monsters.getItemByID(monsterID)
end
end
 
result = result..'\r\n'..table.concat(rows, '\r\n')..'\r\n|}'
result = result..'\r\n'..table.concat(rows, '\r\n')..'\r\n|}'
return result
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
end


return p
return p

Revision as of 22:29, 30 January 2022

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 Icons = require('Module:Icons')
-- 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 monsterList = Monsters.getMonsters(function(item) return true end)
	table.sort(monsterList, function(a, b) return a.id < b.id end)

	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 = '|-\r\n'

		result = result..result..'!!ID'
		rowTxt = rowTxt..'|'..monsterID

		result = result..'!!Name'
		rowTxt = rowTxt..'|'..monster.name

		result = result..'!!CombatLevel'
		local combatlevel = Monsters._getMonsterCombatLevel(monster) -- used for slayer
		rowTxt = rowTxt..'|'..combatlevel

		result = result..'!!HP'
		rowTxt = rowTxt..'|'..Monsters._getMonsterHP(monter)

		result = result..'!!Interval'
		rowTxt = rowTxt..'|'..Monsters._getMonsterAttackSpeed(monster)

		result = result..'!!NormalAttackMaxHit'
		rowTxt = rowTxt..'|'..Monsters._getMonsterMaxHit(monster)

		result = result..'!!NormalAttackType'
		rowTxt = rowTxt..'|'..monster.attackType

		result = result..'!!HasSpecial'
		rowTxt = rowTxt..'|'..tostring(not #(monster.specialAttack))

		result = result..'!!Accuracy'
		rowTxt = rowTxt..'|'..Monsters._getMonsterAR(monster)

		result = result..'!!MeleeEvasion'
		rowTxt = rowTxt..'|'..Monsters.__getMonsterER(monster, 'Melee')

		result = result..'!!RangedEvasion'
		rowTxt = rowTxt..'|'..Monsters.__getMonsterER(monster, 'Ranged')

		result = result..'!!MagicEvasion'
		rowTxt = rowTxt..'|'..Monsters.__getMonsterER(monster, 'Magic')

		result = result..'!!GoldDropMin'
		rowTxt = rowTxt..'|'..monster.dropCoins[0]

		result = result..'!!GoldDropMax'
		rowTxt = rowTxt..'|'..monster.dropCoins[1]

		result = result..'!!BoneType'
		result = result..'!!BonePrayerValue'
		local bones = Items.getItemByID(monster.bones) 
		if bones.prayerPoints then
			rowTxt = rowTxt..'|'..bones.name
			rowTxt = rowTxt..'|'..bones.prayerPoints
		else
			rowTxt = rowTxt..'|'..tostring(false)
			rowTxt = rowTxt..'|'..tostring(0)
		end

		result = result..'!!Location'
		rowTxt = rowTxt..'|'..Monsters._getMonsterAreas(monster, false) --args[2] is excludeDungeons

		result = result..'!!SlayerTier'
		rowTxt = rowTxt..'|'..Constants.getSlayerTierByLevel(combatlevel)
		result = result..'!!SlayerTierName'
		rowTxt = rowTxt..'|'..Constants.getSlayerTierNameByLevel(combatlevel)

		result = result..'!!ItemsID'
		result = result..'!!ItemsWeight'
		result = result..'!!ItemsDenominators'
		result = result..'!!ItemsTotalWeight'
		result = result..'!!ItemsQtyMin'
		result = result..'!!ItemsQtyMax'
		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
		rowTxt = rowTxt..'|'..table.concat(itemIds, ",")
		rowTxt = rowTxt..'|'..table.concat(itemWeights, ",")
		rowTxt = rowTxt..'|'..table.concat(itemDenominators, ",")
		rowTxt = rowTxt..'|'..table.concat(totalWeight, ",")
		rowTxt = rowTxt..'|'..table.concat(itemQtyMins, ",")
		rowTxt = rowTxt..'|'..table.concat(itemQtyMaxs, ",")

		table.insert(rows, rowTxt)
		monsterId = monsterId + 1
		monster = Monsters.getItemByID(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