forked from adamqqqplay/dota2ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathability_item_usage_generic.lua
321 lines (290 loc) · 9.03 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
----------------------------------------------------------------------------
-- Ranked Matchmaking AI v1.3 New Structure
-- Author: adamqqq Email:[email protected]
----------------------------------------------------------------------------
-------
_G._savedEnv = getfenv()
module("ability_item_usage_generic", package.seeall)
local utility = require(GetScriptDirectory() .. "/utility")
local Courier = dofile(GetScriptDirectory() .. "/util/CourierSystem")
local ItemUsageSystem = dofile(GetScriptDirectory() .. "/util/ItemUsageSystem")
local ChatSystem = dofile(GetScriptDirectory() .. "/util/ChatSystem")
local function ConsiderGlyph()
local Towers = {
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
}
if GetGlyphCooldown() > 0 then
return false
end
for i, BuildingID in pairs(Towers) do
local tower = GetTower(GetTeam(), BuildingID)
if tower ~= nil then
local tableNearbyEnemyHeroes = utility.GetEnemiesNearLocation(tower:GetLocation(), 700)
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 SecondaryOperation()
ConsiderGlyph()
ItemUsageSystem.UnImplementedItemUsage()
RecordStuckState()
if(DotaTime()>=-60 and DotaTime()<=-59)
then
ChatSystem.SendVersionAnnouncement()
end
end
function CourierUsageThink()
Courier.CourierUsageThink()
SecondaryOperation()
end
function AbilityLevelUpThink2(AbilityToLevelUp, TalentTree)
local npcBot = GetBot()
if
(npcBot:GetAbilityPoints() < 1 or #AbilityToLevelUp == 0 or
(GetGameState() ~= GAME_STATE_PRE_GAME and GetGameState() ~= GAME_STATE_GAME_IN_PROGRESS))
then
return
end
local abilityname = AbilityToLevelUp[1]
if abilityname == "nil" then
table.remove(AbilityToLevelUp, 1)
return
end
if abilityname == "talent" then
local level = npcBot:GetLevel()
for i, temp in pairs(AbilityToLevelUp) do
if temp == "talent" then
table.remove(AbilityToLevelUp, i)
table.insert(AbilityToLevelUp, i, TalentTree[1]())
table.remove(TalentTree, 1)
break
end
end
end
local ability = npcBot:GetAbilityByName(abilityname)
if ability ~= nil and ability:CanAbilityBeUpgraded() then
npcBot:ActionImmediate_LevelAbility(abilityname)
table.remove(AbilityToLevelUp, 1)
end
end
local function CanBuybackUpperRespawnTime(respawnTime)
local npcBot = GetBot()
if
(not npcBot:IsAlive() and respawnTime ~= nil and npcBot:GetRespawnTime() >= respawnTime and
npcBot:GetBuybackCooldown() == 0 and
npcBot:GetGold() > npcBot:GetBuybackCost())
then
return true
end
return false
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
--GXC BUYBACK LOGIC
function BuybackUsageThink()
local npcBot = GetBot()
if npcBot:IsInvulnerable() or not npcBot:IsHero() or not string.find(npcBot:GetUnitName(), "hero") or npcBot:IsIllusion() or IsMeepoClone() then
return
end
if not npcBot:HasBuyback() then
return;
end
-- no buyback, no need to use GetUnitList() for performance considerations
if (not CanBuybackUpperRespawnTime(20)) then
return
end
local tower_top_3 = GetTower(GetTeam(), TOWER_TOP_3)
local tower_mid_3 = GetTower(GetTeam(), TOWER_MID_3)
local tower_bot_3 = GetTower(GetTeam(), TOWER_BOT_3)
local tower_base_1 = GetTower(GetTeam(), TOWER_BASE_1)
local tower_base_2 = GetTower(GetTeam(), TOWER_BASE_2)
local barracks_top_melee = GetBarracks(GetTeam(), BARRACKS_TOP_MELEE)
local barracks_mid_melee = GetBarracks(GetTeam(), BARRACKS_MID_MELEE)
local barracks_bot_melee = GetBarracks(GetTeam(), BARRACKS_BOT_MELEE)
local ancient = GetAncient(GetTeam())
local buildList = {
tower_top_3,
tower_mid_3,
tower_bot_3,
tower_base_1,
tower_base_2,
barracks_top_melee,
barracks_mid_melee,
barracks_bot_melee,
ancient
}
for _, build in pairs(buildList) do
local tableNearbyEnemyHeroes = build:GetNearbyHeroes(1000, true, BOT_MODE_NONE)
if DotaTime() > 25 * 60 and CanBuybackUpperRespawnTime(20) then
if (tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes > 1) then
if (build:WasRecentlyDamagedByAnyHero(2.0) and CanBuybackUpperRespawnTime(20)) then
npcBot:ActionImmediate_Buyback()
return
end
end
end
end
if (DotaTime() > 35 * 60 and CanBuybackUpperRespawnTime(30)) then
npcBot:ActionImmediate_Buyback()
end
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
end
function GetComboMana(AbilitiesReal)
local npcBot = GetBot()
local tempComboMana = 0
for i, ability in pairs(AbilitiesReal) do
if ability:IsPassive() == false then
if ability:IsUltimate() == false or ability:GetCooldownTimeRemaining() <= 30 then
tempComboMana = tempComboMana + ability:GetManaCost()
end
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 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 UseAbility(AbilitiesReal, cast)
local npcBot = GetBot()
local HighestDesire = 0
local HighestDesireAbility = 0
local HighestDesireAbilityBumber = 0
for i, ability in pairs(AbilitiesReal) do
if (cast.Desire[i] ~= nil and cast.Desire[i] > HighestDesire) then
HighestDesire = cast.Desire[i]
HighestDesireAbilityBumber = i
end
end
if (HighestDesire > 0) then
local j = HighestDesireAbilityBumber
local ability = AbilitiesReal[j]
if (cast.Type[j] == nil) then
if (utility.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_NO_TARGET)) then
npcBot:Action_UseAbility(ability)
return
elseif (utility.CheckFlag(ability:GetBehavior(), ABILITY_BEHAVIOR_POINT)) then
npcBot:Action_UseAbilityOnLocation(ability, cast.Target[j])
return
elseif (utility.CheckFlag(ability:GetTargetType(), ABILITY_TARGET_TYPE_TREE)) then
npcBot:Action_UseAbilityOnTree(ability, cast.Target[j])
return
else
npcBot:Action_UseAbilityOnEntity(ability, cast.Target[j])
return
end
else
if (cast.Type[j] == "Target") then
npcBot:Action_UseAbilityOnEntity(ability, cast.Target[j])
return
elseif (cast.Type[j] == "Location") then
npcBot:Action_UseAbilityOnLocation(ability, cast.Target[j])
return
else
npcBot:Action_UseAbility(ability)
return
end
end
end
end
for k, v in pairs(ability_item_usage_generic) do
_G._savedEnv[k] = v
end