public bool TryHost(Ship ship, Shipyard shipyard) { // ship card must be in the players hand if (!_game.Player.Hand.Contains(ship)) { return(false); } // can only host one card if (shipyard.HostedShip != null) { return(false); } // can only host ships up to a certain size if (ship.Size > shipyard.MaxSize) { return(false); } // need enough money if (ship.BaseCost > _game.Player.Credits) { return(false); } // hosting costs a click if (_game.Player.Clicks < 1) { return(false); } // TODO - we could gather the reasons for failure here and do something e.g display a popup? // if we get here is all good, host away _actions.Add(new HostShipAction(ship, shipyard)); ChangeClicks(-1); _game.Player.ChangeCredits(-ship.BaseCost); shipyard.HostCard(ship); ship.StartConstruction(); _game.Player.Hand.Remove(ship); GameViewController.HostShip(ship, shipyard, true); UpdatePlayerStateGUI(); EnableDisableControls(); GameViewController.AddGameLogMessage(string.Format("<b>You</b> host {0} on {1}", ship.CardName, shipyard.CardName)); return(true); }
private void ProcessOpponentHostShipAction(string shipId, string shipyardId, CardCodename cardCodename) { // ship will be an unknown card at this point so needs to be instantiated Ship ship = (Ship)CardFactory.CreateCard(cardCodename, shipId); Shipyard shipyard = _game.Opponent.Shipyards.Find(x => x.CardId == shipyardId); shipyard.HostCard(ship); ship.StartConstruction(); if (ship.OnPlay != null) { ship.OnPlay(_game, _game.Opponent); } _game.Opponent.ChangeClicks(-1); _game.Opponent.ChangeCredits(-ship.BaseCost); _game.Opponent.Hand.RemoveAt(0); GameViewController.HostShip(ship, shipyard, false); GameViewController.AddGameLogMessage(string.Format("<b>{0}</b> hosts {1} on {2}", _game.Opponent.Name, ship.CardName, shipyard.CardName)); }
public bool TryHost(Game game, Player player, Ship ship, Shipyard shipyard) { ServerLog(string.Format("TryHost player{0}, shipCard{1}, shipyard{2}", player.Name, ship.CardId, shipyard.CardId), game); // can only host one card if (shipyard.HostedShip != null) { return(false); } // can only host ships up to a certain size if (ship.Size > shipyard.MaxSize) { return(false); } // need enough money if (ship.BaseCost > player.Credits) { return(false); } // hosting costs a click if (player.Clicks < 1) { return(false); } // if we get here is all good, host away shipyard.HostCard(ship); ship.StartConstruction(); ChangeCredits(player, -ship.BaseCost); ChangeClicks(player, -1); if (ship.OnPlay != null) { ship.OnPlay(game, player); } return(true); }