public CompState CompressState() { CompState sendState = new CompState { P1 = instance.playerOne.IdUser, P2 = instance.playerTwo.IdUser, P1Lp = instance.playerOneLifePoints, P2Lp = instance.playerTwoLifePoints, PlayerCrystals = instance.playerCrystals, PlayerGems = instance.playerGems, GoesFirst = instance.firstMovePl, OnMove = instance.plOnMove, P1Hand = new List <int>(), P2Hand = new List <int>(), P1Table = new List <CompCard>(), P2Table = new List <CompCard>(), }; foreach (Card card in instance.playerOneHand) { sendState.P1Hand.Add(card.IdCard); } foreach (Card card in instance.playerTwoHand) { sendState.P2Hand.Add(card.IdCard); } foreach (Card card in instance.playerOneTable) { sendState.P1Table.Add(new CompCard(card.IdCard, card.Name, card.Attack, card.Health, card.Shield)); } foreach (Card card in instance.playerTwoTable) { sendState.P2Table.Add(new CompCard(card.IdCard, card.Name, card.Attack, card.Health, card.Shield)); } return(sendState); }
public void UncompressState(CompState state, Dictionary <int, Card> myDeck, Dictionary <int, Card> oponentDeck, User me, User oponent) { instance.playerOneLifePoints = state.P1Lp; instance.playerTwoLifePoints = state.P2Lp; instance.playerCrystals = state.PlayerCrystals; instance.playerGems = state.PlayerGems; instance.firstMovePl = state.GoesFirst; instance.plOnMove = state.OnMove; if (state.P1 == me.IdUser) { instance.playerOne = me; foreach (int cardId in state.P1Hand) { Card value; myDeck.TryGetValue(cardId, out value); instance.playerOneHand.Add(value); } instance.playerTwo = oponent; foreach (CompCard card in state.P1Table) { Card value; myDeck.TryGetValue(card.IdCard, out value); value.Attack = card.Attack; value.Health = card.Health; value.Shield = card.Shield; instance.playerOneHand.Add(value); } foreach (CompCard card in state.P2Table) { Card value; oponentDeck.TryGetValue(card.IdCard, out value); value.Attack = card.Attack; value.Health = card.Health; value.Shield = card.Shield; instance.playerTwoHand.Add(value); } } else { instance.playerTwo = me; foreach (int cardId in state.P2Hand) { Card value; myDeck.TryGetValue(cardId, out value); instance.playerTwoHand.Add(value); } instance.playerOne = oponent; foreach (CompCard card in state.P1Table) { Card value; oponentDeck.TryGetValue(card.IdCard, out value); value.Attack = card.Attack; value.Health = card.Health; value.Shield = card.Shield; instance.playerOneHand.Add(value); } foreach (CompCard card in state.P2Table) { Card value; myDeck.TryGetValue(card.IdCard, out value); value.Attack = card.Attack; value.Health = card.Health; value.Shield = card.Shield; instance.playerTwoHand.Add(value); } } }