-
Notifications
You must be signed in to change notification settings - Fork 40
/
enemy_info.lua
193 lines (161 loc) · 6.9 KB
/
enemy_info.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
-------------------------------------------------------------------------------
--- AUTHOR: Nostrademous
--- GITHUB REPO: https://github.com/Nostrademous/Dota2-FullOverwrite
-------------------------------------------------------------------------------
local utils = require( GetScriptDirectory().."/utility" )
local EnemyInfo = {}
-- GLOBAL ENEMY INFORMATION ARRAY
local LastEnemyUpdate = -1000.0
local UpdateFreq1 = 0.25
local UpdateFreq2 = 1.00
function EnemyInfo.BuildEnemyList()
if GameTime() - LastEnemyUpdate > UpdateFreq1 then
local listEnemyIDs = GetTeamPlayers(utils.GetOtherTeam())
for slot_id, pid in ipairs(listEnemyIDs) do
-- initialize if we have not seen this enemy before
if EnemyInfo[pid] == nil then
EnemyInfo[pid] = {}
-- Let's try to figure out their role
EnemyInfo.InferRole(pid)
end
--------------------------------------------
-- update our understanding of this enemy --
--------------------------------------------
-- are they alive
EnemyInfo[pid].Alive = IsHeroAlive(pid)
-- can we see them now
local hEnemy = EnemyInfo.GetEnemyHeroFromId(pid)
if hEnemy then
-- yes we can see them (at least some of them if multiple)
if EnemyInfo[pid].multiple then
local hNearestCopy = nil
local nDist = 100000
for _, hEnemyCopy in pairs(hEnemy) do
-- TODO: Figure out
-- local dist = GetUnitToUnitDistance()
end
LastEnemyUpdate = GameTime()
return
end
if not hEnemy:IsNull() then
EnemyInfo[pid].Name = utils.GetHeroName(hEnemy)
EnemyInfo[pid].Level = hEnemy:GetLevel()
EnemyInfo[pid].Items = {}
EnemyInfo[pid].Location = hEnemy:GetLocation()
EnemyInfo[pid].LastSeen = GameTime()
EnemyInfo[pid].Lane = utils.NearestLane(hEnemy)
EnemyInfo[pid].ExtraLoc1 = hEnemy:GetExtrapolatedLocation(1.0)
EnemyInfo[pid].ExtraLoc3 = hEnemy:GetExtrapolatedLocation(3.0)
EnemyInfo[pid].ExtraLoc5 = hEnemy:GetExtrapolatedLocation(5.0)
if hEnemy:IsUnableToMiss() then
EnemyInfo[pid].HasTruestrike = true
EnemyInfo.HasTruestrike = true
else
EnemyInfo[pid].HasTruestrike = false
end
if GameTime() - LastEnemyUpdate > UpdateFreq2 then
for i = 0, 5, 1 do
local item = hEnemy:GetItemInSlot(i)
if item ~= nil then
local sItemName = item:GetName()
EnemyInfo[pid].Items[i] = sItemName
-- can we be detected if we go invis
-- TODO: account for abilities
if sItemName == "item_gem" or sItemName == "item_ward_dispenser" or
sItemName == "item_ward_sentry" or sItemName == "item_dust" or
sItemName == "item_necronomicon_3" then
EnemyInfo[pid].HasDetection = true
else
EnemyInfo[pid].HasDetection = false
end
-- can enemy go invis
-- TODO: account for abilities
if sItemName == "item_invis_sword" or sItemName == "item_silver_edge" or
sItemName == "item_glimmer_cape" or sItemName == "item_shadow_amulet" then
else
EnemyInfo[pid].CanGoInvis = false
end
end
end
end
end
else
-- we cannot see them at this time
local hTable = GetHeroLastSeenInfo(pid)
if #hTable > 0 then
EnemyInfo[pid].Location = hTable[1].location
EnemyInfo[pid].LastSeen = hTable[1].time_since_seen
if hTable[1].time_since_seen > 6.0 then
EnemyInfo[pid].Lane = -1
EnemyInfo[pid].ExtraLoc1 = nil
EnemyInfo[pid].ExtraLoc3 = nil
EnemyInfo[pid].ExtraLoc5 = nil
end
end
end
end
LastEnemyUpdate = GameTime()
end
end
function EnemyInfo.GetLocation( id )
-- check if we have seen the enemy at least once before
if EnemyInfo[id] and EnemyInfo[id].ExtraLoc1 == nil then
return nil
end
if EnemyInfo[id].multiple then
utils.myPrint("This enemy has multiple entities... fix")
end
local tDelta = GameTime() - EnemyInfo[id].LastSeen
if tDelta < 0.5 then
return EnemyInfo[id].Location
elseif tDelta <= 1.0 then
return EnemyInfo[id].ExtraLoc1
elseif tDelta <= 3.0 then
return EnemyInfo[id].ExtraLoc3
elseif tDelta <= 5.0 then
return EnemyInfo[id].ExtraLoc5
end
return nil
end
function EnemyInfo.InferRole( id )
local hEnemy = EnemyInfo.GetEnemyHeroFromId(id)
if hEnemy then
if EnemyInfo[id].multiple then
hEnemy = hEnemy[1]
end
if not hEnemy:IsNull() then
-- TODO: Implement
end
end
end
function EnemyInfo.PrintEnemyInfo()
local pids = GetTeamPlayers(utils.GetOtherTeam())
for _, pid in pairs(pids) do
if EnemyInfo[pid].Name then
print(EnemyInfo[pid].Name .. " (Lvl: " .. EnemyInfo[pid].Level .. ")")
print(" Lane: " .. EnemyInfo[pid].Lane)
end
end
end
function EnemyInfo.GetEnemyHeroFromId( id )
local enemyList = GetUnitList(UNIT_LIST_ENEMY_HEROES)
local list = {}
for _, enemy in pairs(enemyList) do
if not enemy:IsNull() and enemy:GetPlayerID() == id then
if not EnemyInfo[id].Alive then
enemy.Illusion = true
end
table.insert(list, enemy)
end
end
EnemyInfo[id].multiple = false
if #list > 0 then
if #list > 1 then
EnemyInfo[id].multiple = true
return list
end
return list[1]
end
return nil
end
return EnemyInfo