Advertisement
syntax53

MajorMUD Exp Calculation Formula in VB

Jan 12th, 2025 (edited)
1,675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Function CalcExpNeeded(ByVal startlevel As Long, ByVal exptable As Long) As Currency
  2. 'FROM: https://www.mudinfo.net/viewtopic.php?p=7703
  3. On Error GoTo error:
  4. Dim nModifiers() As Integer, i As Long, j As Currency, k As Currency, exp_multiplier As Long, exp_divisor As Long, Ret() As Currency
  5. Dim lastexp As Currency, startexp As Currency, running_exp_tabulation As Currency, billions_tabulator As Currency
  6. Dim potential_new_exp As Currency, ALTERNATE_NEW_EXP As Currency, accurate_exp() As Currency
  7. Dim MAX_UINT As Double, numlevels As Integer, num_divides As Integer
  8.  
  9. MAX_UINT = 4294967295#
  10. numlevels = 1
  11.  
  12. ReDim Ret(startlevel To (startlevel + numlevels - 1))
  13.  
  14. For i = 1 To (startlevel + numlevels - 1)
  15.     startexp = lastexp
  16.     If i = 1 Then
  17.         running_exp_tabulation = 0
  18.     ElseIf i = 2 Then
  19.         running_exp_tabulation = exptable * 10
  20.     Else
  21.         If i <= 26 Then 'levels 1-26
  22.            nModifiers() = GetExpModifiers(i)
  23.             exp_multiplier = nModifiers(0)
  24.             exp_divisor = nModifiers(1)
  25.         ElseIf i <= 55 Then 'levels 27-55
  26.            exp_multiplier = 115
  27.             exp_divisor = 100
  28.         ElseIf i <= 58 Then 'levels 56-58
  29.            exp_multiplier = 109
  30.             exp_divisor = 100
  31.         Else 'levels 59+
  32.            exp_multiplier = 108
  33.             exp_divisor = 100
  34.         End If
  35.        
  36.         If i = 97 Then
  37.             'Debug.Print i
  38.        End If
  39.        
  40.         If exp_multiplier = 0 Or exp_divisor = 0 Then
  41.             potential_new_exp = 0
  42.         Else
  43.             potential_new_exp = running_exp_tabulation * exp_multiplier
  44.         End If
  45.        
  46.         If potential_new_exp > MAX_UINT Then 'UINT ROLLOVER #1
  47.            num_divides = 0
  48.             Do While potential_new_exp > MAX_UINT
  49.                 running_exp_tabulation = Fix(running_exp_tabulation / 100)
  50.                 potential_new_exp = running_exp_tabulation * exp_multiplier
  51.                 num_divides = num_divides + 1
  52.             Loop
  53.             If num_divides > 1 Then
  54.                 ALTERNATE_NEW_EXP = Fix((running_exp_tabulation * exp_multiplier * 100) / exp_divisor)
  55.             Else
  56.                 ALTERNATE_NEW_EXP = Fix(potential_new_exp / exp_divisor)
  57.             End If
  58.             Do While num_divides > 0
  59.                 ALTERNATE_NEW_EXP = ALTERNATE_NEW_EXP * 100
  60.                 num_divides = num_divides - 1
  61.             Loop
  62.         Else
  63.             ALTERNATE_NEW_EXP = Fix(potential_new_exp / exp_divisor)
  64.         End If
  65.        
  66.         j = (1000000 * exp_multiplier * billions_tabulator)
  67.         Do While j > MAX_UINT
  68.             j = j - MAX_UINT - 1 'UINT ROLLOVER #2
  69.        Loop
  70.         Do While j >= 1000000000
  71.             j = j - 1000000000
  72.             billions_tabulator = billions_tabulator + 1
  73.         Loop
  74.        
  75.         k = (j + ALTERNATE_NEW_EXP)
  76.         Do While k >= 1000000000
  77.             k = k - 1000000000
  78.             billions_tabulator = billions_tabulator + 1
  79.         Loop
  80.        
  81.         running_exp_tabulation = k
  82.     End If
  83.    
  84.     lastexp = running_exp_tabulation + (billions_tabulator * 1000000000)
  85.    
  86.     If i >= startlevel Then
  87.         Ret(i) = lastexp
  88.     End If
  89. Next i
  90.  
  91. CalcExpNeeded = Ret(startlevel)
  92.  
  93. out:
  94. On Error Resume Next
  95. Exit Function
  96. error:
  97. Call HandleError("CalcExpNeeded")
  98. Resume out:
  99. End Function
  100.  
  101. Private Function GetExpModifiers(ByVal nLevel As Integer) As Integer()
  102. Dim Ret(1) As Integer
  103. Ret(0) = 0
  104. Ret(1) = 0
  105.  
  106. Select Case nLevel
  107.     Case 3:
  108.         Ret(0) = 40
  109.         Ret(1) = 20
  110.         'return [40, 20];
  111.    Case 4, 5:
  112.         Ret(0) = 44
  113.         Ret(1) = 24
  114.         'return [44, 24];
  115.    Case 6, 7:
  116.         Ret(0) = 48
  117.         Ret(1) = 28
  118.         'return [48, 28];
  119.    Case 8, 9:
  120.         Ret(0) = 52
  121.         Ret(1) = 32
  122.         'return [52, 32];
  123.    Case 10, 11:
  124.         Ret(0) = 56
  125.         Ret(1) = 36
  126.         'return [56, 36];
  127.    Case 12, 13:
  128.         Ret(0) = 60
  129.         Ret(1) = 40
  130.         'return [60, 40];
  131.    Case 14, 15:
  132.         Ret(0) = 65
  133.         Ret(1) = 45
  134.         'return [65, 45];
  135.    Case 16, 17:
  136.         Ret(0) = 70
  137.         Ret(1) = 50
  138.         'return [70, 50];
  139.    Case 18:
  140.         Ret(0) = 75
  141.         Ret(1) = 55
  142.         'return [75, 55];
  143.    Case Else:
  144.         If nLevel <= 26 Then
  145.             Ret(0) = 50
  146.             Ret(1) = 40
  147.             'return [50, 40];
  148.        Else
  149.             Ret(0) = 23
  150.             Ret(1) = 20
  151.             'return [23, 20];
  152.        End If
  153.  
  154. End Select
  155.  
  156. GetExpModifiers = Ret
  157.  
  158. 'function GetExpModifiers($iLevel) {
  159. '    switch ($iLevel) {
  160. '        Case 3:
  161. '            return [40, 20];
  162. '        Case 4:
  163. '        Case 5:
  164. '            return [44, 24];
  165. '        Case 6:
  166. '        Case 7:
  167. '            return [48, 28];
  168. '        Case 8:
  169. '        Case 9:
  170. '            return [52, 32];
  171. '        Case 10:
  172. '        Case 11:
  173. '            return [56, 36];
  174. '        Case 12:
  175. '        Case 13:
  176. '            return [60, 40];
  177. '        Case 14:
  178. '        Case 15:
  179. '            return [65, 45];
  180. '        Case 16:
  181. '        Case 17:
  182. '            return [70, 50];
  183. '        Case 18:
  184. '            return [75, 55];
  185. 'default:
  186. '            if ($iLevel <= 26) {
  187. '                return [50, 40];
  188. '            } else {
  189. '                return [23, 20];
  190. '            }
  191. '    }
  192. '}
  193. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement