Exemplo n.º 1
0
        public string SelectFrom(string tableName)
        {
            var result        = innerSelector.SelectFrom(tableName);
            var replaceResult = replacementSelector.SelectRandom(result);

            return(replaceResult);
        }
        public void DecoratorSelectsFromInnerSelector()
        {
            mockInnerSelector.Setup(s => s.SelectFrom("table")).Returns("percentile");
            var result = decorator.SelectFrom("table");

            Assert.That(result, Is.EqualTo("percentile"));
        }
Exemplo n.º 3
0
        public void GetPercentile(int roll, string content)
        {
            mockDice.Setup(d => d.Roll(1).d(100).AsSum <int>()).Returns(roll);
            var result = percentileSelector.SelectFrom(tableName);

            Assert.That(result, Is.EqualTo(content));
        }
        public Item Generate()
        {
            var armor = new Item();

            armor.Name = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneArmors);

            if (armor.Name == AttributeConstants.Shield)
            {
                armor.Name = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneShields);
            }

            armor.ItemType = ItemTypeConstants.Armor;
            var tableName = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, armor.ItemType);

            armor.Attributes = attributesSelector.SelectFrom(tableName, armor.Name);

            var isMasterwork = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IsMasterwork);

            if (isMasterwork)
            {
                armor.Traits.Add(TraitConstants.Masterwork);
            }

            var size = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes);

            armor.Traits.Add(size);

            return(armor);
        }
Exemplo n.º 5
0
        private Item GenerateMundaneItem()
        {
            var tableName = string.Format(TableNameConstants.Percentiles.Formattable.POWERItems, PowerConstants.Mundane);
            var itemType  = percentileSelector.SelectFrom(tableName);
            var generator = mundaneItemGeneratorFactory.CreateGeneratorOf(itemType);

            return(generator.Generate());
        }
Exemplo n.º 6
0
        public void RollPercentile()
        {
            table.Add(9266, "9266 content");
            mockDice.Setup(d => d.Roll(1).d(100).AsSum()).Returns(9266);

            var result = percentileSelector.SelectFrom(tableName);

            Assert.That(result, Is.EqualTo(table[9266]));
        }
Exemplo n.º 7
0
        public void SelectFromTable()
        {
            var result = percentileSelector.SelectFrom("StringPercentileTable");

            Assert.That(result, Is.EqualTo("one")
                        .Or.EqualTo("two")
                        .Or.EqualTo("three")
                        .Or.Empty
                        .Or.EqualTo("eleven to one hundred"));
        }
Exemplo n.º 8
0
        public string SelectFrom(string tableName)
        {
            var result         = innerSelector.SelectFrom(tableName);
            var replaceTargets = replacementTables.Keys.Where(k => result.Contains(k));

            foreach (var replaceTarget in replaceTargets)
            {
                var replacement = innerSelector.SelectFrom(replacementTables[replaceTarget]);
                result = result.Replace(replaceTarget, replacement);
            }

            return(result);
        }
        public Item GenerateAtPower(string power)
        {
            var tableName    = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, ItemTypeConstants.Armor);
            var result       = typeAndAmountPercentileSelector.SelectFrom(tableName);
            var abilityCount = 0;

            while (result.Type == "SpecialAbility")
            {
                abilityCount += result.Amount;
                result        = typeAndAmountPercentileSelector.SelectFrom(tableName);
            }

            if (result.Amount == 0)
            {
                return(specificGearGenerator.GenerateFrom(power, result.Type));
            }

            var armor = new Item();

            armor.ItemType    = ItemTypeConstants.Armor;
            armor.Magic.Bonus = result.Amount;

            tableName  = string.Format(TableNameConstants.Percentiles.Formattable.ARMORTYPETypes, result.Type);
            armor.Name = percentileSelector.SelectFrom(tableName);

            tableName                    = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, armor.ItemType);
            armor.Attributes             = collectionsSelector.SelectFrom(tableName, armor.Name);
            armor.Magic.SpecialAbilities = specialAbilitiesSelector.GenerateFor(armor.ItemType, armor.Attributes, power, armor.Magic.Bonus, abilityCount);

            return(armor);
        }
Exemplo n.º 10
0
        public string GenerateCurse()
        {
            var curse = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.Curses);

            if (curse == CurseConstants.Intermittent)
            {
                return(string.Format("{0} ({1})", curse, GetIntermittentFunctioning()));
            }

            if (curse == CurseConstants.Drawback)
            {
                return(percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.CurseDrawbacks));
            }

            return(curse);
        }
Exemplo n.º 11
0
        public Item GenerateAtPower(string power)
        {
            if (power == PowerConstants.Minor)
            {
                throw new ArgumentException("Cannot generate minor staves");
            }

            var tablename = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, ItemTypeConstants.Staff);
            var staffName = percentileSelector.SelectFrom(tablename);

            var staff = new Item();

            staff.Name          = staffName;
            staff.ItemType      = ItemTypeConstants.Staff;
            staff.Attributes    = new[] { AttributeConstants.OneTimeUse, AttributeConstants.Charged };
            staff               = BuildStaff(staff);
            staff.Magic.Charges = chargesGenerator.GenerateFor(staff.ItemType, staffName);

            if (staff.Name != StaffConstants.Power)
            {
                return(staff);
            }

            staff.Magic.Bonus = 2;

            return(staff);
        }
Exemplo n.º 12
0
        public Item Generate()
        {
            var type       = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneWeapons);
            var tableName  = string.Format(TableNameConstants.Percentiles.Formattable.WEAPONTYPEWeapons, type);
            var weaponName = percentileSelector.SelectFrom(tableName);

            var weapon = new Item();

            if (weaponName == AttributeConstants.Ammunition)
            {
                weapon = ammunitionGenerator.Generate();
            }
            else
            {
                weapon.Name = weaponName;

                if (weapon.Name.Contains("Composite"))
                {
                    weapon.Name = GetCompositeBowName(weaponName);
                    var compositeStrengthBonus = GetCompositeBowBonus(weaponName);
                    weapon.Traits.Add(compositeStrengthBonus);
                }

                weapon.ItemType   = ItemTypeConstants.Weapon;
                tableName         = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, weapon.ItemType);
                weapon.Attributes = collectionsSelector.SelectFrom(tableName, weapon.Name);
            }

            var isMasterwork = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IsMasterwork);

            if (isMasterwork)
            {
                weapon.Traits.Add(TraitConstants.Masterwork);
            }

            if (weapon.Attributes.Contains(AttributeConstants.Thrown) && weapon.Attributes.Contains(AttributeConstants.Melee) == false)
            {
                weapon.Quantity = dice.Roll().d20().AsSum();
            }

            var size = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes);

            weapon.Traits.Add(size);

            return(weapon);
        }
Exemplo n.º 13
0
        public Item Generate()
        {
            var tool = new Item();

            tool.Name     = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.Tools);
            tool.ItemType = ItemTypeConstants.Tool;

            return(tool);
        }
Exemplo n.º 14
0
        public IEnumerable <string> GenerateFor(string itemType, IEnumerable <string> attributes)
        {
            var tableName = GetTableName(itemType, attributes);
            var result    = percentileSelector.SelectFrom(tableName);

            if (string.IsNullOrEmpty(result))
            {
                return(Enumerable.Empty <string>());
            }

            return(result.Split(','));
        }
        public Item Generate()
        {
            var roll = dice.Roll().Percentile().AsSum();

            var ammunition = new Item();

            ammunition.Name       = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.Ammunitions);
            ammunition.Quantity   = Math.Max(1, roll / 2);
            ammunition.Attributes = attributesSelector.SelectFrom(TableNameConstants.Collections.Set.AmmunitionAttributes, ammunition.Name);
            ammunition.ItemType   = ItemTypeConstants.Weapon;

            return(ammunition);
        }
Exemplo n.º 16
0
        private string GetTraitFor(string name)
        {
            switch (name)
            {
            case WondrousItemConstants.HornOfValhalla: return(percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.HornOfValhallaTypes));

            case WondrousItemConstants.CandleOfInvocation: return(percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IntelligenceAlignments));

            case WondrousItemConstants.RobeOfTheArchmagi: return(percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.RobeOfTheArchmagiColors));

            default: return(string.Empty);
            }
        }
Exemplo n.º 17
0
        public Item GenerateAtPower(string power)
        {
            var wand = new Item();

            wand.ItemType  = ItemTypeConstants.Wand;
            wand.IsMagical = true;

            var tablename = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, wand.ItemType);
            var spell     = percentileSelector.SelectFrom(tablename);

            wand.Magic.Charges = chargesGenerator.GenerateFor(wand.ItemType, spell);
            wand.Name          = string.Format("Wand of {0}", spell);
            wand.Attributes    = new[] { AttributeConstants.Charged, AttributeConstants.OneTimeUse };

            return(wand);
        }
        private SpecialAbility GenerateAbilityFrom(IEnumerable <SpecialAbility> availableAbilities, IEnumerable <string> tableNames)
        {
            var abilityName = string.Empty;

            do
            {
                var index     = dice.Roll().d(tableNames.Count()).AsSum() - 1;
                var tableName = tableNames.ElementAt(index);

                abilityName = percentileSelector.SelectFrom(tableName);

                if (abilityName == "BonusSpecialAbility")
                {
                    return new SpecialAbility {
                               Name = abilityName
                    }
                }
                ;
            } while (!availableAbilities.Any(a => a.Name == abilityName));

            return(availableAbilities.First(a => a.Name == abilityName));
        }
Exemplo n.º 19
0
        public TypeAndAmountPercentileResult SelectFrom(string tableName)
        {
            var percentileResult = percentileSelector.SelectFrom(tableName);
            var result           = new TypeAndAmountPercentileResult();

            if (string.IsNullOrEmpty(percentileResult))
            {
                return(result);
            }

            if (percentileResult.Contains(",") == false)
            {
                var message = string.Format("Table {0} was not formatted for type and amount parsing", tableName);
                throw new FormatException(message);
            }

            var parsedResult = percentileResult.Split(',');

            result.Type   = parsedResult[0];
            result.Amount = dice.Roll(parsedResult[1]).AsSum();

            return(result);
        }
Exemplo n.º 20
0
        public IEnumerable <Attack> AddAttacks(IEnumerable <Feat> feats, IEnumerable <Attack> attacks, int numberOfHands)
        {
            var allAttacks       = new List <Attack>(attacks);
            var unnaturalAttacks = allAttacks.Where(a => !a.IsNatural);

            if (!unnaturalAttacks.Any())
            {
                return(allAttacks);
            }

            //Duplicate attacks
            var repeatedAttacks = unnaturalAttacks.Where(a => a.Frequency.Quantity > 1).ToArray();

            foreach (var attack in repeatedAttacks)
            {
                var individualAttacks = Enumerable.Range(1, attack.Frequency.Quantity)
                                        .Select(i => Clone(attack))
                                        .ToArray();

                foreach (var individualAttack in individualAttacks)
                {
                    individualAttack.Frequency.Quantity = 1;
                }

                allAttacks.Remove(attack);
                allAttacks.AddRange(individualAttacks);
            }

            var equipmentAttacks = unnaturalAttacks.Where(a => a.Name == AttributeConstants.Melee || a.Name == AttributeConstants.Ranged);

            if (!equipmentAttacks.Any())
            {
                return(allAttacks);
            }

            //Add additional melee attacks for two/multi-weapon fighting
            var superiorTwoWeaponFeat = feats.Any(f => f.Name == FeatConstants.SpecialQualities.TwoWeaponFighting_Superior ||
                                                  f.Name == FeatConstants.SpecialQualities.MultiweaponFighting_Superior);
            var greaterTwoWeaponFeat = feats.Any(f => f.Name == FeatConstants.TwoWeaponFighting_Greater ||
                                                 f.Name == FeatConstants.Monster.MultiweaponFighting_Greater);
            var improvedTwoWeaponFeat = feats.Any(f => f.Name == FeatConstants.TwoWeaponFighting_Improved ||
                                                  f.Name == FeatConstants.Monster.MultiweaponFighting_Improved);
            var twoWeaponFeat = feats.Any(f => f.Name == FeatConstants.TwoWeaponFighting ||
                                          f.Name == FeatConstants.Monster.MultiweaponFighting);
            var twoWeaponMelee = superiorTwoWeaponFeat ||
                                 greaterTwoWeaponFeat ||
                                 improvedTwoWeaponFeat ||
                                 twoWeaponFeat ||
                                 equipmentAttacks.Count(a => a.IsMelee) > 1 ||
                                 percentileSelector.SelectFrom(.99);
            var twoWeaponRanged = superiorTwoWeaponFeat ||
                                  greaterTwoWeaponFeat ||
                                  improvedTwoWeaponFeat ||
                                  twoWeaponFeat ||
                                  equipmentAttacks.Count(a => !a.IsMelee) > 1 ||
                                  percentileSelector.SelectFrom(.99);

            if (!twoWeaponMelee && !twoWeaponRanged)
            {
                return(allAttacks);
            }

            if (twoWeaponMelee)
            {
                allAttacks = AddAttacksPerHand(AttributeConstants.Melee, numberOfHands, allAttacks);
            }

            if (twoWeaponRanged)
            {
                allAttacks = AddAttacksPerHand(AttributeConstants.Ranged, numberOfHands, allAttacks);
            }

            foreach (var attack in equipmentAttacks)
            {
                if (attack.IsPrimary)
                {
                    attack.MaxNumberOfAttacks = 4;
                    attack.AttackBonuses.Add(-6);

                    if (twoWeaponFeat)
                    {
                        attack.AttackBonuses.Add(2);
                    }

                    if (superiorTwoWeaponFeat)
                    {
                        attack.AttackBonuses.Add(4);
                    }
                }
                else
                {
                    attack.MaxNumberOfAttacks = 1;
                    attack.AttackBonuses.Add(-10);

                    if (twoWeaponFeat)
                    {
                        attack.AttackBonuses.Add(6);
                    }

                    if (improvedTwoWeaponFeat)
                    {
                        attack.MaxNumberOfAttacks++;
                    }

                    if (greaterTwoWeaponFeat)
                    {
                        attack.MaxNumberOfAttacks++;
                    }

                    if (superiorTwoWeaponFeat)
                    {
                        attack.AttackBonuses.Add(4);
                    }
                }
            }

            return(allAttacks);
        }
Exemplo n.º 21
0
        public Intelligence GenerateFor(Item item)
        {
            var highStatResult = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IntelligenceStrongStats);
            var highStat       = Convert.ToInt32(highStatResult);

            var intelligence = new Intelligence();

            intelligence.Ego += highStat - 10 - highStat % 2;
            intelligence.Ego += item.Magic.Bonus;

            foreach (var ability in item.Magic.SpecialAbilities)
            {
                intelligence.Ego += ability.BonusEquivalent;
            }

            switch (dice.Roll().d3().AsSum())
            {
            case 1: intelligence.CharismaStat = 10; break;

            case 2: intelligence.IntelligenceStat = 10; break;

            case 3: intelligence.WisdomStat = 10; break;
            }

            intelligence.CharismaStat     = SetHighStat(highStat, intelligence.CharismaStat);
            intelligence.IntelligenceStat = SetHighStat(highStat, intelligence.IntelligenceStat);
            intelligence.WisdomStat       = SetHighStat(highStat, intelligence.WisdomStat);

            intelligence.Communication = attributesSelector.SelectFrom(TableNameConstants.Collections.Set.IntelligenceCommunication, highStatResult);

            if (intelligence.Communication.Contains("Speech"))
            {
                intelligence.Languages = GenerateLanguages(intelligence.IntelligenceStat);
            }

            intelligence.Ego += BoostEgoByCommunication(intelligence.Communication, "Read");
            intelligence.Ego += BoostEgoByCommunication(intelligence.Communication, "Read magic");
            intelligence.Ego += BoostEgoByCommunication(intelligence.Communication, "Telepathy");

            var intelligenceAttributesResult = intelligenceAttributesSelector.SelectFrom(TableNameConstants.Collections.Set.IntelligenceAttributes, highStatResult);

            intelligence.Senses = intelligenceAttributesResult.Senses;

            var lesserPowers = GeneratePowers("Lesser", intelligenceAttributesResult.LesserPowersCount);

            intelligence.Ego += lesserPowers.Count;
            intelligence.Powers.AddRange(lesserPowers);

            var greaterPowers = GeneratePowers("Greater", intelligenceAttributesResult.GreaterPowersCount);

            var roll = dice.Roll().d4().AsSum();

            if (roll <= intelligenceAttributesResult.GreaterPowersCount)
            {
                greaterPowers.RemoveAt(greaterPowers.Count - 1);
                intelligence.SpecialPurpose = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IntelligenceSpecialPurposes);
                intelligence.DedicatedPower = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.IntelligenceDedicatedPowers);
                intelligence.Ego           += 4;
            }

            intelligence.Ego += greaterPowers.Count * 2;
            intelligence.Powers.AddRange(greaterPowers);
            intelligence.Alignment   = GetAlignment(item);
            intelligence.Personality = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.PersonalityTraits);

            return(intelligence);
        }
        public Boolean SelectFrom(String tableName)
        {
            var result = innerSelector.SelectFrom(tableName);

            return(Convert.ToBoolean(result));
        }
Exemplo n.º 23
0
        public Item GenerateFrom(string power, string specificGearType)
        {
            var tableName = string.Format(TableNameConstants.Percentiles.Formattable.POWERSpecificITEMTYPEs, power, specificGearType);
            var result    = typeAndAmountPercentileSelector.SelectFrom(tableName);

            var gear = new Item();

            gear.Name                   = result.Type;
            gear.Magic.Bonus            = result.Amount;
            gear.Magic.SpecialAbilities = GetSpecialAbilities(specificGearType, gear.Name);
            gear.ItemType               = GetItemType(specificGearType);

            tableName       = string.Format(TableNameConstants.Collections.Formattable.SpecificITEMTYPEAttributes, specificGearType);
            gear.Attributes = collectionsSelector.SelectFrom(tableName, gear.Name);

            tableName = string.Format(TableNameConstants.Collections.Formattable.SpecificITEMTYPETraits, specificGearType);
            var traits = collectionsSelector.SelectFrom(tableName, gear.Name);

            foreach (var trait in traits)
            {
                gear.Traits.Add(trait);
            }

            if (gear.Attributes.Contains(AttributeConstants.Charged))
            {
                gear.Magic.Charges = chargesGenerator.GenerateFor(specificGearType, gear.Name);
            }

            if (gear.Name == WeaponConstants.JavelinOfLightning)
            {
                gear.IsMagical = true;
            }
            else if (gear.Name == ArmorConstants.CastersShield)
            {
                var hasSpell = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.CastersShieldContainsSpell);

                if (hasSpell)
                {
                    var spellType      = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.CastersShieldSpellTypes);
                    var spellLevel     = spellGenerator.GenerateLevel(PowerConstants.Medium);
                    var spell          = spellGenerator.Generate(spellType, spellLevel);
                    var formattedSpell = string.Format("{0} ({1}, {2})", spell, spellType, spellLevel);
                    gear.Contents.Add(formattedSpell);
                }
            }

            gear.Name     = RenameGear(gear.Name);
            gear.Quantity = GetQuantity(gear);

            if (gear.Name == WeaponConstants.SlayingArrow || gear.Name == WeaponConstants.GreaterSlayingArrow)
            {
                var designatedFoe = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.DesignatedFoes);
                var trait         = string.Format("Designated Foe: {0}", designatedFoe);
                gear.Traits.Add(trait);
            }

            if (gear.IsMagical == false)
            {
                var size = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.MundaneGearSizes);
                gear.Traits.Add(size);
            }

            return(gear);
        }
        public Item GenerateAtPower(string power)
        {
            var tablename             = string.Format(TableNameConstants.Percentiles.Formattable.POWERITEMTYPEs, power, ItemTypeConstants.Weapon);
            var bonus                 = percentileSelector.SelectFrom(tablename);
            var specialAbilitiesCount = 0;

            while (bonus == "SpecialAbility")
            {
                specialAbilitiesCount++;
                bonus = percentileSelector.SelectFrom(tablename);
            }

            if (bonus == ItemTypeConstants.Weapon)
            {
                return(specificGearGenerator.GenerateFrom(power, bonus));
            }

            var type = percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.WeaponTypes);

            tablename = string.Format(TableNameConstants.Percentiles.Formattable.WEAPONTYPEWeapons, type);
            var name = percentileSelector.SelectFrom(tablename);

            var weapon = new Item();

            if (name == AttributeConstants.Ammunition)
            {
                weapon = ammunitionGenerator.Generate();
            }
            else
            {
                weapon.ItemType = ItemTypeConstants.Weapon;
                weapon.Name     = name;

                if (weapon.Name.Contains("Composite"))
                {
                    weapon.Name = GetCompositeBowName(name);
                    var compositeStrengthBonus = GetCompositeBowBonus(name);
                    weapon.Traits.Add(compositeStrengthBonus);
                }

                tablename         = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, weapon.ItemType);
                weapon.Attributes = collectionsSelector.SelectFrom(tablename, weapon.Name);
            }

            weapon.Magic.Bonus            = Convert.ToInt32(bonus);
            weapon.Magic.SpecialAbilities = specialAbilitiesGenerator.GenerateFor(weapon.ItemType, weapon.Attributes, power, weapon.Magic.Bonus, specialAbilitiesCount);

            if (weapon.Magic.SpecialAbilities.Any(a => a.Name == SpecialAbilityConstants.SpellStoring))
            {
                var shouldStoreSpell = booleanPercentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.SpellStoringContainsSpell);

                if (shouldStoreSpell)
                {
                    var spellType = spellGenerator.GenerateType();
                    var level     = spellGenerator.GenerateLevel(PowerConstants.Minor);
                    var spell     = spellGenerator.Generate(spellType, level);

                    weapon.Contents.Add(spell);
                }
            }

            if (weapon.Attributes.Contains(AttributeConstants.Thrown) && weapon.Attributes.Contains(AttributeConstants.Melee) == false)
            {
                weapon.Quantity = dice.Roll().d20().AsSum();
            }

            return(weapon);
        }
Exemplo n.º 25
0
        public bool IsAdvanced(string creature)
        {
            var advancements = typeAndAmountSelector.Select(TableNameConstants.TypeAndAmount.Advancements, creature);

            return(percentileSelector.SelectFrom(.9) && advancements.Any());
        }
Exemplo n.º 26
0
 public string GenerateType()
 {
     return(percentileSelector.SelectFrom(TableNameConstants.Percentiles.Set.SpellTypes));
 }