//TODO move this to an extension method of IOracleEntry? /// <summary> /// Gets the result of a oracle roll, and any rolls that would result from it. /// </summary> /// <param name="services"></param> /// <param name="game"></param> /// <returns></returns> public string GetOracleResultPrompt(IServiceProvider services, GameName game, Random rnd = null) { var roller = new OracleRoller(services, game, rnd); var tables = roller.ParseOracleTables(Prompt); if (tables.Count == 0) { return(Prompt); } roller.BuildRollResults(Prompt); var finalResults = roller.RollResultList.Select(ocl => ocl.Result.Prompt); return($"{Prompt}\n" + String.Join(" / ", finalResults)); }
/// <summary> /// Gets the result of a oracle roll, and any rolls that would result from it. /// </summary> /// <param name="services"></param> /// <param name="game"></param> /// <returns></returns> public string GetOracleResult(IServiceProvider services, GameName game, Random rnd = null, string[] additionalSearchTerms = null) { var roller = new OracleRoller(services, game, rnd); var tables = roller.ParseOracleTables(Description); if (tables.Count == 0) { return(Description); } roller.BuildRollResults(Description, additionalSearchTerms); var finalResults = roller.RollResultList.Select(ocl => ocl.Result.Description); return($"{Description}\n" + String.Join(" / ", finalResults)); }
/// <summary> /// Gets the result of a oracle roll, and any rolls that would result from it. /// </summary> /// <param name="services"></param> /// <param name="game"></param> /// <returns></returns> public static string GetOracleResult(this IOracleEntry oracle, IServiceProvider services, GameName game, Random rnd = null) { var roller = new OracleRoller(services, game, rnd); var tables = roller.ParseOracleTables(oracle.Description); if (tables.Count == 0) { return(oracle.Description); } roller.BuildRollResults(oracle.Description); var finalResults = roller.RollResultList.Select(ocl => ocl.Result.Description); return($"{oracle.Description}\n" + String.Join(" / ", finalResults)); }
public List <RollResult> RandomOracleResultList(string TableName, IServiceProvider serviceProvider, GameName game = GameName.None, Random rand = null, string[] additionalSearchTerms = null) { if (rand == null) { rand = BotRandom.Instance; } var row = RandomRow(TableName, game, rand); var tableData = OracleList.Single(ot => ot.Name == TableName && (ot.Game == game || game == GameName.None)); game = tableData.Game ?? GameName.None; string lookup = row.Description; var match = Regex.Match(lookup, @"\[.*(\d+)x"); if (match.Success && int.TryParse(match.Groups[1].Value, out int rolls)) { List <string> ReplaceMultiRollTables = new List <string>(); for (int i = 0; i < rolls; i++) { ReplaceMultiRollTables.Add(tableData.Name); } lookup = lookup.Replace($"{match.Groups[1]}x", string.Join("/", ReplaceMultiRollTables)); } var oracleService = serviceProvider.GetRequiredService <OracleService>(); var roller = new OracleRoller(oracleService, game, rand); var tables = roller.ParseOracleTables(lookup); if (tables.Count == 0) { var rollResult = new RollResult(); rollResult.ParentTable = serviceProvider.GetRequiredService <OracleService>().OracleList.First(tbl => tbl.Name == TableName && (tbl.Game == game || game == GameName.None)); } roller.BuildRollResults(lookup, additionalSearchTerms); var finalResults = roller.RollResultList.Select(ocl => ocl.Result.Description); var spacer = (match.Success) ? " " : "\n"; return(roller.RollResultList); }