#name custom_heathendel_deathknight40c
#speed 6

; 105 : Spirit of Solomon 40  [Group=37]
; 5015 : Spirit of Solomon (15% buff)  [Group=37]
; 101 : Root 6  [Cooldown=ReduceMovementSpeed, Will=5]
; 492 : Wither 40   [Group=112]
; 533 : Deathly Dart 40  [Cooldown=DeathlyDart]
; 373 : Malice Blast : 40
; 539 : Concussion 40   [Cooldown=Concussion]
; 228 : Assault 40
; 446 : Bash 40
; 32766 : Melee autoattack

set VAR 0
set WILL 0
set MIGHT 0
set COOLDOWN 0
set SELFID 0
set TARGID 0
set OLDTARGID 0
set ALLOWROOT 0

get_self SELFID

:begin
call waitfortarget

is_busy var
if var = 1
  goto begin
endif

call checkWillCharge
call checkMightCharge
call checkWill
call checkMight
goto begin


:checkWillCharge
getwillcharge VAR
if VAR < 3
  return
endif

use 373
reset_goto begin



:checkWill
getwill WILL
if WILL < 3
  return
endif

if ALLOWROOT = 1
  call tryRoot
  set ALLOWROOT = 0
endif

call tryDeathlyDart

use 492
reset_goto begin




:checkMightCharge
getmightcharge VAR
if VAR < 1
  return
endif

use 446
reset_goto begin



:checkMight
getmight MIGHT
if MIGHT < 3
  return
endif

call tryConcussion

use 228
reset_goto begin



:tryConcussion
getcooldown "Concussion" COOLDOWN
if COOLDOWN != 0
  return
endif

use 539
reset_goto begin



:tryDeathlyDart
getcooldown "DeathlyDart" COOLDOWN
if COOLDOWN != 0
  return
endif
use 533
reset_goto begin



:tryRoot
if WILL < 5
  return
endif

getcooldown "ReduceMovementSpeed" COOLDOWN
if COOLDOWN != 0
  return
endif

get_speed TARGID VAR
if VAR = 0
  return
endif

use 101
reset_goto begin



:castBuffs
get_buff_tier 37 VAR
if VAR = 0
  use 5015
endif
return



:waitfortarget
has_target VAR
if VAR = 0
  wait 1000
  goto waitfortarget
endif

get_target TARGID
if TARGID != OLDTARGID
  get_target OLDTARGID
  set ALLOWROOT 1
endif 

call castBuffs
use 32766
return