Editing Module:WeaponData

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 3: Line 3:
 
local weaponData = mw.loadData('Module:WeaponData/data')
 
local weaponData = mw.loadData('Module:WeaponData/data')
  
local function addCustomLabel(templateArgs, key, value, index)
+
local function getMiscStatsTable(weaponDefName)
if key then
+
local wd = weaponData[weaponDefName]
templateArgs["customlabel"..index] = key
+
if not wd then return nil end
templateArgs["customdata"..index] = value
+
if not wd.miscstats then return nil end
else
+
templateArgs["special"..index] = value
+
local tbl = {}
 +
for index, tag in ipairs(wd.miscstats) do
 +
tbl[tag] = true
 
end
 
end
index = index + 1
+
return tbl
return index
 
 
end
 
end
  
 
function weapon.getData(frame)
 
function weapon.getData(frame)
 
if not frame then return '' end
 
if not frame then return '' end
local weaponDefName = frame.args.defname or frame.args[1] or "<no name specified>"
+
    local weaponDefName = frame.args[1]
local wd = weaponData[weaponDefName]
+
    if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end
if not (wd) then return 'weapondef ' .. weaponDefName .. ' not found' end
+
    local property = frame.args[2]
local property = (frame.args.defname == nil) and frame.args[2] or frame.args[1]
+
    local result = weaponData[weaponDefName][property]
local result = wd[property]
+
    if not result then result = '' end
if not result then result = '' end
+
    return frame:preprocess(result) or ''
return result
 
 
end
 
end
  
local function addSpecialDataToTemplate(templateArgs, wd)
+
function weapon.printInfobox(frame)
local num = 1
+
local weaponDefName = frame.args[1]
for index, entry in ipairs(wd.extraData or {}) do
+
    if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end
if type(entry) == 'table' then
+
return [[{{User:Histidine/Autoinfobox zkweapon
if entry.type == 'shielddrain' then
+
|defname=]]..weaponDefName..[[}}]]
num = addCustomLabel(templateArgs, "Shield drain (HP/shot)", entry.drain, num)
 
elseif entry.type == 'needs_link' then
 
num = addCustomLabel(templateArgs, "Grid needed", entry.power, num)
 
elseif entry.type == 'spawn' then
 
num = addCustomLabel(templateArgs, "Spawns Unit", "[[" .. entry.name .. "]]", num)
 
num = addCustomLabel(templateArgs, "Spawn Life (s)", entry.expire, num)
 
elseif entry.type == 'areadamage' then
 
local typeName = entry.grav and "Gravity Well" or "Ground Burn"
 
if not grav then
 
num = addCustomLabel(templateArgs, typeName .. " DPS", entry.dps, num)
 
end
 
num = addCustomLabel(templateArgs, typeName .. " radius (elmo)", entry.radius, num)
 
num = addCustomLabel(templateArgs, typeName .. " duration (s)", entry.duration, num)
 
 
 
elseif entry.type == 'stockpile' then
 
num = addCustomLabel(templateArgs, "Stockpile time (s)", entry.time, num)
 
if (entry.cost) then
 
num = addCustomLabel(templateArgs, "Stockpile cost (M)", entry.cost, num)
 
end
 
end
 
else
 
if entry == 'hitscan' then
 
num = addCustomLabel(templateArgs, nil, "Instantly hits", num)
 
elseif entry == 'ignoreshield' then
 
num = addCustomLabel(templateArgs, nil, "Ignores shields", num)
 
elseif entry == 'smoothsground' then
 
num = addCustomLabel(templateArgs, nil, "Smooths ground", num)
 
elseif entry == 'hightraj' then
 
num = addCustomLabel(templateArgs, nil, "High trajectory", num)
 
elseif entry == 'trajtoggle' then
 
num = addCustomLabel(templateArgs, nil, "Trajectory toggle", num)
 
elseif entry == 'watercapable' then
 
num = addCustomLabel(templateArgs, nil, "Water capable", num)
 
elseif entry == 'friendlyfire' then
 
num = addCustomLabel(templateArgs, nil, "Potential friendly fire", num)
 
elseif entry == 'nofriendlyfire' then
 
num = addCustomLabel(templateArgs, nil, "No friendly fire", num)
 
elseif entry == 'nogroundcollide' then
 
num = addCustomLabel(templateArgs, nil, "Passes through ground", num)
 
elseif entry == 'piercing' then
 
num = addCustomLabel(templateArgs, nil, "Damage increase vs large units", num)
 
elseif entry == 'damagefalloff' then
 
num = addCustomLabel(templateArgs, nil, "Damage falls off with range", num)
 
elseif entry == 'inaccuratevsmoving' then
 
num = addCustomLabel(templateArgs, nil, "Inaccuracy vs moving targets", num)
 
elseif entry == 'interceptedbyantinuke' then
 
num = addCustomLabel(templateArgs, nil, "Can be shot down by antinukes", num)
 
end
 
end
 
end
 
 
end
 
end
  
function weapon.getInfoboxTemplate(frame)
+
function weapon.hasTag(frame)
local args = frame.args
+
if not frame then return '' end
local tbl = {title = "Infobox zkweapon", args = {}}
+
    local weaponDefName = frame.args[1]
local w = tbl.args
+
    if not (weaponData[weaponDefName]) then return 'weapondef ' .. weaponDefName .. ' not found' end
local defName = args.defname or args[1] or "<no name specified>"
+
    local tag = frame.args[2]
local wd = weaponData[defName]
 
if not (wd) then return 'weapondef ' .. defName .. ' not found' end
 
 
 
addSpecialDataToTemplate(w, wd)
+
local miscStats = getMiscStatsTable(weaponDefName)
+
if not miscStats then return false end
for key, value in pairs(wd) do
+
return miscStats[tag]
w[key] = args[key] or value
 
end
 
w.extraData = nil
 
if (w.count and w.count > 1) then
 
w.name = w.name .. " x " .. w.count
 
end
 
if (w.projectiles and w.projectiles > 1) then
 
local append = " x " ..  w.projectiles
 
if w.damage then w.damage = w.damage .. append end
 
if w.empdamage then w.empdamage = w.empdamage .. append end
 
if w.slowdamage then w.slowdamage = w.slowdamage .. append end
 
if w.disarmdamage then w.disarmdamage = w.disarmdamage .. append end
 
if w.shielddamage then w.shielddamage = w.shielddamage .. append end
 
end
 
 
return tbl
 
end
 
 
 
function weapon.printInfobox(frame)
 
return frame:expandTemplate(weapon.getInfoboxTemplate(frame))
 
 
end
 
end
  
 
return weapon
 
return weapon

Please note that all contributions to Zero-K are considered to be released under the Creative Commons Attribution-ShareAlike (see Zero-K:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)

Templates used on this page: