Scriptname _00E_A2_PrimalForceSC extends activemagiceffect  

Import _00E_TalentLibrary
Import Debug

;=====================================================================================
;              							EVENTS                					 
;=====================================================================================

Event OnEffectStart(Actor akTarget, Actor akCaster)

	AdjustSpells()
	_00E_A2_PrimalForceIMOD.Apply()
	_00E_A2_PrimalForceThunderM.Play(PlayerREF)
	PlaceMarker = PlayerREF.PlaceAtMe(XMarker, 1)
	PlaceMarker.MoveTo(PlayerREF, 0.0, 0.0, 50.0)
	PlaceMarker.PlaceAtMe(_00E_A2_PrimalForceExp)

	Utility.Wait(0.125)

	If PlayerREF.HasSpell(_00E_A2_EyeOfTheStormAb)

		if _00E_Synergy_PrimalForceEyeOfTheStorm.GetValueInt() == 0
			_00E_Synergy_PrimalForceEyeOfTheStorm.SetValueInt(1)
			_00E_PlayerFunctions.GetSkillControl().ShowSynergyMessage()
		EndIf

		PlayerREF.DispelSpell(_00E_A2_EyeOfTheStormSP)
		_00E_A2_PrimalForceSynergyDMGEnch.SetNthEffectMagnitude(0, (fDamage/0.4))
		Game.ShakeCamera()
		PlayerREF.PlaceAtMe(_00E_A2_PrimalForceSynergyExplosion)

	ElseIf _00E_A1_OnslaughtSynergyTimer.GetValueInt() == 1

		if _00E_Synergy_OnslaughtPrimalForce.GetValueInt() == 0
			_00E_Synergy_OnslaughtPrimalForce.SetValueInt(1)
			_00E_PlayerFunctions.GetSkillControl().ShowSynergyMessage()
		EndIf

		_00E_A1_OnslaughtSynergyTimer.SetValueInt(0)

	EndIf
	
	Utility.Wait(1)
	
	PlayerREF.KnockAreaEffect(1, 512)

EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	
	PlaceMarker.Delete()

EndEvent

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

Function AdjustSpells()

	int iIndex = GetPlayerTalentLevel(_00E_Class_Rage_P09b_Talent_PrimalForce, _00E_Class_Rage_P09b_Talent_PrimalForce2, _00E_Class_Rage_P09b_Talent_PrimalForce3)
	fDamage = _00E_A2_PrimalForceSP.GetNthEffectMagnitude(iIndex)
	fExtraDamage = _00E_A2_PrimalForceSP.GetNthEffectMagnitude(iIndex + 3)
	_00E_A2_PrimalForceExtraDMGEnch.SetNthEffectMagnitude(0, fExtraDamage)
	_00E_A2_PrimalForceExtraDMGEnch.SetNthEffectMagnitude(1, fDamage)

EndFunction

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

ObjectReference PlaceMarker

float fDamage
float fExtraDamage

GlobalVariable Property _00E_Synergy_PrimalForceEyeOfTheStorm Auto Hidden
GlobalVariable Property _00E_Synergy_OnslaughtPrimalForce Auto Hidden
GlobalVariable Property _00E_A1_OnslaughtSynergyTimer Auto Hidden

Actor Property PlayerREF Auto

Enchantment Property _00E_A2_PrimalForceExtraDMGEnch Auto
Enchantment Property _00E_A2_PrimalForceSynergyDMGEnch Auto

Spell Property _00E_A2_PrimalForceSP Auto
Spell Property _00E_A2_EyeOfTheStormAb Auto
Spell Property _00E_A2_EyeOfTheStormSP Auto

Static Property XMarker Auto

Sound Property _00E_A2_PrimalForceThunderM Auto

Explosion Property _00E_A2_PrimalForceExp Auto
Explosion Property _00E_A2_PrimalForceSynergyExplosion Auto

Perk Property _00E_Class_Rage_P09b_Talent_PrimalForce Auto
Perk Property _00E_Class_Rage_P09b_Talent_PrimalForce2 Auto
Perk Property _00E_Class_Rage_P09b_Talent_PrimalForce3 Auto

ImageSpaceModifier Property _00E_A2_PrimalForceIMOD Auto