//::///////////////////////////////////////////////
//:: Aura of Frost on Heartbeat
//:: NW_S1_AuraColdC.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Prolonged exposure to the aura of the creature
    causes frost damage to all within the aura.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: May 25, 2001
//:://////////////////////////////////////////////
#include "NW_I0_SPELLS"
//#include "wm_include"
#include "prc_inc_spells"
void main()
{
//:: Declare major variables
	object oNPC		= GetAreaOfEffectCreator();
	object oTarget 	= GetEnteringObject();
	
    int nHD 		= GetHitDice(oNPC);
	int nCHAMod		= GetAbilityModifier(ABILITY_CHARISMA, oNPC);
    int nFrost 		= 1 + (nHD/3);
    int nDC			= 10 +nCHAMod+ (nHD/2);
    int nDamage;

    effect eDam;
    effect eVis 	= EffectVisualEffect(VFX_IMP_FROST_S);

    //Get the first target in the aura of cold
    oTarget = GetFirstInPersistentObject();
	
    while (GetIsObjectValid(oTarget))
    {
/*         if (NullMagicOverride(GetArea(oTarget), oTarget, oTarget))
        {
        oTarget = GetNextInPersistentObject(OBJECT_SELF);
        continue;
        } */
        if(GetIsEnemy(oTarget, GetAreaOfEffectCreator()))
        {
            //Fire cast spell at event for the specified target
            SignalEvent(oTarget, EventSpellCastAt(oNPC, SPELLABILITY_AURA_COLD));
            //Roll damage based on the creatures HD
            nDamage = d4(nFrost);
            //Make a Fortitude save for half
            if(PRCMySavingThrow(SAVING_THROW_FORT, oTarget, nDC, SAVING_THROW_TYPE_COLD))
            {
                nDamage = nDamage / 2;
            }
            //Set the damage effect
            eDam = EffectDamage(nDamage, DAMAGE_TYPE_COLD);
            //Apply the VFX constant and damage effect
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget);
            ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
        }
        //Get the next target in the aura of cold
        oTarget = GetNextInPersistentObject();
    }
}
