コード例 #1
0
 public bool RemovePlayer(GameplayPlayer gameplayLayer)
 {
     if (gameplayLayer.Gameplay != Parent)
     {
         throw new ArgumentException($"Can't remove a {nameof(GameplayPlayer)} from this {nameof(GameplayPlayerCollection)} as it doesn't recognise this {nameof(LobbyView)} as it's parent.");
     }
     gameplayLayer = null;
     return(internalCollection.Remove(gameplayLayer));
 }
コード例 #2
0
 public bool TryGetPlayer(LocalId ownerId, out GameplayPlayer player)
 {
     foreach (var findPlayer in internalCollection)
     {
         if (findPlayer.OwnerId == ownerId)
         {
             player = findPlayer;
             return(true);
         }
     }
     player = null;
     return(false);
 }
コード例 #3
0
 public void AddPlayer(GameplayPlayer gameplayLayer)
 {
     if (gameplayLayer.Gameplay == null)
     {
         gameplayLayer.Gameplay = Parent;
         internalCollection.Add(gameplayLayer);
     }
     else if (gameplayLayer.Gameplay == Parent)
     {
         throw new ArgumentException($"Can't add a {nameof(GameplayPlayer)} to this {nameof(GameplayPlayerCollection)} as it already belongs to this {nameof(LobbyView)}.");
     }
     else
     {
         throw new InvalidOperationException($"Can't add a {nameof(GameplayPlayer)} to this {nameof(GameplayPlayerCollection)} as it belongs to another {nameof(LobbyView)}.");
     }
 }
コード例 #4
0
 public bool ContainsPlayer(GameplayPlayer gameplayLayer)
 {
     return(internalCollection.Contains(gameplayLayer));
 }
コード例 #5
0
ファイル: GameServer.cs プロジェクト: xJayLee/RPGCore
        public void AcceptInput(LocalId localId, GameCommand command)
        {
            if (command is StartGameCommand startGameCommand)
            {
                var gameRules = LobbyView.Load <GameRulesTemplate>(Lobby.GameData.Resources["gamerules/default-rules.json"]);

                var packTemplates = LobbyView.LoadAll <BuildingPackTemplate>(Lobby.GameData.Tags["type-buildingpack"])
                                    .ToDictionary(template => template.Identifier);

                var resourceTemplates = LobbyView.LoadAll <ResourceTemplate>(Lobby.GameData.Tags["type-resource"]);

                var rand = new Random();

                var sharedBuildings = gameRules.SharedCards
                                      .Select(card => packTemplates[card])
                                      .Select(pack => Lobby.BuildingTemplates.Where(building => building.Value.PackIdentifier == pack.Identifier).ToArray())
                                      .ToArray();

                var playerBuildings = gameRules.PlayerCards
                                      .Select(card => packTemplates[card])
                                      .Select(pack => Lobby.BuildingTemplates.Where(building => building.Value.PackIdentifier == pack.Identifier).ToArray())
                                      .ToArray();

                var globalCardSlots = sharedBuildings.Select(pack =>
                {
                    if (pack == null || pack.Length == 0)
                    {
                        return(null);
                    }

                    return(new GlobalCardSlot()
                    {
                        BuildingIdentifier = pack[rand.Next(0, pack.Length)].Key
                    });
                }).ToArray();

                var gameplayPlayers = new List <GameplayPlayer>(Lobby.Players.Count);
                foreach (var lobbyPlayer in Lobby.Players)
                {
                    var gameplayPlayer = new GameplayPlayer
                    {
                        OwnerId      = lobbyPlayer.OwnerId,
                        CurrentScore = new StatInstance(),
                        ResourceHand = new List <string>(),
                    };

                    var thisPlayerBuildings = playerBuildings
                                              .Select(pack =>
                    {
                        if (pack == null || pack.Length == 0)
                        {
                            return(null);
                        }

                        return(pack[rand.Next(0, pack.Length)].Key);
                    })
                                              .Select(cardId => new SpecialCardSlot()
                    {
                        BuildingIdentifier = cardId
                    })
                                              .ToList();

                    gameplayPlayer.SpecialCards = thisPlayerBuildings;
                    gameplayPlayer.Board        = new GameBoard();

                    gameplayPlayer.Buildings = globalCardSlots.Select(building =>
                    {
                        var buildingTemplate = Lobby.BuildingTemplates[building.BuildingIdentifier];

                        return(new BoardCardSlot()
                        {
                            BuildingIdentifier = building.BuildingIdentifier,
                            BoardEffect = buildingTemplate.BoardEffectGraph?.Unpack()?.Create()
                        });
                    }).ToList();

                    gameplayPlayers.Add(gameplayPlayer);
                }

                var procedure = new StartGameProcedure()
                {
                    Gameplay = new GameplayView()
                    {
                        Players            = new GameplayPlayerCollection(gameplayPlayers),
                        Buildings          = globalCardSlots,
                        CurrentPlayersTurn = 0,
                        DeclaredResource   = false,
                    }
                };

                RemoteCall(procedure);
            }
            else if (command is DeclareResourceCommand declareResourceCommand)
            {
                var procedure = new DeclareResourceProcedure()
                {
                    Player             = localId,
                    ResourceIdentifier = declareResourceCommand.ResourceIdentifier
                };

                RemoteCall(procedure);
            }
            else if (command is PlaceResourceCommand placeResourceCommand)
            {
                var procedure = new PlaceResourceProcedure()
                {
                    Player             = localId,
                    ResourceIdentifier = placeResourceCommand.ResourceIdentifier,
                    ResourcePosition   = placeResourceCommand.ResourcePosition
                };

                RemoteCall(procedure);
            }
            else if (command is BuildBuildingCommand buildBuildingCommand)
            {
                var procedure = new BuildBuildingProcedure()
                {
                    Player             = localId,
                    BuildingIdentifier = buildBuildingCommand.BuildingIdentifier,
                    BuildingPosition   = buildBuildingCommand.BuildingPosition,
                    Offset             = buildBuildingCommand.Offset,
                    Orientation        = buildBuildingCommand.Orientation
                };

                RemoteCall(procedure);
            }
            else if (command is EndTurnCommand endTurnCommand)
            {
                var procedure = new EndTurnProcedure()
                {
                    Player = localId
                };

                RemoteCall(procedure);
            }
        }