3.3 Hero Harrassment

HarassHeroExecuteOverride()

object : oncombateventOverride()

CustomHarassUtilityFnOverride()

object : oncombateventOverride()



-- These are bonus agression points if a skill/item is available for use

object.nPhoenixUp = 10

object.nDragonUp = 12

object.nBlazingUp = 35

object.nSheepstickUp = 12



-- These are bonus agression points that are applied to the bot upon successfully using a skill/item

object.nPhoenixUse = 15

object.nDragonUse = 18

object.nBlazingUse = 55

object.nSheepstickUse = 18





--These are thresholds of aggression the bot must reach to use these abilities

object.nPhoenixThreshold = 20

object.nDragonThreshold = 10

object.nBlazingThreshold = 60

object.nSheepstickThreshold = 10



CustomHarassUtilityFnOverride()



------------------------------------------------------

-- CustomHarassUtility Override --

-- Change Utility according to usable spells here --

------------------------------------------------------

-- @param: IunitEntity hero

-- @return: number

local function CustomHarassUtilityFnOverride(hero)

local nUtil = 0



if skills.abilQ:CanActivate() then

nUtil = nUtil + object.nPhoenixUp

end



if skills.abilW:CanActivate() then

nUtil = nUtil + object.nDragonUp

end



if skills.abilR:CanActivate() then

nUtil = nUtil + object.nStrikeUp

end



if object.itemSheepstick and object.itemSheepstick:CanActivate() then

nUtil = nUtil + object.nSheepstickUp

end



return nUtil

end

-- assisgn custom Harrass function to the behaviourLib object

behaviorLib.CustomHarassUtility = CustomHarassUtilityFnOverride



oncombateventOverride()



----------------------------------------------

-- OncombatEvent Override --

-- Use to check for Infilictors (fe. Buffs) --

----------------------------------------------

-- @param: EventData

-- @return: none

function object:oncombateventOverride(EventData)

self:oncombateventOld(EventData)



local nAddBonus = 0



if EventData.Type == "Ability" then

if EventData.InflictorName == "Ability_Pyromancer2" then

nAddBonus = nAddBonus + object.nDragonUse

elseif EventData.InflictorName == "Ability_Pyromancer1" then

nAddBonus = nAddBonus + object.nPhoenixUse

elseif EventData.InflictorName == "Ability_Pyromancer4" then

nAddBonus = nAddBonus + object.nBlazingUse

end

elseif EventData.Type == "Item" then

if core.itemSheepstick ~= nil and EventData.SourceUnit == core.unitSelf:GetUniqueID() and EventData.InflictorName == core.itemSheepstick:GetName() then

nAddBonus = nAddBonus + self.nSheepstickUse

end

end



if nAddBonus > 0 then

core.DecayBonus(self)

core.nHarassBonus = core.nHarassBonus + nAddBonus

end



end

-- override combat event trigger function.

object.oncombateventOld = object.oncombatevent

object.oncombatevent = object.oncombateventOverride



3.4

Using Skills.

Is the skill available (leveled, mana, cooldown)

is the present bot harassment level above the predefined threshold to use a skill/item

additional check ( range to target, additional targets, other skills/items available)





---code snippit



-- Phoenix Wave

if not bActionTaken then

local abilPhoenix = skills.abilQ

if abilPhoenix:CanActivate() and nLastHarassUtility > botBrain.nPhoenixThreshold then

local nRange = abilPhoenix:GetRange()

if nTargetDistanceSq < (nRange * nRange) then

bActionTaken = core.OrderAbilityPosition(botBrain, abilPhoenix, vecTargetPosition)

else

bActionTaken = core.OrderMoveToUnitClamp(botBrain, unitSelf, unitTarget)

end

end

end





OrderAbilityPosition()

OrderItemEntityClamp()

OrderAbilityEntity()

If the target isn't vulnerable try to use Sheepstick and then DragonFire stun If the bots aggressive level is high enough use PhoenixWave If the bots aggressive level is higher still then use BlazingStrike



--------------------------------------------------------------

-- Harass Behavior --

-- All code how to use abilities against enemies goes here --

--------------------------------------------------------------

-- @param botBrain: CBotBrain

-- @return: none

--

local function HarassHeroExecuteOverride(botBrain)



local unitTarget = behaviorLib.heroTarget

if unitTarget == nil then

return object.harassExecuteOld(botBrain) --Target is invalid, move on to the next behavior

end





local unitSelf = core.unitSelf

local vecMyPosition = unitSelf:GetPosition()

local nAttackRange = core.GetAbsoluteAttackRangeToUnit(unitSelf, unitTarget)

local nMyExtraRange = core.GetExtraRange(unitSelf)



local vecTargetPosition = unitTarget:GetPosition()

local nTargetExtraRange = core.GetExtraRange(unitTarget)

local nTargetDistanceSq = Vector3.Distance2DSq(vecMyPosition, vecTargetPosition)





local nLastHarassUtility = behaviorLib.lastHarassUtil

local bCanSee = core.CanSeeUnit(botBrain, unitTarget)

local bActionTaken = false



--since we are using an old pointer, ensure we can still see the target for entity targeting

if core.CanSeeUnit(botBrain, unitTarget) then

local bTargetVuln = unitTarget:IsStunned() or unitTarget:IsImmobilized() or unitTarget:IsPerplexed()

local abilDragon = skills.abilW

local abilBlazing = skills.abilR

core.FindItems()

local itemSheepstick = core.itemSheepstick



-- Dragon Fire or Sheep - on unit.

if not bActionTaken and not bTargetVuln then

if itemSheepstick then

local nRange = itemSheepstick:GetRange()

if itemSheepstick:CanActivate() and nLastHarassUtility > botBrain.nSheepstickThreshold then

if nTargetDistanceSq < (nRange*nRange) then

bActionTaken = core.OrderItemEntityClamp(botBrain, unitSelf, itemSheepstick, unitTarget)

end

end

end



if abilDragon:CanActivate() and nLastHarassUtility > botBrain.nDragonThreshold then

local nRange = abilDragon:GetRange()

if nTargetDistanceSq < (nRange * nRange) then

bActionTaken = core.OrderAbilityPosition(botBrain, abilDragon, vecTargetPosition)

end

end

end

end





-- Phoenix Wave

if not bActionTaken then

local abilPhoenix = skills.abilQ

if abilPhoenix:CanActivate() and nLastHarassUtility > botBrain.nPhoenixThreshold then

local nRange = abilPhoenix:GetRange()

if nTargetDistanceSq < (nRange * nRange) then

bActionTaken = core.OrderAbilityPosition(botBrain, abilPhoenix, vecTargetPosition)

else

bActionTaken = core.OrderMoveToUnitClamp(botBrain, unitSelf, unitTarget)

end

end

end



-- Blazing Strike

if core.CanSeeUnit(botBrain, unitTarget) then

local abilBlazing = skills.abilR

if not bActionTaken then --and bTargetVuln then

if abilBlazing:CanActivate() and nLastHarassUtility > botBrain.nBlazingThreshold then

local nRange = abilBlazing:GetRange()

if nTargetDistanceSq < (nRange * nRange) then

bActionTaken = core.OrderAbilityEntity(botBrain, abilBlazing, unitTarget)

else

bActionTaken = core.OrderMoveToUnitClamp(botBrain, unitSelf, unitTarget)

end

end

end

end





if not bActionTaken then

return object.harassExecuteOld(botBrain)

end

end







-- overload the behaviour stock function with custom

object.harassExecuteOld = behaviorLib.HarassHeroBehavior["Execute"]

behaviorLib.HarassHeroBehavior["Execute"] = HarassHeroExecuteOverride







4

Conclusion



5

What's Next?

