예제 #1
0
        public Embed GetEmbed()
        {
            string gameName = (Game != GameName.None) ? Game.ToString() : string.Empty;

            EmbedBuilder embed  = new EmbedBuilder().WithTitle($"{OracleResources.OracleResult}").WithAuthor(gameName);
            var          footer = new EmbedFooterBuilder();

            foreach (var item in RollResultList)
            {
                string rollDisplay = (item.ParentTable?.DisplayChances ?? true) ? $" [{item.Roll}]" : string.Empty;
                embed.AddField($"{item?.ParentTable?.Name}{rollDisplay}", item.Result.Description, item.ShouldInline);

                if (item.ParentTable?.Pair?.Length > 0 && !RollResultList.Any(rr => rr.ParentTable.Name == item.ParentTable.Pair))
                {
                    footer.Text = (footer.Text == null || footer.Text.Length == 0) ? $"{OracleResources.PairedTable} {item.ParentTable.Pair}" : $"{CultureInfo.CurrentCulture.TextInfo.ListSeparator} {item.ParentTable.Pair}";
                    embed.WithFooter(footer);
                }

                if (item.Result.Thumbnail?.Length > 0 && embed.ThumbnailUrl == null)
                {
                    embed.WithThumbnailUrl(item.Result.Thumbnail);
                }
            }

            return(embed.Build());
        }
예제 #2
0
        private void RollNested(StandardOracle oracleResult, int depth, OracleTable parentTable)
        {
            if (oracleResult == null || oracleResult.Oracles == null)
            {
                return;
            }

            //Todo fix it so the JSON can tell us what size die to roll
            int roll     = RollerRandom.Next(1, 101);
            var innerRow = oracleResult.Oracles.LookupOracle(roll);

            if (innerRow == null)
            {
                return;
            }

            RollResultList.Add(new RollResult {
                Roll = roll, Result = innerRow, Depth = depth, ParentTable = parentTable
            });

            if (innerRow.Oracles != null)
            {
                RollNested(innerRow, depth + 1, parentTable);
            }
        }
예제 #3
0
        public EmbedBuilder GetEmbedBuilder()
        {
            string gameName = (Game != GameName.None) ? Game.ToString() + " " : string.Empty;

            EmbedBuilder embed  = new EmbedBuilder().WithTitle($"__{gameName}{OracleResources.OracleResult}__");
            var          footer = new EmbedFooterBuilder();

            foreach (var item in RollResultList)
            {
                embed.AddField($"{OracleResources.OracleTable} {item.ParentTable.Name} [{item.Roll}]", item.Result.Description, item.ShouldInline);

                if (item.ParentTable?.Pair?.Length > 0 && !RollResultList.Any(rr => rr.ParentTable.Name == item.ParentTable.Pair))
                {
                    footer.Text = (footer.Text == null || footer.Text.Length == 0) ? $"{OracleResources.PairedTable} {item.ParentTable.Pair}" : $"{CultureInfo.CurrentCulture.TextInfo.ListSeparator} {item.ParentTable.Pair}";
                    embed.WithFooter(footer);
                }
            }

            return(embed);
        }
예제 #4
0
        private void RollFacade(string table, int depth = 0, string[] additionalSearchTerms = null)
        {
            table = table.Trim();

            var TablesToRoll = ParseOracleTables(table, additionalSearchTerms);

            if (TablesToRoll.Count == 0)
            {
                if (this.Game == GameName.None)
                {
                    throw new ArgumentException($"{OracleResources.UnknownTableError}{table}");
                }

                //try again without any game name
                this.Game = GameName.None;
                RollFacade(table, depth, additionalSearchTerms);
            }

            if (this.Game == GameName.None)
            {
                this.Game = TablesToRoll?.FirstOrDefault()?.Game ?? GameName.None;
            }

            foreach (var oracleTable in TablesToRoll)
            {
                int roll         = RollerRandom.Next(1, oracleTable.d + 1);
                var oracleResult = oracleTable.Oracles.LookupOracle(roll);
                if (oracleTable.ShowResult)
                {
                    RollResultList.Add(new RollResult
                    {
                        Roll         = roll,
                        Result       = oracleResult,
                        Depth        = depth,
                        ShouldInline = oracleTable?.DisplayMode?.Equals("Inline", StringComparison.OrdinalIgnoreCase) ?? false,
                        ParentTable  = oracleTable
                    });
                }

                //Check if we have any nested oracles
                if (oracleResult.Oracles != null)
                {
                    RollNested(oracleResult, depth: 1, oracleTable);
                }

                //Check if we need to roll another oracle
                var match = Regex.Match(oracleResult.Description, @"^\[(.*)\]$");
                if (match.Success)
                {
                    string nextTable = match.Groups[0].Value;
                    if (Regex.IsMatch(nextTable, @"^\[\d+x\]"))
                    {
                        MultiRollFacade(nextTable, oracleTable, depth);
                        return;
                    }
                    RollFacade(nextTable, depth + 1, additionalSearchTerms);
                }

                // Match "{Place} of {Namesake}'s {Detail}" style entries
                var formatedStringMatches = Regex.Matches(oracleResult.Description, @"\{([^\}]*)\}").ToList();
                for (int i = formatedStringMatches.Count - 1; i >= 0; i--)
                {
                    Match formatMatch = formatedStringMatches[i];
                    var   subTable    = OracleService.OracleList.SingleOrDefault(o => o.MatchTableAlias(formatMatch.Groups[1].Value) && (Game == GameName.None || Game == o.Game));
                    if (subTable == null)
                    {
                        continue;
                    }

                    var subRoller = new OracleRoller(OracleService, subTable.Game.GetValueOrDefault(), RollerRandom);
                    subRoller.BuildRollResults(subTable.Name);

                    var    replacement    = subRoller.RollResultList.Last().Result.Description;
                    string newDescription = oracleResult.Description.Substring(0, formatMatch.Index) + replacement + oracleResult.Description.Substring(formatMatch.Index + formatMatch.Length);
                    oracleResult.Description = newDescription;
                }
            }

            string output = string.Empty;

            foreach (var rollResult in RollResultList)
            {
                output += $"{OracleResources.Roll}: {rollResult.Roll} {OracleResources.Outcome}: {rollResult.Result.Description}\n";
            }
        }
예제 #5
0
        private void RollFacade(string table, int depth = 0)
        {
            table = table.Trim();

            var TablesToRoll = ParseOracleTables(table);

            if (TablesToRoll.Count == 0)
            {
                if (this.Game == GameName.None)
                {
                    throw new ArgumentException($"{OracleResources.UnknownTableError}{table}");
                }

                //try again without any game name
                this.Game = GameName.None;
                RollFacade(table, depth);
            }

            foreach (var oracleTable in TablesToRoll)
            {
                int roll         = RollerRandom.Next(1, oracleTable.d + 1);
                var oracleResult = oracleTable.Oracles.LookupOracle(roll);
                if (oracleTable.ShowResult)
                {
                    RollResultList.Add(new RollResult
                    {
                        Roll         = roll,
                        Result       = oracleResult,
                        Depth        = depth,
                        ShouldInline = oracleTable?.DisplayMode?.Equals("Inline", StringComparison.OrdinalIgnoreCase) ?? false,
                        ParentTable  = oracleTable
                    });
                }

                //Check if we have any nested oracles
                if (oracleResult.Oracles != null)
                {
                    RollNested(oracleResult, depth: 1);
                }

                //Check if we need to roll another oracle
                var match = Regex.Match(oracleResult.Description, @"^\[(.*)\]$");
                if (match.Success)
                {
                    string nextTable = match.Groups[0].Value;
                    if (Regex.IsMatch(nextTable, @"^\[\d+x\]"))
                    {
                        MultiRollFacade(nextTable, oracleTable, depth);
                        return;
                    }
                    RollFacade(nextTable, depth + 1);
                }
            }

            string output = string.Empty;

            foreach (var rollResult in RollResultList)
            {
                output += $"{OracleResources.Roll}: {rollResult.Roll} {OracleResources.Outcome}: {rollResult.Result.Description}\n";
            }
        }