Scriptname BskMagicSlashHitScript extends activemagiceffect  

import Utility

Int index

Float Damage

Spell Property BskSpellDecap  auto

Sound Property BskFXSlashHit01 Auto
Sound Property BskFXSlashHit02 Auto
Sound Property BskFXSlashHit03 Auto
Sound Property BskFXSlashHit04 Auto

VisualEffect Property BskVisualSlashDecap Auto

Faction Property faction01  Auto  

Faction Property faction02  Auto  
Faction Property faction03  Auto
Faction Property faction04  Auto
Faction Property faction05  Auto


GlobalVariable Property BskDamageRate  Auto  

Event OnEffectStart(Actor Target, Actor Caster)

	Actor PlayerActor = Game.GetPlayer()

	if !Target.IsInFaction(faction01) && !Target.IsDead()

		if !Target.IsHostileToActor(PlayerActor)
			return
		endif

		if Caster.getav("oneHanded") as float > Caster.getav("twoHanded") as float
			Damage =  Caster.getav("oneHanded") as float
		else
			Damage =  Caster.getav("twoHanded") as float
		endif

		BskVisualSlashDecap.play(Target,3.0)

		Damage *= 0.5
		Damage *= BskDamageRate.getValue()


		if Target.getav("Health") as float < Damage && !Target.isEssential() && !((Target.GetBaseObject() as ActorBase).IsProtected()) && !Target.IsInFaction(faction02) && !Target.IsInFaction(faction03) && !Target.IsInFaction(faction04) && !Target.IsInFaction(faction05)

			if !Target.HasSpell(BskSpellDecap)

				Target.addSpell(BskSpellDecap, False)

			endif

		else

			Target.DamageAv("Health", Damage)

			index = RandomInt(1,4)

			if index == 1
				BskFXSlashHit01.play(Caster)  
			elseif index == 2
				BskFXSlashHit02.play(Caster)
			elseif index == 3
				BskFXSlashHit03.play(Caster)
			else
				BskFXSlashHit04.play(Caster)
			endif

			Target.StartCombat(Caster)

		endif

	endif

EndEvent
