protected virtual void FixedUpdate()
    {
        colNr = Col.Cast(Vector2.zero, filter, collisions);

        if (colNr > 0)
        {
            for (int i = 0; i < colNr; i++)
            {
                ICanTakeDamage hitObject = collisions[i].transform.GetComponentInParent <ICanTakeDamage>();
                if (hitObject != null)
                {
                    hitObject.GetHit(damage);
                }
            }
        }
        else
        {
            damage.GenerateID();
        }
    }
Example #2
0
    public void DrawHitboxes(Frame currentFrame)
    {
        float dirX = 1;

        if (spr.flipX == true)
        {
            dirX = -1;
        }

        Collider2D[] hit      = new Collider2D[5];
        Vector2      position = transform.position;

        if (previousFrame != currentFrame && currentFrame.newHitID)
        {
            GenerateID();
        }

        for (int i = 0; i < currentFrame.hitboxes.Count; i++)
        {
            currentFrame.hitboxes[i].ID = currentID;

            Vector2 hitBoxPosition = position + new Vector2(currentFrame.hitboxes[i].position.x * dirX,
                                                            currentFrame.hitboxes[i].position.y);

            int number = Physics2D.OverlapCircleNonAlloc(hitBoxPosition, currentFrame.hitboxes[i].radius, hit, hitLayer);

            if (number > 0)
            {
                for (int j = 0; j < number; j++)
                {
                    ICanTakeDamage hitObject = (ICanTakeDamage)hit[j].GetComponentInParent(typeof(ICanTakeDamage));

                    Damage damage = currentFrame.hitboxes[i].GetDamage(spr.flipX).Clone();
                    //damage.attackType = Chr.currentAttackType;

                    damage.hitID    = currentID;
                    damage.Owner    = Chr;
                    damage.position = hitBoxPosition;

                    if (Chr.CurrentAttackBuff != null) //@@@ is null if a projectile hits. Must be changed, since projectile get a buff if an attack is performed while the projectile hits
                    {
                        damage.damageNumber += Chr.CurrentAttackBuff.damageAdd;
                        damage.damageNumber *= Chr.CurrentAttackBuff.damageMulti;
                    }

                    //damage.damageNumber *= Chr.GetCardEffect_DamageMultiplier(damage.attackType);

                    /*
                     * for (int k = 0; k < Chr.cardEffects.Count; k++)
                     * {
                     *  Chr.cardEffects[k].ModifyDamage(damage);
                     * }
                     */


                    if (Chr is Player)
                    {
                        Player player = (Player)Chr;

                        damage.AddDamage(player.soulCharge);
                    }

                    if (hitObject != null)
                    {
                        for (int l = 0; l < Chr.Buffs.Count; l++)
                        {
                            if (Chr.Buffs[l].GetType() == typeof(BuffAddDamageToAttack))
                            {
                                BuffAddDamageToAttack buff = (BuffAddDamageToAttack)Chr.Buffs[l];

                                if (damage.attackType == buff.attackType)
                                {
                                    damage.damageNumber *= (1 + buff.damagePercent);
                                }
                            }
                        }

                        if (hitObject is Character)
                        {
                            Character hitChr = (Character)hitObject;

                            damage.HitPosition = (Chr.transform.position + hitChr.transform.position) / 2f;

                            //hitChr.GetHit(damage);
                            if (ACharacterHit != null)
                            {
                                ACharacterHit(hitChr, damage);
                            }
                        }
                        else if (hitObject is Item)
                        {
                            Item hitItem = (Item)hitObject;

                            hitItem.Owner = Chr;

                            //hitItem.GetHit(damage);
                        }

                        hitObject.GetHit(damage);
                    }
                }
            }
        }

        previousFrame = currentFrame;
    }