ScriptName _00E_UndercityAisolonBossScript Extends Actor

Actor Property swarm1 Auto
Actor Property swarm2 Auto
Actor Property swarm3 Auto

VisualEffect Property visuals Auto

Bool swarmAct1 = False
Bool swarmAct2 = False
Bool swarmAct3 = False

Bool bDoingCombatRoutine = False

; Backward compatibility
Actor Property queenAisolon Auto

Event OnCombatStateChanged(Actor akTarget, int aeCombatState)
	If aeCombatState > 0
		DoCombatRoutine()
	EndIf
EndEvent

Function DoCombatRoutine()
	If (swarmAct1 && swarmAct2 && swarmAct3) || bDoingCombatRoutine
		Return
	EndIf
	bDoingCombatRoutine = True

	If swarmAct1 == False
		swarmAct1 = True
		EnableSwarm(swarm1)
	EndIf

	Float myBaseHealth = GetBaseActorValue("Health")

	While (Is3DLoaded() && IsDead() == False && swarmAct3 == False)
		Float myCurHealth = GetActorValue("Health")

		If swarmAct2 == False && (myCurHealth < (myBaseHealth * 0.75))
			swarmAct2 = True
			EnableSwarm(swarm2)
		ElseIf swarmAct3 == False && (myCurHealth < (myBaseHealth * 0.5))
			swarmAct3 = True
			EnableSwarm(swarm3)
		EndIf

		Utility.Wait(0.1)
	EndWhile

	bDoingCombatRoutine = False
EndFunction

Function EnableSwarm(Actor swarmRef)
	swarmRef.Enable()
	visuals.Play(self, 3.0)
EndFunction