Module:Constants: Difference between revisions

Updated Arch Tool Level display, Fixed error on nil modifiers in getModifiersDifference
(Add new V1.2.2 modifiers)
(Updated Arch Tool Level display, Fixed error on nil modifiers in getModifiersDifference)
 
(4 intermediate revisions by 2 users 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 206: Line 207:
["Decay"] = { text = "{V}% of Maximum Hitpoints taken as damage on a successful attack (once per turn)", isIncreaseNegative = true, skills = {'Combat'} },
["Decay"] = { text = "{V}% of Maximum Hitpoints taken as damage on a successful attack (once per turn)", isIncreaseNegative = true, skills = {'Combat'} },
["doubleItemsSkill"] = { text = "x{VMUL} Items received from {SV0}", unsigned = true },
["doubleItemsSkill"] = { text = "x{VMUL} Items received from {SV0}", unsigned = true },
["doubleOresMining"] = { text = "x{VMUL} Ores received from Mining", unsigned = true, skills = {'Mining'} },
["doubleOresMining"] = { text = "x2 Ores received from Mining", unsigned = true, skills = {'Mining'} },
["DragonBreathDamage"] = { text = "{V}% damage taken from dragonbreath", isIncreaseNegative = true, skills = {'Combat'} },
["DragonBreathDamage"] = { text = "{V}% damage taken from dragonbreath", isIncreaseNegative = true, skills = {'Combat'} },
["FiremakingCoalChance"] = { text = "{V}% chance to receive coal when burning logs in Firemaking", skills = {'Firemaking'} },
["FiremakingCoalChance"] = { text = "{V}% chance to receive coal when burning logs in Firemaking", skills = {'Firemaking'} },
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 655: Line 656:
["CombinationRuneProduction"] = { text = "{V} Combination Runes produced per action in Runecrafting", skills = {'Runecrafting'} },
["CombinationRuneProduction"] = { text = "{V} Combination Runes produced per action in Runecrafting", skills = {'Runecrafting'} },
["convertBoneDropsIntoCake"] = { text = "Converts all Bone drops from Combat into Birthday Cake Slice drops", skills = {'Comabt'} },
["convertBoneDropsIntoCake"] = { text = "Converts all Bone drops from Combat into Birthday Cake Slice drops", skills = {'Comabt'} },
["CookingIntervalForBasicSoup"] = { text = "{V}% Cooking Interval when making Basic Soup", skills = {'Cooking'} },
["CookingIntervalForBasicSoup"] = { text = "{V}% Cooking Interval when making Basic Soup", isIncreaseNegative = true, skills = {'Cooking'} },
["crystallized"] = { text = "Modifier to determined status of crystallized effect", skills = {'Combat'} },
["crystallized"] = { text = "Modifier to determined status of crystallized effect", skills = {'Combat'} },
["CurseOnHitWithUnholyMark"] = { text = "{V}% chance to apply a random Curse when hitting with an attack if the target has Unholy Mark", skills = {'Combat'} },
["CurseOnHitWithUnholyMark"] = { text = "{V}% chance to apply a random Curse when hitting with an attack if the target has Unholy Mark", 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 isIncrease = true
local modifier = GameData.rawData.modifierData[modifierName]
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
if modifier == nil then
return nil
return nil
end
end


local isPositive = isIncrease
if Shared.startsWith(modifierName, "increased") or Shared.startsWith(modifierName, "decreased") then
if modifier.isIncreaseNegative then
baseName = string.sub(modifierName, 10)
isPositive = not isPositive
end
end


local sign = "+"
return baseName, modifier.description, modifier.isNegative, modifier.modifyValue
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 = 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
 
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 = {
['V'] = function(val) return val end,
['value'] = function(val) return val end,
['VD'] = function(val) return val / 10 end,
['multiplyByNumberMultiplier'] = function(val) return val * 10 end,
['VMS'] = function(val) return val / 1000 end,
['divideByNumberMultiplier'] = function(val) return val / 10 end,
['VX'] = function(val) return val * 10 end,
['milliToSeconds'] = function(val) return val / 1000 end,
['VX100'] = function(val) return val * 100 end,
['(value)=>value*100'] = function(val) return val * 100 end,
['V+100'] = function(val) return val + 100 end,
['(value)=>100+value'] = function(val) return val + 100 end,
['V+1'] = function(val) return val + 1 end,
['(value)=>value+1'] = function(val) return val + 1 end,
['VMUL'] = function(val) return 2^val end,
['(value)=>Math.pow(2,value)'] = function(val) return 2^val end,
['VITEM'] = function(val)
["(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,
-- For golbin raid starting weapons
['ArchaeologyToolLevels'] = function(val)
local startingWeapons = { 'melvorD:Bronze_Scimitar', 'melvorD:Adamant_Scimitar' }
local toolLevel = '+' .. val
local itemID = startingWeapons[val + 1]
if string.match(modName, 'Sieve') then
local item = GameData.getEntityByID('items', itemID)
toolLevel = toolLevel ..  ' level of the Sieve Tool in Archaeology'
if item ~= nil then
elseif string.match(modName, 'Trowel') then
return item.name
toolLevel = toolLevel ..  ' level of the Trowel Tool in Archaeology'
else
elseif string.match(modName, 'Brush') then
return 'Unknown'
toolLevel = toolLevel ..  ' level of the Brush Tool in Archaeology'
end
elseif string.match(modName, 'Shovel') then
end
toolLevel = toolLevel ..  ' level of the Shovel Tool in Archaeology'
}
end
local ruleFunc = ruleFunctions[rule] or ruleFunctions['V']
if val > 1 then
return string.gsub(toolLevel, 'level', 'levels')
if type(value) == 'table' then
else
-- If table is a pair of values then format both & add a separator
return toolLevel
return ruleFunc(value[1]) .. '-' .. ruleFunc(value[2])
end
else
end,
return ruleFunc(value)
['(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
end
}
local ruleFunc = ruleFunctions[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
end


local valueArray, resultArray = nil, {}
local valueArray, resultArray = nil, {}
Line 990: 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 996: Line 1,007:
local skillName = p.getSkillName(subVal.skillID)
local skillName = p.getSkillName(subVal.skillID)
if skillName ~= nil then
if skillName ~= nil then
resultText = string.gsub(resultText, '{SV0}', skillName)
resultText = string.gsub(resultText, '${skillName}', skillName)
end
end
else
else
Line 1,003: Line 1,014:
end
end


local valSign = (valueUnsigned and '' or sign or '')
resultText = string.gsub(resultText, '${value}', function(rule) return (formatModValue(modMagnitude, rule) or '') end)
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,183: 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