示例#1
0
        /// <summary>
        /// Get all stat packages summed up in one.
        /// </summary>
        /// <returns>A sum stat package.</returns>
        public ProfileStatPackage GetAllStatPackages()
        {
            //Create a new temporary stat package to rule them all.
            ProfileStatPackage stats = new ProfileStatPackage(this, -1);

            //For every version specific stat package, transfer the stats.
            foreach (ProfileStatPackage stat in _Statistics)
            {
                stats.Games += stat.Games;
                stats.Wins += stat.Wins;
                stats.Draws += stat.Draws;
                stats.Losses += stat.Losses;
                stats.Points += stat.Points;
                stats.GoalsScored += stat.GoalsScored;
                stats.GoalsConceded += stat.GoalsConceded;
                foreach (KeyValuePair<Player, int> scorer in stat.Scorers) { stats.AddScorer(scorer.Key, scorer.Value); }
            }

            //Return the full stat package.
            return stats;
        }
示例#2
0
        /// <summary>
        /// Load a profile, either from memory or file.
        /// </summary>
        /// <param name="id">The id of the profile.</param>
        /// <returns>The loaded profile.</returns>
        public static Profile LoadProfile(int id)
        {
            //In the all too likely event that everything inexplicably goes to hell.
            try
            {
                //Set up and load the xml file.
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(GetProfilePath(id));

                //Create the profile.
                Profile profile = new Profile(xmlDocument.SelectSingleNode("/Profile/Name").InnerText,
                    int.Parse(xmlDocument.SelectSingleNode("/Profile/Id").InnerText),
                    Summary.Instance.GetTeam(int.Parse(xmlDocument.SelectSingleNode("/Profile/Team").InnerText)));

                //The previous teams.
                foreach (XmlNode teamNode in xmlDocument.SelectNodes("Profile/Teams/Team"))
                {
                    //Load a team.
                    profile.PreviousTeams.Add(LoadTeam(int.Parse(teamNode.Attributes.GetNamedItem("Id").Value)));
                }

                //The statistics.
                foreach (XmlNode statNode in xmlDocument.SelectNodes("Profile/Statistics/StatPackage"))
                {
                    //Create the stat package.
                    ProfileStatPackage stats = new ProfileStatPackage(profile, int.Parse(statNode.Attributes.GetNamedItem("Version").Value));

                    //Parse the xml data.
                    stats.Games = int.Parse(statNode.SelectSingleNode("Games").InnerText);
                    stats.Points = int.Parse(statNode.SelectSingleNode("Points").InnerText);
                    stats.Wins = int.Parse(statNode.SelectSingleNode("Wins").InnerText);
                    stats.Draws = int.Parse(statNode.SelectSingleNode("Draws").InnerText);
                    stats.Losses = int.Parse(statNode.SelectSingleNode("Losses").InnerText);
                    stats.GoalsScored = int.Parse(statNode.SelectSingleNode("GoalsScored").InnerText);
                    stats.GoalsConceded = int.Parse(statNode.SelectSingleNode("GoalsConceded").InnerText);

                    //The scorers.
                    foreach (XmlNode scorerNode in statNode.SelectNodes("Scorers/Scorer"))
                    {
                        //Load a scorer.
                        stats.AddScorer(GetPlayer(scorerNode.Attributes.GetNamedItem("Id").Value),
                            int.Parse(scorerNode.Attributes.GetNamedItem("Goals").Value));
                    }

                    //Add the stat package.
                    profile.Statistics.Add(stats);
                }

                //Return the profile.
                return profile;
            }
            catch { return null; }
        }