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

#include "nw_i0_plot"
#include "bleeding_config"
#include "jhr_i0_partyfunc"

void main() {
    object oPC = GetLastRespawnButtonPresser();

    // Heal them and remove any nasty effects
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),oPC);
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(GetMaxHitPoints(oPC)), oPC);
    RemoveEffects(oPC);

    // Mark them as alive once again
    SetLocalInt(oPC, "PlayerHealth", PC_HEALTH_ALIVE);

    location lRespawnLoc;
    if (GetLocalInt(oPC, "nInBattleFlag") == 1) {
        // If in Vethboro battle scene, respawn there
        lRespawnLoc= GetLocation(GetObjectByTag("JHR_WP_BATTLERESPAWN"));

    }
    else
    {
        if (TestPartyLocalInt(oPC, "nSpokeToHaspaarFlag", 1, 0))
        {
            // If spoke with Haspaar, respawn in his cave
            lRespawnLoc= GetLocation(GetObjectByTag("jhr_wp_respawn_dragon"));
            if (GetLocalInt(GetModule(), "nEpilogeFlag") == 1)
            {
                // If in the epilogue, respawn normally at inn
                lRespawnLoc= GetLocation(GetObjectByTag("jhr_wp_respawn"));
            }
        }
        else
        {
            // normal respawn at the inn
            lRespawnLoc= GetLocation(GetObjectByTag("jhr_wp_respawn"));
        }
    }
    AssignCommand(oPC, JumpToLocation(lRespawnLoc));
}

