summaryrefslogtreecommitdiff
path: root/src/maps/maps.js
blob: 9237c4bd2805d96a17a81260becf06cc2d7c0cf6 (plain)
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
const rarities = require('./rarities.json');
const names = require('./names.json');
const modes = require('./modes.json');

const RARITIES = ['None', 'Rare', 'Epic', 'Legendary'];

function getTalentName(talent) {
  if (talent == 'NoTalent') {
    return 'No Talent';
  }

  switch (talent.slice(talent.length - 7 - 1, talent.length - 1)) {
    case 'TalentA':
    case 'TalentB':
    case 'TalentC':
      if (Object.keys(names).includes(talent)) {
        return names[talent];
      } else {
        return 'unknown';
      }
    default:
      return talent.substring(talent.lastIndexOf('_') + 1, talent.length - 1) // snake case to words
               .replace(/([A-Z])/g, (s) => ' ' + s.toLowerCase())
               .split(' ') // capitalize first letter
               .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
               .join(' ');
  }
}

function getTalentRarity(talent) {
  if (!talent || talent == 'NoTalent') {
    return 'None';
  }

  switch (talent.slice(talent.length - 7 - 1, talent.length - 1)) {
    case 'TalentA': return 'Rare';
    case 'TalentB': return 'Epic';
    case 'TalentC': return 'Legendary';
    default:
      if (Object.keys(rarities).includes(talent)) {
        return rarities[talent];
      } else {
        return 'unknown';
      }
  }
}

function getTalentRarityIndex(talent) {
  return RARITIES.indexOf(getTalentRarity(talent));
}

function getMaxLevel(entry) {
  switch (getTalentRarity(entry.Talent)) {
    case 'unknown':
    case 'None': return -1;
    case 'Rare': return 20;
    case 'Epic': return 10;
    case 'Legendary': return 5;
  }
};

function getScaledLevel(entry) {
  if (['unknown', 'None'].includes(getTalentRarity(entry.Talent))) {
    return 0;
  }
  return entry.Level / getMaxLevel(entry);
};

function getHero(actor) {
  return actor.substring(1, actor.length - 1);
}

function getMode(mode) {
  return modes[mode];
}

function hasTalents(mode) {
  return ['blitz_pvp_ranked', 'casual_aral'].includes(mode);
}

function playersPerMatch(mode) {
  return mode.includes('5v5')? 10 : 6;
}

function killDeathPoints(entry) {
  return entry.Kills - entry.Deaths;
}

function objectivePoints(entry) {
  return entry.CrystalMinerKills + entry.GoldMinerKills + entry.TurretKills;
}

function blitzPointsDelta(entry) {
  return killDeathPoints(entry) + objectivePoints(entry) * 3;
}

module.exports = {
  RARITIES,
  getTalentName,
  getTalentRarity,
  getTalentRarityIndex,
  getMaxLevel,
  getScaledLevel,
  getHero,
  getMode,
  hasTalents,
  playersPerMatch,
  killDeathPoints,
  objectivePoints,
  blitzPointsDelta,
};