Пример #1
0
        private void UpdateRadarRange(PlayerGame playerGame, Game game, Unit newUnit)
        {
            //update tiles in radar range for user
            List<MapTile> radarRange = playerGame.Map.MapTiles.Where(c => c.Xpos >= newUnit.Position.Xpos - newUnit.RadarRange && c.Xpos <= newUnit.Position.Xpos + newUnit.RadarRange && c.Ypos >= newUnit.Position.Ypos - newUnit.RadarRange && c.Ypos <= newUnit.Position.Ypos + newUnit.RadarRange).ToList();
            foreach (MapTile mt in radarRange)
            {
                MapTile motherTile = game.Map.MapTiles.Where(c => c.Xpos == mt.Xpos && c.Ypos == mt.Ypos).First();
                mt.TerrainType = motherTile.TerrainType;
                mt.IsAccessible = motherTile.IsAccessible;
                mt.IsSpawningPoint = motherTile.IsSpawningPoint;
                mt.UserId = playerGame.UserId;
                PlayerMapTile pmt = this.flPlayerTiles.TypedItems<PlayerMapTile>().Where(c => c.Tile.Xpos == mt.Xpos && c.Tile.Ypos == mt.Ypos && c.UserId == playerGame.UserId).FirstOrDefault();
                if (pmt == null)
                {
                    PlayerMapTile playerMapTile = new PlayerMapTile(game.Id, playerGame.UserId, mt);
                    playerMapTile.Save(this.FAppPrivate);
                }
            }

        }
Пример #2
0
        private void JoinGame(GameCommand cmdReceived, Player player, PlayerGame playerGame, Game game)
        {
            if (playerGame != null)
            {
                new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "User already joined game").Save(this.FAppPrivate);
            }
            else
            {
                if (game == null)
                {
                    new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Game not found").Save(this.FAppPrivate);
                }
                else
                {
                    if (game.PlayersInGame.Count >= game.MaxNumberOfPlayers)
                    {
                        new CommandFeedback(cmdReceived, enCommandStatus.Rejected, "Already too many players in the game").Save(this.FAppPrivate);
                    }
                    else
                    {
                        PlayerGame newPlayerGame = new PlayerGame(game, cmdReceived.UserId, player.NickName);

                        foreach (MapTile tile in game.Map.MapTiles)
                        {

                            MapTile playerTile = new MapTile();
                            playerTile.TerrainType = -1;// tile.TerrainType;
                            playerTile.UserId = newPlayerGame.UserId;
                            playerTile.Xpos = tile.Xpos;
                            playerTile.Ypos = tile.Ypos;

                            newPlayerGame.Map.MapTiles.Add(playerTile);

                            //set spawn, check if not occupied first
                            if (newPlayerGame.Spawn == null && tile.IsSpawningPoint)
                            {
                                if (game.PlayersInGame.Where(c => c.Spawn.Xpos == tile.Xpos && c.Spawn.Ypos == tile.Ypos).Count() == 0)
                                {
                                    //not used yet
                                    newPlayerGame.Spawn = playerTile;
                                    PlayerMapTile playerMapTile = new PlayerMapTile(game.Id, cmdReceived.UserId, playerTile);
                                    playerTile.TerrainType = 100;
                                    playerTile.IsSpawningPoint = true;
                                    playerTile.IsAccessible = true;
                                    playerMapTile.Save(this.FAppPrivate);
                                }
                            }
                        }


                        newPlayerGame.Save(this.FAppPrivate);
                        game.PlayersInGame.Add(newPlayerGame);
                        game.Save(this.FAppPublic);
                        new CommandFeedback(cmdReceived, enCommandStatus.Accepted, "Joined the game").Save(this.FAppPrivate);
                    }
                }
            }
        }