public void FreezeCardsVisibility(Group group) { foreach (var c in group.Cards) { c.SetOverrideGroupVisibility(true); } }
public void LookAtBottom(Player player, int uid, Group group, int count, bool look) { if (look) { var skipCount = Math.Max(0, group.Count - count); var cards = group.Skip(skipCount); foreach (var c in cards) { c.PlayersLooking.Add(player); } group.LookedAt.Add(uid, cards.ToList()); Program.GameMess.PlayerEvent(player, "looks at {0} bottom {1} cards.", group, count); } else { if (!group.LookedAt.ContainsKey(uid)) { Program.GameMess.Warning("[LookAtTop] Protocol violation: unknown unique id received."); return; } foreach (var c in group.LookedAt[uid]) { c.PlayersLooking.Remove(player); } Program.GameMess.PlayerEvent(player, "stops looking at {0} bottom {1} cards.", group, count); group.LookedAt.Remove(uid); } }
public void LookAt(Player player, int uid, Group group, bool look) { if (look) { if (group.Visibility != DataNew.Entities.GroupVisibility.Everybody) { foreach (var c in group) { c.PlayersLooking.Add(player); } } group.LookedAt.Add(uid, group.ToList()); Program.GameMess.PlayerEvent(player, "looks at {0}.", group); } else { if (!group.LookedAt.ContainsKey(uid)) { Program.GameMess.Warning("[LookAtTop] Protocol violation: unknown unique id received."); return; } if (group.Visibility != DataNew.Entities.GroupVisibility.Everybody) { foreach (var c in group.LookedAt[uid]) { c.PlayersLooking.Remove(player); } } group.LookedAt.Remove(uid); Program.GameMess.PlayerEvent(player, "stops looking at {0}.", group); } }
public void LookAtTop(Player player, int uid, Group group, int count, bool look) { WriteReplayAction(player.Id); if (look) { var cards = group.Take(count); foreach (var c in cards) { c.PlayersLooking.Add(player); } group.LookedAt.Add(uid, cards.ToList()); Program.GameMess.PlayerEvent(player, "looks at {0} top {1} cards.", group, count); } else { if (!group.LookedAt.ContainsKey(uid)) { Program.GameMess.Warning("[LookAtTop] Protocol violation: unknown unique id received."); return; } foreach (var c in group.LookedAt[uid]) { c.PlayersLooking.Remove(player); } Program.GameMess.PlayerEvent(player, "stops looking at {0} top {1} cards.", group, count); group.LookedAt.Remove(uid); } }
public string GroupGetVisibility(int id) { Group g = Group.Find(id); DataNew.Entities.GroupVisibility vis = g.Visibility; switch (vis) { case DataNew.Entities.GroupVisibility.Everybody: return("all"); case DataNew.Entities.GroupVisibility.Nobody: return("none"); case DataNew.Entities.GroupVisibility.Owner: return("me"); case DataNew.Entities.GroupVisibility.Undefined: return("undefined"); case DataNew.Entities.GroupVisibility.Custom: if (g.Viewers.Count == 1 && g.Viewers[0] == g.Controller) { return("me"); } else { return("custom"); } default: throw new ArgumentOutOfRangeException(); } }
/// <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) { var who = Player.Find((byte)(id[0] >> 16)); WriteReplayAction(who.Id); if (IsLocalPlayer(who)) { return; } for (var i = 0; i < id.Length; i++) { var owner = group.Owner; if (owner == null) { Program.GameMess.Warning("[CreateCard] Player not found."); return; } 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 var card = new Card(owner, id[i], Program.GameEngine.Definition.GetCardById(type[i]), false, size[i]); group.AddAt(card, group.Count); } }
public void CardMoveTo(int cardId, int groupId, int?position) { Card card = Card.Find(cardId); Group group = Group.Find(groupId); if (card.Controller != Player.LocalPlayer) { Program.GameMess.Warning(String.Format("{0} Can't move {1} to {2} because they don't control {1}.", Player.LocalPlayer.Name, card.Name, card.Name)); } if (group.Controller != Player.LocalPlayer) { Program.GameMess.Warning(String.Format("{0} Can't move {1} to {2} because they don't control {1}.", Player.LocalPlayer.Name, card.Name, group.Name)); } if (card.Group != Program.GameEngine.Table && card.Group.Controller != Player.LocalPlayer) { Program.GameMess.Warning(String.Format("{0} Can't move {1} from {2} because they don't control it.", Player.LocalPlayer.Name, card, card.Group)); } QueueAction(() => { //Program.GameEngine.EventProxy.MuteEvents = true; if (position == null) { card.MoveTo(group, true, true); } else { card.MoveTo(group, true, position.Value, true); } //Program.GameEngine.EventProxy.MuteEvents = false; }); }
public void Shuffled(Player player, Group group, int[] card, short[] pos) { if (player == Player.LocalPlayer) { return; } ((Pile)group).DoShuffle(card, pos); }
public void FreezeCardsVisibility(Group group) { WriteReplayAction(); foreach (var c in group.Cards) { c.SetOverrideGroupVisibility(true); } }
public void GroupVisAdd(Player player, Group group, Player whom) { // Ignore messages sent by myself if (player != Player.LocalPlayer) { group.AddViewer(whom, false); } Program.GameMess.PlayerEvent(player, "shows {0} to {1}.", group, whom); }
public void GroupVisRemove(Player player, Group group, Player whom) { // Ignore messages sent by myself if (player != Player.LocalPlayer) { group.RemoveViewer(whom, false); } Program.GameMess.PlayerEvent(player, "hides {0} from {1}.", group, whom); }
public void Shuffled(Player player, Group group, int[] card, short[] pos) { WriteReplayAction(player.Id); if (IsLocalPlayer(player)) { return; } ((Pile)group).DoShuffle(card, pos); }
public int GroupCard(int id, int index) { var c = Group.Find(id)[index]; if (c == null) { return(-1); } return(c.Id); }
public void MoveCard(Player player, int[] card, Group to, int[] idx, bool[] faceUp, bool isScriptMove) { // Ignore cards moved by the local player (already done, for responsiveness) var cards = card.Select(Card.Find).Where(x => x != null).ToArray(); if (player != Player.LocalPlayer) { new MoveCards(player, cards, to, idx, faceUp, isScriptMove).Do(); } }
public void GroupVisRemove(Player player, Group group, Player whom) { WriteReplayAction(player.Id); // Ignore messages sent by myself if (!IsLocalPlayer(player)) { group.RemoveViewer(whom, false); } Program.GameMess.PlayerEvent(player, "hides {0} from {1}.", group, whom); }
public void GroupVisAdd(Player player, Group group, Player whom) { WriteReplayAction(player.Id); // Ignore messages sent by myself if (!IsLocalPlayer(player)) { group.AddViewer(whom, false); } Program.GameMess.PlayerEvent(player, "shows {0} to {1}.", group, whom); }
public void GroupShuffle(int id) { var pile = (Pile)Group.Find(id); if (pile.Controller != Player.LocalPlayer) { Program.GameMess.Warning(String.Format("{0} Can't shuffle {1} because they don't control it.", Player.LocalPlayer.Name, pile.Name)); } QueueAction(() => pile.Shuffle()); }
public bool GroupGetCollapsed(int id) { var g = Group.Find(id); if (!(g is Pile)) { return(false); } Pile pile = (Pile)g; return(pile.ViewState == GroupViewState.Collapsed); }
public void GroupSetCollapsed(int id, bool value) { var g = Group.Find(id); if (!(g is Pile)) { return; } Pile pile = (Pile)g; QueueAction(() => pile.ViewState = (value == true) ? GroupViewState.Collapsed : GroupViewState.Pile); }
public void GroupSetCollapsed(int id, bool value) { var g = Group.Find(id); if (!(g is Pile)) { return; } Pile pile = (Pile)g; QueueAction(() => pile.Collapsed = value); }
public void GroupVis(Player player, Group group, bool defined, bool visible) { // Ignore messages sent by myself if (player != Player.LocalPlayer) { group.SetVisibility(defined ? (bool?)visible : null, false); } if (defined) { Program.GameMess.PlayerEvent(player, visible ? "shows {0} to everybody." : "shows {0} to nobody.", group); } }
public void GroupLookAt(int id, int value, bool isTop) { var g = (Pile)Group.Find(id); if (g.Controller != Player.LocalPlayer) { Program.GameMess.Warning(String.Format("{0} can't look at {1} because they don't control it.", Player.LocalPlayer.Name, g.Name)); } PlayWindow playWindow = WindowManager.PlayWindow; if (playWindow == null) { return; } Octgn.Controls.ChildWindowManager manager = playWindow.wndManager; if (value > 0) { if (isTop) { QueueAction(() => manager.Show(new GroupWindow(@g, PilePosition.Top, value))); } else { QueueAction(() => manager.Show(new GroupWindow(@g, PilePosition.Bottom, value))); } } else if (value == 0) { int count; if (isTop) { count = QueueAction <int>(() => Dialog.InputPositiveInt("View top cards", "How many cards do you want to see?", 1)); QueueAction(() => manager.Show(new GroupWindow(@g, PilePosition.Top, count))); } else { count = QueueAction <int>(() => Dialog.InputPositiveInt("View bottom cards", "How many cards do you want to see?", 1)); QueueAction(() => manager.Show(new GroupWindow(@g, PilePosition.Bottom, count))); } } else { QueueAction(() => manager.Show(new GroupWindow(@g, PilePosition.All, 0))); } }
public void GroupRemoveViewer(int id, int pid) { Group group = Group.Find(id); Player player = Player.Find((byte)pid); if (group.Controller != Player.LocalPlayer) { Program.GameMess.Warning("{0} can't set visibility on {0} because they don't control it.", Player.LocalPlayer.Name, group.Name); return; } if (!group.Viewers.Contains(player)) { return; } else { QueueAction(() => group.RemoveViewer(player, true)); } }
public void GroupSetController(int id, int player) { var g = Group.Find(id); var p = Player.Find((byte)player); if (p == Player.LocalPlayer) { if (g.Controller == Player.LocalPlayer) { return; } QueueAction(() => g.TakeControl()); } else { if (g.Controller != Player.LocalPlayer) { return; } QueueAction(() => g.PassControlTo(p)); } }
public void GroupSetVisibility(int id, string v) { Group group = Group.Find(id); if (group.Controller != Player.LocalPlayer) { Program.GameMess.Warning("{0} can't set visibility on {0} because they don't control it.", Player.LocalPlayer.Name, group.Name); return; } QueueAction( () => { switch (v.ToLower()) { case "none": group.SetVisibility(false, true); return; case "all": group.SetVisibility(true, true); return; case "undefined": group.SetVisibility(null, true); return; case "me": group.SetVisibility(false, true); group.AddViewer(Player.LocalPlayer, true); return; default: Program.GameMess.Warning("Invalid visibility type '{0}'", v); return; } }); }
/// <summary>Loads a player deck.</summary> /// <param name="id">An array containing the loaded CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted).</param> /// <param name="group">An array indicating the group the cards must be loaded into.</param> public void LoadDeck(int[] id, ulong[] type, Group[] group) { if (id.Length != type.Length || id.Length != group.Length) { //Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[LoadDeck] Protocol violation: inconsistent arrays sizes."); Program.GameMess.Warning("[LoadDeck] Protocol violation: inconsistent arrays sizes."); return; } if (id.Length == 0) return; // Loading an empty deck --> do nothing Player who = Player.Find((byte)(id[0] >> 16)); if (who == null) { //Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[LoadDeck] Player not found."); Program.GameMess.Warning("[LoadDeck] Player not found."); return; } Program.GameMess.System("{0} loads a deck", who); CreateCard(id, type, group); Log.Info("LoadDeck Starting Task to Fire Event"); Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_0(who, @group.Distinct().ToArray()); Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_1(who, @group.Distinct().ToArray()); //Task.Factory.StartNew(() => //{ // Log.Info("LoadDeck Factory Started to Fire Event"); // Thread.Sleep(1000); // Log.Info("LoadDeck Firing Event"); // try // { // //Program.Dispatcher.Invoke(new Action(() => Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_0(who, @group.Distinct().ToArray()))); // //Program.Dispatcher.Invoke(new Action(() => Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_1(who, @group.Distinct().ToArray()))); // Log.Info("LoadDeck Finished firing event."); // } // catch (Exception e) // { // Log.Error("LoadDeck Error Firing Event", e); // } //}); }
public void UnaliasGrpDeprecated(Group arg0) { Program.GameMess.Warning("[" + MethodInfo.GetCurrentMethod().Name + "] is deprecated"); }
public void LookAtBottom(Player player, int uid, Group group, int count, bool look) { if (look) { int skipCount = Math.Max(0, group.Count - count); var cards = group.Skip(skipCount); foreach (Card c in cards) { c.PlayersLooking.Add(player); } group.LookedAt.Add(uid, cards.ToList()); Program.GameMess.PlayerEvent(player, "looks at {0} bottom {1} cards.", group, count); } else { if (!group.LookedAt.ContainsKey(uid)) { Program.GameMess.Warning("[LookAtTop] Protocol violation: unknown unique id received."); return; } foreach (Card c in group.LookedAt[uid]) c.PlayersLooking.Remove(player); Program.GameMess.PlayerEvent(player, "stops looking at {0} bottom {1} cards.", group, count); group.LookedAt.Remove(uid); } }
//Temporarily store group visibility information for LoadDeck. //bug (google) #20 public void LoadDeck(IDeck deck, bool limited) { var def = Program.GameEngine.Definition; int nCards = deck.CardCount(); var ids = new int[nCards]; var keys = new Guid[nCards]; var cards = new Card[nCards]; var groups = new Play.Group[nCards]; var sizes = new string[nCards]; var gtmps = new List <GrpTmp>(); //for temp groups visibility int j = 0; foreach (var section in deck.Sections) { { // Add cards to LoadedCards deck if (!LoadedCards.Sections.Any(x => x.Name == section.Name)) { // Add section ((ObservableCollection <ObservableSection>)LoadedCards.Sections).Add(new ObservableSection() { Name = section.Name, Shared = section.Shared, Cards = new ObservableCollection <ObservableMultiCard>() }); } var loadedCardsSection = LoadedCards.Sections.Single(x => x.Name == section.Name); foreach (var card in section.Cards) { var existingCard = loadedCardsSection.Cards.FirstOrDefault(x => x.Id == card.Id); if (existingCard != null) { existingCard.Quantity += card.Quantity; } else { var newCard = new ObservableMultiCard(card); loadedCardsSection.Cards.AddCard(newCard); } } } DeckSection sectionDef = null; sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name]; if (sectionDef == null) { throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file."); } var player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer; Play.Group group = player.Groups.First(x => x.Name == sectionDef.Group.Name); //TODO: match directly to SectionDef Group instead of name matching //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 (IMultiCard element in section.Cards) { //DataNew.Entities.Card mod = Definition.GetCardById(element.Id); for (int i = 0; i < element.Quantity; i++) { //for every card in the deck, generate a unique key for it, ID for it var id = element.GenerateCardId(); var card = new Card(player, id, new DataNew.Entities.Card(element), true, element.Size.Name); // var card = element.ToPlayCard(player); ids[j] = card.Id; keys[j] = card.Type.Model.Id; //keys[j] = card.GetEncryptedKey(); groups[j] = group; sizes[j] = card.Size.Name; cards[j++] = card; group.AddAt(card, group.Count); DeckStats.AddCard(card); } // Load images in the background string pictureUri = element.GetPicture(); Dispatcher.CurrentDispatcher.BeginInvoke( new Func <string, BitmapImage>(ImageUtils.CreateFrozenBitmap), DispatcherPriority.Background, pictureUri); } } string sleeveString = null; if (deck.Sleeve != null) { try { var loadSleeve = true; if (!IsLocal) { var isSubscriber = SubscriptionModule.Get().IsSubscribed; if (isSubscriber == null) { loadSleeve = false; Log.Warn("Can't set deck sleeve, unable to determin if user is a subscriber."); Program.GameMess.Warning($"Deck sleeve can not be loaded, subscriber status is unknown."); } else if (isSubscriber == false) { loadSleeve = false; Log.Warn("Not authorized to use deck sleeve."); Program.GameMess.Warning($"Deck sleeve can not be used, you're not a subscriber."); } } if (loadSleeve) { Player.LocalPlayer.SetSleeve(deck.Sleeve); sleeveString = Sleeve.ToString(deck.Sleeve); } else { Log.Info("Sleeve will not be loaded."); } } catch (Exception ex) { Log.Warn(ex.Message, ex); Program.GameMess.Warning($"There was an error loading the decks sleeve."); } } Program.Client.Rpc.LoadDeck(ids, keys, groups, sizes, sleeveString ?? string.Empty, limited); //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 void ShuffleDeprecated(Group arg0, int[] ints) { Program.GameMess.Warning("[" + MethodInfo.GetCurrentMethod().Name + "] is deprecated"); }
public GrpTmp(Play.Group g, GroupVisibility vis, List <Play.Player> v) { Group = g; Visibility = vis; Viewers = v; }
public void FreezeCardsVisibility(Group group) { foreach (Card c in group.Cards) c.SetOverrideGroupVisibility(true); }
/// <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) { 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], type[i], null, false); group.AddAt(card, group.Count); } }
public void LookAt(Player player, int uid, Group group, bool look) { if (look) { if (group.Visibility != DataNew.Entities.GroupVisibility.Everybody) foreach (Card c in group) { c.PlayersLooking.Add(player); c.RevealTo(Enumerable.Repeat(player, 1)); } group.LookedAt.Add(uid, group.ToList()); Program.GameMess.PlayerEvent(player, "looks at {0}.", group); } else { if (!group.LookedAt.ContainsKey(uid)) { Program.GameMess.Warning("[LookAtTop] Protocol violation: unknown unique id received."); return; } if (group.Visibility != DataNew.Entities.GroupVisibility.Everybody) { foreach (Card c in group.LookedAt[uid]) c.PlayersLooking.Remove(player); } group.LookedAt.Remove(uid); Program.GameMess.PlayerEvent(player, "stops looking at {0}.", group); } }
/// <summary>Loads a player deck.</summary> /// <param name="id">An array containing the loaded CardIdentity ids.</param> /// <param name="type">An array containing the corresponding CardModel guids (encrypted).</param> /// <param name="group">An array indicating the group the cards must be loaded into.</param> public void LoadDeck(int[] id, ulong[] type, Group[] group, string sleeve) { if (id.Length != type.Length || id.Length != group.Length) { //Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[LoadDeck] Protocol violation: inconsistent arrays sizes."); Program.GameMess.Warning("[LoadDeck] Protocol violation: inconsistent arrays sizes."); return; } if (id.Length == 0) return; // Loading an empty deck --> do nothing Player who = Player.Find((byte)(id[0] >> 16)); if (who == null) { //Program.Trace.TraceEvent(TraceEventType.Warning, EventIds.Event, "[LoadDeck] Player not found."); Program.GameMess.Warning("[LoadDeck] Player not found."); return; } Program.GameMess.System("{0} loads a deck", who); CreateCard(id, type, group, sleeve); Log.Info("LoadDeck Starting Task to Fire Event"); Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_0(who, @group.Distinct().ToArray()); Program.GameEngine.EventProxy.OnLoadDeck_3_1_0_1(who, @group.Distinct().ToArray()); }
public void GroupVisRemove(Player player, Group group, Player whom) { // Ignore messages sent by myself if (player != Player.LocalPlayer) group.RemoveViewer(whom, false); Program.GameMess.PlayerEvent(player, "hides {0} from {1}.", group, whom); }
public void GroupVisAdd(Player player, Group group, Player whom) { // Ignore messages sent by myself if (player != Player.LocalPlayer) group.AddViewer(whom, false); Program.GameMess.PlayerEvent(player, "shows {0} to {1}.", group, whom); }
public void GroupVis(Player player, Group group, bool defined, bool visible) { // Ignore messages sent by myself if (player != Player.LocalPlayer) group.SetVisibility(defined ? (bool?)visible : null, false); if (defined) Program.GameMess.PlayerEvent(player, visible ? "shows {0} to everybody." : "shows {0} to nobody.", group); }
public void LookAtTop(Player player, int uid, Group group, int count, bool look) { if (look) { var cards = group.Take(count); foreach (Card c in cards) { c.PlayersLooking.Add(player); c.RevealTo(Enumerable.Repeat(player, 1)); } group.LookedAt.Add(uid, cards.ToList()); Program.GameMess.PlayerEvent(player, "looks at {0} top {1} cards.", group, count); } else { if (!group.LookedAt.ContainsKey(uid)) { Program.GameMess.Warning("[LookAtTop] Protocol violation: unknown unique id received."); return; } foreach (Card c in group.LookedAt[uid]) c.PlayersLooking.Remove(player); Program.GameMess.PlayerEvent(player, "stops looking at {0} top {1} cards.", group, count); group.LookedAt.Remove(uid); } }
public void MoveCard(Player player, int[] card, Group to, int[] idx, bool[] faceUp, bool isScriptMove) { // Ignore cards moved by the local player (already done, for responsiveness) var cards = card.Select(Card.Find).ToArray(); if (player != Player.LocalPlayer) new MoveCards(player, cards, to, idx, faceUp, isScriptMove).Do(); }
public void MoveCard(Player player, Card card, Group to, int idx, bool faceUp, bool isScriptMove) { // Ignore cards moved by the local player (already done, for responsiveness) if (player != Player.LocalPlayer) new MoveCard(player, card, to, idx, faceUp, isScriptMove).Do(); }
//Temporarily store group visibility information for LoadDeck. //bug (google) #20 public void LoadDeck(IDeck deck) { var def = Program.GameEngine.Definition; int nCards = deck.CardCount(); var ids = new int[nCards]; var keys = new ulong[nCards]; var cards = new Card[nCards]; var groups = new Play.Group[nCards]; var gtmps = new List <GrpTmp>(); //for temp groups visibility int j = 0; foreach (ISection section in deck.Sections) { DeckSection sectionDef = null; sectionDef = section.Shared ? def.SharedDeckSections[section.Name] : def.DeckSections[section.Name]; if (sectionDef == null) { throw new InvalidFileFormatException("Invalid section '" + section.Name + "' in deck file."); } var player = section.Shared ? Player.GlobalPlayer : Player.LocalPlayer; Play.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 (IMultiCard element in section.Cards) { DataNew.Entities.Card mod = Definition.GetCardById(element.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.Id.Condense(); int id = GenerateCardId(); ids[j] = id; keys[j] = Crypto.ModExp(key); groups[j] = group; var card = new Card(player, id, key, mod, true); cards[j++] = card; group.AddAt(card, group.Count); } // Load images in the background string pictureUri = element.GetPicture(); 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(); }
/// <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(Player player, Group group, int[] card, short[] pos) { if (player == Player.LocalPlayer) return; ((Pile)group).DoShuffle(card, pos); }