-
Notifications
You must be signed in to change notification settings - Fork 2
/
objectives.js
443 lines (362 loc) · 10.7 KB
/
objectives.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
var settings = require('settings.js').s;
var timers = require('timers');
var isZombie = require('zombie.js').isZombie;
// List of objectives
var objectives = new Array(
// Pickup 15 Gems
{
name: 'Pickup 15 gems',
reward: '+1 stats / gem',
init: function(obj) {
// Make sure name matches
var itemTotal = 15; // Total number of items to spawn
// Valid regions to spawn in
var poses = new Array({
x1: -6436,
y1: 6086,
x2: 2170,
y2: -2572
}, {
x1: 5963,
y1: -6030,
x2: -3010,
y2: -1426
});
var dire_ancient = game.findEntityByTargetname('dota_badguys_fort');
if(dire_ancient != null && dire_ancient.isValid()) {
// Spawn all gems
obj.poses = new Array();
for(var i=0; i<itemTotal;i++) {
// Grab a pos range
var pos = getRandomArray(poses);
// Pick a position for it
var xp = randomFromInterval(pos.x1, pos.x2);
var yp = randomFromInterval(pos.y1, pos.y2);
// Spawn an item into a random position
var item = dota.createItemDrop(dire_ancient, 'item_gem', xp, yp, 256);
// Grab the position is actually spawned at
var itemPos = item.netprops.m_vecOrigin;
// Store where it spawned
obj.poses.push({
x: itemPos.x,
y: itemPos.y,
z: itemPos.z
});
}
}
// Store how many are left
obj.totalRemaining = itemTotal;
},
gameFrame: function(obj) {
var dire_ancient = game.findEntityByTargetname('dota_badguys_fort');
if(dire_ancient == null || !dire_ancient.isValid()) return;
// Cycle all clients
for(var i=0;i<server.clients.length;i++) {
var client = server.clients[i];
if(!client) continue;
// Cycle all heroes of this client
var heroes = client.getHeroes();
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
if(!hero || !hero.isValid()) continue;
// Cycle all items of this hero
for(var j=0;j<14;j++) {
var itemSlot = hero.netprops.m_hItems[j];
if(itemSlot) {
if(itemSlot.netprops.m_hPurchaser == dire_ancient) {
// Delete the item
dota.remove(itemSlot);
// Grab the client's team
var team = client.netprops.m_iTeamNum;
// Check if it was a zombie that picked it up
if(team == dota.TEAM_DIRE) {
// Grab hero's position
var heroPos = hero.netprops.m_vecOrigin;
var realPos = heroPos;
// Find closest spawn point
var maxDist = 1000000;
for(var key in obj.poses) {
var dist = vecDist(heroPos, obj.poses[key]);
if(dist < maxDist) {
maxDist = dist;
realPos = obj.poses[key];
}
}
// Respawn the item
dota.createItemDrop(dire_ancient, 'item_gem', realPos);
// Tell this client they aren't allowed to pick it up
client.printToChat('You can\'t pickup human items.');
}else {
// Remove one
obj.totalRemaining -= 1;
// Change objective
if(obj.totalRemaining != 1) {
obj.name = 'Pickup '+obj.totalRemaining+' gems';
} else {
obj.name = 'Pickup 1 gem';
}
// Check if we've found all gems
if(obj.totalRemaining == 0) {
obj.completed = true;
}
// Tell all clients
for(var i=0;i<server.clients.length;i++) {
var c = server.clients[i];
if(!c || !c.isInGame()) continue;
// Print message
if(obj.totalRemaining != 1) {
c.printToChat('A gem was found! +1 stats to all humans! '+obj.totalRemaining+' gems to go!');
} else {
c.printToChat('A gem was found! +1 stats to all humans! 1 gem to go!');
}
// Make sure this client isn't a zombie
var playerID = c.netprops.m_iPlayerID;
if(!isZombie[playerID]) {
// Give stats
var heroes = c.getHeroes();
// Grab each hero of the client
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
// Add stats
hero.netprops.m_flStrength += 1;
hero.netprops.m_flAgility += 1;
hero.netprops.m_flIntellect += 1;
}
}
// Check if we've completed the objective
if(obj.completed) {
c.printToChat('All gems have been found! Objective complete!');
}
}
}
}
}
}
}
}
}
},
// Survive X minutes
{
name: 'Survive 10 minutes',
reward: '+5 stats / 2 minutes',
init: function(obj) {
obj.once = false;
},
gameFrame: function(obj) {
if(!obj.once && game.rules.props.m_nGameState == dota.STATE_GAME_IN_PROGRESS) {
obj.once = true;
// Add a timer for every 2 minutes
for(var i=2; i<=10; i += 2) {
timers.setTimeout(function() {
for(var i=0;i<server.clients.length;i++) {
var c = server.clients[i];
if(!c || !c.isInGame()) continue;
// Print message
c.printToChat('The humans have survived another 2 minutes! +5 stats to all humans!');
// Make sure this client isn't a zombie
var playerID = c.netprops.m_iPlayerID;
if(!isZombie[playerID]) {
// Give stats
var heroes = c.getHeroes();
// Grab each hero of the client
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
// Add stats
hero.netprops.m_flStrength += 5;
hero.netprops.m_flAgility += 5;
hero.netprops.m_flIntellect += 5;
}
}
}
}, i * 60 * 1000);
}
// This objective is now completed!
timers.setTimeout(function() {
obj.completed = true;
}, 10 * 60 * 1000);
}
}
},
// Hold the rosh pit for 60 seconds
{
name: 'Hold the Rosh Pit for 60 seconds',
reward: '+15 stats',
init: function(obj) {
obj.inside = false;
// Middle of the pit
obj.insidePos = {
x:2505,
y: -391,
z: 4
}
// Distance from this point for it to count
obj.insideDist = 500;
},
gameFrame: function(obj) {
var gameTime = game.rules.props.m_fGameTime;
var someoneInside = false;
loop1:
for(var i=0;i<server.clients.length;i++) {
var c = server.clients[i];
if(!c || !c.isInGame()) continue;
// Make sure this client isn't a zombie
var playerID = c.netprops.m_iPlayerID;
if(!isZombie[playerID]) {
// Give stats
var heroes = c.getHeroes();
// Grab each hero of the client
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
if(vecDist(hero.netprops.m_vecOrigin, obj.insidePos) < obj.insideDist) {
someoneInside = true;
break loop1;
}
}
}
}
if(!obj.inside) {
if(someoneInside) {
// Store that someone is inside
obj.inside = true;
obj.finishTime = gameTime + 60;
// Tell everyone about this challenge
for(var i=0;i<server.clients.length;i++) {
var c = server.clients[i];
if(!c || !c.isInGame()) continue;
// Print message
c.printToChat('A human has entered the Rosh Pit! Hold it for 60 seconds for a reward!');
}
}
} else {
if(!someoneInside) {
// Store that no one is in the pit
obj.inside = false;
// Tell everyone about this challenge
for(var i=0;i<server.clients.length;i++) {
var c = server.clients[i];
if(!c || !c.isInGame()) continue;
// Print message
c.printToChat('No humans are left in the Rosh Pit, the 60 seconds has reset!');
}
return;
}
// Check if the time is up yet
if(gameTime > obj.finishTime) {
// Store that this challenge is completed
obj.completed = true;
// Tell everyone about this challenge
for(var i=0;i<server.clients.length;i++) {
var c = server.clients[i];
if(!c || !c.isInGame()) continue;
// Print message
c.printToChat('The humans have held the Roshan pit for 60 seconds! +15 stats for all humans!');
// Make sure this client isn't a zombie
var playerID = c.netprops.m_iPlayerID;
if(!isZombie[playerID]) {
// Give stats
var heroes = c.getHeroes();
// Grab each hero of the client
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
// Add stats
hero.netprops.m_flStrength += 15;
hero.netprops.m_flAgility += 15;
hero.netprops.m_flIntellect += 15;
}
}
}
}
}
}
}
);
// Hook functions
game.hook('OnMapStart', onMapStart);
game.hook("OnGameFrame", onGameFrame);
// Add command to access objectives
console.addClientCommand('obj', CmdO);
// Command to access objectives
function CmdO(client, args) {
if(!client) return;
for(var i=0; i<objectives.length;i++) {
// Grab the objective
var o = objectives[i];
// Make sure it's not done already
if(!o.completed) {
// Create friendly number
var n = i+1;
if(n < 10) {
n = '0'+n;
}
// Tell the client about it
client.printToChat('['+n+'] '+o.name+' ['+o.reward+']');
}
}
}
function onMapStart() {
// Init all objectivies
for(var i=0; i<objectives.length;i++) {
// Grab the objective
var o = objectives[i];
// Check if it has an init function
if(o.init) {
o.init(o);
}
}
}
function onGameFrame() {
// Init all objectivies
for(var i=0; i<objectives.length;i++) {
// Grab the objective
var o = objectives[i];
// Check if it has an init function
if(!o.completed && o.gameFrame) {
o.gameFrame(o);
}
}
}
function getRandomArray(ar) {
return ar[Math.floor(Math.random()*ar.length)];
}
function randomFromInterval(from,to) {
// Make sure from < to
if(to < from) {
var t = to;
to = from;
from = t;
}
// Pick a number in this range
return Math.floor(Math.random()*(to-from+1)+from);
}
// Calculates the distance between two vectors (not taking into account for z)
function vecDist(vec1, vec2) {
if(!vec1 || !vec2) return 1000000;
var xx = (vec1.x - vec2.x);
var yy = (vec1.y - vec2.y);
return Math.sqrt(xx*xx + yy*yy);
}
// Some useful dev commands for singleplayer
if(settings.singlePlayer) {
console.addClientCommand('pos', function(client, args) {
var heroes = client.getHeroes();
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
server.print(hero.netprops.m_vecOrigin);
}
});
console.addClientCommand('p', function(client, args) {
var o = objectives[0];
var i = parseInt(args[0]) || 0;
var pos = o.poses[i];
dota.pingLocation(client, 0, 0, true, 0, pos);
});
console.addClientCommand('aegis', function(client, args) {
// Grab list of heroes
var heroes = client.getHeroes();
for(var hh=0; hh<heroes.length; hh++) {
var hero = heroes[hh];
dota.giveItemToHero('item_aegis', hero)
}
});
}