예제 #1
0
    protected static internal AccionCompuesta createAttackingAction(PersonajeBase sujeto, PersonajeBase receptor)
    {
        ActionGo      goToEnemy   = new ActionGo(sujeto, SimManagerFinal.positionToGrid(receptor.posicion), receptor);
        AccionAttack  attackEnemy = new AccionAttack(sujeto, receptor);
        List <Accion> orders      = new List <Accion> {
            goToEnemy, attackEnemy
        };
        AccionCompuesta ac = new AccionCompuesta(sujeto, orders, true);

        return(ac);
    }
예제 #2
0
    private bool tooFarAwayFromBase(PersonajeBase unit)
    {
        PersonajeBase enemyToAttack = null;

        if (unit.currentAction != null && (unit.currentAction is AccionCompuesta))
        {
            AccionCompuesta ac = (AccionCompuesta)unit.currentAction;
            ActionGo        ag = (ActionGo)ac.acciones[0];
            enemyToAttack = ag.receptor;
        }
        if (enemyToAttack != null)
        {
            return((enemyToAttack.posicion - SimManagerFinal.gridToPosition(baseCoords)).magnitude > (StatsInfo.baseDistaciaCuracion * 2));
        }
        else
        {
            return(false);
        }
    }
예제 #3
0
    protected internal override List <Accion> getStrategyActions()
    {
        List <Accion> defensiveActions = new List <Accion>();

        foreach (PersonajeBase ally in allies)
        {
            if (!ally.isAlive())
            {
                continue;
            }
            //1 -  COMPROBAR SI HAY UNIDADES QUE NECESITEN CURACION
            if (!ally.isFullHealth())
            {
                if (!ally.isInCombat())               //Si no esta en combate
                {
                    if (!isInBaseRange(ally, baseCoords) && !alreadyComingToBase(ally))
                    {
                        Vector2  closestPoint = getUnitPointOnBase(ally, baseCoords);
                        ActionGo goToBase     = new ActionGo(ally, closestPoint, null);
                        defensiveActions.Add(goToBase);
                    }
                }
                else
                {
                    if (ally.betterToRun() && !alreadyComingToBase(ally))           //vida por debajo del 30%
                    {
                        if (!isInBaseRange(ally, baseCoords))
                        {
                            Vector2  closestPoint = getUnitPointOnBase(ally, baseCoords);
                            ActionGo goToBase     = new ActionGo(ally, closestPoint, null);
                            defensiveActions.Add(goToBase);
                        }
                    }
                }
            }
            else
            {
                //2 - COMPROBAR SI HAY ENEMIGOS EN EL AREA DE LA BASE INTERRUMPIENDO SPAWN
                List <PersonajeBase> enemies_attacking = enemiesOnBase();
                if (enemies_attacking.Count > 0 && !isGoingToAttack(ally))
                {
                    PersonajeBase closestEnemy = getClosestEnemy(ally, enemies_attacking);
                    ActionGo      goToEnemy    = new ActionGo(ally, SimManagerFinal.positionToGrid(closestEnemy.posicion), closestEnemy);
                    AccionAttack  attackEnemy  = new AccionAttack(ally, closestEnemy);
                    List <Accion> orders       = new List <Accion> {
                        goToEnemy, attackEnemy
                    };
                    AccionCompuesta defendBase = new AccionCompuesta(ally, orders, true);
                    defensiveActions.Add(defendBase);
                    defended = true;
                }
                else
                {
                    //3 -  COMPROBAR UNIDADES FUERA DEL PERIMETRO DE LA BASE
                    if (!isInBaseRange(ally, baseCoords) && !alreadyComingToBase(ally))
                    {
                        Vector2  closestPoint = getUnitPointOnBase(ally, baseCoords);
                        ActionGo goToBase     = new ActionGo(ally, closestPoint, null);
                        defensiveActions.Add(goToBase);
                    }
                    //4 - AGRUPAR UNIDADES DENTRO DEL PERIMETRO DE LA BASE
                }
            }
        }
        return(defensiveActions);
    }
예제 #4
0
    protected new void Update()
    {
        if (!iaControlled)
        {
            if (!mouseOverUI)
            {
                if (mouseBehav == MOUSE_ACTION_FINAL.SELECT)
                {
                    if (Input.GetMouseButton(0))
                    {
                        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                        {
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                            {
                                PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                                if (!selectedUnits.Contains(character))
                                {
                                    character.selected = true;
                                    characterWithFocus = character;
                                    selectedUnits.Add(character);
                                    ui.showDebugInfo(true);
                                    (ui as UIManagerFinal).actualizeAgentDebugInfo(characterWithFocus);
                                }
                                else
                                {
                                    character.selected = false;
                                    if (character == characterWithFocus)
                                    {
                                        characterWithFocus = null;
                                        ui.showDebugInfo(false);
                                    }
                                    selectedUnits.Remove(character);
                                }
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                            {
                                PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                                if (character != characterWithFocus)
                                {
                                    characterWithFocus = character;
                                    ui.showDebugInfo(true);
                                    ui.actualizeAgentDebugInfo(character);
                                }
                            }
                        }
                        else
                        {
                            foreach (PersonajePlayer person in selectedUnits)
                            {
                                person.selected = false;
                            }
                            selectedUnits.Clear();
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                            {
                                PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                                character.selected = true;
                                characterWithFocus = character;
                                selectedUnits.Add(character);
                                ui.showDebugInfo(true);
                                (ui as UIManagerFinal).actualizeAgentDebugInfo(characterWithFocus);
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                            {
                                PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                                if (character != characterWithFocus)
                                {
                                    characterWithFocus = character;
                                    ui.showDebugInfo(true);
                                    ui.actualizeAgentDebugInfo(character);
                                }
                            }
                            else
                            {
                                if (characterWithFocus != null)
                                {
                                    characterWithFocus = null;
                                    ui.showDebugInfo(false);
                                }
                            }
                        }
                        ui.actualizeUserButtons(allPossibleActions());
                    }
                }
                else if (mouseBehav == MOUSE_ACTION_FINAL.MOVE)
                {
                    if (selectedUnits.Count > 0)
                    {
                        if (Input.GetMouseButton(0))
                        {
                            RaycastHit hit;

                            /*if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 9))
                             * {
                             *  return;
                             * }
                             * else */

                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                            {
                                PersonajeBase enemigo = hit.collider.GetComponent <PersonajeBase>();
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    AccionCompuesta ac = TacticalModule.createAttackingAction(person, enemigo);
                                    if (person.currentFormacion != null)
                                    {
                                        Formacion formation = person.currentFormacion;
                                        if (person.currentFormacion.lider == person)
                                        {
                                            formation.disbandGrid();
                                            for (int i = 0; i < formation.getMiembros.Length; i++)
                                            {
                                                if (formation.getMiembros[i] != null)
                                                {
                                                    AccionCompuesta attackMachaka = TacticalModule.createAttackingAction(formation.getMiembros[i], enemigo);
                                                    formation.getMiembros[i].accion = attackMachaka;
                                                    formation.getMiembros[i].accion.doit();
                                                }
                                            }
                                            formaciones.Remove(formation);
                                        }
                                        else
                                        {
                                            formation.removeMiembro(person);
                                            person.currentFormacion = null;
                                            person.accion           = ac;
                                            person.accion.doit();
                                        }
                                    }
                                    else
                                    {
                                        person.accion = ac;
                                        person.accion.doit();
                                    }
                                }
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 14))
                            {
                                Vector2 baseToGo = positionToGrid(hit.collider.transform.parent.position);
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    ActionGo gotobase = new ActionGo(person, TacticalModule.getUnitPointOnBaseStatic(person, baseToGo, gm.getAllies()), null);
                                    if (person.currentFormacion != null)
                                    {
                                        Formacion formation = person.currentFormacion;
                                        if (person.currentFormacion.lider == person)
                                        {
                                            formation.disbandGrid();
                                            for (int i = 0; i < formation.getMiembros.Length; i++)
                                            {
                                                if (formation.getMiembros[i] != null)
                                                {
                                                    ActionGo gotobaseMachakas = new ActionGo(formation.getMiembros[i], TacticalModule.getUnitPointOnBaseStatic(formation.getMiembros[i], baseToGo, gm.getAllies()), null);
                                                    formation.getMiembros[i].accion = gotobaseMachakas;
                                                    formation.getMiembros[i].accion.doit();
                                                }
                                            }
                                            formaciones.Remove(formation);
                                        }
                                        else
                                        {
                                            formation.removeMiembro(person);
                                            person.currentFormacion = null;
                                            person.accion           = gotobase;
                                            person.accion.doit();
                                        }
                                    }
                                    else
                                    {
                                        person.accion = gotobase;
                                        person.accion.doit();
                                    }
                                }
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                            {
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    Vector2 posicionDestino = positionToGrid(hit.point);
                                    Vector2 posicionOrigen  = positionToGrid(person.posicion);

                                    ActionGo moverse = new ActionGo(person, posicionDestino, null);

                                    if (person.currentFormacion != null)
                                    {
                                        Formacion formation = person.currentFormacion;
                                        if (person.currentFormacion.lider != person)
                                        {
                                            formation.removeMiembro(person);
                                            person.currentFormacion = null;
                                        }
                                        person.accion = moverse;
                                        person.accion.doit();
                                    }
                                    else
                                    {
                                        person.accion = moverse;
                                        person.accion.doit();
                                    }
                                }
                            }
                        }
                    }
                }
                else if (mouseBehav == MOUSE_ACTION_FINAL.FORM_T || mouseBehav == MOUSE_ACTION_FINAL.FORM_S || mouseBehav == MOUSE_ACTION_FINAL.FORM_R)
                {
                    if (selectedUnits.Count > 0)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                            {
                                // PARA FORMACIONES
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    if (person.currentFormacion != null)
                                    {
                                        formaciones.Remove(person.currentFormacion);
                                        person.currentFormacion.disbandGrid();
                                    }
                                }
                                //Asignamos el lider que clicamos
                                PersonajeBase lider = hit.collider.gameObject.GetComponent <PersonajeBase>();

                                Formacion formacion = null;

                                switch (mouseBehav)
                                {
                                case MOUSE_ACTION_FINAL.FORM_T:
                                    formacion = new FormacionTriangulo(lider);
                                    break;

                                case MOUSE_ACTION_FINAL.FORM_S:
                                    formacion = new FormacionCuadrado(lider);
                                    break;

                                case MOUSE_ACTION_FINAL.FORM_R:
                                    formacion = new FormacionPorRoles(lider);
                                    break;
                                }
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    person.currentFormacion = formacion;
                                    formacion.addMiembro(person);
                                }
                                lider.currentFormacion = formacion;
                                formacion.formacionASusPuestosAccion();
                                //formacion.formacionASusPuestos();
                                formaciones.Add(formacion);
                            }
                        }
                    }
                }
                else if (mouseBehav == MOUSE_ACTION_FINAL.ROUTE_SET)
                {
                    if (selectedUnits.Count > 0)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            RaycastHit hit;
                            if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 11))
                            {
                                foreach (PersonajeBase person in selectedUnits)
                                {
                                    if (person.currentFormacion != null)
                                    {
                                        formaciones.Remove(person.currentFormacion);
                                        person.currentFormacion.disbandGrid();
                                    }
                                }
                                setRouteOnUnits();
                                pathToSet.Clear();
                                setMouseBehaviour(0);
                                ui.selectMouseOption(0);
                            }
                            else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 10))
                            {
                                if (pathToSet.Count == 0)
                                {
                                    foreach (PersonajeBase unit in selectedUnits)
                                    {
                                        foreach (Transform routeElem in unit.routeMarks)
                                        {
                                            Destroy(routeElem.gameObject);
                                        }
                                    }
                                }
                                pathToSet.Add(hit.point);
                                foreach (PersonajeBase unit in selectedUnits)
                                {
                                    GameObject routeMark = Instantiate(routeMarkPrefab, unit.routeMarks);
                                    routeMark.transform.position = new Vector3(hit.point.x, 0.05f, hit.point.z);
                                    if (pathToSet.Count > 1)
                                    {
                                        GameObject routeLine = Instantiate(routeLinePrefab, unit.routeMarks);
                                        routeLine.GetComponent <FlechaDeRutaDelegate>().setRouteDirection(pathToSet[pathToSet.Count - 2], pathToSet[pathToSet.Count - 1]);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        else
        {
            if (Input.GetMouseButton(0))
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    RaycastHit hit;
                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                    {
                        PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                        if (!selectedUnits.Contains(character))
                        {
                            character.selected = true;
                            characterWithFocus = character;
                            selectedUnits.Add(character);
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                        else
                        {
                            character.selected = false;
                            if (character == characterWithFocus)
                            {
                                characterWithFocus = null;
                                ui.showDebugInfo(false);
                            }
                            selectedUnits.Remove(character);
                        }
                    }
                    else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                    {
                        PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                        if (character != characterWithFocus)
                        {
                            characterWithFocus = character;
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                    }
                }
                else
                {
                    foreach (PersonajePlayer person in selectedUnits)
                    {
                        person.selected = false;
                    }
                    selectedUnits.Clear();
                    RaycastHit hit;
                    if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 8))
                    {
                        PersonajePlayer character = hit.collider.gameObject.GetComponent <PersonajePlayer>();
                        character.selected = true;
                        characterWithFocus = character;
                        selectedUnits.Add(character);
                        ui.showDebugInfo(true);
                        ui.actualizeAgentDebugInfo(character);
                    }
                    else if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 10000f, 1 << 13))
                    {
                        PersonajeNPC character = hit.collider.gameObject.GetComponent <PersonajeNPC>();
                        if (character != characterWithFocus)
                        {
                            characterWithFocus = character;
                            ui.showDebugInfo(true);
                            ui.actualizeAgentDebugInfo(character);
                        }
                    }
                    else
                    {
                        if (characterWithFocus != null)
                        {
                            characterWithFocus = null;
                            ui.showDebugInfo(false);
                        }
                    }
                }
            }
        }
    }