Ejemplo n.º 1
0
        void AddModelName(List <DataModel> cardData, List <ModelInfoWrapper> models, CCAttachedModelInfoResponse model)
        {
            var name = model.Name;

            if (name.Contains("(min)"))
            {
                name = name.Replace("(min)", string.Empty);
            }
            else if (name.Contains("(max)"))
            {
                name = name.Replace("(max)", string.Empty);
            }

            // handle req point cards
            else if (name.EndsWith("(2)"))
            {
                name = name.Replace("(2)", string.Empty);
            }
            else if (name.EndsWith("(3)"))
            {
                name = name.Replace("(3)", string.Empty);
            }
            else if (name.EndsWith("(4)"))
            {
                name = name.Replace("(4)", string.Empty);
            }
            else if (name.EndsWith("(5)"))
            {
                name = name.Replace("(5)", string.Empty);
            }
            else if (name.EndsWith("(6)"))
            {
                name = name.Replace("(6)", string.Empty);
            }

            name = name.Trim();

            models.Add(new ModelInfoWrapper
            {
                Name    = name,
                CCModel = model,
                // need to trim the name to match,
                // otherwise things like (min) & (max) will match
                Card = cardData.FirstOrDefault(x => x.Name == name),
            });
        }
Ejemplo n.º 2
0
        public async Task <CCInfoResponse> ParseWarroomText(string text)
        {
            var info = new CCInfoResponse()
            {
                Lists = new CCListInfoResponse[]
                {
                    new CCListInfoResponse()
                }
            };

            var reader = new StringReader(text);

            string line      = null;
            int    lineCount = 0;
            bool   end       = false;

            List <CCModelInfoResponse> models = new List <CCModelInfoResponse>();

            do
            {
                line = await reader.ReadLineAsync();

                if (line != null)
                {
                    lineCount++;
                    if (lineCount == 1)
                    {
                        if (line != "War Room Army")
                        {
                            throw new InvalidDataException("List text must start with 'War Room Army'. Do not modify the text after copying from WarRoom2.");
                        }
                    }
                    else if (lineCount == 3)
                    {
                        // Crucible Guard - list name
                        info.Faction = line.Split(" - ")[0];
                    }
                    else if (lineCount == 5)
                    {
                        // Theme: Magnum Opus
                        info.Lists[0].Theme = line.Substring(7);
                    }
                    else if (lineCount == 6)
                    {
                        int.TryParse(line.Split(" / ")[0], out int points);
                        info.Lists[0].Points = points;
                    }
                    else if (lineCount >= 9)
                    {
                        // empty line between stuff
                        if (string.IsNullOrWhiteSpace(line))
                        {
                            continue;
                        }
                        // end of list text
                        else if (line == "---" || line.StartsWith("THEME:"))
                        {
                            end = true;
                            continue;
                        }
                        // regular model (not attached)
                        else if (!line.StartsWith("-    "))
                        {
                            string type = null;
                            string l    = line;

                            var  costString     = l.Split(" ").LastOrDefault();
                            bool costIntSuccess = int.TryParse(costString, out int costInt);

                            if (l.Contains("WJ:"))
                            {
                                // infernals uses WJ points
                                type = info.Faction == "Infernals" ? "Master" : "Warcaster";
                            }
                            else if (l.Contains("WB:"))
                            {
                                type = "Warlock";
                            }
                            else if (l.Contains("PC:"))
                            {
                                // not sure a better way to do this with out model types in the lookup
                                type = costIntSuccess && costInt >= 10 ? "Battle Engine/Structure" : "Solo";
                            }
                            else
                            {
                                type = "Unit"; // assume unit if doesn't contain WJ/WB/PC
                            }

                            var model = new CCModelInfoResponse()
                            {
                                Name = l.Split(" - ").FirstOrDefault(),
                                Type = type,
                                Cost = costString?.Trim()
                            };

                            models.Add(model);
                        }
                        // attached models, caster/command attachments & jacks/beasts
                        else if (line.StartsWith("-    "))
                        {
                            var l = line.Replace("-    ", string.Empty);

                            // (Battlegroup Points Used XX)
                            if (l.Contains("Battlegroup Points Used"))
                            {
                                l = l.RemoveBetween('(', ')')
                                    .Replace("()", string.Empty);
                            }

                            var parent = models.Last();

                            if (parent.Attached == null)
                            {
                                parent.Attached = new CCAttachedModelInfoResponse[0];
                            }

                            var attached = parent.Attached.ToList();

                            var costString = l.Split(": ").LastOrDefault();

                            bool costIntSuccess = int.TryParse(costString, out int costInt);

                            if (!costIntSuccess)
                            {
                                continue;
                            }

                            var model = new CCAttachedModelInfoResponse
                            {
                                Name = l.Split(" - ").FirstOrDefault(),
                                Type = parent.Type == "Unit" ? "Command Attachement"
                                    : parent.Type == "Warcaster" ? "Warjack"
                                    : parent.Type == "Warlock" ? "Warbeast"
                                    : parent.Type == "Master" ? "Horror"
                                    : null,
                                Cost = l.Split(": ").LastOrDefault()?.Trim()
                            };

                            // assume solo attacement for caster if 5 or less.
                            if ((parent.Type == "Warcaster" || parent.Type == "Warlock" || parent.Type == "Master") &&
                                costIntSuccess && costInt <= 5)
                            {
                                model.Type = "Solo";
                            }

                            attached.Add(model);

                            parent.Attached = attached.ToArray();
                        }
                    }
                }
            }while (!end && line != null);

            info.Lists[0].Models = models.ToArray();

            return(info);
        }