forked from PCMRShutnik/Rage-Trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Skillslogic.lua
458 lines (419 loc) · 15 KB
/
Skillslogic.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
local X = {}
local logic = require(GetScriptDirectory() .. "/util")
local castEntityTarget = 0;
local castPointTarget = 0;
local castAoeTarget = 0;
local castNoTarget = 0;
local castTreeTarget = 0;
local RB = Vector(-7200,-6666)
local DB = Vector(7137,6548)
local BlinkLikeAbility = {
'antimage_blink',
'faceless_void_time_walk',
'magnataur_skewer',
'queenofpain_blink',
'storm_spirit_ball_lightning',
'techies_suicide',
'wisp_relocate',
'sandking_burrowstrike',
'abyssal_underlord_dark_rift'
}
local ClearPathAbilities = {
'pudge_meat_hook',
'rattletrap_hookshot',
'mirana_arrow'
}
function X.CastStolenSpells(ability)
local bot = GetBot()
if not string.find(ability:GetName(), "empty") and not X.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_PASSIVE) then
if X.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_UNIT_TARGET) then
castEntityTarget, castTarget, UnitType = X.ConsiderEntityTarget(ability);
if castEntityTarget > 0 then
if UnitType == "unit" then
bot:Action_UseAbilityOnEntity( ability, castTarget );
return;
elseif UnitType == "tree" then
bot:Action_UseAbilityOnTree( ability, castTarget );
return;
end
end
elseif X.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_POINT) then
castPointTarget, castPoint = X.ConsiderPointTarget(ability);
if castPointTarget > 0 then
bot:Action_UseAbilityOnLocation( ability, castPoint );
return;
end
elseif X.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_NO_TARGET) then
castNoTarget = X.ConsiderNoTarget(ability);
if castNoTarget > 0 then
bot:Action_UseAbility( ability );
return;
end
end
end
end
function X.CanCastOnNonMagicImmune( npcTarget )
return npcTarget:CanBeSeen() and not npcTarget:IsMagicImmune() and not npcTarget:IsInvulnerable();
end
function X.CanCastOnMagicImmune( npcTarget )
return npcTarget:CanBeSeen() and not npcTarget:IsInvulnerable();
end
function X.CheckFlag(bitfield, flag)
return ((bitfield/flag) % 2) >= 1
end
function X.IsEngagingTarget(npcBot)
local mode = npcBot:GetActiveMode();
return mode == BOT_MODE_ROAM or
mode == BOT_MODE_TEAM_ROAM or
mode == BOT_MODE_GANK or
mode == BOT_MODE_ATTACK or
mode == BOT_MODE_DEFEND_ALLY
end
function X.IsRetreating(npcBot)
return npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH;
end
function X.CanBeUseToChaseOrEscape(ability_name)
for _,a in pairs(BlinkLikeAbility)
do
if ability_name == a then
return true;
end
end
return false;
end
function X.AbilityNeedPathToBeClear(ability_name)
for _,a in pairs(ClearPathAbilities)
do
if ability_name == a then
return true
end
end
return false;
end
function X.ConsiderEntityTarget(ability)
local npcBot = GetBot();
if not ability:IsFullyCastable() or ability:IsHidden() then
return BOT_ACTION_DESIRE_NONE, nil;
end
local nCastRange = ability:GetCastRange();
local nAttackRange = npcBot:GetAttackRange();
if nCastRange < nAttackRange then
nCastRange = nCastRange + 200;
end
if ability:GetName() == "tiny_toss" then
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nCastRange )
then
local tableNearbyAllyHeroes = npcBot:GetNearbyHeroes( 275, false, BOT_MODE_NONE );
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 275, true, BOT_MODE_NONE );
local tableNearbyEnemyCreeps = npcBot:GetNearbyLaneCreeps( 275, true );
local tableNearbyAllyCreeps = npcBot:GetNearbyLaneCreeps( 275, false );
if tableNearbyAllyHeroes ~= nil or tableNearbyEnemyHeroes ~= nil or tableNearbyAllyCreeps ~= nil or tableNearbyEnemyCreeps ~= nil
then
return BOT_ACTION_DESIRE_MODERATE, npcTarget, 'unit';
end
end
end
end
if X.CheckFlag(ability:GetTargetTeam(), ABILITY_TARGET_TEAM_ENEMY) and
X.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_HERO) and
X.CheckFlag(ability:GetTargetFlags(), ABILITY_TARGET_FLAG_MAGIC_IMMUNE_ENEMIES)
then
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nCastRange )
then
return BOT_ACTION_DESIRE_MODERATE, npcTarget, 'unit';
end
end
elseif X.CheckFlag(ability:GetTargetTeam(), ABILITY_TARGET_TEAM_ENEMY) and
X.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_HERO) and
not X.CheckFlag(ability:GetTargetFlags(), ABILITY_TARGET_FLAG_MAGIC_IMMUNE_ENEMIES)
then
if X.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
return BOT_ACTION_DESIRE_MODERATE, npcEnemy, 'unit';
end
end
end
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nCastRange )
then
return BOT_ACTION_DESIRE_MODERATE, npcTarget, 'unit';
end
end
elseif X.CheckFlag(ability:GetTargetTeam(), ABILITY_TARGET_TEAM_FRIENDLY) and
X.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_HERO)
then
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
if ( #tableNearbyAttackingAlliedHeroes >= 2 )
then
local tableNearbyAllies = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_NONE );
for _,h in pairs(tableNearbyAllies)
do
if ( h:GetUnitName() ~= npcBot:GetUnitName() and h:GetActiveMode() == BOT_MODE_RETREAT and h:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH ) or h:GetActiveMode() == BOT_MODE_ATTACK then
return BOT_ACTION_DESIRE_MODERATE, h, 'unit';
end
end
end
if X.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
return BOT_ACTION_DESIRE_MODERATE, npcBot, 'unit';
end
end
end
elseif X.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_CREEP) then
local tableNearbyEnemyCreeps = npcBot:GetNearbyLaneCreeps( nCastRange, true );
for _,npcCreepTarget in pairs(tableNearbyEnemyCreeps)
do
if ( GetUnitToUnitDistance( npcCreepTarget, npcBot ) < nCastRange )
then
return BOT_ACTION_DESIRE_MODERATE, npcCreepTarget;
end
end
elseif X.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_TREE) then
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nCastRange )
then
local tableNearbyTrees = npcBot:GetNearbyTrees( nCastRange );
if tableNearbyTrees ~= nil and #tableNearbyTrees > 0 then
return BOT_ACTION_DESIRE_MODERATE, tableNearbyTrees[1], 'tree';
end
end
end
end
return BOT_ACTION_DESIRE_NONE, nil;
end
function X.ConsiderPointTarget(ability)
local npcBot = GetBot();
if not ability:IsFullyCastable() or ability:IsHidden() then
return BOT_ACTION_DESIRE_NONE, {};
end
local nCastRange = ability:GetCastRange();
local nCastPoint = ability:GetCastPoint();
local nAttackRange = npcBot:GetAttackRange();
if nCastRange < nAttackRange then
nCastRange = nCastRange + 200;
end
if X.AbilityNeedPathToBeClear(ability:GetName()) then
local an = ability:GetName();
if an == 'pudge_meat_hook' or an == 'rattletrap_hookshot' then
local nRadius = 0;
local speed = 0;
if an == "pudge_meat_hook" then
nRadius = ability:GetSpecialValueInt("hook_width");
speed = ability:GetSpecialValueInt("hook_speed");
elseif an == "rattletrap_hookshot" then
nRadius = ability:GetSpecialValueInt("latch_radius");
speed = ability:GetSpecialValueInt("speed");
end
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and GetUnitToUnitDistance(npcTarget, npcBot) < nCastRange )
then
local distance = GetUnitToUnitDistance(npcTarget, npcBot)
local pLoc = npcTarget:GetExtrapolatedLocation( nCastPoint + ( distance / speed ) );
if not logic.AreCreepsBetweenMeAndLoc(pLoc, nRadius) then
return BOT_ACTION_DESIRE_MODERATE, pLoc;
end
end
end
elseif an == 'mirana_arrow' then
local nRadius = ability:GetSpecialValueInt( "arrow_width" );
local speed = ability:GetSpecialValueInt( "arrow_speed" );
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and GetUnitToUnitDistance(npcTarget, npcBot) < nCastRange )
then
local distance = GetUnitToUnitDistance(npcTarget, npcBot)
local pLoc = npcTarget:GetExtrapolatedLocation( nCastPoint + ( distance / speed ) );
if not logic.AreEnemyCreepsBetweenMeAndLoc(pLoc, nRadius) then
return BOT_ACTION_DESIRE_MODERATE, pLoc;
end
end
end
end
return BOT_ACTION_DESIRE_NONE, {};
end
if X.CanBeUseToChaseOrEscape(ability:GetName()) then
if X.IsRetreating(npcBot)
then
if GetTeam( ) == TEAM_DIRE then
return BOT_ACTION_DESIRE_MODERATE, DB;
elseif GetTeam( ) == TEAM_RADIANT then
return BOT_ACTION_DESIRE_MODERATE, RB;
end
end
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and
GetUnitToUnitDistance( npcTarget, npcBot ) > nAttackRange - 100 and GetUnitToUnitDistance( npcTarget, npcBot ) < 1200
)
then
local tableNearbyEnemyHeroes = npcTarget:GetNearbyHeroes( 1000, false, BOT_MODE_NONE );
if tableNearbyEnemyHeroes == nil or ( tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes <= 2 ) then
return BOT_ACTION_DESIRE_MODERATE, npcTarget:GetLocation();
end
end
end
else
if X.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_TREE) then
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nCastRange )
then
local nearbyTrees = npcBot:GetNearbyTrees(nCastRange)
if nearbyTrees[1] ~= nil then
return BOT_ACTION_DESIRE_MODERATE, GetTreeLocation(nearbyTrees[1])
end
end
end
else
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nCastRange )
then
return BOT_ACTION_DESIRE_MODERATE, npcTarget:GetLocation();
end
end
end
end
return BOT_ACTION_DESIRE_NONE, {};
end
function X.ConsiderNoTarget(ability)
local npcBot = GetBot();
if not ability:IsFullyCastable() or ability:IsHidden() then
return BOT_ACTION_DESIRE_NONE;
end
local nRadius = ability:GetAOERadius();
local nAttackRange = npcBot:GetAttackRange();
if nRadius == nil or nRadius == 0 then
nRadius = nAttackRange + 200;
end
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nRadius, true, BOT_MODE_NONE );
if X.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_TOGGLE) then
if ability:GetName() == "pudge_rot" then
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and
GetUnitToUnitDistance( npcTarget, npcBot ) < nRadius and not ability:GetToggleState() )
then
return BOT_ACTION_DESIRE_MODERATE;
else
if ability:GetToggleState() then
return BOT_ACTION_DESIRE_MODERATE;
end
end
else
if ability:GetToggleState() then
return BOT_ACTION_DESIRE_MODERATE;
end
end
elseif ability:GetName() == "witch_doctor_voodoo_restoration" then
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
if ( #tableNearbyAttackingAlliedHeroes >= 2 )
then
local tableNearbyAllies = npcBot:GetNearbyHeroes( 500, false, BOT_MODE_NONE );
if (tableNearbyAllies ~= nil and #tableNearbyAllies >= 1 and not ability:GetToggleState()) then
return BOT_ACTION_DESIRE_MODERATE;
else
if ability:GetToggleState() then
return BOT_ACTION_DESIRE_MODERATE;
end
end
end
if X.IsRetreating(npcBot)
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE );
if ( tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes >= 1 and not ability:GetToggleState() )
then
return BOT_ACTION_DESIRE_MODERATE;
else
if ability:GetToggleState() then
return BOT_ACTION_DESIRE_MODERATE;
end
end
end
elseif ability:GetName() == "leshrac_pulse_nova" then
if X.IsEngagingTarget(npcBot) and not npcBot:HasModifier("modifier_leshrac_pulse_nova")
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and
GetUnitToUnitDistance( npcTarget, npcBot ) < nRadius and not ability:GetToggleState() )
then
return BOT_ACTION_DESIRE_MODERATE;
else
if npcBot:HasModifier("modifier_leshrac_pulse_nova") then
return BOT_ACTION_DESIRE_MODERATE;
end
end
else
if npcBot:HasModifier("modifier_leshrac_pulse_nova") then
return BOT_ACTION_DESIRE_MODERATE;
end
end
elseif ability:GetName() == "morphling_morph_agi" then
return BOT_ACTION_DESIRE_NONE;
elseif ability:GetName() == "morphling_morph_str" then
if npcBot:GetMana() / npcBot:GetMaxMana() > 0.35 and not ability:GetToggleState() then
return BOT_ACTION_DESIRE_MODERATE;
elseif npcBot:GetMana() / npcBot:GetMaxMana() < 0.35 and ability:GetToggleState() then
return BOT_ACTION_DESIRE_MODERATE;
end
end
return BOT_ACTION_DESIRE_NONE;
else
if X.IsRetreating(npcBot)
then
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( nRadius, true, BOT_MODE_NONE );
for _,npcEnemy in pairs( tableNearbyEnemyHeroes )
do
if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 1.0 ) )
then
return BOT_ACTION_DESIRE_MODERATE;
end
end
end
if X.IsEngagingTarget(npcBot)
then
local npcTarget = npcBot:GetTarget();
if ( npcTarget ~= nil and npcTarget:IsHero() and X.CanCastOnNonMagicImmune(npcTarget) and GetUnitToUnitDistance( npcTarget, npcBot ) < nRadius )
then
return BOT_ACTION_DESIRE_MODERATE;
end
end
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
if ( #tableNearbyAttackingAlliedHeroes >= 2 )
then
local tableNearbyEnemies = npcBot:GetNearbyHeroes( nRadius, true, BOT_MODE_NONE );
if tableNearbyEnemies ~= nil and #tableNearbyEnemies >= 1 then
return BOT_ACTION_DESIRE_MODERATE;
end
end
end
return BOT_ACTION_DESIRE_NONE;
end
return X