Line 8: |
Line 8: |
| local args = nil | | local args = nil |
| local ship = nil | | local ship = nil |
| + | local target = nil |
| local shipCapabilities = nil | | local shipCapabilities = nil |
| local frame = nil | | local frame = nil |
Line 61: |
Line 62: |
| day = date[3] < 10 and "0" .. date[3] or date[3], | | day = date[3] < 10 and "0" .. date[3] or date[3], |
| } | | } |
| + | end, |
| + | |
| + | test = function(ship, target) |
| + | return ship:level() + ship._accuracy - target:evasion() |
| end, | | end, |
| | | |
Line 76: |
Line 81: |
| local formatting_function = formatting_functions[key] | | local formatting_function = formatting_functions[key] |
| if formatting_function then | | if formatting_function then |
− | return formatting_function(ship) | + | return formatting_function(ship, target) |
| else | | else |
| if shipCapabilities[key] then | | if shipCapabilities[key] then |
Line 97: |
Line 102: |
| function interpret_arg(arg) | | function interpret_arg(arg) |
| local prefix = string.sub(arg, 1, 1) | | local prefix = string.sub(arg, 1, 1) |
| + | local prefix2 = string.sub(arg, 1, 2) |
| if prefix == "@" then | | if prefix == "@" then |
| local enumerator = string.sub(arg, 2) | | local enumerator = string.sub(arg, 2) |
Line 109: |
Line 115: |
| ship = Ship(ship_key) | | ship = Ship(ship_key) |
| shipCapabilities = ShipCapabilities{ ship = ship } | | shipCapabilities = ShipCapabilities{ ship = ship } |
| + | elseif prefix2 == "!!" then |
| + | local key = string.sub(arg, 3) |
| + | target = Ship(key) |
| elseif prefix == "!" then | | elseif prefix == "!" then |
| local ship_key = string.sub(arg, 2) | | local ship_key = string.sub(arg, 2) |
− | if string.sub(ship_key, 1, 3) == "eq:" and ship then | + | if string.sub(ship_key, 1, 1) == "_" and ship then |
− | local eqs = string.sub(ship_key, 4) | + | local kv = mw.text.split(ship_key, "%s*=%s*") |
− | local equipment = {} | + | local k = kv[1] |
− | for eq in string.gmatch(eqs, '([^,]+)') do
| + | local v = kv[2] |
− | table.insert(equipment, { equipment = eq })
| + | 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 |
| + | ship[k] = tonumber(v) |
| + | end |
| end | | end |
− | ship._equipment = equipment
| |
| else | | else |
| local parts = string.gmatch(ship_key, '([^:]+)') | | local parts = string.gmatch(ship_key, '([^:]+)') |
Line 126: |
Line 143: |
| ship = Ship(ship_key) | | ship = Ship(ship_key) |
| shipCapabilities = ShipCapabilities{ ship = ship } | | shipCapabilities = ShipCapabilities{ ship = ship } |
− | elseif i == 2 then | + | else |
− | local equipment = {}
| + | local kv = mw.text.split(part, "%s*=%s*") |
− | for eq in string.gmatch(part, '([^,]+)') do
| + | local k = kv[0] |
− | table.insert(equipment, { equipment = eq })
| + | local v = kv[1] |
| + | 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 |
| + | ship[k] = tonumber(v) |
| + | end |
| end | | end |
− | ship._equipment = equipment
| |
| end | | end |
| i = i + 1 | | i = i + 1 |
Line 206: |
Line 232: |
| mw.log( | | mw.log( |
| Calc.format(nil, { | | Calc.format(nil, { |
− | "!Nagato/Kai Ni: Prototype 41cm Triple Gun Mount, Prototype 41cm Triple Gun Mount", | + | "!Nagato/Kai Ni", |
− | "?day_battle" | + | "!_level = 99", |
| + | "!_accuracy = 10", |
| + | "!!Destroyer Ro-Class", |
| + | "?test" |
| }) | | }) |
| ) | | ) |