-----------------------------------
-- Table defining the skill level max value based on actor level and the skill rank.
-- Skill caps per rank: https://wiki-ffo-jp.translate.goog/html/2570.html?_x_tr_sl=ja&_x_tr_tl=en&_x_tr_hl=en&_x_tr_pto=sc
-----------------------------------
xi = xi or {}
xi.data = xi.data or {}
xi.data.skillLevel = xi.data.skillLevel or {}
-----------------------------------

xi.data.skillLevel.dataTable =
{
-- [Level] = { A+,  A,  B+,   B,  B-,  C+,   C,  C-,   D,   E,   F,   G },
    [ 0] = {   3,   3,   2,   2,   2,   2,   2,   2,   2,   2,   2,   1 },
    [ 1] = {   6,   6,   5,   5,   5,   5,   5,   5,   4,   4,   4,   3 },
    [ 2] = {   9,   9,   7,   7,   7,   7,   7,   7,   6,   6,   6,   5 },
    [ 3] = {  12,  12,  10,  10,  10,  10,  10,  10,   9,   9,   8,   7 },
    [ 4] = {  15,  15,  13,  13,  13,  13,  13,  13,  12,  11,  10,   9 },
    [ 5] = {  18,  18,  16,  16,  16,  16,  16,  16,  14,  14,  13,  11 },
    [ 6] = {  21,  21,  19,  19,  19,  19,  19,  19,  17,  16,  15,  13 },
    [ 7] = {  24,  24,  22,  22,  22,  21,  21,  21,  20,  19,  17,  15 },
    [ 8] = {  27,  27,  25,  25,  25,  24,  24,  24,  22,  21,  20,  17 },
    [ 9] = {  30,  30,  28,  28,  28,  27,  27,  27,  25,  24,  22,  19 },
    [10] = {  33,  33,  31,  31,  31,  30,  30,  30,  28,  26,  24,  21 },
    [11] = {  36,  36,  34,  34,  34,  33,  33,  33,  31,  29,  27,  23 },
    [12] = {  39,  39,  36,  36,  36,  35,  35,  35,  33,  31,  29,  25 },
    [13] = {  42,  42,  39,  39,  39,  38,  38,  38,  36,  34,  31,  27 },
    [14] = {  45,  45,  42,  42,  42,  41,  41,  41,  39,  36,  33,  29 },
    [15] = {  48,  48,  45,  45,  45,  44,  44,  44,  41,  39,  36,  31 },
    [16] = {  51,  51,  48,  48,  48,  47,  47,  47,  44,  41,  38,  33 },
    [17] = {  54,  54,  51,  51,  51,  49,  49,  49,  47,  44,  40,  35 },
    [18] = {  57,  57,  54,  54,  54,  52,  52,  52,  49,  46,  43,  37 },
    [19] = {  60,  60,  57,  57,  57,  55,  55,  55,  52,  49,  45,  39 },
    [20] = {  63,  63,  60,  60,  60,  58,  58,  58,  55,  51,  47,  41 },
    [21] = {  66,  66,  63,  63,  63,  61,  61,  61,  58,  54,  50,  43 },
    [22] = {  69,  69,  65,  65,  65,  63,  63,  63,  60,  56,  52,  45 },
    [23] = {  72,  72,  68,  68,  68,  66,  66,  66,  63,  59,  54,  47 },
    [24] = {  75,  75,  71,  71,  71,  69,  69,  69,  66,  61,  56,  49 },
    [25] = {  78,  78,  74,  74,  74,  72,  72,  72,  68,  64,  59,  51 },
    [26] = {  81,  81,  77,  77,  77,  75,  75,  75,  71,  66,  61,  53 },
    [27] = {  84,  84,  80,  80,  80,  77,  77,  77,  74,  69,  63,  55 },
    [28] = {  87,  87,  83,  83,  83,  80,  80,  80,  76,  71,  66,  57 },
    [29] = {  90,  90,  86,  86,  86,  83,  83,  83,  79,  74,  68,  59 },
    [30] = {  93,  93,  89,  89,  89,  86,  86,  86,  82,  76,  70,  61 },
    [31] = {  96,  96,  92,  92,  92,  89,  89,  89,  85,  79,  73,  63 },
    [32] = {  99,  99,  94,  94,  94,  91,  91,  91,  87,  81,  75,  65 },
    [33] = { 102, 102,  97,  97,  97,  94,  94,  94,  90,  84,  77,  67 },
    [34] = { 105, 105, 100, 100, 100,  97,  97,  97,  93,  86,  79,  69 },
    [35] = { 108, 108, 103, 103, 103, 100, 100, 100,  95,  89,  82,  71 },
    [36] = { 111, 111, 106, 106, 106, 103, 103, 103,  98,  91,  84,  73 },
    [37] = { 114, 114, 109, 109, 109, 105, 105, 105, 101,  94,  86,  75 },
    [38] = { 117, 117, 112, 112, 112, 108, 108, 108, 103,  96,  89,  77 },
    [39] = { 120, 120, 115, 115, 115, 111, 111, 111, 106,  99,  91,  79 },
    [40] = { 123, 123, 118, 118, 118, 114, 114, 114, 109, 101,  93,  81 },
    [41] = { 126, 126, 121, 121, 121, 117, 117, 117, 112, 104,  96,  83 },
    [42] = { 129, 129, 123, 123, 123, 119, 119, 119, 114, 106,  98,  85 },
    [43] = { 132, 132, 126, 126, 126, 122, 122, 122, 117, 109, 100,  87 },
    [44] = { 135, 135, 129, 129, 129, 125, 125, 125, 120, 111, 102,  89 },
    [45] = { 138, 138, 132, 132, 132, 128, 128, 128, 122, 114, 105,  91 },
    [46] = { 141, 141, 135, 135, 135, 130, 130, 130, 125, 116, 107,  93 },
    [47] = { 144, 144, 138, 138, 138, 133, 133, 133, 128, 119, 109,  95 },
    [48] = { 147, 147, 141, 141, 141, 136, 136, 136, 130, 121, 112,  97 },
    [49] = { 150, 150, 144, 144, 144, 139, 139, 139, 133, 124, 114,  99 },
    [50] = { 153, 153, 147, 147, 147, 142, 142, 142, 136, 126, 116, 101 },
    [51] = { 158, 158, 151, 151, 151, 146, 146, 146, 140, 130, 120, 105 },
    [52] = { 163, 163, 156, 156, 156, 151, 151, 151, 145, 135, 124, 109 },
    [53] = { 168, 168, 161, 161, 161, 156, 156, 156, 150, 139, 128, 113 },
    [54] = { 173, 173, 166, 166, 166, 161, 161, 161, 154, 144, 133, 117 },
    [55] = { 178, 178, 171, 171, 171, 166, 166, 166, 159, 148, 137, 121 },
    [56] = { 183, 183, 176, 176, 176, 170, 170, 170, 164, 153, 141, 125 },
    [57] = { 188, 188, 181, 181, 181, 175, 175, 175, 168, 157, 146, 129 },
    [58] = { 193, 193, 186, 186, 186, 180, 180, 180, 173, 162, 150, 133 },
    [59] = { 198, 198, 191, 191, 191, 185, 185, 185, 178, 166, 154, 137 },
    [60] = { 203, 203, 196, 196, 196, 190, 190, 190, 183, 171, 159, 141 },
    [61] = { 207, 207, 199, 199, 198, 192, 192, 192, 184, 172, 161, 143 },
    [62] = { 212, 211, 203, 202, 201, 195, 194, 194, 186, 174, 163, 145 },
    [63] = { 217, 215, 207, 205, 204, 197, 196, 196, 188, 176, 165, 147 },
    [64] = { 222, 219, 210, 208, 206, 200, 199, 198, 190, 178, 167, 149 },
    [65] = { 227, 223, 214, 212, 209, 202, 201, 200, 192, 180, 169, 151 },
    [66] = { 232, 227, 218, 215, 212, 205, 203, 202, 194, 182, 171, 153 },
    [67] = { 236, 231, 221, 218, 214, 207, 205, 204, 195, 184, 173, 155 },
    [68] = { 241, 235, 225, 221, 217, 210, 208, 206, 197, 186, 175, 157 },
    [69] = { 246, 239, 229, 225, 220, 212, 210, 208, 199, 188, 177, 159 },
    [70] = { 251, 244, 233, 228, 223, 215, 212, 210, 201, 190, 179, 161 },
    [71] = { 256, 249, 237, 232, 226, 218, 214, 212, 202, 192, 181, 163 },
    [72] = { 261, 254, 242, 236, 229, 221, 217, 214, 204, 194, 183, 165 },
    [73] = { 266, 259, 246, 241, 233, 224, 219, 216, 206, 196, 185, 167 },
    [74] = { 271, 264, 251, 245, 236, 227, 222, 218, 208, 198, 187, 169 },
    [75] = { 276, 269, 256, 250, 240, 230, 225, 220, 210, 200, 189, 171 },
    [76] = { 281, 274, 261, 255, 245, 235, 230, 225, 214, 203, 191, 173 },
    [77] = { 286, 279, 266, 260, 250, 240, 235, 230, 218, 206, 193, 175 },
    [78] = { 291, 284, 271, 265, 255, 245, 240, 235, 222, 209, 195, 177 },
    [79] = { 296, 289, 276, 270, 260, 250, 245, 240, 226, 212, 197, 179 },
    [80] = { 301, 294, 281, 275, 265, 255, 250, 245, 230, 215, 199, 181 },
    [81] = { 307, 300, 287, 281, 271, 261, 256, 251, 235, 219, 202, 183 },
    [82] = { 313, 306, 293, 287, 277, 267, 262, 257, 240, 223, 205, 185 },
    [83] = { 319, 312, 299, 293, 283, 273, 268, 263, 245, 227, 208, 187 },
    [84] = { 325, 318, 305, 299, 289, 279, 274, 269, 250, 231, 211, 189 },
    [85] = { 331, 324, 311, 305, 295, 285, 280, 275, 255, 235, 214, 191 },
    [86] = { 337, 330, 317, 311, 301, 291, 286, 281, 260, 239, 217, 193 },
    [87] = { 343, 336, 323, 317, 307, 297, 292, 287, 265, 243, 220, 195 },
    [88] = { 349, 342, 329, 323, 313, 303, 298, 293, 270, 247, 223, 197 },
    [89] = { 355, 348, 335, 329, 319, 309, 304, 299, 275, 251, 226, 199 },
    [90] = { 361, 354, 341, 335, 325, 315, 310, 305, 280, 255, 229, 201 },
    [91] = { 368, 361, 348, 342, 332, 322, 317, 312, 286, 260, 233, 204 },
    [92] = { 375, 368, 355, 349, 339, 329, 324, 319, 292, 265, 237, 207 },
    [93] = { 382, 375, 362, 356, 346, 336, 331, 326, 298, 270, 241, 210 },
    [94] = { 389, 382, 369, 363, 353, 343, 338, 333, 304, 275, 245, 213 },
    [95] = { 396, 389, 376, 370, 360, 350, 345, 340, 310, 280, 249, 216 },
    [96] = { 403, 396, 383, 377, 367, 357, 352, 347, 316, 285, 253, 219 },
    [97] = { 410, 403, 390, 384, 374, 364, 359, 354, 322, 290, 257, 222 },
    [98] = { 417, 410, 397, 391, 381, 371, 366, 361, 328, 295, 261, 225 },
    [99] = { 424, 417, 404, 398, 388, 378, 373, 368, 334, 300, 265, 228 },
}

xi.data.skillLevel.getSkillCap = function(actorLevel, skillRank)
    -- Sanitize fed values
    local levelToCheck = utils.defaultIfNil(actorLevel, 0)             -- Assume level 0
    local rankToCheck  = utils.defaultIfNil(skillRank, xi.skillRank.G) -- Assume rank G

    -- Going to assume levels over 99 give 1 skill level, just like master levels.
    return xi.data.skillLevel.dataTable[utils.clamp(levelToCheck, 0, 99)][utils.clamp(rankToCheck, 1, 12)] + utils.clamp(levelToCheck - 99, 0, 156)
end
