//::///////////////////////////////////////////////
//:: FileName jhr_at_setepilog
//:://////////////////////////////////////////////
//:://////////////////////////////////////////////
//:: Created By: Script Wizard
//:: Created On: 7/11/2002 2:35:05 AM
//:://////////////////////////////////////////////
#include "nw_i0_plot"
#include "bleeding_config"

void RewardPartyXP(int XP, object oTarget,int bAllParty=TRUE)
{
    // * for each party member
    // * cycle through them and
    // * and give them the appropriate reward
    // * HACK FOR NOW
    if (bAllParty == TRUE)
    {
        object oPartyMember = GetFirstFactionMember(oTarget, TRUE);
        while (GetIsObjectValid(oPartyMember) == TRUE)
        {
            GiveXPToCreature(oPartyMember, XP);
            oPartyMember = GetNextFactionMember(oTarget, TRUE);
        }
    }
    else
    {
     GiveXPToCreature(oTarget, XP);
    }
}

void main()
{
    SetLocalInt(GetModule(), "nEpilogeFlag", 1);
    CreateObject(OBJECT_TYPE_CREATURE, "jhr_ct_barfly1", GetLocation(GetObjectByTag("JHR_BARFLY1_SPAWN")));
    CreateObject(OBJECT_TYPE_CREATURE, "jhr_ct_barfly2", GetLocation(GetObjectByTag("JHR_BARFLY2_SPAWN")));
    CreateObject(OBJECT_TYPE_CREATURE, "jhr_ct_barfly3", GetLocation(GetObjectByTag("JHR_BARFLY3_SPAWN")));
    CreateObject(OBJECT_TYPE_CREATURE, "jhr_ct_barfly4", GetLocation(GetObjectByTag("JHR_BARFLY4_SPAWN")));
    object oPC = GetPCSpeaker();
    object oPartyMember = GetFirstFactionMember(oPC, TRUE);
    // move time forward to next day at 1pm
    int nNextMorning = 24 - (GetTimeHour() - 13);
    SetTime(GetTimeHour() + nNextMorning,  0, 0, 0);
    while (GetIsObjectValid(oPartyMember) == TRUE)
    {
        ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectHeal(GetMaxHitPoints(oPartyMember)), oPartyMember);
        RemoveEffects(oPartyMember);
        // Mark  as alive once again in case PC is bleeding while friend is conversing (some friend :) )
        SetLocalInt(oPartyMember, "PlayerHealth", PC_HEALTH_ALIVE);
        AssignCommand(oPartyMember, ActionJumpToObject(GetObjectByTag("WP_EPILOGE_START")));
        SendMessageToPC(oPartyMember, "You make your way to the inn for some rest. A full evening passes while you tend to your wounds and reflect upon recent events. You finally emerge from your room in the early afternoon.");
        SendMessageToPC(oPartyMember, "A warm sense of accomplishment comes over you...You know that, for now at least, this one small part of Faerun is safer and happier due to your hard work and courage.");
        oPartyMember = GetNextFactionMember(oPC, TRUE);
        // Respawn back at the inn again
        SetLocalInt(oPartyMember, "nInBattleFlag", 0);

    }
    // clucky follows owner PC
    object oChicken = GetObjectByTag("jhr_chicken");
    if (GetIsObjectValid(oChicken))
    {

        if (GetLocalInt(GetModule(), "nCluckyActiveFlag") == 1)
        {
            RewardPartyXP(250, GetLocalObject(oChicken, "oOwner"));
            SendMessageToPC(GetLocalObject(oChicken, "oOwner"), "You earn a 250 XP bonus for managing to keep Clucky alive this long!");
            AssignCommand(oChicken, ClearAllActions());
            AssignCommand(oChicken, ActionJumpToObject(GetObjectByTag("WP_EPILOGE_START")));
        }
    }

    // Destroy Ragan and Gifford from original Vethboro in case they are inside their
    // homes when the party reaches the epilogue
    DestroyObject(GetObjectByTag("Farmer01"));
    DestroyObject(GetObjectByTag("JHR_WOODSMAN"));

    SignalEvent(GetObjectByTag("JHR_WOODSMAN_EPILOGUE"), EventUserDefined(10));

}
