Scriptname AlternativeNeeds_ScriptNEW extends ReferenceAlias  

Spell Property Tired_Time Auto
Spell Property Thirsty_Time Auto
Spell Property Hungry_Time Auto

		Actor Property PlayerRef Auto
		Import GrimyToolsPluginScript
		GlobalVariable Property Timescale Auto

Spell Property Hungry Auto
Spell Property Thirsty Auto
Spell Property Tired Auto


	GlobalVariable Property TiredStart Auto
	GlobalVariable Property HungryStart Auto
	GlobalVariable Property ThirstyStart Auto

	Int Property Var1 Auto

FormList Property ITMFoodSound Auto
Potion Property FoodItem Auto

	MiscObject Property WineBottle02AEmpty Auto

		Keyword Property Vampire Auto
		Race Property WerewolfBeastRace Auto

Spell property HealthDecay Auto

	Spell Property VampireFeedNeed Auto

Spell Property IsDaedra Auto

	Potion Property BloodPotion_ Auto
	Potion Property DLC1BloodPotion Auto


;============HOUR TO SECOND FUNCTION================
Int Function HourToSecond(Int Var1, GlobalVariable GlobalVar1)
	Var1 = GlobalVar1.GetValueInt() * 60 * 60
		return Var1
endFunction
;===============================================

Function SetDurationOfNeeds()

;==============COUNTDOWN TO GETTING TIRED============================
	SetSpellNthMagicEffectDuration(Tired_Time, (HourToSecond(Var1, TiredStart)/Timescale.GetValueInt()) as int, 0)
	Tired_Time.Cast(PlayerRef,PlayerRef)


;===============COUNTDOWN TO GETTING THIRSTY=========================
	SetSpellNthMagicEffectDuration(Thirsty_Time, (HourToSecond(Var1, ThirstyStart)/Timescale.GetValueInt()) as int, 0)
	Thirsty_Time.Cast(PlayerRef,PlayerRef)


;================COUNTDOWN TO GETTING HUNGRY=========================
	SetSpellNthMagicEffectDuration(Hungry_Time, (HourToSecond(Var1, HungryStart)/Timescale.GetValueInt()) as int, 0)
	Hungry_Time.Cast(PlayerRef,PlayerRef)

EndFunction

Event OnInit()

Utility.Wait(3)
Debug.Notification("Alternative Needs startup complete..")

PlayerRef.AddSpell(IsDaedra, false)

;==============REGISTER FOR SLEEP==========
	RegisterForSleep()

;========Set Duration Of Needs================
	SetDurationOfNeeds()


EndEvent

Event OnPlayerLoadGame()
	RegisterForSleep()

;========Set Duration Of Needs================
	SetSpellNthMagicEffectDuration(Tired_Time, (HourToSecond(Var1, TiredStart)/Timescale.GetValueInt()) as int, 0)
	SetSpellNthMagicEffectDuration(Thirsty_Time, (HourToSecond(Var1, ThirstyStart)/Timescale.GetValueInt()) as int, 0)
	SetSpellNthMagicEffectDuration(Hungry_Time, (HourToSecond(Var1, HungryStart)/Timescale.GetValueInt()) as int, 0)
EndEvent



;======ON SLEEP STOP REMOVE TIRED=================
Event OnSleepStop(bool abinterrupted)

	if PlayerRef.HasMagicEffect(Tired_Time.GetNthEffectMagicEffect(0)) == false
		Tired_Time.Cast(PlayerRef,PlayerRef)
	endif

EndEvent

;=========ON OBJECT EQUIPPED==================
Event OnObjectEquipped(Form akBaseObject, ObjectReference akReference)

if ((akBaseObject) as Potion).IsFood() == true
	FoodItem = akBaseObject as Potion

;======================HUNGER/THIRST=================================
		if FoodItem.GetUseSound() == ITMFoodSound.GetAt(0) As SoundDescriptor && PlayerRef.HasKeyword(Vampire) == false	;SOUPS

			if PlayerRef.HasMagicEffect(Hungry_Time.GetNthEffectMagicEffect(0)) == false
				Hungry_Time.Cast(PlayerRef,PlayerRef)
			endif

			if PlayerRef.HasMagicEffect(Thirsty_Time.GetNthEffectMagicEffect(0)) == false
				Thirsty_Time.Cast(PlayerRef,PlayerRef)
			endif

		endif

;=============================HUNGER===============================
		if FoodItem.GetUseSound() == ITMFoodSound.GetAt(1) As SoundDescriptor && PlayerRef.HasKeyword(Vampire) == false		;MEAT OR VEGGIES

			if PlayerRef.HasMagicEffect(Hungry_Time.GetNthEffectMagicEffect(0)) == false
				Hungry_Time.Cast(PlayerRef,PlayerRef)
			endif

		endif

;=============================THIRST===============================
		if FoodItem.GetUseSound() == ITMFoodSound.GetAt(2) As SoundDescriptor && PlayerRef.HasKeyword(Vampire) == false 	;LIQUIDS

				PlayerRef.AddItem(WineBottle02AEmpty, 1)

			if PlayerRef.HasMagicEffect(Thirsty_Time.GetNthEffectMagicEffect(0)) == false
				Thirsty_Time.Cast(PlayerRef,PlayerRef)
			endif

		endif
endif

;=================VAMPIRE FEEDING==================
	if akBaseObject == DLC1BloodPotion || akBaseObject == BloodPotion_
				PlayerRef.AddItem(WineBottle02AEmpty, 1)

			if PlayerRef.HasMagicEffect(Thirsty_Time.GetNthEffectMagicEffect(0)) == false
				Thirsty_Time.Cast(PlayerRef,PlayerRef)
			endif

	endif
EndEvent