示例#1
0
        void earthwatcherRequest_LandReassignedByPlayingRegion(object sender, EventArgs e)
        {
            Land land = sender as Land;

            try
            {
                if (land != null)
                {
                    //Cambios en memoria de lands
                    var oldLand = Current.Instance.Lands.Where(x => x.Id == Current.Instance.Earthwatcher.Lands.FirstOrDefault().Id).FirstOrDefault();
                    if (oldLand != null)
                    {
                        //Si no está en amarillo o en verde la saco
                        if (oldLand.LandStatus != LandStatus.Alert && oldLand.LandStatus != LandStatus.Ok)
                        {
                            Current.Instance.Lands.Remove(oldLand);
                            Current.Instance.LandInView.Remove(oldLand);
                        }
                        else
                        {   //Si es amarilla o verde la paso a greenpeace
                            oldLand.EarthwatcherId   = Configuration.GreenpeaceId;
                            oldLand.EarthwatcherName = Configuration.GreenpeaceName;
                            oldLand.IsPowerUser      = true;
                        }
                        //Saco del current instance del Ew la land que quiero cambiar
                        var oldEarthwatcherLand = Current.Instance.Earthwatcher.Lands.Where(x => x.Id == oldLand.Id).FirstOrDefault();
                        Current.Instance.Earthwatcher.Lands.Remove(oldEarthwatcherLand);
                    }
                    //si la land que me asignaron no esta en el current instance de lands, la agrega y se la agrega al Ew
                    if (!Current.Instance.Lands.Any(x => x.Id == land.Id))
                    {
                        Current.Instance.Lands.Add(land);
                        Current.Instance.Earthwatcher.Lands.Add(land);
                    }

                    //Actualizo en memoria la nueva region
                    Current.Instance.Region = _selectedRegion;

                    var hexagonLayer = Current.Instance.LayerHelper.FindLayer(Constants.Hexagonlayername) as Earthwatchers.UI.Layers.HexagonLayer;

                    if (hexagonLayer != null)
                    {
                        hexagonLayer.AddHexagon(land);
                    }

                    if (land.IsTutorLand) //Is Tutor Land - All region is complete
                    {
                        //Muestro el mensaje, Deshabilito mi parcela
                        NotificationsWindow notificationsWindow = new NotificationsWindow(ActionPoints.Action.RegionCompleted.ToString());
                        notificationsWindow.Show();
                    }
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                //Traigo nuevamente las lands para el pais que estoy jugando
                landRequests.GetAll(Current.Instance.Earthwatcher.Id, Current.Instance.Earthwatcher.PlayingRegion);

                Earthwatcher earthwatcher = Current.Instance.Earthwatcher;

                if (land == null)
                {
                    MessageBox.Show(Labels.NoMoreLands);
                    ChangeCompleted(this, EventArgs.Empty);
                }
                else
                {
                    //Logueo el cambio de pais de juego
                    MapHelper.ZoomToHexagon(Current.Instance.MapControl, land.GeohexKey);
                    Current.Instance.AddScore.Add(new Score(earthwatcher.Id, ActionPoints.Action.PlayingRegionChanged.ToString(), ActionPoints.Points(ActionPoints.Action.PlayingRegionChanged), earthwatcher.PlayingRegion, Current.Instance.PrecisionScore, earthwatcher.Lands.FirstOrDefault().Id));
                    // Recibe el evento en mainpage y le asigna el puntaje
                    ChangeCompleted(this, EventArgs.Empty);
                }
            }
        }