ScriptName VampireEnthrall extends ActiveMagicEffect
{Permanently Enthrall a NPC and Turn Them Into Vampire Cattle}

Keyword Property VampireHunterKeyword Auto
ReferenceAlias Property VampireEnthrallAlias Auto
Spell Property VampireEnthrallSpell Auto
PlayerVampireQuestScript Property PlayerVampireQuest  Auto
GlobalVariable Property EnableVampireBloodPoints Auto
GlobalVariable Property VampireBloodPoints Auto
Sound Property UIHealthHeartbeatALP Auto
Armor Property ClothesPrisonerTunic Auto
Armor Property ClothesPrisonerShoes Auto
ImageSpaceModifier Property VampireEnthrallCrossFade  Auto 
Faction Property DLC1ThrallFaction Auto
Faction Property PotentialFollowerFaction Auto
Faction Property CurrentFollowerFaction Auto
Idle Property pa_DLC1SeranaHoldsVyrthur Auto
Idle Property IdleSearchBody Auto
Sound Property NPCVampireLordFeedSound Auto
Sound Property VOCShoutFXAnimalAllegianceSound Auto
Sound Property MAGAltarsBlessingFireA2DSound Auto
MagicEffect Property InfluenceAggDownFFAimed Auto

	
Event OnEffectStart(Actor akEnthrallTarget, Actor Caster)

		Float TargetWillpower = akEnthrallTarget.GetAV("Health") + akEnthrallTarget.GetAV("Stamina")
		Float PlayerWillpower = Game.GetPlayer().GetAV("Health") + Game.GetPlayer().GetAV("Stamina")
		
		Int EnthrallInThirdPerson = 1
		
		If akEnthrallTarget.HasKeyword(VampireHunterKeyword) == False && (akEnthrallTarget.HasMagicEffect(InfluenceAggDownFFAimed) == True || akEnthrallTarget.IsBleedingOut() == True) ;&& (TargetWillpower <= PlayerWillpower && akEnthrallTarget.IsPlayerTeammate() == False) 

			akEnthrallTarget.StopCombat()
			
			;If EnableVampireBloodPoints.GetValue() == 10000
			;	PlayerVampireQuest.VampireBloodPoints(40)
			;EndIf			
			
			Int instanceID1 = UIHealthHeartbeatALP.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID1, 1.0)			
			
			utility.wait(1.0)
			
			If Game.GetCameraState() == 0
				EnthrallInThirdPerson = 0
			EndIf
			
			If EnthrallInThirdPerson == 0
				Game.ForceThirdPerson()
			EndIf				
			
			Caster.StopCombat()				
			Game.DisablePlayerControls(false, true, false, false, false, false)
			Utility.Wait(0.5)
			
			Game.GetPlayer().PlayIdleWithTarget(pa_DLC1SeranaHoldsVyrthur, akEnthrallTarget)
			Utility.Wait(1.0)
			Int instanceID2 = NPCVampireLordFeedSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID2, 0.5)
			VampireEnthrallCrossFade.applyCrossFade(1.0)			
			Utility.Wait(1.5)
			Int instanceID3 = NPCVampireLordFeedSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID3, 1.8)
			Utility.Wait(1.0)
			Int instanceID4 = VOCShoutFXAnimalAllegianceSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID4, 1.5)			
			Utility.Wait(1.0)
			Int instanceID5 = MAGAltarsBlessingFireA2DSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID5, 2.0)
			Utility.Wait(0.1)			
			Game.SetPlayerAIDriven(False)		
			
			akEnthrallTarget.RemoveFromAllFactions()
			akEnthrallTarget.UnEquipAll()
			akEnthrallTarget.RemoveAllItems(akTransferTo = Game.GetPlayer())

			VampireEnthrallAlias.ForceRefTo(akEnthrallTarget)

			akEnthrallTarget.EquipItem(ClothesPrisonerTunic, true)
			akEnthrallTarget.EquipItem(ClothesPrisonerShoes, true)

			akEnthrallTarget.SetActorValue("Assistance", 0)
			akEnthrallTarget.SetActorValue("Aggression", 0)
			akEnthrallTarget.SetActorValue("Confidence", 0)
			akEnthrallTarget.SetActorValue("Morality", 0)			
			
			akEnthrallTarget.StopCombat()			
			
			Utility.Wait(3.0)
			Debug.SendAnimationEvent(Game.GetPlayer(), "IdleForceDefaultState")
			Game.EnablePlayerControls()
			Utility.Wait(0.5)
			If EnthrallInThirdPerson == 0
				Game.ForceFirstPerson()
			EndIf				
			imageSpaceModifier.removeCrossFade()
			Sound.StopInstance(instanceID1)			
		
			If akEnthrallTarget.IsInFaction(CurrentFollowerFaction) == True && akEnthrallTarget.GetFactionRank(CurrentFollowerFaction) >= 0
				akEnthrallTarget.AddtoFaction(DLC1ThrallFaction)	
			Else
				akEnthrallTarget.AddtoFaction(DLC1ThrallFaction)	
				akEnthrallTarget.AddtoFaction(PotentialFollowerFaction)
				akEnthrallTarget.SetFactionRank(PotentialFollowerFaction, 0)
				akEnthrallTarget.AddtoFaction(CurrentFollowerFaction)
				akEnthrallTarget.SetFactionRank(CurrentFollowerFaction, -1)	
			EndIf
			
			akEnthrallTarget.SetRelationshipRank(Game.GetPlayer(), 4)
			Game.GetPlayer().SetRelationshipRank(akEnthrallTarget, 4)			
		
			akEnthrallTarget.StopCombat()		
		
		ElseIf akEnthrallTarget.HasKeyword(VampireHunterKeyword) == False && akEnthrallTarget.GetSleepState() == 3
		
			akEnthrallTarget.StopCombat()
			
			;If EnableVampireBloodPoints.GetValue() == 10000
			;	PlayerVampireQuest.VampireBloodPoints(40)
			;EndIf			
			
			Int instanceID1 = UIHealthHeartbeatALP.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID1, 1.0)			
			
			utility.wait(1.0)
			
			If Game.GetCameraState() == 0
				EnthrallInThirdPerson = 0
			EndIf
			
			If EnthrallInThirdPerson == 0
				Game.ForceThirdPerson()
			EndIf				
			
			Caster.StopCombat()				
			Game.DisablePlayerControls(false, true, false, false, false, false)
			Utility.Wait(0.5)
			
			Game.GetPlayer().PlayIdleWithTarget(IdleSearchBody, akEnthrallTarget)
			Utility.Wait(1.0)
			Int instanceID2 = NPCVampireLordFeedSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID2, 0.5)
			VampireEnthrallCrossFade.applyCrossFade(1.0)			
			Utility.Wait(1.5)
			Int instanceID3 = NPCVampireLordFeedSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID3, 1.8)
			Utility.Wait(1.0)
			Int instanceID4 = VOCShoutFXAnimalAllegianceSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID4, 2.0)			
			Utility.Wait(1.0)
			Int instanceID5 = MAGAltarsBlessingFireA2DSound.Play(Game.GetPlayer())
			Sound.SetInstanceVolume(instanceID5, 2.0)
			Utility.Wait(0.1)			
			Game.SetPlayerAIDriven(False)		
			
			akEnthrallTarget.RemoveFromAllFactions()
			akEnthrallTarget.UnEquipAll()
			akEnthrallTarget.RemoveAllItems(akTransferTo = Game.GetPlayer())

			VampireEnthrallAlias.ForceRefTo(akEnthrallTarget)

			akEnthrallTarget.EquipItem(ClothesPrisonerTunic, true)
			akEnthrallTarget.EquipItem(ClothesPrisonerShoes, true)

			akEnthrallTarget.SetActorValue("Assistance", 0)
			akEnthrallTarget.SetActorValue("Aggression", 0)
			akEnthrallTarget.SetActorValue("Confidence", 0)
			akEnthrallTarget.SetActorValue("Morality", 0)			
			
			akEnthrallTarget.StopCombat()			
			
			Utility.Wait(3.0)
			Debug.SendAnimationEvent(Game.GetPlayer(), "IdleForceDefaultState")
			Game.EnablePlayerControls()
			Utility.Wait(0.5)
			If EnthrallInThirdPerson == 0
				Game.ForceFirstPerson()
			EndIf				
			imageSpaceModifier.removeCrossFade()
			Sound.StopInstance(instanceID1)			
		
			If akEnthrallTarget.IsInFaction(CurrentFollowerFaction) == True && akEnthrallTarget.GetFactionRank(CurrentFollowerFaction) >= 0
				akEnthrallTarget.AddtoFaction(DLC1ThrallFaction)	
			Else
				akEnthrallTarget.AddtoFaction(DLC1ThrallFaction)	
				akEnthrallTarget.AddtoFaction(PotentialFollowerFaction)
				akEnthrallTarget.SetFactionRank(PotentialFollowerFaction, 0)
				akEnthrallTarget.AddtoFaction(CurrentFollowerFaction)
				akEnthrallTarget.SetFactionRank(CurrentFollowerFaction, -1)	
			EndIf
			
			akEnthrallTarget.SetRelationshipRank(Game.GetPlayer(), 4)
			Game.GetPlayer().SetRelationshipRank(akEnthrallTarget, 4)			
		
			akEnthrallTarget.StopCombat()		
		
		ElseIf akEnthrallTarget.HasKeyword(VampireHunterKeyword) == True ;(TargetWillpower > PlayerWillpower)
		  
			akEnthrallTarget.DispelSpell(VampireEnthrallSpell)
			Utility.Wait(1.0)
			akEnthrallTarget.StartCombat(Game.GetPlayer())
						
		EndIf		
		

EndEvent



Event OnEffectFinish(Actor akEnthrallTarget, Actor Caster)

	
	
EndEvent
