Skip to content

Commit

Permalink
Fix ability and item (#42)
Browse files Browse the repository at this point in the history
Add file AbilityAbstraction.lua;
Decrease desire of target ability usage at targets with spell block;
Prevent target ability usage at friend illusions;
Decrease desire of passive toggle abilities to save mana;
Fix terrorblade, dark_seer, antimage, necrolyte, kunkka et al. cannot use abilities;
Add medusa split arrow; add medusa toggle shield off to save mana;
Add item purchase (witch_blade, falcon_blade, holy_locket, gleipnir, wind_waker, ghost_sceptre);
Remove courier purchase;

Co-authored-by: adamqqq <[email protected]>
  • Loading branch information
AaronSong321 and adamqqqplay authored Apr 10, 2021
1 parent d59485c commit efb19be
Show file tree
Hide file tree
Showing 209 changed files with 3,129 additions and 879 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ luac.out
*.hex

LICENSE
.vscode
.vscode
.idea
4 changes: 3 additions & 1 deletion ability_item_usage_abaddon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--------------------------------------
local utility = require( GetScriptDirectory().."/utility" )
require(GetScriptDirectory() .. "/ability_item_usage_generic")
local AbilityExtensions = require(GetScriptDirectory().."/util/AbilityAbstraction")

local debugmode=false
local npcBot = GetBot()
Expand Down Expand Up @@ -106,7 +107,7 @@ end

local CanCast={CanCast1,CanCast2}

Consider[1]=function()
Consider[1]=function() -- TODO: lv 25 AOE mist coil
local abilityNumber=1
--------------------------------------
-- Generic Variable Setting
Expand Down Expand Up @@ -424,6 +425,7 @@ Consider[4]=function()

return BOT_ACTION_DESIRE_NONE
end
AbilityExtensions:AutoModifyConsiderFunction(npcBot, Consider, AbilitiesReal)

function AbilityUsageThink()

Expand Down
2 changes: 2 additions & 0 deletions ability_item_usage_abyssal_underlord.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--------------------------------------
local utility = require( GetScriptDirectory().."/utility" )
require(GetScriptDirectory() .. "/ability_item_usage_generic")
local AbilityExtensions = require(GetScriptDirectory().."/util/AbilityAbstraction")

local debugmode=false
local npcBot = GetBot()
Expand Down Expand Up @@ -384,6 +385,7 @@ Consider[4]=function()
return BOT_ACTION_DESIRE_NONE, 0;
end

AbilityExtensions:AutoModifyConsiderFunction(npcBot, Consider, AbilitiesReal)
function AbilityUsageThink()

-- Check if we're already using an ability
Expand Down
246 changes: 169 additions & 77 deletions ability_item_usage_alchemist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--------------------------------------
local utility = require( GetScriptDirectory().."/utility" )
require(GetScriptDirectory() .. "/ability_item_usage_generic")
local AbilityExtensions = require(GetScriptDirectory().."/util/AbilityAbstraction")

local debugmode=false
local npcBot = GetBot()
Expand All @@ -21,6 +22,7 @@ local abilityName = { "alchemist_acid_spray", "alchemist_unstable_concoction", "
local abilityIndex = utility.ReverseTable(abilityName)



local AbilityToLevelUp=
{
Abilities[3],
Expand Down Expand Up @@ -77,7 +79,7 @@ end
--------------------------------------
local cast={} cast.Desire={} cast.Target={} cast.Type={}
local Consider ={}
local CanCast={utility.NCanCast,utility.NCanCast,utility.NCanCast,utility.UCanCast,utility.NCanCast}
local CanCast={utility.NCanCast,utility.NCanCast,utility.NCanCast,utility.UCanCast,utility.CanCastNoTarget}
local enemyDisabled=utility.enemyDisabled

function GetComboDamage()
Expand Down Expand Up @@ -314,66 +316,154 @@ function Consider2()

end

Consider[abilityIndex.alchemist_unstable_concoction_throw]=function()
local abilityNumber=abilityIndex.alchemist_unstable_concoction_throw
--------------------------------------
-- Generic Variable Setting
--------------------------------------
local ability=AbilitiesReal[abilityNumber];

if not ability:IsFullyCastable() then
return BOT_ACTION_DESIRE_NONE, 0;
end

local CastRange = ability:GetCastRange();
local Damage = ability:GetAbilityDamage();
local CastPoint = ability:GetCastPoint();

local allys = npcBot:GetNearbyHeroes( 1200, false, BOT_MODE_NONE );
local enemys = npcBot:GetNearbyHeroes(CastRange+300,true,BOT_MODE_NONE)
local WeakestEnemy,HeroHealth=utility.GetWeakestUnit(enemys)
local creeps = npcBot:GetNearbyCreeps(CastRange+300,true)
local WeakestCreep,CreepHealth=utility.GetWeakestUnit(creeps)
--------------------------------------
-- Global high-priorty usage
--------------------------------------
if ( ManaPercentage+HealthPercentage<=1.2)
then
return BOT_ACTION_DESIRE_LOW
end

-- If we're in a teamfight, use it on the scariest enemy
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
if ( #tableNearbyAttackingAlliedHeroes >= 2)
then
return BOT_ACTION_DESIRE_HIGH
end
--------------------------------------
-- Mode based usage
--------------------------------------
-- If we're seriously retreating, see if we can land a stun on someone who's damaged us recently
if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH )
then
if ( npcBot:WasRecentlyDamagedByAnyHero( 2.0 ) and HealthPercentage<=0.70+#enemys*0.05)
then
return BOT_ACTION_DESIRE_HIGH
end
end

-- If we're going after someone
if ( npcBot:GetActiveMode() == BOT_MODE_ROAM or
npcBot:GetActiveMode() == BOT_MODE_TEAM_ROAM or
npcBot:GetActiveMode() == BOT_MODE_DEFEND_ALLY or
npcBot:GetActiveMode() == BOT_MODE_ATTACK )
then
if ( HealthPercentage<=0.70+#enemys*0.05 )
then
return BOT_ACTION_DESIRE_HIGH
end
end
Consider[abilityIndex.alchemist_chemical_rage]=function()
local abilityNumber=abilityIndex.alchemist_chemical_rage
AbilityExtensions:GetTargetHealModifierPercent(npcBot)
--------------------------------------
-- Generic Variable Setting
--------------------------------------
local ability=AbilitiesReal[abilityNumber];

if not ability:IsFullyCastable() then
return BOT_ACTION_DESIRE_NONE, 0;
end

local CastRange = ability:GetCastRange();
local Damage = ability:GetAbilityDamage();
local CastPoint = ability:GetCastPoint();

local allys = npcBot:GetNearbyHeroes( 1200, false, BOT_MODE_NONE );
local enemys = npcBot:GetNearbyHeroes(CastRange+300,true,BOT_MODE_NONE)
local WeakestEnemy,HeroHealth=utility.GetWeakestUnit(enemys)
local creeps = npcBot:GetNearbyCreeps(CastRange+300,true)
local WeakestCreep,CreepHealth=utility.GetWeakestUnit(creeps)
--------------------------------------
-- Global high-priorty usage
--------------------------------------
if HealthPercentage <= 0.2 then
return BOT_ACTION_DESIRE_HIGH
end
if ( HealthPercentage<=0.4)
then
return BOT_ACTION_DESIRE_LOW
end

-- If we're in a teamfight, use it on the scariest enemy
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
if ( #tableNearbyAttackingAlliedHeroes >= 2)
then
return BOT_ACTION_DESIRE_HIGH
end
--------------------------------------
-- Mode based usage
--------------------------------------
-- If we're seriously retreating, see if we can land a stun on someone who's damaged us recently
if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH )
then
if ( npcBot:WasRecentlyDamagedByAnyHero( 2.0 ) and HealthPercentage<=0.70+#enemys*0.05)
then
return BOT_ACTION_DESIRE_HIGH
end
end

-- If we're going after someone
if ( npcBot:GetActiveMode() == BOT_MODE_ROAM or
npcBot:GetActiveMode() == BOT_MODE_TEAM_ROAM or
npcBot:GetActiveMode() == BOT_MODE_DEFEND_ALLY or
npcBot:GetActiveMode() == BOT_MODE_ATTACK )
then
if ( HealthPercentage<=0.70+#enemys*0.05 )
then
return BOT_ACTION_DESIRE_HIGH
end
end

return BOT_ACTION_DESIRE_NONE
end

return BOT_ACTION_DESIRE_NONE, 0;

Consider[abilityIndex.alchemist_berserk_potion]=function()
local abilityNumber=abilityIndex.alchemist_berserk_potion
--------------------------------------
-- Generic Variable Setting
--------------------------------------
local ability=AbilitiesReal[abilityNumber];

if not ability:IsFullyCastable() then
return BOT_ACTION_DESIRE_NONE, 0;
end

local CastRange = ability:GetCastRange();
local Damage = ability:GetAbilityDamage();
local CastPoint = ability:GetCastPoint();

local allys = npcBot:GetNearbyHeroes( CastRange+200, false, BOT_MODE_NONE );
-- use at myself when chemical rage is not available
local useTable = {}
if not npcBot:HasModifier("modifier_alchemist_chemical_rage") and not npcBot:HasModifier("modifier_alchemist_berserk_potion") then
local useChemicalRageDesire = Consider[abilityIndex.alchemist_chemical_rage]()
if useChemicalRageDesire ~= 0 then
table.insert(useTable, {useChemicalRageDesire, npcBot})
end
end

local checkAlly = function(ally)
if HealthPercentage <= 0.2 then
return BOT_ACTION_DESIRE_HIGH
end
if ( HealthPercentage<=0.4)
then
return BOT_ACTION_DESIRE_LOW
end

-- If we're in a teamfight, use it on the scariest enemy
local tableNearbyAttackingAlliedHeroes = npcBot:GetNearbyHeroes( 1000, false, BOT_MODE_ATTACK );
if ( #tableNearbyAttackingAlliedHeroes >= 2)
then
return BOT_ACTION_DESIRE_HIGH
end
--------------------------------------
-- Mode based usage
--------------------------------------
-- If we're seriously retreating, see if we can land a stun on someone who's damaged us recently
if ( ally:GetActiveMode() == BOT_MODE_RETREAT and ally:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH )
then
if ( ally:WasRecentlyDamagedByAnyHero( 2.0 ) and HealthPercentage<=0.70+#enemys*0.05)
then
return BOT_ACTION_DESIRE_HIGH
end
end

-- If we're going after someone
if ( ally:GetActiveMode() == BOT_MODE_ROAM or
ally:GetActiveMode() == BOT_MODE_TEAM_ROAM or
ally:GetActiveMode() == BOT_MODE_DEFEND_ALLY or
ally:GetActiveMode() == BOT_MODE_ATTACK )
then
if ( HealthPercentage<=0.70+#enemys*0.05 )
then
return BOT_ACTION_DESIRE_HIGH
end
end

return BOT_ACTION_DESIRE_NONE
end
for _, ally in ipairs(allys) do
local useAtAllyDesire = checkAlly(ally) - 0.2
if useAtAllyDesire > 0 then
table.insert(useTable, {useAtAllyDesire, ally})
end
end
local highestDesire = {-1, -1}
for _, target in ipairs(useTable) do
if highestDesire[1] < target[1] then
highestDesire = target
end
end
if highestDesire[1] == -1 then
return 0
else
return highestDesire[1], highestDesire[2]
end
end

Consider[abilityIndex.alchemist_unstable_concoction_throw]=function()
Expand Down Expand Up @@ -418,7 +508,7 @@ Consider[abilityIndex.alchemist_unstable_concoction_throw]=function()
then
if(HeroHealth<=WeakestEnemy:GetActualIncomingDamage(Damage,DAMAGE_TYPE_MAGICAL) or (HeroHealth<=WeakestEnemy:GetActualIncomingDamage(GetComboDamage(),DAMAGE_TYPE_MAGICAL) and npcBot:GetMana()>ComboMana))
then
if((GetUnitToUnitDistance(npcBot,WeakestEnemy)>CastRange-100 and GetUnitToUnitDistance(npcBot,WeakestEnemy)<CastRange) or (TimeSinceCast>4 and TimeSinceCast<5) or WeakestEnemy:GetMaxHealth()/WeakestEnemy:GetMaxHealth()<=0.2)
if((GetUnitToUnitDistance(npcBot,WeakestEnemy)>CastRange-100 and GetUnitToUnitDistance(npcBot,WeakestEnemy)<CastRange) or (TimeSinceCast>3 and TimeSinceCast<5) or WeakestEnemy:GetHealth()/WeakestEnemy:GetMaxHealth()<=0.2)
then
return BOT_ACTION_DESIRE_HIGH,WeakestEnemy
end
Expand All @@ -431,16 +521,12 @@ Consider[abilityIndex.alchemist_unstable_concoction_throw]=function()
-- Mode based usage
--------------------------------------
-- If we're seriously retreating, see if we can land a stun on someone who's damaged us recently
if ( npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH )
then
for _,npcEnemy in pairs( enemys )
do
if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 2.0 ) )
then
if ( CanCast[abilityNumber]( npcEnemy ) and not enemyDisabled(npcEnemy))
then
if((GetUnitToUnitDistance(npcBot,npcEnemy)>CastRange-100 and GetUnitToUnitDistance(npcBot,npcEnemy)<CastRange) or (TimeSinceCast>4 and TimeSinceCast<5) or npcEnemy:GetMaxHealth()/npcEnemy:GetMaxHealth()<=0.2)
then
if npcBot:GetActiveMode() == BOT_MODE_RETREAT and npcBot:GetActiveModeDesire() >= BOT_MODE_DESIRE_HIGH then
for _,npcEnemy in pairs( enemys )do
if ( npcBot:WasRecentlyDamagedByHero( npcEnemy, 2.0 ) ) then
if ( CanCast[abilityNumber]( npcEnemy ) and not enemyDisabled(npcEnemy)) then
if (GetUnitToUnitDistance(npcBot,npcEnemy)>CastRange-100 and GetUnitToUnitDistance(npcBot,npcEnemy)<CastRange) or (TimeSinceCast>3 and TimeSinceCast<5)
or npcEnemy:GetHealth()/npcEnemy:GetMaxHealth() <= 0.2 then
return BOT_ACTION_DESIRE_HIGH,npcEnemy
end
end
Expand All @@ -458,9 +544,9 @@ Consider[abilityIndex.alchemist_unstable_concoction_throw]=function()

if ( npcEnemy ~= nil )
then
if ( CanCast[abilityNumber]( npcEnemy ) and not enemyDisabled(npcEnemy) )
then
if((GetUnitToUnitDistance(npcBot,npcEnemy)>CastRange-100 and GetUnitToUnitDistance(npcBot,npcEnemy)<CastRange) or (TimeSinceCast>4 and TimeSinceCast<5) or npcEnemy:GetMaxHealth()/npcEnemy:GetMaxHealth()<=0.2)
if CanCast[abilityNumber]( npcEnemy ) and not enemyDisabled(npcEnemy) then
if GetUnitToUnitDistance(npcBot,npcEnemy)>CastRange-100 and GetUnitToUnitDistance(npcBot,npcEnemy)<CastRange
or (TimeSinceCast>3 and TimeSinceCast<5) or npcEnemy:GetHealth()/npcEnemy:GetMaxHealth() <= 0.2
then
return BOT_ACTION_DESIRE_HIGH,npcEnemy
end
Expand All @@ -473,10 +559,16 @@ Consider[abilityIndex.alchemist_unstable_concoction_throw]=function()
return BOT_ACTION_DESIRE_HIGH+0.1,enemys[1]
end

return BOT_ACTION_DESIRE_NONE, 0;


-- throw when I'm hurt
if (npcBot:GetHealth()/npcBot:GetMaxHealth() <= 0.25 and TimeSinceCast >= 1) then
local es = npcBot:GetNearbyHeroes(CastRange,true,BOT_MODE_NONE)
if #es > 0 then
return BOT_ACTION_DESIRE_HIGH, es[1]
end
end
return BOT_ACTION_DESIRE_NONE, 0
end
AbilityExtensions:AutoModifyConsiderFunction(npcBot, Consider, AbilitiesReal)

function AbilityUsageThink()

Expand Down
7 changes: 4 additions & 3 deletions ability_item_usage_ancient_apparition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
--------------------------------------
local utility = require( GetScriptDirectory().."/utility" )
require(GetScriptDirectory() .. "/ability_item_usage_generic")
local AbilityExtensions = require(GetScriptDirectory().."/util/AbilityAbstraction")

local debugmode=false
local npcBot = GetBot()
Expand Down Expand Up @@ -114,8 +115,7 @@ Consider[1]=function()
-- Check for a channeling enemy
for _,npcEnemy in pairs( enemys )
do
if ( npcEnemy:IsChanneling() and CanCast[abilityNumber]( npcEnemy ))
then
if npcEnemy:IsChanneling() and CanCast[abilityNumber]( npcEnemy ) then -- TODO: left channel time long enough
return BOT_ACTION_DESIRE_HIGH, npcEnemy
end
end
Expand Down Expand Up @@ -547,7 +547,8 @@ Consider[5]=function()
return BOT_ACTION_DESIRE_NONE;

end

AbilityExtensions:AutoModifyConsiderFunction(npcBot, Consider, AbilitiesReal)

function AbilityUsageThink()

-- Check if we're already using an ability
Expand Down
Loading

0 comments on commit efb19be

Please sign in to comment.