//::///////////////////////////////////////////////
//:: Drangonari Fire Breath 
//:: avlis2_drangonari_fire_breath
//:: Copyright (c) 2006 Avlis2: Crosstreams
//:://////////////////////////////////////////////
/*
    Calculates the proper damage and DC Save for the
    breath weapon based on the HD of the drangoari.
*/
//:://////////////////////////////////////////////
//:: Created By: Gavin Barron (Tesh)
//:: Created On: December 24, 2006 0100 GMT.
//:://////////////////////////////////////////////
#include "NW_I0_SPELLS"
#include "x0_i0_spells"

void DrangBreathFire(int nDamage, int nDC);

void main()
{
    //Declare major variables
	int ABILITY_FOCUS_DRANGONARI_BREATH_WEAPON = 1863;
    int nDamage, nDC, nDamStrike;
    float fDelay;
    object oTarget;
    effect eVis, eBreath;
    //Use a fixed damage rate
	nDamage = d8(6);
	//Calculate the reflex DC
	//(DC 10 + ABILITY_FOCUS_DC_BONI + Con modifier)
	nDC = 10 + GetAbilityModifier(ABILITY_CONSTITUTION, OBJECT_SELF);
	if(GetHasFeat(ABILITY_FOCUS_DRANGONARI_BREATH_WEAPON, OBJECT_SELF, TRUE))
	{
		nDC = nDC + 2;
	}

	//Swap VFX to burning hands as I think it looks better.
	effect eFireBreath = EffectVisualEffect( VFX_DUR_SPELL_BURNING_HANDS );
	//effect eFireBreath = EffectNWN2SpecialEffectFile("fx_red_dragon_breath.sef");
	
    //PlayDragonBattleCry();
	//PlayCustomAnimation(OBJECT_SELF, "Una_breathattack01", 0, 0.7f);
	DelayCommand(0.5f, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eFireBreath, OBJECT_SELF, 3.0f));
   
	
	DelayCommand(0.7f, DrangBreathFire(nDamage, nDC));
}
	
void DrangBreathFire(int nDamage, int nDC)
{
	float fDelay;
    effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);
	float coneSize = RADIUS_SIZE_COLOSSAL;  
	//Get first target in spell area
    object oTarget = GetFirstObjectInShape(SHAPE_SPELLCONE, coneSize, GetSpellTargetLocation(), TRUE);
    while(GetIsObjectValid(oTarget))
    {
        if(oTarget != OBJECT_SELF && spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
        {
            //Reset the damage to full
            int nDamStrike = nDamage;		

            //Fire cast spell at event for the specified target
            SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELLABILITY_DRAGON_BREATH_FIRE));
            //Adjust the damage based on the Reflex Save, Evasion and Improved Evasion.
            if(MySavingThrow(SAVING_THROW_REFLEX, oTarget, nDC, SAVING_THROW_TYPE_FIRE))
            {
                nDamStrike = nDamStrike/2;
                if(GetHasFeat(FEAT_EVASION, oTarget) || GetHasFeat(FEAT_IMPROVED_EVASION, oTarget))
                {
                    nDamStrike = 0;
                }
            }
            else if(GetHasFeat(FEAT_IMPROVED_EVASION, oTarget))
            {
                nDamStrike = nDamStrike/2;
            }			
			effect eBreath = EffectDamage(nDamStrike, DAMAGE_TYPE_FIRE);
            if (nDamStrike > 0)
            {
                //Determine effect delay
                //fDelay = GetDistanceBetween(OBJECT_SELF, oTarget)/20;
                //Apply the VFX impact and effects
                DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oTarget, 3.0f));
                DelayCommand(2.0, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eVis, oTarget, 3.0f));
                DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eBreath, oTarget));
             }
        }
        //Get next target in spell area
        oTarget = GetNextObjectInShape(SHAPE_SPELLCONE, coneSize, GetSpellTargetLocation(), TRUE);
    }
}