//::///////////////////////////////////////////////
//:: Name x2_def_ondeath
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Default OnDeath script
*/
//:://////////////////////////////////////////////
//:: Created By: Keith Warner
//:: Created On: June 11/03
//::////////////////////////////////////Baal / Thor [challenge]
#include "x0_i0_petrify"
#include "spawner"
#include "loot"
#include "rank"

void main()
{


    object oPC = GetLastKiller();
    object oMod = GetModule();
    object oP1 = GetObjectByTag("pool1");
    object oP2 = GetObjectByTag("pool2");
    object oP3 = GetObjectByTag("fountain1");
    object oP4 = GetObjectByTag("fountain2");
    object oLever1 = GetObjectByTag("pool_lever");
    object oLever2 = GetObjectByTag("fount_lever");
    effect eEffect = EffectVisualEffect(VFX_DUR_GLOBE_INVULNERABILITY);
    int nInt2=GetLocalInt(oMod, "d4");
    int nInt3=GetLocalInt(oMod, "d5");
    int nInt4=GetLocalInt(oMod, "d2a");
    int nInt5=GetLocalInt(oMod, "d3");
    int oExploit = GetLocalInt(oMod, "xcheck");
    int iMode = GetLocalInt(oMod, "gamemode");
    //string oDebug = IntToString(nInt3);
    //Message(8.0, oDebug, oPC);
    int nInt;
    int iKilled = GetLocalInt(oPC, "iKilled");
    int oChest;
    int oLife = GetLocalInt(oPC, "lives");
    SetLocalInt(oMod, "gr_xx", 0);
    SetLocalInt(oMod, "sw_ll", 0);
    SetLocalInt(oMod, "ch_ll", 0);

    if (oExploit!=1)
    {
      LastHit();
      if (GetLocalInt(oMod, "hwar_on")==1)
         {
          DelayCommand(3.0, HolyScore(OBJECT_SELF));
         }
      if ((nInt2!=1)&&(nInt3!=1)&&(nInt4!=1)&&(nInt5!=1))
       {
        SetLocalInt(oPC, "lorddead", 1);
        SetLocalInt(oMod, "challenge",0);

        iKilled=iKilled+1;
        SetLocalInt(oPC, "iKilled", iKilled);
        GetRank(oPC);
        DeathStats(oPC);
        FloatingTextStringOnCreature("Victory", oPC);
        AssignCommand(oPC, ClearAllActions());
        DelayCommand(1.5, AssignCommand(oPC, ActionPlayAnimation
                (ANIMATION_FIREFORGET_VICTORY2)));
        if (GetLocalInt(oMod, "hwar_on")!=1)
           {
            TombSpawn(OBJECT_SELF, oPC);
            CreateGold(OBJECT_SELF, 15000);

           }

        if ((GetItemPossessedBy(oPC, "divine_talisman")== OBJECT_INVALID)&&
           (GetItemPossessedBy(oPC, "dark_talisman")== OBJECT_INVALID)&&
           (GetItemPossessedBy(oPC, "divine_talisman2")== OBJECT_INVALID)&&
           (GetItemPossessedBy(oPC, "dark_talisman2")== OBJECT_INVALID)&&
           (GetItemPossessedBy(oPC, "div_key")== OBJECT_INVALID)&&
           (GetLocalInt(oMod, "hwar_on")!=1))
           {
            CreateItemOnObject("div_key", OBJECT_SELF, 1);
           }

      }
    if(nInt2==1)
      {
         QuickRestore(oPC);
         SetLocalInt(oPC, "lorddead", 1);
         iKilled=iKilled+1;
         SetLocalInt(oPC, "iKilled", iKilled);
         GetRank(oPC);
         SetLocalInt(oMod, "d4_complete", 1);
         if (iMode==1)
            {AddJournalQuestEntry("boss5_0", 1, oPC, FALSE, FALSE);}
         else{AddJournalQuestEntry("boss5", 1, oPC, FALSE, FALSE);}
         SetLocalInt(oMod, "challenge", 0);
         DelayCommand(5.0, AssignCommand(oPC, PlaySound("sce_neutral")));
         DelayCommand(5.0, FloatingTextStringOnCreature("W I N N E R", oPC));
         //DelayCommand(7.0, FloatingTextStringOnCreature("Congratulations!", oPC));
         //DelayCommand(9.0, FloatingTextStringOnCreature("Can you survive the ultimate challenge!", oPC));
         SetLocked(GetObjectByTag("arena_gate"), FALSE);
         AssignCommand(oLever1, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
         AssignCommand(oLever2, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
         RemoveEffectOfType(oP1, GetEffectType(eEffect));
         RemoveEffectOfType(oP2, GetEffectType(eEffect));
         RemoveEffectOfType(oP3, GetEffectType(eEffect));
         RemoveEffectOfType(oP4, GetEffectType(eEffect));
         SetLocalInt(oMod, "fountain_state", 0);
         SetLocalInt(oMod, "pool_state", 0);
         SetLocalInt(oPC, "cutscene_on", 1);
         SetLocalInt(oMod, "cutscene_flag", 0);
         if (iMode==1)
            {AddJournalQuestEntry("boss6_0", 1, oPC, FALSE, FALSE);}
         else{AddJournalQuestEntry("boss6", 1, oPC, FALSE, FALSE);}
     }
     if ((nInt4==1)&&(GetLocalInt(oMod, "d2a_complete")!=1))
      {
       QuickRestore(oPC);
       SetLocalInt(oMod, "challenge",0);
       SetLocalInt(oPC, "lorddead", 1);
       iKilled=iKilled+1;
       SetLocalInt(oPC, "iKilled", iKilled);
       GetRank(oPC);
       SetLocalInt(oMod, "d2a_complete", 1);
       AddJournalQuestEntry("boss3", 1, oPC, FALSE, FALSE);
       DelayCommand(6.0, AssignCommand(oPC, PlaySound("sce_neutral")));
       DelayCommand(6.0, FloatingTextStringOnCreature("W I N N E R", oPC));
       SetLocked(GetObjectByTag("arena_gate"), FALSE);
       AssignCommand(oLever1, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
       AssignCommand(oLever2, ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
       RemoveEffectOfType(oP1, GetEffectType(eEffect));
       RemoveEffectOfType(oP2, GetEffectType(eEffect));
       RemoveEffectOfType(oP3, GetEffectType(eEffect));
       RemoveEffectOfType(oP4, GetEffectType(eEffect));
       SetLocalInt(oMod, "fountain_state", 0);
       SetLocalInt(oMod, "pool_state", 0);
       SetLocalInt(oPC, "cutscene_on", 1);
       SetLocalInt(oMod, "cutscene_flag", 0);
       if (iMode==1)
       {AddJournalQuestEntry("boss3_0", 1, oPC, FALSE, FALSE);}
       else{AddJournalQuestEntry("boss3", 1, oPC, FALSE, FALSE);}
      }
     if ((nInt5==1)||(nInt3==1))
     {
      iKilled=iKilled+1;
      SetLocalInt(oPC, "iKilled", iKilled);
      GetRank(oPC);
      ++oLife;
      SetLocalInt(oPC, "lives", oLife);
      Message(2.4, "Bonus Life Granted", oPC);
      PCEffect(3.5, VFX_IMP_SUPER_HEROISM, oPC);
      DelayCommand(2.5, AssignCommand(oPC, ActionPlayAnimation(ANIMATION_FIREFORGET_VICTORY2)));
      if (nInt3!=1)
         {BattleRest(oPC);}

      int oGameMode = GetLocalInt(oMod, "gamemode");
      if (oGameMode==1)
         {
          DelayCommand( 9.8, spawner (oPC, "angel", 0));
          }
      else
          {
           DelayCommand( 9.8, spawner (oPC, "lucifer", 0));
          }

      DoEffect(9.8,VFX_FNF_PWKILL, "monster_wp");
     }
  }

    object oSpawner = GetObjectByTag("spawner");
    AssignCommand(oSpawner,  ActionPlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
    object oTarget= OBJECT_SELF;
    nInt = GetObjectType(oTarget);
    if (nInt != OBJECT_TYPE_WAYPOINT)
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_DEATH), oTarget);
    else ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
    EffectVisualEffect(VFX_IMP_DEATH), GetLocation(oTarget));
    if (nInt != OBJECT_TYPE_WAYPOINT)
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), oTarget);
    else ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
    EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), GetLocation(oTarget));
    if (nInt != OBJECT_TYPE_WAYPOINT)
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_FIRESTORM), oTarget);
    else ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
    EffectVisualEffect(VFX_FNF_FIRESTORM), GetLocation(oTarget));
    //if (nInt != OBJECT_TYPE_WAYPOINT)
    //ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_WAIL_O_BANSHEES), oTarget);
    //else ApplyEffectAtLocation(DURATION_TYPE_INSTANT,
    //EffectVisualEffect(VFX_FNF_WAIL_O_BANSHEES), GetLocation(oTarget));
    AssignCommand(oPC, PlaySound("vs_nzorxxxm_vict"));
    ExecuteScript("nw_c2_default7", OBJECT_SELF);
}