// Module : OnPlayerRespawn by Brian "spilth" Kelly
// For Neverwinter Nights - Bleeding Tutorial

#include "nw_i0_plot"
#include "bleeding_config"

void ApplyPenalty(object oDead)
{
    int nXP = GetXP(oDead);
    int nPenalty = 50 * 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.02 * GetGold(oDead));
    //  a cap of 1000gp taken from you
   if(nHD > 5)
   {
       int nGoldToTake =    FloatToInt(0.10 * GetGold(oDead));
   }
    if (nGoldToTake > 10000)
    {
        nGoldToTake = 10000;
    }
  AssignCommand(oDead, TakeGoldFromCreature(nGoldToTake, oDead, TRUE));
  DelayCommand(4.0, FloatingTextStrRefOnCreature(58299, oDead, FALSE));
  DelayCommand(4.8, FloatingTextStrRefOnCreature(58300, oDead, FALSE));

}

void main() {
    object oPC = GetLastRespawnButtonPresser();
    object oSpawnPoint = GetObjectByTag("NW_DEATH_TEMPLE");
    string sArea = GetTag(GetArea(oPC));
    // Heal them and remove any nasty effects

    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPC);
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPC)), oPC);
    RemoveEffects(oPC);
    ApplyPenalty(oPC);


    // Mark them as alive once again
//    DelayCommand(2.0, SetLocalInt(oPC, "PlayerHealth", PC_HEALTH_ALIVE);
    SetLocalInt(oPC, "PlayerHealth", PC_HEALTH_ALIVE);
//    DelayCommand(3.0, SetLocalInt(oPC, "LastHitPoints", GetCurrentHitPoints(oPC)));
    SetLocalInt(oPC, "LastHitPoints", GetCurrentHitPoints(oPC));
    AssignCommand(oPC,JumpToLocation(GetLocation(oSpawnPoint)));

}


