//::///////////////////////////////////////////////
//:: Balor On Death
//:: NW_S3_BALORDETH
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Fireball explosion does 50 damage to all within
    20ft
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 9, 2002
//::////////////////////////////////////Shiva / Kamaji  [Deathmatch]
#include "loot"
#include "prc_inc_spells"
#include "prc_add_spell_dc"
#include "spawner"
#include "rank"

void main()
{
    object oPC = GetLastKiller();
    object oMod = GetModule();

    SetLocalInt(oMod, "sw_bm", 0);
    SetLocalInt(oMod, "ch_bm", 0);
      SetLocalInt(oMod, "gr_xx", 0);
    int oKil = GetLocalInt(oPC, "iKilled");
    oKil = oKil +1;
    SetLocalInt(oPC, "iKilled", oKil);
    int oExploit = GetLocalInt(oMod, "xcheck");
    if (oExploit!=1)
    {
      LastHit();
      if (GetLocalInt(oMod, "hwar_on")==1)
         {
          DelayCommand(3.0, HolyScore(OBJECT_SELF));
         }
      AssignCommand(oPC, ClearAllActions());
      DelayCommand(1.5, AssignCommand(oPC, ActionPlayAnimation
                (ANIMATION_FIREFORGET_VICTORY2)));
      FloatingTextStringOnCreature("Victory", oPC);
      SetLocalInt(oPC, "marilithdead", 1);
      GetRank(oPC);
      DeathStats(oPC);
      if (GetLocalInt(oMod, "hwar_on")!=1)
      {
      TombSpawn(OBJECT_SELF, oPC);
      CreateGold(OBJECT_SELF, 10000);
      }
    }
int sw1 = GetLocalInt(oMod, "sw_hw");
int sw2 = GetLocalInt(oMod, "sw_dr");
int sw3 = GetLocalInt(oMod, "sw_bl");
int sw4 = GetLocalInt(oMod, "sw_pf");
int sw5 = GetLocalInt(oMod, "sw_df");
int sw6 = GetLocalInt(oMod, "sw_pm");
int sw7 = GetLocalInt(oMod, "sw_bm");
int sw8 = GetLocalInt(oMod, "sw_lm");
int sw9 = GetLocalInt(oMod, "sw_ll");
if ((sw1==0)&&(sw2==0)&&(sw3==0)&&(sw4==0)&&(sw5==0)&&(sw6==0)
    &&(sw7==0)&&(sw8==0)&&(sw9==0)&&(GetLocalInt(oMod, "hwar_on")!=1))
    {
    SetLocked(GetObjectByTag("arena_gate"), FALSE);

    }





    //Declare major variables
    object oCaster = OBJECT_SELF;
    int nMetaMagic = PRCGetMetaMagicFeat();
    int nDamage;
    float fDelay;
    effect eExplode = EffectVisualEffect(VFX_FNF_FIREBALL);
    effect eVis = EffectVisualEffect(VFX_IMP_FLAME_M);
    effect eDam;
    //Get the spell target location as opposed to the spell target.
    location lTarget = GetLocation(OBJECT_SELF);
    //Limit Caster level for the purposes of damage
    //Apply the fireball explosion at the location captured above.
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eExplode, lTarget);
    //Declare the spell shape, size and the location.  Capture the first target object in the shape.
    object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lTarget, TRUE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR);
    //Cycle through the targets within the spell shape until an invalid object is captured.
    while (GetIsObjectValid(oTarget))
    {
       //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_FIREBALL));
        //Get the distance between the explosion and the target to calculate delay
        fDelay = GetDistanceBetweenLocations(lTarget, GetLocation(oTarget))/20;
        if (!PRCDoResistSpell(OBJECT_SELF, oTarget, FloatToInt(fDelay)))
        {
            //Adjust the damage based on the Reflex Save, Evasion and Improved Evasion.
            nDamage = PRCGetReflexAdjustedDamage(50, oTarget, PRCGetSpellSaveDC(), SAVING_THROW_TYPE_FIRE);
            //Set the damage effect
            eDam = EffectDamage(nDamage, DAMAGE_TYPE_FIRE);
            if(nDamage > 0)
            {
                // Apply effects to the currently selected target.
                DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDam, oTarget));
                //This visual effect is applied to the target object not the location as above.  This visual effect
                //represents the flame that erupts on the target not on the ground.
                DelayCommand(fDelay, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget));
            }
         }
       //Select the next target within the spell shape.
       oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_HUGE, lTarget, TRUE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_DOOR);
    }
}