Esempio n. 1
0
    public void nearestSaySomething()
    {
        GameObject obj = getNearestNPC();

        if (obj != null)
        {
            ReactiveAIMK2 ai = obj.GetComponent <ReactiveAIMK2>();

            if (ai.myAnimator.runtimeAnimatorController == ai.noFearController)
            {
                ai.saySomethingGeneral(ai.lowFearThoughts);
            }
            else if (ai.myAnimator.runtimeAnimatorController == ai.lowFearController || ai.myAnimator.runtimeAnimatorController == ai.medFearController)
            {
                ai.saySomethingGeneral(ai.midFearThoughts);
            }
            else if (ai.myAnimator.runtimeAnimatorController == ai.highFearController)
            {
                ai.saySomethingGeneral(ai.highFearThoughts);
            }
        }
        else
        {
            npcs.Remove(obj);
        }
    }
Esempio n. 2
0
    public ReactiveAIMK2 getOneNPC(int depth)
    {
        if (hasAtleastOneNPC())
        {
            return(npcs[0]);
        }
        else if (depth > 0)
        {
            ReactiveAIMK2 tmpNPC = null;
            if (neighbors.Count == 2)
            {
                if (doors[1].isOpen())
                {
                    tmpNPC = neighbors[1].getOneNPC(0);
                }
                if (tmpNPC == null && doors[0].isOpen())
                {
                    tmpNPC = neighbors[0].getOneNPC(0);
                }
            }
            else
            {
                if (doors[0].isOpen())
                {
                    tmpNPC = neighbors[0].getOneNPC(0);
                }
            }
            return(tmpNPC);
        }

        return(null);
    }
 public bool sendNpc(ReactiveAIMK2 newNPC)
 {
     if (!occupied)
     {
         currentNPC = newNPC;
         occupied   = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 4
0
    private void Update()
    {
        if (ringing)
        {
            myTime += Time.deltaTime;
            if (myTime >= ring.length - 1)
            {
                ringing = false;
                animator.SetBool("ringing", ringing);
                myTime    = 0;
                answering = false;
                arrived   = false;
                Debug.Log("Time Killer");
            }
        }
        if (ringing && !answering)
        {
            if (selectedNPC == null)
            {
                Debug.Log("Selected NPC is NULL");
                for (int i = 0; i < scaredNPCS.Count; i++)
                {
                    ReactiveAIMK2 npc = scaredNPCS[i].GetComponent <ReactiveAIMK2>();
                    //NavMeshPath newPath = new NavMeshPath();
                    //bool validPath = npc.myAgent.CalculatePath(npcPosition.position, newPath);

                    if (!npc.stopped)
                    {
                        float tmpDist = Vector3.Distance(npc.transform.position, npcPosition.position);
                        if (tmpDist < dist)
                        {
                            dist        = tmpDist;
                            selectedNPC = npc.gameObject;
                        }
                        else
                        {
                            Debug.Log("tmpDist: " + tmpDist + " >= dis: " + dist);
                        }
                    }
                    else
                    {
                        Debug.Log("a-0");
                        selectedNPC = null;
                        answering   = false;
                        arrived     = false;
                        dist        = 1000000;
                    }
                }
            }
            else
            {
                if (selectedNPC.GetComponent <NavMeshAgent>().destination != npcPosition.position)
                {
                    Debug.Log("a-1");
                    selectedNPC = null;
                    answering   = false;
                    arrived     = false;
                    dist        = 1000000;
                }
            }
            if (selectedNPC != null && !answering)
            {
                Debug.Log("SET NEW PATH");
                selectedNPC.GetComponent <ReactiveAIMK2>().setNewTarget(npcPosition);
                selectedNPC.GetComponent <ReactiveAIMK2>().StartWalk(npcPosition);
                answering = true;
                dist      = 1000000;
            }
        }
        else if (answering && arrived)
        {
            Debug.Log("b-1");
            ringing = false;
            animator.SetBool("ringing", ringing);
            answering = false;
            arrived   = false;
            myAudio.Stop();
            myAudio.PlayOneShot(randomMsg());
            selectedNPC.GetComponent <ReactiveAIMK2>().StopAllCoroutines();
            selectedNPC.GetComponent <ReactiveAIMK2>().myAgent.isStopped = false;
            selectedNPC.GetComponent <ReactiveAIMK2>().stopped           = false;
            selectedNPC.GetComponent <ReactiveAIMK2>().setHeartAttack();
            dist = 1000000;
        }
        else if (answering && selectedNPC != null)
        {
            if (selectedNPC.GetComponent <ReactiveAIMK2>().stopped)
            {
                float tmpDist = Vector3.Distance(selectedNPC.transform.position, npcPosition.position);
                if (tmpDist <= 3)
                {
                    Debug.Log("c-1");
                    arrived = true;
                }

                /*
                 * Debug.Log("c-1");
                 * arrived = true;
                 * ringing = false;
                 * animator.SetBool("ringing", ringing);
                 * answering = false;
                 * arrived = false;
                 * myAudio.Stop();
                 * myAudio.PlayOneShot(randomMsg());
                 * selectedNPC.GetComponent<ReactiveAIMK2>().setHeartAttack();
                 * dist = 1000000;
                 */
            } /*else
               * if (selectedNPC.GetComponent<NavMeshAgent>().destination != npcPosition.position)
               * {
               * Debug.Log("c-2");
               * selectedNPC = null;
               * answering = false;
               * arrived = false;
               * dist = 1000000;
               * }
               *
               * else if(selectedNPC.GetComponent<ReactiveAIMK2>().myAgent.remainingDistance <= 3)
               * {
               * Debug.Log("c-3");
               * arrived = true;
               * ringing = false;
               * animator.SetBool("ringing", ringing);
               * answering = false;
               * arrived = false;
               * myAudio.Stop();
               * myAudio.PlayOneShot(randomMsg());
               * selectedNPC.GetComponent<ReactiveAIMK2>().setHeartAttack();
               * dist = 1000000;
               * }
               */
        }
    }