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()
	
	If isFirstPerson ; Give some time for the camera to settle on switch to 3p
		Wait(0.5)
	endif
	
	Form[] equippedTorches = New Form[2]
	bool bUnequippingTorch = _00E_TorchControl.UnequipTorches(equippedTorches)
	if bUnequippingTorch
		; Give some time for torch unequip animations to settle
		Wait(0.25)
	endif

	_00E_EquipControl.SheatheWeapon(PlayerREF)
	Wait(0.5)
	
	Debug.SendAnimationEvent(PlayerREF, "IdleSmelterEnter")
	Wait(5.0)

	; Stop digging
	Debug.SendAnimationEvent(PlayerREF, "IdleForceDefaultState")
	
	_00E_TorchControl.ReequipTorches(equippedTorches)
	Wait(1.0)
	
	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