public IEnumerable <TypeAndAmountSelection> Select(string tableName, string name) { var collection = collectionSelector.SelectFrom(tableName, name); var typesAndAmounts = collection.Select(e => Parse(e)).ToArray(); //INFO: We want to execute this immediately, so random rolls are not re-iterated and re-rolled return(typesAndAmounts); }
private void UpdateCreatureSpecialQualitiesAndFeats(Creature creature) { var featNamesToKeep = new List <string>(); featNamesToKeep.Add(FeatConstants.SpecialQualities.AttackBonus); var weaponProficiencies = collectionSelector.SelectFrom(TableNameConstants.Collection.FeatGroups, GroupConstants.WeaponProficiency); featNamesToKeep.AddRange(weaponProficiencies); var armorProficiencies = collectionSelector.SelectFrom(TableNameConstants.Collection.FeatGroups, GroupConstants.ArmorProficiency); featNamesToKeep.AddRange(armorProficiencies); var zombieQualities = featsGenerator.GenerateSpecialQualities( CreatureConstants.Templates.Zombie, creature.Type, creature.HitPoints, creature.Abilities, creature.Skills, creature.CanUseEquipment, creature.Size, creature.Alignment); creature.SpecialQualities = creature.SpecialQualities .Where(sq => featNamesToKeep.Contains(sq.Name)) .Union(zombieQualities); creature.Feats = creature.Feats.Where(f => featNamesToKeep.Contains(f.Name)); }
public IEnumerable <string> GenerateWith(string creature, Dictionary <string, Ability> abilities, IEnumerable <Skill> skills) { var languages = new List <string>(); var automaticLanguages = collectionsSelector.SelectFrom(TableNameConstants.Collection.LanguageGroups, creature + LanguageConstants.Groups.Automatic); languages.AddRange(automaticLanguages); var bonusLanguages = collectionsSelector.SelectFrom(TableNameConstants.Collection.LanguageGroups, creature + LanguageConstants.Groups.Bonus); var remainingBonusLanguages = bonusLanguages.Except(languages); var numberOfBonusLanguages = abilities[AbilityConstants.Intelligence].Modifier; if (IsInterpreter(skills)) { numberOfBonusLanguages = Math.Max(1, abilities[AbilityConstants.Intelligence].Modifier + 1); } if (numberOfBonusLanguages >= remainingBonusLanguages.Count()) { languages.AddRange(remainingBonusLanguages); return(languages); } while (numberOfBonusLanguages-- > 0 && remainingBonusLanguages.Any()) { var language = collectionsSelector.SelectRandomFrom(remainingBonusLanguages); languages.Add(language); } return(languages); }
private void UpdateCreatureLanguages(Creature creature) { if (!creature.Languages.Any()) { return; } var languages = new List <string>(creature.Languages); var automaticLanguage = collectionSelector.SelectRandomFrom( TableNameConstants.Collection.LanguageGroups, CreatureConstants.Templates.HalfFiend + LanguageConstants.Groups.Automatic); languages.Add(automaticLanguage); var bonusLanguages = collectionSelector.SelectFrom( TableNameConstants.Collection.LanguageGroups, CreatureConstants.Templates.HalfFiend + LanguageConstants.Groups.Bonus); var quantity = Math.Min(2, creature.Abilities[AbilityConstants.Intelligence].Modifier); var availableBonusLanguages = bonusLanguages.Except(languages); if (availableBonusLanguages.Count() <= quantity && quantity > 0) { languages.AddRange(availableBonusLanguages); } while (quantity-- > 0 && availableBonusLanguages.Any()) { var bonusLanguage = collectionSelector.SelectRandomFrom(availableBonusLanguages); languages.Add(bonusLanguage); } creature.Languages = languages.Distinct(); }
public Item GenerateAtLevel(int level, string itemType, string itemName, params string[] traits) { if (level < LevelLimits.Minimum || level > LevelLimits.Maximum) { throw new ArgumentException($"Level {level} is not a valid level for treasure generation"); } var tableName = string.Format(TableNameConstants.Percentiles.Formattable.LevelXItems, level); var result = typeAndAmountPercentileSelector.SelectFrom(tableName); var powers = collectionSelector.SelectFrom(TableNameConstants.Collections.Set.PowerGroups, itemType); if (itemType != ItemTypeConstants.Scroll && itemType != ItemTypeConstants.Wand) { powers = collectionSelector.SelectFrom(TableNameConstants.Collections.Set.PowerGroups, itemName); } var power = PowerHelper.AdjustPower(result.Type, powers); if (power == PowerConstants.Mundane) { return(GenerateMundaneItem(itemType, itemName, traits)); } return(GenerateMagicalItemAtPower(power, itemType, itemName, traits)); }
public Item GenerateRandom(string power) { var rodPowers = collectionsSelector.SelectFrom(TableNameConstants.Collections.Set.PowerGroups, ItemTypeConstants.Staff); var adjustedPower = PowerHelper.AdjustPower(power, rodPowers); var tablename = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, adjustedPower, ItemTypeConstants.Staff); var selection = typeAndAmountPercentileSelector.SelectFrom(tablename); return(GenerateStaff(selection.Type, selection.Amount)); }
private Weapon GeneratePrototype(string name) { var weapon = new Weapon(); weapon.Name = name; weapon.BaseNames = collectionsSelector.SelectFrom(TableNameConstants.Collections.Set.ItemGroups, name); weapon.Quantity = 0; return(weapon); }
private CreatureType GetCreatureType(string creatureName) { var creatureType = new CreatureType(); var types = collectionSelector.SelectFrom(TableNameConstants.Collection.CreatureTypes, creatureName); creatureType.Name = types.First(); creatureType.SubTypes = types.Skip(1); return(creatureType); }
private Weapon GeneratePrototype(string power, string itemName, bool isSpecific, params string[] traits) { var prototype = new Weapon(); if (isSpecific) { var specificItem = specificGearGenerator.GeneratePrototypeFrom(power, ItemTypeConstants.Weapon, itemName, traits); specificItem.CloneInto(prototype); return(prototype); } var canBeSpecific = specificGearGenerator.CanBeSpecific(power, ItemTypeConstants.Weapon, itemName); var tableName = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, ItemTypeConstants.Weapon); var bonus = string.Empty; var specialAbilitiesCount = 0; do { bonus = percentileSelector.SelectFrom(tableName); }while (!canBeSpecific && bonus == ItemTypeConstants.Weapon); while (bonus == SpecialAbility) { specialAbilitiesCount++; do { bonus = percentileSelector.SelectFrom(tableName); }while (!canBeSpecific && bonus == ItemTypeConstants.Weapon); } prototype.Traits = new HashSet <string>(traits); if (bonus == ItemTypeConstants.Weapon && canBeSpecific) { var specificName = specificGearGenerator.GenerateNameFrom(power, ItemTypeConstants.Weapon, itemName); var specificItem = specificGearGenerator.GeneratePrototypeFrom(power, ItemTypeConstants.Weapon, specificName, traits); specificItem.CloneInto(prototype); return(prototype); } prototype.Name = itemName; prototype.BaseNames = collectionsSelector.SelectFrom(TableNameConstants.Collections.Set.ItemGroups, itemName); prototype.Quantity = 0; prototype.Magic.Bonus = Convert.ToInt32(bonus); prototype.Magic.SpecialAbilities = Enumerable.Repeat(new SpecialAbility(), specialAbilitiesCount); prototype.ItemType = ItemTypeConstants.Weapon; return(prototype); }
private IEnumerable <string> GetUntrainedSkillsNames(bool canUseEquipment) { var untrainedSkillNames = collectionsSelector.SelectFrom(TableNameConstants.Collection.SkillGroups, GroupConstants.Untrained); if (!canUseEquipment) { var unnaturalSkills = collectionsSelector.SelectFrom(TableNameConstants.Collection.SkillGroups, GroupConstants.Unnatural); untrainedSkillNames = untrainedSkillNames.Except(unnaturalSkills); } return(untrainedSkillNames); }
public bool IsCompatible(string creature) { var types = collectionSelector.SelectFrom(TableNameConstants.Collection.CreatureTypes, creature); if (!creatureTypes.Contains(types.First())) { return(false); } var creatureData = creatureDataSelector.SelectFor(creature); if (creatureData.LevelAdjustment.HasValue) { return(true); } var hitDice = adjustmentSelector.SelectFrom <double>(TableNameConstants.Adjustments.HitDice, creature); if (hitDice >= 5) { return(true); } return(false); }
public Item Generate(string power, string itemName, params string[] traits) { var possiblePowers = collectionsSelector.SelectFrom(TableNameConstants.Collections.Set.PowerGroups, itemName); var adjustedPower = PowerHelper.AdjustPower(power, possiblePowers); var tableName = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, adjustedPower, ItemTypeConstants.WondrousItem); var results = typeAndAmountPercentileSelector.SelectAllFrom(tableName); var matches = results.Where(r => r.Type == itemName); var result = collectionsSelector.SelectRandomFrom(matches); var item = BuildWondrousItem(itemName, traits); item.Magic.Bonus = result.Amount; return(item); }
public bool IsCompatible(string creature) { var creatureTypes = collectionSelector.SelectFrom(TableNameConstants.Collection.CreatureTypes, creature); if (creatureTypes.First() != CreatureConstants.Types.Humanoid) { return(false); } var creatureData = creatureDataSelector.SelectFor(creature); if (creatureData.LevelAdjustment.HasValue) { return(true); } if (creatureData.CasterLevel >= PhylacterySpellLevel) { return(true); } var spellcasters = typeAndAmountSelector.Select(TableNameConstants.TypeAndAmount.Casters, creature); if (spellcasters.Any(s => s.Amount >= PhylacterySpellLevel)) { return(true); } return(false); }
public CreatureDataSelection SelectFor(string creatureName) { var data = collectionSelector.SelectFrom(TableNameConstants.Collection.CreatureData, creatureName); var selection = Parse(data); return(selection); }
public T SelectFrom <T>(string tableName, string name) { var collection = collectionsSelector.SelectFrom(tableName, name); var adjustment = GetAdjustment <T>(collection); return(adjustment); }
private FeatSelection SelectFeat(KeyValuePair <string, IEnumerable <string> > dataKVP) { var featSelection = new FeatSelection(); featSelection.Feat = dataKVP.Key; var data = dataKVP.Value.ToArray(); featSelection.RequiredBaseAttack = Convert.ToInt32(data[DataIndexConstants.FeatData.BaseAttackRequirementIndex]); featSelection.FocusType = data[DataIndexConstants.FeatData.FocusTypeIndex]; featSelection.Frequency.Quantity = Convert.ToInt32(data[DataIndexConstants.FeatData.FrequencyQuantityIndex]); featSelection.Frequency.TimePeriod = data[DataIndexConstants.FeatData.FrequencyTimePeriodIndex]; featSelection.Power = Convert.ToInt32(data[DataIndexConstants.FeatData.PowerIndex]); featSelection.MinimumCasterLevel = Convert.ToInt32(data[DataIndexConstants.FeatData.MinimumCasterLevelIndex]); featSelection.RequiredHands = Convert.ToInt32(data[DataIndexConstants.FeatData.RequiredHandQuantityIndex]); featSelection.RequiredNaturalWeapons = Convert.ToInt32(data[DataIndexConstants.FeatData.RequiredNaturalWeaponQuantityIndex]); featSelection.RequiresNaturalArmor = Convert.ToBoolean(data[DataIndexConstants.FeatData.RequiresNaturalArmorIndex]); featSelection.RequiresSpecialAttack = Convert.ToBoolean(data[DataIndexConstants.FeatData.RequiresSpecialAttackIndex]); featSelection.RequiresSpellLikeAbility = Convert.ToBoolean(data[DataIndexConstants.FeatData.RequiresSpellLikeAbilityIndex]); featSelection.RequiresEquipment = Convert.ToBoolean(data[DataIndexConstants.FeatData.RequiresEquipmentIndex]); featSelection.RequiredFeats = GetRequiredFeats(featSelection.Feat); featSelection.RequiredSkills = GetRequiredSkills(featSelection.Feat); featSelection.RequiredAbilities = GetRequiredAbilities(featSelection.Feat); featSelection.RequiredSpeeds = GetRequiredSpeeds(featSelection.Feat); featSelection.RequiredSizes = GetRequiredSizes(featSelection.Feat); var featsTakenMultipleTimes = collectionsSelector.SelectFrom(TableNameConstants.Collection.FeatGroups, GroupConstants.TakenMultipleTimes); featSelection.CanBeTakenMultipleTimes = featsTakenMultipleTimes.Contains(featSelection.Feat); return(featSelection); }
public bool IsCompatible(string creature) { var types = collectionSelector.SelectFrom(TableNameConstants.Collection.CreatureTypes, creature); if (types.Contains(CreatureConstants.Types.Subtypes.Incorporeal)) { return(false); } if (!creatureTypes.Contains(types.First())) { return(false); } var alignments = collectionSelector.SelectFrom(TableNameConstants.Collection.AlignmentGroups, creature); return(alignments.Any(a => !a.Contains(AlignmentConstants.Evil))); }
public WeaponSelection Select(string name) { var data = collectionSelector.SelectFrom(TableNameConstants.Collections.Set.WeaponData, name).ToArray(); var damagesData = collectionSelector.SelectFrom(TableNameConstants.Collections.Set.WeaponDamages, name).ToArray(); var damages = new List <List <Damage> >(); foreach (var damageData in damagesData) { var sizeDamagesData = damageHelper.ParseEntries(damageData); var sizeDamages = new List <Damage>(); foreach (var sizeDamageData in sizeDamagesData) { sizeDamages.Add(new Damage { Roll = sizeDamageData[DataIndexConstants.Weapon.DamageData.RollIndex], Type = sizeDamageData[DataIndexConstants.Weapon.DamageData.TypeIndex], Condition = sizeDamageData[DataIndexConstants.Weapon.DamageData.ConditionIndex], }); } damages.Add(sizeDamages); } var selection = new WeaponSelection(); selection.ThreatRange = Convert.ToInt32(data[DataIndexConstants.Weapon.ThreatRange]); selection.Ammunition = data[DataIndexConstants.Weapon.Ammunition]; selection.CriticalMultiplier = data[DataIndexConstants.Weapon.CriticalMultiplier]; selection.SecondaryCriticalMultiplier = data[DataIndexConstants.Weapon.SecondaryCriticalMultiplier]; var sizes = TraitConstants.Sizes.All().ToArray(); for (var i = 0; i < sizes.Length; i++) { var critIndex = i + sizes.Length; selection.DamagesBySize[sizes[i]] = damages[i]; selection.CriticalDamagesBySize[sizes[i]] = damages[critIndex]; } return(selection); }
public void SelectFrom_ReturnsInnerResult() { mockInnerSelector .Setup(s => s.SelectFrom("my table", "my collection")) .Returns(new[] { "my result", "my other result" }); var result = proxy.SelectFrom("my table", "my collection"); Assert.That(result, Is.EqualTo(new[] { "my result", "my other result" })); }
private Armor SetArmorAttributes(Armor armor) { armor.ItemType = ItemTypeConstants.Armor; armor.Quantity = 1; var tableName = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, armor.ItemType); armor.Attributes = collectionsSelector.SelectFrom(tableName, armor.Name); armor.Size = GetSize(armor); armor.Traits.Remove(armor.Size); var armorSelection = armorDataSelector.Select(armor.Name); armor.ArmorBonus = armorSelection.ArmorBonus; armor.ArmorCheckPenalty = armorSelection.ArmorCheckPenalty; armor.MaxDexterityBonus = armorSelection.MaxDexterityBonus; return(armor); }
public ArmorSelection Select(string name) { var data = innerSelector.SelectFrom(TableNameConstants.Collections.Set.ArmorData, name).ToArray(); var selection = new ArmorSelection(); selection.ArmorBonus = Convert.ToInt32(data[DataIndexConstants.Armor.ArmorBonus]); selection.ArmorCheckPenalty = Convert.ToInt32(data[DataIndexConstants.Armor.ArmorCheckPenalty]); selection.MaxDexterityBonus = Convert.ToInt32(data[DataIndexConstants.Armor.MaxDexterityBonus]); return(selection); }
public Item Generate(string power, string itemName, params string[] traits) { var possiblePowers = collectionSelector.SelectFrom(TableNameConstants.Collections.Set.PowerGroups, itemName); var adjustedPower = PowerHelper.AdjustPower(power, possiblePowers); var tableName = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, adjustedPower, ItemTypeConstants.Potion); var results = typeAndAmountPercentileSelector.SelectAllFrom(tableName); var matches = results.Where(r => NameMatches(r.Type, itemName)); var result = collectionSelector.SelectRandomFrom(matches); return(GeneratePotion(result.Type, result.Amount, traits)); }
public SkillSelection SelectFor(string skill) { var data = collectionSelector.SelectFrom(TableNameConstants.Collection.SkillData, skill).ToArray(); var selection = new SkillSelection(); selection.BaseAbilityName = data[DataIndexConstants.SkillSelectionData.BaseAbilityNameIndex]; selection.SkillName = data[DataIndexConstants.SkillSelectionData.SkillNameIndex]; selection.RandomFociQuantity = Convert.ToInt32(data[DataIndexConstants.SkillSelectionData.RandomFociQuantityIndex]); selection.Focus = data[DataIndexConstants.SkillSelectionData.FocusIndex]; return(selection); }
private Dictionary <string, IEnumerable <string> > GetSpecialMaterialAttributes() { var specialMaterialAttributeRequirements = new Dictionary <string, IEnumerable <string> >(); var allMaterials = TraitConstants.SpecialMaterials.All(); foreach (var material in allMaterials) { var attributeRequirements = collectionsSelector.SelectFrom(TableNameConstants.Collections.Set.SpecialMaterials, material); specialMaterialAttributeRequirements.Add(material, attributeRequirements); } return(specialMaterialAttributeRequirements); }
private string GetArmorType(string itemName) { if (specificGearGenerator.IsSpecific(AttributeConstants.Shield, itemName)) { return(AttributeConstants.Shield); } if (specificGearGenerator.IsSpecific(ItemTypeConstants.Armor, itemName)) { return(ItemTypeConstants.Armor); } var tableName = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, ItemTypeConstants.Armor); var attributes = collectionsSelector.SelectFrom(tableName, itemName); if (attributes.Contains(AttributeConstants.Shield)) { return(AttributeConstants.Shield); } return(ItemTypeConstants.Armor); }
public IEnumerable <AttackSelection> Select(string creatureName, string originalSize, string advancedSize) { var attackData = collectionSelector.SelectFrom(TableNameConstants.Collection.AttackData, creatureName); var selections = new List <AttackSelection>(); foreach (var data in attackData) { var selection = Parse(data, originalSize, advancedSize); selections.Add(selection); } return(selections); }
public IEnumerable <Spell> GenerateKnown(string creature, string caster, int casterLevel, Alignment alignment, Ability castingAbility, params string[] domains) { var spells = new List <Spell>(); var divineCasters = collectionsSelector.SelectFrom(TableNameConstants.Collection.CasterGroups, SpellConstants.Sources.Divine); if (divineCasters.Contains(caster)) { return(GetAllKnownSpells(creature, caster, casterLevel, alignment, castingAbility, domains)); } var quantities = GetKnownSpellQuantities(caster, casterLevel, castingAbility, domains); foreach (var spellQuantity in quantities) { var levelSpells = GetRandomKnownSpellsForLevel(creature, spellQuantity, caster, alignment, domains); spells.AddRange(levelSpells); } return(spells); }
public RangeSelection SelectFrom(string tableName, string name) { var data = innerSelector.SelectFrom(tableName, name).ToArray(); if (data.Count() != 2) { throw new Exception("Data is not in format for range"); } var selection = new RangeSelection(); selection.Minimum = Convert.ToInt32(data[DataIndexConstants.Range.Minimum]); selection.Maximum = Convert.ToInt32(data[DataIndexConstants.Range.Maximum]); return(selection); }
public IntelligenceSelection SelectFrom(string name) { var data = innerSelector.SelectFrom(TableNameConstants.Collections.Set.IntelligenceData, name).ToList(); if (data.Count != 3) { throw new Exception("Data is not formatted for intelligence"); } var result = new IntelligenceSelection(); result.Senses = data[DataIndexConstants.Intelligence.Senses]; result.LesserPowersCount = Convert.ToInt32(data[DataIndexConstants.Intelligence.LesserPowersCount]); result.GreaterPowersCount = Convert.ToInt32(data[DataIndexConstants.Intelligence.GreaterPowersCount]); return(result); }
public SpecialAbilitySelection SelectFrom(string name) { var data = innerSelector.SelectFrom(TableNameConstants.Collections.Set.SpecialAbilityAttributes, name).ToArray(); if (data.Length != 3) { throw new Exception("Data is not formatted for special abilities"); } var selection = new SpecialAbilitySelection(); selection.BaseName = data[DataIndexConstants.SpecialAbility.BaseName]; selection.BonusEquivalent = Convert.ToInt32(data[DataIndexConstants.SpecialAbility.BonusEquivalent]); selection.Power = Convert.ToInt32(data[DataIndexConstants.SpecialAbility.Power]); return(selection); }