Module:Database

From Coromon Wiki
Jump to navigation Jump to search

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

local p = {}

local util = require('Module:Util')
local parse = require('Module:Parse')
local coromon = require('Module:Coromon')
local families = require('Module:Family')
local skills = require('Module:Skills')
local traits = require('Module:Traits')
local items = require('Module:Items')

function numberFromItemName (str)
	
	local index = str:match'^.*() '
	if index == nil then
		return str	
	end
	return tonumber(string.sub(str, index+1, #str))
end

function p.getFlashSkills (f)
	
	local id = f.args[1] or f.args["id"]
	
	local skillFlashes = util.spairs(items.getItemsWith('SKILL_FLASH'), function(t,a,b) return numberFromItemName(t[a].name) < numberFromItemName(t[b].name) end)
	
	local mon = coromon.getCoromon(id)
	local familyID = coromon.getFamilyID({args={id}})
	local wikitext = '{{S|Start|skillFlash=true}}\n'
    
	for k, flash in skillFlashes do
		
		local s = skills.getSkill({args={flash.skill}})
		mw.log(families.hasSkill(familyID, s.name))
		if families.hasSkill(familyID, s.name)~= true and skills.validFlashSkill(mon, flash.skill) then
			local stab = s.category ~= 'Status' and s.type == mon.type
			wikitext = wikitext .. '{{S|'.. s.name ..'|'.. flash.name .. '|stab=' .. tostring(stab) ..'}}\n'
		end
	end
	
	wikitext = wikitext .. '{{S|End}}'
	
	--return wikitext
	return f:preprocess(wikitext)
end

function p.getAllTraits (f)
	
	local traitList = traits.getList()
	
	local wikitext = '{{ListOfTraits|Start}}\n'
	
	local orderedTraits = util.spairs(traitList, 
		function(t,a,b) 
			if a['name'] ~= nil and b['name'] ~= nil then
				return a['name'] < b['name']
			end
			return a < b
	    end)
	
	for id, trait in orderedTraits do
		local totalMonsters = families.getTotalMonstersWithTrait(id) 
		if totalMonsters > 0 and trait.name ~= ' ' then

			wikitext = wikitext .. '{{ListOfTraits/export|traitinfo|totalFamilies=' .. totalMonsters ..'|name=' .. trait.name .. '|type=' .. trait.type .. '|desc=' .. parse.toDisplayText(trait.desc) ..'}}\n'
			wikitext = wikitext .. families.getMonstersForListOfTraits(id)

		end
	end
	
	wikitext = wikitext .. '{{ListOfTraits|End}}'
	
	--return wikitext	
	return f:preprocess(wikitext)
end

function p.getAllUnusedTraits (f)
	
	local traitList = traits.getList()
	
	local wikitext = '{{ListOfTraits|StartUnused}}\n'
	
	local orderedTraits = util.spairs(traitList, 
		function(t,a,b) 
			if a['name'] ~= nil and b['name'] ~= nil then
				return a['name'] < b['name']
			end
			return a < b
	    end)
	
	for id, trait in orderedTraits do
		local totalMonsters = families.getTotalMonstersWithTrait(id) 
		if totalMonsters == 0 and trait.name ~= ' ' then

			wikitext = wikitext .. '{{ListOfTraits/export|traitinfo|name=' .. trait.name .. '|type=' .. trait.type .. '|desc=' .. parse.toDisplayText(trait.desc) ..'}}\n'
			--wikitext = wikitext .. families.getMonstersForListOfTraits(id)

		end
	end
	
	wikitext = wikitext .. '{{ListOfTraits|End}}'
	
	--return wikitext	
	return f:preprocess(wikitext)
end

return p