/// <summary>Reveal a card's identity to one player only.</summary> /// <param name="players"> </param> /// <param name="card">The card, whose identity is revealed.</param> /// <param name="encrypted">Either a ulong[2] containing an encrypted aliased CardIdentity id. Or a ulong[5] containing an encrypted CardModel guid.</param> public void RevealTo(Player[] players, Card card, ulong[] encrypted) { var oldType = card.Type; ulong alias = 0; Guid id = Guid.Empty; players = players.Where(x => x != null).ToArray(); switch (encrypted.Length) { case 2: alias = Crypto.Decrypt(encrypted); break; case 5: id = Crypto.DecryptGuid(encrypted); break; default: Program.TraceWarning("[RevealTo] Invalid data received."); return; } if (!players.All(p => (card.Group.Visibility == DataNew.Entities.GroupVisibility.Custom && card.Group.Viewers.Contains(p)) || card.PlayersLooking.Contains(p) || card.PeekingPlayers.Contains(p))) Program.TraceWarning("[RevealTo] Revealing a card to a player, who isn't allowed to see it. This indicates a bug or cheating."); // If it's an alias, we must revealed it to the final recipient bool sendToMyself = true; if (alias != 0) { sendToMyself = false; CardIdentity ci = CardIdentity.Find((int)alias); if (ci == null) { Program.TraceWarning("[RevealTo] Identity not found."); return; } // If the revealed type is an alias, pass it to the one who owns it to continue the RevealTo chain. if (ci.Alias) { Player p = Player.Find((byte)(ci.Key >> 16)); Program.Client.Rpc.RevealToReq(p, players, card, Crypto.Encrypt(ci.Key, p.PublicKey)); } // Else revealed the card model to the ones, who must see it else { Player[] pArray = new Player[1]; foreach (Player p in players) if (p != Player.LocalPlayer) { pArray[0] = p; Program.Client.Rpc.RevealToReq(p, pArray, card, Crypto.Encrypt(ci.Model.Id, p.PublicKey)); } else { sendToMyself = true; id = ci.Model.Id; } } } // Else it's a type and we are the final recipients if (!sendToMyself) return; if (card.Type.Model == null) card.SetModel(Program.GameEngine.Definition.GetCardById(id)); // Raise a notification oldType.OnRevealed(card.Type); }