Beispiel #1
0
    void ConsumeRessource(Transform target)
    {
        consumeCounter += Time.deltaTime;

        if (consumeCounter >= unitInfo.gatherSpeed)
        {
            target.SendMessage("Consume", unitInfo.gatherTick);
            if (target.GetComponent <Ressource>().getYield() <= 0)
            {
                target.GetComponent <preyAI>().Die(); this.target = null;
            }
            RessourceTypes rt = target.GetComponent <Ressource>().GetRessourceType();

            switch (rt)
            {
            case RessourceTypes.WOOD:
                this.ressourcesQuantity[0] += unitInfo.gatherTick;
                break;

            case RessourceTypes.ANIMAL:
                this.ressourcesQuantity[1] += unitInfo.gatherTick;
                break;

            case RessourceTypes.VEGETAL:
                this.ressourcesQuantity[2] += unitInfo.gatherTick;
                break;

            default:
                break;
            }

            consumeCounter = 0f;
        }
    }
Beispiel #2
0
    private Transform GetNearestRessourcePoint(RessourceTypes ressourceType)
    {
        if (FindObjectsOfType <Ressource>().Length > 0)
        {
            Ressource[]      temp          = FindObjectsOfType <Ressource>();
            List <Ressource> ressourceList = new List <Ressource>();

            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i].GetRessourceType() == ressourceType)
                {
                    ressourceList.Add(temp[i]);
                }
            }

            Transform nearestRessource = ressourceList[0].gameObject.transform;
            float     nearestDistance  = Vector2.Distance(this.gameObject.transform.position, nearestRessource.position);

            foreach (Ressource r in ressourceList)
            {
                float tempDistance = Vector2.Distance(this.gameObject.transform.position, r.gameObject.transform.position);
                if (tempDistance < nearestDistance)
                {
                    nearestDistance  = tempDistance;
                    nearestRessource = r.gameObject.transform;
                }
            }

            return(nearestRessource);
        }
        else
        {
            return(null);
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        attackCounter += Time.deltaTime;

        if (canMove && (target != null || destination != nullVector))
        {
            ComputeMovement();
        }

        //DO STUFF DEPENDING ON TYPE
        if (atDestination)
        {
            rb2d.velocity = Vector2.zero;

            if (target != null && target.gameObject.tag == RESSOURCE_TAG && !isFull)
            {
                ConsumeRessource(target);
            }

            else if (target != null && target.gameObject.tag == DROPPOINT_TAG)
            {
                DropRessources(target);
            }
            else if (target != null && target.gameObject.tag == ENEMY_TAG)
            {
                AttackTarget(target);
            }
            else if (target != null && target.gameObject.tag == PREY_TAG)
            {
                lookingFor = RessourceTypes.ANIMAL;
                if (target.GetComponent <preyAI>().GetHealth() > 0)
                {
                    AttackTarget(target);
                }
                else
                {
                    ConsumeRessource(target);
                }
            }
            else if (target != null && target.gameObject.tag == ENEMYBUILDING_TAG)
            {
                AttackTarget(target);
            }
            else if (target != null && target.gameObject.tag == BUILDABLE_TAG)
            {
                BuildTarget(target);
            }
            else if (target != null && target.gameObject.tag == ENEMYNEXUS_TAG)
            {
                AttackTarget(target);
            }
            else if (destination != nullVector)
            {
                destination = nullVector;
            }
        }
        //Debug.Log(seeker.GetCurrentPath());
        UpdateGFX();
    }
Beispiel #4
0
    private Transform GetNearestRessourcePoint(RessourceTypes ressourceType)
    {
        if (FindObjectsOfType <Ressource>().Length > 0)
        {
            Ressource[]      temp = FindObjectsOfType <Ressource>();
            List <Transform> ressourceLocation = new List <Transform>();
            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i].GetRessourceType() == ressourceType)
                {
                    ressourceLocation.Add(temp[i].gameObject.transform);
                }
            }


            if (ressourceLocation.Count > 0)
            {
                Transform nearestRessource = ressourceLocation[0];
                float     nearestDistance  = Vector2.Distance(this.gameObject.transform.position, nearestRessource.position);

                foreach (Transform r in nearestRessource)
                {
                    float tempDistance = Vector2.Distance(this.gameObject.transform.position, r.position);
                    if (tempDistance < nearestDistance)
                    {
                        nearestDistance  = tempDistance;
                        nearestRessource = r.gameObject.transform;
                    }
                }
                print(nearestRessource);
                lookingFor = ressourceType;

                return(nearestRessource);
            }
            else
            {
                return(null);
            }
        }
        else
        {
            return(null);
        }
    }
Beispiel #5
0
    public void SetTarget(Transform t)
    {
        //Cancel path if existing

        /*if (seeker.GetCurrentPath() != null)
         * {
         *  seeker.CancelCurrentPathRequest();
         *  this.rb2d.velocity = Vector2.zero;
         *
         * }*/
        //ClearPath();

        /*if (path != null)
         * {
         *  OnPathComplete(path);
         *  path = null;
         * }*/

        destination    = nullVector;
        oldDestination = nullVector;

        this.oldTarget = this.target;
        this.target    = t;
        if (t.tag == "Prey")
        {
            lookingFor = RessourceTypes.ANIMAL;
        }
        //   if (t.tag == "Ressource") lookingFor = RessourceTypes.VEGETAL;

        if (this.target != this.oldTarget && this.target.tag != "Enemy" && this.target.tag != "Prey")
        {
            //Debug.Log("test");
            atDestination = false;
            canMove       = true;
        }
        else
        {
            atDestination = false;
            canMove       = true;
        }
        CancelInvoke("UpdatePath");
        InvokeRepeating("UpdatePath", 0f, 0.5f);
    }