Ejemplo n.º 1
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         player_detected = true;
     }
 }
Ejemplo n.º 2
0
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         BlackboardEntry entry = null;
         if (memory.TryGetValue("blackboard", out entry))
         {
             entry.timestamp   = Time.time;
             entry.is_inmemory = false;
         }
         else
         {
             entry = new BlackboardEntry(ev.go, ev.go.transform.position);
             memory.Add("blackboard", entry);
             entry.is_inmemory = false;
         }
     }
     else if (ev.type == global::PerceptionEvent.types.LOST)
     {
         BlackboardEntry entry = null;
         if (memory.TryGetValue("blackboard", out entry))
         {
             entry.timestamp   = Time.time;
             entry.is_inmemory = true;
             entry.position    = ev.go.transform.position;
         }
     }
 }
Ejemplo n.º 3
0
    // TODO 3: Capture perception events and add an entry if the player is detected
    // if the player stop from being seen, the entry should be "in the past memory"

    void PerceptionEvent(PerceptionEvent ev)
    {
        if (ev.type == global::PerceptionEvent.types.SEEING)
        {
            if (playerKnowledge.ContainsKey("player"))
            {
                Knowledge aux_player;
                playerKnowledge.TryGetValue("player", out aux_player);
                aux_player.position       = ev.go.transform.position;
                playerKnowledge["player"] = aux_player;
                Debug.Log("Updating");
            }
            else
            {
                Knowledge player = new Knowledge();
                player.target    = ev.go;
                player.position  = ev.go.transform.position;
                player.timestamp = Time.time;
                player.inMemory  = false;

                playerKnowledge.Add("player", player);
                Debug.Log("Creating new one");
            }
        }
        else
        {
            Knowledge aux_player;
            playerKnowledge.TryGetValue("player", out aux_player);
            Debug.Log(aux_player.position);
        }
    }
Ejemplo n.º 4
0
 void SendEventtoListeners(PerceptionEvent event_send)
 {
     foreach (PerceptionListener listener in listeners_list)
     {
         listener.OnEventRecieved(event_send);
     }
 }
Ejemplo n.º 5
0
    // Update is called once per frame
    void Update()
    {
        Collider[] colliders = Physics.OverlapSphere(transform.position, frustum.farClipPlane, mask);
        Plane[]    planes    = GeometryUtility.CalculateFrustumPlanes(frustum);

        detected_now.Clear();

        foreach (Collider col in colliders)
        {
            if (col.gameObject != gameObject && GeometryUtility.TestPlanesAABB(planes, col.bounds))
            {
                RaycastHit hit;
                ray.origin    = transform.position;
                ray.direction = (col.transform.position - transform.position).normalized;
                ray.origin    = ray.GetPoint(frustum.nearClipPlane);
                Debug.DrawLine(ray.origin, ray.direction);
                if (Physics.Raycast(ray, out hit, frustum.farClipPlane, ray_mask))
                {
                    Debug.Log("Player seen");
                    if (hit.collider.gameObject.CompareTag("Visual Emitter"))
                    {
                        detected_now.Add(col.gameObject);
                    }
                    enemy_detected = true;
                }
            }
        }

        //// Compare detected with detected_now -------------------------------------
        foreach (GameObject go in detected_now)
        {
            if (detected.Contains(go) == false)
            {
                PerceptionEvent p_event = new PerceptionEvent();
                p_event.go    = go;
                p_event.type  = PerceptionEvent.types.NEW;
                p_event.sense = PerceptionEvent.senses.VISION;

                SendMessage("PerceptionEvent", p_event);
            }
        }

        foreach (GameObject go in detected)
        {
            if (detected_now.Contains(go) == false)
            {
                PerceptionEvent p_event = new PerceptionEvent();
                p_event.go    = go;
                p_event.type  = PerceptionEvent.types.LOST;
                p_event.sense = PerceptionEvent.senses.VISION;

                SendMessage("PerceptionEvent", p_event);
            }
        }

        detected.Clear();
        detected.AddRange(detected_now);
    }
    public override bool IsPrioritary(PerceptionEvent new_event)
    {
        if (new_event.type >= PERCEPTION_EVENT_TYPE.PLAYER_SEEN)
        {
            return(true);
        }

        return(false);
    }
    public bool IsPriotitaryEvent(PerceptionEvent new_event)
    {
        if (events_in_memory.Count > 0)
        {
            return(events_in_memory[0].IsPrioritary(new_event));
        }

        return(true);
    }
Ejemplo n.º 8
0
    public override void OnEventRecieved(PerceptionEvent event_recieved)
    {
        if (IsPriotitaryEvent(event_recieved) == true)
        {
            ClearEvents();
        }
        else
        {
            return;
        }

        switch (event_recieved.type)
        {
        case PERCEPTION_EVENT_TYPE.HEAR_EXPLORER_EVENT:
        case PERCEPTION_EVENT_TYPE.HEAR_WALKING_PLAYER:
            PerceptionHearEvent tmp = (PerceptionHearEvent)event_recieved;

            if (OnHearRange(tmp) && GetComponent <EnemyShield_BT>().InCombat() == false)
            {
                PerceptionHearEvent event_to_memory = new PerceptionHearEvent(tmp);
                GetComponent <EnemyShield_BT>().heard_something  = true;
                GetComponent <Investigate_Action>().forgot_event = false;
                GetComponent <Investigate_Action>().SetEvent(event_to_memory);
                GetComponent <EnemyShield_BT>().InterruptAction();
                GetComponent <EnemyShield_BT>().SetAction(Action.ACTION_TYPE.INVESTIGATE_ACTION);
                events_in_memory.Add(event_to_memory);
                event_to_memory.start_counting = false;
            }
            break;

        case PERCEPTION_EVENT_TYPE.PLAYER_SEEN:

            PerceptionPlayerSeenEvent seen_event_tmp = (PerceptionPlayerSeenEvent)event_recieved;

            if (gameObject == seen_event_tmp.enemy_who_saw)
            {
                GetComponent <EnemyShield_BT>().InterruptAction();
                GetComponent <EnemyShield_BT>().player_detected = true;

                if (GetComponent <EnemyShield_BT>().InCombat() == false)
                {
                    GetComponent <EnemyShield_BT>().SetAction(Action.ACTION_TYPE.ENGAGE_ACTION);
                }

                player_seen = true;

                PerceptionPlayerSeenEvent new_event_to_memory = new PerceptionPlayerSeenEvent(seen_event_tmp);
                events_in_memory.Add(new_event_to_memory);
                GetComponent <ChasePlayer_Action>().SetEvent(new_event_to_memory);
                GetComponent <ChasePlayer_Action>().forgot_event = false;
                new_event_to_memory.start_counting = false;
            }
            break;
        }
    }
Ejemplo n.º 9
0
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         SeeingObject(ev.gameObject);
     }
     else
     {
         LostVision(ev.gameObject);
     }
 }
Ejemplo n.º 10
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         AddBit(ev.go.name, ev.go);
     }
     else
     {
         BitToMemory(ev.go.name);
     }
 }
Ejemplo n.º 11
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         Alert.SetActive(true);
     }
     else
     {
         Alert.SetActive(false);
     }
 }
 public PerceptionEvent(PerceptionEvent e)
 {
     type              = e.type;
     time_in_memory    = e.time_in_memory;
     objective_tile_x  = e.objective_tile_x;
     objective_tile_y  = e.objective_tile_y;
     origin_tile_y     = e.origin_tile_y;
     origin_tile_x     = e.origin_tile_x;
     counter_in_memory = 0.0f;
     start_counting    = true;
     is_finished       = false;
 }
Ejemplo n.º 13
0
    // TODO 3: Capture perception events and add an entry if the player is detected
    // if the player stop from being seen, the entry should be "in the past memory"

    void Perception(PerceptionEvent ev)
    {
        if (ev.type == global::PerceptionEvent.types.NEW)
        {
            BlackBoard blackBoard = new BlackBoard(ev.go, ev.go.transform.position, Time.time, true, transform.gameObject);
            my_data.Add("OH YES", blackBoard);
        }
        else
        {
            my_data
        }
    }
 void UpdateEvent(PerceptionEvent event_to_update)
 {
     if (event_to_update.counter_in_memory >= event_to_update.time_in_memory)
     {
         OnEventGone(event_to_update);
         event_to_update.is_finished = true;
     }
     else
     {
         event_to_update.counter_in_memory = event_to_update.counter_in_memory + Time.deltaTime;
     }
 }
Ejemplo n.º 15
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         Debug.Log("Saw something NEW: " + ev.go.name);
         Alert.SetActive(true);
     }
     else
     {
         Debug.Log("LOST: " + ev.go.name);
         Alert.SetActive(false);
     }
 }
Ejemplo n.º 16
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         memory.AddEntry(ev.go);
         Debug.Log("Saw something NEW");
         Alert.SetActive(true);
     }
     else
     {
         memory.PastMemChange(ev.go);
         Debug.Log("LOST something");
         Alert.SetActive(false);
     }
 }
Ejemplo n.º 17
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         Debug.Log("Saw something NEW");
         //Alert.SetActive(true);
         player_detected = true;
     }
     else
     {
         Debug.Log("LOST something");
         //Alert.SetActive(false);
         player_detected = false;
     }
 }
Ejemplo n.º 18
0
 // Update is called once per frame
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         memory.AddBlackBoardEntry(ev.go);
         Debug.Log("Saw something NEW");
         Alert.SetActive(true);
     }
     else         // type == OLD
     {
         memory.UpdateBlackBoardEntry(ev.go, true);
         Debug.Log("LOST something");
         Alert.SetActive(false);
     }
 }
Ejemplo n.º 19
0
    void PerceptionEvent(PerceptionEvent ev)
    {
        if (ev.type == global::PerceptionEvent.types.NEW)
        {
            // Something new
            if (blackboard.ContainsKey(ev.go.name))
            {
                // Already in memory
                blackboard[ev.go.name].timestamp = 0.0f;
                blackboard[ev.go.name].position  = ev.go.transform.position;
                blackboard[ev.go.name].inMemory  = false;
            }
            else
            {
                // Something new
                BlackboardEntry entry = new BlackboardEntry();
                entry.gameObject = ev.go;
                entry.position   = ev.go.transform.position;
                entry.timestamp  = 0.0f;
                entry.inMemory   = false;
                entry.from       = gameObject;

                blackboard.Add(entry.gameObject.name, entry);

                if (ev.sense == global::PerceptionEvent.senses.VISION)
                {
                    foreach (AIMemory friend in friends)
                    {
                        if (!friend.blackboard.ContainsKey(ev.go.name))
                        {
                            friend.blackboard.Add(entry.gameObject.name, entry);
                        }
                    }
                }
            }
        }
        else
        {
            // Lost something
            if (blackboard.ContainsKey(ev.go.name))
            {
                // Already in memory
                blackboard[ev.go.name].position = ev.go.transform.position;
                blackboard[ev.go.name].inMemory = true;
            }
        }
    }
    public override void OnEventRecieved(PerceptionEvent event_recieved)
    {
        if (IsPriotitaryEvent(event_recieved) == true)
        {
            ClearEvents();
        }
        else
        {
            return;
        }

        switch (event_recieved.type)
        {
        case PERCEPTION_EVENT_TYPE.HEAR_EXPLORER_EVENT:
        case PERCEPTION_EVENT_TYPE.HEAR_WALKING_PLAYER:

            break;

        case PERCEPTION_EVENT_TYPE.PLAYER_SEEN:

            PerceptionPlayerSeenEvent seen_event_tmp = (PerceptionPlayerSeenEvent)event_recieved;


            if (gameObject.IsEquals(seen_event_tmp.enemy_who_saw))
            {
                GetComponent <Boss_BT>().InterruptAction();
                GetComponent <Boss_BT>().player_detected = true;

                if (GetComponent <Boss_BT>().InCombat() == false)
                {
                    GetComponent <Boss_BT>().SetAction(Action.ACTION_TYPE.ENGAGE_ACTION);
                }

                GetComponent <ChasePlayer_Action>().SetInterupt(false);

                player_seen = true;

                PerceptionPlayerSeenEvent new_event_to_memory = new PerceptionPlayerSeenEvent(seen_event_tmp);
                events_in_memory.Add(new_event_to_memory);
                GetComponent <ChasePlayer_Action>().SetEvent(new_event_to_memory);
                GetComponent <ChasePlayer_Action>().forgot_event = false;
                new_event_to_memory.start_counting = false;
            }
            break;
        }
    }
Ejemplo n.º 21
0
    // Update is called once per frame
    void Update()
    {
        Collider[] hitColliders = Physics.OverlapSphere(gameObject.transform.position, GetComponentInParent <BoxCollider>().size.z / 2);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            if (hitColliders[i].gameObject.CompareTag("SoundEmmiter"))
            {
                PerceptionEvent perception = new PerceptionEvent();
                perception.go    = hitColliders[i].gameObject;
                perception.sense = PerceptionEvent.senses.SOUND;
                perception.type  = PerceptionEvent.types.NEW;

                SendMessage("PerceptionEvent", perception);
            }
            ++i;
        }
    }
Ejemplo n.º 22
0
 void PerceptionEvent(PerceptionEvent ev)
 {
     if (ev.type == global::PerceptionEvent.types.NEW)
     {
         if (ev.sense == global::PerceptionEvent.senses.VISION)
         {
             Nurse_move.movements = NurseMovements.FollowPlayer;
         }
         if (ev.sense == global::PerceptionEvent.senses.SOUND)
         {
             Nurse_move.movements    = NurseMovements.GoToSound;
             Nurse_move.sound_emiter = ev.go;
         }
         else if (ev.go.CompareTag("Nurse"))
         {
             ev.go.GetComponentInParent <Patrol>().gameObject.SetActive(false);
         }
     }
 }
    public override void OnEventGone(PerceptionEvent event_recieved)
    {
        switch (event_recieved.type)
        {
        case PERCEPTION_EVENT_TYPE.HEAR_EXPLORER_EVENT:
        case PERCEPTION_EVENT_TYPE.HEAR_WALKING_PLAYER:

            break;

        case PERCEPTION_EVENT_TYPE.PLAYER_SEEN:
            /*GetComponent<Boss_BT>().player_detected = false;
             * GetComponent<ChasePlayer_Action>().forgot_event = true;
             *
             * if (GetComponent<Boss_BT>().InCombat() == true && GetComponent<PerceptionSightEnemy>().player_seen == false)
             *  GetComponent<Boss_BT>().SetAction(Action.ACTION_TYPE.DISENGAGE_ACTION);*/


            break;
        }
    }
Ejemplo n.º 24
0
    public override void OnEventGone(PerceptionEvent event_recieved)
    {
        switch (event_recieved.type)
        {
        case PERCEPTION_EVENT_TYPE.HEAR_EXPLORER_EVENT:
        case PERCEPTION_EVENT_TYPE.HEAR_WALKING_PLAYER:
            GetComponent <EnemyShield_BT>().heard_something  = false;
            GetComponent <Investigate_Action>().forgot_event = true;
            break;

        case PERCEPTION_EVENT_TYPE.PLAYER_SEEN:
            GetComponent <EnemyShield_BT>().player_detected = false;
            if (GetComponent <EnemyShield_BT>().InCombat() == true)
            {
                GetComponent <EnemyShield_BT>().SetAction(Action.ACTION_TYPE.DISENGAGE_ACTION);
            }
            GetComponent <ChasePlayer_Action>().forgot_event = true;

            Debug.Log("[error]Event gone type:" + event_recieved.type);
            break;
        }
    }
Ejemplo n.º 25
0
 public void GenEvent(PerceptionEvent new_event)
 {
     perception_events_queue.Add(new_event);
 }
 public virtual bool IsPrioritary(PerceptionEvent new_event)
 {
     return(true);
 }
Ejemplo n.º 27
0
 public void SetEvent(PerceptionEvent e)
 {
     event_to_react = e;
 }
 public virtual void OnEventGone(PerceptionEvent event_recieved)
 {
 }
Ejemplo n.º 29
0
    public override void OnEventRecieved(PerceptionEvent event_recieved)
    {
        if (IsPriotitaryEvent(event_recieved) == true)
        {
            ClearEvents();
        }
        else
        {
            return;
        }

        switch (event_recieved.type)
        {
        case PERCEPTION_EVENT_TYPE.HEAR_EXPLORER_EVENT:
        case PERCEPTION_EVENT_TYPE.HEAR_WALKING_PLAYER:
            PerceptionHearEvent tmp = (PerceptionHearEvent)event_recieved;

            if (OnHearRange(tmp) && GetComponent <EnemySword_BT>().InCombat() == false)
            {
                PerceptionHearEvent event_to_memory = new PerceptionHearEvent(tmp);
                GetComponent <EnemySword_BT>().heard_something   = true;
                GetComponent <Investigate_Action>().forgot_event = false;
                GetComponent <Investigate_Action>().SetEvent(event_to_memory);
                GetComponent <EnemySword_BT>().InterruptAction();
                GetComponent <EnemySword_BT>().SetAction(Action.ACTION_TYPE.INVESTIGATE_ACTION);
                events_in_memory.Add(event_to_memory);
                event_to_memory.start_counting = false;
            }
            break;

        case PERCEPTION_EVENT_TYPE.PLAYER_SEEN:

            PerceptionPlayerSeenEvent seen_event_tmp = (PerceptionPlayerSeenEvent)event_recieved;


            if (gameObject.IsEquals(seen_event_tmp.enemy_who_saw))
            {
                if (GetLinkedObject("event_manager").GetComponent <PerceptionManager>().player_seen == false)
                {
                    //PLAY COMBAT MUSIC
                    Audio.ChangeState("MusicState", "Combat");
                    if (Audio.prank)
                    {
                        Audio.ChangeState("MusicState", "AlternateCombat");
                    }
                    GetLinkedObject("event_manager").GetComponent <PerceptionManager>().player_seen = true;
                    Debug.Log("COMBAT ON", Department.PLAYER, Color.ORANGE);
                }

                GetComponent <EnemySword_BT>().InterruptAction();
                GetComponent <EnemySword_BT>().player_detected = true;

                if (GetComponent <EnemySword_BT>().InCombat() == false)
                {
                    GetComponent <EnemySword_BT>().SetAction(Action.ACTION_TYPE.ENGAGE_ACTION);
                }

                GetComponent <ChasePlayer_Action>().SetInterupt(false);

                player_seen = true;

                PerceptionPlayerSeenEvent new_event_to_memory = new PerceptionPlayerSeenEvent(seen_event_tmp);
                events_in_memory.Add(new_event_to_memory);
                GetComponent <ChasePlayer_Action>().SetEvent(new_event_to_memory);
                GetComponent <ChasePlayer_Action>().forgot_event = false;
                new_event_to_memory.start_counting = false;
            }
            break;
        }
    }
Ejemplo n.º 30
0
    void Update()
    {
        List <GameObject> newDetectedEnemies = new List <GameObject>();

        // 1
        Collider[] colliders = Physics.OverlapSphere(transform.position, distance, mask);
        foreach (Collider col in colliders)
        {
            if (col.gameObject == gameObject)
            {
                continue;
            }

            // 2
            Plane[] planes = GeometryUtility.CalculateFrustumPlanes(camera);
            if (GeometryUtility.TestPlanesAABB(planes, col.bounds))
            {
                // 3
                RaycastHit hitInfo;
                Ray        ray = new Ray(transform.position + transform.forward * camera.nearClipPlane, col.gameObject.transform.position - transform.position);
                if (Physics.Raycast(ray, out hitInfo, distance, rayMask))
                {
                    Debug.DrawRay(ray.origin, col.transform.position - transform.position);

                    if (hitInfo.collider.gameObject.CompareTag("Visual Emitter"))
                    {
                        newDetectedEnemies.Add(hitInfo.collider.gameObject);
                    }
                }
            }
        }

        for (int i = detectedEnemies.Count - 1; i >= 0; --i)
        {
            if (!newDetectedEnemies.Contains(detectedEnemies[i]))
            {
                PerceptionEvent perceptionEvent = new PerceptionEvent();
                perceptionEvent.type  = PerceptionEvent.types.LOST;
                perceptionEvent.sense = PerceptionEvent.senses.VISION;
                perceptionEvent.go    = detectedEnemies[i];
                gameObject.SendMessage("PerceptionEvent", perceptionEvent);

                // Lost enemy
                detectedEnemies.RemoveAt(i);
            }
        }

        foreach (GameObject newDetectedEnemy in newDetectedEnemies)
        {
            if (!detectedEnemies.Contains(newDetectedEnemy))
            {
                PerceptionEvent perceptionEvent = new PerceptionEvent();
                perceptionEvent.type  = PerceptionEvent.types.NEW;
                perceptionEvent.sense = PerceptionEvent.senses.VISION;
                perceptionEvent.go    = newDetectedEnemy;
                gameObject.SendMessage("PerceptionEvent", perceptionEvent);

                // New enemy
                detectedEnemies.Add(newDetectedEnemy);
            }
        }
    }