public void CalcActualItems_GetContentItems_ResolveContentOnce()
        {
            // ARRANGE

            var scheme = new PropScheme();

            var dropResolverMock = new Mock <IDropResolver>();

            dropResolverMock.Setup(x => x.Resolve(It.IsAny <DropTableScheme[]>()))
            .Returns(new IProp[] { CreateFakeResource(scheme) });
            var dropResolver = dropResolverMock.Object;

            var store      = new DropTableChestStore(new DropTableScheme[0], dropResolver);
            var firstProps = store.CalcActualItems();



            // ACT
            var secondProps = store.CalcActualItems();



            // ASSERT
            dropResolverMock.Verify(x => x.Resolve(It.IsAny <DropTableScheme[]>()), Times.Once);
            secondProps.Length.Should().Be(firstProps.Length);
            secondProps[0].Should().BeSameAs(firstProps[0]);
        }
Ejemplo n.º 2
0
        protected override void RegisterSpecificServices(IMap testMap, Mock <IPlayerState> playerStateMock)
        {
            var propScheme = new PropScheme
            {
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[] {
                        EquipmentSlotTypes.Hand
                    }
                }
            };
            var equipment = new Equipment(propScheme, new TacticalActScheme[0]);

            var equipmentViewModelMock = new Mock <IPropItemViewModel>();

            equipmentViewModelMock.SetupGet(x => x.Prop).Returns(equipment);
            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 <EquipCommand>(new PerContainerLifetime());
        }
Ejemplo n.º 3
0
        private static ISchemeService CreateSchemeService()
        {
            var schemeServiceMock = new Mock <ISchemeService>();

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

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

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

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

            var monsterScheme = new MonsterScheme {
                PrimaryAct = new TacticalActStatsSubScheme {
                    Efficient = new Range <float>(10, 20)
                }
            };

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

            var schemeService = schemeServiceMock.Object;

            return(schemeService);
        }
Ejemplo n.º 4
0
        public void Add_AddResourceToEmptyInventory_PropContainsThisResource()
        {
            // ARRANGE
            const int expectedCount = 1;

            var props     = new IProp[0];
            var realStore = CreateContainer(props);

            var testedScheme   = new PropScheme();
            var testedResource = new Resource(testedScheme, expectedCount);

            var propTransferStore = new PropTransferStore(realStore);



            // ACT
            propTransferStore.Add(testedResource);


            // ASSERT
            var factProps = propTransferStore.CalcActualItems();

            factProps[0].Should().BeOfType <Resource>();
            factProps[0].Scheme.Should().Be(testedScheme);
            ((Resource)factProps[0]).Count.Should().Be(expectedCount);
        }
Ejemplo n.º 5
0
        public void SetEquipment_SetSingleEquipment_HasActs()
        {
            // ARRANGE
            var slotSchemes = new[] {
                new PersonSlotSubScheme {
                    Types = EquipmentSlotTypes.Hand
                }
            };

            var personScheme = new PersonScheme
            {
                Slots = slotSchemes
            };

            var defaultActScheme = new TacticalActScheme {
                Stats = new TacticalActStatsSubScheme
                {
                    Efficient = new Range <float>(1, 1)
                },
                Dependency = new[] {
                    new TacticalActDependencySubScheme(CombatStatType.Melee, 1)
                }
            };

            var person = new HumanPerson(personScheme, defaultActScheme, null);

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

            var tacticalActScheme = new TacticalActScheme
            {
                Stats = new TacticalActStatsSubScheme
                {
                    Efficient = new Range <float>(1, 1),
                },
                Dependency = new[] {
                    new TacticalActDependencySubScheme(CombatStatType.Undefined, 1)
                }
            };

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

            const int expectedSlotIndex = 0;



            // ACT

            person.EquipmentCarrier.SetEquipment(equipment, expectedSlotIndex);



            // ARRANGE
            person.TacticalActCarrier.Acts[0].Stats.Should().Be(tacticalActScheme.Stats);
        }
Ejemplo n.º 6
0
        public void Remove_RemoveResourceFromInventoryWithThisResource_PropContains()
        {
            // ARRANGE
            const int inventoryCount = 1;
            const int expectedCount  = 1;

            var testedScheme = new PropScheme();

            var props = new IProp[] {
                new Resource(testedScheme, inventoryCount)
            };

            var realStore = CreateContainer(props);


            var testedResource = new Resource(testedScheme, expectedCount);

            var propTransferStore = new PropTransferStore(realStore);



            // ACT
            propTransferStore.Remove(testedResource);


            // ASSERT
            var factProps = propTransferStore.CalcActualItems();

            factProps.Should().BeEmpty();
        }
Ejemplo n.º 7
0
        public void Add_AddResourceToInventoryWithThisResource_PropContains2UnitsOfResource()
        {
            // ARRANGE
            const int inventoryCount = 1;
            const int testedCount    = 1;
            const int expectedCount  = inventoryCount + testedCount;

            var testedScheme = new PropScheme();

            var props = new IProp[] {
                new Resource(testedScheme, inventoryCount)
            };

            var realStore = CreateContainer(props);


            var testedResource = new Resource(testedScheme, testedCount);

            var propTransferStore = new PropTransferStore(realStore);



            // ACT
            propTransferStore.Add(testedResource);


            // ASSERT
            var factProps = propTransferStore.CalcActualItems();

            factProps.Length.Should().Be(1);  // В инвентаре только один стак ресурсов.
            factProps[0].Should().BeOfType <Resource>();
            factProps[0].Scheme.Should().Be(testedScheme);
            ((Resource)factProps[0]).Count.Should().Be(expectedCount);
        }
Ejemplo n.º 8
0
        public Equipment CreateEquipment(PropScheme scheme)
        {
            if (scheme.Equip == null)
            {
                throw new ArgumentException("Не корректная схема.", nameof(scheme));
            }


            var actSchemes    = new List <TacticalActScheme>();
            var actSchemeSids = scheme.Equip.ActSids;

            if (scheme.Equip.ActSids != null)
            {
                foreach (var actSchemeSid in actSchemeSids)
                {
                    var actScheme = _schemeService.GetScheme <TacticalActScheme>(actSchemeSid);

                    actSchemes.Add(actScheme);
                }


                var equipment = new Equipment(scheme, actSchemes);

                return(equipment);
            }
            else
            {
                return(new Equipment(scheme, null));
            }
        }
        public void CalcActualItems_DropSameResourceTwice_MergeSameResourcesToStack()
        {
            // ARRANGE

            var scheme = new PropScheme();

            var dropResolverMock = new Mock <IDropResolver>();

            dropResolverMock.Setup(x => x.Resolve(It.IsAny <DropTableScheme[]>()))
            .Returns(new IProp[] { CreateFakeResource(scheme), CreateFakeResource(scheme) });
            var dropResolver = dropResolverMock.Object;

            var store = new DropTableChestStore(new DropTableScheme[0], dropResolver);



            // ACT
            var props = store.CalcActualItems();



            // ASSERT
            props.Length.Should().Be(1);
            ((Resource)props[0]).Count.Should().Be(2);
        }
Ejemplo n.º 10
0
        public Resource(PropScheme scheme, int count) : base(scheme)
        {
            if (count <= 0)
            {
                throw new ArgumentException("Ресурсов не может быть 0 или меньше.", nameof(count));
            }

            Count = count;
        }
        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);
        }
Ejemplo n.º 12
0
        private static PropClass GetPropClass(PropScheme scheme)
        {
            if (scheme.Equip != null)
            {
                return(PropClass.Equipment);
            }

            if (scheme.Sid == "conceptual-scheme")
            {
                return(PropClass.Concept);
            }

            return(PropClass.Resource);
        }
Ejemplo n.º 13
0
        /// <inheritdoc />
        /// <summary>
        /// Конструктор.
        /// </summary>
        /// <param name="propScheme"> Схема экипировки. </param>
        /// <param name="acts"> Действия, которые может дать эта экипировка. </param>
        /// <exception cref="T:System.ArgumentException">
        /// Выбрасывает, если на вход подана схема,
        /// не содержащая характеристики экипировки <see cref="P:Zilon.Core.Schemes.PropScheme.Equip" />.
        /// </exception>
        public Equipment(PropScheme propScheme, IEnumerable <TacticalActScheme> acts) : base(propScheme)
        {
            if (propScheme.Equip == null)
            {
                throw new ArgumentException("Не корректная схема.", nameof(propScheme));
            }

            Power = 1;

            if (acts != null)
            {
                Acts = acts.ToArray();
            }
            else
            {
                Acts = new TacticalActScheme[0];
            }
        }
        public void DropTablePropContainerTest()
        {
            // ARRANGE
            var nodeMock = new Mock <IMapNode>();
            var node     = nodeMock.Object;

            var dropTableRecord = new TestDropTableRecordSubScheme
            {
                SchemeSid = "test-prop",
                Weight    = 1,
                MinCount  = 1,
                MaxCount  = 1
            };

            var dropTable = new TestDropTableScheme(1, dropTableRecord);

            var testPropScheme = new PropScheme
            {
                Sid = "test-prop"
            };

            var dropResolverMock = new Mock <IDropResolver>();

            dropResolverMock.Setup(x => x.Resolve(It.IsAny <IEnumerable <IDropTableScheme> >()))
            .Returns(new IProp[] { new Resource(testPropScheme, 1) });
            var dropResolver = dropResolverMock.Object;

            var container = new DropTablePropChest(node,
                                                   new IDropTableScheme[] { dropTable },
                                                   dropResolver);



            // ACT
            var factProps = container.Content.CalcActualItems();



            // ASSERT
            factProps.Length.Should().Be(1);
            factProps[0].Scheme.Should().BeSameAs(testPropScheme);
            ((Resource)factProps[0]).Count.Should().Be(1);
        }
Ejemplo n.º 15
0
        public void Equipment_SchemeWithOutEquipSubScheme_NoExceptions()
        {
            // ARRANGE
            var scheme = new PropScheme();

            var acts = new TacticalActScheme[0];


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



            // ASSERT
            act.Should().Throw <ArgumentException>();
        }
Ejemplo n.º 16
0
        public void SetEquipment_ChangeEquipment_EventRaised()
        {
            // ARRANGE
            var scheme = new PropScheme
            {
                Equip = new TestPropEquipSubScheme
                {
                    SlotTypes = new[] {
                        EquipmentSlotTypes.Hand
                    }
                }
            };

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

            var tacticalActScheme = new TacticalActScheme();

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

            const int changedSlot = 0;

            var carrier = new EquipmentCarrier(slotSchemes);


            // ACT
            using (var monitor = carrier.Monitor())
            {
                carrier.SetEquipment(equipment, changedSlot);



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

            ConsumeCommonRule consumeRule;

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

            case "вода":
                consumeRule = ConsumeCommonRule.Thrist;
                break;

            case "хп":
                consumeRule = ConsumeCommonRule.Health;
                break;

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

            var propScheme = new PropScheme {
                Sid = propSid,
                Use = new TestPropUseSubScheme
                {
                    Consumable  = true,
                    CommonRules = new[] { consumeRule },
                    Value       = provisitonEfficient
                }
            };

            _context.AddResourceToActor(propScheme, 1, actor);
        }
Ejemplo n.º 18
0
        protected override void RegisterSpecificServices(IMap testMap, Mock <IPlayerState> playerStateMock)
        {
            var propScheme = new PropScheme
            {
                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());
        }
Ejemplo n.º 19
0
        public void TransferPropTest()
        {
            // ARRANGE

            var resourceScheme = new PropScheme();

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

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

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



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

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


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

            invResource.Count.Should().Be(1);
        }
Ejemplo n.º 20
0
 public Concept(PropScheme scheme, PropScheme prop) : base(scheme)
 {
     Prop = prop;
 }
Ejemplo n.º 21
0
 /// <summary>
 /// Конструктор.
 /// </summary>
 /// <param name="scheme"> Схема предмета. </param>
 protected PropBase(PropScheme scheme)
 {
     Scheme = scheme;
 }
Ejemplo n.º 22
0
        public void AddResourceToActor(PropScheme resourceScheme, int count, IActor actor)
        {
            var resource = new Resource(resourceScheme, count);

            actor.Person.Inventory.Add(resource);
        }
        private Resource CreateFakeResource(PropScheme scheme)
        {
            var resource = new Resource(scheme, 1);

            return(resource);
        }
Ejemplo n.º 24
0
        public Resource CreateResource(PropScheme scheme, int count)
        {
            var resource = new Resource(scheme, count);

            return(resource);
        }