Scriptname _00E_NQ29_Functions extends Quest  

;=====================================================================================
;              							FUNCTIONS                    					 
;=====================================================================================

Function SpawnAshWidow()

	_00E_MQ11a_MagicAnomalyScreamAM.Play(PlayerREF)
	Game.ShakeCamera()
	NQ29_Boss_AshWidow_REF.Enable()
	Utility.Wait(1)
	ObjectReference widowFurniture = NQ29_Boss_AshWidow_REF.GetLinkedRef()
	If widowFurniture
		; This seems to fix the occasions when the widow gets stuck underground/invisible
		NQ29_Boss_AshWidow_REF.MoveTo(widowFurniture)
	EndIf	
	NQ29_Boss_AshWidow_REF.Activate(PlayerREF)
	NQ29_Boss_AshWidow_REF.PlaceAtMe(FireballStormAlduinDeathExplosion)
	NQ29_Boss_AshWidow_REF.PlaceAtMe(FireStormExplosion02)
	NQ29_Boss_AshWidow_REF.KnockAreaEffect(1, 512)
EndFunction

Float Property MIN_WEATHER_PERIOD = 15.0 AutoReadOnly ; In seconds
Bool bWeatherIsSet = False
Bool bWeatherReleasePending = False
Bool bWeatherReleaseAllowed = False

Function AshWidowSetWeather()

	If bWeatherIsSet == False
		bWeatherIsSet = True
		bWeatherReleasePending = False
		bWeatherReleaseAllowed = False
		SkyrimDA02Weather.SetActive(True)
		RegisterForSingleUpdate(MIN_WEATHER_PERIOD)
	EndIf

EndFunction

Function AshWidowReleaseWeather()
	If bWeatherIsSet
		bWeatherReleasePending = True
		_AshWidowTryReleaseWeather()
	EndIf
EndFunction

Function _AshWidowTryReleaseWeather()
	If bWeatherIsSet && bWeatherReleaseAllowed && bWeatherReleasePending
		bWeatherIsSet = False
		bWeatherReleaseAllowed = False
		bWeatherReleasePending = False
		Weather.ReleaseOverride()
	EndIf
EndFunction

Event OnUpdate()
	bWeatherReleaseAllowed = True
	_AshWidowTryReleaseWeather()
EndEvent

Function Finish()

	Levelsystem.GiveEP(5000)
	If _00E_AchievementsEnabled.getValueInt() == 1
		Game.UnlockAchievement("END_MYTHS_01")
	EndIf
	
EndFunction

;=====================================================================================
;              							PROPERTIES                    					 
;=====================================================================================

_00E_QuestFunctions Property Levelsystem Auto

Actor Property PlayerREF Auto
Actor Property NQ29_Boss_AshWidow_REF Auto

Explosion Property FireballStormAlduinDeathExplosion Auto
Explosion Property FireStormExplosion02 Auto

GlobalVariable Property _00E_AchievementsEnabled Auto

Sound Property _00E_MQ11a_MagicAnomalyScreamAM Auto

Weather Property SkyrimDA02Weather Auto