//On Use Function for item foodForRest
//For use in the Food System
//Created by: Cody Houston 12/20/2007 with the use of the ItemActivate Template
// Modified by Shazbotian for magic meal summoned by "Create Food and Water"
//===================================================================================

int EffectIsFatigue(effect eEffect)
{
	int iIsFatigue = FALSE;
	
	// first, only stat decreases and movement penalties qualify
	if((GetEffectType(eEffect)==EFFECT_TYPE_ABILITY_DECREASE) || (GetEffectType(eEffect) == EFFECT_TYPE_MOVEMENT_SPEED_DECREASE)) {
		// then, only effects caused by certain spells...
		int iSpellID = GetEffectSpellId(eEffect);
		switch(iSpellID) {
			case SPELL_TOUCH_OF_FATIGUE:
			case SPELLABILITY_BARBARIAN_RAGE:
			case SPELL_HYPOTHERMIA:
			case SPELLABILITY_FRENZY:
			case SPELLABILITY_INSPIRE_FRENZY:
			case SPELLABILITY_EPIC_MIGHTY_RAGE:
				iIsFatigue = TRUE;
				break;
			default:
				iIsFatigue = FALSE;
				break;
		}	
	}
	
	return iIsFatigue;
}

//Main Function DO NOT TOUCH!!!!!!!!!
void main()
{
    object oActivator	= GetItemActivator();
    object oItem    	= GetItemActivated();
    object oTarget 		= GetItemActivatedTarget();
    location lTarget	= GetItemActivatedTargetLocation();
	effect eEffect;
	

	// its just a bottle of water... should be able to drink it
//	if (GetIsInCombat(oActivator)) {
//
//		SendMessageToPC(GetItemActivator(), "You can't eat food while fighting!");
//		return;
//	}
	
	//effect eHeal = EffectHeal(2);
	//ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oActivator);
	
	// go through all effects on the activator, remove any associated with "touch of fatigue"
	eEffect = GetFirstEffect(oActivator);
	while(GetIsEffectValid(eEffect)) {
		SendMessageToPC(oActivator, "Effect spell id: " + IntToString(GetEffectSpellId(eEffect)));
		if(EffectIsFatigue(eEffect)) {
			//SendMessageToPC(oActivator, "The refreshing water washes away your fatigue!");
			RemoveEffect(oTarget, eEffect);
		}
		eEffect = GetNextEffect(oActivator);
	}
	

	if(GetLocalInt(oActivator, "ISHungry") > 0) {
		//SetLocalInt(oActivator, "ISHungry", 0);
		eEffect = GetFirstEffect(oTarget);
		while (GetIsEffectValid(eEffect))
		{
			if (GetEffectType(eEffect)==EFFECT_TYPE_ABILITY_DECREASE) RemoveEffect(oTarget, eEffect);
			eEffect = GetNextEffect(oTarget);
		}
	}
	
	//================================================================================================================
	// Below Allows for multiple types of food with different timers.
	// To create: change the DelayCommand float to the value you wish (Default = 5.0)
	// then just save this script as i_<Tag of new food item here>_ac. 	
//	SetLocalInt(oPC, "ISHungry", 1);
//	DelayCommand(5.0,ExecuteScript("func_hungry", oPC));
}