public bool interact(NPCroutine npc)
 {
     if (disableInteract)
     {
         return(false);
     }
     //going to pretend that it's like gaurd 3 has a unique key for this door, but really he's the only one who can unlock it
     if (npc.GetComponent <NPCgaurd3script>() != null)
     {
         if (locked)
         {
             detector.enabled = true;
             locked           = false;
             lockSignal.GetComponent <MeshRenderer>().material = unlockedMat;
         }
         else
         {
             gate.transform.position = gameObject.transform.position;
             detector.enabled        = false;
             locked = true;
             lockSignal.GetComponent <MeshRenderer>().material = lockedMat;
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #2
0
    void Update()
    {
        if (!ejected)
        {
            if (GetComponentInParent <NPCroutine>().ownKey)
            {
                goldKey.enabled = true;
            }
            else
            {
                goldKey.enabled = false;
            }
        }

        if (ejected)
        {
            theBOX.text = " ";
        }

        if (Input.GetKeyUp("space"))
        {
            spaceUp = true;
        }
        if (Input.GetKeyDown("space"))
        {
            spaceUp = false;
            if (!spaceBreak)
            {
                spaceBreak = true;

                Collider[] hitObjects = Physics.OverlapSphere(gameObject.transform.position, ghost_radius);
                // print("Touching objects: ");

                GameObject me = null;

                List <GameObject> closeNPCs = new List <GameObject>();
                foreach (Collider c in hitObjects)
                {
                    //print(c.gameObject);

                    if (c.gameObject.tag.Equals("NPC"))
                    {
                        if (!ejected)
                        {
                            if (c.gameObject.Equals(gameObject.transform.parent.gameObject))
                            {
                                me = c.gameObject;
                                continue;
                            }
                        }
                        closeNPCs.Add(c.gameObject);
                    }
                }
                if (me != null)
                {
                    closeNPCs.Add(me);
                }



                GameObject[] NPCarr = closeNPCs.ToArray();

                if (NPCarr.Length != 0)
                {
                    StartCoroutine(pickInhabit(NPCarr));
                }
                else
                {
                    StartCoroutine(noOneAround());
                }

                /*
                 * if (min_NPC != null){
                 *  if (!ejected)
                 *  {
                 *      npc.setAllowControl(false);
                 *      npc.setControl(false);
                 *  }
                 *
                 *  gameObject.transform.position = min_NPC.transform.position;
                 *  gameObject.transform.parent = min_NPC.transform;
                 *  move = GetComponentInParent<CharacterController>();
                 *  npc = GetComponentInParent<NPCroutine>();
                 *  npc.setAllowControl(true);
                 *
                 *  ejected = false;
                 * }
                 * else
                 * {
                 *  print("nothin to control");
                 * }
                 */
            }
        }


        //Disperse
        if (Input.GetKeyDown(KeyCode.L))
        {
            if (!ejected)
            {
                //not already ejected
                npc.setAllowControl(false);
                lastNpc = npc;
                //npc.setControl(false);
                gameObject.transform.parent = null;
                ejected = true;
            }
            else
            {
                //already ejected
                gameObject.transform.position = lastNpc.transform.position;
                gameObject.transform.parent   = lastNpc.transform;
                move = GetComponentInParent <CharacterController>();
                npc  = GetComponentInParent <NPCroutine>();
                npc.setAllowControl(true);
                npc.writeBox();
                ejected = false;
            }
        }

        if (Input.GetKeyDown(KeyCode.K) && npc != null)
        {
            crazyScript crazy = npc.GetComponent <crazyScript>();
            if (crazy != null)
            {
                Collider[] hitObjects = Physics.OverlapSphere(gameObject.transform.position, ghost_radius);
                // print("Touching objects: ");
                float      min_dist = float.MaxValue;
                GameObject min_NPC  = null;

                foreach (Collider c in hitObjects)
                {
                    //print(c.gameObject);
                    if (c.gameObject.tag.Equals("NPC"))
                    {
                        if (!ejected)
                        {
                            if (c.gameObject.Equals(gameObject.transform.parent.gameObject))
                            {
                                continue;
                            }
                        }

                        float t = Vector3.Magnitude(c.gameObject.transform.position - gameObject.transform.position);
                        if (t < min_dist)
                        {
                            min_dist = t;
                            min_NPC  = c.gameObject;
                        }
                    }
                }
                if (min_dist > 5)
                {
                    print("nothin to fight");
                    return;
                }
                print("fighting: " + min_NPC);
                crazy.goCrazy(min_NPC);
            }
        }

        if (Input.GetKeyDown(KeyCode.J))
        {
            if (ejected)
            {
                return;
            }
            if (GetComponentInParent <NPCroutine>().cuffed)
            {
                return;
            }
            Collider[] hitObjects = Physics.OverlapSphere(gameObject.transform.position, ghost_radius);
            // print("Touching objects: ");
            float      min_dist = float.MaxValue;
            GameObject min_mat  = null;

            foreach (Collider c in hitObjects)
            {
                //print(c.gameObject);

                if (c.gameObject.tag.Equals("mat"))
                {
                    if (c.gameObject.Equals(gameObject.transform.parent.gameObject))
                    {
                        continue;
                    }

                    float t = Vector3.Magnitude(c.gameObject.transform.position - gameObject.transform.position);
                    if (t < min_dist)
                    {
                        min_dist = t;
                        min_mat  = c.gameObject;
                    }
                }
                else if (c.gameObject.tag.Equals("gate"))
                {
                    if (c.gameObject.GetComponentInParent <doorScriptGaurd3>() != null)
                    {
                        c.gameObject.GetComponentInParent <doorScriptGaurd3>().interact(GetComponentInParent <NPCroutine>());
                    }
                    else
                    {
                        c.gameObject.GetComponentInParent <doorScript>().interact(GetComponentInParent <NPCroutine>());
                    }

                    //print("gate interacted");
                }
            }

            if (min_mat == null)
            {
                // print("no mats close enough");
            }
            else
            {
                npc.GetComponent <NPCroutine>().matInteract(min_mat);
            }
        }
    }