예제 #1
0
        public virtual void OnCasting(CastContext ctx)
        {
            if (!CoolDownReady())
            {
                return;
            }
            if (channel)
            {
                HandleChannel(ctx);
                return;
            }

            if (!CastOnRelease() && EnoughEnergy(ctx.caster))
            {
                ConsumeEnergy(ctx.caster);
                NewEffects(new SpellContext()
                {
                    caster      = ctx.caster,
                    deltaTime   = ctx.deltaTime,
                    destination = ctx.destination,
                    origin      = ctx.caster.spellOrigin.position
                });
                EnterCoolDown();
            }
        }
예제 #2
0
        public virtual void OnRelease(CastContext begin, CastContext curr)
        {
            if (channel && channeling)
            {
                StopChanneling();
                EnterCoolDown();
                return;
            }

            if (!CastOnRelease() ||
                !CoolDownReady() ||
                !EnoughEnergy(curr.caster) ||
                distanceOrigin && !EnoughDistance(begin.destination, curr.destination))
            {
                return;
            }

            ConsumeEnergy(curr.caster);
            NewEffects(new SpellContext()
            {
                caster      = curr.caster,
                deltaTime   = curr.deltaTime,
                destination = curr.destination,
                origin      = distanceOrigin ? begin.destination : curr.caster.spellOrigin.position
            });
            EnterCoolDown();
        }
예제 #3
0
        private void UpdateBinding(PlayerSpellInputBinding binding, Vector3 pos, Collider mouseOver)
        {
            var ctx = new CastContext()
            {
                caster      = Player.Local.currPawn,
                destination = pos,
                target      = mouseOver,
                state       = GetState(binding.actionReference.action),
                deltaTime   = Time.deltaTime,
                time        = Time.time,
            };

            switch (ctx.state)
            {
            case CastState.Idle:
                if (binding.onBeginCtx.HasValue && binding.prevCtx.HasValue &&
                    binding.prevCtx.Value.state == CastState.Casting)
                {
                    binding.spell.OnRelease(binding.onBeginCtx.Value, ctx);
                }
                else
                {
                    binding.spell.OnIdle();
                }

                break;

            case CastState.Casting:
                if (!binding.prevCtx.HasValue || binding.prevCtx.Value.state == CastState.Idle)
                {
                    binding.onBeginCtx = ctx;
                }

                binding.spell.OnCasting(ctx);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            binding.prevCtx = ctx;
        }
예제 #4
0
        public virtual void HandleChannel(CastContext ctx)
        {
            if (!channeling)
            {
                if (!CanBeginChannel(ctx.caster))
                {
                    return;
                }

                ConsumeChannelEnergy(ctx.caster, ctx.deltaTime);
                channeling = true;
                channelBeginDestination = ctx.destination;
                UpdateEffects(new SpellContext()
                {
                    caster      = ctx.caster,
                    deltaTime   = ctx.deltaTime,
                    destination = ctx.destination,
                    origin      = distanceOrigin ? channelBeginDestination : ctx.caster.spellOrigin.position
                });
                return;
            }

            if (CanContinueChannel(ctx.caster, ctx.deltaTime))
            {
                ConsumeChannelEnergy(ctx.caster, ctx.deltaTime);
                UpdateEffects(new SpellContext()
                {
                    caster      = ctx.caster,
                    deltaTime   = ctx.deltaTime,
                    destination = ctx.destination,
                    origin      = distanceOrigin ? channelBeginDestination : ctx.caster.spellOrigin.position
                });
                return;
            }

            StopChanneling();
            EnterCoolDown();
        }