ScriptName aaaKimachuuEnhanceArmor Extends ActiveMagicEffect

FormList Property aaaKimachuuEAFL Auto
Spell Property aaaKimachuuEASpell Auto

Int minValue = 10
Int maxValue = 20

Actor actSelf

Event OnEffectStart(Actor akTarget, Actor akCaster)
	actSelf = akTarget
EndEvent

Event OnDying(Actor akKiller)
	actSelf.BlockActivation()
	Utility.Wait(2.0)

	If actSelf.IsDisabled()
		actSelf.BlockActivation(False)
		actSelf.RemoveSpell(aaaKimachuuEASpell)
		actSelf = None
		Return
	EndIf

	Int iDiff = Utility.GetIniInt("iDifficulty:GamePlay")
	iDiff += 1

	Int iLevel = actSelf.GetLevel()
	Float[] fMag = new Float[3]
	Int[] iZero = new Int[3]
	MagicEffect[] meArray = new MagicEffect[3]
	Int[] iMask = new Int[10]
	Int[] iSlot = new Int[10]

	iMask[0] = 0x00000001
	iMask[1] = 0x00000002
	iMask[2] = 0x00000004
	iMask[3] = 0x00000008
	iMask[4] = 0x00000010
	iMask[5] = 0x00000020
	iMask[6] = 0x00000040
	iMask[7] = 0x00000080
	iMask[8] = 0x00000100
	iMask[9] = 0x00001000

	iSlot[0] = 30
	iSlot[1] = 31
	iSlot[2] = 32
	iSlot[3] = 33
	iSlot[4] = 34
	iSlot[5] = 35
	iSlot[6] = 36
	iSlot[7] = 37
	iSlot[8] = 38
	iSlot[9] = 42

	Int i = 0
	Int iSize = aaaKimachuuEAFL.GetSize()
	iSize -= 1

	Armor myArmor
	Enchantment myEnch

	While i <= 10
		Int x = 0
		Float fRank = 0.0
		While x <= 3
		 	fMag[x] = Utility.RandomInt((minValue * iDiff) + (iLevel *2), (maxValue * iDiff) + (iLevel *2))
		 	fRank += fMag[x]
		 	iZero[x] = 0
		 	Int iRnd = Utility.RandomInt(0, iSize)
		 	MagicEffect tempME = aaaKimachuuEAFL.GetAt(iRnd) As MagicEffect
		 	meArray[x] = tempME
		 	x += 1
		EndWhile

		myArmor = actSelf.GetEquippedArmorInSlot(iSlot[i])
		myEnch = myArmor.GetEnchantment()
		Int myEffects = myEnch.GetNumEffects()

		If !myArmor
			;empty
		ElseIf myEffects == 0
			WornObject.CreateEnchantment(actSelf, 0, iMask[i], 0.0, meArray, fMag, iZero, iZero)
			String strName = WornObject.GetDisplayName(actSelf, 0, iMask[i])
			WornObject.SetDisplayName(actSelf, 0, iMask[i], strName + " [Rank:" + fRank As Int + "]", True)
		EndIf
	 	i += 1
	EndWhile

	myArmor = None
	myEnch = None

	actSelf.BlockActivation(False)
	actSelf.RemoveSpell(aaaKimachuuEASpell)
	actSelf = None
EndEvent