2,875
edits
(Put SC and GP costs separate from item costs) |
(Add function to calculate obstacle cost reduction) |
||
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 itemCosts['GP'] then | |||
itemCosts['GP'] = math.ceil(itemCosts['GP'] * (1 - gp)) | |||
end | |||
if itemCosts['SC'] then | |||
itemCosts['SC'] = math.ceil(itemCosts['SC'] * (1 - sc)) | |||
end | |||
local items = itemCosts['Items'] | |||
for k, v in pairs(items) do | |||
items[k] = math.ceil(items[k] * (1 - item)) | |||
end | |||
itemCosts['Items'] = items | |||
return itemCosts | |||
end | end | ||
edits