Esempio n. 1
0
        public async Task <List <Models.GeneratedData> > Generate(CCInfoResponse ccListInfo)
        {
            var cardData = await DataHelper.GetLookupData();

            List <Models.GeneratedData> PDFLinks = new List <Models.GeneratedData>();

            string cardUrl = "http://cards.privateerpress.com?card_items_to_pdf=";

            foreach (var list in ccListInfo.Lists)
            {
                var caster = list.Models.First(x => x.Type == "Warcaster" || x.Type == "Warlock" || x.Type == "Master");

                var models = new List <ModelInfoWrapper>();

                foreach (var model in list.Models)
                {
                    AddModelName(cardData, models, model);

                    if (model.Attached != null)
                    {
                        foreach (var attached in model.Attached)
                        {
                            AddModelName(cardData, models, attached);
                        }
                    }
                }

                var grouped = models.GroupBy(x => x.Name);

                string queryString = null;
                foreach (var group in grouped)
                {
                    var name = group.Key;

                    var card  = group.FirstOrDefault()?.Card;
                    var model = group.FirstOrDefault()?.CCModel;

                    if (card != null)
                    {
                        int count = group.Count();

                        if (model.Type == "Solo")
                        {
                            count = 1;
                        }

                        queryString += $"${card.CardId},{count}";
                    }
                }

                PDFLinks.Add(new GeneratedData
                {
                    CasterName = caster.Name,
                    PDFUrl     = $"{cardUrl}{queryString}",
                    ListOutput = CreateListDisplayText(ccListInfo.Faction, list)
                });
            }

            return(PDFLinks);
        }
Esempio n. 2
0
 public GameListItemViewModel(int index, CCInfoResponse list, CCInfoResponse opponentList, DateTime date, string result, string scenario)
 {
     Index                = index;
     this.Date            = date;
     this.Result          = result;
     this.Scenario        = scenario;
     this.Faction         = list.Faction;
     this.Caster          = list.Lists[0].Caster;
     this.OpponentFaction = opponentList.Faction;
     this.OpponentCaster  = opponentList.Lists[0].Caster;
 }
Esempio n. 3
0
        async Task GeneratePDF()
        {
            try
            {
                this.PDFLinks.Clear();

                if (!string.IsNullOrEmpty(ConflictChamberList) &&
                    !string.IsNullOrEmpty(WarRoomText))
                {
                    await this.jsRuntime.InvokeVoidAsync("alert", "Please enter just a CC link or warroom text, not both");

                    return;
                }

                CCInfoResponse listInfo = null;

                if (!string.IsNullOrWhiteSpace(WarRoomText))
                {
                    listInfo = await DataHelper.ParseWarroomText(this.WarRoomText);
                }
                else if (!string.IsNullOrEmpty(ConflictChamberList) &&
                         DataHelper.TryGetListId(ConflictChamberList, out string ccid))
                {
                    listInfo = await DataHelper.GetConflictChamberList(ccid);
                }
                else
                {
                    throw new Exception("Please enter a valid conflict chamber permalink or WarRoom list text.");
                }

                var links = await this.PDFer.Generate(listInfo);

                PDFLinks.AddRange(links);
            }
            catch (Exception ex)
            {
                await jsRuntime.InvokeVoidAsync("alert", ex.Message);
            }
            finally
            {
                this.StateHasChanged();
            }
        }
Esempio n. 4
0
        static async Task Main(string[] args)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    var dataHelper = new DataHelper(httpClient);

                    Console.WriteLine("Enter List Url");
                    string url = Console.ReadLine().Trim();

                    CCInfoResponse info = null;
                    if (Uri.TryCreate(url, UriKind.RelativeOrAbsolute, out Uri uri) &&
                        dataHelper.TryGetListId(uri.ToString(), out string ccid))
                    {
                        info = await dataHelper.GetConflictChamberList(ccid);
                    }
                    else
                    {
                        info = await dataHelper.ParseWarroomText(listText);
                    }

                    var output = await new PDFer(httpClient, dataHelper)
                                 .Generate(info);

                    Console.WriteLine();
                    foreach (var link in output)
                    {
                        Console.WriteLine(link.PDFUrl);
                    }

                    Console.ReadLine();
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 5
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);
        }