public void TestSetDaytime(Daytime daytime)
 {
     Assert.IsTrue(isServerExists);
     ariesApiHelper.SetDaytime(daytime);
     // Check Post data result
     // Web server should store it somewhere
 }
Exemplo n.º 2
0
        // returns the id and level of a pokemon according to the encounter table
        // if no encounter data is present for the input data, null is returned.
        public EncounterResult?GetResult(EncounterMethod method, Daytime daytime)
        {
            var applicable = _data.Where(d => d.DoesApply(method, daytime));

            // no data found for the input
            if (applicable.Count() == 0)
            {
                return(null);
            }

            // pick a random pokemon based on its encounter chance
            var rates       = applicable.Select(a => a.GetRate(daytime)).ToArray();
            var totalChance = rates.Sum(r => r.chance);
            var pick        = _random.Next(0, totalChance) + 1;
            var runner      = 0;

            for (var i = 0; i < rates.Length; i++)
            {
                var rate = rates[i];
                runner += rate.chance;
                if (runner >= pick)
                {
                    var id = rate.GetPokemonId();
                    var(minLevel, maxLevel) = rate.GetLevelRange();
                    var level = _random.Next(minLevel, maxLevel + 1);
                    return(new EncounterResult {
                        Id = id, Level = level
                    });
                }
            }

            // fallback
            return(null);
        }
Exemplo n.º 3
0
 public Daytime ProcessRow(Daytime daytime, MySqlDataReader Reader, int offset)
 {
     daytime.Id       = Reader.GetInt32(0 + offset);
     daytime.Date     = Reader.GetDateTime(1 + offset);
     daytime.Timeslot = Reader.GetInt32(2 + offset);
     return(daytime);
 }
Exemplo n.º 4
0
 public void Init()
 {
     time          = gameObject.AddComponent <Daytime>();
     powerStations = new List <PowerStation>();
     parkingSpots  = new List <ParkingSpace>();
     creator       = gameObject.AddComponent <WorldCreator>();
     creator.world = this;
 }
 public Criteria(Color color, Country country, Town town, GoodBad goodBad, DayOfTheWeek dayOfTheWeek, Daytime daytime)
 {
     this.Color        = color;
     this.Country      = country;
     this.Town         = town;
     this.GoodBad      = goodBad;
     this.DayOfTheWeek = dayOfTheWeek;
     this.Daytime      = daytime;
 }
Exemplo n.º 6
0
        public void TestSetDaytime(Daytime daytime)
        {
            ariesApiHelper.SetDaytime(daytime);
            Dictionary <string, State> statesFromJSON = TestHelper.ReadState();

            foreach (string agentId in ariesApiHelper.simulation.agents.Keys)
            {
                Assert.AreEqual(statesFromJSON[agentId].pv_panel.solar_irradiance, (int)daytime / 100.0);
            }
        }
        public async Task <Daytime> GetDaytimeById(int id)
        {
            string script    = ScriptsUtils.GetSqlScript("Daytimes\\GetDaytimeById.sql");
            var    daytimeId = new SqlParameter("@daytimeId", id);

            Daytime daytime = await _context.Daytimes.FromSqlRaw(
                script,
                daytimeId
                ).FirstAsync();

            return(daytime);
        }
        public int CreateDaytime(Daytime daytime)
        {
            string script = ScriptsUtils.GetSqlScript("Daytimes\\CreateDaytime.sql");
            var    title  = new SqlParameter("@title", daytime.title);

            int numberOfAffectedRows = _context.Database.ExecuteSqlRaw(
                script,
                title
                );

            return(numberOfAffectedRows);
        }
Exemplo n.º 9
0
        protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            ele.TryPathTo("Daytime", true, out subEle);
            Daytime.WriteXML(subEle, master);

            ele.TryPathTo("Nighttime", true, out subEle);
            Nighttime.WriteXML(subEle, master);

            ele.TryPathTo("Underwater", true, out subEle);
            Underwater.WriteXML(subEle, master);
        }
Exemplo n.º 10
0
        void Session_Drop(object sender, DragEventArgs e)
        {
            CustomLabel session = sender as CustomLabel;

            if (session != null && session.Background != Brushes.Red)
            {
                // If the DataObject contains string data, extract it.
                if (e.Data.GetDataPresent(DataFormats.StringFormat))
                {
                    string dataString = (string)e.Data.GetData(DataFormats.StringFormat);
                    if (dataString != null)
                    {
                        string[] other = dataString.Split(';');
                        Session  s     = _controller.SessionMapper.Find(Convert.ToInt32(other[0]));
                        Daytime  d     = _controller.DaytimeMapper.Find(GetSessionDate(session), Grid.GetRow(session));
                        if (d == null)
                        {
                            string[] date = GetSessionDate(session).Split('-');
                            d    = new Daytime(0, new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])), Grid.GetRow(session) + 1);
                            d.Id = _controller.DaytimeMapper.Save(d);
                        }
                        s.Daytime   = d;
                        s.Classroom = _controller.ClassroomMapper.Find(Grid.GetColumn(session) + 1);
                        addSession(s, false);
                        removeSessionLabel(other[1], Convert.ToInt32(other[2]), Convert.ToInt32(other[3]));
                    }
                }
                else
                {
                    int id = (int)e.Data.GetData("System.Int32");
                    if (id != 0)
                    {
                        Session s = new Session();
                        Daytime d = _controller.DaytimeMapper.Find(GetSessionDate(session), Grid.GetRow(session));
                        if (d == null)
                        {
                            string[] date = GetSessionDate(session).Split('-');
                            d    = new Daytime(0, new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])), Grid.GetRow(session) + 1);
                            d.Id = _controller.DaytimeMapper.Save(d);
                        }
                        s.Daytime   = d;
                        s.Classroom = _controller.ClassroomMapper.Find(Grid.GetColumn(session) + 1);
                        s.Pair      = _controller.PairMapper.Find(Convert.ToInt32(id));
                        addSession(s, true);
                    }
                }
                revertCheckAvailability();
            }
        }
Exemplo n.º 11
0
        /// <summary>
        ///     Change Daytime properties for all agents
        /// </summary>
        /// <param name="time">Daytime enum</param>
        public void SetDaytime(Daytime time)
        {
            var states = new Dictionary <string, State>();

            foreach (var agent in simulation.agents.Keys)
            {
                states.Add(agent, new State
                {
                    pv_panel = new PVPanelState
                    {
                        solar_irradiance = (int)time / 100.0
                    }
                });
            }
            _ariesApi.PostState(states);
        }
Exemplo n.º 12
0
        public static string GetDisplayDaytime(Daytime daytime)
        {
            switch (daytime)
            {
            case Daytime.Morning:
                return("Morn");

            case Daytime.Day:
                return("Day");

            case Daytime.Night:
                return("Nite");
            }

            return("");
        }
Exemplo n.º 13
0
 protected override void ReadData(ESPReader reader)
 {
     using (MemoryStream stream = new MemoryStream(reader.ReadBytes(size)))
         using (ESPReader subReader = new ESPReader(stream, reader.Plugin))
         {
             try
             {
                 Daytime.ReadBinary(subReader);
                 Nighttime.ReadBinary(subReader);
                 Underwater.ReadBinary(subReader);
             }
             catch
             {
                 return;
             }
         }
 }
Exemplo n.º 14
0
        public bool DoesApply(EncounterMethod method, Daytime daytime)
        {
            // different method?
            if (Method != method)
            {
                return(false);
            }

            // if no special rates are defined, daytime does not matter
            if (rates == null || rates.Length == 0)
            {
                return(true);
            }

            // if the daytime is included in the rates, this data applies
            return(rates.Any(r => r.Time.Contains(daytime)));
        }
Exemplo n.º 15
0
        protected override void ReadDataXML(XElement ele, ElderScrollsPlugin master)
        {
            XElement subEle;

            if (ele.TryPathTo("Daytime", false, out subEle))
            {
                Daytime.ReadXML(subEle, master);
            }

            if (ele.TryPathTo("Nighttime", false, out subEle))
            {
                Nighttime.ReadXML(subEle, master);
            }

            if (ele.TryPathTo("Underwater", false, out subEle))
            {
                Underwater.ReadXML(subEle, master);
            }
        }
Exemplo n.º 16
0
        public int Save(Daytime daytime)
        {
            Boolean insert = true;

            if (daytime.Id != 0)
            {
                insert = false;
            }
            this._db.OpenConnection();
            MySqlCommand command = this._db.CreateCommand();

            if (insert)
            {
                command.CommandText = "INSERT INTO daytime (date, timeslot) VALUES " +
                                      "(?date, ?timeslot)";
            }
            else
            {
                command.CommandText = "UPDATE daytime (date, timeslot) VALUES " +
                                      "(?date, ?timeslot) WHERE id = ?id";
            }
            command.Parameters.Add(new MySqlParameter("?id", MySqlDbType.Int32)).Value       = daytime.Id;
            command.Parameters.Add(new MySqlParameter("?date", MySqlDbType.Datetime)).Value  = daytime.Date;
            command.Parameters.Add(new MySqlParameter("?timeslot", MySqlDbType.Int32)).Value = daytime.Timeslot;
            this._db.ExecuteCommand(command);
            this._db.CloseConnection();
            if (insert)
            {
                this._db.OpenConnection();
                MySqlCommand command2 = this._db.CreateCommand();
                command2.CommandText = "SELECT LAST_INSERT_ID()";
                MySqlDataReader Reader = this._db.ExecuteCommand(command2);
                Reader.Read();
                this._db.CloseConnection();
                return(Reader.GetInt32(0));
            }
            return(0);
        }
Exemplo n.º 17
0
 public EncounterRateData GetRate(Daytime daytime)
 {
     if (rates == null || rates.Length == 0)
     {
         var rate = new EncounterRateData
         {
             chance = chance,
             levels = levels,
         };
         rate.SetParent(this);
         return(rate);
     }
     else
     {
         var rate = rates.First(r => r.Time.Contains(daytime));
         // when no levels are set in the rate, overwrite with levels of the encounter data
         if (rate.levels == null || rate.levels.Length == 0)
         {
             rate.levels = levels;
         }
         rate.SetParent(this);
         return(rate);
     }
 }
Exemplo n.º 18
0
        public ActionResult <int> UpdateDaytime(int id, Daytime daytime)
        {
            int numberOfAffectedRows = _repository.UpdateDaytime(id, daytime);

            return(Ok(numberOfAffectedRows));
        }
Exemplo n.º 19
0
        public ActionResult <int> CreateDaytime(Daytime daytime)
        {
            int numberOfAffectedRows = _repository.CreateDaytime(daytime);

            return(Ok(numberOfAffectedRows));
        }
Exemplo n.º 20
0
 public override int GetHashCode()
 {
     return(Daytime.GetHashCode());
 }
Exemplo n.º 21
0
 public Daytime ProcessRow(Daytime daytime, MySqlDataReader Reader)
 {
     return(this.ProcessRow(daytime, Reader, 0));
 }
Exemplo n.º 22
0
 protected override void WriteData(ESPWriter writer)
 {
     Daytime.WriteBinary(writer);
     Nighttime.WriteBinary(writer);
     Underwater.WriteBinary(writer);
 }
Exemplo n.º 23
0
 void Awake()
 {
     daytime = FindObjectOfType <Daytime>();
     curMesh = GetComponent <MeshFilter>();
 }