Example #1
0
    int workOutNumberOfDaysSince(DateTimeStore date)
    {
        int month  = date.month;
        int day    = date.day;
        int retVal = TimeScript.me.howManyHoursHavePassed(0, day, month, TimeScript.me.year);

        /*if (date.month < TimeScript.me.month) {
         *      while (month != TimeScript.me.month) {
         *              numberOfDays += TimeScript.me.daysInMonth [month];
         *              day = 0;
         *              month++;
         *      }
         * }
         *
         *
         * if (date.month > TimeScript.me.month) {
         *      if (date.year < TimeScript.me.year) {
         *              numberOfDays += 365;
         *      }
         * }
         *
         * if (date.month == TimeScript.me.month) {
         *      if (day < TimeScript.me.day) {
         *              while (day < TimeScript.me.day) {
         *                      numberOfDays++;
         *                      day++;
         *              }
         *      }
         * }*/

        return(retVal / 24);
    }
    public void addIncident(string name, Vector3 position)
    {
        if (incidents == null)
        {
            incidents = new List <string> ();
        }

        if (incidentPositions == null)
        {
            incidentPositions = new List <Vector3> ();
        }

        if (datesOfIncidents == null)
        {
            datesOfIncidents = new List <DateTimeStore> ();
        }


        incidents.Add(name);
        incidentPositions.Add(position);
        DateTimeStore d = new DateTimeStore();

        d.min   = TimeScript.me.minute;
        d.hour  = TimeScript.me.hour;
        d.day   = TimeScript.me.day;
        d.month = TimeScript.me.month;
        d.year  = TimeScript.me.year;
        datesOfIncidents.Add(d);
    }
Example #3
0
    bool shouldWeReactToIncident(DateTimeStore date)
    {
        bool retVal = true;

        int value = workOutNumberOfDaysSince(date);

        //Debug.Log ("Incident occured " + value + " days ago");
        return(value <= timeLimit);
    }
    public List <string> getIncidentsAsFile()
    {
        List <string> retVal = new List <string> ();

        for (int x = 0; x < incidents.Count; x++)
        {
            string        toAdd = "";
            DateTimeStore d     = datesOfIncidents [x];
            toAdd += incidents [x] + ";" + incidentPositions [x].ToString() + ";" + d.min + ";" + d.hour + ";" + d.day + ";" + d.month + ";" + d.year;
            retVal.Add(toAdd);
        }
        return(retVal);
    }
Example #5
0
    int workOutNumberOfDaysSince()
    {
        DateTimeStore date = new DateTimeStore();

        date.day   = this.day;
        date.month = this.month;
        date.year  = this.year;
        date.min   = 0;
        date.hour  = 0;
        int numberOfDays = 0;
        int month        = date.month;
        int day          = date.day;


        if (date.month > TimeScript.me.month)
        {
            if (date.year < TimeScript.me.year)
            {
                numberOfDays += (date.month + 1) * 30;
            }
        }

        if (date.month < TimeScript.me.month)
        {
            while (month != TimeScript.me.month)
            {
                numberOfDays += TimeScript.me.daysInMonth [month];
                day           = 0;
                month++;
            }
        }


        if (date.month == TimeScript.me.month)
        {
            if (day < TimeScript.me.day)
            {
                while (day < TimeScript.me.day)
                {
                    numberOfDays++;
                    day++;
                }
            }
        }
        //Debug.Log ("Number of days since effect started is" + numberOfDays);
        return(numberOfDays);
    }
    public void reAddIncident(string name, Vector3 position, DateTimeStore date)
    {
        if (incidents == null)
        {
            incidents = new List <string> ();
        }

        if (incidentPositions == null)
        {
            incidentPositions = new List <Vector3> ();
        }

        if (datesOfIncidents == null)
        {
            datesOfIncidents = new List <DateTimeStore> ();
        }

        //Debug.LogError ("Incident " + name + " re added");
        incidents.Add(name);
        incidentPositions.Add(position);

        datesOfIncidents.Add(date);
    }
Example #7
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();
            }
        }
    }