Exemplo n.º 1
0
        public Skill(Skills skillName, int startLevel = 1, long startExperience = 0L, int endLevel = 99, long endExperience = 13034431L, int rank = -1)
        {
            Skillname = skillName.ToString();
            Rank      = rank;

            // If a value has been passed for startLevel, and not startExperience we take the level and calculate experience
            if (startLevel != 1 && startExperience == 0)
            {
                currentLevel      = startLevel;
                currentExperience = ExperienceAtLevel(currentLevel);
            }
            else if (startExperience != 0 && startLevel == 1) // if we have a value for experience, but not level...
            {
                currentExperience = startExperience;
                currentLevel      = LevelAtExperience(currentExperience);
            }

            // If a value has been passed for endLevel, and not endExperience we take the level and calculate experience
            if (endLevel != 1 && endExperience == 0)
            {
                goalLevel      = endLevel;
                goalExperience = ExperienceAtLevel(endLevel);
            }
            else if (endExperience != 0 && endLevel == 1) // if we have a value for experience, but not level...
            {
                goalExperience = endExperience;
                goalLevel      = LevelAtExperience(endExperience);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Pulls all matching Skill objects from the database from a specific time range.
        /// </summary>
        /// <param name="skillname">Skills object to match for which skill to select.</param>
        /// <param name="UserID">UserID for the player whose skill data is to be selected.</param>
        /// <param name="fromDate">DateTime object representing the beginning of the time range to select from.</param>
        /// <param name="toDate">DateTime object representing the end of the time range to select from.</param>
        /// <returns>Returns a List of all Skill objects which were added to the database within the specified time range.</returns>
        public List <Skill> GetSkillRange(Skills Skillname, Guid UserID, DateTime fromDate, DateTime toDate)
        {
            using (HighscoresDataContext context = new HighscoresDataContext(this.ConnectionString))
            {
                var range = context.Scores.Where(skill => skill.UserID == UserID && skill.Timestamp >= fromDate && skill.Timestamp <= toDate)
                            .GroupBy(skill => skill.Skillname)
                            .First(group => group.Key == Skillname.ToString());

                return(range.ToList());
            }
        }
Exemplo n.º 3
0
 private static int getSkillRank(List <string[]> highscores, Skills SkillName)
 {
     return((int)getValueAtIndex(highscores, SkillName.ToString(), RankIndex));
 }
Exemplo n.º 4
0
 private static long getSkillExp(List <string[]> highscores, Skills SkillName)
 {
     return(getValueAtIndex(highscores, SkillName.ToString(), ExppIndex));
 }
        /// <summary>
        /// Pulls all matching Skill objects from the database from a specific time range.
        /// </summary>
        /// <param name="skillname">Skills object to match for which skill to select.</param>
        /// <param name="UserID">UserID for the player whose skill data is to be selected.</param>
        /// <param name="fromDate">DateTime object representing the beginning of the time range to select from.</param>
        /// <param name="toDate">DateTime object representing the end of the time range to select from.</param>
        /// <returns></returns>
        public List <Skill> GetSkillRange(Skills skillname, Guid UserID, DateTime fromDate, DateTime toDate)
        {
            List <Skill> SkillRange = new List <Skill>();

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
            {
                connection.Open();

                using (SqlCommand cmd = new SqlCommand("SELECT * FROM Scores WHERE Timestamp BETWEEN @FromDate and @ToDate AND " +
                                                       "[UserID] = @UserID AND [Skillname] = @Skillname", connection))
                {
                    cmd.Parameters.Add("@FromDate", System.Data.SqlDbType.DateTime, 8).Value        = fromDate;
                    cmd.Parameters.Add("@ToDate", System.Data.SqlDbType.DateTime, 8).Value          = toDate;
                    cmd.Parameters.Add("@UserID", System.Data.SqlDbType.UniqueIdentifier, 16).Value = UserID;
                    cmd.Parameters.Add("@Skillname", System.Data.SqlDbType.NVarChar).Value          = skillname.ToString();

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            //Debug.WriteLine(reader["Skillname"] + ": " + reader["Experience"] + " @ " + ((DateTime)reader["Timestamp"]).ToLongDateString());
                            SkillRange.Add(new Skill(Skills.Parse(reader["Skillname"]), (long)reader["Experience"], (int)reader["Rank"]));
                        }
                    }
                }
                connection.Close();
            }

            return(SkillRange);
        }
        /// <summary>
        /// Queries the database to find the most recent score data for matching skillname and UserID.
        /// If you want to retieve more than one Skill's data, use GetPlayer() instead.
        /// </summary>
        public Skill GetSkill(Skills skillname, Guid UserID)
        {
            Skill skill = null; // null object is returned if no matching UserID is in the database

            using (SqlConnection connection = new SqlConnection(this.ConnectionString))
            {
                connection.Open();

                using (SqlCommand cmd = new SqlCommand("SELECT * FROM Scores WHERE Timestamp = " +
                                                       "(SELECT MAX(Timestamp) FROM Scores WHERE [UserID] = @UserID AND [Skillname] = @Skillname)", connection))
                {
                    cmd.Parameters.Add("@UserID", System.Data.SqlDbType.UniqueIdentifier, 16).Value = UserID;
                    cmd.Parameters.Add("@Skillname", System.Data.SqlDbType.NVarChar).Value          = skillname.ToString();

                    SqlDataReader reader = cmd.ExecuteReader();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            skill = new Skill(Skills.Parse(reader["Skillname"]), (long)reader["Experience"], (int)reader["Rank"]);
                        }
                    }
                }
                connection.Close();
            }

            return(skill);
        }