Scriptname VampireTolanScript extends activemagiceffect

Actor Property VampireVigilantTolan Auto
Spell Property VampireTolanInvisibility Auto
GlobalVariable Property VampireTolanAttacks Auto
GlobalVariable Property VampireTolanGetsCareless Auto

EVENT OnEffectStart(Actor akTarget, Actor akCaster)

	VampireVigilantTolan = akTarget

	VampireTolanAttacks.SetValue((VampireTolanAttacks.GetValue()+1))	
	VampireTolanGetsCareless.SetValue(Utility.RandomInt(3,4))
	
	Utility.Wait(0.5)
	
	Float PlayerHealth = Game.GetPlayer().GetBaseActorValue("Health")
	Float VampireVigilantTolanHealth = PlayerHealth*1.2
	If VampireTolanAttacks.GetValue() == 1
		VampireVigilantTolanHealth = PlayerHealth*1.3
	ElseIf VampireTolanAttacks.GetValue() == 2
		VampireVigilantTolanHealth = PlayerHealth*1.4
	ElseIf VampireTolanAttacks.GetValue() == 3
		VampireVigilantTolanHealth = PlayerHealth*1.5	
	ElseIf VampireTolanAttacks.GetValue() >= 4
		VampireVigilantTolanHealth = PlayerHealth*1.6
	EndIf	
	VampireVigilantTolan.SetActorValue("Health", VampireVigilantTolanHealth)

	Float PlayerMagicka = Game.GetPlayer().GetBaseActorValue("Magicka")
	VampireVigilantTolan.SetActorValue("Magicka", PlayerMagicka)

	Float PlayerStamina = Game.GetPlayer().GetBaseActorValue("Stamina")
	VampireVigilantTolan.SetActorValue("Stamina", PlayerStamina)	
	
	VampireVigilantTolan.SetActorValue("Sneak", 100)
	
	Float Player1Hand = (Game.GetPlayer().GetActorValue("OneHanded")*1.1)
	VampireVigilantTolan.SetActorValue("OneHanded", Player1Hand)
	
	Float Player2Hand= (Game.GetPlayer().GetActorValue("TwoHanded")*1.2)
	VampireVigilantTolan.SetActorValue("TwoHanded", Player2Hand)

	Float PlayerMarksman = (Game.GetPlayer().GetActorValue("Marksman")*1.2)
	VampireVigilantTolan.SetActorValue("Marksman", PlayerMarksman)
	
	Float PlayerBlock = (Game.GetPlayer().GetActorValue("Block")*1.2)
	VampireVigilantTolan.SetActorValue("Block", PlayerBlock)
	
	Float PlayerDamageResist = (Game.GetPlayer().GetActorValue("DamageResist")*1.5)
	VampireVigilantTolan.ForceActorValue("DamageResist", PlayerDamageResist)

	Game.GetPlayer().SetAV("Variable01", 0)		
	
	RegisterForUpdate(2)
	
EndEvent


Event OnUpdate()

	If VampireTolanAttacks.GetValue() >= VampireTolanGetsCareless.GetValue()
	
		VampireTolanAttacks.SetValue(10000)
		VampireVigilantTolan.SetActorValue("Aggression", 1)
		VampireVigilantTolan.SetActorValue("Confidence", 4)
		ActorBase VampireVigilantTolanBase = VampireVigilantTolan.GetBaseObject() as ActorBase		
		VampireVigilantTolanBase.SetEssential(False)		
		UnregisterforUpdate()
		Game.GetPlayer().SetAV("Variable01", 10000)			
		VampireTolanAttacks.SetValue(10000)
	
	ElseIf VampireTolanAttacks.GetValue() < VampireTolanGetsCareless.GetValue()
	
		If VampireVigilantTolan.GetActorValuePercentage("Health") <= 0.20
			UnregisterforUpdate()
			VampireVigilantTolan.StopCombat()		
			VampireVigilantTolan.SetAV("Confidence", 0)
			Utility.Wait(2.0)		
			VampireTolanInvisibility.Cast(VampireVigilantTolan, VampireVigilantTolan)
			Utility.Wait(2.0)		
			VampireVigilantTolan.Disable(True)
			Utility.Wait(1.0)		
			VampireVigilantTolan.Delete()
		EndIf
		
	EndIf	

	If VampireTolanAttacks.GetValue() >= 10000
		UnregisterforUpdate()	
	EndIf
	
EndEvent


Event OnEffectFinish(Actor akTarget, Actor akCaster)

		UnregisterforUpdate()
		;If VampireTolanAttacks.GetValue() < 10000
		;	Game.GetPlayer().SetAV("Variable01", 0)
		;ElseIf VampireTolanAttacks.GetValue() >= 10000
		;	Game.GetPlayer().SetAV("Variable01", 10000)
		;EndIf		
		
EndEvent

Event OnUnload()

		UnregisterforUpdate()
		If VampireTolanAttacks.GetValue() < 10000
			Game.GetPlayer().SetAV("Variable01", 0)
		ElseIf VampireTolanAttacks.GetValue() >= 10000
			Game.GetPlayer().SetAV("Variable01", 10000)
		EndIf	
		
EndEvent
