summaryrefslogtreecommitdiff
path: root/js/mv/parse.js
blob: 23a0f79d55b7dffcc9a3489e13cde038eb5adc93 (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
var mv = function(mv) {
  mv.parser = function() {
    var parser = {};
    var pcstat = {};
    var fullyDefinedCutoff = 0;
    parser.records = [];
    parser.fullyDefinedCutoff = function() { return fullyDefinedCutoff; };
    parser.parseRecords = function(data) {
      var spl = data.split(/\r?\n/);
      spl.forEach(function(e, i) {
        var d;
        d = e.match(/^(\d+\.\d+) PC(\d+) (\d+):(\d+),(\d+) GAINXP (\d+) (\d+) (\w+)/);
        if (d) {
          var mapSID = parseInt(d[3]);
          var ts = new Date(0);
          ts.setUTCSeconds(d[1]);
          var rec = {
            date: ts,
            pc:   parseInt(d[2]),
            map:  map.nameByServerID(parseInt(d[3]), ts),
            x:    parseInt(d[4]),
            y:    parseInt(d[5]),
            e:    parseInt(d[6]),
            j:    parseInt(d[7]),
            type: d[8],
            pcstat: pcstat[d[2]],
            target: 0,
            dmg: 0,
            wpn: 0
          };
          if (pcstat[d[2]] == undefined && (!fullyDefinedCutoff || ts > fullyDefinedCutoff)) {
            fullyDefinedCutoff = ts;
          }
          /* XXX: Fragile horrible and unstructured, this whole thing needs a rewrite really */
          if (i >= 2 && rec.type == "KILLXP") {
            d = spl[i - 1].match(/^(\d+\.\d+) MOB(\d+) DEAD/);
            if (d) {
              var mID = parseInt(d[2]);
              /* There's a massive wealth of data that can be collected from this. Number of assailants, weapons used, the relationships with the assailants... this can't be done with a simple lookbehind. For now, just extract what mob it was, and what the killing weapon used was. */
              d = spl[i - 2].match(/^(\d+\.\d+) PC(\d+) (\d+):(\d+),(\d+) WPNDMG MOB(\d+) (\d+) FOR (\d+) WPN (\d+)/);
              if (d) {
                softAssert(mID == parseInt(d[6]), "Integrity error: MOB ID mismatch!");
  //               softAssert(rec.pc == parseInt(d[2]), "Integrity error: PC ID mismatch!");
                rec.target = parseInt(d[7]);
                rec.dmg = parseInt(d[8]);
                rec.wpn = parseInt(d[9]);
              }
            } else {
              d = spl[i - 1].match(/^(\d+\.\d+) PC(\d+) (\d+):(\d+),(\d+) GAINXP (\d+) (\d+) (\w+)/);
              if (d) {
                var clone = parser.records[parser.records.length - 1];
                softAssert(rec.map == clone.map, "Integrity error: MAP ID mismatch!");
                rec.target = clone.target;
                rec.dmg = clone.dmg; /* FIXME: Take into account actual assist damage */
                rec.wpn = clone.wpn;
              }
            }
          }
          parser.records.push(rec);
          return;
        }
        d = e.match(/^(?:\d+\.\d+) PC(\d+) (?:\d+):(?:\d+),(?:\d+) STAT (\d+) (\d+) (\d+) (\d+) (\d+) (\d+) /);
        if (d) {
          var s = {
            str: parseInt(d[2]),
            agi: parseInt(d[3]),
            vit: parseInt(d[4]),
            int: parseInt(d[5]),
            dex: parseInt(d[6]),
            luk: parseInt(d[7])
          };
          s.blvl = stat.minLevelForStats(s.str, s.agi, s.vit, s.int, s.dex, s.luk);
          pcstat[d[1]] = s;
          return;
        }
      });
    };
    function softAssert(expr, msg) {
      if (!expr) {
        console.error("SOFTASSERT FAILURE: " + msg);
      }
    }
    return parser;
  }();
  return mv;
}(mv || {});