Module:Skills/Agility: Difference between revisions

no edit summary
(Put SC and GP costs separate from item costs)
No edit summary
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Num = require('Module:Number')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
Line 48: Line 49:
end
end
return result
return result
end
-- Applies the cost reduction to the provided ItemCosts table.
-- CostReduction is a table { ['GP'] = num, ['SC'] = num, ['Item'] = {} }
-- Reduction values range from 0 to 100.
function p.applyCostReduction(itemCosts, costReduction)
if costReduction == nil then return itemCosts end
local gp =  Num.clamp((costReduction['GP'] or 0), 0, 100) / 100
local sc =  Num.clamp((costReduction['SC'] or 0), 0, 100) / 100
local item = Num.clamp((costReduction['Item'] or 0), 0, 100) / 100
if gp > 0 and itemCosts['GP'] then
itemCosts['GP'] = math.ceil(itemCosts['GP'] * (1 - gp))
end
if sc > 0 and itemCosts['SC'] then
itemCosts['SC'] = math.ceil(itemCosts['SC'] * (1 - sc))
end
local items = itemCosts['Items']
if item > 0 then
for k, v in pairs(items) do
items[k] = math.ceil(items[k] * (1 - item))
end
end
itemCosts['Items'] = items
return itemCosts
end
end


964

edits