Module:DoD: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(18 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
-- Extract the number of dice, number of sides per dice, and modifier | -- Extract the number of dice, number of sides per dice, and modifier | ||
local numDice, diceType, modifier = string.match(diceCode, "(%d+)d(%d+)%+? | local numDice, diceType, modifier = string.match(diceCode, "(%d+)d(%d+)([%+%-]?%d*)") | ||
-- If no modifier is provided, set it to 0 | -- If no modifier is provided, set it to 0 | ||
modifier = | modifier = tonumber(modifier) or 0 | ||
-- Check if any of the extracted values are nil | -- Check if any of the extracted values are nil | ||
Line 23: | Line 23: | ||
-- Calculate the median value of rolling the dice | -- Calculate the median value of rolling the dice | ||
local median = | local median = 0 | ||
local totalSides = tonumber(diceType) | |||
-- Calculate the median value of rolling the dice | |||
if totalSides then | |||
-- Calculate median for each die roll | |||
local medianPerRoll = (totalSides + 1) / 2 | |||
-- Calculate the total median without modifier | |||
median = numDice * medianPerRoll | |||
-- Add modifier to the total median | |||
median = math.ceil (median + modifier) | |||
else | |||
return "Error: Invalid number of sides for dice" | |||
end | |||
return median | return median | ||
end | |||
function p.skills(frame) | |||
local result | |||
local frames = mw.getCurrentFrame() | |||
local num_args = 0 | |||
-- Count the number of arguments | |||
for k, v in pairs(frames.args) do | |||
num_args = num_args + 1 | |||
end | |||
local num_skills = math.floor(num_args / 3) | |||
local skills = {} -- Table to store skills | |||
-- Populate the skills table | |||
for i = 1, num_skills do | |||
local name = frame.args[(i - 1) * 3 + 1] | |||
local level = frame.args[(i - 1) * 3 + 2] | |||
local cost = frame.args[(i - 1) * 3 + 3] | |||
table.insert(skills, {name = name, level = level, cost = cost}) | |||
end | |||
-- Sort the skills table based on the 3rd field (cost) | |||
table.sort(skills, function(a, b) return a.name < b.name end) | |||
-- Generate the HTML table | |||
result = "<table><tr><td class='skills'>Färdighet</td><td class='spacer'></td><td align='center'>FV</td><td class='spacer'></td><td class='cost' align='center'>Kostnad</td></tr>" | |||
for _, skill in ipairs(skills) do | |||
result = result .. string.format("<tr><td class='skills'>%s</td><td class='spacer'></td><td class='rd'>%s</td><td class='spacer'></td><td class='rd'>%s</td></tr>", | |||
skill.name, skill.level, skill.cost) | |||
end | |||
result = result .. "</table>" | |||
return result | |||
end | |||
function p.Grupp(frame) | |||
local value = tonumber(frame.args[1]) | |||
local grupp = "+" .. math.ceil(value/5) | |||
return grupp | |||
end | |||
function p.calculate_A_cost(frame) | |||
local args = frame.args | |||
local start_level = tonumber(args[1]) | |||
local end_level = tonumber(args[2]) | |||
local base_cost = tonumber(args[3]) | |||
local total_cost = 0 | |||
for level = start_level, end_level do | |||
local multiplier = math.floor((level - 1) / 5) + 1 | |||
total_cost = total_cost + base_cost * multiplier | |||
end | |||
return tostring(total_cost) | |||
end | |||
function p.calculate_B_cost(frame) | |||
local args = frame.args | |||
local start_level = tonumber(args[1]) | |||
local end_level = tonumber(args[2]) | |||
local base_cost = tonumber(args[3]) | |||
local total_cost = 0 | |||
for i = start_level + 1, end_level do | |||
local multiplier = 0 | |||
if i == 1 or i == 2 then | |||
multiplier = 1 | |||
elseif i <= 5 then | |||
multiplier = i - 1 | |||
end | |||
total_cost = total_cost + base_cost * multiplier | |||
end | |||
return tostring(total_cost) | |||
end | end | ||
return p | return p |
Latest revision as of 06:53, 20 February 2024
Färdighet | FV | Kostnad | ||
Rörlighet | 14 | 4 | ||
Upptäcka | 15 | 3 |
0-22 : Cost of 3 : 180
0-18 : Cost of 2 : 84
5-10 : Cost of 1 : 10
B_Skill at level 1 : Cost of 5 5
B_Skill at level 2 : Cost of 5 10
B_Skill at level 3 : Cost of 5 20
B_Skill at level 4 : Cost of 5 35
B_Skill at level 5 : Cost of 5 55
B_Skill at level 5 from 2 : Cost of 5 45
local p = {} -- Function to parse D&D dice codes and return median value function p.calculateMedian(frame) -- Extract the dice code from the function argument local diceCode = frame.args[1] -- Check if diceCode is nil or empty if not diceCode then return "Error: No valid input provided" end -- Extract the number of dice, number of sides per dice, and modifier local numDice, diceType, modifier = string.match(diceCode, "(%d+)d(%d+)([%+%-]?%d*)") -- If no modifier is provided, set it to 0 modifier = tonumber(modifier) or 0 -- Check if any of the extracted values are nil if not numDice or not diceType then return "Error: Invalid dice code" end -- Calculate the median value of rolling the dice local median = 0 local totalSides = tonumber(diceType) -- Calculate the median value of rolling the dice if totalSides then -- Calculate median for each die roll local medianPerRoll = (totalSides + 1) / 2 -- Calculate the total median without modifier median = numDice * medianPerRoll -- Add modifier to the total median median = math.ceil (median + modifier) else return "Error: Invalid number of sides for dice" end return median end function p.skills(frame) local result local frames = mw.getCurrentFrame() local num_args = 0 -- Count the number of arguments for k, v in pairs(frames.args) do num_args = num_args + 1 end local num_skills = math.floor(num_args / 3) local skills = {} -- Table to store skills -- Populate the skills table for i = 1, num_skills do local name = frame.args[(i - 1) * 3 + 1] local level = frame.args[(i - 1) * 3 + 2] local cost = frame.args[(i - 1) * 3 + 3] table.insert(skills, {name = name, level = level, cost = cost}) end -- Sort the skills table based on the 3rd field (cost) table.sort(skills, function(a, b) return a.name < b.name end) -- Generate the HTML table result = "<table><tr><td class='skills'>Färdighet</td><td class='spacer'></td><td align='center'>FV</td><td class='spacer'></td><td class='cost' align='center'>Kostnad</td></tr>" for _, skill in ipairs(skills) do result = result .. string.format("<tr><td class='skills'>%s</td><td class='spacer'></td><td class='rd'>%s</td><td class='spacer'></td><td class='rd'>%s</td></tr>", skill.name, skill.level, skill.cost) end result = result .. "</table>" return result end function p.Grupp(frame) local value = tonumber(frame.args[1]) local grupp = "+" .. math.ceil(value/5) return grupp end function p.calculate_A_cost(frame) local args = frame.args local start_level = tonumber(args[1]) local end_level = tonumber(args[2]) local base_cost = tonumber(args[3]) local total_cost = 0 for level = start_level, end_level do local multiplier = math.floor((level - 1) / 5) + 1 total_cost = total_cost + base_cost * multiplier end return tostring(total_cost) end function p.calculate_B_cost(frame) local args = frame.args local start_level = tonumber(args[1]) local end_level = tonumber(args[2]) local base_cost = tonumber(args[3]) local total_cost = 0 for i = start_level + 1, end_level do local multiplier = 0 if i == 1 or i == 2 then multiplier = 1 elseif i <= 5 then multiplier = i - 1 end total_cost = total_cost + base_cost * multiplier end return tostring(total_cost) end return p