Exemplo n.º 1
0
    public override void Activate()
    {
        /*
         * Transform[] enemyPos = reference.GetEnemyPositions();
         * Transform playerPos = reference.GetPlayerPosition(0);   // WIP
         *
         * int currentCounter = enemyPos.Length / 2;
         * int min = 0;
         * int max = enemyPos.Length;
         *
         * bool found = false;
         *
         * // Find closest target in terms of x-pos (testing). Improve on this later (look up Kd-tree etc)
         * while((min < max) && (!found))
         * {
         *  // Less than
         *  if (playerPos.position.x < enemyPos[currentCounter].position.x)
         *      min = currentCounter + 1;
         *  else if (playerPos.position.x > enemyPos[currentCounter].position.x)    // Greater than
         *      max = currentCounter - 1;
         *  else
         *      found = true;
         *
         *  if (min >= max) // Keep currentCounter
         *      found = true;
         *  else if (!found)
         *      currentCounter = min + max / 2;
         * }*/

        // Very crude
        GameObject[] enemyPositions  = GameObject.FindGameObjectsWithTag("Enemy");
        Transform    playerPosition  = reference.GetPlayerPosition(0);
        float        closestDistance = Mathf.Infinity;
        int          closestEnemy    = -1;

        // Targets whichever in front of the character is facing only. Ignores enemies behind
        for (int i = 0; i < enemyPositions.Length; i++)
        {
            if ((enemyPositions[i].transform.position.x > playerPosition.position.x) && (Mathf.Pow(enemyPositions[i].transform.position.x - playerPosition.position.x, 2) + Mathf.Pow(enemyPositions[i].transform.position.y - playerPosition.position.y, 2) < closestDistance))
            {
                closestDistance = Mathf.Pow(enemyPositions[i].transform.position.x - playerPosition.position.x, 2) + Mathf.Pow(enemyPositions[i].transform.position.y - playerPosition.position.y, 2);
                closestEnemy    = i;
            }
        }

        // Temporary
        if (closestEnemy != -1)
        {
            DamageCalculations.ApplyCalculation(enemyPositions[closestEnemy], parent, power);
            return;
        }
        else
        {
            print("No target");
        }
        return;
    }
Exemplo n.º 2
0
    public override void Activate()
    {
        targets = GameObject.FindGameObjectsWithTag(targetTag);

        for (int i = 0; i < targets.Length; i++)
        {
            if (targets[i].GetComponent <CharacterStats>() != null)
            {
                DamageCalculations.ApplyCalculation(targets[i], parent, power * Random.Range(0.01f, 4f));
            }
        }
    }
Exemplo n.º 3
0
    //string targetTag = "Enemy";

    public override void Activate()
    {
        targets = GameObject.FindGameObjectsWithTag("Enemy");

        for (int i = 0; i < targets.Length; i++)
        {
            if (targets[i].GetComponent <CharacterStats>() != null)
            {
                DamageCalculations.ApplyCalculation(targets[i], parent, power);
            }
        }

        // Do the same with "Boss"
    }
Exemplo n.º 4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        for (int i = 0; i < targets.Length; i++)
        {
            if (collision.gameObject.tag == targets[i])
            {
                DamageCalculations.ApplyCalculation(collision.gameObject, gameObject, power, actions);

                if (numHits == 0)
                {
                    Destroy(gameObject);
                }
                numHits--;
            }
        }
    }
Exemplo n.º 5
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (hitCooldown <= 0)
        {
            for (int i = 0; i < targets.Length; i++)
            {
                if (collision.gameObject.tag == targets[i])
                {
                    if ((instantKill) && (targets[i] != "Boss"))
                    {
                        collision.gameObject.GetComponent <CharacterStats>().SetCurrentStat(1, 0);
                    }

                    DamageCalculations.ApplyCalculation(collision.gameObject, gameObject, power, actions);
                }
            }
        }
    }
Exemplo n.º 6
0
    // LASERS SHOULD HAVE THEIR OWN TAGS AND NOT BE DESTROYED ON BLOCK
    private void OnTriggerEnter2D(Collider2D collision)
    {
        bool triggerCounter = false;

        for (int i = 0; i < tags.Length; i++)
        {
            if (collision.gameObject.tag == tags[i])
            {
                Destroy(collision.gameObject);

                if (variation == 2)
                {
                    triggerCounter = true;
                }
                else if (variation == 1)
                {
                    reference.AddMana(Mathf.CeilToInt(reference.GetMaxMana() * 0.03f));
                }

                numHits--;
                if (numHits <= 0)
                {
                    enabled = false;
                }
            }
        }

        if (triggerCounter)
        {
            // Enemy...might need to change to incorporate boss or even players later
            allTargets = GameObject.FindGameObjectsWithTag("Enemy");

            for (int i = 0; i < allTargets.Length; i++)
            {
                // Take into account stats of the CHARACTER THIS SHIELD IS ATTACHED TO
                if (Mathf.Pow(gameObject.transform.position.x - allTargets[i].transform.position.x, 2) + Mathf.Pow(gameObject.transform.position.y - allTargets[i].transform.position.y, 2) < 400)
                {
                    DamageCalculations.ApplyCalculation(allTargets[i], gameObject, gameObject.GetComponent <CharacterStats>().GetCurrentStat(0) * 0.7f);
                }
            }
        }
    }
Exemplo n.º 7
0
    public override void Stack(StatusEffect sameEffect)
    {
        power += 0.1f;

        if (stackCount < maxStacks)
        {
            stackCount++;
        }

        if (variation == 1)
        {
            stackCount = 0;
            power      = 1; // Damage calculation occurs without the extra damage

            if ((parent != null) && (parent.GetComponent <Projectile>() != null))
            {
                DamageCalculations.ApplyCalculation(gameObject, parent, parent.GetComponent <Projectile>().GetPower() * 3);
            }
        }
    }
Exemplo n.º 8
0
    //called before Start() method, dictionaries, lists etc needs to be created here first before other classes can access them
    //or else they will have nothing to add the objects to and will end up with empty dictionaries and lists.
    void Awake()
    {
        //create a static instance of this game object so it can be accessed by every other class using GameManager.instance.
        //saves having to make a reference to the game manager in each new class or having to create a new instance to pass values to/from.
        //note would have to do proper singleton coding to ensure mutliple of these gamemangers are not created if moving to/from game scenes.
        instance = this;

        abilityElementsDictionary = new Dictionary <AbilityElement, List <BaseAbility> > ();
        abilityDictionary         = new Dictionary <string, BaseAbility> ();
        enemyDictionary           = new Dictionary <string, BaseEnemy> ();

        //used to create a dictionary where the Value section of the dictionary are all the ability element types from the AbilityElement enum
        foreach (AbilityElement element in Enum.GetValues(typeof(AbilityElement)))
        {
            abilityElementsDictionary [element] = new List <BaseAbility> ();
        }

        spawnedEnemies    = new List <GameObject> ();
        playersInPlay     = new List <GameObject> ();
        feedbackText.text = "";

        damageCalc = new DamageCalculations();
    }
Exemplo n.º 9
0
    private void OnDestroy()
    {
        if (debuffObject != null)
        {
            Destroy(debuffObject);
        }

        if (variation == 0)
        {
            if (buffTimer >= 0)
            {
                GameObject[] allEnemies = GameObject.FindGameObjectsWithTag("Enemy");

                // If enemies are in range
                for (int i = 0; i < allEnemies.Length; i++)
                {
                    if (Mathf.Pow(gameObject.transform.position.x - allEnemies[i].transform.position.x, 2) + Mathf.Pow(gameObject.transform.position.y - allEnemies[i].transform.position.y, 2) < 400)
                    {
                        DamageCalculations.ApplyCalculation(allEnemies[i], parent, 1.2f * power);
                    }
                }
            }
        }
    }