示例#1
0
 public void NewWeatherEvent(WeatherEvent gameEvent)
 {
     if (OnNewWeatherEvent != null)
     {
         OnNewWeatherEvent(gameEvent);
     }
 }
        public int LogWeatherEvent(DateTime datetime, WeatherType type, bool happy,
                                   string name, string quote)
        {
            //This controller method demonstrates that DbSet Add behaves the same
            //as EF6: affecting every item in a [disconnected] graph with the same state
            //As well as Attach, Remove and the new Update.

            WeatherEvent wE;

            if (String.IsNullOrEmpty(name))
            {
                wE = WeatherEvent.Create(datetime, type, happy);
            }
            else
            {
                wE = WeatherEvent.Create(datetime, type, happy,
                                         new List <string[]> {
                    new[] { name, quote }
                });
            }
            _context.WeatherEvents.Add(wE);
            var affectedRowCount = _context.SaveChanges();

            return(affectedRowCount);
        }
        internal void UpdateWeatherEventOnly(WeatherEvent weatherEvent)
        {
            //even if this is a graph, only root will get touched
            _context.Entry(weatherEvent).State = EntityState.Modified;
            _context.SaveChanges();

        }
示例#4
0
    protected void Update()
    {
        //Convert position to 2D for the queries to the weather system
        Vector2 position = new Vector2(transform.position.x, transform.position.z);

        //Get the current weather event and its associated properties
        WeatherEvent      weatherEvent = weatherManager.GetWeatherEventAt(position);
        WeatherProperties properties   = weatherEvent.Properties;

        float?intensity = properties.EvaluateIntensityData(this.PropertyParent, weatherEvent.WeatherPropertiesIntensityCurves, weatherManager.GetIntensityValueAt(position));

        if (intensity == null)
        {
            Debug.LogError("Intensity value could not be found");
            return;
        }

        //This is driven by precipitation, so we want the inverse intensity of that
        float fireIntensity = 1f - (float)intensity;

        //Change look of fire based on the intensity
        ParticleSystem.EmissionModule emission = fireParticleEffect.emission;
        emission.rateOverTime = fireIntensity * 10;

        ParticleSystem.MainModule mainModule = fireParticleEffect.main;
        mainModule.startLifetime = fireIntensity * 5f;
    }
示例#5
0
 private void OnHandler1(object sender, WeatherEvent e)
 {
     if (InvokeRequired)
     {
         ResultsDisplay.Invoke((MethodInvoker) delegate { ResultsDisplay.Text += e.Message + Environment.NewLine; });
     }
 }
 private static void LogEvent(WeatherEvent weatherEvent)
 {
     Console.WriteLine("Received weather event:");
     Console.WriteLine($"Location: {weatherEvent.LocationName}");
     Console.WriteLine($"Temperature: {weatherEvent.Temperature}");
     Console.WriteLine($"Latitude: {weatherEvent.Latitude}");
     Console.WriteLine($"Longitude: {weatherEvent.Longitude}");
 }
        private void PublishToSns(WeatherEvent weatherEvent)
        {
            var response = _sns.PublishAsync(_snsTopic, JsonSerializer.Serialize(weatherEvent)).Result;

            if (response.HttpStatusCode != HttpStatusCode.OK)
            {
                Console.WriteLine($"Failed to publish weather event for {weatherEvent.LocationName}");
            }
        }
示例#8
0
    private void showWeatherEvent(int index)
    {
        WeatherEvent weatherEvent = weatherEventList[index];

        producing      = 0;
        totalProducing = 0;

        for (int i = 0; i < FindObjectOfType <ProducerMarketController>().installedBuildingList.Count; i++)
        {
            FindObjectOfType <ProducerMarketController>().installedBuildingList[i].production = FindObjectOfType <ProducerMarketController>().buildingList[i].production * FindObjectOfType <ProducerMarketController>().installedBuildingList[i].amount;
            FindObjectOfType <ProducerMarketController>().installedBuildingList[i].behaviour  = 0;

            if (weatherEvent.id != 0)
            {
                for (int j = 0; j < weatherEvent.buildingIds.Length; j++)
                {
                    if (FindObjectOfType <ProducerMarketController>().installedBuildingList[i].id == weatherEvent.buildingIds[j])
                    {
                        double change = FindObjectOfType <ProducerMarketController>().installedBuildingList[i].production * weatherEvent.behaviour[j] / 100;
                        FindObjectOfType <ProducerMarketController>().installedBuildingList[i].production += (int)change;
                        FindObjectOfType <ProducerMarketController>().installedBuildingList[i].behaviour   = (int)weatherEvent.behaviour[j];
                    }
                }
            }
            producing      += FindObjectOfType <ProducerMarketController>().installedBuildingList[i].production;
            totalProducing += FindObjectOfType <ProducerMarketController>().installedBuildingList[i].production;
        }

        for (int j = 0; j < FindObjectOfType <ProducerContractController>().contractList.Count; j++)
        {
            if (FindObjectOfType <ProducerContractController>().ongoingContractsList.ContainsKey(j))
            {
                producing -= FindObjectOfType <ProducerContractController>().ongoingContractsList[j].amountSold;
            }
        }

        if (totalProducing < 0)
        {
            totalProducing = 0;
        }

        producingTxt.text      = producing.ToString();
        totalProducingTxt.text = totalProducing.ToString();

        WeatherPopUp.GetComponentsInChildren <Text>()[0].text = weatherEvent.title;
        WeatherPopUp.GetComponentsInChildren <Text>()[1].text = weatherEvent.desc;

        WeatherPopUp.GetComponentInChildren <Button>().onClick.RemoveAllListeners();
        WeatherPopUp.GetComponentInChildren <Button>().onClick.AddListener(() => WeatherPopUp.SetActive(false));

        WeatherPopUp.SetActive(true);
        FindObjectOfType <ProducerMarketController>().UpdateBuilding(FindObjectOfType <ProducerMarketController>().mode);
        rndWeatherIndex = random.Next(0, weatherEventList.Count);
    }
    public void ChangeWeather()
    {
        int randomEventIndex = Random.Range(0, eventManager.weatherSpriteObjects.Count);

        SpriteObject eventObject = eventManager.weatherSpriteObjects[randomEventIndex];

        WeatherEvent newWeather = new WeatherEvent(eventObject);

        currentWeather = newWeather;

        eventManager.NewWeatherEvent(newWeather);
    }
示例#10
0
        private List <WeatherEvent> BuildWeatherEvents()
        {
            var events = new List <WeatherEvent>
            {
                WeatherEvent.Create(DateTime.Now, WeatherType.Sun, true),
                WeatherEvent.Create(DateTime.Now.AddDays(-1), WeatherType.Snow, true),
                WeatherEvent.Create(DateTime.Now.AddDays(-2), WeatherType.Rain, false),
                WeatherEvent.Create(DateTime.Now.AddDays(-3), WeatherType.Sleet, false),
                WeatherEvent.Create(DateTime.Now.AddDays(-4), WeatherType.Hail, false),
                WeatherEvent.Create(DateTime.Now.AddDays(-5), WeatherType.Snow, false),
                WeatherEvent.Create(DateTime.Now, WeatherType.Rain, false)
            };

            return(events);
        }
示例#11
0
        private static WeatherEvent[] BuildWeatherEvents()
        {
            var events = new WeatherEvent[]
            {
                WeatherEvent.Create(DateTime.Now, WeatherType.Sun, true,
                                    new List <string[]> {
                    new [] { "Julie", "Oh so sunny!" }
                }),
                WeatherEvent.Create(DateTime.Now.AddDays(-1), WeatherType.Snow, true),
                WeatherEvent.Create(DateTime.Now.AddDays(-2), WeatherType.Rain, false),
                WeatherEvent.Create(DateTime.Now.AddDays(-3), WeatherType.Sleet, false,
                                    new List <string[]> {
                    new [] { "Julie", "WAT? No snow? I want to ski!" },
                    new [] { "Everyone in vermont", "Bring us the snow!" },
                    new [] { "Julie", "Ah rain! Good for the flowers!" },
                }),
                WeatherEvent.Create(DateTime.Now.AddDays(-4), WeatherType.Hail, false),
                WeatherEvent.Create(DateTime.Now.AddDays(-5), WeatherType.Snow, true),
                WeatherEvent.Create(DateTime.Now.AddDays(-6), WeatherType.Snow, true),
            };

            return(events);
        }
    private void OnNewWeatherEvent(GameEvent gameEvent)
    {
        WeatherEvent newWeather = gameEvent as WeatherEvent;

        weatherImage.sprite = newWeather.image;
    }
示例#13
0
        protected static void OnWeather(Event e)
        {
            WeatherEvent weatherEvent = e as WeatherEvent;

            if (weatherEvent == null)
            {
                return;
            }

            if (Household.ActiveHousehold == null)
            {
                return;
            }

            if (Household.ActiveHousehold.LotHome == null)
            {
                return;
            }

            /*
             * switch (weatherEvent.Weather)
             * {
             *  case Weather.Rain:
             *  case Weather.Hail:
             *      foreach (Plant plant in Household.ActiveHousehold.LotHome.GetObjects<Plant>())
             *      {
             *          if ((!plant.IsOutside) || (SeasonsManager.IsShelteredFromPrecipitation(plant))) continue;
             *
             *          if (plant.WaterLevel < 100)
             *          {
             *              plant.WaterLevel = 100;
             *          }
             *      }
             *      break;
             * }
             */
            switch (weatherEvent.Weather)
            {
            case Weather.Hail:
                foreach (Plant plant in Household.ActiveHousehold.LotHome.GetObjects <Plant>())
                {
                    if ((!plant.IsOutside) || (SeasonsManager.IsShelteredFromPrecipitation(plant)))
                    {
                        continue;
                    }

                    if (RandomUtil.RandomChance(Tempest.Settings.mHailKillsPlants))
                    {
                        plant.SetDead();
                    }
                }
                break;
            }

            switch (weatherEvent.Weather)
            {
            case Weather.Hail:
            case Weather.Snow:
                foreach (HarvestPlant plant in Sims3.Gameplay.Queries.GetObjects <HarvestPlant>())
                {
                    if ((!plant.IsOutside) || (SeasonsManager.IsShelteredFromPrecipitation(plant)))
                    {
                        continue;
                    }

                    if (RandomUtil.RandomChance(Tempest.Settings.mHailKillsHarvestables))
                    {
                        HarvestPlant harvest = plant as HarvestPlant;
                        if (harvest != null)
                        {
                            harvest.SetGrowthStateFromHarvestToNext();
                        }
                    }
                }
                break;
            }
        }
 internal void UpdateWeatherEventOnly(WeatherEvent weatherEvent)
 {
     //even if this is a graph, only root will get touched
     _context.Entry(weatherEvent).State = EntityState.Modified;
     _context.SaveChanges();
 }
示例#15
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            WeatherEvent weatherEvent = (WeatherEvent)target;

            //Draw default weatherType field
            FieldInfo weatherTypeField = typeof(WeatherEvent).GetField("weatherType", BindingFlags.Instance | BindingFlags.NonPublic);

            DrawField(weatherTypeField, serializedObject);

            //Draw default customProperties field
            FieldInfo weatherPropertiesField = typeof(WeatherEvent).GetField("customProperties", BindingFlags.Instance | BindingFlags.NonPublic);

            if (weatherPropertiesField == null)
            {
                throw new ArgumentException("WeatherEvent has no customProperties field");
            }
            DrawField(weatherPropertiesField, serializedObject); //draw default property field for customProperties from the serialized property

            //if there is an assigned weather properties, grab it
            WeatherProperties weatherProperties = (WeatherProperties)weatherPropertiesField.GetValue(weatherEvent);

            //check there is one - if there is we do curve stuff, otherwise display a label to tell user to assign one....
            if (weatherProperties != null)
            {
                FieldInfo                nonRealiantPropertiesField  = typeof(WeatherProperties).GetField("weatherProperties", BindingFlags.Instance | BindingFlags.NonPublic);
                FieldInfo                realiantPropertiesField     = typeof(WeatherProperties).GetField("reliantWeatherProperties", BindingFlags.Instance | BindingFlags.NonPublic);
                WeatherProperty[]        weatherPropertyArray        = (WeatherProperty[])nonRealiantPropertiesField.GetValue(weatherProperties);
                ReliantWeatherProperty[] reliantWeatherPropertyArray = (ReliantWeatherProperty[])realiantPropertiesField.GetValue(weatherProperties);

                FieldInfo        curvesField = typeof(WeatherEvent).GetField("curves", BindingFlags.Instance | BindingFlags.NonPublic);
                AnimationCurve[] curves      = (AnimationCurve[])curvesField.GetValue(weatherEvent);

                int curvesLength = weatherPropertyArray.Length + reliantWeatherPropertyArray.Length;
                if (curves == null) //first time with this object, need to add new curves for editing
                {
                    curves = new AnimationCurve[curvesLength];

                    for (int i = 0; i < curves.Length; i++)
                    {
                        curves[i] = GetDefaultCurve();
                    }
                }

                //need to lengthen or shorten array (or fix a null element)
                if (curves.Length != curvesLength || curves.Contains(null)) //number of properties has changed etc
                {
                    AnimationCurve[] newCurves = new AnimationCurve[curvesLength];
                    if (curves.Length < curvesLength) //less curves than expected...
                    {
                        for (int i = 0; i < curvesLength; i++)
                        {
                            if (i < curves.Length && curves[i] != null) //so fill the curves we have (and replace null elements)
                            {
                                newCurves[i] = curves[i];
                            }
                            else //for the rest, create a new curve
                            {
                                newCurves[i] = GetDefaultCurve();
                            }
                        }
                    }
                    else //null elements or longer than expected
                    {
                        for (int i = 0; i < curvesLength; i++)
                        {
                            if (curves[i] == null) //replace null elements with defaults
                            {
                                newCurves[i] = GetDefaultCurve();
                            }
                            else //fill the rest with the current curves
                            {
                                newCurves[i] = curves[i];
                            }
                        }
                    }
                    curves = newCurves;
                }

                GUILayout.Label("");
                curves = DrawWeatherPropertyCurveArray(weatherPropertyArray, curves, 0, "No weather properties");
                GUILayout.Label("");
                curves = DrawWeatherPropertyCurveArray(reliantWeatherPropertyArray, curves, weatherPropertyArray.Length, "No reliant weather properties");

                //Save curves back to the object
                curvesField.SetValue(weatherEvent, curves);
            }
            else
            {
                GUILayout.Label("No assigned weather properties, assign one to edit intensity curves");
            }
            EditorUtility.SetDirty(weatherEvent);
            serializedObject.ApplyModifiedProperties();
        }