Scriptname lvME2 extends activemagiceffect  
MiniLoversQuestScript Property MiniLoversQuest Auto
lvQQQ Property PVF Auto

Quest Property MiniLoversWaitQuest Auto
MiscObject Property MiniLoversIsSexCoin Auto

Actor target
Actor caster

int idleStage = 1

bool stageKeyFlag = False
bool reverseKeyFlag = False
bool idleSelectKeyFlag = False

Event OnEffectStart(Actor akTarget, Actor akCaster)
	target = akTarget
	caster = akCaster

		caster.UnEquipAll ()
		target.UnEquipAll ()

	target.AddItem(MiniLoversIsSexCoin, 1)
	
	;; 簡易脱衣を使用するならコメントを外して再コンパイル ;;
	;UnequipForPlay()
	
	MiniLoversWaitQuest.Start()
	StartPlayIdle()
	
	RegisterForSingleUpdate(0)
	
	SendStartEvent()
	
EndEvent

Event OnUpdate()
	int reverseAngle = 0
	If (MiniLoversQuest.reversePosition)
		reverseAngle = 180
	EndIf
	float x = (100.0 + MiniLoversQuest.OffsetX) * math.sin(caster.GetAngleZ() + reverseAngle)
	float y = (100.0 + MiniLoversQuest.OffsetX) * math.cos(caster.GetAngleZ() + reverseAngle)
	target.MoveTo(caster, x, y, 0 + MiniLoversQuest.OffsetZ)
	
	If (Input.IsKeyPressed(MiniLoversQuest.IdleSelectKey) && idleSelectKeyFlag == False)
		idleSelectKeyFlag = True
		
		If (Input.IsKeyPressed(MiniLoversQuest.ShiftKey))
			MiniLoversQuest.idleNum -= 1
			If (MiniLoversQuest.idleNum < 0)
				MiniLoversQuest.idleNum = 50 - 1
			EndIf
		Else
			MiniLoversQuest.idleNum += 1
			If (MiniLoversQuest.idleNum >= 50)
				MiniLoversQuest.idleNum = 0
			EndIf
		EndIf
		
		StartPlayIdle()
	ElseIf (Input.IsKeyPressed(MiniLoversQuest.IdleSelectKey) == False && idleSelectKeyFlag)
		idleSelectKeyFlag = False
	EndIf
	
	If (Input.IsKeyPressed(MiniLoversQuest.OffsetXKey))
		If (Input.IsKeyPressed(MiniLoversQuest.ShiftKey))
			MiniLoversQuest.OffsetX -= 0.5
		Else
			MiniLoversQuest.OffsetX += 0.5
		EndIf
	EndIf
	
	If (Input.IsKeyPressed(MiniLoversQuest.OffsetZKey))
		If (Input.IsKeyPressed(MiniLoversQuest.ShiftKey))
			MiniLoversQuest.OffsetZ -= 0.5
		Else
			MiniLoversQuest.OffsetZ += 0.5
		EndIf
	EndIf
	
	If (Input.IsKeyPressed(MiniLoversQuest.StageKey) && stageKeyFlag == False)
		stageKeyFlag = True
		
		If (Input.IsKeyPressed(MiniLoversQuest.ShiftKey))
			If (idleStage == 0)
				idleStage = 3
			ElseIf (idleStage == 2 || idleStage ==3)
				idleStage -= 1
			EndIf
		Else
			If (idleStage == 3)
				idleStage = 0
			ElseIf (idleStage == 1 || idleStage == 2)
				idleStage += 1
			ElseIf (idleStage == 0)
				self.Dispel()
			EndIf
		EndIf
		
		StartPlayIdle()
		
		if ( idleStage == 0 )
			Utility.wait(8.0)
			self.Dispel()
		endif
		
	ElseIf (Input.IsKeyPressed(MiniLoversQuest.StageKey) == False && stageKeyFlag)
		stageKeyFlag = False
	EndIf
	
	If (Input.IsKeyPressed(MiniLoversQuest.ReverseKey) && reverseKeyFlag == False)
		reverseKeyFlag = True
		
		If (MiniLoversQuest.reversePosition)
			MiniLoversQuest.reversePosition = False
		Else
			MiniLoversQuest.reversePosition = True
		EndIf
		
		StartPlayIdle()
	ElseIf (Input.IsKeyPressed(MiniLoversQuest.ReverseKey) == False && reverseKeyFlag)
		reverseKeyFlag = False
	EndIf
	
	RegisterForSingleUpdate(0)
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)

	SendEndEvent()
	caster.additem (aGetDressed, 1, true)
	target.additem (aGetDressed, 1, true)
	
	caster.PushActorAway(target, 1.0)
	target.PushActorAway(caster, 1.0)
	
	target.RemoveItem(MiniLoversIsSexCoin, target.GetItemCount(MiniLoversIsSexCoin))
	MiniLoversWaitQuest.Stop()
	
EndEvent

Function StartPlayIdle()
	Idle idleDef
	Idle idleOff
	
	If (idleStage == 0)
		idleDef = MiniLoversQuest.idleDef0[MiniLoversQuest.idleNum]
		idleOff = MiniLoversQuest.idleOff0[MiniLoversQuest.idleNum]
	ElseIf (idleStage == 1)
		idleDef = MiniLoversQuest.idleDef1[MiniLoversQuest.idleNum]
		idleOff = MiniLoversQuest.idleOff1[MiniLoversQuest.idleNum]
	ElseIf (idleStage == 2)
		idleDef = MiniLoversQuest.idleDef2[MiniLoversQuest.idleNum]
		idleOff = MiniLoversQuest.idleOff2[MiniLoversQuest.idleNum]
	ElseIf (idleStage == 3)
		idleDef = MiniLoversQuest.idleDef3[MiniLoversQuest.idleNum]
		idleOff = MiniLoversQuest.idleOff3[MiniLoversQuest.idleNum]
	EndIf
	
	If (MiniLoversQuest.reversePosition)
		target.PlayIdle(idleOff)
		caster.PlayIdle(idleDef)
	Else
		target.PlayIdle(idleDef)
		caster.PlayIdle(idleOff)
	EndIf
	
	SendStageUpdate()
	
EndFunction

Function SendStartEvent()
	PVF.SetMotionStage( idleStage )
	PVF.SetOffActor( caster )
	PVF.SetDefActor( target )
	PVF.StartVoiceLoop()
EndFunction

Function SendEndEvent()
	PVF.StopVoiceLoop()
EndFunction

Function SendStageUpdate()
	PVF.SetMotionStage( idleStage )
EndFunction

Function UnequipForPlay()
	__UnequipItems__( target )
	__UnequipItems__( caster )
EndFunction

Function __UnequipItems__( Actor pActor )

	Weapon pWeapon

	;pActor.UnequipItemSlot( 32 )
	;pActor.UnequipItemSlot( 39 )
	;pActor.UnequipItemSlot( 46 )	
	;pActor.UnequipItem( pActor.GetEquippedWeapon(), False, True )
	
EndFunction

Ammo Property aGetDressed  Auto  
