public void Resolve_EvilPumpkinHour_EvipPumpkinChanceIncleased() { // ARRANGE // Сейчас в коде генерация модификаторов строго завязана на этот символьныи иденфтикатор. const string testPropSchemeSid = "evil-pumpkin"; // Максимальный пик дропа должен быть 2 ноября любого года. 2019 выбран произвольно. var evilHourDate = new DateTime(2019, 11, 2); const int PUMPKIN_WEIGHT = 1; const int PUMPKIN_WEIGHT_BONUS = 5; const int EXPECTED_WEIGHT = PUMPKIN_WEIGHT * PUMPKIN_WEIGHT_BONUS; var testPropScheme = new TestPropScheme { Sid = testPropSchemeSid, Equip = new TestPropEquipSubScheme() }; var randomSourceMock = new Mock <IDropResolverRandomSource>(); randomSourceMock.Setup(x => x.RollWeight(It.IsAny <int>())) .Returns(EXPECTED_WEIGHT); var randomSource = randomSourceMock.Object; var schemeServiceMock = new Mock <ISchemeService>(); schemeServiceMock.Setup(x => x.GetScheme <IPropScheme>(It.Is <string>(sid => sid == testPropSchemeSid))) .Returns(testPropScheme); var schemeService = schemeServiceMock.Object; var propFactoryMock = new Mock <IPropFactory>(); propFactoryMock.Setup(x => x.CreateEquipment(It.IsAny <IPropScheme>())) .Returns <IPropScheme>(scheme => new Equipment(scheme, null)); propFactoryMock.Setup(x => x.CreateResource(It.IsAny <IPropScheme>(), It.IsAny <int>())) .Returns <IPropScheme, int>((scheme, count) => new Resource(scheme, count)); var propFactory = propFactoryMock.Object; var userTimeProviderMock = new Mock <IUserTimeProvider>(); userTimeProviderMock.Setup(x => x.GetCurrentTime()).Returns(evilHourDate); var userTimeProvider = userTimeProviderMock.Object; var resolver = new DropResolver(randomSource, schemeService, propFactory, userTimeProvider); var testDropTableRecord = new TestDropTableRecordSubScheme { SchemeSid = testPropSchemeSid, Weight = 1 }; var testDropTable = new TestDropTableScheme(1, testDropTableRecord, TestDropTableRecordSubScheme.CreateEmpty(1)); // ACT var factProps = resolver.Resolve(new[] { testDropTable }); // ASSERT factProps[0].Scheme.Should().BeSameAs(testPropScheme); }
protected override void RollStartEquipment(IInventoryModule inventory, HumanPerson person) { var templates = GetPersonTemplateByFraction(person.Fraction, SchemeService); var rolledTemplate = Dice.RollFromList(templates); person.PersonEquipmentTemplate = rolledTemplate.Name; var headDropScheme = rolledTemplate.HeadEquipments; FillSlot(person, headDropScheme, HeadSlotIndex); var armorDropScheme = rolledTemplate.BodyEquipments; FillSlot(person, armorDropScheme, BodySlotIndex); var mainWeaponDropScheme = rolledTemplate.MainHandEquipments; FillSlot(person, mainWeaponDropScheme, MainHandSlotIndex); var offWeaponDropScheme = rolledTemplate.OffHandEquipments; FillSlot(person, offWeaponDropScheme, OffHandSlotIndex); var startPropDropScheme = rolledTemplate.InventoryProps; var startProps = DropResolver.Resolve(new[] { startPropDropScheme }); foreach (var prop in startProps) { AddPropToInventory(inventory, prop); } AddDefaultProps(inventory); }
protected override void RollStartEquipment(IInventoryModule inventory, HumanPerson person) { var headDropScheme = GetHeads(); FillSlot(person, headDropScheme, HeadSlotIndex); var armorDropScheme = GetArmors(); FillSlot(person, armorDropScheme, BodySlotIndex); var mainWeaponDropScheme = GetMainWeapons(); FillSlot(person, mainWeaponDropScheme, MainHandSlotIndex); var offWeaponDropScheme = GetOffWeapons(); FillSlot(person, offWeaponDropScheme, OffHandSlotIndex); var startPropDropScheme = GetStartProps(); var startProps = DropResolver.Resolve(new[] { startPropDropScheme }); foreach (var prop in startProps) { AddPropToInventory(inventory, prop); } AddDefaultProps(inventory); AddEquipment(inventory, "pick-axe"); AddEquipment(inventory, "shovel"); AddEquipment(inventory, "shotgun"); AddResource(inventory, "bullet-45", 100); }
public void GetPropsTest() { // ARRANGE const string testPropSchemeSid = "test-resource"; var testResourceScheme = new PropScheme { Sid = testPropSchemeSid }; var randomSourceMock = new Mock <IDropResolverRandomSource>(); randomSourceMock.Setup(x => x.RollWeight(It.IsAny <int>())) .Returns(1); randomSourceMock.Setup(x => x.RollResourceCount(It.IsAny <int>(), It.IsAny <int>())) .Returns(1); var randomSource = randomSourceMock.Object; var schemeServiceMock = new Mock <ISchemeService>(); schemeServiceMock.Setup(x => x.GetScheme <IPropScheme>(It.Is <string>(sid => sid == testPropSchemeSid))) .Returns(testResourceScheme); var schemeService = schemeServiceMock.Object; var propFactoryMock = new Mock <IPropFactory>(); propFactoryMock.Setup(x => x.CreateResource(It.IsAny <IPropScheme>(), It.IsAny <int>())) .Returns <IPropScheme, int>((scheme, count) => new Resource(scheme, count)); var propFactory = propFactoryMock.Object; var resolver = new DropResolver(randomSource, schemeService, propFactory); var testDropTableRecord = new TestDropTableRecordSubScheme { SchemeSid = testPropSchemeSid, Weight = 1, MinCount = 1, MaxCount = 1 }; var testDropTable = new TestDropTableScheme(1, testDropTableRecord); // ACT var factProps = resolver.Resolve(new[] { testDropTable }); // ASSERT factProps.Length.Should().Be(1); factProps[0].Scheme.Should().BeSameAs(testResourceScheme); ((Resource)factProps[0]).Count.Should().Be(1); }
protected void FillSlot(HumanPerson person, IDropTableScheme?dropScheme, int slotIndex) { if (dropScheme is null) { return; } // Генерируем предметы. // Выбираем предмет, как экипировку в слот. // Если он может быть экипирован, то устанавливаем в слот. // Остальные дропнутые предметы складываем просто в инвентарь. // Если текущий предмет невозможно экипировать, то его тоже помещаем в инвентарь. var inventory = person.GetModule <IInventoryModule>(); var dropedProps = DropResolver.Resolve(new[] { dropScheme }); var usedEquipment = dropedProps.OfType <Equipment>().FirstOrDefault(); if (usedEquipment != null) { var equipmentModule = person.GetModule <IEquipmentModule>(); var canBeEquiped = CanBeEquiped(equipmentModule, slotIndex, usedEquipment); if (canBeEquiped) { AddEquipment(equipmentModule, slotIndex, usedEquipment); var unusedMainWeaponDrops = dropedProps.Where(x => x != usedEquipment).ToArray(); foreach (var prop in unusedMainWeaponDrops) { AddPropToInventory(inventory, prop); } } else { foreach (var prop in dropedProps) { AddPropToInventory(inventory, prop); } } } else { foreach (var prop in dropedProps) { AddPropToInventory(inventory, prop); } } }
public void Resolve_ExtraDropInScheme_ReturnsExtraDrop() { // ARRANGE const string testPropSchemeSid = "test-prop"; const string testExtraSchemeSid = "test-extra"; var testPropScheme = new TestPropScheme { Sid = testPropSchemeSid, Equip = new TestPropEquipSubScheme() }; var testExtraScheme = new TestPropScheme { Sid = testExtraSchemeSid }; var randomSourceMock = new Mock <IDropResolverRandomSource>(); randomSourceMock.Setup(x => x.RollWeight(It.IsAny <int>())) .Returns(1); randomSourceMock.Setup(x => x.RollResourceCount(It.IsAny <int>(), It.IsAny <int>())) .Returns(1); var randomSource = randomSourceMock.Object; var schemeServiceMock = new Mock <ISchemeService>(); schemeServiceMock.Setup(x => x.GetScheme <IPropScheme>(It.Is <string>(sid => sid == testPropSchemeSid))) .Returns(testPropScheme); schemeServiceMock.Setup(x => x.GetScheme <IPropScheme>(It.Is <string>(sid => sid == testExtraSchemeSid))) .Returns(testExtraScheme); var schemeService = schemeServiceMock.Object; var propFactoryMock = new Mock <IPropFactory>(); propFactoryMock.Setup(x => x.CreateEquipment(It.IsAny <IPropScheme>())) .Returns <IPropScheme>(scheme => new Equipment(scheme, null)); propFactoryMock.Setup(x => x.CreateResource(It.IsAny <IPropScheme>(), It.IsAny <int>())) .Returns <IPropScheme, int>((scheme, count) => new Resource(scheme, count)); var propFactory = propFactoryMock.Object; var resolver = new DropResolver(randomSource, schemeService, propFactory, CreateEmptyUserTimeProvider()); var testDropTableRecord = new TestDropTableRecordSubScheme { SchemeSid = testPropSchemeSid, Weight = 1, Extra = new IDropTableScheme[] { new TestDropTableScheme(1, new TestDropTableRecordSubScheme { SchemeSid = testExtraSchemeSid, Weight = 1, MinCount = 1, MaxCount = 1 }) } }; var testDropTable = new TestDropTableScheme(1, testDropTableRecord); // ACT var factProps = resolver.Resolve(new[] { testDropTable }); // ASSERT factProps.Length.Should().Be(2); factProps[0].Scheme.Should().BeSameAs(testPropScheme); factProps[1].Scheme.Should().BeSameAs(testExtraScheme); ((Resource)factProps[1]).Count.Should().Be(1); }