public static IDictionary <string, TerrainType> BuildDictionary(TerrainTypesConfig config) { IDictionary <string, TerrainType> terrainTypes = new Dictionary <string, TerrainType>(); foreach (IList <object> row in config.Query.Data) { try { IList <string> type = row.Select(r => r.ToString()).ToList(); string name = ParseHelper.SafeStringParse(type, config.Name, "Name", false); if (string.IsNullOrEmpty(name)) { continue; } if (!terrainTypes.TryAdd(name, new TerrainType(config, type))) { throw new NonUniqueObjectNameException("terrain type"); } } catch (Exception ex) { throw new TerrainTypeProcessingException((row.ElementAtOrDefault(config.Name) ?? string.Empty).ToString(), ex); } } return(terrainTypes); }
/// <summary> /// Constructor. /// </summary> public TerrainType(TerrainTypesConfig config, IList <string> data) { this.Matched = false; this.Name = ParseHelper.SafeStringParse(data, config.Name, "Name", true); this.CannotStopOn = (ParseHelper.SafeStringParse(data, config.CannotStopOn, "Cannot Stop On", false) == "Yes"); this.BlocksItems = (ParseHelper.SafeStringParse(data, config.BlocksItems, "Blocks Items", false) == "Yes"); this.RestrictAffiliations = ParseHelper.IntCSVParse(data, config.RestrictAffiliations, "Restrict Affiliations", true); this.Groupings = ParseHelper.IntCSVParse(data, config.Groupings, "Groupings", true); this.TextFields = ParseHelper.StringListParse(data, config.TextFields); this.HPModifier = ParseHelper.OptionalInt_Any(data, config.HPModifier, "HP Modifier"); this.CombatStatModifiers = new Dictionary <string, int>(); foreach (NamedStatConfig stat in config.CombatStatModifiers) { int val = ParseHelper.OptionalInt_Any(data, stat.Value, stat.SourceName); if (val == 0) { continue; } this.CombatStatModifiers.Add(stat.SourceName, val); } this.StatModifiers = new Dictionary <string, int>(); foreach (NamedStatConfig stat in config.StatModifiers) { int val = ParseHelper.OptionalInt_Any(data, stat.Value, stat.SourceName); if (val == 0) { continue; } this.StatModifiers.Add(stat.SourceName, val); } this.MovementCosts = new Dictionary <string, int>(); foreach (NamedStatConfig stat in config.MovementCosts) { int val = ParseHelper.Int_NonZeroPositive(data, stat.Value, $"{stat.SourceName} Movement Cost"); this.MovementCosts.Add(stat.SourceName, val); } this.WarpType = GetWarpTypeEnum(ParseHelper.SafeStringParse(data, config.WarpType, "Warp Type", false)); if (this.WarpType == WarpType.Entrance || this.WarpType == WarpType.Dual) { this.WarpCost = ParseHelper.Int_Positive(data, config.WarpCost, "Warp Cost"); } else { this.WarpCost = -1; } }