Scriptname _00E_FS_Affinity_Scourge_TitanSC extends activemagiceffect  

_FS_TheriantrophistControlQuest Property TheriantrophistControlQuest Auto
_00E_Theriantrophist_WolfAttributes Property WolfAttributes Auto
Message Property _00E_Theriantrophist_NotInWolfForm Auto
Explosion Property ExplosionParalyzeMass01 Auto

ImageSpaceModifier Property _00E_FS_Theriantrophist_ScourgeIMOD Auto

EffectShader Property _00E_A1_RocksolidFXS Auto

Sound Property MAGPowerRacialDarkElfAncestorsWrathFire2DM Auto
Sound Property NPCWerewolfFeedingM Auto

Shout Property _00E_Affinity_ScourgeOfTheWilds_Titan Auto

Float Property HealthBoost = 80 Autoreadonly Hidden
Float Property StaminaBoost = 100 Autoreadonly Hidden
Float Property ArmorBoost = 40 Autoreadonly Hidden

Event OnEffectStart(Actor akTarget, Actor akCaster)
	If TheriantrophistControlQuest.IsTransformed()
		_StartTitanForm(akTarget)
	Else
		Dispel()
		_00E_Theriantrophist_NotInWolfForm.Show()
		(akCaster as _00E_Game_TalentControlSC).SetTalentRecoveryTime(_00E_Affinity_ScourgeOfTheWilds_Titan, 0)
	EndIf
Endevent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	If TheriantrophistControlQuest.IsTransformed()
		_EndTitanForm(akTarget)
	EndIf
Endevent

Function _StartTitanForm(Actor player)
	
	_00E_A1_RocksolidFXS.Play(Player)
	WolfAttributes.ModWolfHealth(HealthBoost)
	WolfAttributes.ModWolfStamina(HealthBoost)
	WolfAttributes.ModWolfDamageResist(ArmorBoost)
	
	If (player.IsInInterior())
		TransformTo(Player, 1.2)
	Else
		TransformTo(Player, 1.4)
	EndIf
	
EndFunction

Function TransformTo(Actor player, float fSize)

	_00E_FS_Theriantrophist_ScourgeIMOD.Apply()
	Game.ShakeCamera(afStrength = 0.75, afDuration = 7.0)
	NPCWerewolfFeedingM.Play(Player)
	Game.DisablePlayerControls()
	Player.GetActorBase().SetInvulnerable(True)
	
	If fSize > player.getScale()
		
		while player.getScale() < fSize
			player.setscale(player.getScale() + 0.01)
			; Utility.Wait(0.025)
		endwhile
		
	Else
		while player.getScale() > fSize
			player.setscale(player.getScale() - 0.01)
			; Utility.Wait(0.025)
		endwhile
		
	EndIf
	
	Game.EnablePlayerControls()
	Player.GetActorBase().SetInvulnerable(False)
	MAGPowerRacialDarkElfAncestorsWrathFire2DM.Play(Player)
	Game.ShakeCamera()

EndFunction

Function _EndTitanForm(Actor player)
	
	_00E_A1_RocksolidFXS.Stop(Player)
	TransformTo(Player, 1.0)
	WolfAttributes.ModWolfHealth(-HealthBoost)
	WolfAttributes.ModWolfStamina(-HealthBoost)
	WolfAttributes.ModWolfDamageResist(-ArmorBoost)
	
EndFunction