Scriptname _00E_FS_Affinity_BruteSC extends activemagiceffect  

Int Property MaxDamageBoosts = 5 Autoreadonly Hidden
{each kill will increase the damage boost until this count of kills is reached}
Float Property DamageBoostPercentagePerKill = 5 Autoreadonly Hidden
{the percentage of the base damage which each kill will add as a boost to the dealt damage}

_FS_TheriantrophistControlQuest Property controlQuest Auto
_00E_Theriantrophist_WolfAttributes Property wolfAttributes Auto
Spell Property _00E_FS_Affinity_AbBrute_AlreadyDeadSP Auto
MagicEffect Property _00E_FS_Affinity_AbBrute_AlreadyDead Auto

Sound Property _00E_FS_Affinity_Brute_Sound_DamageBoost1 Auto
Sound Property _00E_FS_Affinity_Brute_Sound_DamageBoost2 Auto
Sound Property _00E_FS_Affinity_Brute_Sound_DamageBoost3 Auto
Sound Property _00E_FS_Affinity_Brute_Sound_DamageBoost4 Auto
Sound Property _00E_FS_Affinity_Brute_Sound_DamageBoostReset Auto

int boostCount

Event OnEffectStart(Actor akTarget, Actor akCaster)
	controlQuest.GetAffinityControl().RegisterForBruteAffinityEvents(self)
EndEvent

Event OnEffectFinish(Actor akTarget, Actor akCaster)
	controlQuest.GetAffinityControl().UnRegisterForBruteAffinityEvents()
EndEvent

Function OnWolfCombatHit(Actor target)
	if (!target.HasMagicEffect(_00E_FS_Affinity_AbBrute_AlreadyDead)) && target.isDead()
		_00E_FS_Affinity_AbBrute_AlreadyDeadSP.Cast(target, target)
		boostCount += 1
		if (boostCount > MaxDamageBoosts)
			boostCount = MaxDamageBoosts
		EndIf
		self._UpdateBoost()
	EndIf
	RegisterForSingleUpdate(7)
EndFunction
		
Function _UpdateBoost()
	wolfAttributes.SetWolfTempWolfUnarmedDamageMod(wolfAttributes.GetWolfUnarmedDamage() * boostCount * DamageBoostPercentagePerKill / 100)
	_PlaySound()
EndFunction

Event OnUpdate()
	boostCount = 0
	_UpdateBoost()
EndEvent

Function _PlaySound()
	if (boostCount == 1)
		_00E_FS_Affinity_Brute_Sound_DamageBoost1.Play(self.getTargetActor())
	Elseif (boostCount == 2)
		_00E_FS_Affinity_Brute_Sound_DamageBoost2.Play(self.getTargetActor())
	Elseif (boostCount == 3)
		_00E_FS_Affinity_Brute_Sound_DamageBoost3.Play(self.getTargetActor())
	Elseif (boostCount == 4)
		_00E_FS_Affinity_Brute_Sound_DamageBoost4.Play(self.getTargetActor())
	Else
		_00E_FS_Affinity_Brute_Sound_DamageBoostReset.Play(self.getTargetActor())
	EndIf
EndFunction