//==================================================================
//电脑英雄自动施放技能系统V1.3 BY 金皮蛋
//使得电脑英雄能够自动对附近的敌方英雄集火并且使用技能
//支持包括通魔在内的绝大部分英雄技能模板
//一键移植,用法极其方便
//==================================================================
library GoldenEggAISettings
globals
public real Range = 1600//AI进攻范围
public real Ratio = 1//AI技能施放范围系数
public boolean Lock = true//true为锁定血量最少的目标,false为不锁定
public boolean OnlyHero = true//true为只对英雄有效,false为对所有单位有效
public boolean CreepAI = false//true为对野怪玩家有效,false为对野怪玩家无效
public boolean HumanAI = false//true为对人类玩家有效,false为对人类玩家无效
endglobals
endlibrary
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
//==================================================================
library HeroSpellSystemAI initializer Init needs GoldenEggAISettings
globals
private integer Top = 0
private boolean AB = false
private unit array Hero
private unit array Htu
private real array Htx
private real array Hty
private integer array LastOI
private integer array OT
private integer array TYPE
private boolean array GUARD
private timer array HT
private group AG = null
private region RR = null
private trigger TE = null
private real Range = 1600
private real Ratio = 1.
private boolean OnlyHero = true
private boolean CreepAI = false
private boolean HumanAI = false
private boolean Lock = true
endglobals
private function DistanceBetweenUnits takes unit u1, unit u2 returns real
return SquareRoot(( GetUnitX(u1)-GetUnitX(u2))*(GetUnitX(u1)-GetUnitX(u2))+(GetUnitY(u1)-GetUnitY(u2))*(GetUnitY(u1)-GetUnitY(u2)))
endfunction
private function IsPlayerComputer takes player p returns boolean
if GetPlayerController(p)==MAP_CONTROL_COMPUTER /*
*/or (GetPlayerController(p)==MAP_CONTROL_USER and HumanAI) /*
*/or (GetPlayerController(p)==MAP_CONTROL_CREEP and CreepAI) then
return true
endif
return false
endfunction
private function IsUnitUseAI takes unit u returns boolean
if IsUnitType(u,UNIT_TYPE_HERO) or OnlyHero==false then
return true
endif
return false
endfunction
private function IsUnitVisibleToEnemy takes unit u returns boolean
local integer i = 0
loop
if IsUnitVisible(u,Player(i)) and IsUnitEnemy(u,Player(i)) then
return true
endif
set i = i + 1
exitwhen i > 15
endloop
return false
endfunction
private function GetHeroId takes unit u returns integer
local integer i = 1
loop
exitwhen i > Top
if u==Hero[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function GetTimerId takes timer t returns integer
local integer i = 1
loop
exitwhen i > Top
if t==HT[i] then
return i
endif
set i = i + 1
endloop
return 0
endfunction
private function IsFree takes integer OI returns boolean
if OI==0 or OI==851972 or OI==851983 or OI == 852128 then
return true
endif
return false
endfunction
private function IS takes unit AU returns boolean
local integer OI = GetUnitCurrentOrder(AU)
if OI == 0/*
*/or OI == 851972/*
*/or OI == 851993/*
*/or OI == 851983/*
*/or OI == 851984/*
*/or OI == 851988/*
*/or OI == 851990/*
*/or OI == 851983/*
*/or OI == 851985/*
*/or OI == 851986/*
*/or OI == 851988/*
*/or OI == 851990/*
*/or OI == 999999 then
return true
endif
return false
endfunction
private function IC takes unit u, integer i returns boolean
if AB==false and GetUnitCurrentOrder(u)!=i and i!=LastOI[GetHeroId(u)] then
return true
endif
return false
endfunction
private function SD takes unit u, integer i returns nothing
local integer id = GetHeroId(u)
set AB = true
set LastOI[id] = i
set OT[id] = 5
endfunction
private function IO takes unit AU, integer AI returns nothing
if IC(AU,AI) then
if IssueImmediateOrderById( AU, AI ) then
call SD(AU,AI)
endif
endif
endfunction
private function IL takes unit AU, integer AI, real x, real y returns nothing
if IC(AU,AI) then
if IssuePointOrderById( AU, AI ,x ,y ) then
call SD(AU,AI)
endif
endif
endfunction
private function IU takes unit AU, integer AI, unit AT returns nothing
if IC(AU,AI) then
if IssueTargetOrderById( AU, AI , AT ) then
call SD(AU,AI)
endif
endif
endfunction
private function SO1 takes unit AU, real R returns nothing//无目标
local real H = GetUnitLifePercent(AU)
call IO( AU, 852129 )
if R<=800*Ratio then
call IO( AU, 852097 )
call IO( AU, 852489 )
call IO( AU, 852126 )
call IO( AU, 852503 )
call IO( AU, 852100 )
call IO( AU, 852528 )
call IO( AU, 852184 )
call IO( AU, 852164 )
call IO( AU, 852180 )
call IO( AU, 852554 )
call IO( AU, 852200 )
call IO( AU, 852594 )
call IO( AU, 852595 )
call IO( AU, 852596 )
call IO( AU, 852667 )
call IO( AU, 852663 )
call IO( AU, 852598 )
call IO( AU, 852599 )
call IO( AU, 852600 )
if H<=50. then
call IO( AU, 852586 )
endif
endif
if R<=400*Ratio then
call IO( AU, 852096 )
call IO( AU, 852086 )
call IO( AU, 852090 )
call IO( AU, 852094 )
call IO( AU, 852127 )
call IO( AU, 852128 )
call IO( AU, 852526 )
call IO( AU, 852181 )
call IO( AU, 852183 )
call IO( AU, 852556 )
call IO( AU, 852217 )
call IO( AU, 852588 )
call IO( AU, 852253 )
call IO( AU, 852246 )
endif
if R<=100*Ratio then
call IO( AU, 852123 )
endif
//激活
call IO( AU, 852174 )
call IO( AU, 852552 )
call IO( AU, 852458 )
call IO( AU, 852656 )
call IO( AU, 852589 )
call IO( AU, 852244 )
call IO( AU, 852578 )
call IO( AU, 852671 )
call IO( AU, 852244 )
call IO( AU, 852602 )
call IO( AU, 852212 )
call IO( AU, 852522 )
call IO( AU, 852150 )
call IO( AU, 852133 )
call IO( AU, 852102 )
call IO( AU, 852249 )
if R<=200*Ratio then
call IO( AU, 852177 )
endif
endfunction
private function SO2 takes unit AU, real x, real y, real R returns nothing//点目标
if R>1200 then
call IL( AU, 852093, x, y )
endif
call IL( AU, 852089, x, y )
call IL( AU, 852488, x, y )
call IL( AU, 852121, x, y )
call IL( AU, 852504, x, y )
call IL( AU, 852125, x, y )
call IL( AU, 852555, x, y )
call IL( AU, 852218, x, y )
call IL( AU, 852224, x, y )
call IL( AU, 852221, x, y )
call IL( AU, 852593, x, y )
call IL( AU, 852592, x, y )
call IL( AU, 852597, x, y )
call IL( AU, 852580, x, y )
call IL( AU, 852238, x, y )
call IL( AU, 852652, x, y )
call IL( AU, 852658, x, y )
call IL( AU, 852669, x, y )
call IL( AU, 852229, x, y )
call IL( AU, 852237, x, y )
call IL( AU, 852560, x, y )
call IL( AU, 852591, x, y )
call IL( AU, 852238, x, y )
if R>800 then
call IL( AU, 852122, x, y )
endif
if R>400 then
call IL( AU, 852525, x, y )
endif
if R<200*Ratio then
call IL( AU, 852664, x, y )
endif
call IL( AU, 852600, x, y )
endfunction
private function SO3 takes unit AU, unit AT, boolean Ally returns nothing//单位目标
// 敌
//if Ally == false then
call IU( AU, 852095, AT )
call IU( AU, 852119, AT )
call IU( AU, 852502, AT )
call IU( AU, 852179, AT )
call IU( AU, 852171, AT )
call IU( AU, 852527, AT )
call IU( AU, 852555, AT )
call IU( AU, 852227, AT )
call IU( AU, 852226, AT )
call IU( AU, 852587, AT )
call IU( AU, 852585, AT )
call IU( AU, 852583, AT )
call IU( AU, 852662, AT )
call IU( AU, 852665, AT )
call IU( AU, 852668, AT )
call IU( AU, 852670, AT )
call IU( AU, 852230, AT )
call IU( AU, 852480, AT )
call IU( AU, 852106, AT )
call IU( AU, 852487, AT )
call IU( AU, 852487, AT )
call IU( AU, 852243, AT )
call IU( AU, 852560, AT )
call IU( AU, 852231, AT )
call IU( AU, 852252, AT )
//else
// 友
call IU( AU, 852501, AT )
call IU( AU, 852225, AT )
//endif
// 任意
call IU( AU, 852092, AT )
call IU( AU, 852222, AT )
call IU( AU, 852274, AT )
call IU( AU, 852600, AT )
endfunction