×
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
    Tag: Manual revert
    No edit summary
    Line 6: Line 6:


    function Stat:new(action_token, 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, position)
    parallel_processing, tactics, command, special_tactics, position, listname)
    ---@class Stat
    ---@class Stat
    local res = {}
    local res = {}
    Line 25: Line 25:
    res.special_tactics = tonumber(special_tactics) or 0
    res.special_tactics = tonumber(special_tactics) or 0
    res.position = position
    res.position = position
    res.listname = tonumber(listname) or 0
    return res
    return res
    end
    end
    Line 37: Line 38:
    local ret = {}
    local ret = {}
    for k, t in pairs(data) do
    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)
    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,
    ---for ik, v in pairs(t) do
    t.special_tactics, t.position, t.listname)
    ---ret[k][ik] = v
    ---end
    end
    end
    return ret
    return ret
    Line 49: Line 49:
    for k, v in pairs(self) do
    for k, v in pairs(self) do
    if type(v) == "number" then
    if type(v) == "number" then
    if self.position == "Operator" and k ~= "trion" then
    if self.position == "Operator" and k ~= "trion" and k ~= "listname" then
    total = total + v
    total = total + v
    elseif self.position ~= "Operator" then
    elseif self.position ~= "Operator" and k ~= "listname" then
    total = total + v
    total = total + v
    end
    end
    Line 67: Line 67:
    name = name:gsub(" ", "_")
    name = name:gsub(" ", "_")
    local key = args[2] or pargs[2] or "total"
    local key = args[2] or pargs[2] or "total"
    ---@type Stat
    local entry = data[name]
    local entry = data[name]
    local res = {}
    local res = {}
    Line 76: Line 77:
    res.total = entry:total()
    res.total = entry:total()
    return res[key]
    return res[key]
    end

    ---@param frame frame
    function Stat.calcListName(self, frame)
    local p = tostring(self.listname)
    local name = "bbf" .. p
    return frame:expandTemplate{title = "ref", args = {name = name, db = 'bbf', p = p}}
    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



    Revision as of 19:17, May 20, 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)
        ---@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
        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 name = "bbf" .. p
        return frame:expandTemplate{title = "ref", args = {name = name, db = 'bbf', p = p}}
    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.