/// <summary> /// Executes behavior with given context /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override BehaviorReturnCode Behave(IBehaviorContext context) { UnitBehaviorContext unitContext = context as UnitBehaviorContext; if (unitContext == null) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } StaticUnit unit = unitContext.Unit as StaticUnit; if (unit == null || unit.Environment is Galaxy || unit.Target == null || unit.Environment != unit.Target.Environment || !unit.CanAttack || unit.Owner == unit.Target.Owner) { returnCode = BehaviorReturnCode.Failure; return(returnCode); } context.AddLogMessage("Attacking Target - " + unit.Target.Name); AttackTask task = new AttackTask(unit); while (!task.IsTaskFinished) { task.Execute(); } returnCode = BehaviorReturnCode.Success; return(returnCode); }
public async Task AttackTask_NoWall_NotThrowsInvalidOperationException() { // Подготовка. Два актёра через клетку. Радиус действия 1-2, достаёт. _testMap = await SquareMapFactory.CreateAsync(3).ConfigureAwait(false); var tacticalActMock = new Mock <ITacticalAct>(); tacticalActMock.SetupGet(x => x.Stats).Returns(new TestTacticalActStatsSubScheme { Range = new Range <int>(1, 2) }); var tacticalAct = tacticalActMock.Object; var combatActModuleMock = new Mock <ICombatActModule>(); combatActModuleMock.Setup(x => x.CalcCombatActs()) .Returns(new[] { tacticalAct }); var combatActModule = combatActModuleMock.Object; var personMock = new Mock <IPerson>(); personMock.Setup(x => x.GetModule <ICombatActModule>(It.IsAny <string>())).Returns(combatActModule); var person = personMock.Object; var actorMock = new Mock <IActor>(); var actorNode = _testMap.Nodes.SelectByHexCoords(0, 0); actorMock.SetupGet(x => x.Node).Returns(actorNode); actorMock.SetupGet(x => x.Person).Returns(person); actorMock.Setup(x => x.UseAct(It.IsAny <IGraphNode>(), It.IsAny <ITacticalAct>())) .Raises <IGraphNode, ITacticalAct>(x => x.UsedAct += null, (target1, act1) => new UsedActEventArgs(target1, act1)); _actor = actorMock.Object; var targetMock = new Mock <IActor>(); var targetNode = _testMap.Nodes.SelectByHexCoords(2, 0); targetMock.Setup(x => x.CanBeDamaged()).Returns(true); targetMock.SetupGet(x => x.Node).Returns(targetNode); var target = targetMock.Object; var actServiceMock = new Mock <ITacticalActUsageService>(); var actService = actServiceMock.Object; var taskContextMock = new Mock <IActorTaskContext>(); var taskContext = taskContextMock.Object; // Создаём саму команду _attackTask = new AttackTask(_actor, taskContext, target, tacticalAct, actService); Action act = () => { // ACT _attackTask.Execute(); }; // ASSERT act.Should().NotThrow <InvalidOperationException>(); }
public void AttackTaskTest() { // ARRANGE // Подготовка. Два актёра через клетку. Радиус действия 1-2, достаёт. var testMap = new TestGridGenMap(3); var actMock = new Mock <ITacticalAct>(); actMock.SetupGet(x => x.Stats).Returns(new TacticalActStatsSubScheme { Range = new Range <int>(1, 2) }); var act = actMock.Object; var actCarrierMock = new Mock <ITacticalActCarrier>(); actCarrierMock.SetupGet(x => x.Acts) .Returns(new ITacticalAct[] { act }); var actCarrier = actCarrierMock.Object; var personMock = new Mock <IPerson>(); personMock.SetupGet(x => x.TacticalActCarrier).Returns(actCarrier); var person = personMock.Object; var actorMock = new Mock <IActor>(); var actorNode = testMap.Nodes.OfType <HexNode>().SelectBy(0, 0); actorMock.SetupGet(x => x.Node).Returns(actorNode); actorMock.SetupGet(x => x.Person).Returns(person); actorMock.Setup(x => x.UseAct(It.IsAny <IAttackTarget>(), It.IsAny <ITacticalAct>())) .Raises <IAttackTarget, ITacticalAct>(x => x.UsedAct += null, (target1, act1) => new UsedActEventArgs(target1, act1)); var actor = actorMock.Object; var targetMock = new Mock <IActor>(); var targetNode = testMap.Nodes.OfType <HexNode>().SelectBy(2, 0); targetMock.Setup(x => x.CanBeDamaged()).Returns(true); targetMock.SetupGet(x => x.Node).Returns(targetNode); var target = targetMock.Object; var actServiceMock = new Mock <ITacticalActUsageService>(); var actService = actServiceMock.Object; // Создаём саму команду var attackTask = new AttackTask(actor, target, actService); using (var monitor = actor.Monitor()) { // ACT attackTask.Execute(); // ASSERT monitor.Should().Raise(nameof(IActor.UsedAct)); } }