-
Notifications
You must be signed in to change notification settings - Fork 1
/
ability_item_usage_shredder.lua
544 lines (466 loc) · 15.5 KB
/
ability_item_usage_shredder.lua
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
if GetBot():IsInvulnerable() or not GetBot():IsHero() or not string.find(GetBot():GetUnitName(), "hero") or GetBot():IsIllusion() then
return;
end
local ability_item_usage_generic = dofile( GetScriptDirectory().."/ability_item_usage_shutnik" )
local utils = require(GetScriptDirectory() .. "/util")
local mutil = require(GetScriptDirectory() .. "/Mylogic")
function AbilityLevelUpThink()
ability_item_usage_generic.AbilityLevelUpThink();
end
function BuybackUsageThink()
ability_item_usage_generic.BuybackUsageThink();
end
function CourierUsageThink()
ability_item_usage_generic.CourierUsageThink();
end
local ClosingDesire = 0;
local castSCDesire = 0;
local castTCDesire = 0;
local castCHDesire = 0;
local castCH2Desire = 0;
local castCHRDesire = 0;
local castCHR2Desire = 0;
local abilitySC = nil;
local abilityTC = nil;
local abilityCH = nil;
local abilityCH2 = nil;
local abilityCHR = nil;
local abilityCHR2 = nil;
local ultLoc = 0;
local ultLoc2 = 0;
local npcBot = nil;
local ultTime1 = 0;
local ultETA1 = 0;
local ultTime2 = 0;
local ultETA2 = 0;
function AbilityUsageThink()
if npcBot == nil then npcBot = GetBot(); end
if mutil.CanNotUseAbility(npcBot) then return end
if abilitySC == nil then abilitySC = npcBot:GetAbilityByName( "shredder_whirling_death" ) end
if abilityTC == nil then abilityTC = npcBot:GetAbilityByName( "shredder_timber_chain" ) end
if abilityCH == nil then abilityCH = npcBot:GetAbilityByName( "shredder_chakram" ) end
if abilityCH2 == nil then abilityCH2 = npcBot:GetAbilityByName( "shredder_chakram_2" ) end
if abilityCHR == nil then abilityCHR = npcBot:GetAbilityByName( "shredder_return_chakram" ) end
if abilityCHR2 == nil then abilityCHR2 = npcBot:GetAbilityByName( "shredder_return_chakram_2" ) end
castSCDesire = ConsiderSlithereenCrush();
castTCDesire, castTree, castType = ConsiderTimberChain();
castCHDesire, castCHLocation, eta = ConsiderChakram();
castCH2Desire, castCH2Location, eta2 = ConsiderChakram2();
castCHRDesire = ConsiderChakramReturn();
castCHR2Desire = ConsiderChakramReturn2();
ClosingDesire, Target = ConsiderClosing();
if ( castCHRDesire > 0 )
then
npcBot:Action_UseAbility( abilityCHR );
ultLoc = 0;
return;
end
if ( castCHR2Desire > 0 )
then
npcBot:Action_UseAbility( abilityCHR2 );
ultLoc2 = 0;
return;
end
if ( castCHDesire > 0 )
then
npcBot:Action_UseAbilityOnLocation( abilityCH, castCHLocation );
ultLoc = castCHLocation;
ultTime1 = DotaTime();
ultETA1 = eta + 0.5;
return;
end
if ( castCH2Desire > 0 )
then
npcBot:Action_UseAbilityOnLocation( abilityCH2, castCH2Location );
ultLoc2 = castCH2Location;
ultTime2 = DotaTime();
ultETA2 = eta2 + 0.5;
return;
end
if ( castTCDesire > 0 )
then
if castType == "tree" then
npcBot:Action_UseAbilityOnLocation( abilityTC, GetTreeLocation(castTree) );
else
npcBot:Action_UseAbilityOnLocation( abilityTC, castTree );
end
return;
end
if ( castSCDesire > 0 )
then
npcBot:Action_UseAbility( abilitySC );
return;
end
if ClosingDesire > 0 then
npcBot:Action_MoveToLocation(Target);
return
end
end
function StillTraveling(cType)
local proj = GetLinearProjectiles();
for _,p in pairs(proj)
do
if p ~= nil and (( cType == 1 and p.ability:GetName() == "shredder_chakram" ) or ( cType == 2 and p.ability:GetName() == "shredder_chakram_2" ) ) then
return true;
end
end
return false;
end
function GetBestTree(npcBot, enemy, nCastRange, hitRadios)
local bestTree=nil;
local mindis=10000;
local trees=npcBot:GetNearbyTrees(nCastRange);
for _,tree in pairs(trees) do
local x=GetTreeLocation(tree);
local y=npcBot:GetLocation();
local z=enemy:GetLocation();
if x~=y then
local a=1;
local b=1;
local c=0;
if x.x-y.x ==0 then
b=0;
c=-x.x;
else
a=-(x.y-y.y)/(x.x-y.x);
c=-(x.y + x.x*a);
end
local d = math.abs((a*z.x+b*z.y+c)/math.sqrt(a*a+b*b));
if d<=hitRadios and mindis>GetUnitToLocationDistance(enemy,x) and (GetUnitToLocationDistance(enemy,x)<=GetUnitToLocationDistance(npcBot,x)) then
bestTree=tree;
mindis=GetUnitToLocationDistance(enemy,x);
end
end
end
return bestTree;
end
function GetBestRetreatTree(npcBot, nCastRange)
local trees=npcBot:GetNearbyTrees(nCastRange);
local dest=utils.VectorTowards(npcBot:GetLocation(),utils.Fountain(GetTeam()),1000);
local BestTree=nil;
local maxdis=0;
for _,tree in pairs(trees) do
local loc=GetTreeLocation(tree);
if (not utils.AreTreesBetween(loc,100)) and
GetUnitToLocationDistance(npcBot,loc)>maxdis and
GetUnitToLocationDistance(npcBot,loc)<nCastRange and
utils.GetDistance(loc,dest)<880
then
maxdis=GetUnitToLocationDistance(npcBot,loc);
BestTree=loc;
end
end
if BestTree~=nil and maxdis>250 then
return BestTree;
end
return nil;
end
function GetUltLoc(npcBot, enemy, nManaCost, nCastRange, s)
local v=enemy:GetVelocity();
local sv=utils.GetDistance(Vector(0,0),v);
if sv>800 then
v=(v / sv) * enemy:GetCurrentMovementSpeed();
end
local x=npcBot:GetLocation();
local y=enemy:GetLocation();
local a=v.x*v.x + v.y*v.y - s*s;
local b=-2*(v.x*(x.x-y.x) + v.y*(x.y-y.y));
local c= (x.x-y.x)*(x.x-y.x) + (x.y-y.y)*(x.y-y.y);
local t=math.max((-b+math.sqrt(b*b-4*a*c))/(2*a) , (-b-math.sqrt(b*b-4*a*c))/(2*a));
local dest = (t+0.35)*v + y;
if GetUnitToLocationDistance(npcBot,dest)>nCastRange or npcBot:GetMana()<100+nManaCost then
return nil;
end
if enemy:GetMovementDirectionStability()<0.4 or ((not utils.IsFacingLocation(enemy,utils.Fountain(GetOpposingTeam()),60)) ) then
dest=utils.VectorTowards(y,utils.Fountain(GetOpposingTeam()),180);
end
if mutil.IsDisabled(true, enemy) then
dest=enemy:GetLocation();
end
return dest;
end
function ConsiderClosing()
if ( not npcBot:HasModifier("modifier_shredder_chakram_disarm") ) then
return BOT_ACTION_DESIRE_NONE, 0;
end
if mutil.IsGoingOnSomeone(npcBot)
then
local npcTarget = npcBot:GetTarget();
if mutil.IsValidTarget(npcTarget) and mutil.IsInRange(npcTarget, npcBot, 1000)
then
return BOT_ACTION_DESIRE_MODERATE, npcTarget:GetLocation();
end
end
return BOT_ACTION_DESIRE_NONE, 0;
end
function ConsiderSlithereenCrush()
if ( not abilitySC:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE;
end
local nRadius = abilitySC:GetSpecialValueInt( "whirling_radius" );
local nCastRange = 0;
local nDamage = abilitySC:GetSpecialValueInt("whirling_damage");
if mutil.IsRetreating(npcBot)
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nRadius, true, BOT_MODE_NONE );
for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
do
if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 1.0 ) and mutil.CanCastOnNonMagicImmune(npcEnemy) )
then
return BOT_ACTION_DESIRE_MODERATE;
end
end
end
if mutil.IsInTeamFight(npcBot, 1200)
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nRadius, true, BOT_MODE_NONE );
if ( tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes >= 2 ) then
return BOT_ACTION_DESIRE_MODERATE;
end
end
if mutil.IsPushing(npcBot)
then
local NearbyCreeps = npcBot:GetNearbyLaneCreeps(nRadius, true);
if NearbyCreeps ~= nil and #NearbyCreeps >= 3 and npcBot:GetMana()/npcBot:GetMaxMana() > 0.65 then
return BOT_ACTION_DESIRE_LOW;
end
end
if mutil.IsGoingOnSomeone(npcBot)
then
local npcTarget = npcBot:GetTarget();
if mutil.IsValidTarget(npcTarget) and mutil.CanCastOnNonMagicImmune(npcTarget) and mutil.IsInRange(npcTarget, npcBot, nRadius)
then
return BOT_ACTION_DESIRE_HIGH;
end
end
return BOT_ACTION_DESIRE_NONE;
end
function ConsiderTimberChain()
if ( not abilityTC:IsFullyCastable() )
then
return BOT_ACTION_DESIRE_NONE, 0;
end
local nRadius = abilityTC:GetSpecialValueInt( "chain_radius" );
local nSpeed = abilityTC:GetSpecialValueInt( "speed" );
local nCastRange = abilityTC:GetCastRange();
local nDamage = abilityTC:GetSpecialValueInt("damage");
if mutil.IsRetreating(npcBot) and npcBot:DistanceFromFountain() > 1000
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1200, true, BOT_MODE_NONE );
if tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes >= 1 then
local BRTree = GetBestRetreatTree(npcBot, nCastRange);
if BRTree ~= nil then
return BOT_ACTION_DESIRE_MODERATE, BRTree, "loc";
end
end
end
if mutil.IsGoingOnSomeone(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( mutil.IsValidTarget(npcTarget) and mutil.CanCastOnNonMagicImmune(npcTarget) and mutil.IsInRange(npcTarget, npcBot, nCastRange) and
not utils.AreTreesBetween( npcTarget:GetLocation(),nRadius ) )
then
local BTree = GetBestTree(npcBot, npcTarget, nCastRange, nRadius);
if BTree ~= nil then
return BOT_ACTION_DESIRE_MODERATE, BTree, "tree";
end
end
end
return BOT_ACTION_DESIRE_NONE, 0;
end
function ConsiderChakram()
if ( not abilityCH:IsFullyCastable() )
then
return BOT_ACTION_DESIRE_NONE, 0, 0;
end
local nRadius = abilityCH:GetSpecialValueFloat( "radius" );
local nSpeed = abilityCH:GetSpecialValueFloat( "speed" );
local nCastRange = abilityCH:GetCastRange();
local nManaCost = abilityCH:GetManaCost( );
local nDamage = 2*abilityCH:GetSpecialValueInt("pass_damage");
if mutil.IsRetreating(npcBot)
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE );
for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
do
if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 1.0 ) )
then
local loc = npcEnemy:GetLocation();
local eta = GetUnitToLocationDistance(npcBot, loc) / nSpeed;
return BOT_ACTION_DESIRE_MODERATE, loc, eta;
end
end
end
if mutil.IsDefending(npcBot) or mutil.IsPushing(npcBot)
then
local locationAoE = npcBot:FindAoELocation( true, false, npcBot:GetLocation(), nCastRange, nRadius, 0, 0 );
if ( locationAoE.count >= 3 and npcBot:GetMana() / npcBot:GetMaxMana() > 0.65 )
then
local loc = locationAoE.targetloc;
local eta = GetUnitToLocationDistance(npcBot, loc) / nSpeed;
return BOT_ACTION_DESIRE_LOW, loc, eta;
end
end
if mutil.IsGoingOnSomeone(npcBot)
then
local npcTarget = npcBot:GetTarget();
if mutil.IsValidTarget(npcTarget) and mutil.CanCastOnNonMagicImmune(npcTarget) and mutil.IsInRange(npcTarget, npcBot, nCastRange-200)
then
local Loc = GetUltLoc(npcBot, npcTarget, nManaCost, nCastRange, nSpeed)
if Loc ~= nil then
local eta = GetUnitToLocationDistance(npcBot, Loc) / nSpeed;
return BOT_ACTION_DESIRE_MODERATE, Loc, eta;
end
end
end
return BOT_ACTION_DESIRE_NONE, 0;
end
function ConsiderChakram2()
if ( not npcBot:HasScepter() or not abilityCH2:IsFullyCastable() )
then
return BOT_ACTION_DESIRE_NONE, 0;
end
local nRadius = abilityCH:GetSpecialValueFloat( "radius" );
local nSpeed = abilityCH:GetSpecialValueFloat( "speed" );
local nCastRange = abilityCH:GetCastRange();
local nManaCost = abilityCH:GetManaCost( );
local nDamage = 2*abilityCH:GetSpecialValueInt("pass_damage");
if mutil.IsRetreating(npcBot)
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE );
for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
do
if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 1.0 ) )
then
local loc = npcEnemy:GetLocation();
local eta = GetUnitToLocationDistance(npcBot, loc) / nSpeed;
return BOT_ACTION_DESIRE_MODERATE, loc, eta;
end
end
end
if mutil.IsDefending(npcBot) or mutil.IsPushing(npcBot)
then
local locationAoE = npcBot:FindAoELocation( true, false, npcBot:GetLocation(), nCastRange, nRadius, 0, 0 );
if ( locationAoE.count >= 3 and npcBot:GetMana() / npcBot:GetMaxMana() > 0.65 )
then
local loc = locationAoE.targetloc
local eta = GetUnitToLocationDistance(npcBot, loc) / nSpeed;
return BOT_ACTION_DESIRE_LOW, loc, eta;
end
end
if mutil.IsGoingOnSomeone(npcBot)
then
local npcTarget = npcBot:GetTarget();
if mutil.IsValidTarget(npcTarget) and mutil.CanCastOnNonMagicImmune(npcTarget) and mutil.IsInRange(npcTarget, npcBot, nCastRange-200)
then
local Loc = GetUltLoc(npcBot, npcTarget, nManaCost, nCastRange, nSpeed)
if Loc ~= nil then
local eta = GetUnitToLocationDistance(npcBot, Loc) / nSpeed;
return BOT_ACTION_DESIRE_MODERATE, Loc, eta;
end
end
end
return BOT_ACTION_DESIRE_NONE, 0;
end
function ConsiderChakramReturn()
if ( ultLoc == 0 or not abilityCHR:IsFullyCastable() or abilityCHR:IsHidden() ) then
return BOT_ACTION_DESIRE_NONE;
end
if DotaTime() < ultTime1 + ultETA1 or StillTraveling(1) then
return BOT_ACTION_DESIRE_NONE;
end
local nRadius = abilityCH:GetSpecialValueFloat( "radius" );
local nDamage = abilityCH:GetSpecialValueInt("pass_damage");
local nManaCost = abilityCH:GetManaCost( );
if npcBot:GetMana() < 100 or GetUnitToLocationDistance(npcBot, ultLoc) > 1600 then
return BOT_ACTION_DESIRE_HIGH;
end
if mutil.IsDefending(npcBot) or mutil.IsPushing(npcBot)
then
local nUnits = 0;
local nLowHPUnits = 0;
local NearbyUnits = npcBot:GetNearbyLaneCreeps(1300, true);
for _,c in pairs(NearbyUnits)
do
if GetUnitToLocationDistance(c, ultLoc) < nRadius then
nUnits = nUnits + 1;
end
if GetUnitToLocationDistance(c, ultLoc) < nRadius and c:GetHealth() <= nDamage then
nLowHPUnits = nLowHPUnits + 1;
end
end
if nUnits == 0 or nLowHPUnits >= 1 then
return BOT_ACTION_DESIRE_HIGH;
end
end
if npcBot:GetActiveMode() == BOT_MODE_RETREAT or mutil.IsGoingOnSomeone(npcBot)
then
local nUnits = 0;
local nLowHPUnits = 0;
local NearbyUnits = npcBot:GetNearbyHeroes(1000, true, BOT_MODE_NONE);
for _,c in pairs(NearbyUnits)
do
if GetUnitToLocationDistance(c, ultLoc) < nRadius then
nUnits = nUnits + 1;
end
if GetUnitToLocationDistance(c, ultLoc) < nRadius and c:GetHealth() <= nDamage / 2 then
nLowHPUnits = nLowHPUnits + 1;
end
end
if nUnits == 0 or nLowHPUnits >= 1 then
return BOT_ACTION_DESIRE_HIGH;
end
end
return BOT_ACTION_DESIRE_NONE;
end
function ConsiderChakramReturn2()
if ( not npcBot:HasScepter() or ultLoc2 == 0 or not abilityCHR2:IsFullyCastable() or abilityCHR2:IsHidden() ) then
return BOT_ACTION_DESIRE_NONE;
end
if DotaTime() < ultTime2 + ultETA2 or StillTraveling(2) then
return BOT_ACTION_DESIRE_NONE;
end
local nRadius = abilityCH:GetSpecialValueFloat( "radius" );
local nDamage = abilityCH:GetSpecialValueInt("pass_damage");
local nManaCost = abilityCH:GetManaCost( );
if npcBot:GetMana() < 100 or GetUnitToLocationDistance(npcBot, ultLoc2) > 1600 then
return BOT_ACTION_DESIRE_HIGH;
end
if mutil.IsDefending(npcBot) or mutil.IsPushing(npcBot)
then
local nUnits = 0;
local nLowHPUnits = 0;
local NearbyUnits = npcBot:GetNearbyLaneCreeps(1000, true);
for _,c in pairs(NearbyUnits)
do
if GetUnitToLocationDistance(c, ultLoc2) < nRadius then
nUnits = nUnits + 1;
end
if GetUnitToLocationDistance(c, ultLoc2) < nRadius and c:GetHealth() <= nDamage then
nLowHPUnits = nLowHPUnits + 1;
end
end
if nUnits == 0 or nLowHPUnits >= 1 then
return BOT_ACTION_DESIRE_HIGH;
end
end
if npcBot:GetActiveMode() == BOT_MODE_RETREAT or mutil.IsGoingOnSomeone(npcBot)
then
local nUnits = 0;
local nLowHPUnits = 0;
local NearbyUnits = npcBot:GetNearbyHeroes(1000, true, BOT_MODE_NONE);
for _,c in pairs(NearbyUnits)
do
if GetUnitToLocationDistance(c, ultLoc2) < nRadius then
nUnits = nUnits + 1;
end
if GetUnitToLocationDistance(c, ultLoc2) < nRadius and c:GetHealth() <= nDamage / 2 then
nLowHPUnits = nLowHPUnits + 1;
end
end
if nUnits == 0 or nLowHPUnits >= 1 then
return BOT_ACTION_DESIRE_HIGH;
end
end
return BOT_ACTION_DESIRE_NONE;
end