public Item Generate(Item template, bool allowRandomDecoration = false) { template.ItemType = ItemTypeConstants.Weapon; var weapon = template.Copy(); if (specificGearGenerator.TemplateIsSpecific(template)) { weapon = specificGearGenerator.GenerateFrom(template); } else if (ammunitionGenerator.TemplateIsAmmunition(template)) { weapon = ammunitionGenerator.GenerateFrom(template); } else { var tableName = string.Format(TableNameConstants.Collections.Formattable.ITEMTYPEAttributes, weapon.ItemType); weapon.Attributes = collectionsSelector.SelectFrom(tableName, weapon.Name); } var abilityNames = template.Magic.SpecialAbilities.Select(a => a.Name); weapon.Magic.SpecialAbilities = specialAbilitiesGenerator.GenerateFor(abilityNames); return(weapon); }
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 void GenerateCustomAmmunition() { var name = Guid.NewGuid().ToString(); var template = itemVerifier.CreateRandomTemplate(name); template.Magic.SpecialAbilities = Enumerable.Empty <SpecialAbility>(); var attributes = new[] { "type 1", "type 2", AttributeConstants.Ammunition }; mockAttributesSelector.Setup(p => p.SelectFrom(TableNameConstants.Collections.Set.AmmunitionAttributes, name)).Returns(attributes); var ammunition = ammunitionGenerator.GenerateFrom(template); itemVerifier.AssertMagicalItemFromTemplate(ammunition, template); Assert.That(ammunition.ItemType, Is.EqualTo(ItemTypeConstants.Weapon)); Assert.That(ammunition.Quantity, Is.EqualTo(template.Quantity)); Assert.That(ammunition.Attributes, Is.EqualTo(attributes)); }