summaryrefslogtreecommitdiff
path: root/js/comp/stat.js
blob: cd756468dfcb87864d0636472d6fb17ec5184e2c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/**
 * Make computations about tmwAthena's stat requirements.
 *
 * Amongst other things, this can be used to derive a minimum base level for a stat configuration.
 */
var stat = function(){
  var stat = {};
  var statpoint = [
    48,
    52,
    56,
    60,
    64,
    69,
    74,
    79,
    84,
    90,
    96,
    102,
    108,
    115,
    122,
    129,
    136,
    144,
    152,
    160,
    168,
    177,
    186,
    195,
    204,
    214,
    224,
    234,
    244,
    255,
    266,
    277,
    288,
    300,
    312,
    324,
    336,
    349,
    362,
    375,
    388,
    402,
    416,
    430,
    444,
    459,
    474,
    489,
    504,
    520,
    536,
    552,
    568,
    585,
    602,
    619,
    636,
    654,
    672,
    690,
    708,
    727,
    746,
    765,
    784,
    804,
    824,
    844,
    864,
    885,
    906,
    927,
    948,
    970,
    992,
    1014,
    1036,
    1059,
    1082,
    1105,
    1128,
    1152,
    1176,
    1200,
    1224,
    1249,
    1274,
    1299,
    1324,
    1350,
    1376,
    1402,
    1428,
    1455,
    1482,
    1509,
    1536,
    1564,
    1592
  ];
  /* If a character is using a certain number of status points, what is the lowest level it could be? */
  stat.minLevelForStatusPoints = function(statusPoints) {
    /*
     * tmwAthena status points for a level are described by the following recurrence relation:
     *  p(1) = 48
     *  p(l) = p(l - 1) + floor((l + 14) / 4)
     * For whatever reason, the server also loads a cached copy from a file of all places - db/statpoint.txt.
     * If this is out of sync with the equation, fun things can happen.
     * For now, naively assume that statpoint.txt is correct and shamelessly dump it here (see above).
     */
    return crossfilter.bisect.left(statpoint, statusPoints, 0, statpoint.length) + 1;
  };
  var statusPointInc = [0, 0]
  stat.statusPointsForStat = function(v) {
    if (isNaN(v)) {
      throw "Invalid input";
    }
    /* First, convert the absolute stat to terms of increments. */
    /* This is as simple as removing the starting value - 1 - from it. */
    /*
     * The status points needed to increase from a stat with value v can be calculated as follows:
     *  floor((v + 9) / 10) + 1
     */
    if (statusPointInc.length > v) {
      return statusPointInc[v];
    }
    var i = stat.statusPointsForStat(v - 1) + Math.floor(((v - 1) + 9) / 10) + 1;
    statusPointInc.push(i);
    return i;
  }
  /* If a character has a certain arrangement of attributes, how many status points are required for this configuration? */
  stat.statusPointsForStats = function(str, agi, vit, dex, int, luk) {
    return stat.statusPointsForStat(str) +
           stat.statusPointsForStat(agi) +
           stat.statusPointsForStat(vit) +
           stat.statusPointsForStat(dex) +
           stat.statusPointsForStat(int) +
           stat.statusPointsForStat(luk);
  };
  /* Helper function currying minLevelForStatusPoints and stat.statusPointsForStats */
  stat.minLevelForStats = function(str, agi, vit, dex, int, luk) {
    return stat.minLevelForStatusPoints(stat.statusPointsForStats(str, agi, vit, dex, int, luk));
  };
  return stat;
}();