Пример #1
0
        public override ProcedureResult Apply(LobbyView view)
        {
            view.Gameplay.CurrentPlayersTurn++;
            view.Gameplay.DeclaredResource = false;

            return(ProcedureResult.Success);
        }
Пример #2
0
        public override ProcedureResult Apply(LobbyView view)
        {
            view.Players.AddPlayer(new LobbyPlayer()
            {
                OwnerId     = OwnerId,
                DisplayName = DisplayName
            });

            return(ProcedureResult.Success);
        }
Пример #3
0
        public override ProcedureResult Apply(LobbyView view)
        {
            view.Gameplay.DeclaredResource = true;

            foreach (var gameplayPlayer in view.Gameplay.Players)
            {
                if (gameplayPlayer.ResourceHand == null)
                {
                    gameplayPlayer.ResourceHand = new List <string>();
                }
                gameplayPlayer.ResourceHand.Add(ResourceIdentifier);
            }

            return(ProcedureResult.Success);
        }
Пример #4
0
        public override ProcedureResult Apply(LobbyView view)
        {
            var gameplayPlayer = view.Gameplay.Players[Player];

            bool owned     = gameplayPlayer.ResourceHand.Remove(ResourceIdentifier);
            var  placeTile = gameplayPlayer.Board[ResourcePosition];

            if (placeTile.Resource != null ||
                placeTile.Building != null ||
                !owned)
            {
                return(ProcedureResult.NotModified);
            }

            placeTile.Resource = ResourceIdentifier;

            return(ProcedureResult.Success);
        }
Пример #5
0
        public override ProcedureResult Apply(LobbyView view)
        {
            var buildingTemplate = new BuildingTemplate()
            {
                Recipe = new string[, ]
                {
                    { "x", "x", "x" },
                    { "x", null, null },
                }
            };

            var rotatedBuilding = new RotatedBuilding(buildingTemplate, Orientation);

            var gameplayPlayer = view.Gameplay.Players[Player];

            for (int x = 0; x < rotatedBuilding.Width; x++)
            {
                for (int y = 0; y < rotatedBuilding.Height; y++)
                {
                    var position = Offset + new Integer2(x, y);

                    string recipeTile = rotatedBuilding[x, y];
                    var    tile       = gameplayPlayer.Board[position];

                    if (recipeTile != null)
                    {
                        tile.Resource = "q";
                    }
                }
            }

            var placeTile = gameplayPlayer.Board[BuildingPosition];

            placeTile.Building = new Building(BuildingIdentifier);

            return(ProcedureResult.Success);
        }
Пример #6
0
        public override ProcedureResult Apply(LobbyView view)
        {
            view.Players.RemovePlayerWithId(OwnerId);

            return(ProcedureResult.Success);
        }
Пример #7
0
        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);
            }
        }
Пример #8
0
        public void StartHosting(IExplorer explorer)
        {
            Lobby = new LobbyView();

            Lobby.SetupDependancies(explorer);
        }