71
editsAd placeholder
Module:DiceUtils: Difference between revisions
Jump to navigation
Jump to search
no edit summary
(Undo revision 19566 by NamelessWonder (talk)) Tag: Undo |
No edit summary |
||
Line 28: | Line 28: | ||
d_type = string.sub(damage_die, idx + 1) | d_type = string.sub(damage_die, idx + 1) | ||
table.insert( | table.insert(damage[d_type], die) | ||
end | end | ||
return table.concat( | |||
for d_type, dice in pairs(damage) do | |||
if not next(dice) == nil then | |||
min_damage = 0 | |||
max_damage = 0 | |||
avg_str = "" | |||
for i, die in ipairs(dice) do | |||
idx = string.find(die, "d") | |||
count = tonumber(string.sub(die, 1, idx -1)) | |||
value = tonumber(string.sub(die, idx + 1)) | |||
min_damage = min_damage + count | |||
max_damage = max_damage + value * count | |||
avg_str = string.format("(%d - %d)", min_damage, max_damage) | |||
end | |||
damage_str = string.format("%s %s %s", table.concat(dice, " + "), d_type, avg_str) | |||
table.insert(damage_str) | |||
end | |||
end | |||
return table.concat(result, "<br>") | |||
end | end | ||
return p | return p |