public IEnumerable <string> SelectAllFrom(string tableName) { var results = innerSelector.SelectAllFrom(tableName); var resultsToPerformReplace = results.Where(r => replacementTables.Keys.Any(k => r.Contains(k))); var otherResults = results.Except(resultsToPerformReplace); var allResults = new List <string>(); allResults.AddRange(otherResults); foreach (var result in resultsToPerformReplace) { var replaceTargets = replacementTables.Keys.Where(k => result.Contains(k)); foreach (var replaceTarget in replaceTargets) { var replacements = innerSelector.SelectAllFrom(replacementTables[replaceTarget]); foreach (var replacement in replacements) { var newResult = result.Replace(replaceTarget, replacement); allResults.Add(newResult); } } } return(allResults); }
public IEnumerable <string> SelectAllFrom(string tableName) { var results = innerSelector.SelectAllFrom(tableName); var allResults = replacementSelector.SelectAll(results); return(allResults); }
public void DecoratorSelectsAllFromInnerSelector() { var percentiles = new[] { "first", "second" }; mockInnerSelector.Setup(s => s.SelectAllFrom("table")).Returns(percentiles); var result = decorator.SelectAllFrom("table"); Assert.That(result, Is.EqualTo(percentiles)); }
public void SelectAllFromTable() { var results = percentileSelector.SelectAllFrom("StringPercentileTable"); Assert.That(results, Is.EquivalentTo(new[] { "one", "two", "three", string.Empty, "eleven to one hundred" })); }
public Item Generate(Item template, bool allowRandomDecoration = false) { template.ItemType = ItemTypeConstants.Weapon; var weapon = template.CopyWithoutMagic(); if (ammunitionGenerator.TemplateIsAmmunition(template)) { weapon = ammunitionGenerator.GenerateFrom(template); weapon = weapon.CopyWithoutMagic(); } else { var tableName = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, weapon.ItemType); weapon.Attributes = collectionsSelector.SelectFrom(tableName, weapon.Name); } var sizes = percentileSelector.SelectAllFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes); if (weapon.Traits.Intersect(sizes).Any() == false) { var size = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes); weapon.Traits.Add(size); } if (allowRandomDecoration) { var isMasterwork = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IsMasterwork); if (isMasterwork) { weapon.Traits.Add(TraitConstants.Masterwork); } } return(weapon); }
public Item Generate(Item template, bool allowRandomDecoration = false) { var armor = template.CopyWithoutMagic(); armor.ItemType = ItemTypeConstants.Armor; armor.Quantity = 1; var tableName = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, armor.ItemType); armor.Attributes = attributesSelector.SelectFrom(tableName, armor.Name); var sizes = percentileSelector.SelectAllFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes); if (armor.Traits.Intersect(sizes).Any() == false) { var size = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes); armor.Traits.Add(size); } if (allowRandomDecoration) { var isMasterwork = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IsMasterwork); if (isMasterwork) { armor.Traits.Add(TraitConstants.Masterwork); } } return(armor); }
private List <SpecialAbility> GetAvailableAbilities(IEnumerable <string> tableNames, int bonus, IEnumerable <string> attributes) { var availableAbilities = new List <SpecialAbility>(); foreach (var tableName in tableNames) { var abilityNames = percentileSelector.SelectAllFrom(tableName); foreach (var abilityName in abilityNames) { if (abilityName == "BonusSpecialAbility") { continue; } var ability = GetSpecialAbility(abilityName); if (AllAttributeRequirementsMet(ability.AttributeRequirements, attributes) && bonus + ability.BonusEquivalent <= MaxBonus) { availableAbilities.Add(ability); } } } return(availableAbilities); }
public void ArmorPowerGroupsMatch(string itemName) { var possiblePowers = new List <string>(); var powers = table[ItemTypeConstants.Armor]; possiblePowers.AddRange(powers); var generalArmors = ArmorConstants.GetAllArmorsAndShields(false); var shields = ArmorConstants.GetAllShields(true); var cursed = percentileSelector.SelectAllFrom(TableNameConstants.Percentiles.Set.SpecificCursedItems); if (!generalArmors.Contains(itemName)) { var gearType = shields.Contains(itemName) ? AttributeConstants.Shield : ItemTypeConstants.Armor; possiblePowers.Remove(PowerConstants.Mundane); if (!cursed.Contains(itemName)) { foreach (var power in powers.Except(new[] { PowerConstants.Mundane })) { var tableName = string.Format(TableNameConstants.Percentiles.Formattable.POWERSpecificITEMTYPEs, power, gearType); var results = typeAndAmountPercentileSelector.SelectAllFrom(tableName); if (!results.Any(r => NameMatchesWithReplacements(r.Type, itemName))) { possiblePowers.Remove(power); } } } } base.Collections(itemName, possiblePowers.ToArray()); }
public void GetAllResultsReturnsAllContentValues() { var results = percentileSelector.SelectAllFrom(tableName); var distinctContent = table.Values.Distinct(); foreach (var content in distinctContent) { Assert.That(results, Contains.Item(content)); } var extras = distinctContent.Except(results); Assert.That(extras, Is.Empty); }
public void GetAllResultsReturnsWholeTable() { table.Add(9266, "9266 content"); table.Add(42, "42 content"); for (var i = 0; i <= 10; i++) { table.Add(i, "content"); } var results = percentileSelector.SelectAllFrom(tableName); var tableContents = table.Values.Distinct(); Assert.That(results, Is.EqualTo(tableContents)); }
public bool TemplateIsAmmunition(Item template) { var allAmmunitions = percentileSelector.SelectAllFrom(TableNameConstants.Percentiles.Set.Ammunitions); return(allAmmunitions.Contains(template.Name)); }