// THIS SCRIPT IS NO LONGER IN USE
// USE DR_REST!


// This script handles vampires resting

// this returns a formerly dead Vampire to normal.
void vamp_coffin_returnToSelf(object oPC)
{
    // Get the original appearance of the Vampire.
    int iOriginalAppearance = GetCampaignInt("Vampire","Appearance",oPC);

    // If they have died and original appearance equals SOMETHING, then
    // change them back.
    if (GetCampaignInt("Vampire","PermaSpectre",oPC)==TRUE && iOriginalAppearance > 0)
    {
        // reset this boolean
        SetCampaignInt("Vampire","PermaSpectre",FALSE,oPC);
        // change them back.
        PrintString("vamp_coffin: vamp_coffin_returnToSelf() - GetAppearanceType was ["+IntToString(GetAppearanceType(oPC))+"] "+GetName(oPC));
        SetCreatureAppearanceType(oPC, iOriginalAppearance);
        PrintString("vamp_coffin: vamp_coffin_returnToSelf() - GetAppearanceType is now ["+IntToString(GetAppearanceType(oPC))+"] "+GetName(oPC));
    }
}
void main()
{
    // Get resting pc.
    object oPC = GetLastPCRested();
    if (GetImmortal(oPC)==TRUE)
        SetImmortal(oPC,FALSE);

    // If resting pc is vampire and rest event is in start stage
    if (GetLastRestEventType()==REST_EVENTTYPE_REST_STARTED
         &&GetSubRace(oPC)=="Vampire")
    {
        // Get coffin
        string sCoffin = GetPCPublicCDKey(oPC);
        if (sCoffin == "")
        {
            sCoffin = "VampireCoffin";
        }

        object oTarget = GetObjectByTag(sCoffin);
        PrintString("vamp_rest: Looking for this coffin tag ["+sCoffin+"] LITERAL TAG:["+GetTag(oTarget)+"]");

        // If there is no coffin. Inform PC
        if (GetIsObjectValid(oTarget)==FALSE)
        {
            SendMessageToPC(oPC,"There is no coffin nearby. You need to rest in your coffin.");
            // Cancel rest
            AssignCommand(oPC,ClearAllActions());
            PrintString("vamp_rest: Found nothing. TAG:"+GetTag(oTarget));
            return;
        }
        // If distance to coffin is over 3m, inform PC
        else if (GetDistanceBetween(oPC, oTarget) >=3.0f)
        {
            SendMessageToPC(oPC,"There is no coffin nearby. You need to rest in your coffin.");
            // Cancel rest
            AssignCommand(oPC,ClearAllActions());
            PrintString("vamp_rest: Target exists, but is too far away to use. TAG:"+GetTag(oTarget));
            return;
        }
        // Check if vampire has died and he need to rest in his coffin.
        if (GetCampaignInt("Vampire", "VampireMustRest", oPC)==1)
        {
            SendMessageToPC(oPC,"You rest near your coffin.");
            // If yes, vampire has rested and now he dosnt die after 5 hours
            SetCampaignInt("Vampire", "VampireMustRest",0,oPC);
            PrintString("vamp_rest: Vampire must rest set to ZERO.  COFFIN TAG:["+GetTag(oTarget)+"] Resetting vampire appearance as well.");
            // reset the vampire's appearance
            vamp_coffin_returnToSelf(oPC);
        }
    }
}