//:://////////////////////////////////////////////
//:: Created By: Ped Xing (pedx1ng@lycos.com)
//:: Created On: 26 June, 2002
//:://////////////////////////////////////////////


// This function determines if a specific item exists in the
// specfified container, which can be a creature or placeable
// object that is a container.

// Modified 12-22-2003 by AW Olorin to Automatically make DM's
// Anonymous to PcScry on module entry.
// Modified 1-25-2004 by AW Olorin - Remove message stones
// Modified 6-11-2004 by AW Olorin - Added Mod news message

  #include "nw_i0_tool"



// * Applies an XP and GP penalty
// * to the player respawning
void ApplyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    int nPenalty = 75 * GetHitDice(oDead);
    int nHD = GetHitDice(oDead);
    // * You can not lose a level with this respawning
    int nMin = ((nHD * (nHD - 1)) / 2) * 1000;

    int nNewXP = nXP - nPenalty;
    if (nNewXP < nMin)
       nNewXP = nMin;
    SetXP(oDead, nNewXP);
    int nGoldToTake =    FloatToInt(0.15 * GetGold(oDead));
    // * a cap of 10 000gp taken from you
    if (nGoldToTake > 1000000)
    {
        nGoldToTake = 1000000;
    }
    AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
    DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
    DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));

}

 void DecrementTalentIndex(int iIndex, object oPC);
// Main code block
void main()
{

 object oPlayer = GetEnteringObject();
  object oPC = GetEnteringObject();
  object target = GetEnteringObject();
    // DM's log on anonymously. -- AW Olorin
    if (GetIsDM(oPlayer)) SetLocalInt(oPlayer,"PCL_ANON",1);
    SetLocalString(oPlayer, "ID",  GetPCPlayerName( oPlayer )  );
    SetLocalString(oPlayer, "NAME",  GetName( oPlayer )  );
    SetLocalString(oPlayer, "KEY", GetPCPublicCDKey( oPlayer ) );
    SetLocalString(oPlayer, "IP",  GetPCIPAddress( oPlayer )  );
    DelayCommand (20.0, SendMessageToPC(oPC, "This world was built by AW Trespasser. Work began on it when NWN was first released. It has been a long arduous procces, but here is the final result."));


//  News or update message sent to PC's on login.  Please change as needed.
    DelayCommand (30.0, SendMessageToPC(oPC, "Update 6/11/04 -- New Area Level restrictions posted on sign in town.  Please read them."));





   if (GetIsPC(oPC) && !GetIsDM(oPC)){
      string bReport;
                    bReport = (GetName(target) + GetPCPlayerName(target));
              int booted =       GetCampaignInt("booted", bReport, oPC);
              if (booted == 5){
                               AssignCommand(target, ClearAllActions());
                    AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!"));
                    DelayCommand(1.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(2.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(3.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(4.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(5.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(6.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(6.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(8.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(9.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
                     DelayCommand(10.0, AssignCommand(target, ActionSpeakString("I HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!")));
         DelayCommand(10.0,  SendMessageToPC(oPC, "YOU HAVE BEEN SMACKED BY THE HAND OF GOD!!!!!!"));
           DelayCommand(15.0, BootPC(oPC));
      }
   }


       string sReport;

        if( GetIsPC( oPlayer ) && !GetIsDM(oPlayer) )
        {

        sReport = ">>> ID: " + GetPCPlayerName( oPlayer )
                    + "; Name: "+ GetName( oPlayer )
                    + "; CD Key:" + GetPCPublicCDKey( oPlayer )
                    + "; IP:" + GetPCIPAddress( oPlayer )
                    + "; has logged in.";
        WriteTimestampedLogEntry( sReport );
         SendMessageToAllDMs( sReport);
    }
   string immortalname;
     immortalname = ">>> ID: " + GetPCPlayerName( oPlayer )
                    + "; Name: "+ GetName( oPlayer )
                    + "; CD Key:" + GetPCPublicCDKey( oPlayer );
             int god=       GetCampaignInt("PoA", "immortalname", oPlayer);
             if (god==2){

DelayCommand (1.0,  ApplyEffectToObject(DURATION_TYPE_PERMANENT, EffectVisualEffect(VFX_DUR_PARALYZED), oPC));

}

DelayCommand(120.0,       SetLocalInt(oPC, "logging", 2));
int nMaxHP = GetMaxHitPoints(oPlayer);
string sVarName = "s"+GetName(oPlayer);
object oModule = GetModule();
    effect eDeath = EffectDeath();
        string ddVarName = "dd"+GetName(oPlayer);
int nHPOnExit = GetLocalInt (oModule, sVarName);
  int oDie = GetLocalInt (oModule, ddVarName);
          if (oDie == 1){
          CreateItemOnObject("death", oPC, 1);

        }


   int deathtime = GetLocalInt(GetModule(), "died"+GetName(oPlayer));

  if(HasItem(oPC, "death"))
   {


   int currenttime = GetLocalInt(GetModule(), "loadtimer");
   int timer = currenttime - deathtime;
        if (timer > 54){



 object oRespawner = oPC;

    SendMessageToPC(oPC,"You would have auto respawned had you been logged in. Executing AutoRespawn script.");

      SetLocalObject(oPC, "respawn", oPC);
        ApplyEffectToObject(DURATION_TYPE_PERMANENT, eDeath, oPC);

    DelayCommand(0.2, AssignCommand(oPC, ExecuteScript("forcerespawn2", oPC)));

if  (GetCampaignInt("PoA", "immortalname", oRespawner) == 2){
return;
}

   if (!GetIsDead(OBJECT_SELF)){
   return;
   }
   }
   if (oDie == 1){

         ApplyEffectToObject(DURATION_TYPE_PERMANENT, eDeath, oPC);
        SetLocalInt(oModule,ddVarName,0);
        }



  }


//Check to see if we have a new char or a reload





int iIndex;

for (iIndex = 1; iIndex < 1000; iIndex++)
{
DecrementTalentIndex(iIndex, oPC);
}

}

void DecrementTalentIndex(int iIndex, object oPC)

{
int iDecrementIndex;

talent tSpell;


/* create our talent */
tSpell = TalentSpell(iIndex);


/* check for all spells */
if (GetIsPC(oPC) && !GetIsDM(oPC))
{
if (GetIsTalentValid(tSpell))
{
if (GetHasSpell(GetIdFromTalent(tSpell), oPC))
{
for (iDecrementIndex = 1; iDecrementIndex < 20; iDecrementIndex++)
{
DecrementRemainingSpellUses(oPC, GetIdFromTalent(tSpell));
}
}
}
}

}