Files
2021-10-24 15:36:18 -04:00

96 lines
2.6 KiB
Lua
Executable File

--[[ Tidehunter AI ]]
require( "ai/ai_core" )
function Spawn( entityKeyValues )
thisEntity:SetContextThink( "AIThink", AIThink, 0.25 )
behaviorSystem = AICore:CreateBehaviorSystem( thisEntity, { BehaviorNone, BehaviorAnchorSmash } )
end
function AIThink() -- For some reason AddThinkToEnt doesn't accept member functions
return behaviorSystem:Think( )
end
--------------------------------------------------------------------------------------------------------
BehaviorNone = {}
function BehaviorNone:Evaluate()
return 1 -- must return a value > 0, so we have a default
end
function BehaviorNone:Begin()
local orders = nil
local hTarget = AICore:ClosestEnemyHeroInRange( thisEntity, 1500 )
if hTarget ~= nil then
thisEntity.lastTargetPosition = hTarget:GetAbsOrigin()
hTarget:MakeVisibleDueToAttack( DOTA_TEAM_BADGUYS, 100 )
orders =
{
UnitIndex = thisEntity:entindex(),
OrderType = DOTA_UNIT_ORDER_ATTACK_TARGET,
TargetIndex = hTarget:entindex()
}
elseif thisEntity.lastTargetPosition ~= nil then
orders =
{
UnitIndex = thisEntity:entindex(),
OrderType = DOTA_UNIT_ORDER_ATTACK_MOVE,
Position = thisEntity.lastTargetPosition
}
else
orders =
{
UnitIndex = thisEntity:entindex(),
OrderType = DOTA_UNIT_ORDER_STOP
}
end
return orders
end
BehaviorNone.Continue = BehaviorNone.Begin
--------------------------------------------------------------------------------------------------------
BehaviorAnchorSmash = {}
function BehaviorAnchorSmash:Evaluate()
--print( "BehaviorAnchorSmash:Evaluate()" )
local desire = 0
self.anchorSmashAbility = thisEntity:FindAbilityByName( "tidehunter_anchor_smash" )
if self.anchorSmashAbility and self.anchorSmashAbility:IsFullyCastable() then
local enemies = FindUnitsInRadius( DOTA_TEAM_BADGUYS, thisEntity:GetOrigin(), nil, 350, DOTA_UNIT_TARGET_TEAM_ENEMY, DOTA_UNIT_TARGET_HERO, DOTA_UNIT_TARGET_FLAG_NO_INVIS, 0, false )
if ( #enemies >= 1 ) then
desire = #enemies + 1
end
end
return desire
end
function BehaviorAnchorSmash:Begin()
--print( "BehaviorAnchorSmash:Begin()" )
if self.anchorSmashAbility and self.anchorSmashAbility:IsFullyCastable() then
--print( "Casting Anchor Smash" )
local order =
{
UnitIndex = thisEntity:entindex(),
OrderType = DOTA_UNIT_ORDER_CAST_NO_TARGET,
AbilityIndex = self.anchorSmashAbility:entindex()
}
return order
end
return nil
end
BehaviorAnchorSmash.Continue = BehaviorAnchorSmash.Begin
--------------------------------------------------------------------------------------------------------
AICore.possibleBehaviors = { BehaviorNone, BehaviorAnchorSmash }