Module:Constants: Difference between revisions

Attempting to indent via find & replace
m (Fix modifier typos)
(Attempting to indent via find & replace)
Line 8: Line 8:
--Just hardcoding these because I guess that's where we're at
--Just hardcoding these because I guess that's where we're at
local modifierTypes = {
local modifierTypes = {
  ["MeleeStrengthBonus"] = { text = "{V}% Melee Strength Bonus", skills = {'Combat'} },
["MeleeStrengthBonus"] = { text = "{V}% Melee Strength Bonus", skills = {'Combat'} },
  ["DamageToDungeonMonsters"] = { text = "{V}% Damage To Dungeon Monsters", skills = {'Combat'} },
["DamageToDungeonMonsters"] = { text = "{V}% Damage To Dungeon Monsters", skills = {'Combat'} },
  ["GlobalMasteryXP"] = { text = "{V}% Global Mastery XP", skills = {'Woodcutting', 'Fishing', 'Firemaking', 'Cooking', 'Mining', 'Smithing', 'Thieving', 'Farming', 'Fletching', 'Crafting', 'Runecrafting', 'Herblore', 'Agility', 'Summoning', 'Astrology'} },
["GlobalMasteryXP"] = { text = "{V}% Global Mastery XP", skills = {'Woodcutting', 'Fishing', 'Firemaking', 'Cooking', 'Mining', 'Smithing', 'Thieving', 'Farming', 'Fletching', 'Crafting', 'Runecrafting', 'Herblore', 'Agility', 'Summoning', 'Astrology'} },
  ["ChanceRandomPotionHerblore"] = { text = "{V}% chance to gain a second potion of a random tier", skills = {'Herblore'} },
["ChanceRandomPotionHerblore"] = { text = "{V}% chance to gain a second potion of a random tier", skills = {'Herblore'} },
  ["FlatPrayerCostReduction"] = { text = "{V} Prayer Point Cost for Prayers", inverseSign = true, skills = {'Prayer'} },
["FlatPrayerCostReduction"] = { text = "{V} Prayer Point Cost for Prayers", inverseSign = true, skills = {'Prayer'} },
  ["MinEarthSpellDmg"] = { text = "{VX} Min Earth Spell Dmg", skills = {'Magic'} },
["MinEarthSpellDmg"] = { text = "{VX} Min Earth Spell Dmg", skills = {'Magic'} },
  ["SlayerTaskLength"] = { text = "{V}% Slayer Task Length/Qty", skills = {'Slayer'} },
["SlayerTaskLength"] = { text = "{V}% Slayer Task Length/Qty", skills = {'Slayer'} },
  ["ChanceToDoubleLootCombat"] = { text = "{V}% Chance To Double Loot in Combat", skills = {'Combat'
["ChanceToDoubleLootCombat"] = { text = "{V}% Chance To Double Loot in Combat", skills = {'Combat'
}
}


--Difficulties are hard coded which is dumb but means hardcoding them here too
--Difficulties are hard coded which is dumb but means hardcoding them here too
local Difficulties = {  
local Difficulties = {  
    [0] = 'Very Easy',
[0] = 'Very Easy',
    [1] = 'Easy',
[1] = 'Easy',
    [2] = 'Medium',
[2] = 'Medium',
    [3] = 'Hard',
[3] = 'Hard',
    [4] = 'Very Hard',
[4] = 'Very Hard',
    [5] = 'Elite',
[5] = 'Elite',
    [6] = 'Insane'}
[6] = 'Insane'}


--07/03/21: Hardcoding in Combat Triangle Modifiers
--07/03/21: Hardcoding in Combat Triangle Modifiers
local CombatTriangle = {
local CombatTriangle = {
  damageBonus = 1.1,  
damageBonus = 1.1,  
  drBonus = 1.25,
drBonus = 1.25,
  damagePenalty = { Normal = 0.85,
damagePenalty = { Normal = 0.85,
                    Hardcore = 0.75 },
Hardcore = 0.75 },
  drPenalty = { Melee = { Normal = 0.5,
drPenalty = { Melee = { Normal = 0.5,
                          Hardcore = 0.25 },
Hardcore = 0.25 },
                Ranged = { Normal = 0.95,
Ranged = { Normal = 0.95,
                          Hardcore = 0.75 },
Hardcore = 0.75 },
                Magic = { Normal = 0.85,
Magic = { Normal = 0.85,
                          Hardcore = 0.75 }},
Hardcore = 0.75 }},
  Melee = { bonus = "Ranged", penalty = "Magic" },
Melee = { bonus = "Ranged", penalty = "Magic" },
  Ranged = { bonus = "Magic", penalty = "Melee" },
Ranged = { bonus = "Magic", penalty = "Melee" },
  Magic = { bonus = "Melee", penalty = "Ranged" },
Magic = { bonus = "Melee", penalty = "Ranged" },
}
}


function p.getTriangleDamageModifier(playerStyle, enemyStyle, mode)
function p.getTriangleDamageModifier(playerStyle, enemyStyle, mode)
  if CombatTriangle[playerStyle].bonus == enemyStyle then
if CombatTriangle[playerStyle].bonus == enemyStyle then
    return CombatTriangle.damageBonus
return CombatTriangle.damageBonus
  elseif CombatTriangle[playerStyle].penalty == enemyStyle then
elseif CombatTriangle[playerStyle].penalty == enemyStyle then
    if mode == 'Hardcore' or mode == 'Adventure' then
if mode == 'Hardcore' or mode == 'Adventure' then
      return CombatTriangle.damagePenalty.Hardcore
return CombatTriangle.damagePenalty.Hardcore
    else
else
      return CombatTriangle.damagePenalty.Normal
return CombatTriangle.damagePenalty.Normal
    end
end
  else
else
    return 1
return 1
  end
end
end
end


Line 364: Line 364:
--Returns a multiplier that can be multiplied with base DR to get the post-Triangle result
--Returns a multiplier that can be multiplied with base DR to get the post-Triangle result
function p.getTriangleDRModifier(playerStyle, enemyStyle, mode)
function p.getTriangleDRModifier(playerStyle, enemyStyle, mode)
  if CombatTriangle[playerStyle].bonus == enemyStyle then
if CombatTriangle[playerStyle].bonus == enemyStyle then
    return CombatTriangle.drBonus
return CombatTriangle.drBonus
  elseif CombatTriangle[playerStyle].penalty == enemyStyle then
elseif CombatTriangle[playerStyle].penalty == enemyStyle then
    if mode == 'Hardcore' or mode == 'Adventure' then
if mode == 'Hardcore' or mode == 'Adventure' then
      return CombatTriangle.drPenalty[playerStyle].Hardcore
return CombatTriangle.drPenalty[playerStyle].Hardcore
    else
else
      return CombatTriangle.drPenalty[playerStyle].Normal
return CombatTriangle.drPenalty[playerStyle].Normal
    end
end
  else
else
    return 1
return 1
  end
end
end
end


function p.getDifficultyString(difficulty)
function p.getDifficultyString(difficulty)
  return Difficulties[difficulty]
return Difficulties[difficulty]
end
end


Line 390: Line 390:


function p.getEquipmentSlotName(id)
function p.getEquipmentSlotName(id)
  return type(id) == 'number' and ConstantData.equipmentSlot[id] or 'Invalid'
return type(id) == 'number' and ConstantData.equipmentSlot[id] or 'Invalid'
end
end


function p.getEquipmentSlotID(name)
function p.getEquipmentSlotID(name)
  return ConstantData.equipmentSlot[name]
return ConstantData.equipmentSlot[name]
end
end


function p.getCombatStyleName(styleNum)
function p.getCombatStyleName(styleNum)
  if type(styleNum) == 'number' then
if type(styleNum) == 'number' then
  local styleName = ConstantData.attackType[styleNum]
local styleName = ConstantData.attackType[styleNum]
  if styleName ~= nil then
if styleName ~= nil then
    return Shared.titleCase(styleName)
return Shared.titleCase(styleName)
    end
end
  end
end
  return "ERROR: Invalid combat style[[Category:Pages with script errors]]"
return "ERROR: Invalid combat style[[Category:Pages with script errors]]"
end
end


function p.getSlayerTierName(tier)
function p.getSlayerTierName(tier)
  return type(tier) == 'number' and ConstantData.slayerTier[tier] or "ERROR: Invalid Slayer tier[[Category:Pages with script errors]]"
return type(tier) == 'number' and ConstantData.slayerTier[tier] or "ERROR: Invalid Slayer tier[[Category:Pages with script errors]]"
end
end


function p.getSlayerTierNameByLevel(lvl)
function p.getSlayerTierNameByLevel(lvl)
  for i, tier in Shared.skpairs(ConstantData.Slayer.Tiers) do
for i, tier in Shared.skpairs(ConstantData.Slayer.Tiers) do
    if tier.minLevel <= lvl and (tier.maxLevel == nil or tier.maxLevel >= lvl) then
if tier.minLevel <= lvl and (tier.maxLevel == nil or tier.maxLevel >= lvl) then
      return tier.display
return tier.display
    end
end
  end
end
  return 'N/A'
return 'N/A'
end
end


function p.getSlayerTier(name)
function p.getSlayerTier(name)
  for i, tier in Shared.skpairs(ConstantData.Slayer.Tiers) do
for i, tier in Shared.skpairs(ConstantData.Slayer.Tiers) do
    if tier.display == name then
if tier.display == name then
      local result = Shared.clone(tier)
local result = Shared.clone(tier)
      result.id = i - 1
result.id = i - 1
      return result
return result
    end
end
  end
end
end
end


function p.getSlayerTierByID(tierID)
function p.getSlayerTierByID(tierID)
  if ConstantData.Slayer.Tiers[tierID + 1] == nil then
if ConstantData.Slayer.Tiers[tierID + 1] == nil then
    return nil
return nil
  end
end


  local result = Shared.clone(ConstantData.Slayer.Tiers[tierID + 1])
local result = Shared.clone(ConstantData.Slayer.Tiers[tierID + 1])
  result.id = tierID
result.id = tierID
  return result
return result
end
end


Line 444: Line 444:
--ex. "MeleeAccuracyBonus", "+{V}% Melee Accuracy", "+", false
--ex. "MeleeAccuracyBonus", "+{V}% Melee Accuracy", "+", false
function p.getModifierDetails(modifierName)
function p.getModifierDetails(modifierName)
  local baseName = modifierName
local baseName = modifierName
  local isIncrease = true
local isIncrease = true
  local isNegative = false
local isNegative = false
  local valueUnsigned = false
local valueUnsigned = false


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


  local modifier = modifierTypes[baseName]
local modifier = modifierTypes[baseName]
  if modifier == nil then
if modifier == nil then
    return nil
return nil
  end
end


  local isPositive = isIncrease
local isPositive = isIncrease
  if modifier.isIncreaseNegative then
if modifier.isIncreaseNegative then
    isPositive = not isPositive
isPositive = not isPositive
  end
end


  local sign = "+"
local sign = "+"
  if (not isIncrease and not modifier.inverseSign) or (isIncrease and modifier.inverseSign) then
if (not isIncrease and not modifier.inverseSign) or (isIncrease and modifier.inverseSign) then
    sign = "-"
sign = "-"
  end
end


  if type(modifier.unsigned) == 'boolean' then valueUnsigned = modifier.unsigned end
if type(modifier.unsigned) == 'boolean' then valueUnsigned = modifier.unsigned end


  return baseName, modifier.text, sign, not isPositive, valueUnsigned, modifier
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, sign, isNegative, valueUnsigned = p.getModifierDetails(modifier)


  if modName == nil then
if modName == nil then
    return 'ERROR: Invalid modifier type for ' .. modifier .. '[[Category:Pages with script errors]]'
return 'ERROR: Invalid modifier type for ' .. modifier .. '[[Category:Pages with script errors]]'
  end
end


  local result = modText
local result = modText


  if type(value) == 'table' then
if type(value) == 'table' then
    if Shared.tableCount(value) > 0 and type(value[1]) == 'table' then
if Shared.tableCount(value) > 0 and type(value[1]) == 'table' then
      --Potentially return multiple rows if necessary
--Potentially return multiple rows if necessary
      local resultArray = {}
local resultArray = {}
      for i, subVal in Shared.skpairs(value) do
for i, subVal in Shared.skpairs(value) do
        table.insert(resultArray, p._getModifierText(modifier, subVal, doColor))
table.insert(resultArray, p._getModifierText(modifier, subVal, doColor))
      end
end
      return table.concat(resultArray, '<br/>')
return table.concat(resultArray, '<br/>')
    else
else
      if value[1] ~= nil then
if value[1] ~= nil then
        local skillName = p.getSkillName(value[1])
local skillName = p.getSkillName(value[1])
        if skillName ~= nil then
if skillName ~= nil then
          result = string.gsub(result, '{SV0}', p.getSkillName(value[1]))
result = string.gsub(result, '{SV0}', p.getSkillName(value[1]))
        end
end
      end
end
      if value[2] ~= nil then value = value[2] end
if value[2] ~= nil then value = value[2] end
    end
end
  end
end
  -- Re-check the type of value, as it may have been modified above even if it was originally a table
-- Re-check the type of value, as it may have been modified above even if it was originally a table
  if type(value) ~= 'table' then
if type(value) ~= 'table' then
    local valSign = (valueUnsigned and '' or sign)
local valSign = (valueUnsigned and '' or sign)
    if string.find(result, '{IV}', 1, true) ~= nil and tonumber(value) ~= nil then
if string.find(result, '{IV}', 1, true) ~= nil and tonumber(value) ~= nil then
      local item = ItemData.Items[tonumber(value) + 1]
local item = ItemData.Items[tonumber(value) + 1]
      if item ~= nil then
if item ~= nil then
        result = string.gsub(result, '{IV}', item.name)
result = string.gsub(result, '{IV}', item.name)
      end
end
    end
end
    result = string.gsub(result, '{V}', valSign..value)
result = string.gsub(result, '{V}', valSign..value)
    result = string.gsub(result, '{VD}', valSign..(value / 10))
result = string.gsub(result, '{VD}', valSign..(value / 10))
    result = string.gsub(result, '{VMS}', valSign..(value / 1000))
result = string.gsub(result, '{VMS}', valSign..(value / 1000))
    result = string.gsub(result, '{VX}', valSign..(value * 10))
result = string.gsub(result, '{VX}', valSign..(value * 10))
    result = string.gsub(result, '{VX100}', valSign..(value * 100))
result = string.gsub(result, '{VX100}', valSign..(value * 100))
    result = string.gsub(result, '{V%+100}', valSign..(value + 100))
result = string.gsub(result, '{V%+100}', valSign..(value + 100))
    result = string.gsub(result, '{VMUL}', 2^value)
result = string.gsub(result, '{VMUL}', 2^value)
    result = string.gsub(result, '{S}', sign)
result = string.gsub(result, '{S}', sign)
  end
end


  if doColor then
if doColor then
    if isNegative ~= nil and isNegative then
if isNegative ~= nil and isNegative then
      result = '<span style="color:red">'..result..'</span>'
result = '<span style="color:red">'..result..'</span>'
    else
else
      result = '<span style="color:green">'..result..'</span>'
result = '<span style="color:green">'..result..'</span>'
    end
end
  end
end


  return result
return result
end
end


function p.getModifierText(frame)
function p.getModifierText(frame)
  local modifier = frame.args ~= nil and frame.args[1] or frame[1]
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 value = frame.args ~= nil and frame.args[2] or frame[2]
  local skill = frame.args ~= nil and frame.args.skill or frame.skill
local skill = frame.args ~= nil and frame.args.skill or frame.skill
  local doColor = frame.args ~= nil and frame.args[3] or frame[3]
local doColor = frame.args ~= nil and frame.args[3] or frame[3]


  if doColor ~= nil then
if doColor ~= nil then
    doColor = string.upper(doColor) ~= 'FALSE'
doColor = string.upper(doColor) ~= 'FALSE'
  end
end


  if skill ~= nil and skill ~= '' then
if skill ~= nil and skill ~= '' then
    value = {p.getSkillID(skill), value}
value = {p.getSkillID(skill), value}
  end
end


  return p._getModifierText(modifier, value, doColor)
return p._getModifierText(modifier, value, doColor)
end
end


function p.getModifiersText(modifiers, doColor)
function p.getModifiersText(modifiers, doColor)
  if modifiers == nil or Shared.tableCount(modifiers) == 0 then
if modifiers == nil or Shared.tableCount(modifiers) == 0 then
    return ''
return ''
  end
end


  local modArray = {}
local modArray = {}
  for bonus, value in Shared.skpairs(modifiers) do
for bonus, value in Shared.skpairs(modifiers) do
    table.insert(modArray, p._getModifierText(bonus, value, doColor))
table.insert(modArray, p._getModifierText(bonus, value, doColor))
  end
end
  return table.concat(modArray, "<br/>")
return table.concat(modArray, "<br/>")
end
end


function p.getModifierSkills(modifiers)
function p.getModifierSkills(modifiers)
  local skillArray = {}
local skillArray = {}


  for modifier, value in Shared.skpairs(modifiers) do
for modifier, value in Shared.skpairs(modifiers) do
    if type(value) == 'table' then
if type(value) == 'table' then
      for i, subVal in Shared.skpairs(value) do
for i, subVal in Shared.skpairs(value) do
        local skillName = p.getSkillName(subVal[1])
local skillName = p.getSkillName(subVal[1])
        if not Shared.contains(skillArray, skillName) then
if not Shared.contains(skillArray, skillName) then
          table.insert(skillArray, skillName)
table.insert(skillArray, skillName)
        end
end
      end
end
    end
end


    local baseName = p.getModifierDetails(modifier)
local baseName = p.getModifierDetails(modifier)
    if baseName == nil then
if baseName == nil then
      return { 'ERROR: Modifier '..modifier..' is invalid' }
return { 'ERROR: Modifier '..modifier..' is invalid' }
    end
end


    if modifierTypes[baseName].skills ~= nil then
if modifierTypes[baseName].skills ~= nil then
      for i, skillName in Shared.skpairs(modifierTypes[baseName].skills) do
for i, skillName in Shared.skpairs(modifierTypes[baseName].skills) do
        if not Shared.contains(skillArray, skillName) then
if not Shared.contains(skillArray, skillName) then
          table.insert(skillArray, skillName)
table.insert(skillArray, skillName)
        end
end
      end
end
    end
end
  end
end


  return skillArray
return skillArray
end
end


return p
return p