library TEST uses AutoCastSystem, RandomUnit
globals
ACS bloodmage
ACS warden
endglobals
private function UnitAlive takes unit u returns boolean
return not IsUnitType(u, UNIT_TYPE_DEAD) and GetUnitTypeId(u)!=0
endfunction
private function FilterAllies takes unit flteredUnit returns boolean
return UnitAlive(flteredUnit) and not IsUnitEnemy(CS.caster, GetOwningPlayer(flteredUnit))
endfunction
private function FilterEnemies takes unit flteredUnit returns boolean
return UnitAlive(flteredUnit) and IsUnitEnemy(CS.caster, GetOwningPlayer(flteredUnit))
endfunction
/*******************************************************
* CAST CONDITIONS AND UNIT FILTERING
********************************************************/
private function CheckAlly takes nothing returns boolean
return FilterAllies(GetFilterUnit())
endfunction
private function CheckEnemies takes nothing returns boolean
return FilterEnemies(GetFilterUnit())
endfunction
private function TargetEnemyNonStructure takes nothing returns boolean
return FilterEnemies(GetFilterUnit()) and not IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)
endfunction
private function TargetEnemyStructure takes nothing returns boolean
return FilterEnemies(GetFilterUnit()) and IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)
endfunction
private function TargetEnemyFlyers takes nothing returns boolean
return FilterEnemies(GetFilterUnit()) and IsUnitType(GetFilterUnit(), UNIT_TYPE_FLYING)
endfunction
/*******************************************************
* NO-TARGET
********************************************************/
private function CastChanceNoTarget takes nothing returns boolean
local boolean b = false
if GetRandomInt(0, 100) < 80 then
set CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 500, Filter(function CheckEnemies))
if CS.target!=null then
set b = true
endif
endif
return b
endfunction
/*******************************************************
* TARGET UNIT
********************************************************/
private function CastHealAlly takes nothing returns boolean
set CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function CheckAlly))
if CS.target!=null and GetWidgetLife(CS.target) < GetUnitState(CS.target, UNIT_STATE_MAX_LIFE) and GetUnitAbilityLevel(CS.target, 'Brej')==0 then
return true
endif
return false
endfunction
private function CastTargetEnemy takes nothing returns boolean
set CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function TargetEnemyNonStructure))
return CS.target!=null
endfunction
private function CastChanceTargetEnemy takes nothing returns boolean
local boolean b = false
if GetRandomInt(0, 100) < 70 then
set CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function TargetEnemyFlyers))
if CS.target!=null and GetUnitAbilityLevel(CS.target, 'Bena')==0 then
set b = true
endif
endif
return b
endfunction
/*******************************************************
* TARGET POINT
********************************************************/
//This is how to manipulate the spell's execution, this is a condition for the spell to take place
//if it returns true the spell is casted
private function CastPointEnemy takes nothing returns boolean
/********************************************
Struct globals you may use, these are self explanatory
CS.caster (readonly)
CS.target (can modify)
CS.SpellTargetX (can modify)
CS.SpellTargetY (can modify)
*********************************************/
set CS.target = GetRandomUnitInArea(GetUnitX(CS.caster), GetUnitY(CS.caster), 900, Filter(function TargetEnemyNonStructure))
if CS.target!=null then
set CS.SpellTargetX = GetUnitX(CS.target)
set CS.SpellTargetY = GetUnitY(CS.target)
return true
endif
//if you do not have a target but just want to cast a spell in the XY of the map
//you may set the CS.SpellTargetX and CS.SpellTargetY to a coordinate you like
//and just return true, but remember that the XY MUST be in range of spell
return false
endfunction
/*******************************************************
* START READING HERE
********************************************************/
private function RemoveBloodmageFromSystem takes nothing returns nothing
//removes the unit from the system
call bloodmage.removeAutocast()
call BJDebugMsg("******************************************")
call BJDebugMsg("Bloodmage removed from casting ALL spells")
endfunction
private function RemoveSpell takes nothing returns nothing
call bloodmage.removeSpellOrderUnit(852218) //carrion swarm
call BJDebugMsg("******************************************")
call BJDebugMsg("After a while again, Blood mage will no longer cast any spells.")
call TimerStart(CreateTimer(), 10.0, false, function RemoveBloodmageFromSystem)
endfunction
function CastAITestBloodmage takes unit u returns nothing
//create a global or local ACS based on struct name
//in this scenario, global is created for it to be used outside this function
//a GLOBAL instance is highly recommended
//units cannot be registered twice
set bloodmage = bloodmage.register(u)
/***************************************************************************
* SPELL REGISTRATION, use OrderID's
****************************************************************************/
//the unit will cast 6 different kinds of spell based below
//you do not need to create a new function, you may add different spell to the same function but
//depends on your condition though
//you may create a condition such as CHANCE for it to be true
//for the purpose of this demo, the cooldown is set to 2 seconds for each of the spells
//all spells also is at range from the standing hero and target unit or point
//the function is the execution condtion while the number is the orderID of the spell
//the function must return TRUE for the spell to take place
//you may add the spell orderID twice or many times to increase the chance for the unit to cast a certain spell
call bloodmage.spellTypeUnitTarget(function CastHealAlly, 852160) //rejuvenation
call bloodmage.spellTypeUnitTarget(function CastTargetEnemy, 852189) //cripple
call bloodmage.spellTypeUnitTarget(function CastTargetEnemy, 852487) //life drain (channel)
call bloodmage.spellTypePointTarget(function CastPointEnemy, 852488) //flame strike
call bloodmage.spellTypePointTarget(function CastPointEnemy, 852218) //carrion swarm
call bloodmage.spellTypeNoTarget(function CastChanceNoTarget, 852588) //howl of terror
/***************************************************************************
* STARTING THE CASTING
****************************************************************************/
//the last thing you need to do, set the interval on how many seconds your caster casts the spell
call bloodmage.launch(1.0) //recommended is 1 second, but it's all up to you
//call BJDebugMsg("******************************************")
//call BJDebugMsg("Carrion Swarm will be removed from casting after a while.")
//removing a specific spell from the system
//in this example, the global bloodmage instance is used
//call TimerStart(CreateTimer(), 10.0, false, function RemoveSpell)
endfunction
function CastAITestWarden takes unit u returns nothing
set warden = warden.register(u)
call warden.spellTypePointTarget(function CastPointEnemy, 852238) //rain of fire (channel)
call warden.spellTypePointTarget(function CastPointEnemy, 852525) //blink
call warden.spellTypeUnitTarget(function CastChanceTargetEnemy, 852106) //ensnare
call warden.spellTypeUnitTarget(function CastChanceTargetEnemy, 852527) //shadow strike
call warden.spellTypeNoTarget(function CastChanceNoTarget, 852526) //fan of knives
call warden.launch(1.0)
endfunction
endlibrary