Module:Horblegorble/Sandbox/Weapon

From Veloren Wiki
Revision as of 13:55, 15 August 2022 by Horblegorble (talk | contribs)

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

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

local p = {}

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

local weapon_found = false
local weapon_info = {}
local findWeapon = function(page_name)
	if weapon_found then
		return
	end
	for i, v in ipairs(weapons_table) do
		weapon_found = true
		if v['name'] == page_name then
			weapon_info['name']       = v['name']
			weapon_info['kind']       = v['kind']
			weapon_info['hands']      = v['hands']
			weapon_info['quality']    = v['quality']
			weapon_info['power']      = v['power']
			weapon_info['speed']      = v['speed']
			weapon_info['poise']      = v['poise']
			weapon_info['critchance'] = v['critchance']
			weapon_info['desc']       = v['desc']
			weapon_info['path']       = v['path']
			break
		end
	end
end

p.getWeaponName = function(frame)
	findWeapon(frame.args[1])
	return weapon_info['name']
end

p.getWeaponKind = function(frame)
	findWeapon(frame.args[1])
	return weapon_info['kind']
end

p.getWeaponHands = function(frame)
	findWeapon(frame.args[1])
	return weapon_info['hands']
end

p.getWeaponImage = function(frame)
	findWeapon(frame.args[1])
	return "veloren_" .. weapon_info['name'] .. ".png"
end

p.getWeaponPoise = function(frame)
	findWeapon(frame.args[1])
	return 10 * weapon_info['poise']
end

p.getWeaponCritChance = function(frame)
	findWeapon(frame.args[1])
	return round(weapon_info['critchance'], 2) .. "%"
end

p.getWeaponPath = function(frame)
	findWeapon(frame.args[1])
	return weapon_info['path']
end

p.getWeaponQuality = function(frame)
	findWeapon(frame.args[1])
	return frame:expandTemplate{ title = weapon_info['quality'] }
end

p.getWeaponDesc = function(frame)
	findWeapon(frame.args[1])
	return weapon_info['desc']
end

p.getWeaponPower = function(frame)
	findWeapon(frame.args[1])
	return 10 * weapon_info['power']
end

p.getWeaponSpeed = function(frame)
	findWeapon(frame.args[1])
	return weapon_info['speed']
end

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