コード例 #1
0
    public virtual IEnumerator enemysturn()
    {
        enemyDone = false;
        animateHead(1);
        animateBody(true);

        //take relic if at the spot
        if (thisNode.isThereAnItemHere())
        {
            relic targetrelic = (relic)thisNode.itemInThisNode.GetComponent <relic>();
            heldRelic = targetrelic;
            targetrelic.onTake(false);
            targetrelic.transform.position = transform.position;
        }

        //is this enemy active
        if (!thisNode.nodeOculto)
        {
            unit_parent prey = null;
            listMovementRange();
            Debug.Log(this.gameObject.name + ">>>>>>");
            selector.camScript.focusedObject = this.gameObject; //NEW

            //step 1: get target unit
            //obtener lista de objetivos
            List <unit_parent> allUnits = new List <unit_parent>();
            foreach (GameObject unit in gridMaster.units)
            {
                allUnits.Add((unit_parent)unit.GetComponent(typeof(unit_parent)));
            }
            //restablecer aggro
            foreach (unit_parent upa in allUnits)
            {
                upa.aggro = 0;
            }
            if (allUnits.Count >= 1)
            {
                //añadir aggro segun criterio
                allUnits.OrderBy(item => item.health).FirstOrDefault().aggro++;
                foreach (unit_parent upa in allUnits)
                {
                    if (upa.heldRelic != null)
                    {
                        upa.aggro += 3;
                    }

                    if (upa.health < this.UnitPower)
                    {
                        upa.aggro += 2;
                    }

                    if (highLightAttackableNodes(upa.thisNode))
                    {
                        upa.aggro += 7;
                    }
                }
                //el de mas aggro es el objetivo
                //prey = allUnits.LastOrDefault();
                prey = allUnits.OrderByDescending(item => item.aggro).FirstOrDefault();
            }


            //step 2: make path to target
            if (prey != null)
            {
                List <Node> attackPath = null;
                attackPath = pathToUnit(prey.thisNode, this.thisNode, 100, true);
                Debug.Log(this.gameObject.name + " path asigned");

                if (attackPath != null && attackPath.Count() > 0)
                {
                    int i = 0;
                    //step 3: move there
                    while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                    {
                        //Debug.Log(this.gameObject.name + " moving to prey[" + attackPath[i].gridPoint + "]");
                        this.thisNode = attackPath[i];
                        this.updatePosition();
                        //wait a bit between movements
                        float time = 0.2f;
                        float ix   = 0.0f;
                        float rate = 4.0f / time;
                        while (ix < 4.0f)
                        {
                            ix += Time.deltaTime * rate;
                            yield return(null);
                        }
                        //yield return new WaitForSeconds(1);
                        i++;
                    }
                }
                else
                {
                    if (attackPath == null)
                    {
                        Debug.Log(this.gameObject.name + " attackPath null");
                    }
                    else
                    {
                        Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                    }
                }

                //step 4: attack
                if (
                    (thisNode.upNode != null && thisNode.upNode.Equals(prey.thisNode)) ||
                    (thisNode.leftNode != null && thisNode.leftNode.Equals(prey.thisNode)) ||
                    (thisNode.rightNode != null && thisNode.rightNode.Equals(prey.thisNode)) ||
                    (thisNode.downNode != null && thisNode.downNode.Equals(prey.thisNode))
                    )
                {
                    animateHead(2);
                    prey.health -= UnitPower;
                    prey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                    if (prey.health <= 0)
                    {
                        //Destroy(prey.gameObject);
                        prey.getRekt();
                    }
                    yield return(new WaitForSeconds(0.5f));
                }
            }
        }
        else
        {
            Debug.Log(this.gameObject.name + " sleeping");
        }
        yield return(null);

        enemyDone = true;
        selector.camScript.focusedObject = null;
        animateHead(0);
        animateBody(false);
    }
コード例 #2
0
    public override IEnumerator enemysturn()
    {
        enemyDone = false;
        if (recovering)
        {
            respawnIn--;
            if (!thisNode.nodeOculto)
            {
                selector.camScript.focusedObject = this.gameObject;
            }
            else
            {
                selector.camScript.focusedObject = null;
            }
            if (respawnIn <= 0)
            {
                health     = maxHealth;
                recovering = false;
            }
            animateHead(respawnIn);
            animateMain("sphinx_rest");
            yield return(new WaitForSeconds(1.5f));
        }
        else
        {
            //normal enemy ai
            //take relic if at the spot
            if (thisNode.isThereAnItemHere())
            {
                relic targetrelic = (relic)thisNode.itemInThisNode.GetComponent <relic>();
                heldRelic = targetrelic;
                targetrelic.onTake(false);
                targetrelic.transform.position = transform.position;
            }

            //is this enemy active
            unit_parent prey = null;
            listMovementRange();
            Debug.Log(this.gameObject.name + ">>>>>>");
            selector.camScript.focusedObject = this.gameObject; //NEW

            //step 1: get target unit
            //obtener lista de objetivos
            List <unit_parent> allUnits = new List <unit_parent>();
            foreach (GameObject unit in gridMaster.units)
            {
                allUnits.Add((unit_parent)unit.GetComponent(typeof(unit_parent)));
            }
            //restablecer aggro
            foreach (unit_parent upa in allUnits)
            {
                upa.aggro = 0;
            }
            if (allUnits.Count >= 1)
            {
                //añadir aggro segun criterio
                allUnits.OrderBy(item => item.health).FirstOrDefault().aggro++;
                foreach (unit_parent upa in allUnits)
                {
                    if (upa.heldRelic != null)
                    {
                        upa.aggro += 10;
                    }

                    if (upa.health < this.UnitPower)
                    {
                        upa.aggro += 2;
                    }
                    if (upa.health == upa.maxHealth)
                    {
                        upa.aggro += 1;
                    }

                    if (highLightAttackableNodes(upa.thisNode))
                    {
                        upa.aggro += 4;
                    }
                }
                //el de mas aggro es el objetivo
                //prey = allUnits.LastOrDefault();
                prey = allUnits.OrderByDescending(item => item.aggro).FirstOrDefault();
            }


            //step 2: make path to target
            if (prey != null)
            {
                List <Node> attackPath = null;
                attackPath = pathToUnit(prey.thisNode, this.thisNode, 100, true);
                Debug.Log(this.gameObject.name + " path asigned");

                if (attackPath != null && attackPath.Count() > 0)
                {
                    int i = 0;
                    //step 3: move there
                    while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                    {
                        //Debug.Log(this.gameObject.name + " moving to prey[" + attackPath[i].gridPoint + "]");
                        animateMain("sphinx_walk");
                        this.thisNode = attackPath[i];
                        if (!thisNode.nodeOculto)
                        {
                            selector.camScript.focusedObject = this.gameObject;
                        }
                        else
                        {
                            selector.camScript.focusedObject = null;
                        }
                        this.updatePosition();
                        //wait a bit between movements
                        float time = 0.2f;
                        float ix   = 0.0f;
                        float rate = 4.0f / time;
                        while (ix < 4.0f)
                        {
                            ix += Time.deltaTime * rate;
                            yield return(null);
                        }
                        //yield return new WaitForSeconds(1);
                        i++;
                    }
                }
                else
                {
                    if (attackPath == null)
                    {
                        Debug.Log(this.gameObject.name + " attackPath null");
                    }
                    else
                    {
                        Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                    }
                }

                //step 4: attack
                if (
                    (thisNode.upNode != null && thisNode.upNode.Equals(prey.thisNode)) ||
                    (thisNode.leftNode != null && thisNode.leftNode.Equals(prey.thisNode)) ||
                    (thisNode.rightNode != null && thisNode.rightNode.Equals(prey.thisNode)) ||
                    (thisNode.downNode != null && thisNode.downNode.Equals(prey.thisNode))

                    )
                {
                    selector.camScript.focusedObject = this.gameObject;
                    if (thisNode.nodeOculto)
                    {
                        thisNode.revealNode();
                    }
                    prey.health -= UnitPower;
                    prey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                    if (prey.health <= 0)
                    {
                        Node preynode = prey.thisNode;
                        prey.getRekt();
                        preynode.burryNode();
                    }
                    animateMain("sphinx_attack");
                    yield return(new WaitForSeconds(0.5f));

                    selector.camScript.focusedObject = null;
                }
                else
                {
                    // como la esfinge prioriza al que tenga una reliquia tiende a ignorar enemigos en la via, asi que se le da un target secundario
                    //prey is out of range but attack something else if there is
                    unit_parent secondprey = null;
                    foreach (Node nn in thisNode.getVecinos())
                    {
                        if (nn.isThereAUnitHere())
                        {
                            if (secondprey == null)
                            {
                                secondprey = nn.unitInThisNode;
                            }
                            else
                            {
                                if (nn.unitInThisNode.health < secondprey.health)
                                {
                                    secondprey = nn.unitInThisNode;
                                }
                            }
                        }
                    }
                    if (secondprey != null)
                    {
                        if (thisNode.nodeOculto)
                        {
                            thisNode.revealNode();
                        }
                        secondprey.health -= UnitPower;
                        secondprey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                        if (secondprey.health <= 0)
                        {
                            Node preynode = secondprey.thisNode;
                            secondprey.getRekt();
                            preynode.burryNode();
                        }
                        yield return(new WaitForSeconds(0.5f));
                    }
                }
                animateMain("sphinx_ok");
            }

            yield return(null);

            enemyDone = true;
        }
        yield return(null);

        enemyDone = true;
        selector.camScript.focusedObject = null;
    }
コード例 #3
0
    public override IEnumerator enemysturn()
    {
        enemyDone = false;
        animateHead(1);

        //take relic if at the spot
        //turns out having the roaming enemy hold a relic wasnt a good idea

        /*if (thisNode.isThereAnItemHere()) {
         *  relic targetrelic = (relic)thisNode.itemInThisNode.GetComponent<relic>();
         *  heldRelic = targetrelic;
         *  targetrelic.onTake(false);
         *  targetrelic.transform.position = transform.position;
         * }*/

        //thief walks trough walls
        if (true)
        {
            unit_parent prey = null;
            unit_HQ     HQ   = selector.unitHQ_code;
            listMovementRange();
            Debug.Log(this.gameObject.name + ">>>>>>");

            /*if (!thisNode.nodeOculto) {
             *  selector.camScript.focusedObject = this.gameObject;
             * }*/

            //step 1: get target unit
            unit_parent[] weakUnits = GameObject.FindObjectsOfType <unit_parent>();
            foreach (unit_parent unit in weakUnits)
            {
                Debug.Log(this.gameObject.name + " vs " + unit.name);
                if (highLightAttackableNodes(unit.thisNode) && (unit.health <= UnitPower || unit.attackPower == 0))
                {
                    if (prey == null)
                    {
                        prey = unit;
                        Debug.Log(this.gameObject.name + " first prey");
                    }
                    else
                    {
                        if (prey.heldRelic != null)
                        {
                            if ((unit.heldRelic != null) && unit.health < prey.health)
                            {
                                prey = unit;
                                Debug.Log(this.gameObject.name + " new target, weaker, relic");
                            }
                        }
                        else
                        {
                            if (unit.heldRelic != null)
                            {
                                prey = unit;
                                Debug.Log(this.gameObject.name + " new target, relic");
                            }
                            else
                            {
                                if (unit.health < prey.health)
                                {
                                    prey = unit;
                                    Debug.Log(this.gameObject.name + " new target, weaker");
                                }
                                else
                                {
                                    Debug.Log(this.gameObject.name + " no change");
                                }
                            }
                        }
                    }
                }
                else
                {
                    Debug.Log(this.gameObject.name + " out of reach, lets raid hq");
                }
            }


            //step 2: make path to target
            if (prey != null)
            {
                List <Node> attackPath = null;
                attackPath = pathToUnit(prey.thisNode, this.thisNode, 100, true);
                Debug.Log(this.gameObject.name + " path asigned");

                if (attackPath != null && attackPath.Count() > 0)
                {
                    int i = 0;
                    //step 3: move there
                    while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                    {
                        //Debug.Log(this.gameObject.name + " moving to prey[" + attackPath[i].gridPoint + "]");
                        this.thisNode = attackPath[i];
                        if (!thisNode.nodeOculto)
                        {
                            selector.camScript.focusedObject = this.gameObject;
                        }
                        else
                        {
                            selector.camScript.focusedObject = null;
                        }
                        this.updatePosition();
                        //wait a bit between movements
                        float time = 0.2f;
                        float ix   = 0.0f;
                        float rate = 4.0f / time;
                        while (ix < 4.0f)
                        {
                            ix += Time.deltaTime * rate;
                            yield return(null);
                        }
                        //yield return new WaitForSeconds(1);
                        i++;
                    }
                }
                else
                {
                    if (attackPath == null)
                    {
                        Debug.Log(this.gameObject.name + " attackPath null");
                    }
                    else
                    {
                        Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                    }
                }

                //step 4: attack
                if (
                    !thisNode.nodeOculto && (
                        (thisNode.upNode != null && thisNode.upNode.Equals(prey.thisNode)) ||
                        (thisNode.leftNode != null && thisNode.leftNode.Equals(prey.thisNode)) ||
                        (thisNode.rightNode != null && thisNode.rightNode.Equals(prey.thisNode)) ||
                        (thisNode.downNode != null && thisNode.downNode.Equals(prey.thisNode))
                        )
                    )
                {
                    prey.health -= UnitPower;
                    animateHead(2);
                    prey.gameObject.GetComponent <Animator>().Play("unitHitAnimation");
                    if (prey.health <= 0)
                    {
                        prey.getRekt();
                    }
                    yield return(new WaitForSeconds(0.5f));
                }
            }
            else
            {
                //Step 2 alternative, attack HQ
                if (!stolenLoot)
                {
                    List <Node> attackPath = null;
                    attackPath = pathToUnit(HQ.thisNode, this.thisNode, 100, true);
                    Debug.Log(this.gameObject.name + " path asigned to hq");

                    if (attackPath != null && attackPath.Count() > 0)
                    {
                        int i = 0;
                        //step 3: move there
                        while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                        {
                            this.thisNode = attackPath[i];
                            if (!thisNode.nodeOculto)
                            {
                                selector.camScript.focusedObject = this.gameObject;
                            }
                            else
                            {
                                selector.camScript.focusedObject = null;
                            }
                            this.updatePosition();
                            float time = 0.2f;
                            float ix   = 0.0f;
                            float rate = 4.0f / time;
                            while (ix < 4.0f)
                            {
                                ix += Time.deltaTime * rate;
                                yield return(null);
                            }
                            i++;
                        }
                    }
                    else
                    {
                        if (attackPath == null)
                        {
                            Debug.Log(this.gameObject.name + " attackPath null");
                        }
                        else
                        {
                            Debug.Log(this.gameObject.name + " attackPath count " + attackPath.Count);
                        }
                    }


                    //step 4: STEAL
                    if (
                        !thisNode.nodeOculto && (
                            (thisNode.upNode != null && thisNode.upNode.Equals(HQ.thisNode)) ||
                            (thisNode.leftNode != null && thisNode.leftNode.Equals(HQ.thisNode)) ||
                            (thisNode.rightNode != null && thisNode.rightNode.Equals(HQ.thisNode)) ||
                            (thisNode.downNode != null && thisNode.downNode.Equals(HQ.thisNode))
                            )
                        )
                    {
                        if (steal(HQ))
                        {
                            yield return(new WaitForSeconds(0.5f));
                        }
                    }
                }
                else
                {
                    if (originNest != null)
                    {
                        List <Node> attackPath = null;
                        attackPath = pathToUnit(originNest.thisNode, this.thisNode, 100, false);
                        Debug.Log(this.gameObject.name + " path asigned to nest");

                        if (attackPath != null && attackPath.Count() > 0)
                        {
                            int i = 0;
                            //step 3: move there
                            while ((i < attackPath.Count) && (i < maxWalkDistance + 1))
                            {
                                this.thisNode = attackPath[i];
                                if (!thisNode.nodeOculto)
                                {
                                    selector.camScript.focusedObject = this.gameObject;
                                }
                                else
                                {
                                    selector.camScript.focusedObject = null;
                                }
                                this.updatePosition();
                                float time = 0.2f;
                                float ix   = 0.0f;
                                float rate = 4.0f / time;
                                while (ix < 4.0f)
                                {
                                    ix += Time.deltaTime * rate;
                                    yield return(null);
                                }
                                i++;
                            }
                        }
                        else
                        {
                            if (attackPath == null)
                            {
                                Debug.Log(this.gameObject.name + " escape path null");
                            }
                            else
                            {
                                Debug.Log(this.gameObject.name + " escape path count " + attackPath.Count);
                            }
                        }

                        //step 4-alt: escape
                        if (thisNode.Equals(originNest.thisNode))
                        {
                            Debug.Log("enemy escaped");
                            if (heldRelic != null)
                            {
                                heldRelic.transform.position = this.transform.position;
                                heldRelic.onReveal();
                                heldRelic = null;
                                Debug.Log("relic dropped");
                            }
                            yield return(new WaitForSeconds(0.2f));

                            stillVisible = false;
                            yield return(new WaitForSeconds(0.2f));

                            enemyDone = true;
                            yield return(null);

                            Destroy(this.gameObject);
                        }
                    }
                }
            }
        } /*else {
           * Debug.Log(this.gameObject.name + " sleeping");
           * }*/

        animateHead(0);
        yield return(null);

        enemyDone = true;
        selector.camScript.focusedObject = null;
    }