Exemplo n.º 1
0
        // create a object BO from a SALT
        public static BuildOrder CreateBOFromSALT(SALT salt)
        {
            // some bo have their informations in the title. This try to extract them
            string titleToParse = salt.Title;
            Dictionary <string, string> metaDatas = salt.MetaDatas;

            // Matchup search
            Regex matchupFinder = new Regex(@".*([ZTP]V[ZTPX]).*", RegexOptions.IgnoreCase);
            Match matchResult   = matchupFinder.Match(titleToParse);

            if (matchResult.Success)
            {
                metaDatas.Add("matchup", matchResult.Groups[1].ToString());
            }
            else
            {
                metaDatas.Add("matchup", "PvX"); // huuum not sure of that
                //throw new FormatException("Matchup not found in this SALT");
            }
            titleToParse = matchupFinder.Replace(titleToParse, "");


            // Type search
            Regex typeFinder      = new Regex(@".*(Economic|All-in|All in|Cheese|Co-op|Timing Attack).*", RegexOptions.IgnoreCase);
            Match typeMatchResult = typeFinder.Match(titleToParse);

            if (typeMatchResult.Success)
            {
                metaDatas.Add("type", typeMatchResult.Groups[1].ToString());
            }
            else
            {
                metaDatas.Add("type", "");
            }
            titleToParse = typeFinder.Replace(titleToParse, "");

            return(new BuildOrder(titleToParse, salt.Actions, metaDatas));
        }
Exemplo n.º 2
0
        // Constructor of SALT
        public SALT(string build)
        {
            StringReader  reader = new StringReader(build);
            StringBuilder meta   = new StringBuilder();

            m_version    = m_mapping[(char)reader.Read()];
            listOfAction = new List <Action>();

            metaDatas = new Dictionary <string, string>();


            // Builds look like this:
            // [version]title|Author|description|~[supply][minutes][seconds][type][item id]...

            char c = (char)reader.Read();

            while (c != '~' && c != 65535 && c != -1)
            {
                meta.Append(c);
                c = (char)reader.Read();
            }

            var metaItems = meta.ToString().Split(new char[] { '|' });

            if (metaItems.Length != 4)
            {
                throw new ArgumentException("Expected 3 metadata items");
            }

            Title = metaItems[0];
            Console.WriteLine(Title);
            metaDatas.Add("author", metaItems[1]);
            metaDatas.Add("description", metaItems[2]);


            int read;

            char[] buffer = new char[5];

            read = reader.ReadBlock(buffer, 0, 5);

            while (read == 5)
            {
                // Supply of 0 is a blank
                int supply = m_mapping[buffer[0]];

                // Getting the action string from code
                string actionString;
                int    code = m_mapping[buffer[4]];

                switch ((StepType)m_mapping[buffer[3]])
                {
                case StepType.Unit:
                    actionString = SALT.GetUnit(code);
                    break;

                case StepType.Structure:
                    actionString = SALT.GetStructure(code);
                    break;

                case StepType.Morph:
                    actionString = SALT.GetMorph(code);
                    break;

                case StepType.Upgrade:
                    actionString = SALT.GetUpgrade(code);
                    break;

                default:
                    actionString = "Unknown";
                    break;
                }

                //var step = new BuildStep(supply, m_mapping[buffer[1]], m_mapping[buffer[2]], (BuildStep.StepType)m_mapping[buffer[3]], m_mapping[buffer[4]]);

                var action = new Action(new TimeSpan(0, 0, m_mapping[buffer[1]], m_mapping[buffer[2]]), actionString, "");
                listOfAction.Add(action);
                read = reader.ReadBlock(buffer, 0, 5);
            }
        }