public void BuildNPCFromEmbed(Embed embed) { foreach (var aspectField in embed.Fields.Where(fld => fld.Name == StarforgedNPCResources.Aspect)) { Aspects.Add(aspectField.Value); } foreach (var dispositionField in embed.Fields.Where(fld => fld.Name == StarforgedNPCResources.Disposition)) { Dispositions.Add(dispositionField.Value); } foreach (var firstLook in embed.Fields.Where(fld => fld.Name == StarforgedNPCResources.FirstLook)) { FirstLooks.Add(firstLook.Value); } foreach (var goal in embed.Fields.Where(fld => fld.Name == NPCResources.Goal)) { Goals.Add(goal.Value); } foreach (var role in embed.Fields.Where(fld => fld.Name == NPCResources.Role)) { Roles.Add(role.Value); } Name = embed.Fields.FirstOrDefault(fld => fld.Name == NPCResources.Name).Value; IconUrl = embed.Thumbnail.HasValue ? embed.Thumbnail.Value.Url : null; EmbedDesc = embed.Description; }
public Settlement FromEmbed(IEmbed embed) { if (!embed.Description.Contains(SettlementResources.Settlement)) { throw new ArgumentException(SettlementResources.SettlementNotFoundError); } this.Authority = embed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.Authority).Value; this.FirstLooks = embed.Fields.Where(fld => fld.Name == SettlementResources.FirstLook)?.Select(item => item.Value).ToList() ?? new List <string>(); this.FirstLooksToReveal = FirstLooks.Count(); this.InitialContactRevealed = embed.Fields.Any(fld => fld.Name == SettlementResources.InitialContact); if (InitialContactRevealed) { this.InitialContact = embed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.InitialContact).Value; } this.Location = embed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.Location).Value; this.Name = embed.Title.Replace("__", ""); this.Population = embed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.Population).Value; this.Projects = embed.Fields.Where(fld => fld.Name == SettlementResources.SettlementProjects)?.Select(item => item.Value).ToList() ?? new List <string>(); this.ProjectsRevealed = embed.Fields.Count(fld => fld.Name.Contains(SettlementResources.SettlementProjects)); this.Region = StarforgedUtilites.GetAnySpaceRegion(embed.Description); this.SettlementTroubleRevealed = embed.Fields.Any(fld => fld.Name == SettlementResources.SettlementTrouble); if (SettlementTroubleRevealed) { this.SettlementTrouble = embed.Fields.FirstOrDefault(fld => fld.Name == SettlementResources.SettlementTrouble).Value; } this.IconUrl = embed.Thumbnail?.Url; return(this); }
public INpcGenerator Build(string NPCCreationOptions) { //TODO fix the regex so it can support Role: role1 Role: role2 syntax Match AspectsRegex = Regex.Match(NPCCreationOptions, $"{StarforgedNPCResources.Aspect}[{NPCResources.ItemSeperators}]([\\w ,]*)"); Match DispositionRegex = Regex.Match(NPCCreationOptions, $"{StarforgedNPCResources.Disposition}[{NPCResources.ItemSeperators}]([\\w ,]*)"); Match FirstLookRegex = Regex.Match(NPCCreationOptions, $"{StarforgedNPCResources.FirstLook}[{NPCResources.ItemSeperators}]([\\w ,]*)"); Match RolesRegex = Regex.Match(NPCCreationOptions, $"{NPCResources.Role}[{NPCResources.ItemSeperators}]([\\w ,]*)"); Match GoalsRegex = Regex.Match(NPCCreationOptions, $"{NPCResources.Goal}[{NPCResources.ItemSeperators}]([\\w ,]*)"); if (AspectsRegex.Success) { Aspects = AspectsRegex.Groups[1].Value.Split(',').ToList(); NPCCreationOptions = NPCCreationOptions.Replace(AspectsRegex.Groups[0].Value, ""); } if (DispositionRegex.Success) { Dispositions = DispositionRegex.Groups[1].Value.Split(',').ToList(); NPCCreationOptions = NPCCreationOptions.Replace(DispositionRegex.Groups[0].Value, ""); } if (FirstLookRegex.Success) { FirstLooks = FirstLookRegex.Groups[1].Value.Split(',').ToList(); NPCCreationOptions = NPCCreationOptions.Replace(FirstLookRegex.Groups[0].Value, ""); } if (GoalsRegex.Success) { Goals = GoalsRegex.Groups[1].Value.Split(',').ToList(); NPCCreationOptions = NPCCreationOptions.Replace(GoalsRegex.Groups[0].Value, ""); } if (RolesRegex.Success) { Roles = RolesRegex.Groups[1].Value.Split(',').ToList(); NPCCreationOptions = NPCCreationOptions.Replace(RolesRegex.Groups[0].Value, ""); } var oracles = Services.GetRequiredService <OracleService>(); if (FirstLooks.Count == 0) { FirstLooks.Add(oracles.RandomOracleResult("Character First Look", Services, GameName.Starforged)); } //TODO make this starforged name when available Name = (NPCCreationOptions.Trim().Length > 0) ? NPCCreationOptions : oracles.RandomRow("Ironlander Names", GameName.Ironsworn).GetOracleResult(Services, GameName.Starforged); return(this); }