×
Create a new article
Write your page title here:
We currently have 1,393 articles on World Trigger Wiki. Type your article name above or create one of the articles listed here!



    World Trigger Wiki

    Module:Char Stat: Difference between revisions

    Content added Content deleted
    mNo edit summary
    No edit summary
     
    (28 intermediate revisions by 3 users not shown)
    Line 1: Line 1:
    ---@type Util
    local util = require("Module:Util")
    local util = require("Module:Util")


    ---@class Stat
    local Stat = {}
    local Stat = {}
    Stat.__index = Stat


    function Stat:new(trion, attack, defense, mobility, skill, range, mechanical_operation, data_analysis,
    function Stat:new(action_token, trion, attack, defense, mobility, skill, range, mechanical_operation, data_analysis,
    parallel_processing, tactics, command, special_tactics)
    parallel_processing, tactics, command, special_tactics, position, listname, args)
    local res = Stat
    ---@class Stat
    setmetatable(res, Stat)
    local res = {}
    setmetatable(res, self)
    self.__index = self
    res.action_token = tonumber(action_token) or 0
    res.trion = tonumber(trion) or 0
    res.trion = tonumber(trion) or 0
    res.attack = tonumber(attack) or 0
    res.attack = tonumber(attack) or 0
    Line 20: Line 24:
    res.command = tonumber(command) or 0
    res.command = tonumber(command) or 0
    res.special_tactics = tonumber(special_tactics) or 0
    res.special_tactics = tonumber(special_tactics) or 0
    res.position = position
    res.listname = tonumber(listname) or 0
    res.args = args or {db = "bbf"}
    return res
    return res
    end
    end


    function Stat:from_table(table)
    function Stat.from_table(table)
    return Stat:new(unpack(table, 1, 12))
    return Stat.new(unpack(table, 1, 13))
    end

    function Stat.from_data()
    ---@type CS_Stat
    local data = require("Module:Char Stat/data")
    local ret = {}
    for k, t in pairs(data) do
    ret[k] = Stat:new(t.action_token, t.trion, t.attack, t.defense, t.mobility, t.skill,
    t.range, t.mechanical_operation, t.data_analysis, t.parallel_processing, t.tactics, t.command,
    t.special_tactics, t.position, t.listname)
    end
    return ret
    end
    end


    function Stat.total(self)
    function Stat.total(self)
    local t = 0
    local total = 0
    for _, v in pairs(self) do
    for k, v in pairs(self) do
    if type(v) == "number" then
    if type(v) == "number" then
    t = t + v
    if self.position == "Operator" and k ~= "trion" and k ~= "listname" then
    total = total + v
    elseif self.position ~= "Operator" and k ~= "listname" then
    total = total + v
    end
    end
    end
    end
    end
    return t
    return total
    end
    end


    local data = Stat.from_data()
    function Stat:from_frame(frame)
    local args, _ = util.get_args_and_pargs(frame)
    return Stat:from_table(args)
    end


    ---@param path string
    ---@param frame frame
    function Stat:from_json(path)
    function Stat.GetStat(frame)
    local stats = {}
    local args, pargs = util.get_args_and_pargs(frame)
    local data = mw.loadJsonData(path)
    local name = args[1] or pargs[1] or ""
    local i = 0
    name = name:gsub(" ", "_")
    local key = args[2] or pargs[2] or "total"
    for _, v in ipairs(data) do
    stats[i] = Stat:from_table(v)
    ---@type Stat
    i = i + 1
    local entry = data[name]
    local res = {}
    for k, v in pairs(entry) do
    if type(v) == "number" or type(v) == "string" then
    res[k] = v
    end
    end
    end
    res.total = entry:total()
    return stats
    return res[key]
    end
    end


    ---@param frame frame
    function Stat:from_data(path)
    function Stat.calcListName(self, frame)
    local stats = {}
    local data = mw.loadData(path)
    local p = tostring(self.listname)
    local i = 0
    local args = self.args
    local name = ""
    for _, v in ipairs(data) do
    if args.db then name = "bbf" .. p elseif args.c then name = "c" .. p end
    stats[i] = Stat:from_table(v)
    i = i + i
    args.name = name
    end
    args.p = p
    return frame:expandTemplate{title = "ref", args = args}
    return stats
    end

    ---@param frame frame
    function Stat.calcChartName(self, frame)
    return "[[Border Briefing File]] Page " .. self.listname .. self:calcListName(frame)
    end

    ---@param frame frame
    function Stat.GetListName(frame)
    local args, pargs = util.get_args_and_pargs(frame)
    local name = args[1] or pargs[1] or ""
    ---@type Stat
    local entry = data[name]
    return "[[" .. name .. "]]" .. entry:calcListName(frame)
    end

    ---@param frame frame
    function Stat.GetChartName(frame)
    local args, pargs = util.get_args_and_pargs(frame)
    local name = args[1] or pargs[1] or ""
    ---@type Stat
    local entry = data[name]
    return entry:calcChartName(frame)
    end
    end



    Latest revision as of 20:11, May 21, 2024

    Documentation for this module may be created at Module:Char Stat/doc

    ---@type Util
    local util = require("Module:Util")
    
    ---@class Stat
    local Stat = {}
    
    function Stat:new(action_token, trion, attack, defense, mobility, skill, range, mechanical_operation, data_analysis,
        parallel_processing, tactics, command, special_tactics, position, listname, args)
        ---@class Stat
        local res = {}
        setmetatable(res, self)
        self.__index = self
        res.action_token = tonumber(action_token) or 0
        res.trion = tonumber(trion) or 0
        res.attack = tonumber(attack) or 0
        res.defense = tonumber(defense) or 0
        res.mobility = tonumber(mobility) or 0
        res.skill = tonumber(skill) or 0
        res.range = tonumber(range) or 0
        res.mechanical_operation = tonumber(mechanical_operation) or 0
        res.data_analysis = tonumber(data_analysis) or 0
        res.parallel_processing = tonumber(parallel_processing) or 0
        res.tactics = tonumber(tactics) or 0
        res.command = tonumber(command) or 0
        res.special_tactics = tonumber(special_tactics) or 0
        res.position = position
        res.listname = tonumber(listname) or 0
        res.args = args or {db = "bbf"}
        return res
    end
    
    function Stat.from_table(table)
        return Stat.new(unpack(table, 1, 13))
    end
    
    function Stat.from_data()
        ---@type CS_Stat
        local data = require("Module:Char Stat/data")
        local ret = {}
        for k, t in pairs(data) do
            ret[k] = Stat:new(t.action_token, t.trion, t.attack, t.defense, t.mobility, t.skill,
            t.range, t.mechanical_operation, t.data_analysis, t.parallel_processing, t.tactics, t.command,
            t.special_tactics, t.position, t.listname)
        end
        return ret
    end
    
    function Stat.total(self)
        local total = 0
        for k, v in pairs(self) do
            if type(v) == "number" then
                if self.position == "Operator" and k ~= "trion" and k ~= "listname" then
                    total = total + v
                elseif self.position ~= "Operator" and k ~= "listname" then
                    total = total + v
                end
            end
        end
        return total
    end
    
    local data = Stat.from_data()
    
    ---@param frame frame
    function Stat.GetStat(frame)
        local args, pargs = util.get_args_and_pargs(frame)
        local name = args[1] or pargs[1] or ""
        name = name:gsub(" ", "_")
        local key = args[2] or pargs[2] or "total"
        ---@type Stat
        local entry = data[name]
        local res = {}
        for k, v in pairs(entry) do
          if type(v) == "number" or type(v) == "string" then
            res[k] = v
          end
        end
        res.total = entry:total()
        return res[key]
    end
    
    ---@param frame frame
    function Stat.calcListName(self, frame)
        local p = tostring(self.listname)
        local args = self.args
        local name = ""
        if args.db then name = "bbf" .. p elseif args.c then name = "c" .. p end
        args.name = name
        args.p = p
        return frame:expandTemplate{title = "ref", args = args}
    end
    
    ---@param frame frame
    function Stat.calcChartName(self, frame)
        return "[[Border Briefing File]] Page " .. self.listname .. self:calcListName(frame)
    end
    
    ---@param frame frame
    function Stat.GetListName(frame)
        local args, pargs = util.get_args_and_pargs(frame)
        local name = args[1] or pargs[1] or ""
        ---@type Stat
        local entry = data[name]
        return "[[" .. name .. "]]" .. entry:calcListName(frame)
    end
    
    ---@param frame frame
    function Stat.GetChartName(frame)
        local args, pargs = util.get_args_and_pargs(frame)
        local name = args[1] or pargs[1] or ""
        ---@type Stat
        local entry = data[name]
        return entry:calcChartName(frame)
    end
    
    return Stat
    
    Cookies help us deliver our services. By using our services, you agree to our use of cookies.

    Recent changes

  • Fairemont • 2 days ago
  • Fairemont • 2 days ago
  • Fairemont • 2 days ago
  • Fairemont • 2 days ago
  • Welcome to WorldTriggerWiki.com!

    We have completed moving the wiki here from FANDOM. This is the wiki that will be maintained and updated in the future (more information). Enjoy your stay!


    If you would like to get involved, or if you have questions or feedback, check out the Community Portal.

    Happy Birthday!

    June 30

    Takeru Yuiga

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