Esempio n. 1
0
        /// <summary>
        /// Refresh the ranking dictionary by re-loading the data from file. Throws an XML
        /// exception if something goes wrong.
        /// </summary>
        public static void RefreshRanks()
        {
            rankDictionary.Clear();

            XmlDocument doc = new XmlDocument();
            doc.Load(RANK_FILE);

            XmlNodeList rankNodes = doc.GetElementsByTagName("rank");
            foreach (XmlNode rankNode in rankNodes)
            {
                /* A Rank has the following properties:
                 * - ID
                 * - Title
                 * - Abbreviation
                 * - Filename
                 */
                int id = -1;
                string title = null;
                string abbreviation = null;
                string filename = null;
                bool valid = true;
                XmlNodeList childrenNodes = rankNode.ChildNodes;
                for (int i = 0; i < childrenNodes.Count; ++i)
                {
                    string nodeValue = childrenNodes[i].InnerText;
                    switch (childrenNodes[i].Name)
                    {
                        case "id":
                            bool successfulParse = int.TryParse(nodeValue, out id);
                            if (!successfulParse)
                            {
                                // Data is malformed, so continue to the next node.
                                Console.Error.WriteLine("Warning: Malformed data in rank ID field: {0}",
                                    nodeValue);
                                valid = false;
                                break;
                            }
                            break;
                        case "title":
                            if (String.IsNullOrEmpty(nodeValue))
                            {
                                Console.Error.WriteLine("Warning: Empty rank title field.");
                            }
                            title = nodeValue;
                            break;
                        case "abbreviation":
                            if (String.IsNullOrEmpty(nodeValue))
                            {
                                Console.Error.WriteLine("Warning: Empty rank abbreviation field.");
                            }
                            abbreviation = nodeValue;
                            break;
                        case "filename":
                            if (String.IsNullOrEmpty(nodeValue))
                            {
                                Console.Error.WriteLine("Warning: Empty rank filename field.");
                            }
                            filename = nodeValue;
                            break;
                        default:
                            Console.Error.WriteLine("Warning: Unknown node name in rank node: {0}",
                                childrenNodes[i].InnerText);
                            break;
                    }
                }

                if (!valid)
                {
                    continue;
                }

                // Now we've collected the node information: store it.
                Rank rank = new Rank(id, title, abbreviation, filename);
                rankDictionary[id] = rank;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Get and display the user's tank.
        /// </summary>
        private void GetRank()
        {
            ServiceManager.Echelon.GetRankAsync((x) =>
            {
                ServiceManager.Game.Invoke((y) =>
                {
                    // This action is performed in the GUI thread:
                    int rankID = x.ReturnedResult;
                    rank = RankLoader.GetRank(rankID);
                    if (rank != null)
                    {
                        Texture2D rankTexture = rank.GetTexture();
                        if (rankTexture != null)
                        {
                            form.RankImage.Image = rankTexture;
                        }

                        form.RankLabel.Text = rank.Title;
                    }
                    else
                    {
                        System.Console.Error.WriteLine("Warning: Rank of rank ID {0} is null.", rankID);
                    }

                    const int GENERAL_RANK = 19;
                    if (rankID != GENERAL_RANK)
                    {
                        long minimumPoints = 0;
                        if (rankID != 0)
                        {
                            minimumPoints = ServiceManager.Echelon.GetPointsForRank(rankID);
                        }

                        long myPoints = ServiceManager.Echelon.GetProxy().GetAccountPoints();
                        long requiredPoints = ServiceManager.Echelon.GetPointsForRank(rankID + 1);

                        // Do calculation to figure out percentage of how far we have to go.
                        double pointsInRank = requiredPoints - minimumPoints;
                        double translatedPoints = myPoints - minimumPoints;

                        form.RankProgressBar.Value = (int)((translatedPoints / pointsInRank) * 100.0);
                        form.RankProgressBar.ToolTip.Text = String.Format("{0} / {1}", myPoints, requiredPoints);

                        int killsRequired = (int)((double)(requiredPoints - myPoints) / 10.0);
                        form.RankNextLabel.Text = String.Format(
                            "{0} more {1} to rank up.", killsRequired, killsRequired == 1 ? "kill" : "kills");
                    }
                    else
                    {
                        form.RankLabel.Text = "General";
                        form.RankProgressBar.Value = 100;
                        form.RankNextLabel.Text = "You are at the maximum rank!";
                    }
                }, x);
            });
        }