// 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)); }
// 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)); }
// 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; }
// C'tor internal Player(DataNew.Entities.Game g, string name, byte id, ulong pkey) { all.CollectionChanged += (sender, args) => { allExceptGlobal.Clear(); foreach (var p in all.ToArray().Where(x=>x != Player.GlobalPlayer)) { allExceptGlobal.Add(p); } }; 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)); Ready = false; OnPropertyChanged("All"); OnPropertyChanged("AllExceptGlobal"); OnPropertyChanged("Count"); }
// C'tor internal Player(DataNew.Entities.Game 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[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)); }
// 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; }
// 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 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; }