//::///////////////////////////////////////////////
//:: Wall of Fire: On Enter
//:: NW_S0_WallFireA.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Person within the AoE take 4d6 fire damage
    per round.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: May 17, 2001
//:://////////////////////////////////////////////

// (Update JLR - OEI 07/19/05) -- Changed Dmg to 2d6 + lvl (max 20), double dmg to Undead


#include "X0_I0_SPELLS"
#include "x2_inc_spellhook"

void main()
{

    //Declare major variables
    int nCasterLvl = JXGetCasterLevel(OBJECT_SELF);
    int nMetaMagic = JXGetMetaMagicFeat();
    int nDamage;
    effect eDam;
    object oTarget;
    //Declare and assign personal impact visual effect.
    effect eVis = EffectVisualEffect(VFX_HIT_SPELL_FIRE);
    //Capture the first target object in the shape.
    oTarget = GetEnteringObject();
    if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, JXGetAOERealCreator()))
    {
        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(JXGetAOERealCreator(), SPELL_WALL_OF_FIRE));
        //Make SR check, and appropriate saving throw(s).
        if(!MyResistSpell(JXGetAOERealCreator(), oTarget))
        {
            //Roll damage.
            nDamage = d6(2);  // JLR - OEI 07/19/05

            //Enter Metamagic conditions
            if (nMetaMagic & METAMAGIC_MAXIMIZE)
            {
                nDamage = 12;//Damage is at max  // JLR - OEI 07/19/05
            }
            if (nMetaMagic & METAMAGIC_EMPOWER)
            {
                nDamage = nDamage + (nDamage/2); //Damage/Healing is +50%
            }

            nDamage += nCasterLvl;  // JLR - OEI 07/19/05
            if ( nDamage > 20 )
            {
                nDamage = 20;
            }
            if ( GetRacialType(oTarget) == RACIAL_TYPE_UNDEAD )
            {
                nDamage *= 2;
            }

            nDamage = GetReflexAdjustedDamage(nDamage, oTarget, JXGetSpellSaveDC(), SAVING_THROW_TYPE_FIRE);
            if(nDamage > 0)
            {
                // Apply effects to the currently selected target.
                eDam = EffectDamage(nDamage, DAMAGE_TYPE_FIRE);
                JXApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget);
                JXApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
            }
        }
    }
}