-
Notifications
You must be signed in to change notification settings - Fork 1
/
ability_item_usage_earth_spirit.lua
472 lines (418 loc) · 16.1 KB
/
ability_item_usage_earth_spirit.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
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 npcBot = GetBot();
local abilityQ = nil;
local abilityW = nil;
local abilityE = nil;
local abilityD = nil;
local abilityF = nil;
local abilityR = nil;
local gripAllies = nil;
local castQDesire = 0;
local castWDesire = 0;
local castEDesire = 0;
local castDDesire = 0;
local castFDesire = 0;
local castRDesire = 0;
local nStone = 0;
local remnantLoc = {};
local remnantCastTime = -100;
local remnantCastGap = 0.1;
local stoneCast = -100;
local stoneCastGap = 1.0;
function AbilityUsageThink()
nStone = npcBot:GetModifierStackCount(npcBot:GetModifierByName('modifier_earth_spirit_stone_caller_charge_counter'));
if npcBot:IsUsingAbility() or npcBot:IsChanneling() or npcBot:IsSilenced() or npcBot:NumQueuedActions() > 0 then return end
if abilityQ == nil then abilityQ = npcBot:GetAbilityByName( "earth_spirit_boulder_smash" ) end
if abilityW == nil then abilityW = npcBot:GetAbilityByName( "earth_spirit_rolling_boulder" ) end
if abilityE == nil then abilityE = npcBot:GetAbilityByName( "earth_spirit_geomagnetic_grip" ) end
if abilityD == nil then abilityD = npcBot:GetAbilityByName( "earth_spirit_stone_caller" ) end
if abilityF == nil then abilityF = npcBot:GetAbilityByName( "earth_spirit_petrify" ) end
if abilityR == nil then abilityR = npcBot:GetAbilityByName( "earth_spirit_magnetize" ) end
if gripAllies == nil then gripAllies = npcBot:GetAbilityByName( "special_bonus_unique_earth_spirit_2" ) end
castQDesire, castQLoc, castQStone, QStoneNear = ConsiderQ();
castWDesire, castWLoc, castWStone, WStoneNear = ConsiderW();
castEDesire, castELoc, castEStone, EStoneNear = ConsiderE();
castDDesire, castDLoc = ConsiderD();
castFDesire, castFTarget = ConsiderF();
castRDesire = ConsiderR();
if ( castRDesire > 0 )
then
npcBot:Action_UseAbility( abilityR );
return;
end
if ( castFDesire > 0 )
then
npcBot:ActionQueue_UseAbilityOnEntity(abilityF, castFTarget);
npcBot:ActionQueue_UseAbilityOnLocation(abilityQ, npcBot:GetLocation()+RandomVector(800));
return;
end
if ( castQDesire > 0 )
then
if castQStone then
npcBot:Action_ClearActions(false);
npcBot:ActionQueue_UseAbilityOnLocation(abilityD, npcBot:GetLocation());
npcBot:ActionQueue_UseAbilityOnLocation(abilityQ, castQLoc);
return;
else
if QStoneNear then
npcBot:Action_UseAbilityOnLocation( abilityQ, castQLoc );
return;
else
npcBot:Action_UseAbilityOnEntity( abilityQ, castQLoc );
return;
end
end
end
if ( castWDesire > 0 )
then
if castWStone then
npcBot:Action_ClearActions(false);
npcBot:ActionQueue_UseAbilityOnLocation(abilityW, castWLoc);
npcBot:ActionQueue_UseAbilityOnLocation(abilityD, npcBot:GetXUnitsTowardsLocation(castWLoc, 300));
return;
else
npcBot:Action_UseAbilityOnLocation( abilityW, castWLoc );
return;
end
end
if ( castEDesire > 0 )
then
if castEStone then
npcBot:Action_ClearActions(false);
npcBot:ActionQueue_UseAbilityOnLocation(abilityD, castELoc);
npcBot:ActionQueue_UseAbilityOnLocation(abilityE, castELoc);
return;
else
npcBot:Action_UseAbilityOnLocation( abilityE, castELoc );
return;
end
end
if ( castDDesire > 0 )
then
npcBot:Action_UseAbilityOnLocation( abilityD, castDLoc );
stoneCast = DotaTime();
return;
end
end
function IsStoneNearby(location, radius)
local units = GetUnitList(UNIT_LIST_ALLIED_OTHER);
for _,u in pairs(units) do
if u ~= nil and u:GetUnitName() == "npc_dota_earth_spirit_stone" and GetUnitToLocationDistance(u, location) < radius then
return true;
end
end
return false;
end
function IsStoneInPath(location, dist)
if npcBot:IsFacingLocation(location, 5) then
local units = GetUnitList(UNIT_LIST_ALLIED_OTHER);
for _,u in pairs(units) do
if u ~= nil and u:GetUnitName() == "npc_dota_earth_spirit_stone"
and npcBot:IsFacingLocation(u:GetLocation(), 5) and GetUnitToUnitDistance(u, npcBot) < dist
then
return true;
end
end
end
return false;
end
function CanChainMag(target, radius)
local enemies = target:GetNearbyHeroes(radius, false, BOT_MODE_NONE);
for _,enemy in pairs(enemies)
do
if not enemy:HasModifier('modifier_earth_spirit_magnetize') then
return true
end
end
return false;
end
function ConsiderQ()
if ( not abilityQ:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE, 0, false, false;
end
local nRadius = abilityQ:GetSpecialValueInt('radius');
local nSearchRad = abilityQ:GetSpecialValueInt('rock_search_aoe');
local nUnitCR = 150;
local nStoneCR = abilityQ:GetSpecialValueInt('rock_distance');
local nCastPoint = abilityQ:GetCastPoint( );
local nManaCost = abilityQ:GetManaCost( );
local nSpeed = abilityQ:GetSpecialValueInt('speed');
local nDamage = abilityQ:GetSpecialValueInt('rock_damage');
if nStoneCR > 1600 then nStoneCR = 1300 end
local stoneNearby = IsStoneNearby(npcBot:GetLocation(), nSearchRad);
if stoneNearby then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nStoneCR, true, BOT_MODE_NONE );
local target = mutil.GetCanBeKilledUnit(tableNearbyEnemyHeroes, nDamage, DAMAGE_TYPE_MAGICAL, false)
if target ~= nil then
local loc = mutil.GetCorrectLoc(target, GetUnitToUnitDistance(npcBot, target)/nSpeed)
return BOT_ACTION_DESIRE_HIGH, loc, false, true;
end
elseif nStone >= 1 then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nStoneCR, true, BOT_MODE_NONE );
local target = mutil.GetCanBeKilledUnit(tableNearbyEnemyHeroes, nDamage, DAMAGE_TYPE_MAGICAL, false)
if target ~= nil then
local loc = mutil.GetCorrectLoc(target, GetUnitToUnitDistance(npcBot, target)/nSpeed)
return BOT_ACTION_DESIRE_HIGH, loc, true, false;
end
elseif nStone < 1 then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nUnitCR+200, true, BOT_MODE_NONE );
local target = mutil.GetCanBeKilledUnit(tableNearbyEnemyHeroes, nDamage, DAMAGE_TYPE_MAGICAL, false)
if target ~= nil then
return BOT_ACTION_DESIRE_HIGH, target, false, false;
end
end
if mutil.IsRetreating(npcBot) and npcBot:WasRecentlyDamagedByAnyHero( 1.0 )
then
if stoneNearby then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nStone, true, BOT_MODE_NONE );
local target = mutil.GetClosestUnit(tableNearbyEnemyHeroes)
if target ~= nil then
return BOT_ACTION_DESIRE_HIGH, target:GetLocation(), false, true;
end
elseif nStone >= 1 then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nStone, true, BOT_MODE_NONE );
local target = mutil.GetClosestUnit(tableNearbyEnemyHeroes)
if target ~= nil then
return BOT_ACTION_DESIRE_HIGH, target:GetLocation(), true, false;
end
elseif nStone < 1 then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nUnitCR+200, true, BOT_MODE_NONE );
local target = mutil.GetClosestUnit(tableNearbyEnemyHeroes)
if target ~= nil then
return BOT_ACTION_DESIRE_HIGH, target, false, false;
end
end
end
if mutil.IsInTeamFight(npcBot, 1200)
then
local locationAoE = npcBot:FindAoELocation( true, true, npcBot:GetLocation(), nStoneCR, nRadius, nCastPoint, 0 );
if ( locationAoE.count >= 2 )
then
if stoneNearby then
return BOT_ACTION_DESIRE_LOW, locationAoE.targetloc, false, true;
elseif nStone >= 1 then
return BOT_ACTION_DESIRE_LOW, locationAoE.targetloc, true, false;
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, nStoneCR + 200)
then
local loc = mutil.GetCorrectLoc(npcTarget, GetUnitToUnitDistance(npcBot, target)/nSpeed)
if stoneNearby then
return BOT_ACTION_DESIRE_HIGH, loc, false, true;
elseif nStone >= 1 then
return BOT_ACTION_DESIRE_HIGH, loc, true, false;
end
end
end
return BOT_ACTION_DESIRE_NONE, 0, false, false;
end
function ConsiderW()
if ( not abilityW:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE, 0, false;
end
local nRadius = abilityW:GetSpecialValueInt('radius');
local nUnitCR = abilityW:GetSpecialValueInt('distance');
local nStoneCR = abilityW:GetSpecialValueInt('rock_distance');
local nCastPoint = abilityW:GetCastPoint( );
local nDelay = abilityW:GetSpecialValueFloat('delay');
local nManaCost = abilityW:GetManaCost( );
local nSpeed = abilityW:GetSpecialValueInt('speed');
local nRSpeed = abilityW:GetSpecialValueInt('rock_speed');
local nDamage = abilityW:GetSpecialValueInt('damage');
if nStoneCR > 1600 then nStoneCR = 1300 end
if nStone >= 1 then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nStoneCR, true, BOT_MODE_NONE );
local target = mutil.GetCanBeKilledUnit(tableNearbyEnemyHeroes, nDamage, DAMAGE_TYPE_MAGICAL, false)
if target ~= nil then
local loc = mutil.GetCorrectLoc(target, (GetUnitToUnitDistance(npcBot, target)/nRSpeed)+nDelay)
if IsStoneInPath(loc, (nUnitCR/2)+200) then
return BOT_ACTION_DESIRE_HIGH, loc, false;
else
return BOT_ACTION_DESIRE_HIGH, loc, true;
end
end
elseif nStone < 1 then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nUnitCR-200, true, BOT_MODE_NONE );
local target = mutil.GetCanBeKilledUnit(tableNearbyEnemyHeroes, nDamage, DAMAGE_TYPE_MAGICAL, false)
if target ~= nil then
return BOT_ACTION_DESIRE_HIGH, target, false;
end
end
if mutil.IsRetreating(npcBot) and npcBot:WasRecentlyDamagedByAnyHero( 1.0 )
then
local loc = utils.GetTowardsFountainLocation(npcBot:GetLocation(), nUnitCR);
if IsStoneInPath(loc, (nUnitCR/2)+200) then
return BOT_ACTION_DESIRE_MODERATE, loc, false;
elseif nStone >= 1 then
return BOT_ACTION_DESIRE_MODERATE, loc, true;
elseif nStone < 1 then
return BOT_ACTION_DESIRE_MODERATE, loc, false;
end
end
if mutil.IsGoingOnSomeone(npcBot)
then
local npcTarget = npcBot:GetTarget();
if nStone >= 1 and mutil.IsValidTarget(npcTarget) and mutil.CanCastOnNonMagicImmune(npcTarget) and mutil.IsInRange(npcTarget, npcBot, nStoneCR + 200)
then
local targetAlly = npcTarget:GetNearbyHeroes(1000, false, BOT_MODE_NONE);
local targetEnemy = npcTarget:GetNearbyHeroes(1000, true, BOT_MODE_NONE);
if targetEnemy ~= nil and targetAlly ~= nil and #targetEnemy >= #targetAlly then
local loc = mutil.GetCorrectLoc(npcTarget, GetUnitToUnitDistance(npcBot, target)/nRSpeed)
if IsStoneInPath(loc, (nUnitCR/2)+200) then
return BOT_ACTION_DESIRE_HIGH, loc, false;
else
return BOT_ACTION_DESIRE_HIGH, loc, true;
end
end
elseif nStone < 1 and mutil.IsValidTarget(npcTarget) and mutil.CanCastOnNonMagicImmune(npcTarget) and mutil.IsInRange(npcTarget, npcBot, nUnitCR / 2) then
local loc = mutil.GetCorrectLoc(npcTarget, GetUnitToUnitDistance(npcBot, target)/nSpeed)
return BOT_ACTION_DESIRE_HIGH, loc, false;
end
end
return BOT_ACTION_DESIRE_NONE, 0, false;
end
function ConsiderE()
if ( not abilityE:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE, 0, false, false;
end
local nRadius = abilityE:GetSpecialValueInt('radius');
local nSearchRad = 175;
local nCastRange = abilityE:GetCastRange();
local nCastPoint = abilityE:GetCastPoint( );
local nManaCost = abilityE:GetManaCost( );
local nDamage = abilityE:GetSpecialValueInt('rock_damage');
if gripAllies ~= nil and gripAllies:IsTrained() then
local tableNearbyAllies = npcBot:GetNearbyHeroes( nCastRange+200, false, BOT_MODE_NONE );
for _,ally in pairs(tableNearbyAllies)
do
if ally:GetActiveMode() == BOT_MODE_RETREAT and ally:WasRecentlyDamagedByAnyHero(2.0) then
return BOT_ACTION_DESIRE_HIGH, ally:GetLocation(), false, true;
end
end
end
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nCastRange, true, BOT_MODE_NONE );
local target = mutil.GetCanBeKilledUnit(tableNearbyEnemyHeroes, nDamage, DAMAGE_TYPE_MAGICAL, false)
if target ~= nil then
local loc = mutil.GetCorrectLoc(target, 2*nCastPoint)
local stoneNearby = IsStoneNearby(loc, nSearchRad);
if stoneNearby and ( nStone >= 1 or nStone < 1 ) then
return BOT_ACTION_DESIRE_HIGH, loc, false, true;
elseif nStone >= 1 then
return BOT_ACTION_DESIRE_HIGH, loc, true, false;
end
end
if mutil.IsInTeamFight(npcBot, 1200)
then
local locationAoE = npcBot:FindAoELocation( true, true, npcBot:GetLocation(), nCastRange, nRadius, nCastPoint, 0 );
if ( locationAoE.count >= 2 )
then
local stoneNearby = IsStoneNearby(locationAoE.targetloc, nSearchRad);
if stoneNearby and ( nStone >= 1 or nStone < 1 ) then
return BOT_ACTION_DESIRE_HIGH, locationAoE.targetloc, false, true;
elseif nStone >= 1 then
return BOT_ACTION_DESIRE_HIGH, locationAoE.targetloc, true, false;
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 - 200)
then
local targetAlly = npcTarget:GetNearbyHeroes(1000, false, BOT_MODE_NONE);
local targetEnemy = npcTarget:GetNearbyHeroes(1000, true, BOT_MODE_NONE);
if targetEnemy ~= nil and targetAlly ~= nil and #targetEnemy >= #targetAlly then
local loc = mutil.GetCorrectLoc(npcTarget, 2*nCastPoint)
local stoneNearby = IsStoneNearby(loc, nSearchRad);
if stoneNearby and ( nStone >= 1 or nStone < 1 ) then
return BOT_ACTION_DESIRE_HIGH, loc, false, true;
elseif nStone >= 1 then
return BOT_ACTION_DESIRE_HIGH, loc, true, false;
end
end
end
end
return BOT_ACTION_DESIRE_NONE, 0, false, false;
end
function ConsiderD()
if ( not abilityD:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE, 0;
end
if DotaTime() < stoneCast + stoneCastGap then
return BOT_ACTION_DESIRE_NONE, 0;
end
local nCastRange = abilityD:GetCastRange( );
local nRadius = abilityR:GetSpecialValueInt('rock_search_radius');
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nCastRange - 200, true, BOT_MODE_NONE );
for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
do
if npcEnemy:HasModifier('modifier_earth_spirit_magnetize')
then
local duration = npcEnemy:GetModifierRemainingDuration(npcEnemy:GetModifierByName('modifier_earth_spirit_magnetize'));
if duration < 1.0 or CanChainMag(npcEnemy, nRadius) then
return BOT_ACTION_DESIRE_MODERATE, npcEnemy:GetLocation();
end
end
end
return BOT_ACTION_DESIRE_NONE, 0;
end
function ConsiderF()
if ( not abilityF:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE, 0;
end
return BOT_ACTION_DESIRE_NONE, 0;
end
function ConsiderR()
if ( not abilityR:IsFullyCastable() ) then
return BOT_ACTION_DESIRE_NONE;
end
local nRadius = abilityR:GetSpecialValueInt( "cast_radius" );
local nCastPoint = abilityR:GetCastPoint( );
local nManaCost = abilityR:GetManaCost( );
if mutil.IsRetreating(npcBot) and npcBot:IsMagicImmune()
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_HIGH;
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-100)
then
return BOT_ACTION_DESIRE_MODERATE;
end
end
return BOT_ACTION_DESIRE_NONE;
end