//::///////////////////////////////////////////////
//:: Name oldhermit_onhb
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Strange Old Hermit's HB script.
*/
//:://////////////////////////////////////////////

#include "prc_inc_spells"

/* // Metamagic flag for Extend Spell
const int METAMAGIC_EXTEND = 4; */

// Check if SPELL_REPEL_VERMIN is active on OBJECT_SELF
int IsRepelVerminActive()
{

    // Iterate through all active effects on the object
    effect eCurrent = GetFirstEffect(OBJECT_SELF);
    while (GetIsEffectValid(eCurrent))
    {
        int nSpellId = GetEffectSpellId(eCurrent);
        if (nSpellId == SPELL_REPEL_VERMIN)
        {
            return TRUE; // Found the spell effect
        }

        eCurrent = GetNextEffect(OBJECT_SELF);
    }

    return FALSE; // Spell effect not found
}

void main()
{
    object oNPC = OBJECT_SELF;

    if (!GetIsAreaInterior())
	{
		if (!IsRepelVerminActive())
		{
			// Get the NPCs HitDice
			int nSpellLevel = GetHitDice(OBJECT_SELF);

			// Cast SPELL_REPEL_VERMIN with Extend Spell metamagic
			ActionSpeakString("Aggh, damn bugs!!", TALKVOLUME_TALK);
			DelayCommand(0.1f, ActionCastSpellAtObject(SPELL_REPEL_VERMIN, oNPC, METAMAGIC_EXTEND, TRUE, nSpellLevel, FALSE));
		}
	}
	
    if ((!GetIsInCombat(oNPC) && (GetItemInSlot(INVENTORY_SLOT_CHEST) == OBJECT_INVALID)))
        DelayCommand(0.5f, ActionEquipMostEffectiveArmor());

//:: Execute the default NPC OnHeartbeat script
    ExecuteScript("nw_c2_default1", oNPC);

//:: Execute the PRC NPC OnHeartbeat script
    ExecuteScript("prc_npc_hb", oNPC);
	
}