ScriptName aaaKimachuuDungeonsTeleport Extends ActiveMagicEffect

Location Property aaaKimachuuDungeonsLoc Auto
GlobalVariable Property aaaKimachuuDungeonsGoNextArea Auto
GlobalVariable Property aaaKimachuuDungeonsKillCount Auto
GlobalVariable Property aaaKimachuuDungeonsCurrentHierarchy Auto
GlobalVariable Property aaaKimachuuDungeonsQuotaCount Auto
GlobalVariable Property aaaKimachuuDungeonsNFFFollowerMove Auto
GlobalVariable Property aaaKimachuuDungeonsRewards Auto
ObjectReference Property aaaKimachuuDungeonsEntranceRef Auto
ObjectReference Property aaaKimachuuDungeonsTeleportRef Auto
Quest Property DialogueFollower Auto

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Location kCurrentLoc = akCaster.GetCurrentLocation()
	if kCurrentLoc != aaaKimachuuDungeonsLoc
		aaaKimachuuDungeonsTeleportRef.MoveTo(akCaster, 0.0, 0.0, 0.0, True)
		akCaster.MoveTo(aaaKimachuuDungeonsEntranceRef, 0.0, 0.0, 0.0, True)
		followerMoveFunction(aaaKimachuuDungeonsEntranceRef)
		resetGlobalFunction()
	else
		akCaster.MoveTo(aaaKimachuuDungeonsTeleportRef, 0.0, 0.0, 0.0, True)
		followerMoveFunction(aaaKimachuuDungeonsTeleportRef)
	endIf
EndEvent

Function resetGlobalFunction()
	aaaKimachuuDungeonsGoNextArea.SetValue(0)
	aaaKimachuuDungeonsKillCount.SetValue(0)
	aaaKimachuuDungeonsCurrentHierarchy.SetValue(0)
	aaaKimachuuDungeonsQuotaCount.SetValue(0)
	aaaKimachuuDungeonsRewards.SetValue(0)
EndFunction

Function followerMoveFunction(ObjectReference obj01)
	if Game.GetModByName("nwsFollowerFramework.esp") < 255 && aaaKimachuuDungeonsNFFFollowerMove.GetValue() == 1
		Quest NFFQuest = DialogueFollower
		int i = 2
		While i <= 12
			Utility.Wait(0.1)
			Actor Follower = (NFFQuest.GetAlias(i) as ReferenceAlias).GetRef() as Actor
			if Follower
				Follower.MoveTo(obj01)
			endif
			i += 1
		EndWhile
	Endif
EndFunction