public override EstadoNPC Procesar(float fDeltaSegundos) { //Estoy yendo a atacar EstadoNPC nuevoEstado = this; if (!thingAAtacar.Eliminado) { Vector2 diferencia = thingAAtacar.Centro - nave.Centro; if (diferencia.Length > DistanciaAcercamiento) { //Todavia no me acerque todo lo posible if (tiempoIntentosFallidos < 2 && diferencia.Length < RadioBusquedaAtaque * 1.5) { if (!EstadoNPCNavegarA.IrA(nave, thingAAtacar.Centro, fDeltaSegundos)) { tiempoIntentosFallidos += fDeltaSegundos; } } else { //Fallé muchas veces en llegar o se alejó mucho, planifico de nuevo nuevoEstado = new EstadoNPCPlanificar(nave); } } diferencia = thingAAtacar.Centro - nave.Centro; if (diferencia.Length <= DistanciaDisparo) { //Estoy cerca para atacar, roto y disparo! EstadoNPCNavegarA.RotarA(nave, thingAAtacar.Centro, fDeltaSegundos); nave.Shoot(); return(this); } } else { //Destrui mi objetivo! Replanifico nuevoEstado = new EstadoNPCPlanificar(nave); } return(nuevoEstado); }
public override EstadoNPC Procesar(float fDeltaSegundos) { if (!recolectando) { //Esta volviendo o yendo a recolectar Vector2 diferencia = destino - nave.Centro; if (diferencia.Length > 50.0f) { //Todavia no llegue a destino if (tiempoIntentosFallidos < 0.5f) { if (!EstadoNPCNavegarA.IrA(nave, destino, fDeltaSegundos)) { tiempoIntentosFallidos += fDeltaSegundos; } return(this); } else { //Fallé muchas veces en llegar, planifico de nuevo return(new EstadoNPCPlanificar(nave)); } } else { //Llegué a destino if (recoleccionRealizada) //Ya habia hecho la recolección, lo que quiere decir que ya llegué de vuelta al planeta! { return(new EstadoNPCPlanificar(nave)); } else { recolectando = true; //Todavia no se hizo la recolección, la inicio return(this); } } } else { Vector2 diferencia = destino - nave.Centro; if (diferencia.Length <= 50.0f) { //Esta recolectando float consumido = recurso.Consumir(velocidadRecoleccion * fDeltaSegundos); recolectado += consumido; if (recolectado >= totalARecolectar || consumido == 0) { //Termino la recolección, ya sea porque consumí todos los recursos disponibles o porque //recolecté todo lo que habia if (recolectado == 0) { //No se recolectó nada, tengo que planificar una nueva recolección return(new EstadoNPCPlanificar(nave)); } else { //Se recolectó algo, tengo que volver al planeta para dejar los recursos recoleccionRealizada = true; recolectando = false; destino = nave.Galaxia.BuscarPosicionPlanetaFaccion(nave.SectorNativo.Centro, RadioBusquedaRecursos, nave.Faccion); if (destino.X == 0 && destino.Y == 0) { return(new EstadoNPCPlanificar(nave)); //No se encontro planeta, replanifico } else { return(this); } } } else { return(this); } } else { //Algo me desplazo, tengo que volver a ubicarme recolectando = false; return(this); } } }