4,687
edits
(Synced with Live Constants) |
(Pulled Modifier data from GameData) |
||
Line 911: | Line 911: | ||
--ex. "MeleeAccuracyBonus", "+{V}% Melee Accuracy", "+", false | --ex. "MeleeAccuracyBonus", "+{V}% Melee Accuracy", "+", false | ||
function p.getModifierDetails(modifierName) | function p.getModifierDetails(modifierName) | ||
local baseName = modifierName | |||
local valueUnsigned = false | |||
local modifier = GameData.rawData.modifierData[modifierName] | |||
if modifier == nil then | |||
return nil | |||
end | |||
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then | |||
baseName = string.sub(modifierName, 10) | |||
end | |||
--TODO: Is this necessary anymore? This could theoretically match 'increasedRolledReflectDamage' ('+0-${value} Reflect Damage') incorrectly | |||
local sign = "+" | |||
if string.match(modifier.description, '${value}') then | |||
sign = "-" | |||
end | |||
if string.match(modifier.description, ' ${value}') then valueUnsigned = true end | |||
return baseName, modifier.description, sign, modifier.isNegative, valueUnsigned, modifier | |||
end | |||
--TODO: Remove this | |||
function p.test(modifierName) | |||
local baseName = modifierName | |||
local valueUnsigned = false | |||
local modifier = GameData.rawData.modifierData[modifierName] | |||
if modifier == nil then | |||
return nil | |||
end | |||
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then | |||
baseName = string.sub(modifierName, 10) | |||
end | |||
--TODO: Is this necessary anymore? This could theoretically match 'increasedRolledReflectDamage' ('+0-${value} Reflect Damage') incorrectly | |||
local sign = "+" | |||
if string.match(modifier.description, '${value}') then | |||
sign = "-" | |||
end | |||
if string.match(modifier.description, ' ${value}') then valueUnsigned = true end | |||
return modifier | |||
end | |||
--TODO: Remove this; Original getModifierDetails | |||
function p.ogetModifierDetails(modifierName) | |||
local baseName = modifierName | local baseName = modifierName | ||
local isIncrease = true | local isIncrease = true | ||
Line 943: | Line 991: | ||
function p._getModifierText(modifier, value, doColor) | function p._getModifierText(modifier, value, doColor) | ||
if doColor == nil then doColor = true end | if doColor == nil then doColor = true end | ||
local modName, modText, sign, isNegative, valueUnsigned = p.getModifierDetails(modifier) | local modName, modText, sign, isNegative, valueUnsigned, modifierData = p.getModifierDetails(modifier) | ||
if modName == nil then | |||
return Shared.printError('Invalid modifier type for "' .. modifier .. '"') | |||
end | |||
--TODO: Untested: value+1; No items to test with | |||
local formatModValue = function(value, rule) | |||
local ruleFunctions = { | |||
['value'] = function(val) return val end, | |||
['multiplyByNumberMultiplier'] = function(val) return val * 10 end, | |||
['divideByNumberMultiplier'] = function(val) return val / 10 end, | |||
['milliToSeconds'] = function(val) return val / 1000 end, | |||
['(value)=>value*100'] = function(val) return val * 100 end, | |||
['(value)=>100+value'] = function(val) return val + 100 end, | |||
['(value)=>value+1'] = function(val) return val + 1 end, | |||
['(value)=>Math.pow(2,value)'] = function(val) return 2^val end, | |||
['(value)=>game.golbinRaid.startingWeapons[value].name'] = function(val) | |||
-- For golbin raid starting weapons | |||
local startingWeapons = { 'melvorD:Bronze_Scimitar', 'melvorD:Adamant_Scimitar' } | |||
local itemID = startingWeapons[val + 1] | |||
local item = GameData.getEntityByID('items', itemID) | |||
if item ~= nil then | |||
return item.name | |||
else | |||
return 'Unknown' | |||
end | |||
end | |||
} | |||
local ruleFunc = ruleFunctions[modifierData.modifyValue] or ruleFunctions['value'] | |||
if type(value) == 'table' then | |||
-- If table is a pair of values then format both & add a separator | |||
return ruleFunc(value[1]) .. '-' .. ruleFunc(value[2]) | |||
else | |||
return ruleFunc(value) | |||
end | |||
end | |||
local valueArray, resultArray = nil, {} | |||
if type(value) ~= 'table' then | |||
valueArray = {value} | |||
else | |||
valueArray = value | |||
end | |||
for i, subVal in ipairs(valueArray) do | |||
local resultText = modText | |||
local modMagnitude = nil | |||
if type(subVal) == 'table' and subVal.skillID ~= nil then | |||
-- Modifier value is skill specific | |||
modMagnitude = subVal.value | |||
local skillName = p.getSkillName(subVal.skillID) | |||
if skillName ~= nil then | |||
resultText = string.gsub(resultText, '${skillName}', skillName) | |||
end | |||
else | |||
-- Modifier value is the magnitude only | |||
modMagnitude = subVal | |||
end | |||
local valSign = (valueUnsigned and '' or '') | |||
resultText = string.gsub(resultText, '${(value[^}]*)}', function(rule) return valSign .. (formatModValue(modMagnitude, rule) or '') end) | |||
if doColor then | |||
local colorCode = (isNegative ~= nil and isNegative and 'color:red' or 'color:green') | |||
resultText = '<span style="' .. colorCode .. '">' .. resultText .. '</span>' | |||
end | |||
table.insert(resultArray, resultText) | |||
end | |||
return table.concat(resultArray, '<br/>') | |||
end | |||
--TODO: Remove this; Original _getModifierText | |||
function p._ogetModifierText(modifier, value, doColor) | |||
if doColor == nil then doColor = true end | |||
local modName, modText, sign, isNegative, valueUnsigned = p.ogetModifierDetails(modifier) | |||
if modName == nil then | if modName == nil then | ||
Line 1,102: | Line 1,225: | ||
local baseName = p.getModifierDetails(modifier) | local baseName = p.getModifierDetails(modifier) | ||
if baseName == nil then | |||
return { Shared.printError('Modifier "' .. modifier .. '" is invalid') } | |||
end | |||
if modifierTypes[baseName].skills ~= nil then | |||
for i, skillName in Shared.skpairs(modifierTypes[baseName].skills) do | |||
if not Shared.contains(skillArray, skillName) then | |||
table.insert(skillArray, skillName) | |||
end | |||
end | |||
end | |||
end | |||
return skillArray | |||
end | |||
--TODO: Remove this; Original getModifierSkills | |||
function p.ogetModifierSkills(modifiers) | |||
local skillArray = {} | |||
for modifier, value in pairs(modifiers) do | |||
if type(value) == 'table' then | |||
for i, subVal in ipairs(value) do | |||
if type(subVal) == 'table' and subVal.skillID ~= nil then | |||
local skillName = p.getSkillName(subVal.skillID) | |||
if not Shared.contains(skillArray, skillName) then | |||
table.insert(skillArray, skillName) | |||
end | |||
end | |||
end | |||
end | |||
local baseName = p.ogetModifierDetails(modifier) | |||
if baseName == nil then | if baseName == nil then | ||
return { Shared.printError('Modifier "' .. modifier .. '" is invalid') } | return { Shared.printError('Modifier "' .. modifier .. '" is invalid') } |