Module:CharactersData

From Tokyo Afterschool Summoners
Revision as of 07:04, 27 February 2017 by Ptown2 (talk | contribs) (Created page with "local p = {} p.cachecount = 0 p.List = {} p.WeaponTypes = {} p.WeaponTypes[0] = { Class = "Strike", Method = "Fist", Mult = 1.00 } p.WeaponTypes[1] = { Class = "Slash", Me...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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

local p = {}

p.cachecount = 0
p.List = {}

p.WeaponTypes = {}
p.WeaponTypes[0] = { Class = "Strike", Method = "Fist",  Mult = 1.00 }
p.WeaponTypes[1] = { Class = "Slash",  Method = "Sword", Mult = 0.45 }
p.WeaponTypes[2] = { Class = "Pierce", Method = "Spear", Mult = 0.55 }
p.WeaponTypes[3] = { Class = "Ranged", Method = "Bow",   Mult = 0.45 }
p.WeaponTypes[4] = { Class = "Magic",  Method = "Rod",   Mult = 0.28 }

p.ClassTypes = {
	"Fire", "Water", "Earth", "Dark", "Light", "Demon", "Neutral"
}


-- AddNewUnit
function p:AddNewUnit( name, fullname, classid, wepid, stars, id )
	self.cachecount = self.cachecount + 1

	self.List[ name ] = {
		ID = id or self.cachecount,
		Name = name,
		FullName = fullname or name,
		wType = self.WeaponTypes[ wepid ],
		cType = self.ClassTypes[ classid or 6 ],
		Stars = stars,
	}

	return self.List[ name ]
end


-- FindUnitByName
function p:FindUnitByName( name )
	-- What if its a direct name?
	if self.List[ name ] then
		return self.List[ name ]
	end

	-- What if its a full name?
	for _, info in pairs( self.List ) do
		if info.Name == name or info.FullName == name then
			return self.List[ info.name ]
		end
	end

	return nil
end


-- FindUnitByID
function p:FindUnitByID( id )
	for _, info in pairs( self.List ) do
		if info.ID == id then
			return self.List[ info.Name ]
		end
	end
end


-- ListAllUnitsByWeapon
function p:ListAllUnitsByWeapon( id )
	local units = {}

	for _, info in pairs( self.List ) do
		if info.wType.Class == self.WeaponTypes[ id ].Class then
			units[ units + 1 ] = self.List[ info.Name ]
		end
	end

	return units
end


-- ListAllUnitsByClass
function p:ListAllUnitsByClass( id )
	local units = {}

	for _, info in pairs( self.List ) do
		if info.cType == self.ClassTypes[ id ] then
			units[ units + 1 ] = self.List[ info.Name ]
		end
	end

	return units
end


-- ListAllUnitsByStar
function p:ListAllUnitsByStar( starSt, starEnd )
	if not starEnd then
		starEnd = starSt
	end

	local units = {}

	for _, info in pairs( self.List ) do
		if info.Stars == starSt or info.Stars == starEnd or ( info.Stars >= starSt and info.Stars <= starEnd ) then
			units[ units + 1 ] = self.List[ info.Name ]
		end
	end

	return units
end


return p