ScriptName aaaKimachuuGMAFMain Extends ReferenceAlias

Actor Property PlayerRef Auto
Faction Property aaaKimachuuGMAF Auto
FormList Property aaaKimachuuGMAFActorFL Auto
LeveledItem Property aaaKimachuuGMAFLvItem Auto
Message Property aaaKimachuuGMAFMes01 Auto
MiscObject Property aaaKimachuuGMAFMisc Auto
Spell Property aaaKimachuuGMAFSpell Auto

Bool bInit = False
Float fResultTime

Import StorageUtil

Event OnInit()
	Utility.Wait(0.1)
	If bInit
		Return
	Else
		bInit = True
		Utility.Wait(5.0)
		initFunction()
		PlayerRef.AddItem(aaaKimachuuGMAFMisc, 1)
		PlayerRef.AddSpell(aaaKimachuuGMAFSpell)
		Debug.Notification("KimachuuGMAF Start.")
		RegisterForUpdateGameTime(1.0)
	EndIf
EndEvent

Event OnUpdateGameTime()
	Int i = aaaKimachuuGMAFActorFL.GetSize()
	If i == 0
		Return
	EndIf

	Bool bExist = False
	While i > 0
		i -= 1
		Actor actTemp = aaaKimachuuGMAFActorFL.GetAt(i) As Actor

		If (PlayerRef.GetCurrentLocation() != actTemp.GetCurrentLocation())
			bExist = True
			Float fTime = GetFloatValue(actTemp, "strTime") ;出発時、定期チェック時の時間
			Float fProgressTime = Utility.GetCurrentGameTime() ;現在の時間
			fResultTime = 0.0
			fResultTime = ((fProgressTime - fTime) * 24.0) ;経過時間を計算

			If fResultTime >= 1.0
				actTemp.AddItem(aaaKimachuuGMAFLvItem, fResultTime As Int)
			Else
				actTemp.AddItem(aaaKimachuuGMAFLvItem, 1)
			EndIf		
			SetFloatValue(actTemp, "strTime", Utility.GetCurrentGameTime())
		EndIf
	EndWhile
	If bExist == True
		aaaKimachuuGMAFMes01.Show()
	EndIf
	RegisterForUpdateGameTime(1.0)
EndEvent

Function initFunction()
	Int i = aaaKimachuuGMAFActorFL.GetSize()
	While i > 0
		i -= 1
		Actor actTemp = aaaKimachuuGMAFActorFL.GetAt(i) As Actor
		If actTemp != None
			actTemp.AddToFaction(aaaKimachuuGMAF)
			SetFloatValue(actTemp, "strTime", Utility.GetCurrentGameTime())
		EndIf
	EndWhile	
EndFunction