Module:Sandbox/Constants: Difference between revisions

Remove nil modifiers from getModifiersDifference
(Pulled Modifier data from GameData)
(Remove nil modifiers from getModifiersDifference)
 
(8 intermediate revisions by the same user not shown)
Line 5: Line 5:


--Just hardcoding these because I guess that's where we're at
--Just hardcoding these because I guess that's where we're at
--getModifierSkills still needs skills, otherwise this can be removed
local modifierTypes = {
local modifierTypes = {
["MeleeStrengthBonus"] = { text = "{V}% Melee Strength Bonus from Equipment", skills = {'Combat'} },
["MeleeStrengthBonus"] = { text = "{V}% Melee Strength Bonus from Equipment", skills = {'Combat'} },
Line 392: Line 393:
["DamageTakenWhenStunned"] = { text = "{V}% damage taken when stunned", isIncreaseNegative = true, skills = {'Combat'} },
["DamageTakenWhenStunned"] = { text = "{V}% damage taken when stunned", isIncreaseNegative = true, skills = {'Combat'} },
["DeadlyPoisonDOTDamage"] = { text = "{V}% Damage taken from Deadly Poison", skills = {'Combat'} },
["DeadlyPoisonDOTDamage"] = { text = "{V}% Damage taken from Deadly Poison", skills = {'Combat'} },
["DeadlyToxinsFromHerblore"] = { text = "When creating Lethal Toxins Potions in Herblore, gain {V} Deadly Toxins Potion(s) as an additional Potion (Cannot be doubled)", skills = {'Herblore'} },
["DeadlyToxinsFromHerblore"] = { text = "When creating Lethal Toxins Potions in Herblore, gain +${value} Deadly Toxins Potion(s) as an additional Potion (Cannot be doubled)", skills = {'Herblore'} },
["decreaseEnemyEvasionOnSleep"] = { text = "When a Sleep is applied to the Target, -10% Global Evasion Rating for the remainder of the fight (Stacks up to 3 times)", skills = {'Combat'} },
["decreaseEnemyEvasionOnSleep"] = { text = "When a Sleep is applied to the Target, -10% Global Evasion Rating for the remainder of the fight (Stacks up to 3 times)", skills = {'Combat'} },
["decreaseEnemyEvasionOnStun"] = { text = "When a Stun is applied to the Target, -10% Global Evasion Rating for the remainder of the fight (Stacks up to 3 times)", skills = {'Combat'} },
["decreaseEnemyEvasionOnStun"] = { text = "When a Stun is applied to the Target, -10% Global Evasion Rating for the remainder of the fight (Stacks up to 3 times)", skills = {'Combat'} },
Line 907: Line 908:
--- End of slayer functions
--- End of slayer functions


--Turns a modifier name like 'increasedMeleeAccuracyBonus' into several pieces of data:
--Turns a modifier name like 'increasedHPRegenFlat' into several pieces of data:
--Base Name, Text, Sign, and IsNegative
--Base Name, Description, IsNegative, and modifyValue
--ex. "MeleeAccuracyBonus", "+{V}% Melee Accuracy", "+", false
--ex. "HPRegenFlat", "+${value} Flat Hitpoints Regeneration", false, "multiplyByNumberMultiplier"
function p.getModifierDetails(modifierName)
function p.getModifierDetails(modifierName)
local baseName = modifierName
local baseName = modifierName
local valueUnsigned = false
local modifier = GameData.rawData.modifierData[modifierName]
local modifier = GameData.rawData.modifierData[modifierName]


Line 923: Line 923:
end
end


--TODO: Is this necessary anymore? This could theoretically match 'increasedRolledReflectDamage' ('+0-${value} Reflect Damage') incorrectly
return baseName, modifier.description, modifier.isNegative, modifier.modifyValue
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 isIncrease = true
local isNegative = false
local valueUnsigned = false
 
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then
baseName = string.sub(modifierName, 10)
isIncrease = Shared.startsWith(modifierName, "increased")
end
 
local modifier = modifierTypes[baseName]
if modifier == nil then
return nil
end
 
local isPositive = isIncrease
if modifier.isIncreaseNegative then
isPositive = not isPositive
end
 
local sign = "+"
if (not isIncrease and not modifier.inverseSign) or (isIncrease and modifier.inverseSign) then
sign = "-"
end
 
if type(modifier.unsigned) == 'boolean' then valueUnsigned = modifier.unsigned end
 
return baseName, modifier.text, sign, not isPositive, valueUnsigned, modifier
end
end


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, modifierData = p.getModifierDetails(modifier)
local modName, modText, isNegative, modifyValue = p.getModifierDetails(modifier)


if modName == nil then
if modName == nil then
return Shared.printError('Invalid modifier type for "' .. modifier .. '"')
return Shared.printError('Invalid modifier type for "' .. modifier .. '"')
end
end
--TODO: Untested: value+1; No items to test with
 
if modifyValue ~= nil and string.match(modifyValue, 'ToolLevels') then
modifyValue = 'ArchaeologyToolLevels'
end
 
local formatModValue = function(value, rule)
local formatModValue = function(value, rule)
local ruleFunctions = {
local ruleFunctions = {
Line 1,007: Line 948:
['(value)=>value+1'] = function(val) return val + 1 end,
['(value)=>value+1'] = function(val) return val + 1 end,
['(value)=>Math.pow(2,value)'] = function(val) return 2^val end,
['(value)=>Math.pow(2,value)'] = function(val) return 2^val end,
["(value)=>{if(value>=2){return getLangString('ALLOW_UNHOLY_PRAYERS');}\nelse if(value>=1){return getLangString('ALLOW_UNHOLY_PRAYERS_WITH_EQUIPMENT');}\nelse{return 'Invalid modifier value.';}}"] = function(val) return 'Allows for Unholy Prayers to be used' end,
['ArchaeologyToolLevels'] = function(val)
local toolLevel = '+' .. val
if string.match(modName, 'Sieve') then
toolLevel = toolLevel ..  ' level of the Sieve Tool in Archaeology'
elseif string.match(modName, 'Trowel') then
toolLevel = toolLevel ..  ' level of the Trowel Tool in Archaeology'
elseif string.match(modName, 'Brush') then
toolLevel = toolLevel ..  ' level of the Brush Tool in Archaeology'
elseif string.match(modName, 'Shovel') then
toolLevel = toolLevel ..  ' level of the Shovel Tool in Archaeology'
end
if val > 1 then
return string.gsub(toolLevel, 'level', 'levels')
else
return toolLevel
end
end,
['(value)=>game.golbinRaid.startingWeapons[value].name'] = function(val)
['(value)=>game.golbinRaid.startingWeapons[value].name'] = function(val)
-- For golbin raid starting weapons
-- For golbin raid starting weapons
local startingWeapons = { 'melvorD:Bronze_Scimitar', 'melvorD:Adamant_Scimitar' }
local startingWeapons = { 'melvorD:Bronze_Scimitar', 'melvorD:Adamant_Scimitar' }
local itemID = startingWeapons[val + 1]
local itemID = startingWeapons[val + 1]
local item = GameData.getEntityByID('items', itemID)
local item = GameData.getEntityByID('items', itemID)
if item ~= nil then
if item ~= nil then
return item.name
return item.name
else
else
return 'Unknown'
return 'Unknown'
end
end
end
end
}
}
local ruleFunc = ruleFunctions[modifierData.modifyValue] or ruleFunctions['value']
local ruleFunc = ruleFunctions[modifyValue] or ruleFunctions['value']
 
if type(value) == 'table' then
if type(value) == 'table' then
-- If table is a pair of values then format both & add a separator
-- If table is a pair of values then format both & add a separator
Line 1,038: Line 997:
for i, subVal in ipairs(valueArray) do
for i, subVal in ipairs(valueArray) do
local resultText = modText
local resultText = modText
-- A few modifiers don't have official descriptions; Fallback to manual ones instead
if string.match(resultText, 'UNDEFINED TRANSLATION') then
resultText = modifierTypes[modName].text
end
local modMagnitude = nil
local modMagnitude = nil
if type(subVal) == 'table' and subVal.skillID ~= nil then
if type(subVal) == 'table' and subVal.skillID ~= nil then
Line 1,051: Line 1,014:
end
end


local valSign = (valueUnsigned and '' or '')
resultText = string.gsub(resultText, '${value}', function(rule) return (formatModValue(modMagnitude, rule) or '') end)
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
return Shared.printError('Invalid modifier type for "' .. modifier .. '"')
end
local formatModValue = function(value, rule)
local ruleFunctions = {
['V'] = function(val) return val end,
['VD'] = function(val) return val / 10 end,
['VMS'] = function(val) return val / 1000 end,
['VX'] = function(val) return val * 10 end,
['VX100'] = function(val) return val * 100 end,
['V+100'] = function(val) return val + 100 end,
['V+1'] = function(val) return val + 1 end,
['VMUL'] = function(val) return 2^val end,
['VITEM'] = 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[rule] or ruleFunctions['V']
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, '{SV0}', skillName)
end
else
-- Modifier value is the magnitude only
modMagnitude = subVal
end
 
local valSign = (valueUnsigned and '' or sign or '')
resultText = string.gsub(resultText, '{(V[^}]*)}', function(rule) return valSign .. (formatModValue(modMagnitude, rule) or '') end)
resultText = string.gsub(resultText, '{S}', sign)


if doColor then
if doColor then
Line 1,225: Line 1,111:


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') }
Line 1,338: Line 1,192:
end
end
modDiff[modName] = (modDiff[modName] or 0) + math.abs(value)
modDiff[modName] = (modDiff[modName] or 0) + math.abs(value)
if GameData.rawData.modifierData[modName] == nil then
modDiff[modName] = nil
end
end
end
end
end
463

edits