private void ProcessOpponentOperationAction(string operationId, CardCodename cardCodename)
    {
        // instantiate
        Operation operation = (Operation)CardFactory.CreateCard(cardCodename, operationId);

        _game.Opponent.ChangeClicks(-1);
        _game.Opponent.ChangeCredits(-operation.BaseCost);
        _game.Opponent.Hand.RemoveAt(0);
        if (operation.OnPlay != null)
        {
            operation.OnPlay(_game, _game.Opponent);
        }

        if (operation.OperationType == OperationType.ONESHOT)
        {
            _game.Opponent.Discard.Add(operation);
        }
        else
        {
            _game.Opponent.OngoingOperations.Add(operation);
            GameViewController.AddOperation(operation, false);
        }

        // log
        GameViewController.AddGameLogMessage(string.Format("<b>{0}</b> plays {1}", _game.Opponent.Name, operation.CardName));
    }
    public static Card CreateCard(CardCodename cardCodename, string cardId)
    {
        CardType cardType = CardData.CardTypes[cardCodename];

        switch (cardType)
        {
        case CardType.SHIP:
            return(new Ship(cardCodename, cardId));

        case CardType.SHIPYARD:
            return(new Shipyard(cardCodename, cardId));

        case CardType.HOMEWORLD:
            return(new Homeworld(cardCodename, cardId));

        case CardType.OPERATION:
            return(new Operation(cardCodename, cardId));

        case CardType.UNKNOWN:
            return(new UnknownCard(cardCodename, cardId));

        default:
            throw new Exception("Invalid card type or card type not found for " + cardCodename);
        }
    }
 public Homeworld(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     this.CardType = CardType.HOMEWORLD;
     MaxHealth = DetermineMaxHealth();
     CurrentHealth = MaxHealth;
 }
 public PlayableCard(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     BaseCost = DetermineBaseCost();
     Phase = DeterminePhase();
     OnPlay += DetermineOnPlayAction();
 }
 public void AddCard(CardCodename CardCodename, int count = 1)
 {
     for (int i = 0; i < count; i++)
     {
         _cards.Add((PlayableCard)CardFactory.CreateCard(CardCodename));
     }
 }
Exemple #6
0
 public void AddCard(CardCodename CardCodename, int count = 1)
 {
     for (int i = 0; i < count; i++)
     {
         _cards.Add((PlayableCard)CardFactory.CreateCard(CardCodename));
     }
 }
    private void ProcessOpponentAction(string action)
    {
        Debug.Log(string.Format("Processing action {0}", action));
        string[]   actionData = action.Split('|');
        ActionType actionType = (ActionType)Enum.Parse(typeof(ActionType), actionData[0]);

        switch (actionType)
        {
        case ActionType.CLICK_FOR_CARD:
            ProcessOpponentClickForCardAction();
            break;

        case ActionType.CLICK_FOR_CREDIT:
            ProcessOpponentClickForCreditAction();
            break;

        case ActionType.HOST_SHIP:
            string       shipId       = actionData[1];
            string       shipyardId   = actionData[2];
            CardCodename cardCodename = (CardCodename)Enum.Parse(typeof(CardCodename), actionData[3]);
            ProcessOpponentHostShipAction(shipId, shipyardId, cardCodename);
            break;

        case ActionType.DEPLOY_SHIP:
            shipId     = actionData[1];
            shipyardId = actionData[2];
            ProcessOpponentDeployShipAction(shipId, shipyardId);
            break;

        case ActionType.ADVANCE_CONSTRUCTION:
            shipId     = actionData[1];
            shipyardId = actionData[2];
            ProcessOpponentAdvanceConstructionAction(shipId, shipyardId);
            break;

        case ActionType.SHIPYARD:
            shipyardId   = actionData[1];
            cardCodename = (CardCodename)Enum.Parse(typeof(CardCodename), actionData[2]);
            ProcessOpponentShipyardAction(shipyardId, cardCodename);
            break;

        case ActionType.OPERATION:
            string operationId = actionData[1];
            cardCodename = (CardCodename)Enum.Parse(typeof(CardCodename), actionData[2]);
            ProcessOpponentOperationAction(operationId, cardCodename);
            break;

        case ActionType.WEAPON_TARGET:
            shipId = actionData[1];
            int    weaponIndex = int.Parse(actionData[2]);
            string targetId    = actionData[3];
            ProcessOpponentWeaponTargetAction(shipId, weaponIndex, targetId);
            break;

        default:
            Debug.LogError("Unknown action type [" + actionType + "]");
            break;
        }
    }
 public Shipyard(CardCodename codename, string cardId) : base(codename, cardId)
 {
     CardType      = CardType.SHIPYARD;
     MaxSize       = GetMaxSize();
     Efficiency    = GetEfficiency();
     MaxHealth     = DetermineMaxHealth();
     CurrentHealth = MaxHealth;
 }
 public Card(CardCodename cardCodename, string cardId)
 {
     CardId = cardId;
     CardCodename = cardCodename;
     CardName = DetermineCardName();
     ImageName = DetermineImageName();
     CardText = DetermineCardText();
 }
Exemple #10
0
 public Card(CardCodename cardCodename, string cardId)
 {
     CardId       = cardId;
     CardCodename = cardCodename;
     CardName     = DetermineCardName();
     ImageName    = DetermineImageName();
     CardText     = DetermineCardText();
 }
Exemple #11
0
 public Ship(CardCodename codename, string cardId) : base(codename, cardId)
 {
     CardType      = CardType.SHIP;
     Size          = DetermineSize();
     Weapons       = DetermineWeapons();
     MaxHealth     = DetermineMaxHealth();
     CurrentHealth = MaxHealth;
 }
Exemple #12
0
 public Ship(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     CardType = CardType.SHIP;
     Size = DetermineSize();
     Weapons = DetermineWeapons();
     MaxHealth = DetermineMaxHealth();
     CurrentHealth = MaxHealth;
 }
 public Shipyard(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     CardType = CardType.SHIPYARD;
     MaxSize = GetMaxSize();
     Efficiency = GetEfficiency();
     MaxHealth = DetermineMaxHealth();
     CurrentHealth = MaxHealth;
 }
    // TODO - now that both client and server are using the same Game object, can possibly merge client and server code into a common class?
    private void ProcessAction(string action, Game game, Player player, Player opponent)
    {
        string[]   actionData = action.Split('|');
        ActionType actionType = (ActionType)Enum.Parse(typeof(ActionType), actionData[0]);

        switch (actionType)
        {
        case ActionType.CLICK_FOR_CARD:
            ProcessClickForCardAction(player, game);
            break;

        case ActionType.CLICK_FOR_CREDIT:
            ProcessClickForCreditAction(player, game);
            break;

        case ActionType.HOST_SHIP:
            string       shipId       = actionData[1];
            string       shipyardId   = actionData[2];
            CardCodename cardCodename = (CardCodename)Enum.Parse(typeof(CardCodename), actionData[3]);
            ProcessHostShipAction(player, opponent, game, shipId, shipyardId, cardCodename);
            break;

        case ActionType.DEPLOY_SHIP:
            shipId     = actionData[1];
            shipyardId = actionData[2];
            ProcessDeployShipAction(player, opponent, game, shipId, shipyardId);
            break;

        case ActionType.ADVANCE_CONSTRUCTION:
            shipId     = actionData[1];
            shipyardId = actionData[2];
            ProcessAdvanceConstructionAction(player, opponent, game, shipId, shipyardId);
            break;

        case ActionType.SHIPYARD:
            shipyardId = actionData[1];
            ProcessShipyardAction(player, opponent, game, shipyardId);
            break;

        case ActionType.OPERATION:
            string operationId = actionData[1];
            ProcessOperationAction(player, opponent, game, operationId);
            break;

        case ActionType.WEAPON_TARGET:
            shipId = actionData[1];
            int    weaponIndex = int.Parse(actionData[2]);
            string targetId    = actionData[3];
            ProcessWeaponTargetAction(player, opponent, game, shipId, weaponIndex, targetId);
            break;

        default:
            ServerLogError("Unknown action type [" + actionType + "]", game);
            break;
        }
    }
    private void ProcessOpponentShipyardAction(string shipyardId, CardCodename cardCodename)
    {
        // card needs to be instantiated
        Shipyard shipyard = (Shipyard)CardFactory.CreateCard(cardCodename, shipyardId);

        GameViewController.AddShipyard(shipyard, false);

        // spend the resources
        _game.Opponent.ChangeClicks(-1);
        _game.Opponent.ChangeCredits(-shipyard.BaseCost);
        _game.Opponent.Hand.RemoveAt(0);
        _game.Opponent.Shipyards.Add(shipyard);

        // log
        GameViewController.AddGameLogMessage(string.Format("<b>{0}</b> plays {1}", _game.Opponent.Name, shipyard.CardName));
    }
 public static Card CreateCard(CardCodename cardCodename, string cardId)
 {
     CardType cardType = CardData.CardTypes[cardCodename];
     switch(cardType)
     {
         case CardType.SHIP:
             return new Ship(cardCodename, cardId);
         case CardType.SHIPYARD:
             return new Shipyard(cardCodename, cardId);
         case CardType.HOMEWORLD:
             return new Homeworld(cardCodename, cardId);
         case CardType.OPERATION:
             return new Operation(cardCodename, cardId);
         case CardType.UNKNOWN:
             return new UnknownCard(cardCodename, cardId);
         default:
             throw new Exception("Invalid card type or card type not found for " + cardCodename);
     }
 }
    private void OnDrawnCardMessage(NetworkMessage netMsg)
    {
        var    msg = netMsg.ReadMessage <MessageTypes.DrawnCardMessage>();
        var    cardCodenameData = msg.CardCodename;
        string cardId           = msg.cardId;

        Debug.Log(String.Format("Card drawn: {0}({1})", cardCodenameData, cardId));

        // add to local version of game state
        CardCodename cardCodename = (CardCodename)Enum.Parse(typeof(CardCodename), cardCodenameData);
        PlayableCard card         = (PlayableCard)CardFactory.CreateCard(cardCodename, cardId);

        _game.Player.Hand.Add(card);

        GameViewController.AddCardToHand(card, true);

        // update player state gui
        UpdatePlayerStateGUI();
    }
    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));
    }
    void ProcessHostShipAction(Player player, Player opponent, Game game, string shipId, string shipyardId, CardCodename cardCodename)
    {
        // find card and shipyard by their id
        PlayableCard card = FindCardIn(shipId, player.Hand);//player.Hand.Find(x => x.CardId == cardId);
        Ship         ship = (Ship)card;
        // TODO - error if card not in hand - at the moment we just trust that it is
        // TODO - error if cardCodename is not the same - need to verify this as we pass to opponent on trust otherwise

        Shipyard shipyard = FindCardIn(shipyardId, player.Shipyards);//player.Shipyards.Find(x => x.ShipyardId == shipyardId);

        // TODO - error if shipyard not found

        ServerLog(string.Format("Trying to host {0}({1}) on {2}({3}) for {4}", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId, player.Name), game);
        if (TryHost(game, player, ship, shipyard) == false)
        {
            ServerLogError(string.Format("Failed trying to host {0}({1}) on {2}({3}) for {4}", ship.CardName, ship.CardId, shipyard.CardName, shipyard.CardId, player.Name), game);
        }
    }
 public Operation(CardCodename codename)
     : this(codename, Guid.NewGuid().ToString())
 {
 }
Exemple #21
0
 public Operation(CardCodename codename) : this(codename, Guid.NewGuid().ToString())
 {
 }
Exemple #22
0
 public Operation(CardCodename codename, string cardId) : base(codename, cardId)
 {
     CardType      = CardType.OPERATION;
     OperationType = DetermineOperationType();
 }
Exemple #23
0
 public Strategy(CardCodename codename, string cardId) : base(codename, cardId)
 {
     CardType = CardType.STRATEGY;
 }
 public Homeworld(CardCodename codename, string cardId) : base(codename, cardId)
 {
     this.CardType = CardType.HOMEWORLD;
     MaxHealth     = DetermineMaxHealth();
     CurrentHealth = MaxHealth;
 }
 public Strategy(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     CardType = CardType.STRATEGY;
 }
 public static Card CreateCard(CardCodename cardCodename)
 {
     return(CreateCard(cardCodename, Guid.NewGuid().ToString()));
 }
Exemple #27
0
 public Ship(CardCodename codename)
     : this(codename, Guid.NewGuid().ToString())
 {
 }
 public Homeworld(CardCodename codename)
     : this(codename, Guid.NewGuid().ToString())
 {
 }
 public PlayableCard(CardCodename codename, string cardId) : base(codename, cardId)
 {
     BaseCost = DetermineBaseCost();
     Phase    = DeterminePhase();
     OnPlay  += DetermineOnPlayAction();
 }
 public UnknownCard(CardCodename codename)
     : this(codename, Guid.NewGuid().ToString())
 {
 }
 public UnknownCard(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     CardType = CardType.UNKNOWN;
 }
Exemple #32
0
 public Ship(CardCodename codename) : this(codename, Guid.NewGuid().ToString())
 {
 }
 public static Card CreateCard(CardCodename cardCodename)
 {
     return CreateCard(cardCodename, Guid.NewGuid().ToString());
 }
 public Operation(CardCodename codename, string cardId)
     : base(codename, cardId)
 {
     CardType = CardType.OPERATION;
     OperationType = DetermineOperationType();
 }
 public Homeworld(CardCodename codename) : this(codename, Guid.NewGuid().ToString())
 {
 }
Exemple #36
0
 public UnknownCard(CardCodename codename) : this(codename, Guid.NewGuid().ToString())
 {
 }
Exemple #37
0
 public UnknownCard(CardCodename codename, string cardId) : base(codename, cardId)
 {
     CardType = CardType.UNKNOWN;
 }