-
-
Notifications
You must be signed in to change notification settings - Fork 86
/
ability_item_usage_generic.lua
393 lines (365 loc) · 12.6 KB
/
ability_item_usage_generic.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
----------------------------------------------------------------------------
-- Ranked Matchmaking AI v1.3 New Structure
-- Author: adamqqq Email:[email protected]
----------------------------------------------------------------------------
local BotsInit = require("game/botsinit");
local MyModule = BotsInit.CreateGeneric();
local utility = require(GetScriptDirectory() .. "/utility")
local Courier = dofile(GetScriptDirectory() .. "/util/CourierSystem")
local ItemUsageSystem = dofile(GetScriptDirectory() .. "/util/ItemUsageSystem")
local ChatSystem = dofile(GetScriptDirectory() .. "/util/ChatSystem")
local AbilityExtensions = require(GetScriptDirectory() .. "/util/AbilityAbstraction")
local TeamItemThink = require(GetScriptDirectory() .. "/util/TeamItemThink")
local Buyback = require(GetScriptDirectory() .. "/util/lib/Buyback")
local towerId = {
TOWER_TOP_1,
TOWER_TOP_2,
TOWER_TOP_3,
TOWER_MID_1,
TOWER_MID_2,
TOWER_MID_3,
TOWER_BOT_1,
TOWER_BOT_2,
TOWER_BOT_3,
TOWER_BASE_1,
TOWER_BASE_2,
}
local RefreshBuildingHealth = AbilityExtensions:SingleForTeam(AbilityExtensions:EveryManySeconds(0.5, function()
for _, id in ipairs(towerId) do
local tower = GetTower(GetTeam(), id)
if tower ~= nil and tower:GetHealth() > 0 then
tower.health0SecondsAgo = tower:GetHealth()
if tower:IsAlive() then
for _, i in ipairs({ 0.5, 1, 1.5, 2 }) do
tower["health" .. tostring(i) .. "SecondsAgo"] = tower["health" .. tostring(i - 0.5) .. "SecondsAgo"]
end
end
end
end
end))
local function ConsiderGlyph()
RefreshBuildingHealth()
if GetGlyphCooldown() > 0 then
return false
end
for i, BuildingID in pairs(towerId) do
local tower = GetTower(GetTeam(), BuildingID)
if tower ~= nil and tower:GetHealth() > 0 then
local tableNearbyEnemyHeroes = utility.GetEnemiesNearLocation(tower:GetLocation(), 700)
if tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes >= 1 and tower["health1SecondsAgo"] and
tower:GetHealth() - tower["health1SecondsAgo"] >= 7.5 * DotaTime() / 60 and DotaTime() >= 12 * 60 then
GetBot():ActionImmediate_Glyph()
end
if tower:GetHealth() >= 200 and tower:GetHealth() <= 1000 and #tableNearbyEnemyHeroes >= 2 then
GetBot():ActionImmediate_Glyph()
break
end
end
end
end
local function RecordStuckState()
local npcBot = GetBot()
local botLoc = npcBot:GetLocation();
if npcBot:IsAlive() and npcBot:GetCurrentActionType() == BOT_ACTION_TYPE_MOVE_TO and not IsLocationPassable(botLoc) then
if npcBot.stuckLoc == nil then
npcBot.stuckLoc = botLoc
npcBot.stuckTime = DotaTime();
elseif npcBot.stuckLoc ~= botLoc then
npcBot.stuckLoc = botLoc
npcBot.stuckTime = DotaTime();
end
else
npcBot.stuckTime = nil;
npcBot.stuckLoc = nil;
end
end
local function AncientBelow(team, health)
local ancient = GetAncient(team)
return ancient:IsInvulnerable() and ancient:GetHealth() < health
end
local function SecondaryOperation()
ConsiderGlyph()
ItemUsageSystem.UnImplementedItemUsage()
TeamItemThink.Think()
RecordStuckState()
if (DotaTime() >= -60 and DotaTime() <= -59)
then
ChatSystem.SendVersionAnnouncement()
end
if AncientBelow(TEAM_RADIANT, 1500) or AncientBelow(TEAM_DIRE, 1500) then
AbilityExtensions:AnnounceGroups1(GetBot())
end
if AncientBelow(TEAM_RADIANT, 1200) or AncientBelow(TEAM_DIRE, 1200) then
AbilityExtensions:AnnounceGroups2(GetBot())
end
end
local fun2 = require(GetScriptDirectory() .. "/util/CommonBehaviours")
local A = require(GetScriptDirectory() .. "/util/MiraDota")
function CourierUsageThink()
if not GetBot():IsAlive() then
return
end
AbilityExtensions:TickFromDota()
A.Game.TickFromDota()
A.ItemUse.ItemUsageThink()
fun2.Think()
SecondaryOperation()
end
local ExecuteAbilityLevelUp = function(AbilityToLevelUp, TalentTree)
local GetAbilityLevelUpIndex = function(npcBot)
return npcBot:GetLevel() - npcBot:GetAbilityPoints() + 1 + AbilityToLevelUp.incorrectAbilityLevelUpNumber
end
local npcBot = GetBot()
local function GetNextTalent()
return AbilityExtensions:First(AbilityExtensions:GetTalents(npcBot), function(t)
return not t:IsTrained()
end)
end
if AbilityToLevelUp.justLevelUpAbility then
if AbilityToLevelUp.abilityPoints == npcBot:GetAbilityPoints() then
AbilityToLevelUp.incorrectAbilityLevelUpNumber = AbilityToLevelUp.incorrectAbilityLevelUpNumber + 1
end
AbilityToLevelUp.justLevelUpAbility = false
end
AbilityToLevelUp.abilityPoints = npcBot:GetAbilityPoints()
if npcBot:GetAbilityPoints() < 1 + AbilityToLevelUp.incorrectAbilityLevelUpNumber or
GetGameState() ~= GAME_STATE_PRE_GAME and GetGameState() ~= GAME_STATE_GAME_IN_PROGRESS then
return
end
local abilityName = AbilityToLevelUp[GetAbilityLevelUpIndex(npcBot)]
if abilityName == AbilityExtensions.IncorrectAbilityName or abilityName == AbilityExtensions.SpecialBonusAttributes then
AbilityToLevelUp.incorrectAbilityLevelUpNumber = AbilityToLevelUp.incorrectAbilityLevelUpNumber + 1
print(npcBot:GetUnitName() .. ": learn error ability: " .. tostring(abilityName))
else
if abilityName == "talent" then
AbilityToLevelUp.talentTreeIndex = AbilityToLevelUp.talentTreeIndex + 1
if type(TalentTree[AbilityToLevelUp.talentTreeIndex]) == "function" then
abilityName = TalentTree[AbilityToLevelUp.talentTreeIndex]()
else
abilityName = GetNextTalent():GetName()
end
end
npcBot:ActionImmediate_LevelAbility(abilityName)
AbilityToLevelUp.justLevelUpAbility = true
end
end
function AbilityLevelUpThink2(AbilityToLevelUp, TalentTree)
ExecuteAbilityLevelUp(AbilityToLevelUp, TalentTree)
return
end
function IsMeepoClone()
local npcBot = GetBot()
if npcBot:GetUnitName() == "npc_dota_hero_meepo" and npcBot:GetLevel() > 1
then
for i = 0, 5 do
local item = npcBot:GetItemInSlot(i);
if item ~= nil and not (string.find(item:GetName(), "boots") or string.find(item:GetName(), "treads"))
then
return false;
end
end
return true;
end
return false;
end
function BuybackUsageThink()
Buyback.BuybackUsageComplement()
end
function InitAbility(Abilities, AbilitiesReal, Talents)
local npcBot = GetBot()
for i = 0, 25, 1 do
local ability = npcBot:GetAbilityInSlot(i)
if (ability ~= nil) then
if (ability:GetName() ~= "generic_hidden") then
if (ability:IsTalent() == true) then
table.insert(Talents, ability:GetName())
else
table.insert(Abilities, ability:GetName())
table.insert(AbilitiesReal, ability)
end
end
end
end
npcBot.abilityInited = true -- set to true every time the scripts are reloaded
end
function GetComboMana(AbilitiesReal)
local npcBot = GetBot()
local tempComboMana = 0
for i, ability in pairs(AbilitiesReal) do
local success, message = pcall(function()
if ability and ability:GetLevel() >= 1 and not ability:IsPassive() and not ability:IsHidden() then
if ability:IsUltimate() == false or ability:GetCooldownTimeRemaining() <= 30 then
tempComboMana = tempComboMana + ability:GetManaCost()
end
end
end)
if not success then
-- abilites acquired by doom_bringer_devour
end
end
return math.max(tempComboMana, 300)
end
function GetComboDamage(AbilitiesReal)
local npcBot = GetBot()
local tempComboDamage = 0
for i, ability in pairs(AbilitiesReal) do
if ability:IsPassive() == false then
tempComboDamage = tempComboDamage + ability:GetAbilityDamage()
end
end
return math.max(tempComboDamage, GetBot():GetOffensivePower())
end
function PrintDebugInfo(AbilitiesReal, cast)
local npcBot = GetBot()
for i = 1, #AbilitiesReal do
if (cast.Desire[i] ~= nil and cast.Desire[i] > 0) then
local ability = AbilitiesReal[i]
if ((cast.Type[i] == nil or cast.Type[i] == "Target") and cast.Target[i] ~= nil and
utility.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_UNIT_TARGET))
then
if (cast.Target[i] ~= nil) then
utility.DebugTalk(
"try to use skill " .. i .. " at " .. cast.Target[i]:GetUnitName() .. " Desire= " .. cast.Desire[i]
)
else
utility.DebugTalk("try to use skill " .. i .. " Desire= " .. cast.Desire[i])
end
else
utility.DebugTalk("try to use skill " .. i .. " Desire= " .. cast.Desire[i])
end
end
end
end
function ConsiderAbility(AbilitiesReal, Consider)
local npcBot = GetBot()
local cast = {}
cast.Desire = {}
cast.Target = {}
cast.Type = {}
for i, ability in pairs(AbilitiesReal) do
if not ability:IsHidden() and ability:IsPassive() == false and Consider[i] ~= nil then
cast.Desire[i], cast.Target[i], cast.Type[i] = Consider[i]()
end
end
return cast
end
function ConsiderAbilityCoroutine(AbilitiesReal, Consider)
local npcBot = GetBot()
local cast = {}
cast.Desire = {}
cast.Target = {}
cast.Type = {}
for i, ability in pairs(AbilitiesReal) do
if Consider[i] ~= nil then
local consider1 = AbilityExtensions:ResumeUntilReturn(Consider[i])
consider1 = AbilityExtensions:Max(consider1, function(t) return t[1] end)
if consider1 then
cast.Desire[i], cast.Target[i], cast.Type[i] = AbilityExtensions:Unpack(consider1)
else
cast.Desire[i] = 0
end
end
end
return cast
end
local worldBounds = GetWorldBounds()
local function OutOfBound(vector)
return worldBounds[1] >= vector.x or worldBounds[2] >= vector.y or worldBounds[3] <= vector.x or
worldBounds[4] <= vector.y
end
function UseAbility(AbilitiesReal, cast)
local npcBot = GetBot()
local HighestDesire = 0
local HighestDesireAbility = 0
local HighestDesireAbilityNumber = 0
for i, ability in pairs(AbilitiesReal) do
if (cast.Desire[i] ~= nil and cast.Desire[i] > HighestDesire) then
HighestDesire = cast.Desire[i]
HighestDesireAbilityNumber = i
end
end
if (HighestDesire > 0) then
local j = HighestDesireAbilityNumber
local ability = AbilitiesReal[j]
local sToPrint = npcBot:GetUnitName() .. ": use " .. ability:GetName()
-- if ability:GetName() ~= "doom_bringer_infernal_blade" then
-- print(sToPrint)
-- end
if not ability:IsCooldownReady() then
print("Ability still in cooldown: " .. ability:GetName())
AbilityExtensions:DebugPause()
return
end
if npcBot:GetMana() < ability:GetManaCost() * 0.7 then --GetManaCost() doesn't count mana cost reduction
print("Ability mana not enough: " .. ability:GetName())
AbilityExtensions:DebugPause()
return
end
if ability:IsHidden() then
print("Ability is hidden: " .. ability:GetName())
AbilityExtensions:DebugPause()
return
end
-- if npcBot:IsRooted() then
-- print("use when rooted: "..ability:GetName())
-- end
local function CallWithTarget()
cast.Type[j] = "Target"
-- if cast.Target[j]:GetTeam() == npcBot:GetTeam() then
-- print(ability:GetName().." used at "..cast.Target[j]:GetUnitName())
-- end
-- if not AbilityExtensions:IsHero(cast.Target[j]) then
-- print("target at creep"..ability:GetName())
-- end
-- print("target ability :"..ability:GetName())
if AbilityExtensions:IsVector(cast.Target[j]) then
print("Wrong target type")
print(ability:GetName(), cast.Target[j], cast.Type[j])
AbilityExtensions:DebugPause()
return
else
npcBot:Action_UseAbilityOnEntity(ability, cast.Target[j])
end
end
local function CallWithLocation()
cast.Type[j] = "Location"
if not AbilityExtensions:IsVector(cast.Target[j]) then
print("Wrong target type")
print(ability:GetName(), cast.Target[j], cast.Type[j])
AbilityExtensions:DebugPause()
return
elseif OutOfBound(cast.Target[j]) then
print("Ability cast out of world bounds!")
print(ability:GetName(), cast.Target[j], cast.Type[j])
AbilityExtensions:DebugPause()
return
else
npcBot:Action_UseAbilityOnLocation(ability, cast.Target[j])
end
end
if (cast.Type[j] == nil) then
if (utility.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_NO_TARGET)) then
npcBot:Action_UseAbility(ability)
elseif (utility.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_POINT)) then
CallWithLocation()
elseif (utility.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_TREE)) then
cast.Type[j] = "Tree"
npcBot:Action_UseAbilityOnTree(ability, cast.Target[j])
else
CallWithTarget()
end
else
if cast.Type[j] == "Target" then
CallWithTarget()
elseif cast.Type[j] == "Location" then
CallWithLocation()
elseif cast.Type[j] == "Tree" then
npcBot:Action_UseAbilityOnTree(ability, cast.Target[j])
else
npcBot:Action_UseAbility(ability)
end
end
return j, cast.Target[j], cast.Type[j]
end
end
return MyModule;