Esempio n. 1
0
    // Start is called before the first frame update
    void Start()
    {
        /* Zara Initialization code start =======>> */

        ZaraEngine.Helpers.InitializeRandomizer(UnityEngine.Random.Range);

        _dateTime  = DateTime.Now;
        _timeOfDay = TimesOfDay.Evening;
        _health    = new HealthController(this);
        _body      = new BodyStatusController(this);
        _weather   = new WeatherDescription();
        _player    = new PlayerStatus();
        _inventory = new InventoryController(this);

        _body.Initialize();
        _health.Initialize();

        /* <<======= Zara Initialization code end */

        #region Demo app init

        // Let's add some items to the inventory to play with in this demo

        var flaskWithWater = new ZaraEngine.Inventory.Flask();

        flaskWithWater.FillUp(WorldTime.Value);
        //flaskWithWater.Disinfect(WorldTime.Value);

        _jacket = new ZaraEngine.Inventory.WaterproofJacket();
        _pants  = new ZaraEngine.Inventory.WaterproofPants();
        _boots  = new ZaraEngine.Inventory.RubberBoots();
        _hat    = new ZaraEngine.Inventory.LeafHat();

        _inventory.AddItem(flaskWithWater);

        _inventory.AddItem(_jacket);
        _inventory.AddItem(_pants);
        _inventory.AddItem(_boots);
        _inventory.AddItem(_hat);

        var meat = new ZaraEngine.Inventory.Meat {
            Count = 1
        };

        // We just gathered two of spoiled Meat.
        meat.AddGatheringInfo(WorldTime.Value.AddHours(-5), 2);

        // We just gathered one item of fresh Meat. These will spoil in MinutesUntilSpoiled game minutes.
        meat.AddGatheringInfo(WorldTime.Value, 1);

        _inventory.AddItem(new ZaraEngine.Inventory.Cloth {
            Count = 20
        });
        _inventory.AddItem(meat);
        _inventory.AddItem(new ZaraEngine.Inventory.AntisepticSponge {
            Count = 5
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Bandage {
            Count = 5
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Acetaminophen {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Antibiotic {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Aspirin {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.EmptySyringe {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Loperamide {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Oseltamivir {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Sedative {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.AtropineSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.EpinephrineSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.AntiVenomSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.DoripenemSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.MorphineSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.DisinfectingPellets {
            Count = 5
        });

        RefreshConsumablesUICombo();
        RefreshToolsUICombo();

        // Defaults
        _weather.SetTemperature(27f);
        _weather.SetWindSpeed(2f);
        _weather.SetRainIntensity(0f);

        #endregion
    }
Esempio n. 2
0
        public override IEnumerable <ForecastFromSource> GetForecasts(DateTime deadline, ref List <DailyIcon> icons)
        {
            IEnumerable <DailyIcon> localIcons = null;

            try
            {
                localIcons = GetDailyIcons();
                JObject data = JsonFromUrl(ForecastURL);

                if (data == null || icons == null)
                {
                    if (deadline > DateTime.Now)
                    {
                        Thread.Sleep(1000 * 60 * 3);// 3 min
                        return(GetForecasts(deadline, ref icons));
                    }

                    return(null);
                }
                ;
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                var threeHourResult = from forecast in (JArray)data["data"]
                                      select new ForecastFromSource()
                {
                    forecastCreating = DateTime.Today.AddHours(DateTime.Now.Hour),
                    source           = this,
                    date             = WeatherSource.DateTimeFromUnixTimestampSeconds((long)forecast["ts"]),
                    airTemperature   = Convert.ToDouble(forecast["temp"].ToString()),
                    description      = WeatherDescription.GetWeatherDescription(forecast["weather"]["description"].ToString().ToLower()),
                    isDay            = forecast["pod"].ToString() == "d" ? true : false,
                    pressure         = Convert.ToDouble(forecast["slp"].ToString()) * WeatherCondition.mBarInMMGH,
                    humidity         = Convert.ToDouble(forecast["rh"].ToString()),
                    windSpeed        = Convert.ToDouble(forecast["wind_spd"].ToString()),
                    windDirection    = new WindDirection(Convert.ToDouble(forecast["wind_dir"].ToString()), forecast["wind_cdir"].ToString()),
                    rain             = Convert.ToDouble(forecast["precip"].ToString()),           //precipitation in 3 hours
                    snow             = Convert.ToDouble(forecast["snow"].ToString()),             //precipitation in 3 hours
                    cloud            = Convert.ToInt32(forecast["clouds"].ToString())
                };

                if (threeHourResult.Count() == CountOfForecasts)
                {
                    icons.AddRange(localIcons);
                    return(threeHourResult);
                }
                else
                {
                    if (deadline > DateTime.Now)
                    {
                        Thread.Sleep(1000 * 60 * 3);// 3 min
                        return(GetForecasts(deadline, ref icons));
                    }
                    return(null);
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(String.Format("An error occurred while trying to data processing from the source: {0}; in the method : {1}; by the address {2}", Name, "GetForecasts", ForecastURL), ex);

                if (deadline > DateTime.Now)
                {
                    Thread.Sleep(1000 * 60 * 3);// 3 min
                    return(GetForecasts(deadline, ref icons));
                }
                return(null);
            }
        }
Esempio n. 3
0
        public override IEnumerable <ForecastFromSource> GetForecasts(DateTime deadline, ref List <DailyIcon> icons)
        {
            IEnumerable <DailyIcon> localIcons = null;

            try
            {
                localIcons = GetDailyIcons();
                JObject data = JsonFromUrl(ForecastURL);
                if (data == null || icons == null)
                {
                    if (deadline > DateTime.Now)
                    {
                        Thread.Sleep(1000 * 60 * 3);// 3 min
                        return(GetForecasts(deadline, ref icons));
                    }
                    return(null);
                }

                // determine the first time point, which has already passed. according time zones  3,6,9,12,15,18,21,00
                int hours = DateTime.Now.Hour;
                if (hours % 3 > 0)
                {
                    hours = hours - hours % 3;
                }


                //as this source offers an hourly forecast
                //let's define an array of dates with time for selecting the forecasts we need
                var dates = Enumerable.Range(0, CountOfForecasts).Select(x => x * 3).Select(dd => DateTime.Today.AddHours(dd + hours).ToString("yyyy-MM-dd HH:mm")).ToArray();//2017-09-20 00:00

                //make a request to the object - the result of the request to the resource
                //inside the query, create and populate a collection of Forecast objects for a three-hour forecast
                var threeHourResult = from day in (JArray)data["forecast"]["forecastday"]
                                      from hour in (JArray)day["hour"]
                                      where dates.Contains(((JValue)hour["time"]).Value.ToString())
                                      select new ForecastFromSource()
                {
                    forecastCreating = DateTime.Now,
                    source           = this,
                    date             = DateTime.ParseExact(hour["time"].ToString(), "yyyy-MM-dd HH:mm", System.Globalization.CultureInfo.InvariantCulture),
                    airTemperature   = Convert.ToDouble(hour["temp_c"].ToString()),
                    description      = WeatherDescription.GetWeatherDescription(hour["condition"]["text"].ToString().ToLower()),
                    isDay            = hour["is_day"].ToString() == "1" ? true : false,
                    pressure         = Convert.ToDouble(hour["pressure_mb"].ToString()) * WeatherCondition.mBarInMMGH,
                    humidity         = Convert.ToDouble(hour["humidity"].ToString()),
                    windSpeed        = Convert.ToDouble(hour["wind_kph"].ToString()) * WeatherCondition.metersPerSecondInKPH,
                    windDirection    = new WindDirection(Convert.ToDouble(hour["wind_degree"].ToString()), hour["wind_dir"].ToString()),
                    rain             = Convert.ToDouble(hour["precip_mm"].ToString()),             //precipitation in 3 hours
                    cloud            = Convert.ToInt32(hour["cloud"].ToString())
                };
                if (threeHourResult.Count() == CountOfForecasts)
                {
                    icons.AddRange(localIcons);
                    return(threeHourResult);
                }
                return(null);
            }
            catch (Exception ex)
            {
                Logger.Log.Error(String.Format("An error occurred while trying to data processing from the source: {0}; in the method : {1}; by the address {2}", Name, "GetForecasts", ForecastURL), ex);
                return(null);
            }
        }
Esempio n. 4
0
 public static WeatherObject TryToGetWeather(WeatherDescription description, int time)
 {
     return(TryToGetWeather(description.Type, time, description.Temperature));
 }
Esempio n. 5
0
        public override IEnumerable <ForecastFromSource> GetForecasts(DateTime deadline, ref List <DailyIcon> icons)
        {
            IEnumerable <DailyIcon> localIcons = null;

            try
            {
                localIcons = GetDailyIcons();
                JObject data = JsonFromUrl(ForecastURL);
                if (data == null || icons == null)
                {
                    if (deadline > DateTime.Now)
                    {
                        Thread.Sleep(1000 * 60 * 3);// 3 min
                        return(GetForecasts(deadline, ref icons));
                    }
                    return(null);
                }

                var threeHourResult = from day in (JArray)data["list"]
                                      select new ForecastFromSource()
                {
                    forecastCreating = DateTime.Today.AddHours(DateTime.Now.Hour),
                    source           = this,
                    date             = WeatherSource.DateTimeFromUnixTimestampSeconds((long)day["dt"]),
                    airTemperature   = Convert.ToDouble(day["main"]["temp"].ToString()),
                    description      = WeatherDescription.GetWeatherDescription(day["weather"][0]["description"].ToString().ToLower()),
                    isDay            = day["sys"]["pod"].ToString() == "d" ? true : false,
                    pressure         = Convert.ToDouble(day["main"]["sea_level"].ToString()) * WeatherCondition.mBarInMMGH,
                    humidity         = Convert.ToDouble(day["main"]["humidity"].ToString()),
                    windSpeed        = Convert.ToDouble(day["wind"]["speed"].ToString()),
                    windDirection    = new WindDirection(Convert.ToDouble(day["wind"]["deg"].ToString())),
                    rain             = day.SelectToken("rain") == null ? 0.0 : day["rain"].HasValues? Convert.ToDouble(day["rain"]["3h"].ToString()): 0.0,
                    snow             = day.SelectToken("snow") == null ? 0.0 : day["snow"].HasValues ? Convert.ToDouble(day["snow"]["3h"].ToString()) : 0.0,
                    cloud            = Convert.ToInt32(day["clouds"]["all"].ToString())
                };
                if (threeHourResult.Count() == CountOfForecasts)
                {
                    icons.AddRange(localIcons);
                    return(threeHourResult);
                }
                else
                {
                    if (threeHourResult.Count() >= CountOfForecasts - 5)
                    {
                        icons.AddRange(localIcons);
                        return(threeHourResult);
                    }
                    else
                    {
                        if (deadline > DateTime.Now)
                        {
                            Thread.Sleep(1000 * 60 * 3);// 3 min
                            return(GetForecasts(deadline, ref icons));
                        }
                        Logger.Log.Debug("the number of forecasts is less than normal(40-5) and equal  " + threeHourResult.Count());
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log.Error(String.Format("An error occurred while trying to data processing from the source: {0}; in the method : {1}; by the address {2}", Name, "GetForecasts", ForecastURL), ex);

                if (deadline > DateTime.Now)
                {
                    Thread.Sleep(1000 * 60 * 3);    // 3 min
                    return(GetForecasts(deadline, ref icons));
                }
                return(null);
            }
        }
Esempio n. 6
0
    // Start is called before the first frame update
    void Start()
    {
        /* Zara Initialization code start =======>> */

        ZaraEngine.Helpers.InitializeRandomizer((a, b) => UnityEngine.Random.Range(a, b));

        _dateTime  = DateTime.Now;
        _timeOfDay = TimesOfDay.Evening;
        _health    = new HealthController(this);
        _body      = new BodyStatusController(this);
        _weather   = new WeatherDescription();
        _player    = new PlayerStatus();
        _inventory = new InventoryController(this);

        ClothesGroups.Initialize(this);

        _body.Initialize();
        _health.Initialize();

        /* <<======= Zara Initialization code end */

        // Let's add some items to the inventory to play with in this demo

        var flaskWithWater = new ZaraEngine.Inventory.Flask();

        flaskWithWater.FillUp(WorldTime.Value);
        //flaskWithWater.Disinfect(WorldTime.Value);

        _jacket = new ZaraEngine.Inventory.WaterproofJacket();
        _pants  = new ZaraEngine.Inventory.WaterproofPants();
        _boots  = new ZaraEngine.Inventory.RubberBoots();
        _hat    = new ZaraEngine.Inventory.LeafHat();

        _inventory.AddItem(flaskWithWater);

        _inventory.AddItem(_jacket);
        _inventory.AddItem(_pants);
        _inventory.AddItem(_boots);
        _inventory.AddItem(_hat);

        _inventory.AddItem(new ZaraEngine.Inventory.Cloth {
            Count = 20
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Meat {
            Count = 3
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Bandage {
            Count = 5
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Acetaminophen {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Antibiotic {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Aspirin {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.EmptySyringe {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Loperamide {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Oseltamivir {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.Sedative {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.AtropineSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.EpinephrineSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.AntiVenomSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.DoripenemSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.MorphineSolution {
            Count = 10
        });
        _inventory.AddItem(new ZaraEngine.Inventory.DisinfectingPellets {
            Count = 5
        });

        RefreshConsumablesUICombo();
        RefreshToolsUICombo();

        // Defaults
        _weather.SetTemperature(27f);
        _weather.SetWindSpeed(0.1f);
        _weather.SetRainIntensity(0f);
    }