Exemple #1
0
    public void Attack(float deltaTime, IAttackable target)
    {
        if (target == null || !AttackReady(deltaTime))
        {
            return;
        }

        target.ApplyDamage(tower.AttackDamage);
        attackAbility.Apply(target);
    }
Exemple #2
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        //does it right?
        IAttackable attackable = collision.gameObject.GetComponent <IAttackable>();

        if (attackable != null)
        {
            attackable.ApplyDamage(Damage, gameObject);
        }
    }
Exemple #3
0
    public void Attack(float deltaTime, IAttackable target)
    {
        if (target == null || !AttackReady(deltaTime))
        {
            return;
        }

        float damage = tower.AttackDamage;

        target.ApplyDamage(damage);
        attackAbility.Apply(target);

        int count = UnitScanner.ScanFor(target.Position, tower.CurrentLevel.aoeRadius, buffer);

        for (int i = 0; i < count; ++i)
        {
            float distance = Vector3.Distance(target.Position, buffer[i].Position);
            buffer[i].ApplyDamage(damage / (distance + 1.0f));
            attackAbility.Apply(buffer[i]);
        }
    }
Exemple #4
0
 public void ApplyDamage(float damage = 0, GameObject causer = null, DamageType type = DamageType.Normal, DamageEffect effect = DamageEffect.None)
 {
     parentAttack.ApplyDamage(damage, causer, type, effect);
 }
Exemple #5
0
    public void OnTriggerEnter2D(Collider2D collision)
    {
        bool        PosisiDepan;
        IAttackable attackable = collision.gameObject.GetComponent <IAttackable>();

        if (collision.gameObject.CompareTag("Player"))
        {
            Vector2 temp = new Vector2(transform.position.x - collision.gameObject.transform.position.x, transform.position.y - collision.gameObject.transform.position.y);
            temp.Normalize();
            if (Mathf.Abs(temp.x) > Mathf.Abs(temp.y))
            {
                if (temp.x == 1)
                {
                    if (collision.gameObject.GetComponent <GayatriCharacter>().direction == Direction.Right)
                    {
                        PosisiDepan = true;
                    }
                    else
                    {
                        PosisiDepan = false;
                    }
                    //Kanan
                }
                else
                {
                    if (collision.gameObject.GetComponent <GayatriCharacter>().direction == Direction.Left)
                    {
                        PosisiDepan = true;
                    }
                    else
                    {
                        PosisiDepan = false;
                    }
                    //Kiri
                }
            }
            else
            {
                if (temp.y == 1)
                {
                    if (collision.gameObject.GetComponent <GayatriCharacter>().direction == Direction.Back)
                    {
                        PosisiDepan = true;
                    }
                    else
                    {
                        PosisiDepan = false;
                    }
                    //Belakang
                }
                else
                {
                    if (collision.gameObject.GetComponent <GayatriCharacter>().direction == Direction.Front)
                    {
                        PosisiDepan = true;
                    }
                    else
                    {
                        PosisiDepan = false;
                    }
                    //Depan
                }
            }

            if (PosisiDepan && collision.gameObject.GetComponent <GayatriCharacter>().isReflect)
            {
                gameObject.SetActive(false);
            }
            else
            {
                attackable.ApplyDamage(damage, gameObject);
                gameObject.SetActive(false);
            }
        }



        //Updated.

        /*
         * Things to do:
         *  - Ngecek posisi dimana bullet itu ketika dibandingkan sama Gayatri
         *  - Normalize
         *  - Dibandingkan dengan Arah Gayatri pada saat itu
         *  - terus kalo iya destroy atau kalo engga apply damage + destroy
         */


        //Previous

        /*
         * Debug.Log("masuk ke sini?");
         * IAttackable attackable = collision.gameObject.GetComponent<IAttackable>();
         * if (attackable != null)
         * {
         *  Debug.Log("Testing_Luar");
         *  if (collision.gameObject.CompareTag("Player") && collision.gameObject.GetComponent<GayatriCharacter>().isReflect)
         *  {
         *      Destroy(gameObject);
         *      return;
         *  }
         *  attackable.ApplyDamage(damage);
         *  //Temporary, nanti ada Poolingnya.
         *  Destroy(gameObject);
         * }
         */
    }
Exemple #6
0
    public void Attacking()
    {
        rigid2D.velocity = Vector2.zero;

        ComboFeedback feedback    = combo_Sys.FilterCombo(comboCounter, senjata);
        ComboEnum     comboPlayer = feedback.combo;

        comboCounter = feedback.counter;

        float TempDamage = 0f;

        Debug.Log("Attacking is " + comboPlayer + " dengan combo " + comboCounter);

        if (comboPlayer == ComboEnum.Perfect)
        {
            TempDamage = (senjata.Damage[comboCounter] / 100f) * Persentase_Perfect;
        }
        else if (comboPlayer == ComboEnum.Good)
        {
            TempDamage = (senjata.Damage[comboCounter] / 100f) * Persentase_Good;
        }
        else if (comboPlayer == ComboEnum.Miss)
        {
            TempDamage = (senjata.Damage[comboCounter] / 100f) * Persentase_Miss;
        }

        // Debug.Log("temp damage "+ TempDamage);

        /*
         *      Manggil Combonya gimana?
         *      Method Combonya -> ComboSystem.FilterCombo(Equipment,ComboBerapa)
         */

        Vector2 _castDir = Vector2.zero;

        switch (direction)
        {
        case Direction.Back:
            _castDir = Vector2.up;
            break;

        case Direction.Front:
            _castDir = Vector2.down;
            break;

        case Direction.Left:
            _castDir = Vector2.left;
            break;

        case Direction.Right:
            _castDir = Vector2.right;
            break;
        }

        rigid2D.AddForce(_castDir * attackLaunch);
        RaycastHit2D[] hits = Physics2D.BoxCastAll(boxCollider2D.transform.position, boxCollider2D.size, 0.0f, _castDir, attackDistance);
        //Debug.Log("Jumlah hits ada "+hits.Length);

        for (int i = 0; i < hits.Length; i++)
        {
            if (hits[i].collider != null && !hits[i].collider.gameObject.Equals(this.gameObject))
            {
                IAttackable attackable = hits[i].collider.gameObject.GetComponent <IAttackable>();
                if (attackable != null)
                {
                    //Debug.Log("Menyerang "+ hits[i].collider.gameObject.name);
                    if (comboPlayer == ComboEnum.Perfect)
                    {
                        attackable.ApplyDamage(TempDamage, gameObject, DamageType.Critical);
                    }
                    else
                    {
                        attackable.ApplyDamage(TempDamage, gameObject, DamageType.Normal);
                    }
                }
            }
        }
        //CancelInvoke("UnAttack");
        //Invoke("UnAttack",senjata.attackSpeed[comboCounter].wait);
    }