示例#1
0
    void OnTriggerEnter2D(Collider2D collider)
    {
        // if the player collides with any of the below gameObjects
        // Get the gameObjects damage value and take away from health bar
        Enemy    enemy    = collider.gameObject.GetComponent <Enemy>();
        EnemyAI  enemyAI  = collider.gameObject.GetComponent <EnemyAI>();
        BulletAI bulletAi = collider.GetComponent <BulletAI>();

        if (enemy)
        {
            Hit(enemy.GetDamage());
            enemy.Hit();
        }

        if (enemyAI)
        {
            Hit(enemyAI.GetDamage());
            enemyAI.Hit();
        }

        if (bulletAi)
        {
            Hit(bulletAi.GetDamage());
            bulletAi.Hit();
        }
    }
示例#2
0
    //multi attack for whimsical tower
    private void MultiAttack()
    {
        if (timeSinceAttack >= stats.AttackSpeed)
        {
            for (int i = 0; i < multiEnemiesInRange.Count; i++)
            {
                if (multiEnemiesInRange.Count > 0 && multiEnemiesInRange[i] != null && i < whims_maxTargets)
                {
                    BulletAI newBullet = Instantiate(bullet, transform.position, UnityEngine.Quaternion.identity, multiEnemiesInRange[i].transform).GetComponent <BulletAI>();
                    newBullet.BulletDamage = stats.Attack;
                    ElementTypes[] ttypes = { stats.Element, stats.ImmutableElement };
                    newBullet.BulletType   = ttypes;
                    newBullet.StatusEffect = chaosModOn;
                    newBullet.tower        = transform;
                }
                else if (multiEnemiesInRange.Count > 0 && i < whims_maxTargets)
                {
                    multiEnemiesInRange.RemoveAt(i);
                    i--;
                }
            }

            timeSinceAttack = 0;
            shootSound.Play();
        }
        else
        {
            timeSinceAttack += Time.fixedDeltaTime;
        }
    }
示例#3
0
    public void Shoot()
    {
        if (reloadTimer >= reloadTime)
        {
            reloadTimer = 0.0f;

            PlaySound("shoot");
            currentBulletAI.SetMoveDirectionAndDamage(GameManager.Instance.GetCameraMain().ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 20.0f)), weaponDamage);
            currentBulletAI = null;

            ShowBullet();
        }
    }
示例#4
0
    /// <summary>
    /// Нахождение выключеной не занятой пули и помещение её в слот для выстрела.
    /// </summary>
    private void ShowBullet()
    {
        for (int i = 0; i < bulletPoolGO.Count; i++)
        {
            if (!bulletPoolGO[i].activeSelf)
            {
                bulletPoolGO[i].SetActive(true);
                bulletPoolTR[i].position = shootPointTR.position;
                currentBulletAI          = bulletPool_AI[i];

                break;
            }
        }
    }
示例#5
0
    /// <summary>
    /// 对随机敌人进行打击
    /// </summary>
    void DoAttack()
    {
        float interval = mItem.Attributes[Lv - 1][1];
        int   damage   = (int)mItem.Attributes[Lv - 1][0];

        if (Time.time - lastAttackTime < interval || GameController.Instance.mStatus != GameStatus.Gaming)
        {
            return;
        }
        EnemyAI enemy = GameController.Instance.GetRandomEnemy();

        if (enemy == null)
        {
            return;
        }

        lastAttackTime = Time.time;
        BulletAI ai = Instantiate(Effect).GetComponent <BulletAI>();

        ai.transform.position = transform.position;
        ai.transform.parent   = EffectParent.transform;
        ai.SetTarget(enemy, damage);
    }
示例#6
0
    //shoot bullets at enemies when they enter range
    private void ShootAt(Transform target, int statusEffect)
    {
        if (timeSinceAttack >= stats.AttackSpeed)
        {
            BulletAI newBullet = Instantiate(bullet, transform.position, UnityEngine.Quaternion.identity, target.transform).GetComponent <BulletAI>();
            newBullet.BulletDamage = stats.Attack;
            ElementTypes[] ttypes = { stats.Element, stats.ImmutableElement };
            newBullet.BulletType   = ttypes;
            newBullet.StatusEffect = statusEffect + chaosModOn;
            newBullet.tower        = transform;
            timeSinceAttack        = 0;
            shootSound.Play();

            if (lightning_challenge && stats.ImmutableElement == ElementTypes.Lightning && target.transform.GetComponentsInChildren <BulletAI>().Length >= 10)
            {
                int numLightningBullets = 0;

                foreach (BulletAI bullet in target.transform.GetComponentsInChildren <BulletAI>())
                {
                    if (bullet.name.Contains("lightning"))
                    {
                        numLightningBullets++;
                    }
                }

                if (numLightningBullets >= 10)
                {
                    //FindObjectOfType<ChallengeManager>().SaveChallengeState("lightningskill");
                    lightning_challenge = false;
                }
            }
        }
        else
        {
            timeSinceAttack += Time.fixedDeltaTime;
        }
    }
    //take damage from bullets
    private void OnTriggerEnter2D(Collider2D collision)
    {
        //only trigger if it is a bullet that is targeting this enemy
        if (collision.transform.tag == "bullet" && collision.transform.IsChildOf(transform))
        {
            BulletAI bullet       = collision.gameObject.GetComponent <BulletAI>();
            float    beforeHealth = health;
            health -= bullet.DamageToDeal(type);
            float preChaosHealth = health;

            switch (bullet.StatusEffect)
            {
            //earth tower
            case 1:
                slowed    = true;
                slowTimer = 2;
                //see game_balancing.txt for information on this equation
                slowAmount = (1 / maxHealth) * (maxHealth - bullet.DamageToDeal(ElementTypes.Error));
                moveSpeed *= slowAmount;

                //earth challenge
                if (earth_challenge && !challengeManager.earthChallengeCounter.Contains(this))
                {
                    challengeManager.earthChallengeCounter.Add(this);

                    if (challengeManager.earthChallengeCounter.Count >= 10)
                    {
                        //challengeManager.SaveChallengeState("earthskill");
                        earth_challenge = false;
                    }
                }
                break;

            //nature tower
            case 2:
                stunned   = true;
                stunTimer = bullet.DamageToDeal(ElementTypes.Error) / 3f;
                moveSpeed = 0;

                //nature challenge
                if (firstTimeStunned)
                {
                    nature_challenge_pos = transform.position;
                    firstTimeStunned     = false;
                }
                break;

            //chaos tower
            case 3:
                health  = beforeHealth - (beforeHealth - health) * .1f;
                health -= maxHealth * .1f;
                break;

            //earth + chaos tower
            case 4:
                slowed     = true;
                slowTimer  = 2;
                slowAmount = (1 / maxHealth) * (bullet.DamageToDeal(ElementTypes.Error) - maxHealth);
                moveSpeed *= slowAmount;
                health     = beforeHealth - (beforeHealth - health) * .1f;
                health    -= maxHealth * .1f;

                //earth challenge
                if (earth_challenge && !challengeManager.earthChallengeCounter.Contains(this))
                {
                    challengeManager.earthChallengeCounter.Add(this);

                    if (challengeManager.earthChallengeCounter.Count >= 10)
                    {
                        //challengeManager.SaveChallengeState("earthskill");
                        earth_challenge = false;
                    }
                }
                break;

            //nature + chaos tower
            case 5:
                stunned   = true;
                stunTimer = bullet.DamageToDeal(ElementTypes.Error) / 3f;
                moveSpeed = 0;
                health    = beforeHealth - (beforeHealth - health) * .1f;
                health   -= maxHealth * .1f;

                //nature challenge
                if (firstTimeStunned)
                {
                    nature_challenge_pos = transform.position;
                    firstTimeStunned     = false;
                }
                break;

                //currently if an earth bullet and nature bullet hit an enemy on the same frame i think only one of them will happen
                //idk how to fix this since it would be 2 different objects that cant interact with each other
                //i also dont know if only one of them will happen or if it will be fine and both will happen
                //i kind of assume that because they're two different objects it will work fine
                //but i dont know until i test it and im not sure how to force 2 bullets to hit an enemy on the same frame
            }

            //do effects of special enemies
            switch (enemyClass)
            {
            //knight bonus damage skill
            case EnemyClass.Knight:
                health -= (beforeHealth - preChaosHealth) * knightBonusDamage;
                break;

            //gain a shield for 5 seconds after being hit 3 times
            case EnemyClass.Paladin:
                if (paladin_shield_timer <= 0)
                {
                    paladin_shield_count++;
                }
                else
                {
                    health = beforeHealth;
                }

                if (paladin_shield_count >= 3)
                {
                    paladin_shield_timer = paladinShieldMaxTime;
                    Color palCol = paladin_shield.color;
                    palCol.a             = 1;
                    paladin_shield.color = palCol;
                    paladin_shield_count = 0;
                }
                break;

            //increase speed and attack based on missing health
            case EnemyClass.Assassin:
                moveSpeed = assassin_original_speed + ((maxHealth * 5 - health * 6) / maxHealth) + 1;                                                                        //as health approaches 0, speed approaches +6
                realSpeed = moveSpeed;
                attack    = assassin_original_attack + ((maxHealth * enemyWave * assassinMultiplierSkill - health * (enemyWave * assassinMultiplierSkill - 1)) / maxHealth); //health go boo attack go woo
                break;

            //ignores movement impairing effects and heals when hit by them
            case EnemyClass.Succubus:
                if (slowed || stunned)
                {
                    health   += maxHealth * succubusHealPercent;
                    slowed    = false;
                    stunned   = false;
                    moveSpeed = realSpeed;

                    Color succCol = succubus_kiss.color;
                    succCol.a           = 1;
                    succubus_kiss.color = succCol;
                    succubus_kiss_timer = .25f;

                    if (health > maxHealth)
                    {
                        health = maxHealth;
                    }
                }
                break;

            //takes less damage the farther the bullet travels
            case EnemyClass.Armorer:
                float dist      = Vector3.Distance(transform.position, bullet.tower.position);
                float damageMod = (51 - dist) / 50;

                if (bullet.tower.GetComponent <TowerAI>().Range / 2 > dist)
                {
                    health -= (beforeHealth - health) * armorerBonusDamage;
                }

                health = beforeHealth - ((beforeHealth - health) * damageMod);
                break;

            //takes no damage if the damage is less than 25% of its max health
            case EnemyClass.Warlock:
                if ((beforeHealth - health) / maxHealth < warlockNegateThreshhold)
                {
                    health = beforeHealth;
                    Color warCol = warlock_negater.color;
                    warCol.a = 1;
                    warlock_negater.color = warCol;
                    warlock_negater_timer = .25f;
                }
                break;
            }

            //Debug.LogError(health);

            Destroy(collision.gameObject);
            UpdateHealthBar(health, maxHealth);

            if (health <= 0)
            {
                //chaos challenge
                if (chaos_challenge && preChaosHealth > 0)
                {
                    challengeManager.chaosChallengeCounter++;

                    if (challengeManager.chaosChallengeCounter >= 10)
                    {
                        //challengeManager.SaveChallengeState("chaosskill");
                        chaos_challenge = false;
                    }
                }

                //fire challenge
                if (fire_challenge && enemyClass == EnemyClass.Knight && beforeHealth == maxHealth)
                {
                    //challengeManager.SaveChallengeState("fireskill");
                    fire_challenge = false;
                }

                //nature challenge
                if (nature_challenge && nature_challenge_pos == transform.position)
                {
                    //challengeManager.SaveChallengeState("natureskill");
                    nature_challenge = false;
                }

                //enemypedia
                switch (enemyClass)
                {
                case EnemyClass.Cur:
                    if (!cur_found)
                    {
                        challengeManager.SaveEnemypediaToFile("cur");
                    }
                    break;

                case EnemyClass.Knight:
                    if (!knight_found)
                    {
                        challengeManager.SaveEnemypediaToFile("knight");
                    }
                    break;

                case EnemyClass.Monk:
                    if (!monk_found)
                    {
                        challengeManager.SaveEnemypediaToFile("monk");
                    }
                    break;

                case EnemyClass.Assassin:
                    if (!assassin_found)
                    {
                        challengeManager.SaveEnemypediaToFile("assassin");
                    }
                    break;

                case EnemyClass.Paladin:
                    if (!paladin_found)
                    {
                        challengeManager.SaveEnemypediaToFile("paladin");
                    }
                    break;

                case EnemyClass.Armorer:
                    if (!armorer_found)
                    {
                        challengeManager.SaveEnemypediaToFile("armorer");
                    }
                    break;

                case EnemyClass.Succubus:
                    if (!succubus_found)
                    {
                        challengeManager.SaveEnemypediaToFile("succubus");
                    }
                    break;

                case EnemyClass.Warlock:
                    if (!warlock_found)
                    {
                        challengeManager.SaveEnemypediaToFile("warlock");
                    }
                    break;
                }

                //Debug.LogError("destroyed");
                //Debug.LogError(currency);
                AudioSource deathsound = Instantiate(enemyDeathSound).GetComponent <AudioSource>();
                deathsound.volume = deathSoundVolume;
                Destroy(transform.gameObject);
                currency.CurrentCurrency += (uint)Mathf.FloorToInt(killWorth);
            }
        }
    }