Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

User:Horblegorble/Sandbox/Module:Weapon

Revision as of 08:11, 25 August 2022 by Horblegorble (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

local weapons_table = mw.text.jsonDecode(mw.getCurrentFrame():expandTemplate{title='User:Horblegorble/Sandbox/Template: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 _, v in pairs(weapons_table) do weapon_found = true if v['name'] == page_name then -- general weapon_info['name' ] = v['name' ] weapon_info['kind' ] = v['kind' ] weapon_info['hands' ] = v['hands' ] weapon_info['desc' ] = v['desc' ] weapon_info['craftable' ] = v['craftable' ] -- displayed stats 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['range' ] = v['range' ] weapon_info['efficiency'] = v['efficiency'] weapon_info['buff' ] = v['buff' ] weapon_info['bufftype' ] = v['bufftype' ] -- detailed stats weapon_info['equiptime' ] = v['equiptime' ] -- assets weapon_info['path' ] = v['path' ] weapon_info['vox' ] = v['vox' ] weapon_info['ron' ] = v['ron' ] weapon_info['manifest' ] = v['manifest' ] break end end end

-- general

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.getWeaponDesc = function(frame) findWeapon(frame.args[1]) return weapon_info['desc'] end

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

-- displayed stats

p.getWeaponQuality = function(frame) findWeapon(frame.args[1]) return frame:expandTemplate{ title = weapon_info['quality'] } 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

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.getWeaponRange = function(frame) findWeapon(frame.args[1]) return weapon_info['range'] end

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

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

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

-- detailed stats

p.getWeaponEquipTime = function(frame) findWeapon(frame.args[1]) return weapon_info['equiptime'] .. ' seconds' end

-- assets

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

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

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

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

return p

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