Esempio n. 1
0
        void StartLocalGame(DataNew.Entities.Game game, string name, string password)
        {
            var hs = new HostedGame(HostPort, game.Id, game.Version, game.Name, name, null, new User(Prefs.Nickname + "@" + AppConfig.ChatServerPath), true);
            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Program.LobbyClient.CurrentHostedGamePort = HostPort;
            Program.GameSettings.UseTwoSidedTable = HostGame.UseTwoSidedTable;
            Program.IsHost = true;
            Program.GameEngine = new GameEngine(game, Prefs.Nickname, password,true);

            var ip = IPAddress.Parse("127.0.0.1");

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    Program.Client = new Octgn.Networking.ClientSocket(ip, HostPort);
                    Program.Client.Connect();
                    return;
                }
                catch (Exception e)
                {
                    Log.Warn("Start local game error", e);
                    if (i == 4) throw;
                }
                Thread.Sleep(2000);
            }
            throw new UserMessageException("Cannot start local game. You may be missing a file.");
        }
Esempio n. 2
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]);
     }
 }
Esempio n. 3
0
        private int _state; // Value of this counter

        #endregion Fields

        #region Constructors

        public Counter(Player player, DataNew.Entities.Counter def)
        {
            _player = player;
            _state = def.Start;
            _name = def.Name;
            _id = def.Id;
            _defintion = def;
        }
Esempio n. 4
0
 public void CheckXml(DataNew.Entities.Game game)
 {
     XmlSetParser xmls = xml_set;
     if (game.Id.ToString() != xmls.game())
     {
         throw new Exception("Error! Wrong game specified in xml");
     }
     xmls.check();
 }
Esempio n. 5
0
 public DataGameViewModel(DataNew.Entities.Game game)
 {
     Id = game.Id;
     Name = game.Name;
     Version = game.Version;
     CardBackUri = game.GetCardBackUri();
     //FullPath = game.FullPath;
     IsSelected = false;
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 public void CheckXml(Windows.ChangeSetsProgressDialog wnd, int max, DataNew.Entities.Game game)
 {
     XmlSetParser xmls = xml_set;
     if (game.Id.ToString() != xmls.game())
     {
         wnd.UpdateProgress(max, max, string.Format("Error! Wrong game specified in xml"), false);
         return;
     }
     xmls.check();
 }
Esempio n. 8
0
 public CreateCard(Player owner, int id,bool faceUp, DataNew.Entities.Card model, int x, int y,
                   bool deletesWhenLeavesGroup)
 {
     _owner = owner;
     _id = id;
     _faceUp = faceUp;
     _deletesWhenLeavesGroup = deletesWhenLeavesGroup;
     _model = model;
     _x = x;
     _y = y;
 }
Esempio n. 9
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;
 }
Esempio n. 10
0
 public SearchControl(DataNew.Entities.Game game)
 {
     Game = game;
     InitializeComponent();
     filtersList.ItemsSource =
         Enumerable.Repeat<object>("First", 1).Union(
             Enumerable.Repeat<object>(new SetPropertyDef(Game.Sets()), 1).Union(
                 game.AllProperties().Where(p => !p.Hidden)));
     GenerateColumns(game);
     //resultsGrid.ItemsSource = game.SelectCards(null).DefaultView;
     UpdateDataGrid(game.AllCards().ToDataTable(Game).DefaultView);
 }
Esempio n. 11
0
 // 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");
 }
Esempio n. 12
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;
 }
Esempio n. 13
0
 public SearchControl(DataNew.Entities.Game game, DeckBuilderWindow deckWindow)
 {
     _deckWindow = deckWindow;
     NumMod = "";
     Game = game;
     InitializeComponent();
     filtersList.ItemsSource =
         Enumerable.Repeat<object>("First", 1).Union(
             Enumerable.Repeat<object>(new SetPropertyDef(Game.Sets().Where(x => x.Hidden == false)), 1).Union(
                 game.AllProperties().Where(p => !p.Hidden)));
     GenerateColumns(game);
     //resultsGrid.ItemsSource = game.SelectCards(null).DefaultView;
     UpdateDataGrid(game.AllCards(true).ToDataTable(Game).DefaultView);
     FileName = "";
     UpdateCount();
 }
Esempio n. 14
0
 public SearchControl(DataNew.Entities.Game game, DeckBuilderWindow deckWindow)
 {
     _deckWindow = deckWindow;
     NumMod = "";
     Game = game;
     InitializeComponent();
     filtersList.ItemsSource =
         Enumerable.Repeat<object>("First", 1).Union(
             Enumerable.Repeat<object>(new SetPropertyDef(Game.Sets()), 1).Union(
                 game.AllProperties().Where(p => !p.Hidden)));
     GenerateColumns(game);
     //resultsGrid.ItemsSource = game.SelectCards(null).DefaultView;
     UpdateDataGrid(game.AllCards().ToDataTable(Game).DefaultView);
     FileName = "";
     UpdateCount();
 }//Why are we populating the list on load? I'd rather wait until the search is run with no parameters (V)_V
Esempio n. 15
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];
 }
Esempio n. 16
0
 public void CheckVerboseXml(Windows.ChangeSetsProgressDialog wnd, int max, DataNew.Entities.Game game)
 {
     XmlSetParser xmls = xml_set;
     wnd.UpdateProgress(1, max, "Parsing retrieved xml...", false);
     xmls.check();
     if (game.Id.ToString() != xmls.game())
     {
         wnd.UpdateProgress(10, 10, string.Format("Error! Wrong game specified in xml"), false);
         return;
     }
     wnd.UpdateProgress(2, max, "Name: " + xmls.name(), false);
     wnd.UpdateProgress(3, max, "Game: " + xmls.game(), false);
     wnd.UpdateProgress(4, max, "UUID: " + xmls.uuid(), false);
     wnd.UpdateProgress(5, max, "Version: " + xmls.version(), false);
     wnd.UpdateProgress(6, max, "Date: " + xmls.date(), false);
     wnd.UpdateProgress(7, max, "Link: " + xmls.link(), false);
     wnd.UpdateProgress(8, max, "Login: "******"Password: "******"Xml seems ok"), false);
 }
Esempio n. 17
0
 // 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));
 }
Esempio n. 18
0
 public CardModelEventArgs(DataNew.Entities.Card model, RoutedEvent routedEvent, object source)
     : base(routedEvent, source)
 {
     CardModel = model;
 }
Esempio n. 19
0
 private void GenerateColumns(DataNew.Entities.Game game)
 {
     foreach (DataNew.Entities.PropertyDef prop in game.CustomProperties)
     {
         if (prop.Name == "Name") continue;
         resultsGrid.Columns.Add(new DataGridTextColumn
                                     {
                                         Binding = new Binding
                                                       {
                                                           Path = new PropertyPath(prop.Name),
                                                           Mode = BindingMode.OneTime
                                                       },
                                         Header = prop.Name
                                     });
     }
 }
Esempio n. 20
0
 internal void SetModel(DataNew.Entities.Card model)
 {
     #if (DEBUG)
     Debug.WriteLine("SetModel event happened!");
     #endif
     bool processSwitches = false;
     if (Type.Model == null) processSwitches = true;//if there is no current model, we've built up unperformed Alternate Switches
     Type.Model = model;
     OnPropertyChanged("Picture");//This should be changed - the model is much more than just the picture.
     if (processSwitches) catchUpOnAlternateSwitches();
 }
Esempio n. 21
0
        protected virtual List<Control> CreateCardMenuItems(Card card, DataNew.Entities.Group def)
        {
            var items = new List<Control>();
            if (!card.CanManipulate())
            {
                var item = new MenuItem { Header = card.Name, Background = card.Controller.TransparentBrush };
                item.SetResourceReference(StyleProperty, "MenuHeader");
                items.Add(item);

                item = new MenuItem { Header = "Take control" };
                item.Click += delegate { card.TakeControl(); };
                items.Add(item);
                return items;
            }
            else {
                var selection = Selection.ExtendToSelection(card);
                //actionFilter showCard = async (IGroupAction a) =>
                actionFilter showCard = (IGroupAction a) =>
                {
                    if (a.ShowIf != null)
                    {
                      //return await CallActionShowIf(a.ShowIf, selection);
                      return CallActionShowIf(a.ShowIf, selection);
                    }
                    return true;
                };
                var visibleActionsTasks = def.CardActions.Select(item => new { Item = item, PredTask = showCard.Invoke(item) }).ToList();
                //await TaskEx.WhenAll(visibleActionsTasks.Select(x => x.PredTask));
                //var visibleActions = visibleActionsTasks.Where(x => x.PredTask.Result).Select(x => x.Item).ToArray();
                var visibleActions = visibleActionsTasks.Where(x => x.PredTask).Select(x => x.Item).ToArray();
                var nCardActions = visibleActions.Length;

                if (nCardActions > 0 || group.Controller == null)
                {
                    var cardHeader = new MenuItem();
                    cardHeader.SetResourceReference(StyleProperty, "MenuHeader");
                    cardHeader.Header = card.Name;
                    cardHeader.Background = card.Controller.TransparentBrush;
                    items.Add(cardHeader);
                }
                if (nCardActions > 0)
                {
                    items.AddRange(visibleActions.Select(action => CreateActionMenuItem(action, CardActionClicked)));
                    if (group.Controller == null)
                        items.Add(new Separator());
                }
                if (group.Controller == null)
                    items.Add(CreateCardPassToItem());
            }
            if (!card.FaceUp)
            {
              var peekItem = new MenuItem { Header = "Peek", InputGestureText = "Ctrl+P" };
              peekItem.Click += delegate { ContextCard.Peek(); };
              items.Add(peekItem);
            }

            return items;
        }
Esempio n. 22
0
 void StartOnlineGame(DataNew.Entities.Game game, string name, string password)
 {
     var client = new Octgn.Site.Api.ApiClient();
     if (!client.IsGameServerRunning(Program.LobbyClient.Username, Program.LobbyClient.Password))
     {
         throw new UserMessageException("The game server is currently down. Please try again later.");
     }
     Program.CurrentOnlineGameName = name;
     // TODO: Replace this with a server-side check
     password = SubscriptionModule.Get().IsSubscribed == true ? password : String.Empty;
     Program.LobbyClient.BeginHostGame(game, name, password, game.Name, game.IconUrl, 
         typeof(Octgn.Server.Server).Assembly.GetName().Version,Specators);
 }
Esempio n. 23
0
 public void SetCardModel(DataNew.Entities.Card model)
 {
     Debug.Assert(this.Card == null, "Cannot set the CardModel of a CardRun if it is already defined");
     this.Card = model;
     if (_updateAction != null)
         _updateAction.Invoke(model, GameCard);
 }
Esempio n. 24
0
 public CardRun(DataNew.Entities.Card model)
     : base(model.PropertyName())
 {
     _card = model;
 }
Esempio n. 25
0
 public void SetCardModel(DataNew.Entities.Card model)
 {
     Debug.Assert(_card == null, "Cannot set the CardModel of a CardRun if it is already defined");
     _card = model;
     Text = model.PropertyName();
 }
Esempio n. 26
0
 internal void AddMarker(DataNew.Entities.Marker model, ushort count)
 {
     Marker marker = _markers.FirstOrDefault(m => m.Model.Equals(model));
     if (marker != null)
         marker.SetCount((ushort) (marker.Count + count));
     else if (count > 0)
         _markers.Add(new Marker(this, model, count));
 }
Esempio n. 27
0
        void StartLocalGame(DataNew.Entities.Game game, string name, string password)
        {
            var hostport = new Random().Next(5000,6000);
            while (!Networking.IsPortAvailable(hostport)) hostport++;
            var hs = new HostedGame(hostport, game.Id, game.Version, game.Name,game.IconUrl, name
                , Password, new User(Username + "@" + AppConfig.ChatServerPath),Specators, true);
            if (!hs.StartProcess())
            {
                throw new UserMessageException("Cannot start local game. You may be missing a file.");
            }
            Prefs.Nickname = Username;
            Program.LobbyClient.CurrentHostedGamePort = hostport;
            Program.GameEngine = new GameEngine(game, Username, false, password, true);
//            Program.GameSettings.UseTwoSidedTable = true;
            Program.CurrentOnlineGameName = name;
            Program.IsHost = true;
            Program.IsMatchmaking = false;

            var ip = IPAddress.Parse("127.0.0.1");

            for (var i = 0; i < 5; i++)
            {
                try
                {
                    Program.Client = new ClientSocket(ip, hostport);
                    Program.Client.Connect();
                    SuccessfulHost = true;
                    return;
                }
                catch (Exception e)
                {
                    Log.Warn("Start local game error",e);
                    if (i == 4) throw;
                }
                Thread.Sleep(2000);
            }
            
        }
Esempio n. 28
0
 internal void AddMarker(DataNew.Entities.Marker model)
 {
     AddMarker(model, 1);
 }
Esempio n. 29
0
 internal Pile(Player owner, DataNew.Entities.Group def)
     : base(owner, def)
 {
     _collapsed = def.Collapsed;
 }
Esempio n. 30
0
        protected virtual List<Control> CreateGroupMenuItems(DataNew.Entities.Group def)
        {
            var items = new List<Control> {CreateGroupHeader()};
            if (!group.CanManipulate())
            {
                items.Add(CreateGroupHeader());

                var item = new MenuItem {Header = "Take control"};
                item.Click += delegate { group.TakeControl(); };
                items.Add(item);

                items.Add(new Separator());
                item = CreateLookAtCardsMenuItem();
                if (item != null) items.Add(item);
            } else {
                var tempActions = def.GroupActions.ToArray();
                int nGroupActions = def.GroupActions == null ? 0 : tempActions.Length;
                for (int i = 0; i < nGroupActions; i++)
                    items.Add(CreateActionMenuItem(tempActions[i], GroupActionClicked));

                if (nGroupActions > 0)
                    items.Add(new Separator());

                if (group.Controller != null)
                    items.Add(CreateGroupPassToItem());
                if (group.Visibility != GroupVisibility.Undefined)
                    items.Add(CreateVisibilityItem());
                MenuItem item = CreateLookAtCardsMenuItem();
                if (item != null)
                    items.Add(item);
                if (def.Id == Program.GameEngine.Definition.Table.Id)
                {
                    if (!(items.Last() is Separator))
                        items.Add(new Separator());
                    var noteItem = new MenuItem() { Header = "Create Note" };
                    noteItem.Click += NoteItemOnClick;
                    items.Add(noteItem);
                }

                if (items.Last() is Separator)
                    items.RemoveAt(items.Count - 1);
            }
            return items;
        }