Esempio n. 1
0
        public void UpdateResponse(InGameAction action)
        {
            if (Player != null)
            {
                if (action.Sender == Player.XmlPlayer.ID)
                {
                    AcceptOfferAction accept = action as AcceptOfferAction;
                    if (accept != null)
                    {
                        UpdateAccept(accept);
                    }

                    RejectOfferAction reject = action as RejectOfferAction;
                    if (reject != null)
                    {
                        UpdateReject(reject);
                    }

                    CounterTradeOfferAction counter = action as CounterTradeOfferAction;
                    if (counter != null)
                    {
                        UpdateCounter(counter);
                    }
                }
            }
        }
Esempio n. 2
0
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            if (AllowedAction(action, game))
            {
                action.PerformTurnAction(game);

                EndTurnAction endTurn = action as EndTurnAction;
                if (endTurn != null)
                {
                    return new BeforeDiceRollTurnPhase();
                }

                return this;
            }
            else
            {
                // Check if we are allowed to trade
                TradeOfferAction tradeOffer = action as TradeOfferAction;
                if (tradeOffer != null)
                {
                    // Only when game setting allows it
                    if (game.Settings.TradingAfterBuilding)
                    {
                        return _TradingPhase;
                    }
                    return null;
                }
                return null;
            }
        }
Esempio n. 3
0
 public override void ProcessAction(InGameAction inGameAction, XmlGame game)
 {
     /*
     HostStartsGameAction hostStarts = inGameAction as HostStartsGameAction;
     if (hostStarts != null)
     {
         game.ActionsQueue.Enqueue(new DetermineFirstPlayerGamePhase() { Sender = 0 });
     }
      */
     inGameAction.PerformTurnAction(game);
 }
Esempio n. 4
0
 public virtual bool AllowedAction(InGameAction inGameAction, XmlGame game)
 {
     if (_AllowedActions.Contains(inGameAction.GetType()))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Esempio n. 5
0
        public override bool AllowedAction(InGameAction inGameAction, XmlGame game)
        {
            if (!base.AllowedAction(inGameAction, game))
                return false;

            // Check if we are allowed to trade
            TradeOfferAction tradeOffer = inGameAction as TradeOfferAction;
            if (tradeOffer != null && !game.Settings.TradingAfterBuilding)
                return false;

            // Default on returning true
            return true;
        }
Esempio n. 6
0
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            inGameAction.PerformTurnAction(game);

            if (game.ActionsQueue.Count == 0)
            {
                // Notify we want to start the placement phase
                game.ActionsQueue.Enqueue(new PortsPlacedAction() { Sender = 0 });
            }
            else
            {
                // Move to the next player
                game.PlayerOnTurn = game.NextPlayer;
            }
        }
Esempio n. 7
0
        public override bool IsAllowed(InGameAction inGameAction, XmlGame game)
        {
            if (!base.IsAllowed(inGameAction, game)) return false;

            // When a placeport action is preformed, the action should be originating
            // from the expected player on the actionsqueue
            PlacePortAction placePort = inGameAction as PlacePortAction;
            if (placePort != null)
            {
                if (placePort.Sender != game.ActionsQueue.Peek().Sender)
                {
                    return false;
                }
            }

            return true;
        }
Esempio n. 8
0
 public bool BeginAction(InGameAction action)
 {
     if (_InteractionBehaviour != null)
     {
         _InteractionBehaviour.RemoveStartState(Board);
     }
     _InteractionBehaviour = BoardVisualBehaviour.CreateBehaviour(action, CurrentGame);
     if (_InteractionBehaviour != null)
     {
         _InteractionBehaviour.SetStartState(Board);
         return true;
     }
     else
     {
         return false;
     }
 }
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            RollDiceAction rollDice = action as RollDiceAction;
            if (rollDice != null)
            {
                return new RollDiceTurnPhase();
            }
            if (AllowedAction(action, game))
            {

                action.PerformTurnAction(game);
                return this;
            }
            else
            {
                return null;
            }
        }
Esempio n. 10
0
 public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
 {
     // If the action is allowed to be executed in this phase, do it
     if (AllowedAction(action, game))
     {
         action.PerformTurnAction(game);
         return this;
     }
     else
     // If action is not allowed to execute, check if buildphase allows it. If so, move to
     // buildphase
     {
         if (_BuildPhase.AllowedAction(action, game))
         {
             return _BuildPhase;
         }
         throw new Exception("whoa");
     }
 }
Esempio n. 11
0
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            ClaimVictoryAction claimVictory = inGameAction as ClaimVictoryAction;
            if (claimVictory != null)
            {
                _TurnPhase.ProcessAction(inGameAction, game);
                return;
            }

            PlacementDoneAction placementDone = inGameAction as PlacementDoneAction;
            if (placementDone != null)
            {
                _TurnPhase.ProcessAction(inGameAction, game);
                return;
            }
            EndTurnAction endTurn = inGameAction as EndTurnAction;
            if (endTurn != null)
            {
                _TurnPhase = new BeforeDiceRollTurnPhase();
                endTurn.PerformTurnAction(game);
                return;
            }
            // Process the actual in the current turnphase
            TurnPhase next = _TurnPhase.ProcessAction(inGameAction, game);

            // If return phase does not match current phase, we have to switch phases and process the action
            // again
            if (_TurnPhase != next)
            {
                _TurnPhase = next;
                _TurnPhase = _TurnPhase.ProcessAction(inGameAction, game);
            }

            // When the incoming action is not valid, check if it's valid in the next phase.
            // If so, switch phases
            if (!_TurnPhase.AllowedAction(inGameAction, game))
            {
                if (_TurnPhase.Next().AllowedAction(inGameAction, game))
                {
                    _TurnPhase = _TurnPhase.Next();
                }
            }
        }
Esempio n. 12
0
        public void ExecuteAction(InGameAction action)
        {
            //check if the userid of the action is actually playing
            if ((from u in _Users where u.ID == action.UserID select u).Count() == 0)
            {
                if (action is BuildRoadAction)
                {
                    TryBuildRoad((BuildRoadAction)action);
                }
            }
            else
            // we received an ingame action from a user which is not in this game
            {
                MessageFromServerAction message = new MessageFromServerAction();
                message.Message = String.Format(
                    "Hey! You send an action for game with id: {0}, but you with userid {1} are not in the players list of game with id: {0}",
                    action.GameID, action.UserID);

            }
        }
Esempio n. 13
0
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            // If we build a town or a city, make sure the next action (buildroad)
            // has OriginatingTownOrCity set. This is ignored for the third road
            // as required by Tournament Starting Rules.
            BuildTownAction buildTown = inGameAction as BuildTownAction;
            if (buildTown != null)
            {
                BuildRoadAction buildRoad3 = game.ActionsQueue.Peek() as BuildRoadAction;
                buildRoad3.OriginatingTownOrCity = buildTown.Location;
            }
            BuildCityAction buildCity = inGameAction as BuildCityAction;
            if (buildCity != null)
            {
                BuildRoadAction buildRoad2 = game.ActionsQueue.Peek() as BuildRoadAction;
                buildRoad2.OriginatingTownOrCity = buildCity.Location;
            }

            inGameAction.PerformTurnAction(game);

            // If the last road or ship has been built, add new gamephase action on the queue
            BuildRoadAction buildRoad = inGameAction as BuildRoadAction;
            BuildShipAction buildShip = inGameAction as BuildShipAction;
            if (buildRoad != null || buildShip != null)
            {
                if (game.ActionsQueue.Count == 0)
                {
                    game.ActionsQueue.Enqueue(new PlacementDoneAction() { Sender = 0 });
                }
                else
                {
                    // Next player is the player of the first action on the queue
                    game.PlayerOnTurn = game.GetPlayer(game.ActionsQueue.Peek().Sender);
                }

            }
        }
Esempio n. 14
0
        public GameAction ExecuteAction(InGameAction action)
        {
            if (action.IsValid(_Game))
            {
                //Execute the game action if the action is valid
                action.PerformTurnAction(_Game);

                // Send action back to sender for confirmation

                //Send action to all other players and spectators

                //Add action to the gamelog
                _Game.GameLog.Add(action);
                return action;
            }
            else
            // we received an illegal ingameaction.
            // This should only happen when a user deliberately tampers with data
            {
                MessageFromServerAction message = new MessageFromServerAction();
                message.Message = String.Format(
                    "The game action does not seem to be valid. The reason: action object says \"{0}\"",
                    action.InvalidMessage);
                return message;
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Returns interaction behaviour for the 3D viewport depending on a game action
        /// </summary>
        /// Pattern: Factory method
        /// <param name="action"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public static BoardVisualBehaviour CreateBehaviour(InGameAction action, XmlGame game)
        {
            PlaceRobberPirateAction placerobberPirate = action as PlaceRobberPirateAction;
            if (placerobberPirate != null)
                return new PlaceRobberBehaviour() { OriginatingAction = action };

            BuildCityAction buildCity = action as BuildCityAction;
            if (buildCity != null)
                return new BuildCityBehaviour(false) { OriginatingAction = action };

            BuildTownAction buildTown = action as BuildTownAction;
            if (buildTown != null)
            {
                bool isStart;
                if (game.Phase.GetType() == typeof(PlayTurnsGamePhase))
                    isStart = false;
                else
                    isStart = true;
                return new BuildTownBehaviour(isStart) { OriginatingAction = action };
            }

            BuildRoadAction buildRoad = action as BuildRoadAction;
            if (buildRoad != null)
                return new BuildRoadBehaviour()
                {
                    StartingTownOrCity = buildRoad.OriginatingTownOrCity,
                    OriginatingAction = action
                };

            BuildShipAction buildShip = action as BuildShipAction;
            if (buildShip != null)
                return new BuildShipBehaviour() { OriginatingAction = action };

            TradeBankAction tba = action as TradeBankAction;
            if (tba != null)
                return new ShowPointsBehaviour();

            ClaimVictoryAction claimWin = action as ClaimVictoryAction;
            if (claimWin != null)
            {
                return new TestBehaviour();
            }

            MoveShipAction moveShip = action as MoveShipAction;
            if (moveShip != null)
            {
                return new MoveShipBehaviour()
                {
                    OriginatingAction = moveShip
                };
            }

            RollDiceAction rollDice = action as RollDiceAction;
            if (rollDice != null)
            {
                return new ShowResourcesGainedBehaviour()
                {
                    OriginatingAction=rollDice
                };
            }
            return null;
        }
Esempio n. 16
0
        private void TryHandleGameAction(InGameAction action)
        {
            if (CheckIfPlayerBelongsToGame(action.GameID, action.Sender))
            {
                //HandleGameAction(action);
            }
            else
            {
                //notify the user some mismatch happened
                MessageFromServerAction response = new MessageFromServerAction();

                response.Message = String.Format(
                    "You, player {0} do not belong to game with ID {1}",
                    action.GameID, _CurrentPerson.Name);

                response.Sender = _ServerUser.ID;
                Whisper(action.Sender, response);
                return;
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Executes a given InGameAction
        /// </summary>
        /// <param name="inGameAction"></param>
        private void ExecuteInGameAction(InGameAction action)
        {
            ServerGame serverGame = (from g in _Games
                                     where g.Game.ID == action.GameID
                                     select g).Single();

            if (!(action).IsValid(serverGame.Game))
            {
                SayError(_CurrentPerson.ID, "Invalid InGameAction object");
            }
            else
            {
                GameAction inGameAction = serverGame.ExecuteAction((InGameAction)action);
                TurnAction turnAction = inGameAction as TurnAction;

                if (turnAction != null)
                // When we have a turnaction, we must nullify the data sent to
                // spectators and players. No need for them to know what kind of
                // development cards or resources a player has.
                // The data should not even reside on a clients computer.
                {
                    // before sending, make sure the actual player gets the
                    // right data
                    Whisper(action.Sender, turnAction);

                    //Now we can nullify it
                    turnAction.NullifyData();

                    //to send it to spectators and players
                    foreach (XmlUser spectator in serverGame.Spectators)
                        Whisper(spectator.ID, turnAction);

                    foreach (XmlUser player in serverGame.Users)
                    {
                        //we already sent it to the actual player, so omit him
                        if (player.ID != action.Sender)
                            Whisper(player.ID, turnAction);
                    }
                }
                else
                {
                    if (inGameAction != null)
                    {
                        // Send message without nullifying data (no need for ingameactions)
                        // to all clients (players & spectators)
                        foreach (XmlUser client in serverGame.Users.Union<XmlUser>(serverGame.Spectators))
                            Whisper(client.ID, inGameAction);
                    }
                    else
                    //Some error occured, only reflect back to the originating client
                    {
                        Whisper(action.Sender, inGameAction);
                    }
                }
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Broadcast the message to all participants of a game
        /// </summary>
        /// <param name="action">Action to broadcast</param>
        /// <param name="game">The game with the participants</param>
        private void BroadcastMessage(InGameAction action, ServerGame game)
        {
            // broadcast message to all users
            foreach (XmlUser user in game.Users)
                BroadcastMessage(action, user);

            // broadcast message to all spectators
            foreach (XmlUser spectator in game.Spectators)
                BroadcastMessage(action, spectator);
        }
Esempio n. 19
0
        private void HandleGameAction(InGameAction action)
        {
            // get the corresponding servergame

            //execute the action on the game
        }
 private void OnExecuteGameAction(InGameAction action)
 {
     if (ExecuteGameAction != null)
         ExecuteGameAction(action);
 }
Esempio n. 21
0
 private void OnActionCompleted(InGameAction action)
 {
     if (ActionCompleted != null)
         ActionCompleted(action);
 }
Esempio n. 22
0
 void OnInGameActionReceived(InGameAction action)
 {
     if (InGameActionReceived != null)
         InGameActionReceived(action);
 }
 public override bool AllowedAction(InGameAction inGameAction, XmlGame game)
 {
     return base.AllowedAction(inGameAction, game);
 }
Esempio n. 24
0
 /// <summary>
 /// Returns true if passed action is allowed to be performed in current
 /// game phase
 /// </summary>
 /// <param name="inGameAction"></param>
 /// <returns></returns>
 public virtual bool IsAllowed(InGameAction inGameAction, XmlGame game)
 {
     return _AllowedActions.Contains(inGameAction.GetType());
 }
Esempio n. 25
0
 public virtual TurnPhase ProcessAction(InGameAction action, XmlGame game)
 {
     throw new NotImplementedException();
 }
Esempio n. 26
0
 public virtual void ProcessAction(InGameAction inGameAction, XmlGame game)
 {
     // base class should implement
     throw new NotImplementedException();
 }
Esempio n. 27
0
        public void SetStatus(InGameAction action)
        {
            RollDiceAction rollDice = action as RollDiceAction;
            if (rollDice != null)
            {

            }
        }
        /// <summary>
        /// Creates gamequeue for each player
        /// </summary>
        /// <param name="inGameAction"></param>
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            inGameAction.PerformTurnAction(game);

            RollDiceAction rollDice = inGameAction as RollDiceAction;
            if (rollDice != null)
            {
                // Check if a phase has ended. If the queue is empty, every player has rolled the dice.
                if (game.ActionsQueue.Count() == 0)
                {
                    // Make a list of rolls in this round
                    List<RollDiceAction> rolledDices = game.GameLog.GetCurrentRoundRolls(game);

                    // highroll dice number
                    int highRoll = (from rd in rolledDices select rd.Dice).Max();

                    // When starting player is not determined yet, repeat dice roll between winners until
                    // winner is detemined
                    if (game.GameLog.FirstPlayerIsDetermined(game))
                    {
                        // We have a starting player
                        int winnerID = rolledDices.Where(rd => rd.Dice == highRoll)
                                                                          .First()
                                                                          .Sender;

                        game.ActionsQueue.Enqueue(new StartingPlayerDeterminedAction()
                        {
                            // The starter of the placement/portplacement/turnactionsgamephase
                            PlayerID = winnerID,
                            // winning dice
                            DiceRoll = highRoll,
                            // Server will send this message
                            Sender = 0
                        });
                        return;
                    }
                    else
                    {
                        // Starting player is not determined. Notify players and update Game object
                        game.ActionsQueue.Enqueue(new RolledSameAction()
                        {
                            // Pass on the highest diceroll
                            HighRoll = highRoll,
                            // Server says dice rolled the same
                            Sender = 0
                        });

                        // Enqueue each highroller
                        foreach (RollDiceAction sameRoll in rolledDices.Where(rd => rd.Dice == highRoll))
                        {
                            game.ActionsQueue.Enqueue(new RollDiceAction() { GamePlayer = sameRoll.GamePlayer });
                        }

                        // First player is on turn
                        game.PlayerOnTurn = game.ActionsQueue.ElementAt(1).GamePlayer;
                        return;
                    }
                }

                // Next player should be the player next on the queue
                game.PlayerOnTurn = game.GetPlayer(game.ActionsQueue
                    .OfType<RollDiceAction>()
                    .First()
                    .Sender);

            }
        }
Esempio n. 29
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            if (AllowedAction(action, game))
            {
                RollDiceAction rollDice = action as RollDiceAction;
                if (rollDice != null)
                {
                    rollDice.PerformTurnAction(game);

                    // When a volcano is rolled, expect player to roll dice for volcano
                    /*
                    if (rollDice.HexesAffected.OfType<VolcanoHex>().Count() > 0)
                    {
                        game.ActionsQueue.Enqueue(new RollVolcanoDiceAction()
                        {
                            GamePlayer = rollDice.GamePlayer,
                            VolcanosRolled = rollDice.HexesAffected.OfType<VolcanoHex>().ToList<VolcanoHex>()
                        });

                        // We expect another action, return current phase
                        return this;
                    }
                     */

                    // When a 7 is rolled, enqueue every player required to loose cards to do so
                    if (rollDice.Dice == 7)
                    {
                        // Add each player required to loose cards to the queue
                        foreach (int i in rollDice.LooserPlayers)
                        {
                            game.ActionsQueue.Enqueue(new LooseCardsAction()
                            {
                                GamePlayer = game.GetPlayer(i)
                            });
                        }

                        // Expect player to place robber/pirate and rob a player
                        game.ActionsQueue.Enqueue(new PlaceRobberPirateAction() { GamePlayer = action.GamePlayer });
                        game.ActionsQueue.Enqueue(new RobPlayerAction() { GamePlayer = action.GamePlayer });

                        // We have actions to be done, we should stay in this phase
                        return this;
                    }

                    // Any other number has been rolled.
                    // Proceed to trading phase
                    if (game.ActionsQueue.Count == 0)
                    {
                        return new TradingTurnPhase();
                    }
                    else
                    {
                        return this;
                    }
                }

                RobPlayerAction robPlayer = action as RobPlayerAction;
                if (robPlayer != null)
                {
                    robPlayer.PerformTurnAction(game);

                    // When finished robbing, advance phase to trading
                    return this;
                }
                // perform the action
                action.PerformTurnAction(game);
                EndTurnAction endTurn = action as EndTurnAction;
                if (endTurn != null)
                {
                    return new BuildTurnPhase(null);
                }

                // Return current state
                return this;
            }
            else
            // Action is not allowed in rollDice phase. Check if it is allowed in subsequent phases,
            // then return that phase
            {
                TradingTurnPhase trading = new TradingTurnPhase();
                BuildTurnPhase building = new BuildTurnPhase(trading);
                if (trading.AllowedAction(action, game))
                {
                    return trading;
                }
                if (building.AllowedAction(action, game))
                {
                    return building;
                }
                return null;
            }
        }
Esempio n. 30
0
 public override bool IsAllowed(InGameAction inGameAction, XmlGame game)
 {
     return _TurnPhase.AllowedAction(inGameAction, game);
 }