public void TransferProp_Resources_StoreEventsRaised() { // ARRANGE var resourceScheme = new TestPropScheme(); var resource = new Resource(resourceScheme, 1); // Инвентарь var inventory = new InventoryModule(); // контейнер var containerProps = new IProp[] { resource }; 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.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); }
public void TransferProp_InventoryHasEquipment_StoreEventsRaised() { // ARRANGE var equipmentScheme = new TestPropScheme { Equip = new TestPropEquipSubScheme() }; // Инвентарь var inventory = new InventoryModule(); inventory.Add(new Equipment(equipmentScheme, Array.Empty <ITacticalActScheme>())); // контейнер var containerProps = new IProp[] { new Equipment(equipmentScheme, 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, PropTransferMachineStore.Container, PropTransferMachineStore.Inventory); // ASSERT monitorInventory.Should().Raise(nameof(PropTransferStore.Added)); monitorContainer.Should().Raise(nameof(PropTransferStore.Removed)); }
public UseItemCommandHandler(InventoryModule module) { this.module = module; }
public ShowInventoryCommandHandler(InventoryModule module) { this.module = module; }
public IPerson Create(string personSchemeSid, IFraction fraction) { var personScheme = SchemeService.GetScheme <IPersonScheme>(personSchemeSid); var person = new HumanPerson(personScheme, fraction); var attributeModule = RollAndAddPersonAttributesToPerson(person); var movingModule = new MovingModule(attributeModule); person.AddModule(movingModule); var inventoryModule = new InventoryModule(); person.AddModule(inventoryModule); var equipmentModule = new EquipmentModule(personScheme.Slots); person.AddModule(equipmentModule); var effectsModule = new EffectsModule(); person.AddModule(effectsModule); var evolutionModule = new EvolutionModule(SchemeService); person.AddModule(evolutionModule); RollTraitPerks(evolutionModule); var survivalModule = new HumanSurvivalModule(personScheme, _survivalRandomSource, attributeModule, effectsModule, evolutionModule, equipmentModule) { PlayerEventLogService = PlayerEventLogService }; person.AddModule(survivalModule); RollStartEquipment(inventoryModule, person); var defaultActScheme = SchemeService.GetScheme <ITacticalActScheme>(person.Scheme.DefaultAct); var combatActModule = new CombatActModule( defaultActScheme, equipmentModule, effectsModule, evolutionModule); person.AddModule(combatActModule); var combatStatsModule = new CombatStatsModule(evolutionModule, equipmentModule); person.AddModule(combatStatsModule); var diseaseModule = new DiseaseModule(effectsModule); person.AddModule(diseaseModule); var fowModule = new FowData(); person.AddModule(fowModule); person.PlayerEventLogService = PlayerEventLogService; return(person); }
public HumanPerson Restore(ISchemeService schemeService, ISurvivalRandomSource survivalRandomSource, IPropFactory propFactory) { if (schemeService is null) { throw new ArgumentNullException(nameof(schemeService)); } if (survivalRandomSource is null) { throw new ArgumentNullException(nameof(survivalRandomSource)); } if (propFactory is null) { throw new ArgumentNullException(nameof(propFactory)); } var storedPerson = this; var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var inventory = new InventoryModule(); var evolutionData = new EvolutionModule(schemeService); RestoreEvolutionData(schemeService, storedPerson, evolutionData); var person = new HumanPerson(personScheme); //TODO Создать необходимые модули и заполнить их. foreach (var survivalStoredItem in storedPerson.Survival) { var normalizedValueShare = RangeHelper.NormalizeShare(survivalStoredItem.Value); var stat = person.GetModule <ISurvivalModule>().Stats.Single(x => x.Type == survivalStoredItem.Type); stat.SetShare(normalizedValueShare); } foreach (var storedProp in storedPerson.Inventory) { var propScheme = schemeService.GetScheme <IPropScheme>(storedProp.Sid); IProp prop; switch (storedProp.Type) { case PropType.Resource: prop = propFactory.CreateResource(propScheme, storedProp.Count); break; case PropType.Equipment: var equipment = propFactory.CreateEquipment(propScheme); equipment.Durable.Value = storedProp.Durable; prop = equipment; break; default: throw new Exception(); } inventory.Add(prop); } for (var i = 0; i < storedPerson.Equipments.Length; i++) { var storedEquipment = storedPerson.Equipments[i]; if (storedEquipment == null) { continue; } var equipmentScheme = schemeService.GetScheme <IPropScheme>(storedEquipment.Sid); var equipment = propFactory.CreateEquipment(equipmentScheme); equipment.Durable.Value = storedEquipment.Durable; person.GetModule <IEquipmentModule>()[i] = equipment; //TODO Уменьшать прочность согласно сохранённым данным } return(person); }
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 GiveCommandHandler(InventoryModule module) { this.module = module; }