Advertisement
Guest User

UndauntedShoulderCollector.lua

a guest
Aug 20th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.90 KB | None | 0 0
  1. -- Creating a chat proxy and setting long and short addon tag names
  2. -- Each print will be prefixed by the addon tag, depending on user settings the long, short or neither tag will be used
  3. local chat = LibChatMessage("Undaunted Shoulder Collector", "USC")
  4.  
  5. UndauntedShoulderCollector = {
  6.     dashedLines = "------------------------------------------------",
  7.     mysteryCofferMaj = "Maj's Mystery Coffer",
  8.     mysteryCofferGlirion = "Glirion's Mystery Coffer",
  9.     mysteryCofferUrgarlag = "Urgarlag's Mystery Coffer",
  10. }
  11.  
  12. UndauntedShoulderCollector.name = "UndauntedShoulderCollector"
  13.  
  14. -- Accepts a number
  15. -- Returns imported number truncated to 2 decimal places
  16. function UndauntedShoulderCollector.RoundToDecimalPoints(num, decPoints)
  17.   return tonumber(string.format("%." .. (decPoints) .. "f", num))
  18. end
  19.  
  20. -- Accepts set ID of an item
  21. -- Generates a string that ESO interprats as a link for an item
  22. function UndauntedShoulderCollector.MakeItemLink(id)
  23.     local itemLink = string.format("|H1:item:%d:364:50:0:0:0:0:0:0:0:0:0:0:0:0:ITEMSTYLE_NONE:0:0:0:10000:0|h|h", id)
  24.  
  25.     return(itemLink)
  26. end
  27.  
  28. -- Accepts a coffer name, amount of shoulders in that coffer and the amount of shoulders collected from that coffer
  29. -- Returns a string that will display the box name, amount of shoulders from that coffer collected as a fraction and the chance of unlocking a new piece from that coffer
  30. function UndauntedShoulderCollector.printBoxData(boxName, totalBoxShoulders, collectedBoxShoulders)
  31.     if totalBoxShoulders == collectedBoxShoulders then
  32.         return (boxName .. " (" .. collectedBoxShoulders .. "/" .. totalBoxShoulders ..") - " .. "COMPLETED")
  33.     end
  34.     return (
  35.         boxName .. " (" ..  collectedBoxShoulders .. "/" .. totalBoxShoulders .. ") - " ..
  36.         UndauntedShoulderCollector.RoundToDecimalPoints(100 - collectedBoxShoulders / totalBoxShoulders * 100, 2) .. "% chance for new"
  37.     )
  38. end
  39.  
  40. -- Accepts a mystery coffer name, amount of shoulders in that coffer and the amount of shoulders collected from that coffer
  41. -- If I've got X chance of unlocking a new piece from a mystery coffer, then i have 1 - (1-X)^5 chance of unlocking a new piece from 5 mystery coffers  - Kyzeragon
  42. -- Returns a string that will display the box name and the chance of getting at least 1 shoulder piece from spending 5 keys on that coffer
  43. function UndauntedShoulderCollector.printMysteryBox5KeyData(boxName, totalBoxShoulders, collectedBoxShoulders)
  44.     if totalBoxShoulders == collectedBoxShoulders then
  45.         return (boxName .. " - " .. "COMPLETED")
  46.     end
  47.     chanceOfOldShoulder1Key = UndauntedShoulderCollector.RoundToDecimalPoints(collectedBoxShoulders / totalBoxShoulders, 4)
  48.     chanceofNewShoulder5Key = UndauntedShoulderCollector.RoundToDecimalPoints(100 - (chanceOfOldShoulder1Key ^ 5 * 100), 2)
  49.     return (boxName .. " - " .. chanceofNewShoulder5Key .. "%" .. " chance for at least one new from 5 keys")
  50. end
  51.  
  52. -- Accepts a subtable of a pledge giver and prints links for all the tables items and states if each piece is collected
  53. -- Used only in early testing, probably should delete
  54. function UndauntedShoulderCollector.PrintLinksOfTable(inTable)
  55.     d(inTable[7])
  56.     for i = 1, #inTable - 1 do
  57.         itemLink = UndauntedShoulderCollector.MakeItemLink(inTable[i])
  58.         d(itemLink)
  59.         d(IsItemSetCollectionPieceUnlocked(GetItemLinkItemId(itemLink)))
  60.     end
  61. end
  62.  
  63. -- Accepts a subtable from data file of one of the pledge givers
  64. -- Returns the amount of shoulders that are collected and name of dungeon group from table
  65. function UndauntedShoulderCollector.AmountOfShouldersInTableCollected(inTable)
  66.     amountCollected = 0
  67.     dungeonGroup = inTable[7]
  68.    
  69.     for i = 1, #inTable - 1 do
  70.         itemLink = UndauntedShoulderCollector.MakeItemLink(inTable[i])
  71.         if (IsItemSetCollectionPieceUnlocked(GetItemLinkItemId(itemLink)))
  72.         then
  73.             amountCollected = amountCollected + 1
  74.         end
  75.     end
  76.     return amountCollected, dungeonGroup
  77. end
  78.  
  79. -- Accepts a group of tables (Maj/Glirion/Urgarlag) and name of pledge givers mystery coffer
  80. -- Displays the amount of pieces collected from each coffer the pledge giver offers as well as the chance of getting a new piece from each coffer
  81. -- Returns nothing
  82. function UndauntedShoulderCollector.ShowAllPledgeGiver(inTable, inMysteryCofferName)
  83.     totalShoulders = 0
  84.     collectedShoulders = 0
  85.     boxDataOutputStrings = {}
  86.  
  87.     for k,v in pairs(inTable) do
  88.         amountCollected, dungeonGroup = UndauntedShoulderCollector.AmountOfShouldersInTableCollected(inTable[k])
  89.         table.insert(boxDataOutputStrings, UndauntedShoulderCollector.printBoxData(dungeonGroup, 6, amountCollected))
  90.         totalShoulders = totalShoulders + 6
  91.         collectedShoulders = collectedShoulders + amountCollected
  92.     end
  93.     chat:Print(
  94.         UndauntedShoulderCollector.dashedLines ..
  95.         "\n" .. table.concat(boxDataOutputStrings, "\n") ..
  96.         "\n" .. UndauntedShoulderCollector.printBoxData(inMysteryCofferName, totalShoulders, collectedShoulders) ..
  97.         "\n" .. UndauntedShoulderCollector.printMysteryBox5KeyData(inMysteryCofferName, totalShoulders, collectedShoulders)
  98.     )
  99. end
  100.  
  101. -- Accepts a group of tables (Maj/Glirion/Urgarlag)
  102. -- Calculates the shoulder box with the highest chance of producing an uncollected shoulder per key
  103. -- Returns name of most effficient box, the amount collected of the most efficient box, overall shoulders in table and overall collected shoulders in table
  104. function UndauntedShoulderCollector.MostEfficientBoxSetPerKey(inTable)
  105.     -- Values to store data for 1 key boxes
  106.     totalShouldersAmount = 0
  107.     totalCollectedShouldersAmount = 0
  108.    
  109.     mostEfficientBox = ""
  110.     mostEfficientAmount = 100 -- Any value > 6 should do
  111.  
  112.     for k,v in pairs(inTable) do
  113.         tempAmount, tempName = UndauntedShoulderCollector.AmountOfShouldersInTableCollected(inTable[k])
  114.         totalShouldersAmount = totalShouldersAmount + 6
  115.         totalCollectedShouldersAmount = totalCollectedShouldersAmount + tempAmount
  116.         if (tempAmount < mostEfficientAmount) then
  117.             mostEfficientAmount = tempAmount
  118.             mostEfficientBox = tempName
  119.         end
  120.     end
  121.     return mostEfficientBox, mostEfficientAmount, totalShouldersAmount, totalCollectedShouldersAmount
  122. end
  123.  
  124. -- Accepts nothing
  125. -- Prints the most efficient 1 key and 5 key purchase to chat
  126. -- Returns nothing
  127. function UndauntedShoulderCollector.CalculateMostEfficientKeyPurchases()
  128.     mostEfficientBox, mostEfficientAmount, shouldersAmount, collectedShouldersAmount
  129.         = UndauntedShoulderCollector.MostEfficientBoxSetPerKey(UndauntedShoulderCollectorData.Maj)
  130.    
  131.     mostEfficientMysteryBox = "Maj's Mystery Coffer"
  132.    
  133.     tempMostEfficientBox, tempMostEfficientAmount, tempShouldersAmount, tempCollectedShouldersAmount
  134.         = UndauntedShoulderCollector.MostEfficientBoxSetPerKey(UndauntedShoulderCollectorData.Glirion)
  135.    
  136.     if (tempMostEfficientAmount < mostEfficientAmount) then
  137.         mostEfficientAmount = tempMostEfficientAmount
  138.         mostEfficientBox = tempMostEfficientBox
  139.     end
  140.    
  141.     if (tempCollectedShouldersAmount / tempShouldersAmount < collectedShouldersAmount / shouldersAmount) then
  142.         collectedShouldersAmount = tempCollectedShouldersAmount
  143.         shouldersAmount = tempShouldersAmount
  144.         mostEfficientMysteryBox = "Glirion's Mystery Coffer"
  145.     end
  146.        
  147.     tempMostEfficientBox, tempMostEfficientAmount, tempShouldersAmount, tempCollectedShouldersAmount
  148.         = UndauntedShoulderCollector.MostEfficientBoxSetPerKey(UndauntedShoulderCollectorData.Urgarlag)
  149.    
  150.     if (tempMostEfficientAmount < mostEfficientAmount) then
  151.         mostEfficientAmount = tempMostEfficientAmount
  152.         mostEfficientBox = tempMostEfficientBox
  153.     end
  154.    
  155.     if (tempCollectedShouldersAmount / tempShouldersAmount < collectedShouldersAmount / shouldersAmount) then
  156.         collectedShouldersAmount = tempCollectedShouldersAmount
  157.         shouldersAmount = tempShouldersAmount
  158.         mostEfficientMysteryBox = "Urgarlag's Mystery Coffer"
  159.     end
  160.    
  161.     chat:Print(
  162.         UndauntedShoulderCollector.dashedLines ..
  163.         "\n" .. "Best 5 key deal: " .. UndauntedShoulderCollector.printBoxData(mostEfficientBox, 6, mostEfficientAmount) ..
  164.         "\n" .. "Best 1 key deal: " .. UndauntedShoulderCollector.printBoxData(mostEfficientMysteryBox, shouldersAmount, collectedShouldersAmount) ..
  165.         "\n" .. UndauntedShoulderCollector.printMysteryBox5KeyData(mostEfficientMysteryBox, shouldersAmount, collectedShouldersAmount)
  166.     )
  167. end
  168.  
  169. -- Accepts nothing
  170. -- Displays amount of pieces collected from all 1 key mystery coffers, in fraction and percentage formats
  171. -- Returns nothing
  172. function UndauntedShoulderCollector.ShowAllMysteryCoffers()
  173.     _, _, majMaxShouldersAmount, majCollectedShouldersAmount
  174.         = UndauntedShoulderCollector.MostEfficientBoxSetPerKey(UndauntedShoulderCollectorData.Maj)
  175.     _, _, glirionMaxShouldersAmount, glirionCollectedShouldersAmount
  176.         = UndauntedShoulderCollector.MostEfficientBoxSetPerKey(UndauntedShoulderCollectorData.Glirion)
  177.     _, _, urgarlagMaxShouldersAmount, urgarlagCollectedShouldersAmount
  178.         = UndauntedShoulderCollector.MostEfficientBoxSetPerKey(UndauntedShoulderCollectorData.Urgarlag)
  179.        
  180.     majOutput1 = UndauntedShoulderCollector.printBoxData(UndauntedShoulderCollector.mysteryCofferMaj, majMaxShouldersAmount, majCollectedShouldersAmount)
  181.     glirionOutput1 = UndauntedShoulderCollector.printBoxData(UndauntedShoulderCollector.mysteryCofferGlirion, glirionMaxShouldersAmount, glirionCollectedShouldersAmount)
  182.     urgarlagOutput1 = UndauntedShoulderCollector.printBoxData(UndauntedShoulderCollector.mysteryCofferUrgarlag, urgarlagMaxShouldersAmount, urgarlagCollectedShouldersAmount)
  183.    
  184.     majOutput2 = UndauntedShoulderCollector.printMysteryBox5KeyData(UndauntedShoulderCollector.mysteryCofferMaj, majMaxShouldersAmount, majCollectedShouldersAmount)
  185.     glirionOutput2 = UndauntedShoulderCollector.printMysteryBox5KeyData(UndauntedShoulderCollector.mysteryCofferGlirion, glirionMaxShouldersAmount, glirionCollectedShouldersAmount)
  186.     urgarlagOutput2 = UndauntedShoulderCollector.printMysteryBox5KeyData(UndauntedShoulderCollector.mysteryCofferUrgarlag, urgarlagMaxShouldersAmount, urgarlagCollectedShouldersAmount)
  187.    
  188.     chat:Print(
  189.         UndauntedShoulderCollector.dashedLines ..
  190.         "\n" .. majOutput1 ..
  191.         "\n" .. majOutput2 ..
  192.         "\n" .. glirionOutput1 ..
  193.         "\n" .. glirionOutput2 ..
  194.         "\n" .. urgarlagOutput1 ..
  195.         "\n" .. urgarlagOutput2
  196.     )
  197. end
  198.  
  199. -- Accepts nothing
  200. -- Prints all commands along with a description of each command
  201. -- Returns nothing
  202. function UndauntedShoulderCollector.PrintHelpMessages()
  203.     chat:Print(
  204.         UndauntedShoulderCollector.dashedLines ..
  205.         "\n" .. "List of commands  available in Undaunted Shoulder Collector" ..
  206.         "\n" .. "/usc :  Displays most efficient 5 key and 1 key purchases along with the chance of unlocking a new set piece from each of those boxes" ..
  207.         "\n" .. "/uscmystery :  Displays collected amounts for each mystery coffer and the chance of unlocking a new piece from each one" ..
  208.         "\n" .. "/uscmaj :  Displays collected amounts for each coffer available from Maj and the chance of unlocking a new piece from each one" ..
  209.         "\n" .. "/uscglirion :  Displays collected amounts for each coffer available from Glirion and the chance of unlocking a new piece from each one" ..
  210.         "\n" .. "/uscurgarlag :  Displays collected amounts for each coffer available from Urgarlag and the chance of unlocking a new piece from each one" ..
  211.         "\n" .. "/uschelp :  Displays help message to chatbox listing available commands"
  212.     )
  213. end
  214.  
  215.  
  216. SLASH_COMMANDS["/usc"] = function() UndauntedShoulderCollector.CalculateMostEfficientKeyPurchases() end
  217. SLASH_COMMANDS["/uscmystery"] = function() UndauntedShoulderCollector.ShowAllMysteryCoffers() end
  218. SLASH_COMMANDS["/uscmaj"] = function() UndauntedShoulderCollector.ShowAllPledgeGiver(UndauntedShoulderCollectorData.Maj, UndauntedShoulderCollector.mysteryCofferMaj) end
  219. SLASH_COMMANDS["/uscglirion"] = function() UndauntedShoulderCollector.ShowAllPledgeGiver(UndauntedShoulderCollectorData.Glirion, UndauntedShoulderCollector.mysteryCofferGlirion) end
  220. SLASH_COMMANDS["/uscurgarlag"] = function() UndauntedShoulderCollector.ShowAllPledgeGiver(UndauntedShoulderCollectorData.Urgarlag, UndauntedShoulderCollector.mysteryCofferUrgarlag) end
  221. SLASH_COMMANDS["/uschelp"] = function() UndauntedShoulderCollector.PrintHelpMessages() end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement