forked from PCMRShutnik/Rage-Trigger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMylogic.lua
208 lines (208 loc) · 6.57 KB
/
Mylogic.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
local U = {};
local RB = Vector(-7200,-6666)
local DB = Vector(7137,6548)
local fSpamThreshold = 0.55;
local modifier = {
"modifier_winter_wyvern_winters_curse",
"modifier_modifier_dazzle_shallow_grave",
"modifier_modifier_oracle_false_promise",
"modifier_oracle_fates_edict"
}
function U.IsRetreating(npcBot)
return npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH;
end
function U.IsValidTarget(npcTarget)
return npcTarget ~= nil and npcTarget:IsAlive() and not npcTarget:IsIllusion() and npcTarget:IsHero();
end
function U.CanCastOnMagicImmune(npcTarget)
return npcTarget:CanBeSeen() and not npcTarget:IsInvulnerable();
end
function U.CanCastOnNonMagicImmune(npcTarget)
return npcTarget:CanBeSeen() and not npcTarget:IsMagicImmune() and not npcTarget:IsInvulnerable();
end
function U.CanCastOnTargetAdvanced( npcTarget )
return npcTarget:CanBeSeen() and not npcTarget:IsMagicImmune() and not npcTarget:IsInvulnerable() and not U.HasForbiddenModifier(npcTarget)
end
function U.CanKillTarget(npcTarget, dmg, dmgType)
return npcTarget:GetActualIncomingDamage( dmg, dmgType ) >= npcTarget:GetHealth();
end
function U.HasForbiddenModifier(npcTarget)
for _,mod in pairs(modifier)
do
if npcTarget:HasModifier(mod) then
return true
end
end
return false;
end
function U.ShouldEscape(npcBot)
local tableNearbyEnemyHeroes = npcBot:GetNearbyHeroes( 1000, true, BOT_MODE_NONE );
if ( npcBot:WasRecentlyDamagedByAnyHero(2.0) or npcBot:WasRecentlyDamagedByTower(2.0) or ( tableNearbyEnemyHeroes ~= nil and #tableNearbyEnemyHeroes > 1 ) )
then
return true;
end
end
function U.IsRoshan(npcTarget)
return npcTarget ~= nil and npcTarget:IsAlive() and string.find(npcTarget:GetUnitName(), "roshan");
end
function U.IsDisabled(enemy, npcTarget)
if enemy
then
return npcTarget:IsRooted( ) or npcTarget:IsStunned( ) or npcTarget:IsHexed( ) or npcTarget:IsNightmared();
else
return npcTarget:IsRooted( ) or npcTarget:IsStunned( ) or npcTarget:IsHexed( ) or npcTarget:IsNightmared() or npcTarget:IsSilenced( );
end
end
function U.IsInRange(npcTarget, npcBot, nCastRange)
return GetUnitToUnitDistance( npcTarget, npcBot ) <= nCastRange;
end
function U.IsInTeamFight(npcBot, range)
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( range, false, BOT_MODE_ATTACK );
return tableNearbyAttackingAlliedHeroes ~= nil and #tableNearbyAttackingAlliedHeroes >= 2;
end
function U.CanNotUseAbility(npcBot)
return npcBot:IsUsingAbility() or npcBot:IsInvulnerable() or npcBot:IsChanneling() or npcBot:IsSilenced();
end
function U.IsGoingOnSomeone(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 U.IsDefending(npcBot)
local mode = npcBot:GetActiveMode();
return mode == BOT_MODE_DEFEND_TOWER_TOP or
mode == BOT_MODE_DEFEND_TOWER_MID or
mode == BOT_MODE_DEFEND_TOWER_BOT
end
function U.IsPushing(npcBot)
local mode = npcBot:GetActiveMode();
return mode == BOT_MODE_PUSH_TOWER_TOP or
mode == BOT_MODE_PUSH_TOWER_MID or
mode == BOT_MODE_PUSH_TOWER_BOT
end
function U.GetTeamFountain()
local Team = GetTeam();
if Team == TEAM_DIRE then
return DB;
else
return RB;
end
end
function U.GetComboItem(npcBot, item_name)
local Slot = npcBot:FindItemSlot(item_name);
if Slot >= 0 and Slot <= 5 then
return npcBot:GetItemInSlot(Slot);
else
return nil;
end
end
function U.GetMostHpUnit(ListUnit)
local mostHpUnit = nil;
local maxHP = 0;
for _,unit in pairs(ListUnit)
do
local uHp = unit:GetHealth();
if uHp > maxHP then
mostHpUnit = unit;
maxHP = uHp;
end
end
return mostHpUnit
end
function U.StillHasModifier(npcTarget, modifier)
return npcTarget:HasModifier(modifier);
end
function U.AllowedToSpam(npcBot, nManaCost)
return ( npcBot:GetMana() - nManaCost ) / npcBot:GetMaxMana() >= fSpamThreshold;
end
function U.IsProjectileIncoming(npcBot, range)
local incProj = npcBot:GetIncomingTrackingProjectiles()
for _,p in pairs(incProj)
do
if GetUnitToLocationDistance(npcBot, p.location) < range and not p.is_attack and p.is_dodgeable then
return true;
end
end
return false;
end
function U.GetMostHPPercent(listUnits, magicImmune)
local mostPHP = 0;
local mostPHPUnit = nil;
for _,unit in pairs(listUnits)
do
local uPHP = unit:GetHealth() / unit:GetMaxHealth()
if ( ( magicImmune and U.CanCastOnMagicImmune(unit) ) or ( not magicImmune and U.CanCastOnNonMagicImmune(unit) ) )
and uPHP > mostPHP
then
mostPHPUnit = unit;
mostPHP = uPHP;
end
end
return mostPHPUnit;
end
function U.GetCanBeKilledUnit(units, nDamage, nDmgType, magicImmune)
local target = nil;
for _,unit in pairs(units)
do
if ( ( magicImmune and U.CanCastOnMagicImmune(unit) ) or ( not magicImmune and U.CanCastOnNonMagicImmune(unit) ) )
and U.CanKillTarget(unit, nDamage, nDmgType)
then
unitKO = target;
end
end
return target;
end
function U.GetCorrectLoc(target, delay)
if target:GetMovementDirectionStability() < 1.0 then
return target:GetLocation();
else
return target:GetExtrapolatedLocation(delay);
end
end
function U.GetClosestUnit(units)
local target = nil;
if units ~= nil and #units >= 1 then
return units[1];
end
return target;
end
function U.GetEnemyFountain()
local Team = GetTeam();
if Team == TEAM_DIRE then
return RB;
else
return DB;
end
end
function U.IsStuck2(npcBot)
if npcBot.stuckLoc ~= nil and npcBot.stuckTime ~= nil then
local EAd = GetUnitToUnitDistance(npcBot, GetAncient(GetOpposingTeam()));
if DotaTime() > npcBot.stuckTime + 5.0 and GetUnitToLocationDistance(npcBot, npcBot.stuckLoc) < 25
and npcBot:GetCurrentActionType() == BOT_ACTION_TYPE_MOVE_TO and EAd > 2200
then
print(npcBot:GetUnitName().." is stuck")
return true;
end
end
return false
end
function U.IsStuck(npcBot)
if npcBot.stuckLoc ~= nil and npcBot.stuckTime ~= nil then
local attackTarget = npcBot:GetAttackTarget();
local EAd = GetUnitToUnitDistance(npcBot, GetAncient(GetOpposingTeam()));
local TAd = GetUnitToUnitDistance(npcBot, GetAncient(GetTeam()));
local Et = npcBot:GetNearbyTowers(200, true);
local At = npcBot:GetNearbyTowers(200, false);
if npcBot:GetCurrentActionType() == BOT_ACTION_TYPE_MOVE_TO and attackTarget == nil and EAd > 2200 and TAd > 2200 and ( Et == nil or #Et == 0 ) and ( At == nil or #At == 0 )
and DotaTime() > npcBot.stuckTime + 5.0 and GetUnitToLocationDistance(npcBot, npcBot.stuckLoc) < 25
then
print(npcBot:GetUnitName().." is stuck")
return true;
end
end
return false
end
return U;