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

void LastHit3()
{

    object oMod = GetModule();
    object oPC = GetLastDamager(OBJECT_SELF);
    int oDam = GetTotalDamageDealt();
    string oAtt;
    string oSelf;
    string oMon;
    object oDest;
    int oHit;
    int oMhit;
    int oPCdam;
    int oSDTaken;
    int oUDTaken;
    int oSDDealt;
    int oUDDealt;
    int iSFhit;
    int iSFdam;
    int iFBhit;
    int iFBdam;
    int oHWdam;
    int oHWhit;
    int iCHdam;
    int iCHhit;
    int iArenaChall =GetLocalInt(oMod, "challenge");
    int iSFDuel =GetLocalInt(oMod, "duel_on");
    int iWarWon = GetLocalInt(oMod, "war_won");
    int iJoinSwitch = GetLocalInt(oPC, "join_switch");
    int iHwar = GetLocalInt(oMod, "hwar_on");
    //FloatingTextStringOnCreature("duel on:  "+IntToString(GetLocalInt(oMod, "duel_on")), oPC);



    if (GetIsPC(oPC))
       {
        oHit = GetLocalInt(oPC, "pc_hit");
        oPCdam = GetLocalInt(oPC, "player_dd");
        ++oHit;
        oPCdam+=oDam;
        SetLocalInt(oPC, "pc_hit", oHit);
        SetLocalInt(oPC, "player_dd", oPCdam);
        if (iHwar==1)
           {
            oHWdam = GetLocalInt(oPC, "pc_HWdam");
            oHWhit = GetLocalInt(oPC, "pc_HWhit");
            ++oHWhit;
            oHWdam+=oDam;
           SetLocalInt(oPC, "pc_HWhit", oHWhit);
           SetLocalInt(oPC, "pc_HWdam", oHWdam);
           }
        if (iArenaChall==1)
           {
            iCHdam = GetLocalInt(oPC, "pc_CHdam");
            iCHhit = GetLocalInt(oPC, "pc_CHhit");
            iCHdam+=oDam;
            ++iCHhit;
            SetLocalInt(oPC, "pc_CHhit", iCHhit);
            SetLocalInt(oPC, "pc_CHdam", iCHdam);
           }

       }
}

void main()
{
    // Setup variables

    object oPC = GetLastKiller();
    object oMod = GetModule();
    object oTarget= OBJECT_SELF;
    int oDam = GetTotalDamageDealt();

    int nInt;
    int iFBhit;
    int iFBdam;
    int iFBswing;

    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");
    int sw10 = GetLocalInt(oMod, "sw_xx");
    int iKilled = GetLocalInt(oPC, "iKilled");
    int iFinalBattle = GetLocalInt(oPC, "final_on");
    int iHolyWar = GetLocalInt(oMod, "hwar_on");

    if ((iHolyWar!=1)&&((iFinalBattle==1)&&(GetIsPC(oPC)))){QuickRestore(oPC);}

     // Re-enable spawner

    SetLocalInt(oMod, "sw_xx", 0);
    SetLocalInt(oMod, "ch_xx", 0);
    SetLocalInt(oMod, "gr_xx", 0);
    SetLocalInt(oMod, "challenge", 0);
    LastHit3();
    if (iFinalBattle==1)
           {
            iFBdam = GetLocalInt(oPC, "pc_FBdam");
            iFBhit = GetLocalInt(oPC, "pc_FBhit");
            iFBdam+=oDam;
            ++iFBhit;
            SetLocalInt(oPC, "pc_FBhit", iFBhit);
            SetLocalInt(oPC, "pc_FBdam", iFBdam);
            if (GetName(GetLastWeaponUsed(oPC))=="")
               {
                iFBswing = GetLocalInt(oPC, "pc_FBswing");
                ++iFBswing;
                SetLocalInt(oPC, "pc_FBswing", iFBswing);
               }
           }


    // effect ***************************************

    //AssignCommand(oPC, PlaySound("vs_nzeliepm_dead"));

    PCEffect(0.0, VFX_IMP_DEATH_L, oTarget);
    PCEffect(0.3, VFX_IMP_MAGIC_PROTECTION, oTarget);
    PCEffect(0.0, VFX_FNF_WAIL_O_BANSHEES, oTarget);
    PCEffect(0.3, VFX_FNF_SCREEN_SHAKE, oTarget);
    PCEffect(0.5, VFX_FNF_DISPEL_GREATER, oTarget);
    PCEffect(0.6, VFX_IMP_MAGIC_PROTECTION, oTarget);

    // If battle terminator wasn't used: Create treasure, adjust kills &
    // play victory animation and flag monster as killed by pc

    int oExploit = GetLocalInt(oMod, "xcheck");
    if (oExploit!=1)
    {
      if (GetLocalInt(oMod, "hwar_on")==1)
         {
          DelayCommand(3.0, HolyScore(OBJECT_SELF));
         }

     AssignCommand(oPC, PlaySound("bf_huge"));
     iKilled=iKilled+1;
     SetLocalInt(oPC, "iKilled", iKilled);
     DelayCommand(0.5, GetRank(oPC)); // Update the players rank
     AssignCommand(oPC, ClearAllActions());
     DelayCommand(1.5, AssignCommand(oPC, ActionPlayAnimation
                (ANIMATION_FIREFORGET_VICTORY2)));
     FloatingTextStringOnCreature("Victory", oPC);

     int iHwarFlag = GetLocalInt(oMod, "hwar_on");
     int iLdead = GetLocalInt(oPC, "luciferdead");
     if (iLdead==1)
        {
         if (iHwarFlag!=1)
            {
             TombSpawn(OBJECT_SELF, oPC);
             CreateGold(OBJECT_SELF, 50000);
            }
        }

     else if (iLdead!=1)
        {
         QuickRestore(oPC);
         SetLocalInt(oPC, "luciferdead", 1);
         SetLocalInt(oPC, "cutscene_on", 1);
         SetLocalInt(oPC, "cutscene_flag", 0);
          }



    }

    // if there are no monsters in the arena, unlock the gate

if ((sw1==0)&&(sw2==0)&&(sw3==0)&&(sw4==0)&&(sw5==0)&&(sw6==0)
    &&(sw7==0)&&(sw8==0)&&(sw9==0)&&(sw10==0)&&(GetLocalInt(oMod, "hwar_on")!=1))
    {
    SetLocked(GetObjectByTag("arena_gate"), FALSE);
    }
ExecuteScript("nw_c2_default7", OBJECT_SELF);
}