Example #1
0
        public void Run(HSInputState state)
        {
            var debt   = _context.GetComponent <PlayerDebt>();
            var player = _context.GetPlayer(state.PlayerId.Value);
            var propId = (int)state.MiscInfo;

            var choice = _context.GetComponent <HSCommandChoice>();

            if (choice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    _context.Add(new PrintLine($"You're in debt. Debt amount: {debt.DebtAmount}; current Cash: {player.Cash}",
                                               OutputStream.HSInputLog));

                    var availableCommands = _context.GetAvailablePropertyActions(player, propId)
                                            .Where(command => IsSuitablePropertyAction(command))
                                            .ToList();

                    availableCommands.Add(MonopolyCommand.CancelAction);
                    if (player.Cash >= debt.DebtAmount)
                    {
                        availableCommands.Add(MonopolyCommand.PayDebt);
                    }

                    _context.Add(new PrintLine("\nProperty to manage:", OutputStream.HSInputLog));
                    _context.Add(new PrintProperties(propId, OutputStream.HSInputLog));
                    _context.Add(new PrintLine("", OutputStream.HSInputLog));
                    _context.Add(new PrintCommands(availableCommands));

                    _context.Add(new HSCommandChoiceRequest(availableCommands, player.Id));
                }

                return;
            }

            switch (choice.Command)
            {
            case MonopolyCommand.MortgageProperty:
                _context.Mortgage(player, propId);
                break;

            case MonopolyCommand.SellHouse:
                _context.SellHouse(player, propId);
                break;

            case MonopolyCommand.CancelAction:
                state.Set(HSState.DebtChooseProperty, player.Id);
                break;

            case MonopolyCommand.PayDebt:
                _context.Add(new PaidOffDebt(player.Id));
                state.Nullify();
                break;
            }

            _context.Remove(choice);
            _context.Add(new ClearOutput());
        }
        public void Run(HSInputState state)
        {
            var player = _context.GetPlayer(state.PlayerId.Value);

            var commandChoice = _context.GetComponent <HSCommandChoice>();

            if (commandChoice == null)
            {
                if (!_context.ContainsComponent <HSCommandChoiceRequest>())
                {
                    var commands = GetAvailableCommands(player);
                    _context.Add(new PrintCommands(commands));
                    _context.Add(new HSCommandChoiceRequest(commands, player.Id));
                }
                return;
            }

            _context.Add(new ClearOutput());
            switch (commandChoice.Command)
            {
            case MonopolyCommand.ManageProperty:
                state.Set(HSState.PropManageChooseProperty, player.Id);
                break;

            case MonopolyCommand.CreateTradeOffer:
                var offer = new TradeOffer();
                offer.InitiatorAssets.PlayerId = player.Id;
                _context.Add(offer);
                state.Set(HSState.TradeChoosePlayer, player.Id);
                break;

            case MonopolyCommand.MakeMove:
                _context.Add(new ThrowDice());
                _context.Add(new MoveDice(player.Id));
                state.Nullify();
                break;

            case MonopolyCommand.EndTurn:
                _context.Add(new EndTurn());
                state.Nullify();
                break;

            case MonopolyCommand.PrintPlayerStatus:
                _context.Add(new PrintPlayerStatus(commandChoice.PlayerId));
                break;

            case MonopolyCommand.PrintGameStatus:
                _context.Add(new PrintGameStatus());
                break;

            case MonopolyCommand.PrintMap:
                _context.Add(new PrintMap());
                break;

            case MonopolyCommand.PayJailFine:
                _context.Add(new JailPayFine(player.Id));
                break;

            case MonopolyCommand.JailRollDice:
                _context.Add(new ThrowDice());
                _context.Add(new JailDiceRoll(player.Id));
                break;

            case MonopolyCommand.UseJailCard:
                _context.Add(new JailUseCard(player.Id));
                break;
            }
            _context.Remove <HSCommandChoice>(c => c.Command == commandChoice.Command);
        }