//::///////////////////////////////////////////////
//:: Drangonari Acid Fog: On Enter
//:: avlis2_drang_acid_fog_on_enter.nss
//:: Copyright (c) 2006 Avlis2: Crosstreams
//:://////////////////////////////////////////////
/*
    All entering the AoE take 4d6 acid damage
    per round and upon entering if they fail a Fort Save
	(DC 16 + drangonari's Cha modifier)
    or their movement is halved.
*/
//:://////////////////////////////////////////////
//:: Created By: Gavin Barron (Tesh)
//:: Created On: December 24, 2006, 0130 GMT
//:://////////////////////////////////////////////

#include "X0_I0_SPELLS"

void main()
{

    //Declare major variables
    int nDamage;
    effect eDam;
    effect eVis = EffectVisualEffect(VFX_HIT_SPELL_ACID);
    effect eSlow = EffectMovementSpeedDecrease(50);
    object oTarget = GetEnteringObject();
    float fDelay = GetRandomDelay(1.0, 2.2);
	//Fortitude save (DC 16 + drangonari's Cha modifier)
	int nDC = 16 + GetAbilityModifier(ABILITY_CHARISMA, GetAreaOfEffectCreator());
    if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, GetAreaOfEffectCreator()))
    {
        //Fire cast spell at event for the target
        SignalEvent(oTarget, EventSpellCastAt(GetAreaOfEffectCreator(), SPELL_ACID_FOG));
        //Spell resistance check
        if(!MyResistSpell(GetAreaOfEffectCreator(), oTarget, fDelay))
        {
            //Roll Damage
            nDamage = d6(4);
			
            //Make a Fortitude Save to avoid the effects of the movement hit.
            if(!MySavingThrow(SAVING_THROW_FORT, oTarget, nDC, SAVING_THROW_TYPE_ACID, GetAreaOfEffectCreator(), fDelay))
            {
                //slowing effect
                ApplyEffectToObject(DURATION_TYPE_PERMANENT, eSlow, oTarget);
            }

            //Set Damage Effect with the modified damage
            eDam = EffectDamage(nDamage, DAMAGE_TYPE_ACID);
            //Apply damage and visuals
            DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget));
            DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget));
        }
    }
}