Exemplo n.º 1
0
        private bool TrySearchTarget(Vector3 area, ICollection <Actor> ignore, out Actor target)
        {
            var potentialTargets = Physics.OverlapSphere(area, _searchRange, (int)LayerMaskFlag.Entity);

            foreach (var potentialTarget in potentialTargets)
            {
                if (!AbilityHelper.TryGetActor(potentialTarget, out var actor))
                {
                    continue;
                }
                if (!Checker.AllowTarget(actor))
                {
                    continue;
                }
                if (ignore.Contains(actor))
                {
                    continue;
                }

                //TODO when targetable works, add this
                // if (!actor.TryGetComponent<ITargetable>(out _))
                // continue;
                if (!actor.TryGetModule <IDamageable>(out _))
                {
                    continue;
                }

                target = actor;
                return(true);
            }

            target = default;
            return(false);
        }
Exemplo n.º 2
0
        public void CastGroundTarget(Vector3 worldPos)
        {
            var origin         = Self.transform.position;
            var length         = AbilityHelper.GetLineLength(origin, worldPos);
            var boxHalfExtents = new Vector3(_pathWidth, 2f, length);
            var rotation       = AbilityHelper.GetRotation(origin, worldPos);
            var center         = AbilityHelper.GetBoxCenter(origin, boxHalfExtents, rotation);

            var colliders = Physics.OverlapBox(center, boxHalfExtents, rotation, (int)LayerMaskFlag.Entity);

            var atkDamage = Modules.Attackerable.Damage;

            var dmg = new Damage(_bonusDamage + atkDamage, DamageType.Physical,
                                 DamageFlags.Ability | DamageFlags.Attack);

            foreach (var col in colliders)
            {
                if (!AbilityHelper.TryGetActor(col, out var actor))
                {
                    continue;
                }
                if (!Checker.AllowTarget(actor))
                {
                    continue;
                }
                Modules.Attackerable.RawAttack(actor, dmg);
            }

            Modules.Movable.WarpTo(worldPos);
            Modules.Commandable.ClearCommands();
        }
Exemplo n.º 3
0
        public override void ConfirmCast()
        {
            if (!Checker.AllowCast())
            {
                return;
            }

            var ray = AbilityHelper.GetScreenRay();

            if (!AbilityHelper.TryGetWorldOrEntity(ray, out var hit))
            {
                return;
            }
            var unitCast = AbilityHelper.TryGetActor(hit.collider, out var actor);

            if (actor == Self)
            {
                return;
            }
            var position = unitCast
                ? actor.transform.position
                : hit.point;

            if (!CastRange.InRange(position))
            {
                return;
            }

            if (unitCast)
            {
                if (!Checker.AllowTarget(actor))
                {
                    return;
                }

                Checker.DoCast();
                CastObjectTarget(actor);
            }
            else
            {
                Checker.DoCast();
                CastGroundTarget(position);
            }

            Modules.Abilitiable.NotifyAbilityCast(new AbilityEventArgs(Self, Checker.MagicCost.Cost));
        }
Exemplo n.º 4
0
        private void OnAbilityCast(object sender, AbilityEventArgs args)
        {
            var caster = args.Caster;

            if (!Checker.AllowTarget(caster))
            {
                return;
            }

            if (!caster.TryGetModule <IDamageable>(out var damageTarget))
            {
                return;
            }

            var damageValue = _damagePerManaSpent * args.ManaSpent;

            damageValue = Mathf.Max(damageValue, 0f);
            var damage = new Damage(damageValue, DamageType.Pure, DamageFlags.Ability);

            damageTarget.TakeDamage(Self, damage);
        }