Scriptname _00E_DigControl extends Quest Hidden 

import Utility

bool function Dig()

	; Play the mauling animation in werewolf form
	if PlayerREF.GetRace() == _00E_Theriantrophist_PlayerWerewolfRace
		if PlayerREF.IsInCombat()
			_00E_TreasureMarkerScript_sCannotDigInCombat.Show()
			return false
		endif
		Game.DisablePlayerControls(true, true, true, true, true, true, true, true)
		Debug.SendAnimationEvent(PlayerREF, "pa_KillWerewolfPairedMaulingWithHuman")
		Wait(4.8)
		Game.EnablePlayerControls()
		return true
	endif

	if PlayerREF.GetItemCount(ShovelKeyword) == 0
		_00E_TreasureMarkerScript_sShovelNeeded.Show()
		return false
	endif
	
	if PlayerREF.IsInCombat()
		_00E_TreasureMarkerScript_sCannotDigInCombat.Show()
		return false
	endif

	Game.DisablePlayerControls(true, true, true, true, true, true, true, true)
	Game.SetPlayerAIDriven()
	
	bool isFirstPerson = PlayerREF.GetAnimationVariableBool("IsFirstPerson")

	; Start digging
	Game.ForceThirdPerson()
	
	Form[] equippedTorches = New Form[2]
	Bool torchesUnequipping = _00E_TorchControl.UnequipTorches(equippedTorches)

	If PlayerREF.IsWeaponDrawn() ; Sheathe the weapon
		PlayerREF.PlayIdle(DefaultSheathe)
		Wait(2)
	ElseIf isFirstPerson ; Give some time for the camera to settle on switch to 3p
		Wait(0.5)
	ElseIf torchesUnequipping ; Give some time for torch unequip animations to settle
		Wait(0.25)
	EndIf

	Debug.SendAnimationEvent(PlayerREF, "IdleSmelterEnter")
	Wait(5.0)

	; Stop digging
	Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState")
	
	_00E_TorchControl.ReequipTorches(equippedTorches)
	Wait(1)
	
	Game.SetPlayerAIDriven(false)
	Game.EnablePlayerControls()
	
	If isFirstPerson
		Game.ForceFirstPerson()
	EndIf
	
	return true

endfunction

Actor Property PlayerRef  Auto  

Message Property _00E_TreasureMarkerScript_sCannotDigInCombat  Auto  
Message Property _00E_TreasureMarkerScript_sShovelNeeded  Auto  

Keyword Property ShovelKeyword  Auto  

Idle Property DefaultSheathe  Auto  

Race Property _00E_Theriantrophist_PlayerWerewolfRace  Auto