예제 #1
0
        private void UpdateGameState(Guid key)
        {
            GameplayCommunicationsStore client = ConnectedClients[key];

            Core.GameStateInformation.GameStateUpdate gameStateUpdate = new Core.GameStateInformation.GameStateUpdate();

            Character playerCharacter = _players.Where(i => i.Id == client.PlayerCharacterId).First();

            gameStateUpdate.ViewableArea  = GetViewableArea(playerCharacter.Location, gameStateUpdate);
            gameStateUpdate.OtherPlayers  = GetOtherViewablePlayersPositions(key, playerCharacter.Location);
            gameStateUpdate.NpcsInTheArea = GetNpcsInTheArea(key, playerCharacter.Location);

            client.Callback.GameStateUpdatedCallback(gameStateUpdate);
        }
예제 #2
0
        public void Join(Guid key)
        {
            //Get the call back for the game play client
            IGameplayCallback callback = OperationContext.Current.GetCallbackChannel <IGameplayCallback>();

            //Create a CommunicationsStore to hold information about the connected client
            GameplayCommunicationsStore client = new GameplayCommunicationsStore(OperationContext.Current.InstanceContext, callback);

            //TODO:Need to handle the client not being authenticated
            client.UserAccount = Authentication.AuthenticationService.GetUserAccount(key);

            if (!OperationContext.Current.IncomingMessageProperties.ContainsKey(RemoteEndpointMessageProperty.Name))
            {
                client.IPAddress = "127.0.0.1";
            }
            else
            {
                client.IPAddress = ((RemoteEndpointMessageProperty)OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]).Address;
            }

            //Add the client to our static list.  We need to lock the list for synchronization safety.
            lock (ConnectedClients)
            {
                ConnectedClients.Add(key, client);
            }

            PlayerCharacter playerCharacter = new PlayerCharacter(_game);

            _players.Add(playerCharacter);
            playerCharacter.Location = new System.Drawing.Point(13, 10);
            client.PlayerCharacterId = playerCharacter.Id;
            _zombiesSystem.Players.Add(playerCharacter);

            Console.WriteLine("{0} joined the game.", client.UserAccount.Nickname);

            UpdateGameState(key);
        }
예제 #3
0
        public void Move(Guid key, List <Core.GameStateInformation.Directions> movements)
        {
            if (!ConnectedClients.ContainsKey(key))
            {
                return;
            }

            GameplayCommunicationsStore connectedClient = ConnectedClients[key];
            Character playerCharacter = _players.Where(i => i.Id == connectedClient.PlayerCharacterId).First();

            //TODO:Implement movement restrictions here
            //TODO:This is allowing the player to move diagonally through two hexes that are unpassable.
            foreach (Core.GameStateInformation.Directions movementDirection in movements)
            {
                Point newLocation = playerCharacter.Location;
                switch (movementDirection)
                {
                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.North:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X, playerCharacter.Location.Y - 1);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.South:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X, playerCharacter.Location.Y + 1);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.East:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X + 1, playerCharacter.Location.Y);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.West:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X - 1, playerCharacter.Location.Y);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.NorthEast:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X + 1, playerCharacter.Location.Y - 1);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.NorthWest:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X - 1, playerCharacter.Location.Y - 1);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.SouthEast:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X + 1, playerCharacter.Location.Y + 1);
                    break;

                case LegendsOfKesmaiSurvival.Core.GameStateInformation.Directions.SouthWest:
                    newLocation = new System.Drawing.Point(playerCharacter.Location.X - 1, playerCharacter.Location.Y + 1);
                    break;
                }

                //Get the tile that the player is trying to move to
                Game.GameTile newTile = _game.GameMap.GetTileFromLocation(newLocation.X, newLocation.Y);

                //Do not let the player move to a tile that is not accessible
                if (newTile.IsPassable)
                {
                    playerCharacter.Location = newLocation;
                }
            }

            //TODO:Only need to update the game states of clients that would be affected by the player moving in or into the viewable area
            foreach (Guid clientKey in ConnectedClients.Keys)
            {
                UpdateGameState(clientKey);
            }
        }