/// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="group">The group, in which the cards are added.</param> /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso> public void CreateCard(int[] id, ulong[] type, Group group) { Player owner = Player.Find((byte)(id[0] >> 16)); if (owner == null) { Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCard] Player not found."); return; } //var c = new Card(owner,id[0], type[0], Program.Game.Definition.CardDefinition, null, false); var c = Card.Find(id[0]); Program.TracePlayerEvent(owner, "{0} creates {1} {2} in {3}'s {4}", owner.Name, id.Length, c == null ? "card" : c.Name, group.Owner.Name, group.Name); // Ignore cards created by oneself if (owner == Player.LocalPlayer) { return; } for (int i = 0; i < id.Length; i++) { //Card c = new Card(owner, id[i], type[i], Program.Game.Definition.CardDefinition, null, false); //group.AddAt(c, group.Count); var card = new Card(owner, id[i], type[i], null, false); group.AddAt(card, group.Count); } }
/// <summary>Part of a shuffle process.</summary> /// <param name="group">The group being shuffled.</param> /// <param name="card">An array containing the CardIdentity ids to shuffle.</param> //public void Shuffle(Group group, int[] card) //{ // // Array to hold the new aliases (sent to CreateAlias) // ulong[] aliases = new ulong[card.Length]; // // Intialize the group shuffle // group.FilledShuffleSlots = 0; // group.HasReceivedFirstShuffledMessage = false; // group.MyShufflePos = new short[card.Length]; // // Check if we received enough cards // if (Player.Count - 1 <= 0) return; // if (card.Length < group.Count / (Player.Count - 1)) // Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[Shuffle] Too few cards received."); // // Do the shuffling // var rnd = new CryptoRandom(); // for (int i = card.Length - 1; i >= 0; i--) // { // int r = rnd.Next(i + 1); // int tc = card[r]; // card[r] = card[i]; // // Create a new alias, if the card is not face up // CardIdentity ci = CardIdentity.Find(tc); // if (group.FindByCardIdentity(ci) != null) // { // card[i] = tc; aliases[i] = ulong.MaxValue; // ci.Visible = true; // } // else // { // ci = new CardIdentity(ExtensionMethods.GenerateCardId()); // ci.MySecret = ci.Alias = true; // ci.Key = ((ulong)Crypto.PositiveRandom()) << 32 | (uint)tc; // card[i] = ci.Id; aliases[i] = Crypto.ModExp(ci.Key); // ci.Visible = false; // } // // Give a random position to the card // group.MyShufflePos[i] = (short)Crypto.Random(group.Count); // } // // Send the results // Program.Client.Rpc.CreateAlias(card, aliases); // Program.Client.Rpc.Shuffled(group, card, group.MyShufflePos); //} public void Shuffled(Group group, int[] card, short[] pos) { // Check the args if (card.Length != pos.Length) { Program.TraceWarning("[Shuffled] Cards and positions lengths don't match."); return; } // Insert the cards for (int j = 0; j < card.Length; j++) { // Get the wished position int i = pos[j]; // Get the card CardIdentity ci = CardIdentity.Find(card[j]); if (ci == null) { Program.TraceWarning("[Shuffled] Card not found."); continue; } // Check if the slot is free, otherwise choose the first free one //if (i >= group.Count || group[i].Type != null) i = group.FindNextFreeSlot(i); //if (i >= group.Count) continue; // Set the type //group[i].Type = ci; var mcard = group[j]; group.Remove(group[j]); group.AddAt(mcard, i); group[i].SetVisibility(ci.Visible ? DataNew.Entities.GroupVisibility.Everybody : DataNew.Entities.GroupVisibility.Nobody, null); } group.OnShuffled(); }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="group">The group, in which the cards are added.</param> /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso> public void CreateCard(int[] id, ulong[] type, Group group) { Player owner = Player.Find((byte)(id[0] >> 16)); if (owner == null) { Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCard] Player not found."); return; } // Ignore cards created by oneself if (owner == Player.LocalPlayer) { return; } for (int i = 0; i < id.Length; i++) { Card c = new Card(owner, id[i], type[i], Program.Game.Definition.CardDefinition, null, false); group.AddAt(c, group.Count); } }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. The cards may be in different groups.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="groups">An array indicating the group the cards must be loaded into.</param> /// <seealso cref="CreateCard(int[], ulong[], Group)"> for a more efficient way to insert cards inside one group.</seealso> private static void CreateCard(IList <int> id, IList <ulong> type, IList <Group> groups) { Player owner = Player.Find((byte)(id[0] >> 16)); if (owner == null) { Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCard] Player not found."); return; } // Ignore cards created by oneself if (owner == Player.LocalPlayer) { return; } for (int i = 0; i < id.Count; i++) { Card c = new Card(owner, id[i], type[i], null, false); Group group = groups[i]; group.AddAt(c, group.Count); } }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="group">The group, in which the cards are added.</param> /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso> public void CreateCard(int[] id, ulong[] type, Group group) { Player owner = Player.Find((byte)(id[0] >> 16)); if (owner == null) { Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCard] Player not found."); return; } //var c = new Card(owner,id[0], type[0], Program.Game.Definition.CardDefinition, null, false); var c = Card.Find(id[0]); Program.TracePlayerEvent(owner, "{0} creates {1} {2} in {3}'s {4}", owner.Name, id.Length, c == null ? "card" : c.Name, group.Owner.Name,group.Name); // Ignore cards created by oneself if (owner == Player.LocalPlayer) return; for (int i = 0; i < id.Length; i++) { //Card c = new Card(owner, id[i], type[i], Program.Game.Definition.CardDefinition, null, false); //group.AddAt(c, group.Count); var card = new Card(owner,id[i], type[i], null, false); group.AddAt(card, group.Count); } }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="group">The group, in which the cards are added.</param> /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso> public void CreateCard(int[] id, ulong[] type, Group group) { Player owner = Player.Find((byte)(id[0] >> 16)); if (owner == null) { Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCard] Player not found."); return; } // Ignore cards created by oneself if (owner == Player.LocalPlayer) return; for (int i = 0; i < id.Length; i++) { Card c = new Card(owner, id[i], type[i], Program.Game.Definition.CardDefinition, null, false); group.AddAt(c, group.Count); } }
//Temporarily store group visibility information for LoadDeck. //bug (google) #20 public void LoadDeck(Deck deck) { Player player = deck.IsShared ? Player.GlobalPlayer : Player.LocalPlayer; GameDef def = Program.Game.Definition; DeckDef deckDef = deck.IsShared ? def.SharedDeckDefinition : def.DeckDefinition; CardDef cardDef = def.CardDefinition; int nCards = deck.CardCount; var ids = new int[nCards]; var keys = new ulong[nCards]; var cards = new Card[nCards]; var groups = new Group[nCards]; var gtmps = new List <GrpTmp>(); //for temp groups visibility int j = 0; foreach (Deck.Section section in deck.Sections) { DeckSectionDef sectionDef = deckDef.Sections[section.Name]; if (sectionDef == null) { throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file."); } Group group = player.Groups.First(x => x.Name == sectionDef.Group); //In order to make the clients know what the card is (if visibility is set so that they can see it), //we have to set the visibility to Nobody, and then after the cards are sent, set the visibility back //to what it was. //bug (google) #20 var gt = new GrpTmp(group, group.Visibility, group.Viewers.ToList()); if (!gtmps.Contains(gt)) { gtmps.Add(gt); group.SetVisibility(false, false); } foreach (Deck.Element element in section.Cards) { CardModel mod = Database.GetCardById(element.Card.Id); for (int i = 0; i < element.Quantity; i++) { //for every card in the deck, generate a unique key for it, ID for it ulong key = ((ulong)Crypto.PositiveRandom()) << 32 | element.Card.Id.Condense(); int id = GenerateCardId(); ids[j] = id; keys[j] = Crypto.ModExp(key); groups[j] = group; var card = new Card(player, id, key, cardDef, mod, true); cards[j++] = card; group.AddAt(card, group.Count); } // Load images in the background string pictureUri = element.Card.Picture; Dispatcher.CurrentDispatcher.BeginInvoke( new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap), DispatcherPriority.ApplicationIdle, pictureUri); } } Program.Client.Rpc.LoadDeck(ids, keys, groups); //reset the visibility to what it was before pushing the deck to everybody. //bug (google) #20 foreach (GrpTmp g in gtmps) { switch (g.Visibility) { case GroupVisibility.Everybody: g.Group.SetVisibility(true, false); break; case GroupVisibility.Nobody: g.Group.SetVisibility(false, false); break; default: foreach (Player p in g.Viewers) { g.Group.AddViewer(p, false); } break; } } gtmps.Clear(); gtmps.TrimExcess(); }
public override void Do() { if (Doing != null) { Doing(this, EventArgs.Empty); } if (Card == null || Card.Group == null || To == null) { return; } base.Do(); #if (DEBUG) Debug.WriteLine("Moving " + Card.Name + " from " + From + " to " + To); #endif bool shouldSee = Card.FaceUp, shouldLog = true; var oldGroup = Card.Group; var oldIndex = Card.GetIndex(); var oldX = (int)Card.X; var oldY = (int)Card.Y; // Move the card if (Card.Group != To) { Card.Group.Remove(Card); if (Card.DeleteWhenLeavesGroup) { Card.Group = null; } //TODO Card.Delete(); else { Card.SwitchTo(Who); Card.SetFaceUp(FaceUp);//FaceUp may be false - it's one of the constructor parameters for this Card.SetOverrideGroupVisibility(false); Card.X = X; Card.Y = Y; To.AddAt(Card, Idx); Program.GameEngine.EventProxy.OnMoveCard(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y); } } else { shouldLog = false; Card.X = X; Card.Y = Y; if (To.Cards.IndexOf(Card) != Idx) { if (To.Ordered) { Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(Who), "{0} reorders {1}", Who, To); } Card.SetIndex(Idx); } Program.GameEngine.EventProxy.OnMoveCard(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y); } // Should the card be named in the log ? shouldSee |= Card.FaceUp; // Prepare the message if (shouldLog) { Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(Who), "{0} moves '{1}' to {3}{2}", Who, shouldSee ? Card.Type : (object)"Card", To, To is Pile && Idx > 0 && Idx + 1 == To.Count ? "the bottom of " : ""); } if (Done != null) { Done(this, EventArgs.Empty); } }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="group">The group, in which the cards are added.</param> /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso> public void CreateCard(int[] id, Guid[] type, string[] size, Group group) { if (Player.Find((byte)(id[0] >> 16)) == Player.LocalPlayer) return; for (int i = 0; i < id.Length; i++) { Player owner = group.Owner; if (owner == null) { Program.GameMess.Warning("[CreateCard] Player not found."); return; } //var c = new Card(owner,id[0], type[0], Program.Game.Definition.CardDefinition, null, false); var c = Card.Find(id[0]); Program.GameMess.PlayerEvent(owner, "{0} creates {1} {2} in {3}'s {4}", owner.Name, id.Length, c == null ? "card" : (object)c, group.Owner.Name, group.Name); // Ignore cards created by oneself //Card c = new Card(owner, id[i], type[i], Program.Game.Definition.CardDefinition, null, false); //group.AddAt(c, group.Count); var card = new Card(owner, id[i], Program.GameEngine.Definition.GetCardById(type[i]), false, size[i]); group.AddAt(card, group.Count); } }
public override void Do() { if (Doing != null) { Doing(this, EventArgs.Empty); } if (Card == null) { return; } if (To == null) { Log.DebugFormat("To == null {0}", Card.Id); return; } if (Card.Group == null) { Log.DebugFormat("Card.Group == null {0}", Card.Id); return; } base.Do(); #if (DEBUG) Debug.WriteLine("Moving " + Card.Name + " from " + From + " to " + To); #endif bool shouldSee = Card.FaceUp, shouldLog = true; var oldGroup = Card.Group; var oldIndex = Card.GetIndex(); var oldX = (int)Card.X; var oldY = (int)Card.Y; var oldHighlight = Card.HighlightColorString; var oldMarkers = Card.MarkersString; // Move the card if (Card.Group != To) { Card.Group.Remove(Card); if (Card.DeleteWhenLeavesGroup) { Card.Group = null; } //TODO Card.Delete(); else { Card.CardMoved = true; Card.SwitchTo(Who); Card.SetFaceUp(FaceUp);//FaceUp may be false - it's one of the constructor parameters for this Card.SetOverrideGroupVisibility(false); Card.X = X; Card.Y = Y; To.AddAt(Card, Idx); if ((oldGroup != To) || (oldX != X) || (oldY != Y)) { if (IsScriptMove) { Program.GameEngine.EventProxy.OnScriptedMoveCard_3_1_0_1(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y, IsScriptMove, oldHighlight, oldMarkers); } else { Program.GameEngine.EventProxy.OnMoveCard_3_1_0_1(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y, IsScriptMove, oldHighlight, oldMarkers); } } Program.GameEngine.EventProxy.OnMoveCard_3_1_0_0(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y, IsScriptMove); } } else { shouldLog = false; if ((Card.X != X) || (Card.Y != Y)) { Card.CardMoved = true; } Card.X = X; Card.Y = Y; if (To.Cards.IndexOf(Card) != Idx) { if (To.Ordered) { Program.GameMess.PlayerEvent(Who, "reorders {0}", To); } Card.SetIndex(Idx); } if ((oldGroup != To) || (oldX != X) || (oldY != Y)) { if (IsScriptMove) { Program.GameEngine.EventProxy.OnScriptedMoveCard_3_1_0_1(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y, IsScriptMove, oldHighlight, oldMarkers); } else { Program.GameEngine.EventProxy.OnMoveCard_3_1_0_1(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y, IsScriptMove, oldHighlight, oldMarkers); } } Program.GameEngine.EventProxy.OnMoveCard_3_1_0_0(Who, Card, oldGroup, To, oldIndex, Idx, oldX, oldY, X, Y, IsScriptMove); } // Should the card be named in the log ? shouldSee |= Card.FaceUp; // Prepare the message if (shouldLog) { Program.GameMess.PlayerEvent(Who, "moves '{0}' to {2}{1}", shouldSee ? Card.Type : (object)"Card", To, To is Pile && Idx > 0 && Idx + 1 == To.Count ? "the bottom of " : ""); } if (Done != null) { Done(this, EventArgs.Empty); } }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. All cards are created in the same group.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="group">The group, in which the cards are added.</param> /// <seealso cref="CreateCard(int[], ulong[], Group[])"> to add cards to several groups</seealso> public void CreateCard(int[] id, Guid[] type, string[] size, Group group) { if (Player.Find((byte)(id[0] >> 16)) == Player.LocalPlayer) { return; } for (int i = 0; i < id.Length; i++) { Player owner = group.Owner; if (owner == null) { Program.GameMess.Warning("[CreateCard] Player not found."); return; } //var c = new Card(owner,id[0], type[0], Program.Game.Definition.CardDefinition, null, false); var c = Card.Find(id[0]); Program.GameMess.PlayerEvent(owner, "{0} creates {1} {2} in {3}'s {4}", owner.Name, id.Length, c == null ? "card" : (object)c, group.Owner.Name, group.Name); // Ignore cards created by oneself //Card c = new Card(owner, id[i], type[i], Program.Game.Definition.CardDefinition, null, false); //group.AddAt(c, group.Count); var card = new Card(owner, id[i], Program.GameEngine.Definition.GetCardById(type[i]), false, size[i]); group.AddAt(card, group.Count); } }
/// <summary>Creates new Cards as well as the corresponding CardIdentities. The cards may be in different groups.</summary> /// <param name="id">An array with the new CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted)</param> /// <param name="groups">An array indicating the group the cards must be loaded into.</param> /// <seealso cref="CreateCard(int[], ulong[], Group)"> for a more efficient way to insert cards inside one group.</seealso> private static void CreateCard(IList <int> id, IList <Guid> type, IList <Group> groups, IList <string> sizes, string sleeveUrl = "") { // Ignore cards created by oneself if (Player.Find((byte)(id[0] >> 16)) == Player.LocalPlayer) { return; } for (int i = 0; i < id.Count; i++) { Group group = groups[i]; Player owner = group.Owner; if (owner == null) { //Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[CreateCard] Player not found."); Program.GameMess.Warning("[CreateCard] Player not found."); continue; } Card c = new Card(owner, id[i], Program.GameEngine.Definition.GetCardById(type[i]), false, sizes[i]); c.SetSleeve(sleeveUrl); group.AddAt(c, group.Count); } }
/// <summary>Part of a shuffle process.</summary> /// <param name="group">The group being shuffled.</param> /// <param name="card">An array containing the CardIdentity ids to shuffle.</param> //public void Shuffle(Group group, int[] card) //{ // // Array to hold the new aliases (sent to CreateAlias) // ulong[] aliases = new ulong[card.Length]; // // Intialize the group shuffle // group.FilledShuffleSlots = 0; // group.HasReceivedFirstShuffledMessage = false; // group.MyShufflePos = new short[card.Length]; // // Check if we received enough cards // if (Player.Count - 1 <= 0) return; // if (card.Length < group.Count / (Player.Count - 1)) // Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[Shuffle] Too few cards received."); // // Do the shuffling // var rnd = new CryptoRandom(); // for (int i = card.Length - 1; i >= 0; i--) // { // int r = rnd.Next(i + 1); // int tc = card[r]; // card[r] = card[i]; // // Create a new alias, if the card is not face up // CardIdentity ci = CardIdentity.Find(tc); // if (group.FindByCardIdentity(ci) != null) // { // card[i] = tc; aliases[i] = ulong.MaxValue; // ci.Visible = true; // } // else // { // ci = new CardIdentity(ExtensionMethods.GenerateCardId()); // ci.MySecret = ci.Alias = true; // ci.Key = ((ulong)Crypto.PositiveRandom()) << 32 | (uint)tc; // card[i] = ci.Id; aliases[i] = Crypto.ModExp(ci.Key); // ci.Visible = false; // } // // Give a random position to the card // group.MyShufflePos[i] = (short)Crypto.Random(group.Count); // } // // Send the results // Program.Client.Rpc.CreateAlias(card, aliases); // Program.Client.Rpc.Shuffled(group, card, group.MyShufflePos); //} public void Shuffled(Group group, int[] card, short[] pos) { // Check the args if (card.Length != pos.Length) { Program.TraceWarning("[Shuffled] Cards and positions lengths don't match."); return; } //Build the Dict. of new locations var shuffled = new Dictionary<int, Card>(); for (int i = 0; i < card.Length; i++) { shuffled.Add(pos[i],group[i]); // Get the card CardIdentity ci = CardIdentity.Find(card[i]); if (ci == null) { Program.TraceWarning("[Shuffled] Card not found."); continue; } group[i].SetVisibility(ci.Visible ? DataNew.Entities.GroupVisibility.Everybody : DataNew.Entities.GroupVisibility.Nobody, null); } //Move cards to their new indexes for (int i = 0; i < card.Length; i++) { group.Remove(shuffled[i]); group.AddAt(shuffled[i], i); } group.OnShuffled(); }