Line 2: |
Line 2: |
| local format = require("Module:StringOperations").format | | local format = require("Module:StringOperations").format |
| local Formatting = require("Module:Formatting") | | local Formatting = require("Module:Formatting") |
| + | local Equipment = require("Module:Equipment") |
| local Ship = require("Module:Ship") | | local Ship = require("Module:Ship") |
| local ShipIterator = require("Module:ShipIterator") | | local ShipIterator = require("Module:ShipIterator") |
Line 153: |
Line 154: |
| function format_arg(arg) | | function format_arg(arg) |
| return args.format == "table" and ("|" .. arg .. "\n") or arg | | return args.format == "table" and ("|" .. arg .. "\n") or arg |
| + | end |
| + | |
| + | function interpret_setter(s) |
| + | local kv = mw.text.split(s, "%s*~%s*") |
| + | local k = kv[1] |
| + | local v = kv[2] |
| + | if k and v then |
| + | if k == "_equipment" then |
| + | local equipment = {} |
| + | local accuracy = 0 |
| + | for eq in string.gmatch(v, '([^,]+)') do |
| + | local eqObj = Equipment(eq) |
| + | table.insert(equipment, { equipment = eqObj }) |
| + | accuracy = accuracy + (eqObj:shelling_accuracy() or 0) |
| + | end |
| + | ship._equipment = equipment |
| + | ship._accuracy = accuracy |
| + | else |
| + | if v ~= "nil" then |
| + | ship[k] = tonumber(v) |
| + | end |
| + | end |
| + | return true |
| + | else |
| + | return false |
| + | end |
| end | | end |
| | | |
Line 178: |
Line 205: |
| target = Ship(key) | | target = Ship(key) |
| elseif prefix == "!" then | | elseif prefix == "!" then |
− | local ship_key = string.sub(arg, 2) | + | local key = string.sub(arg, 2) |
− | local kv = mw.text.split(ship_key, "%s*~%s*")
| + | if not interpret_setter(key) then |
− | local k = kv[1]
| + | local parts = string.gmatch(key, '([^:]+)') |
− | local v = kv[2]
| |
− | if k and v then | |
− | if k == "_equipment" then
| |
− | local equipment = {}
| |
− | for eq in string.gmatch(v, '([^,]+)') do
| |
− | table.insert(equipment, { equipment = eq })
| |
− | end
| |
− | ship._equipment = equipment
| |
− | else
| |
− | if v ~= "nil" then
| |
− | ship[k] = tonumber(v)
| |
− | --[[
| |
− | local kv = mw.text.split(k, "%.")
| |
− | local k1 = kv[1]
| |
− | local k2 = kv[2]
| |
− | if k1 and k2 then
| |
− | if not ship[k1] then
| |
− | ship[k1] = {}
| |
− | end
| |
− | ship[k1][k2] = tonumber(v)
| |
− | else
| |
− | ship[k] = tonumber(v)
| |
− | end
| |
− | ]]--
| |
− | end
| |
− | end
| |
− | else
| |
− | local parts = string.gmatch(ship_key, '([^:]+)') | |
| local i = 1 | | local i = 1 |
| for part in parts do | | for part in parts do |
| if i == 1 then | | if i == 1 then |
− | ship_key = part | + | key = part |
− | ship = Ship(ship_key) | + | ship = Ship(key) |
| shipCapabilities = ShipCapabilities{ ship = ship } | | shipCapabilities = ShipCapabilities{ ship = ship } |
| else | | else |
− | local kv = mw.text.split(part, "%s*~%s*") | + | interpret_setter(part) |
− | local k = kv[1]
| |
− | local v = kv[2]
| |
− | if k and v then
| |
− | if k == "_equipment" then
| |
− | local equipment = {}
| |
− | for eq in string.gmatch(part, '([^,]+)') do
| |
− | table.insert(equipment, { equipment = eq })
| |
− | end
| |
− | ship._equipment = equipment
| |
− | else
| |
− | if v ~= "nil" then
| |
− | ship[k] = tonumber(v)
| |
− | end
| |
− | end
| |
− | end
| |
| end | | end |
| i = i + 1 | | i = i + 1 |
Line 301: |
Line 285: |
| Calc.format(nil, { | | Calc.format(nil, { |
| format = "table", | | format = "table", |
− | "!Nagato/Kai Ni: 41cm Triple Gun Mount Kai, 41cm Triple Gun Mount Kai, Type 13 Air Radar Kai", | + | "!Nagato/Kai Ni", |
| + | "!_equipment ~ 41cm Triple Gun Mount Kai, 41cm Triple Gun Mount Kai, Type 13 Air Radar Kai", |
| "!_level ~ 99", | | "!_level ~ 99", |
− | "!_accuracy ~ 10",
| |
| "!_luck ~ nil", | | "!_luck ~ nil", |
| "!_morale ~ 25", | | "!_morale ~ 25", |
− | "!_fit ~ 7", | + | "!!Destroyer Ro-Class", |
| "!cl0 ~ 56", | | "!cl0 ~ 56", |
| "!cl1 ~ 807", | | "!cl1 ~ 807", |
| "!cl2 ~ 137", | | "!cl2 ~ 137", |
− | "!!Destroyer Ro-Class",
| |
| "?card", | | "?card", |
| "?level", | | "?level", |
− | "2x 41cmK, 1x T13K",
| |
| "?format_morale", | | "?format_morale", |
| "?accuracy", | | "?accuracy", |
Line 321: |
Line 303: |
| "?cl1", | | "?cl1", |
| "?cl2", | | "?cl2", |
− | "?FitData.crit", | + | "", |
| + | "-", |
| "?FitData.hit", | | "?FitData.hit", |
| "?FitData.error", | | "?FitData.error", |
| + | "?FitData.crit", |
| "?hit_rate", | | "?hit_rate", |
| + | "?critical_hit_rate", |
| "?FitData.difference", | | "?FitData.difference", |
| + | "?FitData.critical_difference", |
| + | "?FitData.accuracy_value", |
| + | "?FitData.fit", |
| }) | | }) |
| ) | | ) |