Beispiel #1
0
        public static AskForCardUsageResponse Parse(int id, ISkill skill, List <Card> cards, List <Player> players, int wrtPlayerId)
        {
            AskForCardUsageResponse response = new AskForCardUsageResponse();

            response.Id        = id;
            response.SkillItem = SkillItem.Parse(skill);
            if (cards == null)
            {
                response.CardItems = null;
            }
            else
            {
                response.CardItems = new List <CardItem>();
                foreach (var card in cards)
                {
                    response.CardItems.Add(CardItem.Parse(card, wrtPlayerId));
                }
            }
            if (players == null)
            {
                response.PlayerItems = null;
            }
            else
            {
                response.PlayerItems = new List <PlayerItem>();
                foreach (var player in players)
                {
                    response.PlayerItems.Add(PlayerItem.Parse(player));
                }
            }
            return(response);
        }
Beispiel #2
0
        public static AskForCardChoiceResponse Parse(int id, List <List <Card> > cards, int optionId, int wrtPlayerId)
        {
            AskForCardChoiceResponse response = new AskForCardChoiceResponse();

            response.Id = id;
            if (cards == null)
            {
                response.CardItems = null;
            }
            else
            {
                var cardItems = new List <List <CardItem> >();
                foreach (var cardDeck in cards)
                {
                    Trace.Assert(cardDeck != null);
                    if (cardDeck == null)
                    {
                        continue;
                    }
                    var items = new List <CardItem>();
                    foreach (var card in cardDeck)
                    {
                        items.Add(CardItem.Parse(card, wrtPlayerId));
                    }
                    cardItems.Add(items);
                }
                response.CardItems = NestedCardList.Parse(cardItems);
            }
            response.OptionId = optionId;
            return(response);
        }
Beispiel #3
0
        public static CardItem Parse(Card card, int wrtPlayerId)
        {
            if (card == null)
            {
                return(null);
            }
            var item = new CardItem()
            {
                DeckPlaceItem = DeckPlaceItem.Parse(card.Place),
                PlaceInDeck   = Game.CurrentGame.Decks[card.Place].IndexOf(card)
            };

            if (card.Place.Player != null && card.Place.DeckType == DeckType.Hand &&
                wrtPlayerId >= 0 && wrtPlayerId < Game.CurrentGame.Players.Count &&
                Game.CurrentGame.HandCardVisibility[Game.CurrentGame.Players[wrtPlayerId]].Contains(card.Place.Player))
            {
                item.CardId = card.Id;
                return(item);
            }
            else
            {
                if (card.RevealOnce)
                {
                    item.CardId     = card.Id;
                    card.RevealOnce = false;
                }
                else
                {
                    item.CardId = -1;
                }
                return(item);
            }
        }
Beispiel #4
0
 public static Card DecodeForClient(CardItem i, int wrt)
 {
     // you know this hand card. therefore the deserialization look up this card in particular
     if (i.playerId >= 0 && i.deck == DeckType.Hand && Game.CurrentGame.HandCardVisibility[Game.CurrentGame.Players[wrt]].Contains(Game.CurrentGame.Players[i.playerId]))
     {
         foreach (Card c in Game.CurrentGame.Decks[Game.CurrentGame.Players[i.playerId], i.deck])
         {
             if (c.Id == i.Id)
             {
                 return c;
             }
         }
         Trace.Assert(false);
     }
     if (i.Id >= 0)
     {
         Trace.TraceInformation("Identify {0}{1}{2} is {3}{4}{5}", i.playerId, i.deck, i.place, i.suit, i.rank, i.type);
         Card gameCard;
         if (i.playerId < 0)
         {
             gameCard = Game.CurrentGame.Decks[null, i.deck][i.place];
         }
         else
         {
             gameCard = Game.CurrentGame.Decks[Game.CurrentGame.Players[i.playerId], i.deck][i.place];
         }
         var place = gameCard.Place;
         gameCard.CopyFrom(GameEngine.CardSet[i.Id]);
         gameCard.Place = place;
         gameCard.Rank = i.rank;
         gameCard.Suit = (SuitType)i.suit;
         if (i.type != null) gameCard.Type = Translator.TranslateCardType(i.type, i.typeHorseName);
     }
     Card ret;
     if (i.playerId < 0)
     {
         ret = Game.CurrentGame.Decks[null, i.deck][i.place];
     }
     else
     {
         ret = Game.CurrentGame.Decks[Game.CurrentGame.Players[i.playerId], i.deck][i.place];
     }
     return ret;
 }
Beispiel #5
0
        public static CardItem TranslateForServer(Card card, int wrt)
        {
            CardItem item = new CardItem();
            item.playerId = Game.CurrentGame.Players.IndexOf(card.Place.Player);
            item.deck = card.Place.DeckType;
            item.place = Game.CurrentGame.Decks[card.Place.Player, card.Place.DeckType].IndexOf(card);
            Translator.TranslateCardType(ref item.type, ref item.typeHorseName, card.Type);
            Trace.Assert(item.place >= 0);
            item.rank = card.Rank;
            item.suit = (int)card.Suit;
            item.Id = card.Id;

            // this is a card that the client knows. keep the id anyway
            if (card.Place.Player != null && item.deck == DeckType.Hand && Game.CurrentGame.HandCardVisibility[Game.CurrentGame.Players[wrt]].Contains(card.Place.Player))
            {
                card.RevealOnce = false;
            }
            else
            {
                if (!card.RevealOnce)
                {
                    item.Id = -1;
                }
                card.RevealOnce = false;
            }
            return item;
        }
Beispiel #6
0
 public static CardItem TranslateForClient(Card card)
 {
     CardItem item = new CardItem();
     item.playerId = Game.CurrentGame.Players.IndexOf(card.Place.Player);
     item.deck = card.Place.DeckType;
     item.place = Game.CurrentGame.Decks[card.Place.Player, card.Place.DeckType].IndexOf(card);
     Translator.TranslateCardType(ref item.type, ref item.typeHorseName, card.Type);
     Trace.Assert(item.place >= 0);
     item.rank = card.Rank;
     item.suit = (int)card.Suit;
     item.Id = card.Id;
     return item;
 }
Beispiel #7
0
 public static Card DecodeForServer(CardItem i, int wrt)
 {
     // you know this hand card. therefore the deserialization look up this card in particular
     if (i.playerId >= 0 && i.deck == DeckType.Hand && Game.CurrentGame.HandCardVisibility[Game.CurrentGame.Players[wrt]].Contains(Game.CurrentGame.Players[i.playerId]))
     {
         foreach (Card c in Game.CurrentGame.Decks[Game.CurrentGame.Players[i.playerId], i.deck])
         {
             if (c.Id == i.Id)
             {
                 return c;
             }
         }
         Trace.Assert(false);
     }
     Card ret;
     if (i.playerId < 0)
     {
         ret = Game.CurrentGame.Decks[null, i.deck][i.place];
     }
     else
     {
         ret = Game.CurrentGame.Decks[Game.CurrentGame.Players[i.playerId], i.deck][i.place];
     }
     return ret;
 }
Beispiel #8
0
 public object Receive()
 {
     object o = null;
     ItemType type = ItemType.Serializable;
     try
     {
         type = (ItemType)deserializer.DeserializeInt();
         Trace.TraceInformation("Trying to parse a {0}", type);
         switch (type)
         {
             case ItemType.CardItem:
                 var cardItem = new CardItem();
                 cardItem.playerId = deserializer.DeserializeInt();
                 cardItem.place = deserializer.DeserializeInt();
                 cardItem.rank = deserializer.DeserializeInt();
                 cardItem.suit = deserializer.DeserializeInt();
                 cardItem.id = deserializer.DeserializeInt();
                 cardItem.deckName = deserializer.DeserializeString();
                 cardItem.typeName = deserializer.DeserializeString();
                 cardItem.typeHorseName = deserializer.DeserializeString();
                 o = cardItem;
                 break;
             case ItemType.Player:
                 int? id = deserializer.DeserializeNInt();
                 o = (id == null ? null : Game.CurrentGame.Players[(int)id]);
                 break;
             case ItemType.Int:
                 o = deserializer.DeserializeInt();
                 break;
             case ItemType.SkillItem:
                 var skillItem = new SkillItem();
                 skillItem.playerId = deserializer.DeserializeInt();
                 skillItem.skillId = deserializer.DeserializeInt();
                 skillItem.name = deserializer.DeserializeString();
                 skillItem.additionalTypeName = deserializer.DeserializeString();
                 skillItem.additionalTypeHorseName = deserializer.DeserializeString();
                 o = skillItem;
                 break;
             case ItemType.CommandItem:
                 CommandItem item = new CommandItem();
                 item.command = (Command)deserializer.DeserializeInt();
                 item.type = (ItemType)deserializer.DeserializeInt();
                 if (item.type == ItemType.Int)
                     item.data = deserializer.DeserializeInt();
                 else if (item.type == ItemType.HandCardMovement)
                     item.data = deserializer.Deserialize(typeof(HandCardMovement));
                 else if (item.type == ItemType.CardRearrangement)
                     item.data = deserializer.Deserialize(typeof(CardRearrangement));
                 else if (item.type == ItemType.CardUsageResponded)
                     item.data = deserializer.Deserialize(typeof(CardUsageResponded));
                 o = item;
                 break;
             case ItemType.ValueType:
                 Type objectType = Type.GetType(deserializer.DeserializeString());
                 o = deserializer.Deserialize(objectType);
                 break;
             case ItemType.Serializable:
                 o = formatter.Deserialize(stream);
                 break;
             default:
                 o = null;
                 Trace.TraceError("Unknown item type: {0}", type);
                 break;
         }
     }
     catch (Exception e)
     {
         Trace.TraceError("Error occured when trying to deserialize an {0}, {1}. ", type, e.StackTrace);
         return null;
     }
     return o;
 }
Beispiel #9
0
 public static CardItem Parse(Card card, int wrtPlayerId)
 {
     if (card == null) return null;
     var item = new CardItem()
     {
         DeckPlaceItem = DeckPlaceItem.Parse(card.Place),
         PlaceInDeck = Game.CurrentGame.Decks[card.Place].IndexOf(card)
     };
     if (card.Place.Player != null && card.Place.DeckType == DeckType.Hand &&
         wrtPlayerId >= 0 && wrtPlayerId < Game.CurrentGame.Players.Count &&
         Game.CurrentGame.HandCardVisibility[Game.CurrentGame.Players[wrtPlayerId]].Contains(card.Place.Player))
     {
         item.CardId = card.Id;
         return item;
     }
     else
     {
         if (card.RevealOnce)
         {
             item.CardId = card.Id;
             card.RevealOnce = false;
         }
         else { item.CardId = -1; }
         return item;
     }
 }
Beispiel #10
0
 private void QueueCard(CardItem card)
 {
     serializer.Serialize(ItemType.CardItem);
     serializer.Serialize(card.playerId);
     serializer.Serialize(card.place);
     serializer.Serialize(card.rank);
     serializer.Serialize(card.suit);
     serializer.Serialize(card.id);
     serializer.Serialize(card.deckName ?? string.Empty);
     serializer.Serialize(card.typeName ?? string.Empty);
     serializer.Serialize(card.typeHorseName ?? string.Empty);
 }
Beispiel #11
0
 private void QueueCard(CardItem card)
 {
     formatter.Serialize(stream, card);
 }
Beispiel #12
0
 public static CardItem EncodeCard(Card card)
 {
     CardItem item = new CardItem();
     item.playerId = Game.CurrentGame.Players.IndexOf(card.Place.Player);
     item.deckName = card.Place.DeckType.Name;
     item.place = Game.CurrentGame.Decks[card.Place.Player, card.Place.DeckType].IndexOf(card);
     Translator.EncodeCardHandler(card.Type, out item.typeName, out item.typeHorseName);
     Trace.Assert(item.place >= 0);
     item.rank = card.Rank;
     item.suit = (int)card.Suit;
     item.id = card.Id;
     return item;
 }