Module:Weapon

From Veloren Wiki

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

local weapons_table = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{title='Template:Weapons.json'})

local p = {}

function round(number, decimals)
    local power = 10^decimals
    return math.floor(number * power) / power
end


p.getWeaponImage = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			image = v['name']
		end
	end
	image = "veloren_" .. image .. ".png"
	return image
end


p.getWeaponRating = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			rating = v['rating']
		end
	end
	return round(rating, 2) * 10
end

p.getWeaponPoise = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			poise = v['poise'] * 10
		end
	end
	return poise
end

p.getWeaponCritChance = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			critchance = v['critchance'] * 100
		end
	end
	return round(critchance, 2) .. "%"
end

p.getWeaponName = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			name = v['name']
		end
	end
	return name
end

p.getWeaponPath = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			path = v['path']
		end
	end
	return path
end

p.getWeaponQuality = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			quality = v['quality']
		end
	end
	return frame:expandTemplate{ title = quality }
end

p.getWeaponDesc = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			desc = v['desc']
		end
	end
	return desc
end

p.getWeaponDamage = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			damage = v['power'] * 10
		end
	end
	return damage
end

p.getWeaponSpeed = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			speed = v['speed']
		end
	end
	return speed
end

p.getWeapon = function(frame)
	local weapon = frame.args[1]
	for k, v in pairs(weapons_table) do
		if v['name'] == weapon then
			image = v['name']
			name = v['name']
			w_type = v['type']
			path = v['path']
			quality = v['quality']
			damage = v['damage'] * 10
			speed = v['speed']
			critchance = v['critchance']
			desc = v['desc']
		end
	end
	txt = frame:expandTemplate{ title = 'Infobox weapon', args = { image = image .. '.png', title = name, description = desc, power = damage, quality = quality, speed = speed, critchance = critchance .. '%'} }
	return txt
end

return p
Cookies help us deliver our services. By using our services, you agree to our use of cookies.