//::///////////////////////////////////////////////
//:: Custom User Defined Event
//:: FileName
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*

*/
//:://////////////////////////////////////////////
//:: Created By:
//:: Created On:
//:://////////////////////////////////////////////

void main()
{
    int nUser = GetUserDefinedEventNumber();


    if(nUser == 1001) //HEARTBEAT
    {
        if (!(IsInConversation(OBJECT_SELF)))
        {
            int nCurrentTask = GetLocalInt(OBJECT_SELF, "nCurrentUDEvent");
            if ((nCurrentTask == 20) || (nCurrentTask == 60))
            {
                if (Random(8) < 2)
                {
                    ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(nCurrentTask + 10)));
                }
                else
                {
                    if (GetDistanceToObject(GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC)) > 5.0)
                    {
                        if (nCurrentTask == 20)
                        {
                            DoPlaceableObjectAction(GetObjectByTag("jhr_invis1_epilogue"), PLACEABLE_ACTION_BASH);
                        }
                        else
                        {
                            DoPlaceableObjectAction(GetObjectByTag("jhr_invis2_epilogue"), PLACEABLE_ACTION_BASH);
                        }
                    }
                }
            }
            if (((GetTimeHour() >= 19) || (GetTimeHour() < 6)) && (nCurrentTask != 101))
            {
                if (nCurrentTask != 101)
                {
                    // rest nearby
                    ClearAllActions();
                    ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(101)));
                }
            }
            else
            {
                if (nCurrentTask == 101)
                {
                    // Wake up and start working
                    ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(10)));
                }
            }
        }
    }
    else if(nUser == 1002) // PERCEIVE
    {
        //if (GetIsPC(GetLastPerceived()))
        //{
        //    ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(70)));
        //}
    }
    else if(nUser == 1003) // END OF COMBAT
    {

    }
    else if(nUser == 1004) // ON DIALOGUE
    {

    }
    else if(nUser == 1005) // ATTACKED
    {

    }
    else if(nUser == 1006) // DAMAGED
    {

    }
    else if(nUser == 1007) // DEATH
    {

    }
    else if(nUser == 1008) // DISTURBED
    {

    }
    else if(nUser == 10) // goto wp1
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionMoveToObject(GetObjectByTag("JHR_WP_WOODSMAN1_EPILOGUE"));
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(20)));
    }
    else if(nUser == 20) // attack wp1 invis obj
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        DoPlaceableObjectAction(GetObjectByTag("jhr_invis1_epilogue"), PLACEABLE_ACTION_BASH);
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(30)));
    }
    else if(nUser == 30) // goto woodpile
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionMoveToObject(GetObjectByTag("JHR_WP_WOODPILE_EPILOGUE"));
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(40)));
    }
    else if(nUser == 40) // action low
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 5.0);
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(50)));
    }
    else if(nUser == 50) // goto wp2
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionMoveToObject(GetObjectByTag("JHR_WP_WOODSMAN2_EPILOGUE"));
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(60)));
    }
    else if(nUser == 60) // attack invis obj
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        //ActionAttack(GetObjectByTag("jhr_invis2_epilogue"));
        DoPlaceableObjectAction(GetObjectByTag("jhr_invis2_epilogue"), PLACEABLE_ACTION_BASH);
        //DelayCommand(10.0, ClearAllActions());
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(70)));
    }
    else if(nUser == 70) // goto woodpile
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionMoveToObject(GetObjectByTag("JHR_WP_WOODPILE_EPILOGUE"));
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(80)));
    }
    else if(nUser == 80) // action low
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionPlayAnimation(ANIMATION_LOOPING_GET_LOW, 1.0, 5.0);
        ActionDoCommand(SignalEvent(OBJECT_SELF, EventUserDefined(10)));
    }
    else if(nUser == 101) // night
    {
        SetLocalInt(OBJECT_SELF, "nCurrentUDEvent", nUser);
        ActionMoveToObject(GetObjectByTag("WP_WOODSMAN_NIGHT_EPILOGUE"));
        ActionPlayAnimation(ANIMATION_LOOPING_SIT_CROSS, 1.0);
    }
}

