Esempio n. 1
0
    public void createIncidentReaction(int min, int hour, int day, int month, int year, Vector3 pos)
    {
        DateTimeStore date = new DateTimeStore();

        date.min   = min;
        date.hour  = hour;
        date.day   = day;
        date.month = month;
        date.year  = year;
        if (shouldWeReactToIncident(date) == true)
        {
            LevelIncidentController.me.reAddIncident(incidentName, pos, date);
            GameObject g        = getRelevantGameObject(pos);
            GameObject toCreate = getObjectToCreate();
            GameObject obj      = null;
            if (toCreate != null)
            {
                obj = (GameObject)Instantiate(toCreate, g.transform.position, Quaternion.Euler(0, 0, g.transform.rotation.eulerAngles.z));
                //create the stuff, find area for misc objects
            }

            if (incidentName == "Window")
            {
                obj.GetComponent <DoorScript> ().doorOpenSpeed   = 0.0f;
                obj.GetComponent <DoorScript> ().doorSoundEffect = null;
                if (objectToCreate == null)
                {
                }
                else
                {
                    createObject(pos);
                }
            }
            else if (incidentName == "FireExit" || incidentName == "GlassDoor" || incidentName == "WoodDoor")
            {
                DoorScript ds = obj.GetComponent <DoorScript> ();
                ds.doorOpenSpeed /= 2;
                if (objectToCreate == null)
                {
                }
                else
                {
                    createObject(pos);
                }
            }
            else if (incidentName == "Robbery")
            {
                RoomScript    r      = LevelController.me.getRoomPosIsIn(pos);
                LightSource[] lights = FindObjectsOfType <LightSource>();
                if (r == null)
                {
                    foreach (GameObject g2 in optionalObjectsToCreate)
                    {
                        int r2 = Random.Range(0, 6);
                        for (int x2 = 0; x2 < r2; x2++)
                        {
                            Vector3 pos2 = pos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0);
                            Instantiate(g2, pos2, Quaternion.Euler(0, 0, Random.Range(0.0f, 1.0f)));
                        }
                    }

                    foreach (LightSource l in lights)
                    {
                        if (Vector2.Distance(l.transform.position, pos) < 15.0f)
                        {
                            l.lightOn = false;
                        }
                    }
                }
                else
                {
                    foreach (roomRect r3 in r.rectsInRoom)
                    {
                        float blx = r3.bottomLeft.transform.position.x;
                        float bly = r3.bottomLeft.transform.position.y;
                        float trx = r3.topRight.transform.position.x;
                        float trY = r3.topRight.transform.position.y;

                        foreach (GameObject g2 in optionalObjectsToCreate)
                        {
                            int r2 = Random.Range(0, 6);
                            for (int x2 = 0; x2 < r2; x2++)
                            {
                                Vector3 pos2 = new Vector3(Random.Range(blx, trx), Random.Range(bly, trY), 0);
                                Instantiate(g2, pos2, Quaternion.Euler(0, 0, Random.Range(0.0f, 1.0f)));
                            }
                        }
                    }

                    foreach (LightSource l in lights)
                    {
                        RoomScript lr = LevelController.me.getRoomPosIsIn(l.transform.position);
                        if (lr == r)
                        {
                            l.lightOn = false;
                        }
                    }
                }
                if (objectToCreate == null)
                {
                }
                else
                {
                    createObject(pos);
                }
            }
            else if (incidentName == "Fire")
            {
                BuildingScript b = LevelController.me.getBuildingPosIsIn(pos);
                if (b == null)
                {
                }
                else
                {
                    b.buildingClosed = true;
                }
                int r = Random.Range(3, 8);
                for (int x = 0; x < r; x++)
                {
                    Vector3 pos2 = pos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0);
                    Instantiate(objectToCreate, pos2, Quaternion.Euler(0, 0, 0));
                }

                if (TimeScript.me.howManyHoursHavePassed(hour, day, month, year) > 72)
                {
                    foreach (GameObject g2 in optionalObjectsToCreate)
                    {
                        int chance = Random.Range(0, 100);
                        if (chance < 5)
                        {
                            Vector3 pos2 = pos + new Vector3(Random.Range(-5, 5), Random.Range(-5, 5), 0);
                            // Instantiate(g2, pos, Quaternion.Euler(0, 0, 0));
                            createObject(g, pos2);
                        }
                    }
                }
            }
            else if (incidentName == "Murder")
            {
                Instantiate(objectToCreate, pos, Quaternion.Euler(0, 0, Random.Range(0.0f, 1.0f)));
                BuildingScript b = LevelController.me.getBuildingPosIsIn(pos);
                if (b == null)
                {
                }
                else
                {
                    b.buildingClosed = true;
                }
            }
        }
        else
        {
            //destoy save date relating to incident and the destroyed stuff is reset.
            if (incidentName == "Window")
            {
                GameObject g  = getRelevantGameObject(pos);
                WindowNew  wn = g.GetComponent <WindowNew> ();
                //stop it displaying the smashed window
                //re enable window script, mesh and collider
                wn.window.SetActive(true);
                wn.destroyed.SetActive(false);
                wn.windowDestroyed = false;
                wn.windowClosedCol.SetActive(true);
                wn.initilised = false;
                wn.callStart();
            }
            else if (incidentName == "FireExit" || incidentName == "GlassDoor" || incidentName == "WoodDoor")
            {
                GameObject g  = getRelevantGameObject(pos);
                DoorScript ds = g.GetComponent <DoorScript> ();
                ds.enabled = true;
                ds.doorMesh.SetActive(true);
                Destroy(g.GetComponent <SpriteRenderer> ());
                ds.doorHealth = 5;
                Shadow s = g.GetComponent <Shadow> ();
                g.GetComponent <BoxCollider2D> ().enabled = true;

                foreach (GameObject gs in s.myShadows)
                {
                    Destroy(gs.gameObject);
                }
                Destroy(s);
                ds.setDoorActions();
            }
        }
    }