Guest User

MH Ref 7.8.4 VBA code

a guest
May 11th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 74.26 KB | None | 0 0
  1. Option Explicit
  2. Dim stTime As Double, usrSortKey As String
  3. Sub BonusLuckWeekend()
  4. ' Copypasta from ShieldToggle()
  5. Dim filterflag As Boolean, stTime#
  6. stTime = Timer
  7. Application.ScreenUpdating = False
  8. Application.Calculation = xlCalculationManual
  9.  
  10. Call TrapReset("Luck")
  11. Application.Calculate
  12. usrSortKey = Sheets("Bestsetup").Cells(22, Sheets("bestSetup").ListObjects("Trbstable").Sort.SortFields.Item(1).Key.Column).Value
  13. If Not usrSortKey Like "Per*" Then usrSortKey = vbNullString
  14. Call SortLocation(usrSortKey)
  15.  
  16. Application.Calculation = xlCalculationAutomatic
  17. Application.ScreenUpdating = True
  18. Debug.Print "ShieldToggle: " & Format(Timer - stTime, "##0.0000") & " seconds total"
  19. Exit Sub
  20. End Sub
  21. Sub ShieldToggle()
  22. ' Written 3/31/11 by Ben Hauch
  23. ' Last updated 5/5/11 by Ben Hauch
  24. Dim filterflag As Boolean, stTime#
  25. stTime = Timer
  26. Application.ScreenUpdating = False
  27. Application.Calculation = xlCalculationManual
  28.  
  29. Call TrapReset("Luck")
  30. usrSortKey = Sheets("Bestsetup").Cells(22, Sheets("bestSetup").ListObjects("Trbstable").Sort.SortFields.Item(1).Key.Column).Value
  31. If Not usrSortKey Like "Per*" Then usrSortKey = vbNullString
  32. Call SortLocation(usrSortKey)
  33.  
  34. Application.Calculation = xlCalculationAutomatic
  35. Application.ScreenUpdating = True
  36. Debug.Print "ShieldToggle: " & Format(Timer - stTime, "##0.0000") & " seconds total"
  37. Exit Sub
  38. End Sub
  39. Sub AssignMousesNamePowerType()
  40. ' Patterned after GetMiceNames as written by Ben Hauch and updated by RJS
  41. ' Last updated by Ben Hauch on 02/02/12
  42.  
  43. stTime = Timer
  44. Application.ScreenUpdating = False
  45. Application.Calculation = xlManual
  46. Dim CheeseCol%, i%, j%, AutoFCriteria() As Variant, filterflag As Boolean, tmp, tmp2, tmp3, tmp4
  47. Dim aMice() As Variant, MiceTbl() As Variant, EventMice As Boolean, rMice() As Variant
  48.  
  49. ' Remove all mice, subgroups, and catch rates from the sheet
  50. If Sheets("BestSetup").ListObjects("TrBsTable").Sort.SortFields.Count > 0 Then usrSortKey = Sheets("Bestsetup").Cells(22, Sheets("bestSetup").ListObjects("Trbstable").Sort.SortFields.Item(1).Key.Column).Value
  51. Sheets("BestSetup").Columns("K:BA").Delete
  52.  
  53. ' Reset to Common cheese if changing locations
  54. If Range("LocationIndex").Value <> Range("OldLocation") Then
  55.     Range("CheeseIndex").Value = 1
  56.     Range("OldLocation").Value = Range("LocationIndex").Value
  57.     End If
  58.    
  59. ' Determine the proper lookup column to use on M_cheese sheet
  60. CheeseCol = Application.VLookup(Range("LocationName").Value, Range("L_Cheese[#Data]"), _
  61.              13, False) + Range("CheeseIndex").Value + 3
  62.  
  63. ' Perform the autofilter to enable properly sizing rMice()
  64. Sheets("M_cheese").ListObjects("M_attraction").Range.AutoFilter field:=CheeseCol, Criteria1:="<>"
  65. If Range("EventIndex").Value = 2 Then
  66.         EventMice = False
  67.         Sheets("M_cheese").ListObjects("M_attraction").Range.AutoFilter field:=2, Criteria1:="<>Event Mice"
  68.         Else: EventMice = True
  69.     End If
  70.  
  71. ' Filter out the unwanted mice
  72. aMice = Range("M_attraction").Value
  73. MiceTbl = Range("Mice[[#All],[Mice]:[Tactical]]").Value
  74.  
  75. If Not UBound(aMice) = UBound(MiceTbl) - 1 Then GoTo SubExit 'Test to ensure equality without using lookups
  76. On Error GoTo SubExit
  77. ReDim rMice(1 To 4, 1 To Range("M_attraction[Mice]").SpecialCells(xlCellTypeVisible).Count)
  78. On Error GoTo 0
  79. Let j = 1
  80. For i = 1 To UBound(aMice)
  81.     If Not IsEmpty(aMice(i, CheeseCol)) Then        'Mouse attractable?
  82.         If Not EventMice Then                       'Ignore Event mice?
  83.             If Not aMice(i, 2) = "Event Mice" Then      'Is this an event mouse?
  84.                 rMice(1, j) = aMice(i, 1)               'Ok not an event mouse
  85.                 rMice(2, j) = MiceTbl(i + 1, 3)
  86.                 rMice(3, j) = MiceTbl(i + 1, 6)
  87.                 rMice(4, j) = aMice(i, CheeseCol)       'Get attraction weighting factor
  88.                 j = j + 1
  89.             End If
  90.         Else                                        'Don't ignore Event mice
  91.             rMice(1, j) = aMice(i, 1)
  92.             rMice(2, j) = MiceTbl(i + 1, 3)
  93.             rMice(3, j) = MiceTbl(i + 1, 6)
  94.             rMice(4, j) = aMice(i, CheeseCol)
  95.             j = j + 1
  96.         End If
  97.     End If
  98. Next i
  99.  
  100. ' Has the user enabled some custom Trap/Base/Charm/qualifier filters?  Preserve them!
  101. ' Need have selected a cell in the filtered table for the call to work. <---Dumb but true D:<
  102. Sheets("BestSetup").Range("B22").Select
  103. If Sheets("BestSetup").FilterMode Then
  104.     filterflag = True
  105.     AutoFCriteria = GetAutofilterNames
  106.     Sheets("BestSetup").AutoFilterMode = False
  107.     Sheets("BestSetup").Range("TrBsTable").AutoFilter
  108.     End If
  109.    
  110. ' Write attracted mice & total attraction rate
  111. Sheets("BestSetup").Range(Cells(5, 11), Cells(8, 10 + UBound(rMice, 2))).Value = rMice
  112. Sheets("BestSetup").Range("totAR").Value = Application.Sum(Sheets("BestSetup").Range(Cells(8, 11), Cells(8, 10 + UBound(rMice, 2))))
  113.  
  114. ' Sort the attracted mice by Mouse Power (could use flag to sort by attraction rate)
  115. Sheets("BestSetup").Sort.SortFields.Clear
  116. Sheets("BestSetup").Sort.SortFields.Add Key:=Range("K7:BA7"), _
  117.     SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:=xlSortNormal
  118. With Sheets("BestSetup").Sort
  119.     .SetRange Range("K5:BA8")
  120.     .Header = xlNo
  121.     .Orientation = xlLeftToRight
  122.     .Apply
  123. End With
  124.  
  125. 'Load sorted rMice array into memory
  126. rMice = Sheets("BestSetup").Range(Cells(5, 11), Cells(7, 10 + UBound(rMice, 2))).Value
  127.  
  128. 'Perform location-based stat increases before doing catch rate calculations
  129. Select Case Application.Index(Range("Locations29[Locations]"), Range("LocationIndex"))
  130.     Case "Seasonal Garden - Spring", "Seasonal Garden - Summer", "Seasonal Garden - Winter"
  131.         If Range("PrevLoc") <> "Seas" Then Call SeasonalBoost
  132.         Range("PrevLoc").Value = "Seas"
  133.     Case "Seasonal Garden - Fall"
  134.         If Range("Prevloc") <> "SeasF" Then
  135.             Call SeasonalBoost
  136.             Call SoulXLuckBoost("Seasonal")
  137.         End If
  138.         Range("PrevLoc").Value = "Seasf"
  139.     Case "Derr Dunes", "Nerg Plains", "Elub Shore", "Cape Clawed"
  140.         If Range("CharmName").Value = "Tribal Power" Then
  141.             Call TrapReset("Power")
  142.         ElseIf Range("PrevLoc") <> "Trib" Then
  143.             Call TikiBoost
  144.         End If
  145.         Range("PrevLoc").Value = "Trib"
  146.     Case "Chocolate Factory 2011", "Chocolate Factory 2012"
  147.         If Application.IsEven(Range("CheeseIndex")) Then 'Need to use Dark chocolate charm
  148.             Call CharmMods
  149.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  150.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  151.             GoTo SubExit
  152.         ElseIf Range("PrevCharm").Value = "DChoco" Then 'Last charm was chocolate, but we switched cheese to no chocolate
  153.             Range("CharmIndex").Value = Application.Match("None", Range("CharmNames"), 0) 'clear charms
  154.             Range("OldCharm").Value = 999 'Trigger guaranteed recalculation
  155.             Call CharmMods
  156.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  157.             GoTo SubExit
  158.             End If
  159.     Case "Festive Comet 2011"
  160.         If (Range("CheeseIndex").Value = 4) Then ' Need Winter Charm
  161.             Call CharmMods
  162.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  163.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  164.             GoTo SubExit
  165.         ElseIf Range("prevcharm").Value = "Winter" Then
  166.             Range("CharmIndex").Value = Application.Match("None", Range("CharmNames"), 0)
  167.             Range("OldCharm").Value = 999
  168.             Call CharmMods
  169.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  170.             GoTo SubExit
  171.         End If
  172.     Case "Year of the Dragon Festival"
  173.         If (((Range("CheeseIndex").Value - 1) Mod 4) > 0) Then  ' Need to equip a charm...
  174.             Call CharmMods
  175.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  176.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  177.             GoTo SubExit
  178.         ElseIf ((Range("PrevCharm").Value = "Fcracker") Or (Range("Prevcharm").Value = "Npoop") Or (Range("PrevCharm").Value = "DBreath")) Then
  179.             Range("CharmIndex").Value = Application.Match("None", Range("Charmnames"), 0)
  180.             Range("OldCharm").Value = 999
  181.             Call CharmMods
  182.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  183.             GoTo SubExit
  184.         End If
  185.     Case "Snow Fortress - Gateway", "Snow Fortress - Courtyard", "Snow Fortress - Keep"
  186.         If (Range("CheeseIndex").Value = 2) Then ' Need Winter Charm
  187.             Call CharmMods
  188.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  189.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  190.             GoTo SubExit
  191.         ElseIf Range("prevcharm").Value = "Winter" Then
  192.             Range("CharmIndex").Value = Application.Match("None", Range("CharmNames"), 0)
  193.             Range("OldCharm").Value = 999
  194.             Call CharmMods
  195.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  196.             GoTo SubExit
  197.         End If
  198.     Case "Terrortories - Corn Maze", "Terrortories - Haunted Manor", "Terrortories - Pumpkin Patch"
  199.         If Range("PrevLoc").Value <> "Terror" Then Call SoulXLuckBoost("Terror")
  200.         Range("PrevLoc").Value = "Terror"
  201.         If (((Range("CheeseIndex").Value - 1) \ 4) > 0) Then
  202.             ' Using a Spookified bait, enforce charm
  203.             Call CharmMods
  204.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  205.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.000") & " sec"
  206.             GoTo SubExit
  207.         ElseIf Range("PrevCharm").Value = "Spooky" Then ' Last Charm was Spooky Charm, but we switched cheese to non-spooky bait
  208.             Range("Charmindex").Value = Application.Match("None", Range("Charmnames"), 0)   ' so clear the charm
  209.             Range("OldCharm").Value = 999   ' Trigger stats recalculation
  210.             Call CharmMods
  211.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.000") & " sec"
  212.             GoTo SubExit
  213.         End If
  214.     Case "Muridae Market"
  215.         If Application.IsEven(Range("CheeseIndex")) Then
  216.             Call CharmMods
  217.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  218.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  219.             GoTo SubExit
  220.         ElseIf Range("PrevCharm").Value = "Artisan" Then
  221.             Range("CharmIndex").Value = Application.Match("None", Range("Charmnames"), 0)
  222.             Range("OldCharm").Value = 999
  223.             Call CharmMods
  224.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  225.             GoTo SubExit
  226.         End If
  227.     Case "Slushy Shoreline"
  228.         If Application.IsEven(Range("CheeseIndex")) Then
  229.             Call CharmMods
  230.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  231.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  232.             GoTo SubExit
  233.         ElseIf Range("PrevCharm").Value = "SoftServe" Then
  234.             Range("CharmIndex").Value = Application.Match("None", Range("Charmnames"), 0)
  235.             Range("OldCharm").Value = 999
  236.             Call CharmMods
  237.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  238.             GoTo SubExit
  239.         End If
  240.     Case "Crystal Library"
  241.         If Application.IsEven(Range("CheeseIndex")) Then
  242.             Call CharmMods
  243.             If Range("K27").Value = vbNullString Then Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  244.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  245.             GoTo SubExit
  246.         ElseIf Range("PrevCharm").Value = "CScholar" Then
  247.             Range("CharmIndex").Value = Application.Match("None", Range("Charmnames"), 0)
  248.             Range("OldCharm").Value = 999
  249.             Call CharmMods
  250.             Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " sec"
  251.             GoTo SubExit
  252.         End If
  253.     Case Else
  254.         If Range("PrevLoc").Value = "Seas" Then
  255.             Range("PrevLoc").Value = ""
  256.             Call TrapReset("Power")
  257.             GoTo SubExit
  258.             End If
  259.         If (Range("PrevLoc").Value = "Trib") Or (Range("PrevLoc").Value = "Seasf") Or (Range("PrevLoc").Value = "Terror") Then
  260.             Range("PrevLoc").Value = ""
  261.             Call TrapReset("All")
  262.             GoTo SubExit
  263.             End If
  264. End Select
  265.  
  266. 'Perform Catch Rate calculations
  267. Call CatchRateColumns(rMice, MiceTbl, Range("LocationName").Value)
  268.  
  269. ' Create ranking columns that compute methods of comparing setups
  270. Call CreateSortColumns
  271.  
  272. SubExit:   ' Catch rates & sort rank already calculated in a called sub (eg trap reset or charmmods)
  273.  
  274. If Not Range("TrBsTable[#Headers]").End(xlToRight).Value = "Per Cheese" Then Call CreateSortColumns
  275. Range("TrBsTable[[Per Hunt]:[Per Cheese]]").NumberFormat = "#0.000"
  276.  
  277.  
  278. ' Format the mouse names area
  279. With Sheets("BestSetup").Range(Cells(5, 11), Cells(5, Cells(22, 10).End(xlToRight).Column - 2))
  280.     .WrapText = True
  281.     .Font.ThemeColor = xlThemeColorLight2
  282.     .Font.Bold = True
  283.     .HorizontalAlignment = xlCenter
  284.     .Interior.ThemeColor = xlThemeColorAccent6
  285.     .Interior.TintAndShade = 0.55
  286. End With
  287. With Sheets("BestSetup").Range(Cells(7, 11), Cells(7, Cells(22, 10).End(xlToRight).Column - 2))
  288.     .NumberFormat = "#,##0"
  289.     .Interior.ThemeColor = xlThemeColorLight2
  290.     .Interior.TintAndShade = 0.8
  291. End With
  292. With Sheets("BestSetup").Range(Cells(5, 11), Cells(7, Cells(22, 10).End(xlToRight).Column - 2))
  293.     .Borders.ThemeColor = 1
  294. End With
  295. Sheets("BestSetup").Columns("K:AA").ColumnWidth = 10
  296.  
  297. ' Restore Autofilters
  298. If filterflag Then Call SetAutofilterNames(AutoFCriteria())
  299.  
  300. ' Restore M_cheese worksheet state
  301. Sheets("M_cheese").ListObjects("M_attraction").Range.AutoFilter field:=CheeseCol
  302. If Range("EventIndex").Value = 2 Then _
  303.         Sheets("M_cheese").ListObjects("M_attraction").Range.AutoFilter field:=2
  304.  
  305.  
  306. 'Write the cheese used
  307. Range("PrevCheese").Value = Range("CheeseIndex").Value
  308. Application.Calculate
  309. If Not usrSortKey Like "Per*" Then usrSortKey = vbNullString
  310. Call SortLocation(usrSortKey)
  311. Debug.Print "AssignMPetc: " & Format(Timer - stTime, "##0.0000") & " seconds total"
  312. Application.Calculation = xlCalculationAutomatic
  313. Application.ScreenUpdating = True
  314. End Sub
  315. Sub CharmMods()
  316. ' Charms can do funky things -- so let's account for it.
  317. ' Written by Ben Hauch on 3/31/11
  318. ' Last updated 02/02/12 by Ben Hauch
  319.  
  320. Dim CharmName$, Full%
  321. Application.ScreenUpdating = False
  322. Application.Calculation = xlCalculationManual
  323.  
  324. If Not Range("PrevCharm").Value = vbNullString Then Full = 1 Else Full = 0
  325. Select Case Application.Index(Range("Locations29"), Sheets("BestSetup").Range("LocationIndex"))
  326. Case "Chocolate Factory 2011", "Chocolate Factory 2012"
  327.     If Application.IsEven(Range("CheeseIndex")) Then 'Force use of Dark Chocolate Charms
  328.         Range("CharmIndex").Value = Application.Match("Dark Chocolate", Range("Charmnames"), 0)
  329.         If Range("PrevCharm").Value = "DChoco" Then ' already have DChoco stats calculated
  330.             If Range("PrevCheese").Value = Range("Cheeseindex").Value Then
  331.                 Application.Calculation = xlCalculationAutomatic
  332.                 Application.ScreenUpdating = True
  333.                 Exit Sub
  334.             End If
  335.         Else
  336.             CharmName = "Dark Chocolate"
  337.             Range("PrevCharm").Value = "DChoco"
  338.         End If
  339.     Else
  340.         CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  341.         If CharmName = "Dark Chocolate" Then
  342.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 1
  343.             Call AssignMousesNamePowerType
  344.             End If
  345.     End If
  346. Case "Muridae Market"
  347.     If Application.IsEven(Range("CheeseIndex")) Then 'Force use of Artisan Charms
  348.         Range("CharmIndex").Value = Application.Match("Artisan", Range("Charmnames"), 0)
  349.         If Range("PrevCharm").Value = "Artisan" Then ' already have Artisan stats calculated
  350.             If Range("PrevCheese").Value = Range("Cheeseindex").Value Then
  351.                 Application.Calculation = xlCalculationAutomatic
  352.                 Application.ScreenUpdating = True
  353.                 Exit Sub
  354.             End If
  355.         Else
  356.             CharmName = "Artisan"
  357.             Range("PrevCharm").Value = "Artisan"
  358.         End If
  359.     Else
  360.         CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  361.         If CharmName = "Artisan" Then
  362.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 1
  363.             Call AssignMousesNamePowerType
  364.             End If
  365.     End If
  366. Case "Slushy Shoreline"
  367.     If Application.IsEven(Range("CheeseIndex")) Then 'Force use of Soft Serve Charms
  368.         Range("CharmIndex").Value = Application.Match("Soft Serve", Range("Charmnames"), 0)
  369.         If Range("PrevCharm").Value = "SoftServe" Then ' already have Soft Serve stats calculated
  370.             If Range("PrevCheese").Value = Range("Cheeseindex").Value Then
  371.                 Application.Calculation = xlCalculationAutomatic
  372.                 Application.ScreenUpdating = True
  373.                 Exit Sub
  374.             End If
  375.         Else
  376.             CharmName = "Soft Serve"
  377.             Range("PrevCharm").Value = "SoftServe"
  378.         End If
  379.     Else
  380.         CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  381.         If CharmName = "Soft Serve" Then
  382.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 1
  383.             Call AssignMousesNamePowerType
  384.             End If
  385.     End If
  386. Case "Crystal Library"
  387.     If Application.IsEven(Range("CheeseIndex")) Then 'Force use of Scholar Charms
  388.         Range("CharmIndex").Value = Application.Match("Scholar", Range("Charmnames"), 0)
  389.         If Range("PrevCharm").Value = "CScholar" Then ' already have Scholar stats calculated
  390.             If Range("PrevCheese").Value = Range("Cheeseindex").Value Then
  391.                 Application.Calculation = xlCalculationAutomatic
  392.                 Application.ScreenUpdating = True
  393.                 Exit Sub
  394.             End If
  395.         Else
  396.             CharmName = "Scholar"
  397.             Range("PrevCharm").Value = "CScholar"
  398.         End If
  399.     Else
  400.         CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  401.         If CharmName = "Scholar" Then
  402.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 1
  403.             Call AssignMousesNamePowerType
  404.             End If
  405.     End If
  406. Case "Terrortories - Corn Maze", "Terrortories - Haunted Manor", "Terrortories - Pumpkin Patch"
  407.     If (((Range("CheeseIndex").Value - 1) \ 4) > 0) Then    ' Force Spooky Charm
  408.         Range("CharmIndex").Value = Application.Match("Spooky", Range("CharmNames"), 0)
  409.         If Range("PrevCharm").Value = "Spooky" Then ' Stats are up-to-date
  410.             If Range("PrevCheese").Value = Range("CheeseIndex").Value Then
  411.                 Application.Calculation = xlCalculationAutomatic
  412.                 Application.ScreenUpdating = True
  413.                 Exit Sub
  414.             End If
  415.         Else
  416.             CharmName = "Spooky"
  417.             Range("PrevCharm").Value = "Spooky"
  418.         End If
  419.     Else
  420.         CharmName = Application.Index(Range("Charmnames"), Range("CharmIndex").Value)
  421.         If CharmName = "Spooky" Then
  422.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 4
  423.             Call AssignMousesNamePowerType
  424.         End If
  425.     End If
  426. Case "Festive Comet 2011"
  427.     If (Range("Cheeseindex").Value = 4) Then
  428.         ' Need Winter Charms
  429.         Range("CharmIndex").Value = Application.Match("Winter", Range("CharmNames"), 0)
  430.         If Range("PrevCharm").Value = "Winter" Then
  431.             If Range("PrevCheese").Value = Range("CheeseIndex").Value Then
  432.                 Application.Calculation = xlCalculationAutomatic
  433.                 Application.ScreenUpdating = True
  434.                 Exit Sub
  435.             End If
  436.         Else
  437.             CharmName = "Winter"
  438.             Range("PrevCharm").Value = "Winter"
  439.         End If
  440.     Else
  441.         CharmName = Application.Index(Range("CharmNames"), Range("CharmIndex").Value)
  442.         If CharmName = "Winter" Then
  443.             Range("CheeseIndex").Value = 4
  444.             Call AssignMousesNamePowerType
  445.         End If
  446.     End If
  447. Case "Snow Fortress - Gateway", "Snow Fortress - Courtyard", "Snow Fortress - Keep"
  448.     If (Range("Cheeseindex").Value = 2) Then
  449.         ' Need Winter Charms
  450.         Range("CharmIndex").Value = Application.Match("Winter", Range("CharmNames"), 0)
  451.         If Range("PrevCharm").Value = "Winter" Then
  452.             If Range("PrevCheese").Value = Range("CheeseIndex").Value Then
  453.                 Application.Calculation = xlCalculationAutomatic
  454.                 Application.ScreenUpdating = True
  455.                 Exit Sub
  456.             End If
  457.         Else
  458.             CharmName = "Winter"
  459.             Range("PrevCharm").Value = "Winter"
  460.         End If
  461.     Else
  462.         CharmName = Application.Index(Range("CharmNames"), Range("CharmIndex").Value)
  463.         If CharmName = "Winter" Then
  464.             Range("CheeseIndex").Value = 2
  465.             Call AssignMousesNamePowerType
  466.         End If
  467.     End If
  468. Case "Year of the Dragon Festival"
  469.     Select Case ((Range("Cheeseindex").Value - 1) Mod 4) ' 0 = regular charm, 1 = FC, 2 = Poop, 3 = Breath
  470.     Case 0
  471.         ' Enforce appropriate (dis)arming of Firecracker/Nitropop/Dragon Breath charms
  472.         CharmName = Application.Index(Range("CharmNames"), Range("CharmIndex").Value)
  473.         Select Case CharmName
  474.         Case "Firecracker"
  475.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 1
  476.             Call AssignMousesNamePowerType
  477.         Case "Nitropop"
  478.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 2
  479.             Call AssignMousesNamePowerType
  480.         Case "Dragon Breath"
  481.             Range("CheeseIndex").Value = Range("CheeseIndex").Value + 3
  482.             Call AssignMousesNamePowerType
  483.         End Select
  484.     Case 1
  485.         ' Enforce arming of Firecracker charms
  486.         Range("CharmIndex").Value = Application.Match("Firecracker", Range("CharmNames"), 0)
  487.         If Range("PrevCharm").Value = "Fcracker" Then
  488.             If Range("PrevCheese").Value = Range("CheeseIndex").Value Then
  489.                 Application.Calculation = xlCalculationAutomatic
  490.                 Application.ScreenUpdating = True
  491.                 Exit Sub
  492.             End If
  493.         Else
  494.             CharmName = "Firecracker"
  495.             Range("PrevCharm").Value = "Fcracker"
  496.         End If
  497.     Case 2
  498.         ' Enforce arming of Nitropop charms
  499.         Range("CharmIndex").Value = Application.Match("Nitropop", Range("CharmNames"), 0)
  500.         If Range("PrevCharm").Value = "Npoop" Then
  501.             If Range("PrevCheese").Value = Range("CheeseIndex").Value Then
  502.                 Application.Calculation = xlCalculationAutomatic
  503.                 Application.ScreenUpdating = True
  504.                 Exit Sub
  505.             End If
  506.         Else
  507.             CharmName = "Nitropop"
  508.             Range("PrevCharm").Value = "Npoop"
  509.         End If
  510.     Case 3
  511.         ' Enforce arming of Dragon Breath charms
  512.         Range("CharmIndex").Value = Application.Match("Dragon Breath", Range("CharmNames"), 0)
  513.         If Range("PrevCharm").Value = "DBreath" Then
  514.             If Range("PrevCheese").Value = Range("CheeseIndex").Value Then
  515.                 Application.Calculation = xlCalculationAutomatic
  516.                 Application.ScreenUpdating = True
  517.                 Exit Sub
  518.             End If
  519.         Else
  520.             CharmName = "Dragon Breath"
  521.             Range("PrevCharm").Value = "DBreath"
  522.         End If
  523.     End Select
  524. Case Else
  525.     CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  526. End Select
  527.  
  528. ' Has anything even really changed?  Will only apply for CR boosting stats
  529. If Range("OldCharm").Value = Range("CharmIndex").Value Then
  530.     Application.Calculation = xlCalculationAutomatic
  531.     Application.ScreenUpdating = True
  532.     Exit Sub
  533.     End If
  534.  
  535. Select Case CharmName
  536. ' Attraction-only charms
  537. Case "Attraction", "Valentine"
  538.     If CharmName = "Valentine" Then
  539.         Range("PrevCharm").Value = "Nanny"  'This will trigger a cheese effect calculation
  540.     Else                                    ' which is why here it is set before the reset call
  541.         Range("PrevCharm").Value = "Attraction"
  542.         End If
  543.     If Full = 1 Then Call TrapReset("All") Else Call TrapReset("Attraction")
  544.    
  545. ' Power-only charms
  546. Case "Power", "Empowered Anchor", "First Ever", "Prospector", "Scientist", "Super Rotten", _
  547.      "Ultimate Power", "Rotten", "Dark Chocolate", "Super Power", "Tribal Power", "Spellbook", _
  548.      "Spooky", "Firecracker", "Nitropop", "Dragon Breath", "Mining"
  549.     If (CharmName Like "*otten") Then
  550.         Range("PrevCharm").Value = "Nanny"  'This will trigger a cheese effect calculation
  551.     ElseIf (CharmName = "Dark Chocolate") Then
  552.         Range("PrevCharm").Value = "DChoco" ' which is why here it is set before the reset call
  553.     ElseIf (CharmName = "Spellbook") Then
  554.         Range("PrevCharm").Value = "SBB"
  555.     ElseIf (CharmName = "Spooky") Then
  556.         Range("PrevCharm").Value = "Spooky"
  557.     ElseIf (CharmName = "Firecracker") Then
  558.         Range("PrevCharm").Value = "Fcracker"
  559.     ElseIf (CharmName = "Nitropop") Then
  560.         Range("PrevCharm").Value = "Npoop"
  561.     ElseIf (CharmName = "Dragon Breath") Then
  562.         Range("PrevCharm").Value = "DBreath"
  563.     Else
  564.         Range("PrevCharm").Value = "Power"
  565.     End If
  566.     If Full = 1 Then Call TrapReset("All") Else Call TrapReset("Power")
  567.    
  568. ' Luck-only charms
  569. Case "Luck", "Lucky Rabbit", "Ultimate Luck", "Super Luck", "Winter", "Winter Toy"
  570.     If (CharmName = "Winter") Then
  571.         Range("PrevCharm").Value = "Winter"
  572.     Else
  573.         Range("PrevCharm").Value = "Luck"
  574.     End If
  575.     If Full = 1 Then Call TrapReset("All") Else Call TrapReset("Luck")
  576.    
  577. ' Multi-mode charms
  578. Case "Artisan", "Lucky Power", "Nanny", "Freshness", "Cackle", "Champion", "Chrome", "Tarnished", "Party"
  579.     If CharmName = "Nanny" Then Range("TrBsTable[Trap type]").Value = "Parental"
  580.     Call TrapReset("All")
  581.     If CharmName = "Artisan" Then
  582.         Range("PrevCharm").Value = "Artisan"
  583.     Else
  584.         Range("PrevCharm").Value = "Nanny"
  585.     End If
  586.    
  587. ' Cheese effect only charms
  588. ' need to develop, includes Freshness and Tarnished
  589.    
  590. ' Charms that have a hidden catch rate bonus but no normal universal stat bonus
  591. ' Note that the hidden catch rate bonus will need to be coded in CatchRateColumns for this to do anything
  592. Case "Super Warpath Archer", "Super Warpath Cavalry", "Super Warpath Mage", "Flamebane", _
  593.      "Super Warpath Scout", "Super Warpath Warrior", "Super Warpath Commander", "Dragonbane", _
  594.      "Rook Crumble", "Scholar", "Dreaded"
  595.     If Full = 1 Then Call TrapReset("All") Else Call TrapReset("Luck")
  596.     If CharmName = "Scholar" Then Range("PrevCharm").Value = "CScholar" Else Range("PrevCharm").Value = "Luck"
  597.    
  598. ' Charms that have no effect on anything the sheet can manage
  599. Case "Warpath Archer", "Warpath Cavalry", "Warpath Mage", "Warpath Scout", "Warpath Warrior", _
  600.     "Warpath Commander", "Antiskele", "Monger", "Wealth", "Amplifier", "Uncharged Scholar", "Eggstra", _
  601.     "Soft Serve", "Wax", "Sticky"
  602.     If Full = 1 Then Call TrapReset("All")
  603.     If Not CharmName = "Soft Serve" Then Range("PrevCharm").Value = vbNullString Else Call TrapReset("Attraction")
  604.    
  605. Case "None"
  606.     Select Case Range("PrevCharm").Value
  607.     Case "Attraction", "SoftServe"
  608.         Call TrapReset("Attraction")
  609.         Range("PrevCharm").Value = vbNullString
  610.     Case "Power", "SBB", "Fcracker", "Npoop", "DBreath"
  611.         Call TrapReset("Power")
  612.         Range("PrevCharm").Value = vbNullString
  613.     Case "Luck", "Winter"
  614.         Call TrapReset("Luck")
  615.         Range("PrevCharm").Value = vbNullString
  616.     Case "Nanny", "DChoco", "Artisan", "CScholar", "Spooky"
  617.         Call TrapReset("All")
  618.         Range("PrevCharm").Value = vbNullString
  619.     End Select
  620. End Select
  621. Range("OldCharm").Value = Range("CharmIndex").Value
  622. If Sheets("BestSetup").ListObjects("TrBsTable").Sort.SortFields.Count > 0 Then usrSortKey = Sheets("Bestsetup").Cells(22, Sheets("bestSetup").ListObjects("Trbstable").Sort.SortFields.Item(1).Key.Column).Value
  623. If Not usrSortKey Like "Per*" Then usrSortKey = vbNullString
  624. Call SortLocation(usrSortKey)
  625. Application.Calculation = xlCalculationAutomatic
  626. Application.ScreenUpdating = True
  627. End Sub
  628.  
  629. Private Sub btnClear1_Click()
  630.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup1") = ""
  631. End Sub
  632.  
  633. Private Sub btnClear2_Click()
  634.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup2") = ""
  635. End Sub
  636.  
  637. Private Sub btnClear3_Click()
  638.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup3") = ""
  639. End Sub
  640.  
  641. Private Sub btnClear4_Click()
  642.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup4") = ""
  643. End Sub
  644.  
  645. Private Sub btnClear5_Click()
  646.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup5") = ""
  647. End Sub
  648.  
  649. Private Sub btnClear6_Click()
  650.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup6") = ""
  651. End Sub
  652. Private Sub btnPaste1_Click()
  653.     Dim i As Integer: Application.ScreenUpdating = False
  654.     If ActiveSheet.Name = "CRE" Then
  655.         For i = 2 To 6
  656.             Sheets("CRE").Range("CRESetup" & "" & i & "").Value = Sheets("CRE").Range("CRESetup1").Value
  657.         Next i
  658.     End If
  659.     Application.ScreenUpdating = True
  660. End Sub
  661. ' btnPaste Subs added by Frank Halena on 02/03/12
  662. Private Sub btnPaste2_Click()
  663.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup2").Value = Sheets("CRE").Range("CRESetup1").Value
  664. End Sub
  665.  
  666. Private Sub btnPaste3_Click()
  667.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup3").Value = Sheets("CRE").Range("CRESetup2").Value
  668. End Sub
  669.  
  670. Private Sub btnPaste4_Click()
  671.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup4").Value = Sheets("CRE").Range("CRESetup3").Value
  672. End Sub
  673.  
  674. Private Sub btnPaste5_Click()
  675.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup5").Value = Sheets("CRE").Range("CRESetup4").Value
  676. End Sub
  677.  
  678. Private Sub btnPaste6_Click()
  679.   If ActiveSheet.Name = "CRE" Then Sheets("CRE").Range("CRESetup6").Value = Sheets("CRE").Range("CRESetup5").Value
  680. End Sub
  681. '
  682. '
  683. 'END MAINLINE MACROS
  684. 'BEGIN "UTILITY" MACROS
  685. '
  686.  
  687. Public Function CATCHRATE(ByVal Eff#, ByVal Power#, ByVal Luck#, ByVal MousePower#)
  688. ' Written by Ben Hauch
  689. ' Last updated by Ben Hauch on 2/12/11
  690.  
  691.     ' By using a function we can clean up the user-end of the spreadsheet
  692.     ' A function also makes it easy to change the model if necessary
  693.     ' Use of the function requires macro support
  694.     ' Prior formulas are:
  695.         ' For BestSetup page
  696. '=IF([@Effective]=0,0,MIN(0.9999,(([@Effective]*[@Power])+(3-MIN(2,[@Effective]))*(MIN(2,[@Effective])*[@Luck])^2)/(([@Effective]*[@Power])+$E$4)))
  697.        
  698.         ' For CRE page
  699. '=IF(OR(ISBLANK(C$2),ISBLANK(C$3),ISBLANK(C$7)),"",IF(C$15=0,0,MIN(0.9999,((C$15*C$9)+(3-MIN(2,C$15))*(MIN(2,C$15)*C$11)^2)/((C$15*C$9)+$B23))))
  700.     If Eff < 2 Then
  701.         CATCHRATE = (Eff * Power + (3 - Eff) * (Eff * Luck) ^ 2) / _
  702.                             (Eff * Power + MousePower)
  703.     Else
  704.         CATCHRATE = (Eff * Power + (2 * Luck) ^ 2) / _
  705.                        (Eff * Power + MousePower)
  706.     End If
  707.     If CATCHRATE >= 1 Then CATCHRATE = 0.9999
  708. End Function
  709. Private Sub SortLocation(Optional sSortKeyL, Optional iUpDownL)
  710. ' Based on SortCatch as written by Ben Hauch, 2/16/11
  711. ' Significantly repurposed by Ryan J Smith on 3/28/11
  712. ' Last updated 3/25/11 by Ben Hauch
  713.  
  714. If IsMissing(sSortKeyL) Or sSortKeyL = vbNullString Then sSortKeyL = "Per Hunt"
  715. If IsMissing(iUpDownL) Then iUpDownL = 2
  716.  
  717. 'Ensure that the weighting formula is present & current
  718. If Range("TrBsTable[Luck]").Count > Range("TrBsTable[Per Hunt]").Count Then Call CreateSortColumns
  719.  
  720. Sheets("BestSetup").ListObjects("TrBsTable").Sort.SortFields.Clear
  721. ActiveWorkbook.Worksheets("BestSetup").ListObjects("TrBsTable").Sort.SortFields.Add _
  722.         Key:=Range("TrBsTable[[#All],[" & sSortKeyL & "]]"), SortOn:=xlSortOnValues, _
  723.         Order:=iUpDownL, DataOption:=xlSortTextAsNumbers
  724.  
  725. With Sheets("BestSetup").ListObjects("TrBsTable").Sort
  726.     .Header = xlYes
  727.     .MatchCase = False
  728.     .Orientation = xlTopToBottom
  729.     .Apply
  730. End With
  731. End Sub
  732. Private Sub TikiBoost()
  733. ' Written by Ben Hauch on 3/31/11
  734. ' Last updated 5/5/11 by Ben Hauch
  735. ' Adds the location-specific boost to Tiki Base combinations only (+6 LCK)
  736.  
  737. Dim i%, rCell As Range, CharmName$, TrapL%, BaseL%, CharmL%, TikiCells As Range, stTime
  738. stTime = Timer
  739. Let i = 0
  740. CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  741. CharmL = Sheets("Charms").Range("Charms[Charm]").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 4).Value
  742. Set TikiCells = Find_Range("Tiki", Sheets("BestSetup").Range("TrBsTable[Base]").SpecialCells(xlCellTypeVisible))
  743. If Range("ShieldIndex").Value = 1 Then CharmL = CharmL + 7
  744. On Error Resume Next
  745. For Each rCell In TikiCells
  746.     ' Add 6 Luck to the Luck Column -- make sure to alter offset when changing TrBsTable dimensions
  747.     rCell.Offset(0, 7).Value = Range("Traps").Find(rCell.Offset(0, -1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 6).Value + 6 + CharmL
  748. Next rCell
  749. On Error GoTo 0
  750. Debug.Print "TikiBoost: " & Format(Timer - stTime, "##0.000") & " seconds"
  751. End Sub
  752. Private Sub SoulXLuckBoost(Location As String)
  753. ' Written by Ben Hauch on 10/21/11
  754. ' Last updated by Ben Hauch on 10/21/11
  755. ' Adds the Luck Boost for the Soul Catcher and Soul Harvester LE traps
  756. '  when in Terrortories or SG - Fall (Harvester only)
  757. Dim i As Long, rCell As Range, Boostcells As Range, WeaponLuck, stTime, _
  758.     CharmName As String, CharmL As Integer
  759. stTime = Timer
  760. Let i = 0
  761. CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  762. CharmL = Sheets("Charms").Range("Charms[Charm]").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 4).Value
  763. If Range("ShieldIndex").Value = 1 Then CharmL = CharmL + 7
  764. If Range("BonusWeekend").Value = 1 Then CharmL = CharmL + 5
  765. If Location = "Terror" Then
  766. '  Apply bonus to both
  767.     Set Boostcells = Find_Range("Soul ", Sheets("BestSetup").Range("TrBsTable[Trap]").SpecialCells(xlCellTypeVisible), LookIn:=xlValues, LookAt:=xlPart)
  768.     On Error Resume Next
  769.     For Each rCell In Boostcells
  770.         ' Add 10 luck to the luck value
  771.         rCell.Offset(0, 8).Value = Range("Bases").Find(rCell.Offset(0, 1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 5).Value + 10 + CharmL + _
  772.                                    Range("Traps").Find(rCell.Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 6).Value
  773.     Next rCell
  774.     On Error GoTo 0
  775. Else
  776. '  Apply bonus only to Soul Harvester
  777.     Set Boostcells = Find_Range("Soul Harvester", Sheets("BestSetup").Range("TrBsTable[Trap]").SpecialCells(xlCellTypeVisible))
  778.     On Error Resume Next
  779.     For Each rCell In Boostcells
  780.         ' add 10? luck to the luck value
  781.         rCell.Offset(0, 8).Value = Range("Bases").Find(rCell.Offset(0, 1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 5).Value + 10 + CharmL + 12
  782.     Next rCell
  783.     On Error GoTo 0
  784. End If
  785. Debug.Print "Soulboost: " & Format(Timer - stTime, "###0.000") & " seconds"
  786. End Sub
  787. Private Sub SeasonalBoost()
  788. ' Written by Ben Hauch on 3/31/11
  789. ' Last updated 5/5/11 by Ben Hauch
  790. ' Adds the location-specific boost to Seasonal Base combinations only (+18% PB)
  791. Dim i%, rCell As Range, SeasonalCells As Range, WeaponPower#, WeaponBonus#, CharmPower#, CharmBonus#, CharmName$, stTime
  792. stTime = Timer
  793. Let i = 0
  794. CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  795. If CharmName = "Tribal Power" Then
  796.     CharmPower = 0
  797.     CharmBonus = 0
  798. Else
  799.     CharmPower = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 1).Value
  800.     CharmBonus = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 2).Value
  801. End If
  802. Set SeasonalCells = Find_Range("Seasonal", Sheets("BestSetup").Range("TrBsTable[Base]").SpecialCells(xlCellTypeVisible))
  803. On Error Resume Next
  804. For Each rCell In SeasonalCells
  805.     WeaponPower = Range("Traps").Find(rCell.Offset(0, -1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 3).Value + 300 + CharmPower
  806.     WeaponBonus = Range("Traps").Find(rCell.Offset(0, -1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 4).Value + 0.18 + CharmBonus
  807.     rCell.Offset(0, 3).Value = WeaponPower
  808.     rCell.Offset(0, 4).Value = WeaponBonus
  809.     rCell.Offset(0, 5).Value = WeaponPower * (1 + WeaponBonus)
  810. Next rCell
  811. On Error GoTo 0
  812. Debug.Print "SeasonalBoost: " & Format(Timer - stTime, "##0.000") & " seconds"
  813. End Sub
  814. Private Sub SBBCharm()
  815. ' Written by Ben Hauch on 8/12/11
  816. ' Last updated by Ben Hauch on 8/12/11
  817. ' Adds the base-specific boost when using the Spellbook Charm (+500 power, +8% bonus)
  818. Dim i%, rCell As Range, SBBCells As Range, WeaponPower#, WeaponBonus#
  819. Let i = 0
  820. Set SBBCells = Find_Range("Spellbook", Sheets("BestSetup").Range("TrBsTable[Base]").SpecialCells(xlCellTypeVisible))
  821. On Error Resume Next
  822. For Each rCell In SBBCells
  823.     WeaponPower = Range("Traps").Find(rCell.Offset(0, -1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 3).Value + 500 + 500
  824.     WeaponBonus = Range("Traps").Find(rCell.Offset(0, -1).Value, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 4).Value + 0.14 + 0.08
  825.     rCell.Offset(0, 3).Value = WeaponPower
  826.     rCell.Offset(0, 4).Value = WeaponBonus
  827.     rCell.Offset(0, 5).Value = WeaponPower * (1 + WeaponBonus)
  828. Next rCell
  829. On Error GoTo 0
  830. Debug.Print "SBBBoosted"
  831. End Sub
  832. Private Sub TrapReset(Attrib$)
  833. ' Written by Ben Hauch on 3/31/11
  834. ' Last updated 10/21/11 by Ben Hauch
  835. ' Recalculates the specified trap attributes in accordance with generic charms or special base usage
  836. Dim stTime#
  837. stTime = Timer
  838. Dim Shield%, CharmName$, CharmPower#, CharmBonus#, CharmA#, CharmL%, CharmCFX%, filterflag As Boolean, AutoFCriteria() As Variant
  839. Dim PasteRange As Range, t() As Variant, CRE() As Variant, j As Long, tmp1() As Variant, tmp2() As Variant
  840. Dim BaseRow%, TrapRow%, rMice() As Variant, allMice() As Variant, Location$
  841.  
  842. 'Store any Autofilters (e.g. trap&base combinations) and then remove them
  843. Sheets("BestSetup").Range("B22").Select
  844. If Sheets("BestSetup").FilterMode Then
  845.     filterflag = True
  846.     AutoFCriteria = GetAutofilterNames
  847.     Sheets("BestSetup").AutoFilterMode = False
  848.     Sheets("BestSetup").Range("TrBsTable").AutoFilter
  849.     End If
  850. Let j = 1
  851. Shield = Range("ShieldIndex").Value
  852. CharmName = Application.Index(Range("Charmnames"), Range("Charmindex").Value)
  853. Location = Range("LocationName").Value
  854. Set PasteRange = Nothing
  855.  
  856. ReDim CRE(1 To Range("TrBsTable[Trap]").Count, 1 To Range("TrBsTable[Luck]").Column - 1) '-1 because we start in column B, not A
  857. ReDim tmp1(1 To Range("Traps[Weapon]").Count, 1 To 8), _
  858.       tmp2(1 To Range("Bases[Base]").Count, 1 To 7)
  859.  
  860. ' Copy the current BestSetup table into a VBA array
  861. CRE = Range("TrBsTable[[Trap]:[Luck]]").Value
  862.  
  863. ' Reset only the values that need resetting
  864. Select Case Range("PrevCharm").Value
  865. Case "Nanny", "DChoco", "Artisan", "Champion"
  866.     Attrib = "All" 'Trigger Cheese Effect recalculation
  867. End Select
  868. Select Case Attrib
  869.     Case "Power"
  870.         Set PasteRange = Range("TrBsTable[[Sum Power]:[Power]]")
  871.         CharmPower = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 1).Value
  872.         CharmBonus = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 2).Value
  873.        
  874.         'Tribal Area only location effect  - however, is not called if the setup doesn't change but location does
  875.         If (CharmName = "Tribal Power") Then
  876.             If Not ((Location = "Nerg Plains") Or (Location = "Derr Dunes") Or (Location = "Elub Shore")) Then
  877.                 CharmPower = 0
  878.                 CharmBonus = 0
  879.             End If
  880.         End If
  881.        
  882.         ' First - Redimension the arrays to the current size of the CRE table
  883.         ReDim t(1 To UBound(CRE), 1 To 4)
  884.         ' Next - Redim tmp1() to the trap table only, and tmp2 to the base table only
  885.         tmp1 = Range("Traps[[Weapon]:[Cheese Effect]]").Value
  886.         tmp2 = Range("Bases[[Base]:[Cheese Effect]]").Value
  887.         For j = 1 To UBound(CRE)
  888.             TrapRow = Application.Match(CRE(j, 1), Application.Index(tmp1, 0, 1), 0)
  889.             BaseRow = Application.Match(CRE(j, 2), Application.Index(tmp2, 0, 1), 0)
  890.             t(j, 1) = tmp1(TrapRow, 4)
  891.             t(j, 2) = tmp1(TrapRow, 5)
  892.             t(j, 3) = tmp2(BaseRow, 3)
  893.             t(j, 4) = tmp2(BaseRow, 4)
  894.         Next j
  895.         ' Now we're done with tmp1 and tmp2, so we can run the total power computation in a redimensioned array
  896.         ReDim tmp1(1 To UBound(CRE), 1 To 3), tmp2(0)
  897.         For j = 1 To UBound(tmp1)
  898.             tmp1(j, 1) = t(j, 1) + t(j, 3) + CharmPower
  899.             tmp1(j, 2) = t(j, 2) + t(j, 4) + CharmBonus
  900.             tmp1(j, 3) = Application.RoundUp(tmp1(j, 1) * (1 + tmp1(j, 2)), 0)
  901.         Next j
  902.         ' now we just need to paste this Nx3 array back to the CRE table
  903.         PasteRange.Value = tmp1
  904.         ' erase arrays from memory
  905.         Set PasteRange = Nothing
  906.         ReDim CRE(0), tmp1(0)
  907.     Case "Attraction"
  908.         CharmA = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 3).Value
  909.         Set PasteRange = Range("TrBsTable[ATR]")
  910.         ReDim t(1 To UBound(CRE), 5 To 6)
  911.         tmp1 = Range("Traps[[Weapon]:[Cheese Effect]]").Value
  912.         tmp2 = Range("Bases[[Base]:[Cheese Effect]]").Value
  913.         For j = 1 To UBound(CRE)
  914.             t(j, 5) = Application.VLookup(CRE(j, 1), tmp1, 6, False)
  915.             t(j, 6) = Application.VLookup(CRE(j, 2), tmp2, 5, False)
  916.         Next j
  917.         ReDim tmp1(1 To UBound(CRE), 1 To 1), tmp2(0)
  918.         For j = 1 To UBound(tmp1)
  919.             tmp1(j, 1) = (t(j, 5) + t(j, 6) + CharmA)
  920.         Next j
  921.         PasteRange.Value = tmp1
  922.         Set PasteRange = Nothing
  923.         ReDim CRE(0), tmp1(0)
  924.     Case "Luck"
  925.         CharmL = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 4).Value
  926.         Set PasteRange = Range("TrBsTable[Luck]")
  927.         ReDim t(1 To UBound(CRE), 7 To 8)
  928.         tmp1 = Range("Traps[[Weapon]:[Cheese Effect]]").Value
  929.         tmp2 = Range("Bases[[Base]:[Cheese Effect]]").Value
  930.         For j = 1 To UBound(CRE)
  931.             t(j, 7) = Application.VLookup(CRE(j, 1), tmp1, 7, False)
  932.             t(j, 8) = Application.VLookup(CRE(j, 2), tmp2, 6, False)
  933.         Next j
  934.         If Shield = 1 Then CharmL = CharmL + 7
  935.         If Range("BonusWeekend").Value = 1 Then CharmL = CharmL + 5
  936.         ReDim tmp1(1 To UBound(CRE), 1 To 1), tmp2(0)
  937.         For j = 1 To UBound(tmp1)
  938.             tmp1(j, 1) = (t(j, 7) + t(j, 8) + CharmL)
  939.         Next j
  940.         PasteRange.Value = tmp1
  941.         Set PasteRange = Nothing
  942.         ReDim CRE(0), tmp1(0)
  943.     Case "All"
  944.         CharmL = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 4).Value
  945.         CharmA = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 3).Value
  946.         CharmPower = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 1).Value
  947.         CharmBonus = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 2).Value
  948.         CharmCFX = Range("Charms").Find(CharmName, LookIn:=xlValues, LookAt:=xlWhole).Offset(0, 5).Value
  949.         If Shield = 1 Then CharmL = CharmL + 7
  950.         If Range("BonusWeekend").Value = 1 Then CharmL = CharmL + 5
  951.         'Tribal Area only location effect  - however, is not called if the setup doesn't change but location does
  952.         If (CharmName = "Tribal Power") Then
  953.             If Not ((Location = "Nerg Plains") Or (Location = "Derr Dunes") Or (Location = "Elub Shore")) Then
  954.                 CharmPower = 0
  955.                 CharmBonus = 0
  956.             End If
  957.         End If
  958.         Set PasteRange = Range("TrBsTable[[Trap]:[Luck]]")
  959.         tmp1 = Range("Traps[[Weapon]:[Cheese Effect]]").Value
  960.         tmp2 = Range("Bases[[Base]:[Cheese Effect]]").Value
  961.         ReDim t(1 To UBound(CRE), 1 To 10)
  962.         If CharmName = "Champion" Then
  963.             For j = 1 To UBound(CRE)
  964.                 TrapRow = Application.Match(CRE(j, 1), Application.Index(tmp1, 0, 1), 0)
  965.                 BaseRow = Application.Match(CRE(j, 2), Application.Index(tmp2, 0, 1), 0)
  966.                 t(j, 1) = tmp1(TrapRow, 4)  ' Trap Power
  967.                 t(j, 2) = tmp1(TrapRow, 5)  ' Trap Bonus
  968.                 t(j, 3) = tmp2(BaseRow, 3)  ' Base Power
  969.                 t(j, 4) = tmp2(BaseRow, 4)  ' Base Bonus
  970.                 t(j, 5) = tmp1(TrapRow, 6)  ' Trap Attraction Bonus
  971.                 t(j, 6) = tmp2(BaseRow, 5)  ' Base Attraction Bonus
  972.                 t(j, 7) = tmp1(TrapRow, 7)  ' Trap Luck
  973.                 If CRE(j, 2) Like "Bronze To*" Then
  974.                     t(j, 8) = 7                 ' 5 base + 2 with Champ charm
  975.                 ElseIf CRE(j, 2) Like "Silver To*" Then
  976.                     t(j, 8) = 10                ' 7 base + 3 with Champ charm
  977.                 ElseIf CRE(j, 2) Like "Golden To*" Then
  978.                     t(j, 8) = 12                ' 8 base + 4 with Champ charm
  979.                 Else
  980.                     t(j, 8) = tmp2(BaseRow, 6)  ' For non-Tourney bases
  981.                 End If
  982.                 t(j, 9) = tmp1(TrapRow, 3)  ' Trap Type
  983.                 t(j, 10) = Application.Min(6, Application.Max(-6, tmp1(TrapRow, 8) + tmp2(BaseRow, 7) + CharmCFX))
  984.             Next j
  985.         Else
  986.             For j = 1 To UBound(CRE)
  987.                 TrapRow = Application.Match(CRE(j, 1), Application.Index(tmp1, 0, 1), 0)
  988.                 BaseRow = Application.Match(CRE(j, 2), Application.Index(tmp2, 0, 1), 0)
  989.                 t(j, 1) = tmp1(TrapRow, 4)  ' Trap Power
  990.                 t(j, 2) = tmp1(TrapRow, 5)  ' Trap Bonus
  991.                 t(j, 3) = tmp2(BaseRow, 3)  ' Base Power
  992.                 t(j, 4) = tmp2(BaseRow, 4)  ' Base Bonus
  993.                 t(j, 5) = tmp1(TrapRow, 6)  ' Trap Attraction Bonus
  994.                 t(j, 6) = tmp2(BaseRow, 5)  ' Base Attraction Bonus
  995.                 t(j, 7) = tmp1(TrapRow, 7)  ' Trap Luck
  996.                 t(j, 8) = tmp2(BaseRow, 6)  ' Base Luck
  997.                 t(j, 9) = tmp1(TrapRow, 3)  ' Trap Type
  998.                 t(j, 10) = Application.Min(6, Application.Max(-6, tmp1(TrapRow, 8) + tmp2(BaseRow, 7) + CharmCFX))
  999.             Next j
  1000.         End If
  1001.         ReDim tmp1(1 To UBound(CRE), 1 To 1), tmp2(1 To 13, 1 To 2)
  1002.         tmp2 = Range("CheeseEffect").Value
  1003.         For j = 1 To UBound(tmp1)
  1004.             CRE(j, 3) = t(j, 9)
  1005.             CRE(j, 4) = tmp2(t(j, 10) + 7, 1)
  1006.             CRE(j, 5) = t(j, 1) + t(j, 3) + CharmPower
  1007.             CRE(j, 6) = t(j, 2) + t(j, 4) + CharmBonus
  1008.             CRE(j, 7) = Application.RoundUp(CRE(j, 5) * (1 + CRE(j, 6)), 0)
  1009.             CRE(j, 8) = (t(j, 5) + t(j, 6) + CharmA)
  1010.             CRE(j, 9) = (t(j, 7) + t(j, 8) + CharmL)
  1011.         Next j
  1012.         PasteRange.Value = CRE
  1013.         Set PasteRange = Nothing
  1014.         ReDim CRE(0)
  1015. End Select
  1016.  
  1017. Select Case Application.Index(Range("Locations29[Locations]"), Range("LocationIndex"))
  1018.     Case "Seasonal Garden - Spring", "Seasonal Garden - Summer", "Seasonal Garden - Winter"
  1019.         Call SeasonalBoost
  1020.         Range("PrevLoc").Value = "Seas"
  1021.     Case "Seasonal Garden - Fall"
  1022.         Call SeasonalBoost
  1023.         Call SoulXLuckBoost("SG")
  1024.         Range("PrevLoc").Value = "Seasf"
  1025.     Case "Derr Dunes", "Nerg Plains", "Elub Shore", "Cape Clawed"
  1026.         Call TikiBoost
  1027.         Range("PrevLoc").Value = "Trib"
  1028.     Case "Terrortories - Corn Maze", "Terrortories - Haunted Manor", "Terrortories - Pumpkin Patch"
  1029.         Call SoulXLuckBoost("Terror")
  1030.         Range("PrevLoc").Value = "Terror"
  1031.     Case Else
  1032.         If Range("PrevLoc").Value = "Seas" Then
  1033.             Range("PrevLoc").Value = ""
  1034.             Call TrapReset("Power")
  1035.             End If
  1036.         If Range("PrevLoc").Value = "Trib" Then
  1037.             Range("PrevLoc").Value = ""
  1038.             Call TrapReset("Luck")
  1039.             End If
  1040.         If Range("PrevLoc").Value = "Seasf" Or Range("Prevloc").Value = "Terror" Then
  1041.             Range("PrevLoc").Value = ""
  1042.             Call TrapReset("All")
  1043.             End If
  1044. End Select
  1045. If Range("CharmName").Value = "Nanny" Then Range("TrBsTable[Trap type]").Value = "Parental"
  1046. If Range("CharmName").Value = "Spellbook" Then Call SBBCharm
  1047. rMice = Sheets("BestSetup").Range(Cells(5, 11), Cells(7, Cells(7, 10).End(xlToRight).Column)).Value
  1048. If UBound(rMice, 2) > 60 Then GoTo SubExit
  1049. allMice = Range("Mice[[#All],[Mice]:[Tactical]]").Value
  1050. Call CatchRateColumns(rMice, allMice, Application.Index(Range("Locations29[Locations]"), Range("LocationIndex")))
  1051. Call CreateSortColumns
  1052.  
  1053. SubExit:
  1054. ' Restore Autofilters
  1055. If filterflag Then Call SetAutofilterNames(AutoFCriteria())
  1056. Debug.Print "TrapReset(" & Attrib & "): " & Format(Timer - stTime, "##0.000") & " seconds"
  1057. End Sub
  1058.  
  1059. Private Sub CatchRateColumns(rMice() As Variant, allMice() As Variant, Location$)
  1060. ' Written by Ben Hauch over a freaking long period of time ;)
  1061. ' Last updated by Ben Hauch on 10/21/11
  1062.  
  1063. ' Call this sub after making a change to Power|Luck|Trap Type|Location|Cheese
  1064. ' rMice is the array containing the mouse name, subgroup, power, and attraction rate for which catch rates need to
  1065. ' be calculated.
  1066. ' allMice is the array containing all mice, powers, and effectivenesses
  1067. ' Based on LocationName, a different method will be executed (i.e. Dracano is separate due to Dragon & Dragonbane,
  1068. ' Warpath is separate due to Super Charms, ZT is separate due to the power/penalty adjustments of pinchers/oat/bsp)
  1069. stTime = Timer
  1070. ' General Purpose items
  1071. Dim Trapty() As Variant, Power() As Variant, Luck() As Variant, i As Long, j As Long, k As Long, Ubnd As Long
  1072. Dim MouseRow%, TraptyCol() As Variant, CRC() As Variant, CharmName$, TrapNames() As Variant
  1073. ReDim CRC(1 To Range("TrBsTable[Power]").Count, 1 To UBound(rMice, 2))
  1074.  
  1075. Ubnd = UBound(CRC, 1)
  1076. Power = Sheets("BestSetup").Range("TrBsTable[[Sum Power]:[Power]]").Value
  1077. Luck = Sheets("BestSetup").Range("TrBsTable[Luck]").Value
  1078. Trapty = Sheets("BestSetup").Range("TrBsTable[Trap Type]").Value
  1079. ReDim TraptyCol(1 To Ubnd)
  1080. CharmName = Application.Index(Range("Charmnames"), Range("CharmIndex"))
  1081.  
  1082. ' Longest operation is determining which columns to grab effectiveness values from.
  1083. ' To counteract this, we use case statements instead since new types are added very rarely
  1084. ' and the Mice sheet column order is rather stable
  1085. For i = 1 To Ubnd
  1086.     Select Case Trapty(i, 1)
  1087.     Case "Arcane": TraptyCol(i) = 7
  1088.     Case "Draconic": TraptyCol(i) = 8
  1089.     Case "Forgotten": TraptyCol(i) = 9
  1090.     Case "Hydro": TraptyCol(i) = 10
  1091.     Case "Parental": TraptyCol(i) = 11
  1092.     Case "Physical": TraptyCol(i) = 12
  1093.     Case "Shadow": TraptyCol(i) = 13
  1094.     Case "Tactical": TraptyCol(i) = 14
  1095.     End Select
  1096. Next i
  1097.  
  1098. Select Case Location
  1099. Case "Dracano"
  1100.     If rMice(1, 1) <> "" Then
  1101.         ' Do special case (Dragon is always first mouse if sorting didn't fail)
  1102.         MouseRow = Application.Match(rMice(1, 1), Application.Index(allMice, 0, 1), 0)
  1103.         On Error Resume Next
  1104.         For i = 1 To Ubnd
  1105.             If Not CharmName = "Dragonbane" Then
  1106.                 CRC(i, 1) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, 1))
  1107.             Else
  1108.                 CRC(i, 1) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (4 + Power(i, 2)), Luck(i, 1), rMice(3, 1))
  1109.             End If
  1110.         Next i
  1111.         On Error GoTo 0
  1112.         ' Now do the other 2 or more mice
  1113.         For j = 2 To UBound(rMice, 2)
  1114.             MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1115.             For i = 1 To Ubnd
  1116.                 CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1117.             Next i
  1118.         Next j
  1119.     End If
  1120. Case "Jungle of Dread"
  1121.     ' The Dreaded Charm gives a boost against all members of Dreaded Horde
  1122.     If rMice(1, 1) <> "" Then
  1123.         For j = 1 To UBound(rMice, 2)
  1124.             MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1125.             If Not CharmName = "Dreaded" Then
  1126.                 ' Regular case
  1127.                 For i = 1 To Ubnd
  1128.                     CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1129.                 Next i
  1130.             Else
  1131.                 If Not rMice(2, j) = "Dreaded Horde" Then
  1132.                     ' Still nothing, you Sylvan you
  1133.                     For i = 1 To Ubnd
  1134.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1135.                     Next i
  1136.                 Else
  1137.                     ' Boom!
  1138.                     For i = 1 To Ubnd
  1139.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (4 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1140.                     Next i
  1141.                 End If
  1142.             End If
  1143.         Next j
  1144.     End If
  1145. Case "Fiery Warpath - Wave 1", "Fiery Warpath - Wave 2", "Fiery Warpath - Wave 3", "Fiery Warpath - Wave 4"
  1146.     ' Need to boost all setups that have Super Warpath * as the charm
  1147.     If rMice(1, 1) <> "" Then
  1148.         For j = 1 To UBound(rMice, 2)
  1149.         MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1150.         If Not CharmName = "Flamebane" Then
  1151.             Select Case rMice(2, j)
  1152.             Case "Marching Flame - Archer"
  1153.                 On Error Resume Next
  1154.                 For i = 1 To Ubnd
  1155.                     If Not CharmName = "Super Warpath Archer" Then
  1156.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1157.                     Else
  1158.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (1.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1159.                     End If
  1160.                 Next i
  1161.                 On Error GoTo 0
  1162.             Case "Marching Flame - Warrior"
  1163.                 On Error Resume Next
  1164.                 For i = 1 To Ubnd
  1165.                     If Not CharmName = "Super Warpath Warrior" Then
  1166.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1167.                     Else
  1168.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (1.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1169.                     End If
  1170.                 Next i
  1171.                 On Error GoTo 0
  1172.             Case "Marching Flame - Cavalry"
  1173.                 On Error Resume Next
  1174.                 For i = 1 To Ubnd
  1175.                     If Not CharmName = "Super Warpath Cavalry" Then
  1176.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1177.                     Else
  1178.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (1.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1179.                     End If
  1180.                 Next i
  1181.                 On Error GoTo 0
  1182.             Case "Marching Flame - Mage"
  1183.                 On Error Resume Next
  1184.                 For i = 1 To Ubnd
  1185.                     If Not CharmName = "Super Warpath Mage" Then
  1186.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1187.                     Else
  1188.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (1.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1189.                     End If
  1190.                 Next i
  1191.                 On Error GoTo 0
  1192.             Case "Marching Flame - Scout"
  1193.                 On Error Resume Next
  1194.                 For i = 1 To Ubnd
  1195.                     If Not CharmName = "Super Warpath Scout" Then
  1196.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1197.                     Else
  1198.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (1.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1199.                     End If
  1200.                 Next i
  1201.                 On Error GoTo 0
  1202.             Case "Marching Flame - Commander"
  1203.                 On Error Resume Next
  1204.                 For i = 1 To Ubnd
  1205.                     If Not CharmName = "Super Warpath Commander" Then
  1206.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1207.                     Else
  1208.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (1.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1209.                     End If
  1210.                 Next i
  1211.                 On Error GoTo 0
  1212.             Case Else
  1213.                 For i = 1 To Ubnd
  1214.                     CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1215.                 Next i
  1216.             End Select
  1217.         Else  'Using Flamebane Charm = +150% power bonus
  1218.             For i = 1 To Ubnd
  1219.                 CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 1) * (2.5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1220.             Next i
  1221.         End If
  1222.         Next j
  1223.     End If
  1224. Case "Zugzwang's Tower"
  1225.     ' Need to apply side bonuses & penalties
  1226.     If rMice(1, 1) <> "" Then
  1227.     ' ZT is looped by column then by row, rather than by row then column, due to the insanity
  1228.         Dim mouserowarray() As Variant
  1229.         ReDim mouserowarray(1 To UBound(rMice, 2))
  1230.         For i = 1 To UBound(rMice, 2)
  1231.             mouserowarray(i) = Application.Match(rMice(1, i), Application.Index(allMice, 0, 1), 0)
  1232.         Next i
  1233.         TrapNames = Range("TrBsTable[Trap]").Value
  1234.         ' Iterate through mice
  1235.         For i = 1 To Ubnd
  1236.             Select Case TrapNames(i, 1)
  1237.             Case "Mystic Pawn Pincher"
  1238.                 For j = 1 To UBound(rMice, 2)
  1239.                     If Not rMice(1, j) = "Mystic Pawn" Then
  1240.                         If Not rMice(1, j) = "Technic Pawn" Then
  1241.                             ' Normal attractable mouse
  1242.                             If Not CharmName = "Rook Crumble" Then
  1243.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 3), Luck(i, 1), rMice(3, j))
  1244.                             Else
  1245.                                 ' Rook Crumble Charm
  1246.                                 If Not rMice(1, j) Like "*Rook" Then
  1247.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 3), Luck(i, 1), rMice(3, j))
  1248.                                 Else
  1249.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 1) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1250.                                 End If
  1251.                             End If
  1252.                         Else ' Technic Pawn -- include penalty to power & bonus
  1253.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), TraptyCol(i)), (Power(i, 1) - 60) * (1 + Power(i, 2) - 0.05), Luck(i, 1), rMice(3, j))
  1254.                         End If
  1255.                     Else ' Mystic Pawn! Yay! pwn it.
  1256.                         CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), TraptyCol(i)), (Power(i, 1) + 10920) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1257.                     End If
  1258.                 Next j
  1259.             Case "Technic Pawn Pincher"
  1260.                 For j = 1 To UBound(rMice, 2)
  1261.                     If Not rMice(1, j) = "Technic Pawn" Then
  1262.                         If Not rMice(1, j) = "Mystic Pawn" Then
  1263.                             ' Normal attractable mouse
  1264.                             If Not CharmName = "Rook Crumble" Then
  1265.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 3), Luck(i, 1), rMice(3, j))
  1266.                             Else
  1267.                                 ' Rook Crumble Charm
  1268.                                 If Not rMice(1, j) Like "*Rook" Then
  1269.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 3), Luck(i, 1), rMice(3, j))
  1270.                                 Else
  1271.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 1) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1272.                                 End If
  1273.                             End If
  1274.                         Else ' Mystic Pawn -- include penalty to power & bonus
  1275.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 60) * (1 + Power(i, 2) - 0.05), Luck(i, 1), rMice(3, j))
  1276.                         End If
  1277.                     Else ' Technic Pawn! Yay! pwn it.
  1278.                         CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 10920) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1279.                     End If
  1280.                 Next j
  1281.             Case "Blackstone Pass"
  1282.                 For j = 1 To UBound(rMice, 2)
  1283.                     If Not rMice(1, j) Like "Mystic*" Then
  1284.                         If Not rMice(1, j) Like "Technic*" Then
  1285.                             ' Normal attractable mouse
  1286.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 3), Luck(i, 1), rMice(3, j))
  1287.                         Else ' Technic Side -- include penalty to power & bonus
  1288.                             If Not CharmName = "Rook Crumble" Then
  1289.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 2400) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1290.                             Else
  1291.                                 If Not rMice(1, j) Like "*Rook" Then
  1292.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 2400) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1293.                                 Else
  1294.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 2400) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1295.                                 End If
  1296.                             End If
  1297.                         End If
  1298.                     Else ' Mystic Side! Yay! pwn it.
  1299.                         If Not CharmName = "Rook Crumble" Then
  1300.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 1800) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1301.                         Else
  1302.                             If Not rMice(1, j) Like "*Rook" Then
  1303.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 1800) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1304.                             Else
  1305.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 1800) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1306.                             End If
  1307.                         End If
  1308.                     End If
  1309.                 Next j
  1310.             Case "Obvious Ambush"
  1311.                 For j = 1 To UBound(rMice, 2)
  1312.                     If Not rMice(1, j) Like "Technic*" Then
  1313.                         If Not rMice(1, j) Like "Mystic*" Then
  1314.                             ' Normal attractable mouse
  1315.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), Power(i, 3), Luck(i, 1), rMice(3, j))
  1316.                         Else ' Mystic Side -- include penalty to power & bonus
  1317.                             If Not CharmName = "Rook Crumble" Then
  1318.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 2400) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1319.                             Else
  1320.                                 If Not rMice(1, j) Like "*Rook" Then
  1321.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 2400) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1322.                                 Else
  1323.                                     CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) - 2400) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1324.                                 End If
  1325.                             End If
  1326.                         End If
  1327.                     Else ' Technic Side! Yay! pwn it.
  1328.                         If Not CharmName = "Rook Crumble" Then
  1329.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 1800) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1330.                         Else
  1331.                             If Not rMice(1, j) Like "*Rook" Then
  1332.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 1800) * (1 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1333.                             Else
  1334.                                 CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), 14), (Power(i, 1) + 1800) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1335.                             End If
  1336.                         End If
  1337.                     End If
  1338.                 Next j
  1339.             Case Else 'Not a ZT trap
  1340.                 For j = 1 To UBound(rMice, 2)
  1341.                     If Not CharmName = "Rook Crumble" Then
  1342.                         CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1343.                     Else
  1344.                         If Not rMice(1, j) Like "*Rook" Then
  1345.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1346.                         Else
  1347.                             CRC(i, j) = CATCHRATE(allMice(mouserowarray(j), TraptyCol(i)), Power(i, 1) * (5 + Power(i, 2)), Luck(i, 1), rMice(3, j))
  1348.                         End If
  1349.                     End If
  1350.                 Next j
  1351.             End Select
  1352.         Next i
  1353.     End If
  1354. Case "Crystal Library"
  1355.     ' Zurreal's Folly gets a boost vs. Zurreal if the Scholar charm is active
  1356.     If Not CharmName Like "Scholar*" Then
  1357.         ' No special CR code
  1358.         If Not rMice(1, 1) = "" Then
  1359.             For j = 1 To UBound(rMice, 2)
  1360.                 MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1361.                 For i = 1 To Ubnd
  1362.                     CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1363.                 Next i
  1364.             Next j
  1365.         End If
  1366.     Else
  1367.         ' Zurreal is attractable, so need to give ZF some powah vs. Zurry
  1368.         If Not rMice(1, 1) = "" Then
  1369.             TrapNames = Range("TrBsTable[Trap]").Value
  1370.             For j = 1 To UBound(rMice, 2)
  1371.                 Select Case rMice(2, j)
  1372.                 Case "Zurreal - Zurreal"
  1373.                     MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1374.                     For i = 1 To Ubnd
  1375.                         If TrapNames(i, 1) = "Zurreal's Folly" Then
  1376.                             ' Need to know the effectiveness - assuming 3000% to start (10/15: changed to 5500%)
  1377.                             CRC(i, j) = CATCHRATE(55, Power(i, 3), Luck(i, 1), rMice(3, j))
  1378.                         Else
  1379.                             CRC(i, j) = 0 'CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1380.                         End If
  1381.                     Next i
  1382.                 Case Else
  1383.                     MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1384.                     For i = 1 To Ubnd
  1385.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1386.                     Next i
  1387.                 End Select
  1388.             Next j
  1389.         End If
  1390.     End If
  1391. Case "Snow Fortress - Throne Room"
  1392.     ' Only Nutcracker trap can work vs. Mad Elf Mouse, and nobody should be using anything but it
  1393.     If Not rMice(1, 1) = "" Then
  1394.         TrapNames = Range("TrBsTable[Trap]").Value
  1395.         For j = 1 To UBound(rMice, 2)
  1396.             Select Case rMice(2, j)
  1397.             Case "Event - Mad Elf"
  1398.                 MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1399.                 For i = 1 To Ubnd
  1400.                     If TrapNames(i, 1) = "Nutcracker Nuisance" Then
  1401.                         CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1402.                     Else
  1403.                         CRC(i, j) = 0
  1404.                     End If
  1405.                 Next i
  1406.             Case Else
  1407.                 MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1408.                 For i = 1 To Ubnd
  1409.                     CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1410.                 Next i
  1411.             End Select
  1412.         Next j
  1413.     End If
  1414. Case Else
  1415.     ' Nothing special, proceed as usual
  1416.     If Not rMice(1, 1) = "" Then
  1417.         For j = 1 To UBound(rMice, 2)
  1418.             MouseRow = Application.Match(rMice(1, j), Application.Index(allMice, 0, 1), 0)
  1419.             For i = 1 To Ubnd
  1420.                 CRC(i, j) = CATCHRATE(allMice(MouseRow, TraptyCol(i)), Power(i, 3), Luck(i, 1), rMice(3, j))
  1421.             Next i
  1422.         Next j
  1423.     End If
  1424. End Select
  1425. ' Adjust this range if moving the table....
  1426. Range(Cells(22, 11), Cells(22, 10 + UBound(rMice, 2))).Value = "CR "
  1427. With Range(Cells(23, 11), Cells(22 + UBound(CRC, 1), 10 + UBound(rMice, 2)))
  1428.     .Value = CRC
  1429.     .NumberFormat = "0.0%"
  1430. End With
  1431. Debug.Print "CRC: " & Format(Timer - stTime, "##0.000") & " seconds"
  1432. End Sub
  1433. Private Sub CreateSortColumns()
  1434. ' Created by Ben Hauch 3/24/2012
  1435. ' Last updated 3/24/2012 by Ben Hauch
  1436.  
  1437. Dim ChzEffArr(), StalePrbArr(), tmpStale(), Atr(), CRpH(), CHpH(), rMice()
  1438. Dim CheeseCats(), CatchTable(), totAR As Double, PrbAtr As Double
  1439. Dim i As Long, j As Integer, nRows As Long, nCols As Integer, output()
  1440.  
  1441. ' Do we need to create the columns?
  1442. If Not Range("TrBsTable[#Headers]").End(xlToRight).Value = "Per Cheese" Then
  1443.     Range("TrBsTable[#Headers]").End(xlToRight).Offset(0, 1).Value = "Per Hunt"
  1444.     Range("TrBsTable[#Headers]").End(xlToRight).Offset(0, 1).Value = "Per Cheese"
  1445. End If
  1446.  
  1447. ' Load data from worksheets
  1448. ChzEffArr = Range("EffectLookup[[Cheese Effect]:[Prb]]").Value
  1449. CheeseCats = Application.Index(ChzEffArr, 0, 1)
  1450. StalePrbArr = Range("TrBsTable[Cheese Effect]").Value
  1451. Atr = Range("TrBsTable[ATR]").Value
  1452. totAR = Range("totAR").Value
  1453. On Error GoTo exitsub
  1454. CatchTable = Range("TrBsTable[[CR ]:[Per Hunt]]").Value
  1455. On Error GoTo 0
  1456. rMice = Sheets("BestSetup").Range(Cells(8, 11), Cells(8, 11).End(xlToRight)).Value
  1457.  
  1458. ' Have columns & data, do work.
  1459. nRows = UBound(Atr, 1)
  1460. nCols = UBound(rMice, 2)
  1461. If nCols > 100 Then nCols = 1
  1462. ReDim tmpStale(1 To nRows)
  1463. ReDim output(1 To nRows, 1 To 2)
  1464. ' Loop over each setup
  1465. For i = 1 To nRows
  1466.     ' And then each mouse
  1467.     For j = 1 To nCols
  1468.         ' Calculate the sumproduct
  1469.         output(i, 1) = output(i, 1) + CatchTable(i, j) * rMice(1, j) / 100 * (1 + (100 - totAR) * Atr(i, 1) / totAR)
  1470.     Next j
  1471.     tmpStale(i) = Application.Match(StalePrbArr(i, 1), CheeseCats, 0)
  1472.     PrbAtr = totAR + (100 - totAR) * Atr(i, 1)
  1473.     output(i, 2) = output(i, 1) * 100 / (PrbAtr + (100 - PrbAtr) * ChzEffArr(tmpStale(i), 2))
  1474. Next i
  1475. Range("TrBsTable[[Per Hunt]:[Per Cheese]]").Value = output
  1476. exitsub:
  1477. On Error GoTo 0
  1478. End Sub
  1479. Private Function Find_Range(Find_Item As Variant, _
  1480.                             Search_Range As Range, _
  1481.                             Optional LookIn As Variant, _
  1482.                             Optional LookAt As Variant) As Range
  1483. Dim c As Range, firstAddress
  1484. If IsMissing(LookIn) Then LookIn = xlValues
  1485. If IsMissing(LookAt) Then LookAt = xlWhole
  1486.  
  1487. With Search_Range
  1488.     Set c = .Find(What:=Find_Item, LookIn:=LookIn, LookAt:=LookAt, searchorder:=xlByRows, searchdirection:=xlNext)
  1489.     If Not c Is Nothing Then
  1490.         Set Find_Range = c
  1491.         firstAddress = c.Address
  1492.         Do
  1493.             Set Find_Range = Union(Find_Range, c)
  1494.             Set c = .FindNext(c)
  1495.         Loop While Not c Is Nothing And c.Address <> firstAddress
  1496.     End If
  1497. End With
  1498. End Function
  1499. Private Function GetAutofilterNames() As Variant
  1500. ' Written by Ben Hauch on 4/13/11
  1501. ' Last updated by Ben Hauch on 4/16/11
  1502.  
  1503. ' Determines current active autofilters, if any, and stores them.
  1504. ' Can store ANY number of autofilters, e.g. not just 1 or 2.
  1505.  
  1506. Dim w As Worksheet, strFilterRange$, FilterArray() As Variant, f As Long
  1507. Set w = ActiveSheet
  1508. With w.AutoFilter
  1509.     strFilterRange = .Range.Address
  1510.     With .Filters
  1511.         ReDim FilterArray(1 To .Count + 1, 1 To 3)
  1512.         For f = 2 To .Count + 1
  1513.             With .Item(f - 1)
  1514.                 If .On Then
  1515.                     FilterArray(f, 1) = .Criteria1
  1516.                     If .Operator Then
  1517.                         FilterArray(f, 2) = .Operator
  1518.                         On Error Resume Next
  1519.                         If Not IsError(.Criteria2) Then FilterArray(f, 3) = .Criteria2
  1520.                         On Error GoTo 0
  1521.                         End If
  1522.                     End If
  1523.                 End With
  1524.             Next f
  1525.         End With
  1526.     End With
  1527. ' Store the filtered range in the first index of the returned array
  1528. FilterArray(1, 1) = strFilterRange
  1529. GetAutofilterNames = FilterArray
  1530. End Function
  1531. Private Function SetAutofilterNames(FilterArray() As Variant)
  1532. ' Written by Ben Hauch on 4/13/11
  1533. ' Last updated by Ben Hauch on 4/16/11
  1534.  
  1535. ' Restores all autofilters that were saved with GetAutofilterNames
  1536.  
  1537. Dim w As Worksheet, col%, strFilterRange$
  1538. Set w = ActiveSheet
  1539. strFilterRange = FilterArray(1, 1)
  1540. FilterArray(1, 1) = Empty
  1541. For col = 2 To UBound(FilterArray(), 1)
  1542.     If Not IsEmpty(FilterArray(col, 1)) Then
  1543.         If FilterArray(col, 2) Then ' An operator is present -> 2 or more criteria
  1544.             If IsEmpty(FilterArray(col, 3)) Then 'more than 2 criteria?
  1545.             w.Range(strFilterRange).AutoFilter field:=col - 1, _
  1546.                 Criteria1:=Array(FilterArray(col, 1)), _
  1547.                 Operator:=FilterArray(col, 2)
  1548.             Else 'Exactly two criteria were used
  1549.                 w.Range(strFilterRange).AutoFilter field:=col - 1, Criteria1:=FilterArray(col, 1), Operator:=FilterArray(col, 2), Criteria2:=FilterArray(col, 3)
  1550.                 End If
  1551.         Else ' No operator -> Single criterion
  1552.             w.Range(strFilterRange).AutoFilter field:=col - 1, _
  1553.             Criteria1:=FilterArray(col, 1)
  1554.             End If
  1555.         End If
  1556.     Next col
  1557. End Function
Advertisement
Add Comment
Please, Sign In to add comment