Exemplo n.º 1
0
        public void TestPlacingBombCommand()
        {
            var map     = new GameMap(2, 1, 0);
            var player1 = new PlayerEntity();

            player1.BombBag = 1;

            var block = map.GetBlockAtLocation(1, 1);

            block.SetEntity(player1);

            var transaction = new CommandTransaction(new DummyLogger());
            var command     = new PlaceBombCommand();

            command.PerformCommand(map, player1, transaction);
            transaction.ValidateCommands(map);
            transaction.ProcessCommands(map);

            transaction = new CommandTransaction(new DummyLogger());
            command     = new PlaceBombCommand();
            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(map, player1, transaction),
                                                    "Cannot place bomb in same location twice");

            var moveCommand = new MovementCommand(MovementCommand.Direction.Right);

            moveCommand.PerformCommand(map, player1, transaction);
            transaction.ValidateCommands(map);
            transaction.ProcessCommands(map);

            transaction = new CommandTransaction(new DummyLogger());
            command     = new PlaceBombCommand();
            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(map, player1, transaction),
                                                    "Player cannot place more bombs than is in the bomb bag");
        }
        public void PerformCommand(GameMap gameMap, PlayerEntity player, CommandTransaction commandTransaction)
        {
            if (gameMap.GetPlayerBombCount(player) == 0)
            {
                throw new InvalidCommandException("Player has not bombs to trigger");
            }

            var bombs = gameMap.GetPlayerBombs(player);

            if (bombs.Any(x => x.IsExploding))
            {
                throw new InvalidCommandException("There is already a bomb currently exlpoding, cannot trigger another one");
            }

            var bomb = bombs.OrderBy(x => x.BombTimer).FirstOrDefault();

            if (bomb != null)
            {
                bomb.BombTimer = 1;
            }
            else
            {
                throw new InvalidCommandException("There are no eligible bombs to trigger");
            }
        }
Exemplo n.º 3
0
        public void TestTransaction()
        {
            var vertices = PEMockFactory.CreateVertices(new V2(0, 0), new V2(1, 0), new V2(0, 1), new V2(1, 1)).ToArray();

            var transaction = new CommandTransaction(new[]
            {
                new CommandApplyVertexEdit(vertices, Matrix.Translation(1, 0, 0)),
                new CommandApplyVertexEdit(vertices, Matrix.Translation(0, 1, 0)),
                new CommandApplyVertexEdit(vertices, Matrix.Translation(1, 1, 0))
            });

            transaction.Do();
            Assert.AreEqual(2, vertices[0].UV.X);
            Assert.AreEqual(2, vertices[0].UV.Y);
            Assert.AreEqual(3, vertices[1].UV.X);
            Assert.AreEqual(2, vertices[1].UV.Y);
            Assert.AreEqual(2, vertices[2].UV.X);
            Assert.AreEqual(3, vertices[2].UV.Y);
            Assert.AreEqual(3, vertices[3].UV.X);
            Assert.AreEqual(3, vertices[3].UV.Y);

            transaction.Undo();
            Assert.AreEqual(0, vertices[0].UV.X);
            Assert.AreEqual(0, vertices[0].UV.Y);
            Assert.AreEqual(1, vertices[1].UV.X);
            Assert.AreEqual(0, vertices[1].UV.Y);
            Assert.AreEqual(0, vertices[2].UV.X);
            Assert.AreEqual(1, vertices[2].UV.Y);
            Assert.AreEqual(1, vertices[3].UV.X);
            Assert.AreEqual(1, vertices[3].UV.Y);
        }
Exemplo n.º 4
0
 public HttpResponseMessage Post([FromBody] CommandTransaction commandTransaction)
 {
     commandTransaction.ReceivedId  = IdGenerator.GetId();
     commandTransaction.JsonContent = this.Request.Content.ReadAsStringAsync().Result.ToFormattedJson();
     DispatcherHelper.DispatchAction(() =>
                                     AppMessenger.Messenger.NotifyColleagues("AddCommandTransaction", commandTransaction));
     return(new HttpResponseMessage(HttpStatusCode.Created));
 }
Exemplo n.º 5
0
        public void TransactionDisposed(CommandTransaction item)
        {
            var transaction = GetTransaction(item);

            if (transaction != null)
            {
                transaction.DisposedAt = item.AtDateTime;
            }
        }
Exemplo n.º 6
0
        public void TransactionRolledBack(CommandTransaction item)
        {
            var transaction = GetTransaction(item);

            if (transaction != null)
            {
                transaction.RolledBackAt = item.AtDateTime;
            }
        }
Exemplo n.º 7
0
        public void TransactionBegan(CommandTransaction item)
        {
            if (item.ApplicationIdentity.Equals(GuiModelData.SelectedApplicationIdentity) &&
                !GuiModelData.RelatedTransactions.Contains(item))
            {
                GuiModelData.RelatedTransactions.Add(item);
            }

            PluginContext.NotifyPluginsHost(NotificationType.Update, 1);
            UpdateAppIdentityNotificationsCount(item);
        }
Exemplo n.º 8
0
        public void UpdateNewConnectionsTransactionIds(CommandTransaction item)
        {
            var lastNewConnection = PluginContext.ProfilerData.Connections
                                    .LastOrDefault(
                x =>
                x.ConnectionId == item.ConnectionId &&
                x.ApplicationIdentity.Equals(item.ApplicationIdentity) &&
                x.TransactionId == null);

            if (lastNewConnection != null)
            {
                lastNewConnection.TransactionId = item.TransactionId;
            }
        }
Exemplo n.º 9
0
        public void TestPlayerMovementCommand()
        {
            var gameMap     = GameMapTest.GenerateTestMap();
            var player      = gameMap.RegisteredPlayerEntities.First();
            var transaction = new CommandTransaction(new DummyLogger());

            var playerLocation = player.Location;

            var block = gameMap.GetBlockAtLocation(player.Location.X, player.Location.Y);

            block.PlantBomb(2);

            var command = new MovementCommand(MovementCommand.Direction.Up);

            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(gameMap, player, transaction),
                                                    "Player should not be able to occupy the space of another entity");
            command = new MovementCommand(MovementCommand.Direction.Left);
            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(gameMap, player, transaction),
                                                    "Player should not be able to occupy the space of another entity");

            command = new MovementCommand(MovementCommand.Direction.Right);
            command.PerformCommand(gameMap, player, transaction);

            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(gameMap, player, transaction),
                                                    "Player can only performa one command per transaction");

            transaction.ValidateCommands(gameMap);
            transaction.ProcessCommands(gameMap);

            Assert.AreEqual(playerLocation.Y, player.Location.Y, "Player moved in the wrong direction");
            Assert.AreEqual(playerLocation.X + 1, player.Location.X, "Player moved in the wrond direction");

            command = new MovementCommand(MovementCommand.Direction.Left);
            Assert.Throws <InvalidCommandException>(() => command.PerformCommand(gameMap, player, transaction),
                                                    "Player should not be able to occupy the space if a bomb is in the location");


            gameMap     = GameMapTest.GenerateTestMap();
            player      = gameMap.RegisteredPlayerEntities.First();
            transaction = new CommandTransaction(new DummyLogger());

            transaction = new CommandTransaction(new DummyLogger());
            command     = new MovementCommand(MovementCommand.Direction.Down);
            command.PerformCommand(gameMap, player, transaction);
            transaction.ValidateCommands(gameMap);
            transaction.ProcessCommands(gameMap);
            Assert.AreEqual(playerLocation.Y + 1, player.Location.Y, "Player moved in the wrong direction");
            Assert.AreEqual(playerLocation.X, player.Location.X, "Player moved in the wrond direction");
        }
Exemplo n.º 10
0
        public void PerformCommand(GameMap gameMap, PlayerEntity player, CommandTransaction commandTransaction)
        {
            if (player.BombBag - gameMap.GetPlayerBombCount(player) == 0)
            {
                throw new InvalidCommandException(String.Format("Already placed all the bombs for player {0}", player));
            }

            var playerBlock = gameMap.GetBlockAtLocation(player.Location.X, player.Location.Y);

            if (playerBlock.Bomb != null)
            {
                throw new InvalidCommandException(String.Format("There is already a bomb placed here {0}", playerBlock.Location));
            }

            var bombTimer = Math.Min(9, (player.BombBag * _timerMultiplier)) + 1;

            playerBlock.PlantBomb(bombTimer);
        }
Exemplo n.º 11
0
        public void TransactionBegan(DbConnection connection, DbConnectionContext context)
        {
            var commandTransaction = new CommandTransaction
            {
                IsAsync         = context.IsAsync,
                TransactionType = CommandTransactionType.Began,
                IsCanceled      = context.IsCanceled,
                Exception       = context.Exception != null ? context.Exception.Message : "",
                StackTrace      = new CallingMethod {
                    AssembliesToExclude = AssembliesToExclude
                }.GetCallingMethodInfo()
            };

            setBaseInfo(context, commandTransaction);

            commandTransaction.TransactionId  = context.TransactionId;
            commandTransaction.IsolationLevel = context.IsolationLevel;

            _baseInfoQueue.Enqueue(commandTransaction);
        }
Exemplo n.º 12
0
        public void LogTransaction(DbTransaction transaction,
                                   DbTransactionContext interceptionTransactionContext,
                                   CommandTransactionType type)
        {
            var commandTransaction = new CommandTransaction
            {
                IsAsync         = interceptionTransactionContext.IsAsync,
                TransactionType = type,
                IsCanceled      = interceptionTransactionContext.IsCanceled,
                Exception       = interceptionTransactionContext.Exception != null ? interceptionTransactionContext.Exception.Message : "",
                StackTrace      = new CallingMethod {
                    AssembliesToExclude = AssembliesToExclude
                }.GetCallingMethodInfo()
            };

            setBaseInfo(interceptionTransactionContext, commandTransaction);
            commandTransaction.TransactionId = UniqueIdExtensions <DbTransaction> .GetUniqueId(transaction).ToInt();

            _baseInfoQueue.Enqueue(commandTransaction);
        }
Exemplo n.º 13
0
        public void PerformCommand(GameMap gameMap, PlayerEntity player, CommandTransaction commandTransaction)
        {
            if (gameMap.GetPlayerBombCount(player) == 0)
            {
                throw new InvalidCommandException("Player has no bombs to trigger");
            }

            var bombs = gameMap.GetPlayerBombs(player);

            var bomb = bombs.Where(x => !x.IsExploding && x.BombTimer >= 1).OrderBy(x => x.BombTimer).FirstOrDefault();

            if (bomb != null)
            {
                bomb.BombTimer = 1;
            }
            else
            {
                throw new InvalidCommandException("There are no eligible bombs to trigger");
            }
        }
        /// <summary>
        /// Process the player commands.  Player commands are processed in a commands transaction,
        /// the transaction is verified, removing invalid commands, and then the commands are persisted onto the game map
        /// </summary>
        protected void ProcessPlayerCommands()
        {
            _logger.LogDebug("Processing Player Commands");
            var hadCommands = _commandsToProcess.Any();

            var transaction = new CommandTransaction(_logger);

            foreach (var command in _commandsToProcess)
            {
                if (command.Key.PlayerEntity.Killed || _entitiesToDestroy.Contains(command.Key.PlayerEntity))
                {
                    _logger.LogInfo(String.Format("Player {0} has been killed, and the command {1} will be ignored", command.Key.PlayerEntity, command.Value));
                    continue;
                }

                try
                {
                    command.Value.PerformCommand(_gameMap, command.Key.PlayerEntity, transaction);
                }
                catch (InvalidCommandException ex)
                {
                    command.Key.PlayerCommandFailed(command.Value, ex.Message);
                    _logger.LogException(String.Format("Failed to process command {0} for player {1}", command.Value, command.Key.PlayerEntity), ex);
                }
            }
            transaction.ValidateCommands(_gameMap);
            transaction.ProcessCommands(_gameMap);

            _commandsToProcess.Clear();

            //Do another round of marking entities for destruction, just incase a player moved into a bomb blast
            if (hadCommands)
            {
                MarkEntitiesForDestruction();
            }
        }
Exemplo n.º 15
0
        public void TestPlayerCollidingMovementCommand()
        {
            var map = new GameMap(3, 1, 0);

            var player1 = new PlayerEntity();
            var player2 = new PlayerEntity();

            var block = map.GetBlockAtLocation(1, 1);

            block.SetEntity(player1);

            block = map.GetBlockAtLocation(3, 1);
            block.SetEntity(player2);

            var transaction = new CommandTransaction(new DummyLogger());

            new MovementCommand(MovementCommand.Direction.Right).PerformCommand(map, player1, transaction);
            new MovementCommand(MovementCommand.Direction.Left).PerformCommand(map, player2, transaction);

            transaction.ValidateCommands(map);
            transaction.ProcessCommands(map);

            Assert.AreNotEqual(player1.Location.X, player2.Location.X, "Only one of the players should have moved to the location");
        }
Exemplo n.º 16
0
 public void UpdateNumberOfTransactions(CommandTransaction item)
 {
     UpdateNumberOfTransactions(GetContext(item));
     UpdateNumberOfTransactions(GetStackTrace(item));
     UpdateNumberOfTransactions(GetTrafficUrl(item));
 }
Exemplo n.º 17
0
 public void PerformCommand(GameMap gameMap, PlayerEntity player, CommandTransaction commandTransaction)
 {
 }