ScriptName aaaKimachuuGMAFME Extends ActiveMagicEffect

Faction Property aaaKimachuuGMAF Auto
FormList Property aaaKimachuuGMAFActorFL Auto
Message Property aaaKimachuuGMAFMes02 Auto
Message Property aaaKimachuuGMAFMes03 Auto
Quest Property aaaKimachuuGMAFQuest Auto

Import StorageUtil

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Int iIndex = aaaKimachuuGMAFMes02.Show()
	If iIndex == 0
		aaaKimachuuGMAFQuest.Start()
		Debug.Notification("Quest Start.")
	ElseIf iIndex == 1
		aaaKimachuuGMAFQuest.Stop()
		Debug.Notification("Quest Stop.")
	ElseIf iIndex == 2
		Utility.Wait(0.1)
		GoToState("StateD")
		Return
	Else
		;empty
	EndIf
EndEvent

State StateD
	Event OnBeginState()
		Int iIndex = aaaKimachuuGMAFMes03.Show()
		If iIndex == 1
			Int i = aaaKimachuuGMAFActorFL.GetSize()
			While i > 0
				i -= 1
				Actor actTemp = aaaKimachuuGMAFActorFL.GetAt(i) As Actor
				If actTemp != None
					actTemp.RemoveFromFaction(aaaKimachuuGMAF)
					aaaKimachuuGMAFActorFL.RemoveAddedForm(actTemp)
					UnsetFloatValue(actTemp, "strTime")
				EndIf
			EndWhile
			aaaKimachuuGMAFQuest.Stop()
			aaaKimachuuGMAFActorFL.Revert()
			Debug.Notification("Emptying the FormList and stopping the quest.")
			GotoState("")
		Else
			GotoState("")
		EndIf
	EndEvent
EndState