forked from odota/core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.js
171 lines (168 loc) · 4.58 KB
/
constants.js
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* File managing constant values for the application
**/
var fs = require('fs');
var cfs = fs.readdirSync('./json');
var countries = require('world-countries');
var constants = {};
cfs.forEach(function(f)
{
constants[f.split(".")[0]] = require('./json/' + f);
});
var heroes = constants.heroes.result.heroes;
//key heroes by id
constants.heroes = {};
//key heroes by name
constants.hero_names = {};
heroes.forEach(function(h)
{
h.img = "/apps/dota2/images/heroes/" + h.name.replace("npc_dota_hero_", "") + "_full.png";
constants.heroes[h.id] = h;
constants.hero_names[h.name] = h;
});
/*
//leagues, key by id
var leagues = JSON.parse(JSON.stringify(constants.leagues.result.leagues));
constants.leagues = {};
leagues.forEach(function(l) {
l.name = l.name.replace("#DOTA_Item_", "").split("_").join(" ");
constants.leagues[l.leagueid] = l;
});
*/
//items, already keyed by name
var items = constants.items.itemdata;
constants.item_ids = {};
for (var key in items)
{
constants.item_ids[items[key].id] = key;
items[key].img = "/apps/dota2/images/items/" + items[key].img;
}
constants.item_groups = [];
for (var key in items)
{
if (items[key].components)
{
var arr = expandItemGroup(key);
var obj = {};
arr.forEach(function(e)
{
obj[e] = 1;
});
constants.item_groups.push(obj);
}
}
function expandItemGroup(key)
{
var base = [key];
if (items[key] && items[key].components)
{
return [].concat.apply(base, items[key].components.map(function(c)
{
return expandItemGroup(c);
}));
}
else
{
return base;
}
}
constants.countries = {};
countries.forEach(function(c){
constants.countries[c.cca2] = c;
});
//console.log(constants.item_groups);
constants.items = items;
//abilities, already keyed by name
var abilities = constants.abilities.abilitydata;
// Add missing Shadow Fiend raze abilities by copying the shortest raze
if (!abilities.nevermore_shadowraze2) {
abilities.nevermore_shadowraze2 = Object.assign({}, abilities.nevermore_shadowraze1);
// Find and replace short raze range with medium raze range
abilities.nevermore_shadowraze2.attrib = abilities.nevermore_shadowraze2.attrib.replace(/\d{3}/, 450);
}
if (!abilities.nevermore_shadowraze3) {
abilities.nevermore_shadowraze3 = Object.assign({}, abilities.nevermore_shadowraze1);
// Find and replace short raze range with long raze range
abilities.nevermore_shadowraze3.attrib = abilities.nevermore_shadowraze3.attrib.replace(/\d{3}/, 700);
}
for (var key2 in abilities)
{
abilities[key2].img = "/apps/dota2/images/abilities/" + key2 + "_md.png";
abilities[key2].cmb = abilities[key2].cmb.replace("http://cdn.dota2.com", "");
}
abilities.attribute_bonus = {
dname: "Attribute Bonus",
img: '/public/images/Stats.png',
attrib: "+2 All Attributes"
};
constants.abilities = abilities;
var ability_ids = {};
for (var key in constants.npc_abilities.DOTAAbilities)
{
var block = constants.npc_abilities.DOTAAbilities[key];
if (block && block.ID)
{
ability_ids[block.ID] = key;
}
}
constants.ability_ids = ability_ids;
constants.lanes = [];
for (var i = 0; i < 128; i++)
{
constants.lanes.push([]);
for (var j = 0; j < 128; j++)
{
var lane;
if (Math.abs(i - (127 - j)) < 8)
{
lane = 2; //mid
}
else if (j < 27 || i < 27)
{
lane = 3; //top
}
else if (j >= 100 || i >= 100)
{
lane = 1; //bot
}
else if (i < 50)
{
lane = 5; //djung
}
else if (i >= 77)
{
lane = 4; //rjung
}
else
{
lane = 2; //mid
}
constants.lanes[i].push(lane);
}
}
var cluster = {};
var region = {};
//Remove regions nesting
constants.regions = constants.regions.regions;
var regions = constants.regions;
for (var key in regions)
{
region[regions[key].region] = regions[key].display_name.slice("#dota_region_".length).split("_").map(function(s)
{
return s.toUpperCase();
}).join(" ");
if (regions[key].clusters)
{
regions[key].clusters.forEach(function(c)
{
cluster[c] = Number(regions[key].region);
});
}
}
cluster["121"] = constants.regions['USEast'].region;
constants.cluster = cluster;
constants.region = region;
constants.anonymous_account_id = 4294967295;
constants.map_url = '/public/images/map.png';
constants.ICON_PATH = '/public/images/yasp-icon.svg'; //path to the icon
module.exports = constants;