示例#1
0
        public void TransferProp_Equipment()
        {
            // ARRANGE

            var equipmentScheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme()
            };

            // Инвентарь
            var inventory = new InventoryModule();

            // контейнер
            var containerProps = new IProp[] {
                new Equipment(equipmentScheme, System.Array.Empty <ITacticalActScheme>())
            };

            var container = new FixedPropChest(containerProps);

            // трансферная машина
            var transferMachine = new PropTransferMachine(inventory, container.Content);

            // ACT
            var transferResource = containerProps.First();

            transferMachine.TransferProp(transferResource,
                                         PropTransferMachineStores.Container,
                                         PropTransferMachineStores.Inventory);

            // ASSERT
            transferMachine.Inventory.PropAdded[0].Should().BeOfType <Equipment>();
            transferMachine.Container.PropRemoved[0].Should().BeOfType <Equipment>();
        }
示例#2
0
        protected override void RegisterSpecificServices(IMap testMap, Mock <ISectorUiState> playerStateMock)
        {
            var propScheme = new TestPropScheme
            {
                Use = new TestPropUseSubScheme()
            };
            var usableResource = new Resource(propScheme, 1);

            var equipmentViewModelMock = new Mock <IPropItemViewModel>();

            equipmentViewModelMock.SetupGet(x => x.Prop).Returns(usableResource);
            var equipmentViewModel = equipmentViewModelMock.Object;

            var inventoryStateMock = new Mock <IInventoryState>();

            inventoryStateMock.SetupProperty(x => x.SelectedProp, equipmentViewModel);
            var inventoryState = inventoryStateMock.Object;

            Container.AddSingleton(factory => inventoryState);

            Container.AddSingleton <UseSelfCommand>();

            var actorManagerMock = new Mock <IActorManager>();

            actorManagerMock.SetupGet(x => x.Items).Returns(Array.Empty <IActor>());
            var actorManager = actorManagerMock.Object;

            Container.AddSingleton(actorManager);
        }
        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);
        }
示例#4
0
        private static ISchemeService CreateSchemeService()
        {
            var schemeServiceMock = new Mock <ISchemeService>();

            var propScheme = new TestPropScheme
            {
                Sid = "test-prop"
            };

            schemeServiceMock.Setup(x => x.GetScheme <IPropScheme>(It.IsAny <string>()))
            .Returns(propScheme);

            var trophyTableScheme = new TestDropTableScheme(0, new DropTableRecordSubScheme[0])
            {
                Sid = "default"
            };

            schemeServiceMock.Setup(x => x.GetScheme <IDropTableScheme>(It.IsAny <string>()))
            .Returns(trophyTableScheme);

            var monsterScheme = new TestMonsterScheme
            {
                PrimaryAct = new TestTacticalActStatsSubScheme()
            };

            schemeServiceMock.Setup(x => x.GetScheme <IMonsterScheme>(It.IsAny <string>()))
            .Returns(monsterScheme);

            var schemeService = schemeServiceMock.Object;

            return(schemeService);
        }
示例#5
0
        public void TransferProp_Equipment_StoreEventsRaised()
        {
            // ARRANGE

            var equipmentScheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme()
            };

            // Инвентарь
            var inventory = new InventoryModule();

            // контейнер
            var containerProps = new IProp[] {
                new Equipment(equipmentScheme, System.Array.Empty <ITacticalActScheme>())
            };

            var container = new FixedPropChest(containerProps);

            // трансферная машина
            var transferMachine = new PropTransferMachine(inventory, container.Content);

            // ACT
            using var monitorInventory = transferMachine.Inventory.Monitor();
            using var monitorContainer = transferMachine.Container.Monitor();
            var transferResource = containerProps.First();

            transferMachine.TransferProp(transferResource,
                                         PropTransferMachineStores.Container,
                                         PropTransferMachineStores.Inventory);

            // ASSERT
            monitorInventory.Should().Raise(nameof(PropTransferStore.Added));
            monitorContainer.Should().Raise(nameof(PropTransferStore.Removed));
        }
示例#6
0
        public void TransferProp_Resources()
        {
            // ARRANGE

            var resourceScheme = new TestPropScheme();

            // Инвентарь
            var inventory = new InventoryModule();

            // контейнер
            var containerProps = new IProp[] {
                new Resource(resourceScheme, 1)
            };

            var container = new FixedPropChest(containerProps);

            // трансферная машина
            var transferMachine = new PropTransferMachine(inventory, container.Content);

            // ACT
            var transferResource = new Resource(resourceScheme, 1);

            transferMachine.TransferProp(transferResource,
                                         PropTransferMachineStores.Container,
                                         PropTransferMachineStores.Inventory);

            // ASSERT
            transferMachine.Inventory.PropAdded[0].Should().BeOfType <Resource>();
            var invResource = (Resource)transferMachine.Inventory.PropAdded[0];

            invResource.Count.Should().Be(1);
        }
        protected override void RegisterSpecificServices(IMap testMap, Mock <ISectorUiState> playerStateMock)
        {
            var propScheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Hand
                    }
                }
            };
            var equipment = new Equipment(propScheme, Array.Empty <TacticalActScheme>());

            var equipmentViewModelMock = new Mock <IPropItemViewModel>();

            equipmentViewModelMock.SetupGet(x => x.Prop).Returns(equipment);
            var equipmentViewModel = equipmentViewModelMock.Object;

            _inventoryStateMock = new Mock <IInventoryState>();
            _inventoryStateMock.SetupProperty(x => x.SelectedProp, equipmentViewModel);
            var inventoryState = _inventoryStateMock.Object;

            Container.AddSingleton(factory => inventoryState);
            Container.AddSingleton <EquipCommand>();
        }
示例#8
0
        public void TransferProp_ChangesResources_StoreEventsRaised()
        {
            // ARRANGE

            var resourceScheme = new TestPropScheme();

            // Инвентарь
            var inventory = new InventoryModule();

            inventory.Add(new Resource(resourceScheme, 1));

            // контейнер
            var containerProps = new IProp[] {
                new Resource(resourceScheme, 2)
            };

            var container = new FixedPropChest(containerProps);

            // трансферная машина
            var transferMachine = new PropTransferMachine(inventory, container.Content);

            // ACT
            using var monitorInventory = transferMachine.Inventory.Monitor();
            using var monitorContainer = transferMachine.Container.Monitor();
            var transferResource = new Resource(resourceScheme, 1);

            transferMachine.TransferProp(transferResource,
                                         PropTransferMachineStores.Container,
                                         PropTransferMachineStores.Inventory);

            // ASSERT
            monitorInventory.Should().Raise(nameof(PropTransferStore.Changed));
            monitorContainer.Should().Raise(nameof(PropTransferStore.Changed));
        }
        public void CanExecute_SelectConsumableResource_ReturnsFalse()
        {
            // ARRANGE
            var propScheme = new TestPropScheme
            {
                Use = new TestPropUseSubScheme
                {
                    Consumable  = true,
                    CommonRules = new[]
                    {
                        new ConsumeCommonRule(ConsumeCommonRuleType.Health, PersonRuleLevel.Lesser)
                    }
                }
            };
            var resource = new Resource(propScheme, 10);

            var equipmentViewModelMock = new Mock <IPropItemViewModel>();

            equipmentViewModelMock.SetupGet(x => x.Prop).Returns(resource);
            var equipmentViewModel = equipmentViewModelMock.Object;

            _inventoryStateMock.SetupGet(x => x.SelectedProp).Returns(equipmentViewModel);

            var command = ServiceProvider.GetRequiredService <EquipCommand>();

            command.SlotIndex = 0;

            // ACT
            var canExecute = command.CanExecute();

            // ASSERT
            canExecute.IsSuccess.Should().BeFalse();
        }
示例#10
0
        public void SetUp()
        {
            _equipmentScheme = new TestPropScheme
            {
                Sid  = "equipment",
                Name = new LocalizedStringSubScheme
                {
                    Ru = "Тестовая экипировка"
                },
                Equip = new TestPropEquipSubScheme()
            };

            _resourceScheme = new TestPropScheme
            {
                Sid  = "resource",
                Name = new LocalizedStringSubScheme
                {
                    Ru = "Тестовый ресурс"
                }
            };

            _conceptScheme = new TestPropScheme
            {
                Sid  = "concept",
                Name = new LocalizedStringSubScheme
                {
                    Ru = "Тестовый чертёж"
                }
            };
        }
示例#11
0
        public void SetEquipment_ChangeEquipment_EventRaised()
        {
            // ARRANGE
            var scheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[] {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var slotSchemes = new[] {
                new PersonSlotSubScheme {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var tacticalActScheme = new TestTacticalActScheme();

            var equipment = new Equipment(scheme, new[] { tacticalActScheme });

            const int changedSlot = 0;

            var carrier = new EquipmentModule(slotSchemes);

            // ACT
            using var monitor    = carrier.Monitor();
            carrier[changedSlot] = equipment;

            // ASSERT
            monitor.Should().Raise(nameof(carrier.EquipmentChanged));
        }
示例#12
0
        public void GivenВИнвентареУАктёраЕстьФейковыйПровиантFake_FoodНаХарактеристикуЭффективностью(string propSid,
                                                                                                      string provisionStat)
        {
            var actor = Context.GetActiveActor();

            ConsumeCommonRuleType consumeRuleType;
            var direction = PersonRuleDirection.Positive;

            switch (provisionStat)
            {
            case "сытость":
                consumeRuleType = ConsumeCommonRuleType.Satiety;
                break;

            case "вода":
                consumeRuleType = ConsumeCommonRuleType.Thirst;
                break;

            case "хп":
                consumeRuleType = ConsumeCommonRuleType.Health;
                break;

            case "-сытость":
                consumeRuleType = ConsumeCommonRuleType.Satiety;
                direction       = PersonRuleDirection.Negative;
                break;

            case "-вода":
                consumeRuleType = ConsumeCommonRuleType.Thirst;
                direction       = PersonRuleDirection.Negative;
                break;

            case "-хп":
                consumeRuleType = ConsumeCommonRuleType.Health;
                direction       = PersonRuleDirection.Negative;
                break;

            default:
                throw new NotSupportedException("Передан неподдерживаемый тип характеристики.");
            }

            var propScheme = new TestPropScheme
            {
                Sid = propSid,
                Use = new TestPropUseSubScheme
                {
                    Consumable  = true,
                    CommonRules = new[] {
                        new ConsumeCommonRule(consumeRuleType, PersonRuleLevel.Lesser, direction)
                    }
                }
            };

            Context.AddResourceToActor(propScheme, 1, actor);
        }
        public void SetEquipment_SetSingleEquipment_HasActs()
        {
            // ARRANGE
            var slotSchemes = new[] {
                new PersonSlotSubScheme {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var personScheme = new PersonScheme
            {
                Slots = slotSchemes
            };

            var defaultActScheme = new TestTacticalActScheme
            {
                Stats = new TestTacticalActStatsSubScheme()
            };

            var evolutionDataMock = new Mock <IEvolutionData>();
            var evolutionData     = evolutionDataMock.Object;

            var survivalRandomSourceMock = new Mock <ISurvivalRandomSource>();
            var survivalRandomSource     = survivalRandomSourceMock.Object;

            var person = new HumanPerson(personScheme, defaultActScheme, evolutionData, survivalRandomSource);

            var propScheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[] { EquipmentSlotTypes.Hand }
                }
            };

            var tacticalActScheme = new TestTacticalActScheme
            {
                Stats = new TestTacticalActStatsSubScheme()
            };

            var equipment = new Equipment(propScheme, new[] { tacticalActScheme });

            const int expectedSlotIndex = 0;



            // ACT

            person.EquipmentCarrier[expectedSlotIndex] = equipment;



            // ARRANGE
            person.TacticalActCarrier.Acts[0].Stats.Should().Be(tacticalActScheme.Stats);
        }
        public void SetEquipment_ChangePistolByOtherPistol_EquipmentChanged()
        {
            // ARRANGE
            var pistolScheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Ranged, PropTags.Equipment.Weapon },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var pistol2Scheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Ranged, PropTags.Equipment.Weapon },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var slotSchemes = new[]
            {
                new PersonSlotSubScheme
                {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var tacticalActScheme = new TestTacticalActScheme();

            var pistol1 = new Equipment(pistolScheme, new[] { tacticalActScheme });
            var pistol2 = new Equipment(pistol2Scheme, new[] { tacticalActScheme });

            const int changedSlot = 0;

            var carrier = new EquipmentModule(slotSchemes);

            // ACT
            carrier[changedSlot] = pistol1;
            Action act = () =>
            {
                carrier[changedSlot] = pistol2;
            };

            // ASSERT
            act.Should().NotThrow();
        }
        public void SetEquipment_DualShortSwords_NoException()
        {
            // ARRANGE
            var scheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Weapon },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var slotSchemes = new[]
            {
                new PersonSlotSubScheme
                {
                    Types = EquipmentSlotTypes.Hand
                },
                new PersonSlotSubScheme
                {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var tacticalActScheme = new TestTacticalActScheme
            {
                Stats = new TestTacticalActStatsSubScheme
                {
                    Range = new Range <int>(1, 1)
                }
            };

            var swordEquipment1 = new Equipment(scheme, new[] { tacticalActScheme });
            var swordEquipment2 = new Equipment(scheme, new[] { tacticalActScheme });

            const int swordSlot1 = 0;
            const int swordSlot2 = 1;

            var carrier = new EquipmentModule(slotSchemes);

            // ACT
            Action act = () =>
            {
                carrier[swordSlot1] = swordEquipment1;
                carrier[swordSlot2] = swordEquipment2;
            };

            // ASSERT
            act.Should().NotThrow <Exception>();
        }
        public void SetEquipment_DualPistols_ExceptionRaised()
        {
            // ARRANGE
            var scheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Ranged, PropTags.Equipment.Weapon },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var slotSchemes = new[]
            {
                new PersonSlotSubScheme
                {
                    Types = EquipmentSlotTypes.Hand
                },
                new PersonSlotSubScheme
                {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var tacticalActScheme = new TestTacticalActScheme
            {
                Stats = new TestTacticalActStatsSubScheme
                {
                    Range = new Range <int>(1, 6)
                }
            };

            var pistolEquipment1 = new Equipment(scheme, new[] { tacticalActScheme });
            var pistolEquipment2 = new Equipment(scheme, new[] { tacticalActScheme });

            const int pistolSlot1 = 0;
            const int pistolSlot2 = 1;

            var carrier = new EquipmentModule(slotSchemes);

            // ACT
            Action act = () =>
            {
                carrier[pistolSlot1] = pistolEquipment1;
                carrier[pistolSlot2] = pistolEquipment2;
            };

            // ASSERT
            act.Should().Throw <Exception>();
        }
        public void EquipTask_EquipedSlotAndFromSlot_PropEquipedInSlot()
        {
            // ARRANGE
            const int testedSlotIndex = 0;
            var       propScheme      = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme()
            };
            var testedEquipmentProp  = new Equipment(propScheme, new ITacticalActScheme[0], name: "tested");
            var equipedEquipmentProp = new Equipment(propScheme, new ITacticalActScheme[0], name: "equiped");

            var actorMock = new Mock <IActor>();
            var actor     = actorMock.Object;

            var personMock = new Mock <IPerson>();
            var person     = personMock.Object;

            actorMock.SetupGet(x => x.Person).Returns(person);

            var equipmentsInit       = new Equipment[] { equipedEquipmentProp, testedEquipmentProp };
            var equipmentCarrierMock = new Mock <EquipmentCarrierBase>(new object[] { equipmentsInit })
                                       .As <IEquipmentCarrier>();

            equipmentCarrierMock.CallBase = true;
            var equipmentCarrier = equipmentCarrierMock.Object;

            personMock.SetupGet(x => x.EquipmentCarrier).Returns(equipmentCarrier);

            var inventoryMock = new Mock <IPropStore>();
            var inventory     = inventoryMock.Object;

            personMock.SetupGet(x => x.Inventory).Returns(inventory);



            var task = new EquipTask(actor, testedEquipmentProp, testedSlotIndex);



            // ACT
            task.Execute();



            // ASSERT
            equipmentCarrier[0].Should().BeSameAs(testedEquipmentProp);
            equipmentCarrier[1].Should().BeSameAs(equipedEquipmentProp);
            inventoryMock.Verify(x => x.Add(It.IsAny <IProp>()), Times.Never);
            inventoryMock.Verify(x => x.Remove(It.IsAny <IProp>()), Times.Never);
        }
示例#18
0
        public void EquipTask_EquipedSlotAndFromInventory_PropEquipedInSlot()
        {
            // ARRANGE
            const int testedSlotIndex = 0;
            var       propScheme      = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme()
            };
            var testedEquipmentProp  = new Equipment(propScheme, System.Array.Empty <ITacticalActScheme>());
            var equipedEquipmentProp = new Equipment(propScheme, System.Array.Empty <ITacticalActScheme>());

            var actorMock = new Mock <IActor>();
            var actor     = actorMock.Object;

            var personMock = new Mock <IPerson>();
            var person     = personMock.Object;

            actorMock.SetupGet(x => x.Person).Returns(person);

            var initEquipments       = new Equipment[] { equipedEquipmentProp };
            var equipmentCarrierMock = new Mock <EquipmentModuleBase>(new object[] { initEquipments })
                                       .As <IEquipmentModule>();

            equipmentCarrierMock.CallBase = true;
            var equipmentModule = equipmentCarrierMock.Object;

            personMock.Setup(x => x.GetModule <IEquipmentModule>(It.IsAny <string>())).Returns(equipmentModule);

            var inventoryMock = new Mock <IInventoryModule>();
            var inventory     = inventoryMock.Object;

            personMock.Setup(x => x.GetModule <IInventoryModule>(It.IsAny <string>())).Returns(inventory);



            var task = new EquipTask(actor, testedEquipmentProp, testedSlotIndex);



            // ACT
            task.Execute();



            // ASSERT
            equipmentModule[0].Should().BeSameAs(testedEquipmentProp);
            inventoryMock.Verify(x => x.Remove(It.Is <IProp>(equipment => equipment == testedEquipmentProp)), Times.Once);
            inventoryMock.Verify(x => x.Add(It.Is <IProp>(equipment => equipment == equipedEquipmentProp)), Times.Once);
        }
示例#19
0
        public void EquipTask_EquipedSlotAndFromSlot_PropEquipedInSlot()
        {
            // ARRANGE
            const int testedSlotIndex = 0;
            var       propScheme      = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme()
            };
            var testedEquipmentProp  = new Equipment(propScheme, Array.Empty <ITacticalActScheme>(), name: "tested");
            var equipedEquipmentProp = new Equipment(propScheme, Array.Empty <ITacticalActScheme>(), name: "equiped");

            var actorMock = new Mock <IActor>();
            var actor     = actorMock.Object;

            var personMock = new Mock <IPerson>();
            var person     = personMock.Object;

            actorMock.SetupGet(x => x.Person).Returns(person);

            var equipmentsInit      = new[] { equipedEquipmentProp, testedEquipmentProp };
            var equipmentModuleMock = new Mock <EquipmentModuleBase>(new object[] { equipmentsInit })
                                      .As <IEquipmentModule>();

            equipmentModuleMock.CallBase = true;
            var equipmentModule = equipmentModuleMock.Object;

            personMock.Setup(x => x.GetModule <IEquipmentModule>(It.IsAny <string>())).Returns(equipmentModule);

            var inventoryMock = new Mock <IInventoryModule>();
            var inventory     = inventoryMock.Object;

            personMock.Setup(x => x.GetModule <IInventoryModule>(It.IsAny <string>())).Returns(inventory);

            var contextMock = new Mock <IActorTaskContext>();
            var context     = contextMock.Object;

            var task = new EquipTask(actor, context, testedEquipmentProp, testedSlotIndex);

            // ACT
            task.Execute();

            // ASSERT
            equipmentModule[0].Should().BeSameAs(testedEquipmentProp);
            equipmentModule[1].Should().BeSameAs(equipedEquipmentProp);
            inventoryMock.Verify(x => x.Add(It.IsAny <IProp>()), Times.Never);
            inventoryMock.Verify(x => x.Remove(It.IsAny <IProp>()), Times.Never);
        }
        public void TransferProp_InventoryHasEquipment_StoreEventsRaised()
        {
            // ARRANGE

            var equipmentScheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme()
            };

            // Инвентарь
            var inventory = new Inventory();

            inventory.Add(new Equipment(equipmentScheme, new ITacticalActScheme[0]));

            // контейнер
            var containerProps = new IProp[] {
                new Equipment(equipmentScheme, new ITacticalActScheme[0])
            };
            var nodeMock  = new Mock <IMapNode>();
            var node      = nodeMock.Object;
            var container = new FixedPropChest(node, containerProps);

            // трансферная машина
            var transferMachine = new PropTransferMachine(inventory, container.Content);



            // ACT
            using (var monitorInventory = transferMachine.Inventory.Monitor())
                using (var monitorContainer = transferMachine.Container.Monitor())
                {
                    var transferResource = containerProps.First();
                    transferMachine.TransferProp(transferResource,
                                                 PropTransferMachineStores.Container,
                                                 PropTransferMachineStores.Inventory);



                    // ASSERT
                    monitorInventory.Should().Raise(nameof(PropTransferStore.Added));
                    monitorContainer.Should().Raise(nameof(PropTransferStore.Removed));
                }
        }
示例#21
0
        public void UserProp_ComsumableWithDetoxication_ReduceIntoxication()
        {
            // ARRANGE
            var survivalModuleMock = new Mock <ISurvivalModule>();
            var survivalModule     = survivalModuleMock.Object;

            var personMock = new Mock <IPerson>();

            personMock.Setup(x => x.GetModule <ISurvivalModule>(It.IsAny <string>())).Returns(survivalModule);
            personMock.Setup(x => x.HasModule(It.IsAny <string>())).Returns(true);
            var person = personMock.Object;

            var node = new Mock <IGraphNode>().Object;

            var taskSourceMock = new Mock <IActorTaskSource <ISectorTaskSourceContext> >();
            var taskSource     = taskSourceMock.Object;

            var actor = new Actor(person, taskSource, node);

            var testPropScheme = new TestPropScheme
            {
                Use = new TestPropUseSubScheme
                {
                    CommonRules = new[]
                    {
                        new ConsumeCommonRule(
                            ConsumeCommonRuleType.Intoxication,
                            PersonRuleLevel.Lesser,
                            PersonRuleDirection.Negative)
                    }
                }
            };
            var testResource = new Resource(testPropScheme, 1);

            // ACT
            actor.UseProp(testResource);

            // ASSERT
            survivalModuleMock.Verify(x =>
                                      x.DecreaseStat(It.Is <SurvivalStatType>(v => v == SurvivalStatType.Intoxication),
                                                     It.IsAny <int>()));
        }
        public void TransferProp_Resources_StoreEventsRaised()
        {
            // ARRANGE

            var resourceScheme = new TestPropScheme();
            var resource       = new Resource(resourceScheme, 1);

            // Инвентарь
            var inventory = new Inventory();

            // контейнер
            var containerProps = new IProp[]
            {
                resource
            };
            var nodeMock  = new Mock <IMapNode>();
            var node      = nodeMock.Object;
            var container = new FixedPropChest(node, containerProps);

            // трансферная машина
            var transferMachine = new PropTransferMachine(inventory, container.Content);



            // ACT
            using (var monitorInventory = transferMachine.Inventory.Monitor())
                using (var monitorContainer = transferMachine.Container.Monitor())
                {
                    var transferResource = new Resource(resourceScheme, 1);
                    transferMachine.TransferProp(transferResource,
                                                 PropTransferMachineStores.Container,
                                                 PropTransferMachineStores.Inventory);



                    // ASSERT
                    monitorInventory.Should().Raise(nameof(PropTransferStore.Added))
                    .WithArgs <PropStoreEventArgs>(args => args.Props[0].Scheme == resource.Scheme);
                    monitorContainer.Should().Raise(nameof(PropTransferStore.Removed))
                    .WithArgs <PropStoreEventArgs>(args => args.Props[0].Scheme == resource.Scheme);
                }
        }
示例#23
0
        public void Equipment_SchemeWithOutEquipSubScheme_NoExceptions()
        {
            // ARRANGE
            var scheme = new TestPropScheme
            {
                Equip = null //Явно указываем, что предмет не является экипировкой.
            };

            var acts = new TacticalActScheme[0];

            // ACT
            Action act = () =>
            {
                // ReSharper disable once UnusedVariable
                var equipment = new Equipment(scheme, acts);
            };

            // ASSERT
            act.Should().Throw <ArgumentException>();
        }
        public void CheckPropAllowedByRestrictions_HasMaxSurivalHazardEffect_UsageIsNoAllowed(
            SurvivalStatType effectStatType, UsageRestrictionRule usageRule)
        {
            // ARRANGE

            var personMock = new Mock <IPerson>();

            var сonditionsModuleMock = new Mock <IConditionsModule>();
            var сonditions           = new[]
            {
                new SurvivalStatHazardCondition(effectStatType, SurvivalStatHazardLevel.Max,
                                                Mock.Of <ISurvivalRandomSource>())
            };

            сonditionsModuleMock.Setup(x => x.Items).Returns(сonditions);
            personMock.Setup(x => x.GetModule <IConditionsModule>(nameof(IConditionsModule)))
            .Returns(сonditionsModuleMock.Object);
            personMock.Setup(x => x.HasModule(nameof(IConditionsModule))).Returns(true);

            var actor = Mock.Of <IActor>(x => x.Person == personMock.Object);

            var propScheme = new TestPropScheme
            {
                Use = new TestPropUseSubScheme
                {
                    Restrictions = Mock.Of <IUsageRestrictions>(x =>
                                                                x.Items == new[] { Mock.Of <IUsageRestrictionItem>(item => item.Type == usageRule) })
                }
            };
            var prop = new Resource(propScheme, 1);

            var context = Mock.Of <IActorTaskContext>();

            // ACT

            var fact = UsePropHelper.CheckPropAllowedByRestrictions(prop, actor, context);

            // ASSERT
            fact.Should().BeFalse();
        }
示例#25
0
        protected override void RegisterSpecificServices(IMap testMap, Mock <ISectorUiState> playerStateMock)
        {
            var propScheme = new TestPropScheme
            {
                Use = new TestPropUseSubScheme()
            };
            var usableResource = new Resource(propScheme, 1);

            var equipmentViewModelMock = new Mock <IPropItemViewModel>();

            equipmentViewModelMock.SetupGet(x => x.Prop).Returns(usableResource);
            var equipmentViewModel = equipmentViewModelMock.Object;

            var inventoryStateMock = new Mock <IInventoryState>();

            inventoryStateMock.SetupProperty(x => x.SelectedProp, equipmentViewModel);
            var inventoryState = inventoryStateMock.Object;

            Container.Register(factory => inventoryState, new PerContainerLifetime());

            Container.Register <UseSelfCommand>(new PerContainerLifetime());
        }
        public void SetEquipment_Armor_NoException()
        {
            // ARRANGE
            var armorScheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Armor },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Body
                    }
                }
            };

            var slotSchemes = new[]
            {
                new PersonSlotSubScheme
                {
                    Types = EquipmentSlotTypes.Body
                }
            };

            var armorEquipment = new Equipment(armorScheme, Array.Empty <ITacticalActScheme>());

            const int ARMOR_SLOT = 0;

            var carrier = new EquipmentModule(slotSchemes);

            // ACT
            Action act = () =>
            {
                carrier[ARMOR_SLOT] = armorEquipment;
            };

            // ASSERT
            act.Should().NotThrow <Exception>();
        }
        public void CanExecute_SelectTwoHandedAndMainHandSlot_ReturnsTrue()
        {
            // ARRANGE
            var propScheme = new TestPropScheme
            {
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[]
                    {
                        EquipmentSlotTypes.Hand
                    },
                    EquipRestrictions = new TestPropEquipRestrictions
                    {
                        PropHandUsage = PropHandUsage.TwoHanded
                    }
                }
            };
            var resource = new Equipment(propScheme);

            var equipmentViewModelMock = new Mock <IPropItemViewModel>();

            equipmentViewModelMock.SetupGet(x => x.Prop).Returns(resource);
            var equipmentViewModel = equipmentViewModelMock.Object;

            _inventoryStateMock.SetupGet(x => x.SelectedProp).Returns(equipmentViewModel);

            var command = ServiceProvider.GetRequiredService <EquipCommand>();

            command.SlotIndex = 0;

            // ACT
            var canExecute = command.CanExecute();

            // ASSERT
            canExecute.IsSuccess.Should().BeTrue();
        }
示例#28
0
        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);
        }
示例#29
0
        public void UseOn_DecreaseBullets_BulletRemovedFromInventory()
        {
            // ARRANGE

            var handlerSelector = CreateEmptyHandlerSelector();

            var actUsageService = new TacticalActUsageService(
                _actUsageRandomSource,
                handlerSelector);

            var personMock = new Mock <IPerson>();
            var person     = personMock.Object;

            var actorMock = new Mock <IActor>();

            actorMock.SetupGet(x => x.Node).Returns(new HexNode(0, 0));
            actorMock.SetupGet(x => x.Person).Returns(person);
            var actor = actorMock.Object;

            var monsterMock = CreateOnHitMonsterMock();
            var monster     = monsterMock.Object;

            var actStatsSubScheme = new TestTacticalActStatsSubScheme
            {
                Offence = new TestTacticalActOffenceSubScheme
                {
                    Type   = OffenseType.Tactical,
                    Impact = ImpactType.Kinetic,
                    ApRank = 10
                }
            };

            var actConstrainsSubScheme = new TestTacticalActConstrainsSubScheme
            {
                PropResourceType  = "7-62",
                PropResourceCount = 1
            };

            var inventory    = new InventoryModule();
            var bulletScheme = new TestPropScheme
            {
                Sid    = "bullet-7-62",
                Bullet = new TestPropBulletSubScheme
                {
                    Caliber = "7-62"
                }
            };

            inventory.Add(new Resource(bulletScheme, 10));
            personMock.Setup(x => x.GetModule <IInventoryModule>(It.IsAny <string>())).Returns(inventory);

            var actMock = new Mock <ITacticalAct>();

            actMock.SetupGet(x => x.Stats).Returns(actStatsSubScheme);
            actMock.SetupGet(x => x.Constrains).Returns(actConstrainsSubScheme);
            var shootAct = actMock.Object;

            var actTargetInfo = new ActTargetInfo(monster, monster.Node);

            var usedActs = new UsedTacticalActs(new[] { shootAct });

            // ACT

            actUsageService.UseOn(actor, actTargetInfo, usedActs, _sector);

            // ASSERT

            var bullets = inventory.CalcActualItems().Single(x => x.Scheme.Sid == "bullet-7-62") as Resource;

            bullets.Count.Should().Be(9);
        }
        public void SetEquipment_PistolAndShield2_NoException()
        {
            // ARRANGE
            var pistolScheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Weapon, PropTags.Equipment.Ranged },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[] {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var shieldScheme = new TestPropScheme
            {
                Tags  = new[] { PropTags.Equipment.Shield },
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[] {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

            var slotSchemes = new[] {
                new PersonSlotSubScheme {
                    Types = EquipmentSlotTypes.Hand
                },
                new PersonSlotSubScheme {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var tacticalActScheme = new TestTacticalActScheme
            {
                Stats = new TestTacticalActStatsSubScheme
                {
                    Range = new Range <int>(1, 1)
                }
            };

            var pistolEquipment1 = new Equipment(pistolScheme, new[] { tacticalActScheme });
            var sheildEquipment2 = new Equipment(shieldScheme, new[] { tacticalActScheme });

            // Смена слотов относительно предыдузего теста
            const int swordSlot1 = 1;
            const int swordSlot2 = 0;

            var carrier = new EquipmentCarrier(slotSchemes);


            // ACT
            Action act = () =>
            {
                carrier[swordSlot1] = pistolEquipment1;
                carrier[swordSlot2] = sheildEquipment2;
            };


            // ASSERT
            act.Should().NotThrow <Exception>();
        }