Example #1
0
 // C'tor
 internal Player(GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     _name = name;
     Id = id;
     PublicKey = pkey;
     // Register the lPlayer
     all.Add(this);
     //Create the color brushes
     SetPlayerColor(id);
     // Create counters
     _counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         if (g.PlayerDefinition.Counters != null)
             Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
     // Create variables
     Variables = new Dictionary<string, int>();
     foreach (VariableDef varDef in g.Variables.Where(v => !v.Global))
         Variables.Add(varDef.Name, varDef.DefaultValue);
     // Create global variables
     GlobalVariables = new Dictionary<string, string>();
     foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
         GlobalVariables.Add(varD.Name, varD.Value);
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
         _hand = new Hand(this, g.PlayerDefinition.Hand);
     // Create groups
     _groups = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     _groups[0] = _hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
         if (g.PlayerDefinition.Groups != null) _groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
 }
Example #2
0
 // C'tor
 internal Player(Definitions.GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     this.name = name; this.Id = id; this.PublicKey = pkey;
     // Register the player
     all.Add(this);
     OnPropertyChanged("Color");
     // Create the color brushes
     solidBrush = new System.Windows.Media.SolidColorBrush(Color);
     solidBrush.Freeze();
     transparentBrush = new System.Windows.Media.SolidColorBrush(Color);
     transparentBrush.Opacity = 0.4;
     transparentBrush.Freeze();
     OnPropertyChanged("Brush");
     OnPropertyChanged("TransparentBrush");
     // Create counters
     counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
       // Create variables
       Variables = new Dictionary<string, int>();
       foreach (var varDef in g.Variables.Where(v => !v.Global))
     Variables.Add(varDef.Name, varDef.DefaultValue);
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
         hand = new Hand(this, g.PlayerDefinition.Hand);
     // Create groups
     groups = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     groups[0] = hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
 }
Example #3
0
        // C'tor for global items
        internal Player(DataNew.Entities.Game g)
        {
            all.CollectionChanged += (sender, args) =>
            {
                allExceptGlobal.Clear();
                foreach (var p in all.ToArray().Where(x => x != Player.GlobalPlayer))
                {
                    allExceptGlobal.Add(p);
                }
            };
            State = PlayerState.Connected;
            var globalDef = g.GlobalPlayer;

            // Register the lPlayer
            lock (all)
                all.Add(this);
            // Init fields
            _name     = "Global";
            Id        = 0;
            PublicKey = 0;
            if (GlobalVariables == null)
            {
                // Create global variables
                GlobalVariables = new Dictionary <string, string>();
                foreach (var varD in g.Player.GlobalVariables)
                {
                    GlobalVariables.Add(varD.Name, varD.Value);
                }
            }
            // Create counters
            _counters = new Counter[0];
            if (globalDef.Counters != null)
            {
                _counters = globalDef.Counters.Select(x => new Counter(this, x)).ToArray();
            }
            // Create global's lPlayer groups
            // TODO: This could fail with a run-time exception on write, make it safe
            // I don't know if the above todo is still relevent - Kelly Elton - 3/18/2013
            if (globalDef.Groups != null)
            {
                var tempGroups = globalDef.Groups.ToArray();
                _groups    = new Group[tempGroups.Length + 1];
                _groups[0] = _hand;
                for (int i = 1; i < IndexedGroups.Length; i++)
                {
                    _groups[i] = new Pile(this, tempGroups[i - 1]);
                }
            }
            OnPropertyChanged("All");
            OnPropertyChanged("AllExceptGlobal");
            OnPropertyChanged("Count");
        }
Example #4
0
 // C'tor
 internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey)
 {
     State = PlayerState.Connected;
     // Init fields
     _name     = name;
     Id        = id;
     PublicKey = pkey;
     // Register the lPlayer
     Application.Current.Dispatcher.Invoke(new Action(() => all.Add(this)));
     //Create the color brushes
     SetPlayerColor(id);
     // Create counters
     _counters = new Counter[0];
     if (g.Player.Counters != null)
     {
         _counters = g.Player.Counters.Select(x => new Counter(this, x)).ToArray();
     }
     // Create variables
     Variables = new Dictionary <string, int>();
     foreach (var varDef in g.Variables.Where(v => !v.Global))
     {
         Variables.Add(varDef.Name, varDef.Default);
     }
     // Create global variables
     GlobalVariables = new Dictionary <string, string>();
     foreach (var varD in g.Player.GlobalVariables)
     {
         GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create a hand, if any
     if (g.Player.Hand != null)
     {
         _hand = new Hand(this, g.Player.Hand);
     }
     // Create groups
     _groups = new Group[0];
     if (g.Player.Groups != null)
     {
         var tempGroups = g.Player.Groups.ToArray();
         _groups    = new Group[tempGroups.Length + 1];
         _groups[0] = _hand;
         for (int i = 1; i < IndexedGroups.Length; i++)
         {
             _groups[i] = new Pile(this, tempGroups[i - 1]);
         }
     }
     // Raise the event
     if (PlayerAdded != null)
     {
         PlayerAdded(null, new PlayerEventArgs(this));
     }
 }
Example #5
0
 // C'tor
 internal Player(GameDef g, string name, byte id, ulong pkey)
 {
     // Init fields
     _name     = name;
     Id        = id;
     PublicKey = pkey;
     // Register the lPlayer
     all.Add(this);
     //Create the color brushes
     SetPlayerColor(id);
     // Create counters
     _counters = new Counter[g.PlayerDefinition.Counters != null ? g.PlayerDefinition.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
     {
         if (g.PlayerDefinition.Counters != null)
         {
             Counters[i] = new Counter(this, g.PlayerDefinition.Counters[i]);
         }
     }
     // Create variables
     Variables = new Dictionary <string, int>();
     foreach (VariableDef varDef in g.Variables.Where(v => !v.Global))
     {
         Variables.Add(varDef.Name, varDef.DefaultValue);
     }
     // Create global variables
     GlobalVariables = new Dictionary <string, string>();
     foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
     {
         GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create a hand, if any
     if (g.PlayerDefinition.Hand != null)
     {
         _hand = new Hand(this, g.PlayerDefinition.Hand);
     }
     // Create groups
     _groups    = new Group[g.PlayerDefinition.Groups != null ? g.PlayerDefinition.Groups.Length + 1 : 1];
     _groups[0] = _hand;
     for (int i = 1; i < IndexedGroups.Length; i++)
     {
         if (g.PlayerDefinition.Groups != null)
         {
             _groups[i] = new Pile(this, g.PlayerDefinition.Groups[i - 1]);
         }
     }
     // Raise the event
     if (PlayerAdded != null)
     {
         PlayerAdded(null, new PlayerEventArgs(this));
     }
 }
Example #6
0
 // C'tor
 internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey)
 {
     SetupPlayer();
     // Init fields
     _name = name;
     Id = id;
     PublicKey = pkey;
     // Register the lPlayer
     Application.Current.Dispatcher.Invoke(new Action(()=>all.Add(this)));
     //Create the color brushes
     SetPlayerColor(id);
     // Create counters
     _counters = new Counter[0];
     if (g.Player.Counters != null)
         _counters = g.Player.Counters.Select(x =>new Counter(this, x) ).ToArray();
     // Create variables
     Variables = new Dictionary<string, int>();
     foreach (var varDef in g.Variables.Where(v => !v.Global))
         Variables.Add(varDef.Name, varDef.Default);
     // Create global variables
     GlobalVariables = new Dictionary<string, string>();
     foreach (var varD in g.Player.GlobalVariables)
         GlobalVariables.Add(varD.Name, varD.Value);
     // Create a hand, if any
     if (g.Player.Hand != null)
         _hand = new Hand(this, g.Player.Hand);
     // Create groups
     _groups = new Group[0];
     if (g.Player.Groups != null)
     {
         var tempGroups = g.Player.Groups.ToArray();
         _groups = new Group[tempGroups.Length + 1];
         _groups[0] = _hand;
         for (int i = 1; i < IndexedGroups.Length; i++)
             _groups[i] = new Pile(this, tempGroups[i - 1]);
     }
     // Raise the event
     if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
     Ready = false;
     OnPropertyChanged("All");
     OnPropertyChanged("AllExceptGlobal");
     OnPropertyChanged("Count");
     minHandSize = 250;
 }
Example #7
0
        // C'tor for global items
        internal Player(GameDef g)
        {
            SharedDef globalDef = g.GlobalDefinition;

            // Register the lPlayer
            all.Add(this);
            // Init fields
            _name     = "Global";
            Id        = 0;
            PublicKey = 0;
            if (GlobalVariables == null)
            {
                // Create global variables
                GlobalVariables = new Dictionary <string, string>();
                foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
                {
                    GlobalVariables.Add(varD.Name, varD.Value);
                }
            }
            // Create counters
            _counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
            for (int i = 0; i < Counters.Length; i++)
            {
                if (globalDef.Counters != null)
                {
                    Counters[i] = new Counter(this, globalDef.Counters[i]);
                }
            }
            // Create global's lPlayer groups
            // TODO: This could fail with a run-time exception on write, make it safe
            _groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
            for (int i = 1; i < IndexedGroups.Length; i++)
            {
                if (globalDef.Groups != null)
                {
                    _groups[i] = new Pile(this, globalDef.Groups[i - 1]);
                }
            }
        }
Example #8
0
        // C'tor
        internal Player(DataNew.Entities.Game g, string name, string userId, byte id, ulong pkey, bool spectator, bool local)
        {
            // Cannot access Program.GameEngine here, it's null.

            Id    = id;
            _name = name;

            if (!string.IsNullOrWhiteSpace(userId))
            {
                UserId = userId;

                if (!userId.StartsWith("##LOCAL##"))
                {
                    Task.Factory.StartNew(async() => {
                        try {
                            var c = new ApiClient();

                            var apiUser = await c.UserFromUserId(userId);
                            if (apiUser != null)
                            {
                                this.DisconnectPercent = apiUser.DisconnectPercent;
                                this.UserIcon          = apiUser.IconUrl;
                            }
                        } catch (Exception e) {
                            Log.Warn("Player() Error getting api stuff", e);
                        }
                    });
                }
            }
            else
            {
                UserId = $"##LOCAL##{name}:{id}";
            }
            _spectator = spectator;
            SetupPlayer(Spectator);
            PublicKey = pkey;
            if (Spectator == false)
            {
                all.Add(this);
            }
            else
            {
                spectators.Add(this);
            }
            // Assign subscriber status
            _subscriber = SubscriptionModule.Get().IsSubscribed ?? false;
            //Create the color brushes
            SetPlayerColor(id);
            // Create counters
            _counters = new Counter[0];
            if (g.Player.Counters != null)
            {
                _counters = g.Player.Counters.Select(x => new Counter(this, x)).ToArray();
            }
            // Create global variables
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varD in g.Player.GlobalVariables)
            {
                GlobalVariables.Add(varD.Name, varD.Value);
            }
            // Create a hand, if any
            if (g.Player.Hand != null)
            {
                _hand = new Hand(this, g.Player.Hand);
            }
            // Create groups
            _groups = new Group[0];
            if (g.Player.Groups != null)
            {
                var tempGroups = g.Player.Groups.ToArray();
                _groups    = new Group[tempGroups.Length + 1];
                _groups[0] = _hand;
                for (int i = 1; i < IndexedGroups.Length; i++)
                {
                    _groups[i] = new Pile(this, tempGroups[i - 1]);
                }
            }
            minHandSize = 250;
            if (Spectator == false)
            {
                // Raise the event
                if (PlayerAdded != null)
                {
                    PlayerAdded(null, new PlayerEventArgs(this));
                }
                Ready = false;
                OnPropertyChanged("All");
                OnPropertyChanged("AllExceptGlobal");
                OnPropertyChanged("Count");
            }
            else
            {
                OnPropertyChanged("Spectators");
                Ready = true;
            }
            CanKick = local == false && Program.IsHost;
        }
Example #9
0
 // C'tor for global items
 internal Player(GameDef g)
 {
     SharedDef globalDef = g.GlobalDefinition;
     // Register the lPlayer
     all.Add(this);
     // Init fields
     _name = "Global";
     Id = 0;
     PublicKey = 0;
     if (GlobalVariables == null)
     {
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (GlobalVariableDef varD in g.PlayerDefinition.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create counters
     _counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         if (globalDef.Counters != null) Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's lPlayer groups
     // TODO: This could fail with a run-time exception on write, make it safe
     _groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         if (globalDef.Groups != null) _groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }
Example #10
0
 // C'tor for global items
 internal Player(DataNew.Entities.Game g)
 {
     var globalDef = g.GlobalPlayer;
     // Register the lPlayer
     all.Add(this);
     // Init fields
     _name = "Global";
     Id = 0;
     PublicKey = 0;
     if (GlobalVariables == null)
     {
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (var varD in g.Player.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create counters
     _counters = new Counter[0];
     if (globalDef.Counters != null)
         _counters = globalDef.Counters.Select(x => new Counter(this, x)).ToArray();
     // Create global's lPlayer groups
     // TODO: This could fail with a run-time exception on write, make it safe
     // I don't know if the above todo is still relevent - Kelly Elton - 3/18/2013
     if (globalDef.Groups != null)
     {
         var tempGroups = globalDef.Groups.ToArray();
         _groups = new Group[tempGroups.Length + 1];
         _groups[0] = _hand;
         for (int i = 1; i < IndexedGroups.Length; i++)
             _groups[i] = new Pile(this, tempGroups[i - 1]);
     }
 }
Example #11
0
        // C'tor
        internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey, bool spectator, bool local)
        {
            // Cannot access Program.GameEngine here, it's null.

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var c    = new ApiClient();
                    var list = c.UsersFromUsername(new String[] { name });
                    var item = list.FirstOrDefault();
                    if (item != null)
                    {
                        this.DisconnectPercent = item.DisconnectPercent;
                        this.UserIcon          = item.IconUrl;
                    }
                }
                catch (Exception e)
                {
                    Log.Warn("Player() Error getting api stuff", e);
                }
            });
            _spectator = spectator;
            SetupPlayer(Spectator);
            // Init fields
            _name     = name;
            Id        = id;
            PublicKey = pkey;
            if (Spectator == false)
            {
                all.Add(this);
            }
            else
            {
                spectators.Add(this);
            }
            // Assign subscriber status
            _subscriber = SubscriptionModule.Get().IsSubscribed ?? false;
            //Create the color brushes
            SetPlayerColor(id);
            // Create counters
            _counters = new Counter[0];
            if (g.Player.Counters != null)
            {
                _counters = g.Player.Counters.Select(x => new Counter(this, x)).ToArray();
            }
            // Create variables
            Variables = new Dictionary <string, int>();
            foreach (var varDef in g.Variables.Where(v => !v.Global))
            {
                Variables.Add(varDef.Name, varDef.Default);
            }
            // Create global variables
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varD in g.Player.GlobalVariables)
            {
                GlobalVariables.Add(varD.Name, varD.Value);
            }
            // Create a hand, if any
            if (g.Player.Hand != null)
            {
                _hand = new Hand(this, g.Player.Hand);
            }
            // Create groups
            _groups = new Group[0];
            if (g.Player.Groups != null)
            {
                var tempGroups = g.Player.Groups.ToArray();
                _groups    = new Group[tempGroups.Length + 1];
                _groups[0] = _hand;
                for (int i = 1; i < IndexedGroups.Length; i++)
                {
                    _groups[i] = new Pile(this, tempGroups[i - 1]);
                }
            }
            minHandSize = 250;
            if (Spectator == false)
            {
                // Raise the event
                if (PlayerAdded != null)
                {
                    PlayerAdded(null, new PlayerEventArgs(this));
                }
                Ready = false;
                OnPropertyChanged("All");
                OnPropertyChanged("AllExceptGlobal");
                OnPropertyChanged("Count");
            }
            else
            {
                OnPropertyChanged("Spectators");
                Ready = true;
            }
            CanKick = local == false && Program.IsHost;
        }
Example #12
0
 // C'tor
 internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey, bool spectator, bool local)
 {
     _spectator = spectator;
     SetupPlayer(Spectator);
     // Init fields
     _name = name;
     Id = id;
     PublicKey = pkey;
     if (Spectator == false)
     {
         // Register the lPlayer
         all.Add(this);
         //Create the color brushes
         SetPlayerColor(id);
         // Create counters
         _counters = new Counter[0];
         if (g.Player.Counters != null)
             _counters = g.Player.Counters.Select(x => new Counter(this, x)).ToArray();
         // Create variables
         Variables = new Dictionary<string, int>();
         foreach (var varDef in g.Variables.Where(v => !v.Global))
             Variables.Add(varDef.Name, varDef.Default);
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (var varD in g.Player.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
         // Create a hand, if any
         if (g.Player.Hand != null)
             _hand = new Hand(this, g.Player.Hand);
         // Create groups
         _groups = new Group[0];
         if (g.Player.Groups != null)
         {
             var tempGroups = g.Player.Groups.ToArray();
             _groups = new Group[tempGroups.Length + 1];
             _groups[0] = _hand;
             for (int i = 1; i < IndexedGroups.Length; i++)
                 _groups[i] = new Pile(this, tempGroups[i - 1]);
         }
         // Raise the event
         if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
         Ready = false;
         OnPropertyChanged("All");
         OnPropertyChanged("AllExceptGlobal");
         OnPropertyChanged("Count");
         minHandSize = 250;
     }
     else
     {
         spectators.Add(this);
         SetPlayerColor(id);
         OnPropertyChanged("Spectators");
         Ready = true;
     }
     CanKick = local == false&& Program.IsHost;
 }
Example #13
0
 // C'tor for global items
 internal Player(Definitions.GameDef g)
 {
     var globalDef = g.GlobalDefinition;
     // Register the player
     all.Add(this);
     // Init fields
     name = "Global"; Id = 0; PublicKey = 0;
     if (GlobalVariables == null)
     {
         // Create global variables
         GlobalVariables = new Dictionary<string, string>();
         foreach (var varD in g.PlayerDefinition.GlobalVariables)
             GlobalVariables.Add(varD.Name, varD.Value);
     }
     // Create counters
     counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's player groups
     groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }
Example #14
0
        // C'tor
        internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey, bool spectator, bool local)
        {
            // Cannot access Program.GameEngine here, it's null.

            Task.Factory.StartNew(() =>
            {
                try
                {
                    var c = new ApiClient();
                    var list = c.UsersFromUsername(new String[] { name });
                    var item = list.FirstOrDefault();
                    if (item != null)
                    {
                        this.DisconnectPercent = item.DisconnectPercent;
                        this.UserIcon = item.IconUrl;
                    }
                }
                catch (Exception e)
                {
                    Log.Warn("Player() Error getting api stuff", e);
                }
            });
            _spectator = spectator;
            SetupPlayer(Spectator);
            // Init fields
            _name = name;
            Id = id;
            PublicKey = pkey;
            if (Spectator == false)
            {
                all.Add(this);
            }
            else
            {
                spectators.Add(this);
            }
            // Assign subscriber status
            _subscriber = SubscriptionModule.Get().IsSubscribed ?? false;
            //Create the color brushes           
            SetPlayerColor(id);
            // Create counters
            _counters = new Counter[0];
            if (g.Player.Counters != null)
                _counters = g.Player.Counters.Select(x => new Counter(this, x)).ToArray();
            // Create variables
            Variables = new Dictionary<string, int>();
            foreach (var varDef in g.Variables.Where(v => !v.Global))
                Variables.Add(varDef.Name, varDef.Default);
            // Create global variables
            GlobalVariables = new Dictionary<string, string>();
            foreach (var varD in g.Player.GlobalVariables)
                GlobalVariables.Add(varD.Name, varD.Value);
            // Create a hand, if any
            if (g.Player.Hand != null)
                _hand = new Hand(this, g.Player.Hand);
            // Create groups
            _groups = new Group[0];
            if (g.Player.Groups != null)
            {
                var tempGroups = g.Player.Groups.ToArray();
                _groups = new Group[tempGroups.Length + 1];
                _groups[0] = _hand;
                for (int i = 1; i < IndexedGroups.Length; i++)
                    _groups[i] = new Pile(this, tempGroups[i - 1]);
            }
            minHandSize = 250;
            if (Spectator == false)
            {
                // Raise the event
                if (PlayerAdded != null) PlayerAdded(null, new PlayerEventArgs(this));
                Ready = false;
                OnPropertyChanged("All");
                OnPropertyChanged("AllExceptGlobal");
                OnPropertyChanged("Count");
            }
            else
            {
                OnPropertyChanged("Spectators");
                Ready = true;
            }
            CanKick = local == false && Program.IsHost;
        }
Example #15
0
 // C'tor
 internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey, bool spectator, bool local)
 {
     _spectator = spectator;
     SetupPlayer(Spectator);
     // Init fields
     _name     = name;
     Id        = id;
     PublicKey = pkey;
     if (Spectator == false)
     {
         // Register the lPlayer
         all.Add(this);
         //Create the color brushes
         SetPlayerColor(id);
         // Create counters
         _counters = new Counter[0];
         if (g.Player.Counters != null)
         {
             _counters = g.Player.Counters.Select(x => new Counter(this, x)).ToArray();
         }
         // Create variables
         Variables = new Dictionary <string, int>();
         foreach (var varDef in g.Variables.Where(v => !v.Global))
         {
             Variables.Add(varDef.Name, varDef.Default);
         }
         // Create global variables
         GlobalVariables = new Dictionary <string, string>();
         foreach (var varD in g.Player.GlobalVariables)
         {
             GlobalVariables.Add(varD.Name, varD.Value);
         }
         // Create a hand, if any
         if (g.Player.Hand != null)
         {
             _hand = new Hand(this, g.Player.Hand);
         }
         // Create groups
         _groups = new Group[0];
         if (g.Player.Groups != null)
         {
             var tempGroups = g.Player.Groups.ToArray();
             _groups    = new Group[tempGroups.Length + 1];
             _groups[0] = _hand;
             for (int i = 1; i < IndexedGroups.Length; i++)
             {
                 _groups[i] = new Pile(this, tempGroups[i - 1]);
             }
         }
         // Raise the event
         if (PlayerAdded != null)
         {
             PlayerAdded(null, new PlayerEventArgs(this));
         }
         Ready = false;
         OnPropertyChanged("All");
         OnPropertyChanged("AllExceptGlobal");
         OnPropertyChanged("Count");
         minHandSize = 250;
     }
     else
     {
         spectators.Add(this);
         SetPlayerColor(id);
         OnPropertyChanged("Spectators");
         Ready = true;
     }
     CanKick = local == false && Program.IsHost;
 }
Example #16
0
 // C'tor for global items
 internal Player(Definitions.GameDef g)
 {
     var globalDef = g.GlobalDefinition;
     // Register the player
     all.Add(this);
     // Init fields
     name = "Global"; Id = 0; PublicKey = 0;
     // Create counters
     counters = new Counter[globalDef.Counters != null ? globalDef.Counters.Length : 0];
     for (int i = 0; i < Counters.Length; i++)
         Counters[i] = new Counter(this, globalDef.Counters[i]);
     // Create global's player groups
     groups = new Pile[globalDef.Groups != null ? g.GlobalDefinition.Groups.Length + 1 : 0];
     for (int i = 1; i < IndexedGroups.Length; i++)
         groups[i] = new Pile(this, globalDef.Groups[i - 1]);
 }