ScriptName aaaKimachuuEndOfTheCentury Extends ActiveMagicEffect

Actor property PlayerRef auto
Faction property f01 auto
Outfit property o01 auto
Spell property s01 auto

Actor EnemyRef

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Float fTime = Utility.RandomFloat(1.0, 2.0)
	Utility.Wait(fTime)

	If akTarget.IsChild()
		akTarget.RemoveSpell(s01)
		akTarget.Disable()
		akTarget.Delete()
		Return
	EndIf

	Int intFormID = akTarget.GetFormID()
	Int intOrder = Math.RightShift(intFormID, 24)

    If intOrder == 0xFF
        ;empty
    Else
    	ActorBase EnemyBase = akTarget.GetActorBase()
    	EnemyBase.SetEssential(false)
		EnemyRef = akTarget.PlaceActorAtMe(akTarget.GetActorBase())
		EnemyRef.SetOutfit(o01)
		EnemyRef.RemoveFromAllFactions()
		EnemyRef.SetRelationshipRank(PlayerRef, -3)
		EnemyRef.SetAV("Aggression", 2)
		EnemyRef.SetAV("Confidence", 3)
		EnemyRef.AddToFaction(f01)
		akTarget.Disable()
		akTarget.Delete()
    EndIf
EndEvent

Event OnDeath(Actor akKiller)
	EnemyRef.RemoveSpell(s01)
	EnemyRef.Delete()
	EnemyRef = None
EndEvent
