Module:Constants
From Melvor Idle
Documentation for this module may be created at Module:Constants/doc
local p = {}
local ConstantData = mw.loadData('Module:Constants/data')
local ItemData = mw.loadData('Module:Items/data')
local Shared = require('Module:Shared')
--Just hardcoding these because I guess that's where we're at
local modifierTypes = {
["increasedGlobalAccuracy"] = { text = "+{V}% Global Accuracy", },
["increasedMeleeAccuracyBonus"] = { text = "+{V}% Melee Accuracy Bonus", },
["increasedMeleeStrengthBonus"] = { text = "+{V}% Melee Strength Bonus", },
["increasedMeleeEvasion"] = { text = "+{V}% Melee Evasion", },
["increasedRangedAccuracyBonus"] = { text = "+{V}% Ranged Accuracy Bonus", },
["increasedRangedStrengthBonus"] = { text = "+{V}% Ranged Strength Bonus", },
["increasedRangedEvasion"] = { text = "+{V}% Ranged Evasion", },
["increasedMagicAccuracyBonus"] = { text = "+{V}% Magic Accuracy Bonus", },
["increasedMagicDamageBonus"] = { text = "+{V}% Magic Damage Bonus", },
["increasedMagicEvasion"] = { text = "+{V}% Magic Evasion", },
["increasedMaxHitFlat"] = { text = "+{VX} Max Hit", },
["increasedMaxHitPercent"] = { text = "+{V}% Max Hit", },
["increasedDamageReduction"] = { text = "+{V}% Damage Reduction", },
["increasedChanceToDoubleLootCombat"] = { text = "+{V}% Chance To Double Loot in Combat", },
["increasedSlayerCoins"] = { text = "+{V}% Slayer Coins", },
["increasedSlayerXP"] = { text = "+{V}% Slayer XP", },
["increasedHPRegenFlat"] = { text = "+{V} Flat HP Regen", },
["increasedGPGlobal"] = { text = "+{V}% Global GP (except Item Sales)", },
["increasedGPFromMonsters"] = { text = "+{V}% GP From Monsters", },
["increasedGPFromMonstersFlat"] = { text = "+{V} GP From Monsters", },
["increasedGPFromThieving"] = { text = "+{V}% GP From Thieving", },
["increasedGPFromThievingFlat"] = { text = "+{V} GP From Thieving", },
["increasedGPFromAgility"] = { text = "+{V}% GP From Agility", },
["decreasedGPFromAgility"] = { text = "-{V}% GP From Agility", isNegative = true },
["increasedDamageToBosses"] = { text = "+{V}% Damage To Bosses", },
["increasedDamageToSlayerTasks"] = { text = "+{V}% Damage To Slayer Tasks", },
["increasedDamageToSlayerAreaMonsters"] = { text = "+{V}% Damage To Slayer Area Monsters", },
["increasedDamageToCombatAreaMonsters"] = { text = "+{V}% Damage To Combat Area Monsters", },
["increasedDamageToDungeonMonsters"] = { text = "+{V}% Damage To Dungeon Monsters", },
["increasedDamageToAllMonsters"] = { text = "+{V}% Damage To All Monsters", },
["increasedAutoEatEfficiency"] = { text = "+{V}% Auto Eat Efficiency", },
["increasedAutoEatThreshold"] = { text = "+{V}% Auto Eat Threshold", },
["increasedAutoEatHPLimit"] = { text = "+{V}% Auto Eat HP Limit", },
["increasedFoodHealingValue"] = { text = "+{V}% Food Healing Value", },
["increasedChanceToPreservePrayerPoints"] = { text = "+{V}% Chance To Preserve Prayer Points", },
["increasedMinAirSpellDmg"] = { text = "+{VX} Min Air Spell Dmg", },
["increasedMinWaterSpellDmg"] = { text = "+{VX} Min Water Spell Dmg", },
["increasedMinEarthSpellDmg"] = { text = "+{VX} Min Earth Spell Dmg", },
["increasedMinFireSpellDmg"] = { text = "+{VX} Min Fire Spell Dmg", },
["increasedAmmoPreservation"] = { text = "+{V}% Ammo Preservation", },
["increasedRunePreservation"] = { text = "+{V}% Rune Preservation", },
["increasedHiddenSkillLevel"] = { text = "+{V1} Hidden {SV0} Level", },
["decreasedPlayerAttackSpeed"] = { text = "-{VMS}s Player Attack Speed", },
["decreasedPlayerAttackSpeedPercent"] = { text = "-{V}% Player Attack Speed", },
["increasedSlayerAreaEffectNegationFlat"] = { text = "+{V}% Flat Slayer Area Effect Negation", },
["decreasedMonsterRespawnTimer"] = { text = "-{VMS}s Monster Respawn Timer", },
["decreasedGlobalAccuracy"] = { text = "-{V}% Global Accuracy", isNegative = true },
["decreasedMeleeAccuracyBonus"] = { text = "-{V}% Melee Accuracy Bonus", isNegative = true },
["decreasedMeleeStrengthBonus"] = { text = "-{V}% Melee Strength Bonus", isNegative = true },
["decreasedMeleeEvasion"] = { text = "-{V}% Melee Evasion", isNegative = true },
["decreasedRangedAccuracyBonus"] = { text = "-{V} Ranged Accuracy Bonus", isNegative = true },
["decreasedRangedStrengthBonus"] = { text = "-{V}% Ranged Strength Bonus", isNegative = true },
["decreasedRangedEvasion"] = { text = "-{V}% Ranged Evasion", isNegative = true },
["decreasedMagicAccuracyBonus"] = { text = "-{V}% Magic Accuracy Bonus", isNegative = true },
["decreasedMagicDamageBonus"] = { text = "-{V}% Magic Damage Bonus", isNegative = true },
["decreasedMagicEvasion"] = { text = "-{V}% Magic Evasion", isNegative = true },
["decreasedMaxHitFlat"] = { text = "-{VX} Max Hit", isNegative = true },
["decreasedMaxHitPercent"] = { text = "-{V}% Max Hit", isNegative = true },
["decreasedDamageReduction"] = { text = "-{V}% Damage Reduction", isNegative = true },
["decreasedChanceToDoubleLootCombat"] = { text = "-{V}% Chance To Double Loot in Combat", isNegative = true },
["decreasedSlayerCoins"] = { text = "-{V}% Slayer Coins", isNegative = true },
["decreasedSlayerXP"] = { text = "-{V}% Slayer XP", isNegative = true },
["decreasedHPRegenFlat"] = { text = "-{V} Flat HP Regen", isNegative = true },
["decreasedGPGlobal"] = { text = "-{V}% GP from all sources (Except Item Selling)", isNegative = true },
["decreasedGPFromMonsters"] = { text = "-{V}% GP From Monsters", isNegative = true },
["decreasedGPFromMonstersFlat"] = { text = "-{V} GP From Monsters", isNegative = true },
["decreasedDamageToBosses"] = { text = "-{V}% Damage To Bosses", isNegative = true },
["decreasedDamageToSlayerTasks"] = { text = "-{V}% Damage To Slayer Tasks", isNegative = true },
["decreasedDamageToSlayerAreaMonsters"] = { text = "-{V}% Damage To Slayer Area Monsters", isNegative = true },
["decreasedDamageToCombatAreaMonsters"] = { text = "-{V}% Damage To Combat Area Monsters", isNegative = true },
["decreasedDamageToDungeonMonsters"] = { text = "-{V}% Damage To Dungeon Monsters", isNegative = true },
["decreasedDamageToAllMonsters"] = { text = "-{V}% Damage To All Monsters", isNegative = true },
["decreasedAutoEatEfficiency"] = { text = "-{V}% Auto Eat Efficiency", isNegative = true },
["decreasedAutoEatThreshold"] = { text = "-{V}% Auto Eat Threshold", isNegative = true },
["decreasedAutoEatHPLimit"] = { text = "-{V}% Auto Eat HP Limit", isNegative = true },
["decreasedFoodHealingValue"] = { text = "-{V}% Food Healing Value", isNegative = true },
["decreasedChanceToPreservePrayerPoints"] = { text = "-{V}% Chance To Preserve Prayer Points", isNegative = true },
["decreasedMinAirSpellDmg"] = { text = "-{VX} Min Air Spell Dmg", isNegative = true },
["decreasedMinWaterSpellDmg"] = { text = "-{VX} Min Water Spell Dmg", isNegative = true },
["decreasedMinEarthSpellDmg"] = { text = "-{VX} Min Earth Spell Dmg", isNegative = true },
["decreasedMinFireSpellDmg"] = { text = "-{VX} Min Fire Spell Dmg", isNegative = true },
["decreasedAmmoPreservation"] = { text = "-{V}% Ammo Preservation", isNegative = true },
["decreasedRunePreservation"] = { text = "-{V}% Rune Preservation", isNegative = true },
["decreasedHiddenSkillLevel"] = { text = "-{V1} Hidden {SV0} Level", isNegative = true },
["increasedPlayerAttackSpeed"] = { text = "+{VMS}s Player Attack Speed", isNegative = true },
["increasedPlayerAttackSpeedPercent"] = { text = "+{V}% Player Attack Speed", isNegative = true },
["increasedMonsterRespawnTimer"] = { text = "+{VMS}s Monster Respawn Timer", isNegative = true },
["decreasedSlayerAreaEffectNegationFlat"] = { text = "-{V}% Flat Slayer Area Effect Negation", isNegative = true },
["increasedGPFromSales"] = { text = "+{V}% GP From Sales", },
["increasedBankSpace"] = { text = "+{V} Bank Space", },
["increasedBankSpaceShop"] = { text = "+{V} Bank Space from Shop", },
["increasedChanceToPreservePotionCharge"] = { text = "+{V}% Chance To Preserve Potion Charge", },
["decreasedGPFromSales"] = { text = "-{V}% GP From Sales", isNegative = true },
["decreasedBankSpace"] = { text = "-{V} Bank Space", isNegative = true },
["decreasedBankSpaceShop"] = { text = "-{V} Bank Space from Shop", isNegative = true },
["decreasedChanceToPreservePotionCharge"] = { text = "-{V}% Chance To Preserve Potion Charge", isNegative = true },
["decreasedSkillInterval"] = { text = "-{VMS1}s {SV0} Interval", },
["decreasedSkillIntervalPercent"] = { text = "-{V1}% {SV0} Interval", },
["increasedChanceToDoubleLootThieving"] = { text = "+{V}% Chance To Double Loot in Thieving", },
["increasedPreservationChance"] = { text = "+{V}% Chance to Preserve Resources", },
["increasedStaminaPreservationChance"] = { text = "+{V}% Chance to Preserve Stamina", },
["increasedGlobalMasteryXP"] = { text = "+{V}% Global Mastery XP", },
["increasedGlobalSkillXP"] = { text = "+{V}% Global Skill XP", },
["decreasedGlobalSkillXP"] = { text = "-{V}% Global Skill XP", isNegative = true },
["increasedMasteryXP"] = { text = "+{V1}% {SV0} Mastery XP", },
["increasedSkillXP"] = { text = "+{V1}% {SV0} Skill XP", },
["increasedMaxStamina"] = { text = "+{V}% Max Stamina", },
["increasedMiningNodeHP"] = { text = "+{V} Mining Node HP", },
["increasedSkillInterval"] = { text = "+{VMS1}s {SV0} Interval", isNegative = true },
["increasedSkillIntervalPercent"] = { text = "+{V1}% {SV0} Interval", isNegative = true },
["decreasedChanceToDoubleLootThieving"] = { text = "-{V}% Chance To Double Loot in Thieving", isNegative = true },
["decreasedPreservationChance"] = { text = "-{V}% Chance to Preserve Resources", isNegative = true },
["decreasedStaminaPreservationChance"] = { text = "-{V}% Chance to Preserve Stamina", isNegative = true },
["decreasedGlobalMasteryXP"] = { text = "-{V}% Global Mastery XP", isNegative = true },
["decreasedMasteryXP"] = { text = "-{V1}% {SV0} Mastery XP", isNegative = true },
["decreasedSkillXP"] = { text = "-{V1}% {SV0} Skill XP", isNegative = true },
["decreasedMaxStamina"] = { text = "-{V} Max Stamina", isNegative = true },
["decreasedMiningNodeHP"] = { text = "-{V} Mining Node HP", isNegative = true },
["decreasedGPFromThieving"] = { text = "-{V}% GP From Thieving", isNegative = true },
["decreasedGPFromThievingFlat"] = { text = "-{V} GP From Thieving", isNegative = true },
["dungeonEquipmentSwapping"] = { text = "{V} Dungeon Equipment Swapping", },
["increasedEquipmentSets"] = { text = "+{V} Equipment Sets", },
["autoSlayerUnlocked"] = { text = "{V} Auto Slayer Unlocked", },
["increasedTreeCutLimit"] = { text = "+{V} Tree Cut Limit", },
["increasedChanceToDoubleItems"] = { text = "+{V} Chance To Double Items", },
["decreasedChanceToDoubleItems"] = { text = "-{V} Chance To Double Items", isNegative = true },
["increasedGlobalPreservationChance"] = { text = "+{V}% Chance to Preserve Resources in Skills", },
["decreasedGlobalPreservationChance"] = { text = "-{V}% Chance to Preserve Resources in Skills", isNegative = true },
["increasedFarmingYield"] = { text = "+{V}% Farming Yield", },
["decreasedFarmingYield"] = { text = "-{V}% Farming Yield", isNegative = true },
["increasedMaxHitpoints"] = { text = "+{VX} Maximum Hitpoints", },
["decreasedMaxHitpoints"] = { text = "-{VX} Maximum Hitpoints", isNegative = true },
["increasedStaminaPerObstacle"] = { text = "+{V} Stamina per Agility Obstacle Completion", },
["decreasedStaminaPerObstacle"] = { text = "+{V} Stamina per Agility Obstacle Completion", isNegative = true },
["increasedSlayerTaskLength"] = { text = "+{V}% Slayer Task Length/Qty", },
["decreasedSlayerTaskLength"] = { text = "+{V}% Slayer Task Length/Qty", isNegative = true },
["decreasedFlatPrayerCostReduction"] = { text = "+{V} Prayer Point Cost for Prayers", isNegative = true },
["increasedFlatPrayerCostReduction"] = { text = "-{V} Prayer Point Cost for Prayers", },
["increasedStaminaCost"] = { text = "+{V} Stamina Cost per action", isNegative = true },
["decreasedStaminaCost"] = { text = "+{V} Stamina Cost per action", },
["increasedChanceToDoubleItemsSkill"] = { text = "+{V1}% Chance to Double Items in {SV0}", },
["decreasedChanceToDoubleItemsSkill"] = { text = "+{V1}% Chance to Double Items in {SV0}", isNegative = true },
["increasedChanceToDoubleItemsGlobal"] = { text = "+{V}% Chance to Double Items Globally", },
["decreasedChanceToDoubleItemsGlobal"] = { text = "+{V}% Chance to Double Items Globally", isNegative = true },
["increasedLifesteal"] = { text = "+{V}% Lifesteal", },
["decreasedLifesteal"] = { text = "+{V}% Lifesteal", isNegative = true },
["increasedReflectDamage"] = { text = "+{V}% Reflect Damage", },
["decreasedReflectDamage"] = { text = "+{V}% Reflect Damage", isNegative = true },
["increasedSkillPreservationChance"] = { text = "+{V1}% Chance to Preserve Resources in {SV0}", },
["decreasedSkillPreservationChance"] = { text = "-{V1}% Chance to Preserve Resources in {SV0}", isNegative = true},
["increasedChanceToDoubleOres"] = { text = "+{V}% Chance to Double Ores in Mining" },
["decreasedChanceToDoubleOres"] = { text = "-{V}% Chance to Double Ores in Mining", isNegative = true },
["increasedHitpointRegeneration"] = { text = "+{V}% Hitpoint Regeneration" },
["decreasedHitpointRegeneration"] = { text = "-{V}% Hitpoint Regeneration", isNegative = true },
["increasedMinHitBasedOnMaxHit"] = { text = "+{V}% of Maximum Hit added to Minimum Hit" },
["decreasedMinHitBasedOnMaxHit"] = { text = "-{V}% of Maximum Hit added to Minimum Hit", isNegative = true },
["increasedPotionChargesFlat"] = { text = "+{V} Charges per Potion" },
["decreasedPotionChargesFlat"] = { text = "-{V} Charges per Potion", isNegative = true },
["golbinRaidStartingWeapon"] = { text = "Start the Golbin Raid with an {IV}" },
["golbinRaidIncreasedStartingRuneCount"] = { text = "+{V} to starting Elemental Rune count" },
--Rows below here are custom handlers for things the game doesn't include yet
["increasedChanceForElementalRune"] = { text = "+{V}% chance to receive random elemental runes per Runecraft"},
["increasedElementalRuneGain"] = { text = "+{V} runes received when generating random elemental runes"},
["increasedBirdNestDropRate"] = { text = "+{V}% Bird Nest drop rate" },
["increasedAttackRolls"] = { text = "+Lucky Hit Chance (Roll twice, take the better result)" },
["increasedChanceDoubleHarvest"] = { text = "+{V}% chance for double harvest" },
["increasedChanceNoDamageMining"] = { text = "+{V}% chance to do zero damage to Ores and Rune Essence" },
["increasedSeeingGoldChance"] = { text = "+{V}% chance for Silver Ore to also produce a Gold Bar when smithed" },
["decreasedBonfireLogCost"] = { text = "+ Automatically relight bonfires for free" },
["increasedChanceRandomPotionHerblore"] = { text = "+{V}% chance to gain a second potion of a random tier" }
}
function p.getSkillName(skillID)
for skName, ID in Shared.skpairs(ConstantData.skill) do
if ID == skillID then
return skName
end
end
return nil
end
function p.getEquipmentSlotName(id)
for slotName, i in Shared.skpairs(ConstantData.equipmentSlot) do
if i == id then
return slotName
end
end
return 'Invalid'
end
function p.getSkillID(skillName)
return ConstantData.skill[skillName]
end
function p._getModifierText(modifier, value, doColor)
if doColor == nil then doColor = true end
local template = modifierTypes[modifier]
if template == nil then
return 'ERROR: Invalid modifier type [[Category:Pages with script errors]]'
end
local result = template.text
if type(value) == 'table' then
if Shared.tableCount(value) > 0 and type(value[1]) == 'table' then
--Potentially return multiple rows if necessay
local resultArray = {}
for i, subVal in Shared.skpairs(value) do
table.insert(resultArray, p._getModifierText(modifier, subVal, doColor))
end
return table.concat(resultArray, '<br/>')
else
if value[1] ~= nil then
local skillName = p.getSkillName(value[1])
if skillName ~= nil then
result = string.gsub(result, '{SV0}', p.getSkillName(value[1]))
end
end
if value[2] ~= nil then
result = string.gsub(result, '{V1}', value[2])
result = string.gsub(result, '{VMS1}', value[2] / 1000)
end
end
else
if string.find(result, '{IV}', 1, true) ~= nil and tonumber(value) ~= nil then
local item = ItemData.Items[tonumber(value) + 1]
if item ~= nil then
result = string.gsub(result, '{IV}', item.name)
end
end
result = string.gsub(result, '{V}', value)
result = string.gsub(result, '{VMS}', value / 1000)
result = string.gsub(result, '{VX}', value * 10)
end
if doColor then
if template.isNegative ~= nil and template.isNegative then
result = '<span style="color:red">'..result..'</span>'
else
result = '<span style="color:green">'..result..'</span>'
end
end
return result
end
function p.getModifierText(frame)
local modifier = frame.args ~= nil and frame.args[1] or frame[1]
local value = frame.args ~= nil and frame.args[2] or frame[2]
local skill = frame.args ~= nil and frame.args.skill or frame.skill
local doColor = frame.args ~= nil and frame.args[3] or frame[3]
if doColor ~= nil then
doColor = strupper(doColor) ~= 'FALSE'
end
if skill ~= nil then
value = {p.getSkillID(skill), value}
end
return p._getModifierText(modifier, value, doColor)
end
return p