예제 #1
0
        public override void Update()
        {
            // TODO: Potential issue to solve here is that if second attack is retriggered too quickly, maybe the
            //     it's downtime wont be detected by dependent listeners?
            // also, don't actually want to block this way. example, dash can cancel attack animation?
            if (primaryAbilityBuffer.IsBlocked())
            {
                return;
            }

            if (primaryAbilityBuffer.IsBufferedInputAvailable(state => state.state == 1))
            {
                // if the player is grounded, block right and left movement input, to allow the ability's movement
                //     control to take over unimpeded.
                if (grounded.Value)
                {
                    // TODO: block the non buffered inputs
                    // rightMovementBuffer.BlockExecution(blockingTime);
                    // leftMovementBuffer.BlockExecution(blockingTime);
                }

                // block self for specified number of frames to prevent re-triggering before desired
                primaryAbilityBuffer.BlockExecution(blockingTime);
                primaryAbilityBuffer.ExecuteBufferOnCondition(state => state.state == 1);

                // Here if hit an npc, don't do primary ability
                Vector2 playerToMouseVector =
                    Input.mousePosition -
                    cameraVariable.Value.WorldToScreenPoint(playerPosition.Value);
                float x = playerToMouseVector.x;
                float y = playerToMouseVector.y;
                if (Mathf.Abs(x) > Mathf.Abs(y))
                {
                    primaryAbilityDirection.SetValue(new Vector2(x > 0 ? 1 : -1, 0));
                }
                else
                {
                    primaryAbilityDirection.SetValue(new Vector2(0, y > 0 ? 1 : -1));
                }

                attacking.SetValue(true);
                return;
            }

            attacking.SetValue(false);
        }
        public override void Update()
        {
            if (grounded.Value)
            {
                _dashAvailable = true;
            }

            if (secondaryAbilityBuffer.IsBlocked())
            {
                if (ceilingHit.Value && dashing.Value)
                {
                    _dashAvailable = false;
                    dashing.SetValue(false);
                }
                return;
            }

            if (_dashAvailable && secondaryAbilityBuffer.IsBufferedInputAvailable(state => state.state == 1))
            {
                secondaryAbilityBuffer.BlockExecution(blockingTime);
                secondaryAbilityBuffer.ExecuteBufferOnCondition(state => state.state == 1);

                dashing.SetValue(true);

                // Here if hit an npc, don't do primary ability
                Vector2 playerToMouseVector = GetPlayerToMouseVector();
                _dashAvailable = false;

                if (grounded.Value)
                {
                    secondaryAbilityDirection.SetValue(
                        GetNearestHorizontalDirection(playerToMouseVector.x)
                        );
                    return;
                }

                secondaryAbilityDirection.SetValue(playerToMouseVector.normalized);
                return;
            }

            dashing.SetValue(false);
        }