public void Run(HSInputState state) { var offer = _context.TradeOffer(); var choice = _context.GetComponent <HSCommandChoice>(); if (choice == null) { if (!_context.ContainsComponent <HSCommandChoiceRequest>()) { var commands = new List <MonopolyCommand> { MonopolyCommand.ConfirmTrade, MonopolyCommand.ChangeInitiatorAssets, MonopolyCommand.ChangeReceiverAssets, MonopolyCommand.CancelAction, }; _context.Add(new PrintTradeOffer(offer, OutputStream.HSInputLog)); _context.Add(new PrintLine("", OutputStream.HSInputLog)); _context.Add(new PrintCommands(commands)); _context.Add(new HSCommandChoiceRequest(commands, state.PlayerId.Value)); } return; } switch (choice.Command) { case MonopolyCommand.ConfirmTrade: state.Nullify(); break; case MonopolyCommand.ChangeReceiverAssets: case MonopolyCommand.ChangeInitiatorAssets: state.CurState = HSState.TradeChangeAssets; if (choice.Command == MonopolyCommand.ChangeInitiatorAssets) { state.MiscInfo = offer.InitiatorAssets; } else { state.MiscInfo = offer.ReceiverAssets; } break; case MonopolyCommand.CancelAction: _context.Remove(offer); state.Nullify(); break; } _context.Add(new ClearOutput()); _context.Remove <HSCommandChoice>(); }
public void Run(HSInputState state) { var commandChoice = _context.GetComponent <HSCommandChoice>(); if (commandChoice == null) { return; } _context.Add(new ClearOutput()); var player = _context.GetPlayer(state.PlayerId.Value); switch (commandChoice.Command) { case MonopolyCommand.BuyProperty: _context.Add(new BuyProperty(player.Id, player.CurTileId)); break; case MonopolyCommand.AuctionProperty: _context.Add(new StartAuction(player.CurTileId)); break; } _context.Remove <HSCommandChoice>(c => c.Command == commandChoice.Command); state.Nullify(); }
public void Run(HSInputState state) { var choice = _context.GetComponent <HSCommandChoice>(); if (choice == null) { if (!_context.ContainsComponent <HSCommandChoiceRequest>()) { var commands = new List <MonopolyCommand> { MonopolyCommand.AcceptOffer, MonopolyCommand.DeclineOffer, }; _context.Add(new PrintCommands(commands)); _context.Add(new HSCommandChoiceRequest(commands, state.PlayerId.Value)); } return; } switch (choice.Command) { case MonopolyCommand.AcceptOffer: _context.Add(new TradeAccept()); break; case MonopolyCommand.DeclineOffer: _context.Add(new TradeRefuse()); break; } _context.Remove(choice); _context.Add(new ClearOutput()); state.Nullify(); }
public void Run(HSInputState state) { var choice = _context.GetComponent <HSPlayerChoice>(); if (choice == null) { if (!_context.ContainsComponent <HSPlayerChoiceRequest>()) { var availablePlayers = _context.GetAllPlayers() .Select(p => p.Id) .Where(id => id != state.PlayerId.Value) .ToList(); _context.Add(new PrintLine("Choose a player to trade with:", OutputStream.HSInputLog)); _context.Add(new PrintPlayers(availablePlayers, OutputStream.HSInputLog)); _context.Add(new PrintLine("Write -1 to cancel", OutputStream.HSInputLog)); _context.Add(new HSPlayerChoiceRequest(state.PlayerId.Value, availablePlayers)); } return; } // if player canceled his choice if (!choice.PlayerChoiceId.HasValue) { _context.Remove <TradeOffer>(); state.Nullify(); } else { _context.TradeOffer().ReceiverAssets.PlayerId = choice.PlayerChoiceId.Value; state.CurState = HSState.TradeChooseAction; } _context.Add(new ClearOutput()); _context.Remove(choice); }
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 debt = _context.GetComponent <PlayerDebt>(); var player = _context.GetPlayer(state.PlayerId.Value); 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 = new List <MonopolyCommand> { MonopolyCommand.ChooseProperty }; if (player.Cash >= debt.DebtAmount) { availableCommands.Add(MonopolyCommand.PayDebt); } else { _context.Add(new PrintLine("You can sell houses and mortgage property to stay in the game", OutputStream.HSInputLog)); } _context.Add(new PrintCommands(availableCommands)); _context.Add(new HSCommandChoiceRequest(availableCommands, player.Id)); } return; } switch (choice.Command) { case MonopolyCommand.ChooseProperty: state.CurState = HSState.DebtChooseProperty; break; case MonopolyCommand.PayDebt: state.Nullify(); _context.Add(new PaidOffDebt(player.Id)); break; } _context.Add(new ClearOutput()); _context.Remove(choice); }
public void Run(HSInputState state) { var intChoice = _context.GetComponent <HSIntChoice>(); if (intChoice == null) { return; } if (intChoice == 0) { _context.Add(new AuctionWithdraw(state.PlayerId.Value)); } else { _context.Add(new AuctionBid(state.PlayerId.Value, intChoice)); } _context.Add(new ClearOutput()); _context.Remove(intChoice); state.Nullify(); }
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); }