Scriptname chymikum_lycanthropist extends activemagiceffect  

bool Function calculateTolerance(float Magnitude, Actor akTarget)
	float tolerance = 0
	if !akTarget.hasPerk(thickBlood)
		tolerance = 35	;*10
	elseif !akTarget.hasPerk(viciouskBlood)
		tolerance = 50	;*10
	elseif !akTarget.hasPerk(strongBlood)
		tolerance = 85	;*10
	elseif !akTarget.hasPerk(darkBlood)
		tolerance = 100	;*10
	elseif !akTarget.hasPerk(blackBlood)
		tolerance = 150	;*10
	endif
	
	tolerance -= actualMagnitude.GetValue()

	if Magnitude > tolerance
		return false
	else
		return true
	endif

endfunction

Event OnEffectStart(Actor akTarget, Actor akCaster)
	Float Magnitude = self.GetMagnitude()
	Bool canReachEffect = true 

	canReachEffect = calculateTolerance(Magnitude, akTarget)

;	Debug.Messagebox((akCaster as Actor).hasMagicEffect(self.getbaseobject())+" power: "+Magnitude+" vs "+actualLimit.GetValue()+" / "+maxLimit.GetValue() + " vs "+akTarget.hasPerk(thickBlood))
		
	if !canReachEffect
		self.Dispel()
		Debug.Messagebox("hash")
		dealDmg(akTarget, Magnitude)
		tooStrongPotionM.Show()
	else
		float tempMag = actualMagnitude.GetValue() + Magnitude
		actualMagnitude.SetValue(tempMag)
		lycanthDummy.Additem(lycanthIngredent, (Magnitude as Int), true)	
	endif
endEvent

Function dealDmg(Actor akTarget, float Magnitude)
	akTarget.DamageActorValue("Health", Magnitude*2)
endFunction

Event OnMagicEffectApply(ObjectReference akCaster, MagicEffect akEffect)
	if selfMagic == akEffect
		dealDmg((akCaster as Actor),  lycanthDummy.GetItemCount(lycanthIngredent ))
		samePotionsM.Show()
	endif	
EndEvent



Event OnEffectFinish(Actor akTarget, Actor akCaster)
;	Debug.Messagebox("removing")
	float a = actualLimit.GetValue() - 1
	actualLimit.SetValue(a)
	lycanthDummy.RemoveItem(lycanthIngredent, lycanthDummy.GetItemCount(lycanthIngredent ))
endEvent

Perk Property thickBlood  Auto  
Perk Property viciouskBlood  Auto  
Perk Property strongBlood  Auto  
Perk Property darkBlood  Auto  
Perk Property blackBlood  Auto  

GlobalVariable Property actualLimit  Auto  
GlobalVariable Property maxLimit  Auto  

Message Property samePotionsM  Auto  
Message Property tooManyPotionsM  Auto  
Message Property tooStrongPotionM  Auto  

GlobalVariable Property actualMagnitude  Auto  

Actor Property lycanthDummy Auto
Ingredient Property lycanthIngredent Auto 

MagicEffect Property selfMagic  Auto