Exemple #1
0
        protected bool ExecuteHitbox(ICombatant combatant, uint damage)
        {
            var hb   = Hitbox;
            var xDir = Math.Sign(combatant.FacingDirection.x);

            if (xDir != 0)
            {
                hb.Center.x *= xDir;
            }

            hb.Center += (Vector2)combatant.Transform.position;
            var s = combatant as IGizmosSchedulable;

            if (s != null)
            {
                s.ScheduleGizmos(() => DebugUtil.DrawBounds2D(hb, Color.green));
            }

            var success = false;
            var found   = Physics2D.OverlapBoxAll(hb.Center, hb.Size, 0, HitboxMask);

            foreach (var hit in found)
            {
                var e = hit.GetComponentInParent <ICombatant>();
                if (e != null && e.Ignored)
                {
                    continue;
                }

                if (e == null || e == combatant || !e.CanAttack(combatant))
                {
                    continue;
                }

                Effect.Apply(e);
                success = true;
                if (!SingleEntity)
                {
                    continue;
                }

                return(true);
            }

            return(success);
        }