public HttpResponseMessage PutSubirCantidad(int id, RelJugadorDestacamento rjd)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            try
            {
                Boolean compro = blHandler.updateRelJugadorDestacamento(rjd);
                if (compro)
                {
                    var rel  = blHandler.getRelJugadorDestacamento(rjd.id);
                    var cant = rjd.cantidad - rel.cantidad;
                    Scheduler.ScheduleUpload <DestacamentoUpload>(WebApiConfig.tenant, DateTime.Now.ToString(), rjd.id, cant, cant * rel.destacamento.tiempoInicial);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Recursos insuficientes"));
                }
                //blHandler.executeUpdateRelJD(rjd);
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }

            return(Request.CreateResponse(HttpStatusCode.OK));
        }
        public void executeUpdateRelJD(RelJugadorDestacamento rel)
        {
            var relJMHandler = new RelJugadorMapaHandlerEF(ctx);
            var r            = ctx.RelJugadorDestacamento
                               .Where(w => w.id == rel.id)
                               .SingleOrDefault();

            r.cantidad += rel.cantidad;
            ctx.SaveChangesAsync().Wait();
            relJMHandler.actualizarProduccionCapacidad(r.colonia.id);
        }
        private void ApplyChanges(List <IInteractionable> list)
        {
            list.Where(c => c.mustSend()).ToList().ForEach((Interactionable) => {
                var recursos     = api.getRelJugadorRecursoHandler().getRecursosByColonia(Interactionable.GetID());
                var destacamento = api.getRelJugadorDestacamentoHandler().getDestacamentosByColonia(Interactionable.GetID());
                Interactionable.GetRecursos().ForEach((rec) =>
                {
                    RelJugadorRecurso r = recursos.Where(c => c.recurso.id == rec.GetId()).First();
                    r.cantidadR         = r.cantidadR - rec.GetAmount();
                    api.getRelJugadorRecursoHandler().updateRelJugadorRecurso(r);
                });
                Interactionable.GetFlota().ForEach((rec) =>
                {
                    RelJugadorDestacamento r = destacamento.Where(c => c.destacamento.id == rec.GetId()).First();
                    r.cantidad = r.cantidad - rec.GetAmount();
                    r.setForceUpdate(true);
                    api.getRelJugadorDestacamentoHandler().updateRelJugadorDestacamento(r);
                });
            });
            list.Where(c => c.GetMustUpdate()).ToList().ForEach((Interactionable) =>
            {
                bool isrequester = requester.GetID() == Interactionable.GetID();

                var recursos     = api.getRelJugadorRecursoHandler().getRecursosByColonia(Interactionable.GetID());
                var destacamento = api.getRelJugadorDestacamentoHandler().getDestacamentosByColonia(Interactionable.GetID());
                Interactionable.GetDefensas().ForEach((rec) =>
                {
                    RelJugadorDestacamento r = destacamento.Where(c => c.destacamento.id == rec.GetId()).First();
                    r.cantidad = r.cantidad + rec.GetAmount();
                    r.setForceUpdate(true);
                    api.getRelJugadorDestacamentoHandler().updateRelJugadorDestacamento(r);
                });
                Interactionable.GetFlota().ForEach((rec) =>
                {
                    RelJugadorDestacamento r = destacamento.Where(c => c.destacamento.id == rec.GetId()).First();
                    r.cantidad = r.cantidad + rec.GetAmount();
                    r.setForceUpdate(true);
                    api.getRelJugadorDestacamentoHandler().updateRelJugadorDestacamento(r);
                });
                Interactionable.GetRecursos().ForEach((rec) =>
                {
                    RelJugadorRecurso r = recursos.Where(c => c.recurso.id == rec.GetId()).First();
                    r.cantidadR         = r.cantidadR + rec.GetAmount();
                    api.getRelJugadorRecursoHandler().updateRelJugadorRecurso(r);
                });
            });
        }
        public Boolean updateRelJugadorDestacamento(RelJugadorDestacamento rje)
        {
            RelJugadorRecursoHandlerEF jrHandler = new RelJugadorRecursoHandlerEF(ctx);
            var relJMHandler = new RelJugadorMapaHandlerEF(ctx);

            try
            {
                var r = ctx.RelJugadorDestacamento
                        .Where(w => w.id == rje.id)
                        .SingleOrDefault();

                if (r != null)
                {
                    var dest = r.getShared();
                    var cant = rje.cantidad - r.cantidad;
                    if (!rje.getForceUpdate())
                    {
                        List <Entities.Costo> costos = r.destacamento.calCostoXNivel(0, cant);
                        Boolean compro = jrHandler.restarCompra(r.colonia.id, costos);
                        if (compro == false)
                        {
                            return(false);
                        }
                        DateTime ahora         = DateTime.Now;
                        TimeSpan tConstruccion = TimeSpan.FromSeconds(dest.destacamento.tiempoInicial * cant);
                        r.finalizaConstruccion = ahora.Add(tConstruccion);
                    }
                    else
                    {
                        r.cantidad = rje.cantidad;
                    }

                    ctx.SaveChangesAsync().Wait();
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public void createRelJugadorDestacamento(RelJugadorDestacamento r)
        {
            CostoHandlerEF cosoH = new CostoHandlerEF(ctx);
            var            col   = ctx.RelJugadorMapa.Where(w => w.id == r.colonia.id).SingleOrDefault();
            var            des   = ctx.Destacamento.Where(w => w.id == r.destacamento.id).SingleOrDefault();

            List <Entities.Costo> cos = new List <Entities.Costo>();

            foreach (var item in r.destacamento.costos)
            {
                var rec  = ctx.Recurso.Where(w => w.id == item.recurso.id).SingleOrDefault();
                var prod = ctx.Producto.Where(w => w.id == item.idProducto).SingleOrDefault();
                var c    = new Entities.Costo(rec, prod, item.valor, item.incrementoNivel);
                cos.Add(c);
            }
            List <Entities.Capacidad> cap = new List <Entities.Capacidad>();

            foreach (var item in r.destacamento.capacidad)
            {
                var rec  = ctx.Recurso.Where(w => w.id == item.recurso.id).SingleOrDefault();
                var prod = ctx.Producto.Where(w => w.id == item.idProducto).SingleOrDefault();
                var c    = new Entities.Capacidad(rec, prod, item.valor, item.incrementoNivel);
                cap.Add(c);
            }

            var rje = new Entities.RelJugadorDestacamento(col, des, r.cantidad, r.finalizaConstruccion);

            try
            {
                ctx.RelJugadorDestacamento.Add(rje);

                ctx.SaveChanges();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        //ESTADO INICIAL JUGADOR

        public void inicializarJugador(Jugador j)
        {
            var    mapas = builder.getMapaNodeHandler().getAllMapas();
            Random rnd   = new Random();

            int[]   nivel   = { -1, -1, -1, -1, -1 };
            int     i       = 0;
            string  coord   = "";
            string  c       = "/";
            Boolean hayMapa = true;

            do
            {
                i     = 0;
                coord = "";
                c     = "/";
                foreach (var m in mapas)
                {
                    nivel[i] = rnd.Next(1, m.cantidad + 1);
                    coord   += c;
                    c        = nivel[i] + "/";
                    i++;
                }
                hayMapa = builder.getRelJugadorMapaHandler().existeColonia(nivel[0], nivel[1], nivel[2], nivel[3], nivel[4]);
            } while (hayMapa == true);

            var reljm = new RelJugadorMapa(1, nivel[0], nivel[1], nivel[2], nivel[3], nivel[4], coord, j);

            builder.getRelJugadorMapaHandler().createRelJugadorMapa(reljm);

            List <RelJugadorMapa> colonias = builder.getRelJugadorMapaHandler().getMapasByJugador(j.id);
            var colonia = colonias.First();

            var ahora = DateTime.Now;

            List <Recurso> recursos = builder.getRecursoHandler().getAllRecursos();

            foreach (var rec in recursos)
            {
                var rel = new RelJugadorRecurso(1, rec, colonia, rec.capacidadInicial, rec.cantInicial, rec.produccionXTiempo, ahora);
                builder.getRelJugadorRecursoHandler().createRelJugadorRecurso(rel);
            }

            List <Edificio> edificios = builder.getUnidadHandler().getAllEdificios();

            foreach (var ed in edificios)
            {
                var rel = new RelJugadorEdificio(1, colonia, ed, 0, ahora);
                builder.getRelJugadorEdificioHandler().createRelJugadorEdificio(rel);
            }

            List <Destacamento> destacamentos = builder.getUnidadHandler().getAllDestacamentos();

            foreach (var des in destacamentos)
            {
                var rel = new RelJugadorDestacamento(1, colonia, des, 0, ahora);
                builder.getRelJugadorDestacamentoHandler().createRelJugadorDestacamento(rel);
            }

            List <Investigacion> investigaciones = builder.getInvestigacionHandler().getAllInvestigaciones();

            foreach (var inv in investigaciones)
            {
                var rel = new RelJugadorInvestigacion(1, colonia, inv, 0, ahora);
                builder.getRelJugadorInvestigacionHandler().createRelJugadorInvestigacion(rel);
            }
        }
Esempio n. 7
0
 public void executeUpdateRelJD(RelJugadorDestacamento rel)
 {
     builder.getRelJugadorDestacamentoHandler().executeUpdateRelJD(rel);
 }
Esempio n. 8
0
 public Boolean updateRelJugadorDestacamento(RelJugadorDestacamento reljugadoredificio)
 {
     return(builder.getRelJugadorDestacamentoHandler().updateRelJugadorDestacamento(reljugadoredificio));
 }
Esempio n. 9
0
 public void createRelJugadorDestacamento(RelJugadorDestacamento reljugadordestacamento)
 {
     builder.getRelJugadorDestacamentoHandler().createRelJugadorDestacamento(reljugadordestacamento);
 }