Module:Test: Difference between revisions
From Elwiki
No edit summary |
No edit summary |
||
Line 51: | Line 51: | ||
x.multipliers.duration = 555 | x.multipliers.duration = 555 | ||
self.__index = | self.__index = self | ||
setmetatable(t, self) | setmetatable(t, self) | ||
Revision as of 17:14, 26 August 2022
Documentation for this module may be created at Module:Test/doc
require('Module:CommonFunctions')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- Main process
function p.main(frame)
local args = getArgs(frame);
function dump(o)
if type(o) == 'table' then
local s = '{ <br>'
for k, v in pairs(o) do
if type(k) ~= 'number' then
k = '"' .. k .. '"'
end
s = s .. '[' .. k .. '] = ' .. dump(v) .. ',<br>'
end
return s .. '}'
else
return tostring(o)
end
end
-- Argument init
local traits = args[3]
if (traits == nil) then
traits = '-, -'
end
traits = split(traits);
local skill = args[2]
-- Define the class blueprint for traits.
Trait = {
name = "",
multipliers = {
mp_cost = 100,
cooldown = 100
},
details = {
mp_cost = {0, 0},
cooldown = {0, 0},
duration = {0, 0}
}
}
function Trait:new(t)
t = t or {}
x = {}
x.multipliers = {}
x.multipliers.duration = 555
self.__index = self
setmetatable(t, self)
return t
end
function Trait:math()
for k, v in pairs(self.details) do
for i = 1, 2, 1 do
self.details[k][i] = v[i] * (self.multipliers[k] / 100)
end
end
return self
end
local data = {
mp_cost = {{300, 300}, 60},
cooldown = {{22, 50}, 150},
duration = {{10, 3}, 100}
}
-- Define the mother object of traits.
local reversed = Trait:new({
name = "Reversed",
multipliers = {
mp_cost = data.mp_cost[2],
cooldown = data.cooldown[2],
duration = 300
},
details = {
mp_cost = data.mp_cost[1],
cooldown = data.cooldown[1]
}
})
-- Output point
-- return tostring(trait_table);
return dump(reversed:math());
end
return p