Пример #1
0
 internal Card(Player owner, int id, ulong key, DataNew.Entities.Card model, bool mySecret)
     : base(owner)
 {
     _id  = id;
     Type = new CardIdentity(id)
     {
         Key = key, Model = model.Clone(), MySecret = mySecret
     };
     // var _definition = def;
     lock (All)
     {
         if (All.ContainsKey(id))
         {
             All[id] = this;
         }
         else
         {
             All.Add(id, this);
         }
     }
     _alternateOf = null;
     numberOfSwitchWithAlternatesNotPerformed = 0;
     _isAlternateImage = false;
     _cardMoved        = false;
 }
Пример #2
0
 internal Card(Player owner, int id, DataNew.Entities.Card model, bool mySecret, string cardsize)            : base(owner)
 {
     _id  = id;
     Type = new CardIdentity(id)
     {
         Model = model.Clone()
     };
     // var _definition = def;
     lock (All)
     {
         if (All.ContainsKey(id))
         {
             All[id] = this;
         }
         else
         {
             All.Add(id, this);
         }
     }
     _alternateOf = null;
     //numberOfSwitchWithAlternatesNotPerformed = 0;
     //_isAlternateImage = false;
     _cardMoved = false;
     Size       = Program.GameEngine.Definition.CardSizes[cardsize];
 }
Пример #3
0
 public void OnRevealed(CardIdentity newId)
 {
     if (Revealed != null)
     {
         Revealed(this, new RevealEventArgs {
             NewIdentity = newId
         });
     }
 }
Пример #4
0
 /// <summary>Create new CardIdentities, which hide aliases to other CardIdentities</summary>
 /// <param name="id">An array containing the new CardIdentity ids</param>
 /// <param name="type">An array with the aliased CardIdentity ids (encrypted)</param>
 public void CreateAlias(int[] id, ulong[] type)
 {
     byte playerId = (byte)(id[0] >> 16);
     // Ignore cards created by oneself
     if (playerId == Player.LocalPlayer.Id) return;
     for (int i = 0; i < id.Length; i++)
     {
         if (type[i] == ulong.MaxValue) continue;
         CardIdentity ci = new CardIdentity(id[i]) {Alias = true, Key = type[i]};
     }
 }
Пример #5
0
 internal Card(Player owner, int id, ulong key, CardDef def, DataNew.Entities.Card model, bool mySecret)
     : base(owner)
 {
     _id = id;
     Type = new CardIdentity(id) {Alias = false, Key = key, Model = model, MySecret = mySecret};
     // var _definition = def;
     All.Add(id, this);
     _alternateOf = null;
     numberOfSwitchWithAlternatesNotPerformed = 0;
     _isAlternateImage = false;
 }
Пример #6
0
 internal Card(Player owner, int id, ulong key, CardDef def, CardModel model, bool mySecret)
     : base(owner)
 {
     _id  = id;
     Type = new CardIdentity(id)
     {
         Alias = false, Key = key, Model = model, MySecret = mySecret
     };
     // var _definition = def;
     All.Add(id, this);
     _alternateOf = null;
     numberOfSwitchWithAlternatesNotPerformed = 0;
     _isAlternateImage = false;
 }
Пример #7
0
 internal Card(Player owner, int id, ulong key,  DataNew.Entities.Card model, bool mySecret)
     : base(owner)
 {
     _id = id;
     Type = new CardIdentity(id) {Key = key, Model = model.Clone() , MySecret = mySecret};
     // var _definition = def;
     lock (All)
     {
         if (All.ContainsKey(id)) All[id] = this;
         else All.Add(id, this);
     }
     _alternateOf = null;
     numberOfSwitchWithAlternatesNotPerformed = 0;
     _isAlternateImage = false;
 }
Пример #8
0
        public void Rename(object sender, RevealEventArgs e)
        {
            var id = (CardIdentity)sender;

            id.Revealed -= Rename;
            CardIdentity newId = e.NewIdentity;

            if (newId.Model != null)
            {
                Target.SetCardModel(newId.Model);
            }
            else
            {
                newId.Revealed += Rename;
            }
        }
Пример #9
0
 internal Card(Player owner, int id, DataNew.Entities.Card model, bool mySecret, string cardsize)
     : base(owner)
 {
     _id = id;
     Type = new CardIdentity(id) { Model = model.Clone() };
     // var _definition = def;
     lock (All)
     {
         if (All.ContainsKey(id)) All[id] = this;
         else All.Add(id, this);
     }
     _alternateOf = null;
     numberOfSwitchWithAlternatesNotPerformed = 0;
     _isAlternateImage = false;
     _cardMoved = false;
     Size = Program.GameEngine.Definition.CardSizes[cardsize];
 }
Пример #10
0
Файл: Pile.cs Проект: wlk0/OCTGN
        // Do the shuffle
        internal void DoShuffle(int[] card, short[] pos)
        {
            // Check the args
            if (card.Length != pos.Length)
            {
                Program.GameMess.Warning("[Shuffled] Cards and positions lengths don't match.");
                return;
            }
            //Build the Dict. of new locations
            var shuffled = new Dictionary <int, Card>();
            var broke    = false;

            for (int i = 0; i < card.Length; i++)
            {
                var cur = this[i];
                if (cur == null)
                {
                    broke = true;
                    break;
                }
                shuffled.Add(pos[i], cur);
                // Get the card
                CardIdentity ci = CardIdentity.Find(card[i]);
                if (ci == null)
                {
                    Program.GameMess.Warning("[Shuffled] Card not found.");
                    continue;
                }
                cur.SetVisibility(ci.Visible ? DataNew.Entities.GroupVisibility.Everybody : DataNew.Entities.GroupVisibility.Nobody, null);
            }
            if (broke)
            {
                Program.GameMess.Warning("[Shuffled] Tried to shuffle, but it looks like something broke in the process...");
                return;
            }
            //Move cards to their new indexes
            for (int i = 0; i < card.Length; i++)
            {
                Remove(shuffled[i]);
                AddAt(shuffled[i], i);
            }

            OnShuffled();
        }
Пример #11
0
        public void OnRevealed(CardIdentity newId)
        {
            if (Revealed != null)
                Revealed(this, new RevealEventArgs() { NewIdentity = newId });

            // TODO: shouldn't this be a subscription to Revealed event?
            if (revealSuspendedScript != null)
            {
                if (newId.alias)
                {
                    newId.revealSuspendedScript = revealSuspendedScript;
                    revealSuspendedScript = null;
                }
                else
                {
                    var temp = revealSuspendedScript;
                    revealSuspendedScript = null;
                    Script.ScriptEngine.Continue(temp);
                }
            }
        }
Пример #12
0
        // Do the shuffle
        internal void DoShuffle()
        {
            // Set internal fields
            PreparingShuffle   = false;
            FilledShuffleSlots = 0;
            HasReceivedFirstShuffledMessage = false;
            // Create aliases
            var cis = new CardIdentity[cards.Count];

            for (int i = 0; i < cards.Count; i++)
            {
                if (cards[i].IsVisibleToAll())
                {
                    cis[i]         = cards[i].Type;
                    cis[i].Visible = true;
                }
                else
                {
                    CardIdentity ci = cis[i] = new CardIdentity(Program.Game.GenerateCardId());
                    ci.Alias   = ci.MySecret = true;
                    ci.Key     = ((ulong)Crypto.PositiveRandom()) << 32 | (uint)cards[i].Type.Id;
                    ci.Visible = false;
                }
            }
            // Shuffle
            var cardIds     = new int[cards.Count];
            var cardAliases = new ulong[cards.Count];
            var rnd         = new CryptoRandom();

            for (int i = cards.Count - 1; i >= 0; i--)
            {
                int r = rnd.Next(i + 1);
                cardIds[i]     = cis[r].Id;
                cardAliases[i] = cis[r].Visible ? ulong.MaxValue : Crypto.ModExp(cis[r].Key);
                cis[r]         = cis[i];
            }
            // Send the request
            Program.Client.Rpc.CreateAlias(cardIds, cardAliases);
            Program.Client.Rpc.Shuffle(this, cardIds);
        }
Пример #13
0
 /// <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(Program.GameEngine.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);
 }
Пример #14
0
 internal Card FindByCardIdentity(CardIdentity identity)
 {
     lock (cards)
         return(cards.FirstOrDefault(c => c.Type == identity));
 }
Пример #15
0
 // Do the shuffle
 internal void DoShuffle()
 {
     // Set internal fields
     PreparingShuffle = false;
     FilledShuffleSlots = 0;
     HasReceivedFirstShuffledMessage = false;
     // Create aliases
     var cis = new CardIdentity[cards.Count];
     for (int i = 0; i < cards.Count; i++)
     {
         if (cards[i].IsVisibleToAll())
         {
             cis[i] = cards[i].Type;
             cis[i].Visible = true;
         }
         else
         {
             CardIdentity ci = cis[i] = new CardIdentity(Program.Game.GenerateCardId());
             ci.Alias = ci.MySecret = true;
             ci.Key = ((ulong) Crypto.PositiveRandom()) << 32 | (uint) cards[i].Type.Id;
             ci.Visible = false;
         }
     }
     // Shuffle
     var cardIds = new int[cards.Count];
     var cardAliases = new ulong[cards.Count];
     var rnd = new CryptoRandom();
     for (int i = cards.Count - 1; i >= 0; i--)
     {
         int r = rnd.Next(i + 1);
         cardIds[i] = cis[r].Id;
         cardAliases[i] = cis[r].Visible ? ulong.MaxValue : Crypto.ModExp(cis[r].Key);
         cis[r] = cis[i];
     }
     // Send the request
     Program.Client.Rpc.CreateAlias(cardIds, cardAliases);
     Program.Client.Rpc.Shuffle(this, cardIds);
 }
Пример #16
0
 public void OnRevealed(CardIdentity newId)
 {
     if (Revealed != null)
         Revealed(this, new RevealEventArgs {NewIdentity = newId});
 }