Example #1
0
 public Player()
 {
     LastSeen = new Seen
                    {
                        Count = 0,
                        System = String.Empty,
                        Time = DateTime.MinValue
                    };
 }
Example #2
0
 public Player()
 {
     LastSeen = new Seen
     {
         Count  = 0,
         System = String.Empty,
         Time   = DateTime.MinValue
     };
 }
Example #3
0
        private Player GetFullPlayer(SQLiteConnection Conn, string Name )
        {
            var player = new Player
                             {
                                 Name = Name,
                                 KnownShips = new List<Ship>(),
                                 Seen = new List<Seen>(),
                                 CharacterID = 0
                             };

            bool updateCharID = false;

            using (SQLiteCommand cmd = Conn.CreateCommand())
            {
                cmd.CommandText = "select Corp, Alliance, CharacterID from Player where Name = @NAME";
                cmd.Parameters.AddWithValue("@NAME", Name);
                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        player.Corp = reader.GetString(0);
                        player.Alliance = reader.GetString(1);
                        if(!reader.IsDBNull(2))
                            player.CharacterID = reader.GetInt64(2);
                        if (player.CharacterID == 0)
                            updateCharID = true;
                    }
                }
            }

            using (SQLiteCommand cmd = Conn.CreateCommand())
            {
                cmd.CommandText = "select Seen.Ship, Seen.isKiller, Kill.System, Kill.Time from Seen" +
                                  " left outer join Kill on seen.KillID = Kill.ID" +
                                  " where Seen.Player = @NAME";
                cmd.Parameters.AddWithValue("@NAME", Name);

                using (SQLiteDataReader reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        string ShipName = reader.GetString(0);
                        Ship ship = player.KnownShips.Find(S => S.Name == ShipName);
                        DateTime lastUsed = reader.GetDateTime(3);
                        bool killer = reader.GetBoolean(1);
                        string System = reader.GetString(2);

                        if (ship == null)
                        {
                            ship = new Ship
                                       {
                                           Name = ShipName,
                                           LastUsed = lastUsed,
                                           TimesUsed = 1,
                                           TimesLost = killer ? 0 : 1
                                       };
                            player.KnownShips.Add(ship);
                        }
                        else
                        {
                            ship.TimesUsed++;
                            if (!killer)
                                ship.TimesLost++;
                            if (ship.LastUsed < lastUsed)
                                ship.LastUsed = lastUsed;
                        }

                        Seen seen = player.Seen.Find(S => S.System == System);
                        if (seen == null)
                        {
                            seen = new Seen
                                       {
                                           Count = 1,
                                           System = System,
                                           Time = lastUsed
                                       };                                                       

                            player.Seen.Add(seen);
                        }
                        else
                        {
                            seen.Count++;
                            if (seen.Time < lastUsed)
                                seen.Time = lastUsed;
                        }

                        if (lastUsed > player.LastSeen.Time)
                        {
                            player.LastSeen.Time = lastUsed;
                            player.LastSeen.System = System;
                        }
                    }
                }
            }

            //TODO: Call update charid + update db
            if(updateCharID)
            {
                player.CharacterID= EVEIntel.Repository.EVEApi.Character.GetCharacterID(player.Name);
                SetPlayerCharacterID(player.Name, player.CharacterID, Conn);
            }

            return player;
        }