Scriptname aaaTKCInitQuestScript extends Quest  


int forwardkey
int backkey
int leftkey
int rightkey
int sprintkey
int povkey
int attackkey
int blockkey

bool IsDodge = false
Actor player

float DTapStart
int DTapKey1 
int DTapKey2
int ReleasedKey


Event OnInit()

forwardkey	= Input.GetMappedKey("Forward")
backkey		= Input.GetMappedKey("Back")
leftkey		= Input.GetMappedKey("Strafe Left")
rightkey		= Input.GetMappedKey("Strafe Right")
sprintkey	= Input.GetMappedKey("Sprint")
povkey		= Input.GetMappedKey("Toggle POV")
attackkey	= Input.GetMappedKey("Right Attack/Block")
blockkey	= Input.GetMappedKey("Left Attack/Block")

RegisterForKey(forwardkey)		;W
RegisterForKey(leftkey)			;A
RegisterForKey(backkey)		;S
RegisterForKey(rightkey)		;D
RegisterForKey(sprintkey)		;SprintKey
RegisterForKey(34)				;gKey
RegisterForKey(povkey)
RegisterForKey(attackkey)
RegisterForKey(blockkey)

player = Game.GetPlayer()


EndEvent

Event OnKeyDown(Int KeyCode)

If (!Utility.IsInMenuMode()) && (!IsDodge)

;ダブルタップの場合
If DTapKey1 && (DTapKey1 == ReleasedKey) && (ReleasedKey == DTapKey2)
	if (DTapKey1 == backkey)
		Debug.notification("Dtapping")
	endif
EndIf

If (Utility.GetCurrentRealTime() - DTapStart) > 500
	DTapKey1		= 0
	DTapKey2		= 0
	ReleasedKey	= 0
	DTapStart		= 0
EndIf

If (!DTapKey1) 
	If KeyCode == backkey
		DTapKey1 = backkey
	EndIf
	If DTapKey1
		DTapStart = Utility.GetCurrentRealTime()	
	EndIf
ElseIf(!ReleasedKey)
	If (!KeyCode == DTapKey1)
		ReleasedKey = DTapKey1
	EndIf
ElseIf(!DTapKey2) 
	If (!KeyCode == DTapKey1)
		DTapKey2  = DTapKey1
	EndIf
EndIf




; スプリントキーの場合


   If input.IsKeyPressed(backkey)
	If KeyCode == 34
		DoDodgeAction("DodgeBack")
	EndIf
   Elseif input.IsKeyPressed(leftkey) 
	If KeyCode == 34
		DoDodgeAction("DodgeLeft")
	EndIf
   Elseif input.IsKeyPressed(rightkey)
	If KeyCode == 34
		DoDodgeAction("DodgeRight")
	EndIf
   Elseif input.IsKeyPressed(forwardkey)
	If KeyCode == 34
		DoForwardAction()
	EndIf	 
 

   EndIf

; 	ドッジキャンセルすると一人称視点で走りっぱなしになる対策
   if (KeyCode == attackkey || KeyCode == blockkey) && IsDodge &&  player.GetAnimationVariableInt("i1stPerson") == 1
	Input.Tapkey(sprintkey)
   Endif
   If KeyCode == povkey &&  !input.IsKeyPressed(sprintkey)
	Debug.SendAnimationEvent(player, "sprintStop")
   EndIf




EndIf

EndEvent

Function DoForwardAction()
		IsDodge = true
		Debug.SendAnimationEvent(player, "attackStop")
		Debug.SendAnimationEvent(player, "SneakStart")
		Debug.SendAnimationEvent(player, "SneakSprintStartRoll")
		Debug.SendAnimationEvent(player, "SneakStop")
		player.SetGhost()
		Utility.Wait(0.4)
		player.SetGhost(false)
		Utility.Wait(0.3)
		IsDodge = false

EndFunction

Function DoDodgeAction(String asDodge)
		IsDodge = true
		Debug.SendAnimationEvent(player, "attackStop")
		Debug.SendAnimationEvent(player, "sprintStart")
		Debug.SendAnimationEvent(player, "sprintStop")
		Debug.SendAnimationEvent(player, asDodge)
		player.SetGhost()
		Utility.Wait(0.4)
		player.SetGhost(false)
		Utility.Wait(0.3)
		IsDodge = false
EndFunction