Пример #1
0
        public void AttackLogic(InputComponent input, GameTime gameTime)
        {
            if (input.Bindings.TryGetValue(typeof(AttackBehaviorComponent), out var attackBehaviorBinding))
            {
                AttackBehaviorComponent attackBehavior = attackBehaviorBinding as AttackBehaviorComponent;
                SetAttackStates(attackBehavior);

                if (HasDelayedAttack(attackBehavior))
                {
                    input.MovementDirection = Vector2.Zero;
                    CountdownRemainingAttackDelay(attackBehavior, gameTime);
                    TrySpawnDelayedAttack(input, attackBehavior, gameTime);
                    return;
                }
                if (IsInAttackCooldown(attackBehavior))
                {
                    CountdownRemainingAttackCooldown(attackBehavior, gameTime);
                }

                if (!(input.PrimaryAttack || input.SecondaryAttack))
                {
                    return;
                }
                if (attackBehavior.RemainingAttackCooldownMilliseconds > 0)
                {
                    return;
                }

                FindAndStartTriggeredAttack(input, attackBehavior, gameTime);
            }
        }
Пример #2
0
        private void SpawnAttackProjectile(InputComponent input, Point cursor, AttackBehaviorComponent attackBehavior, AttackComponent attack, GameTime gameTime)
        {
            Vector2 cursorDelta;

            if (attack.CursorType == CursorType.Absolute)
            {
                cursorDelta = new Vector2(cursor.X, cursor.Y) - attack.SourcePos.Vector2;
            }
            else //Relative
            {
                cursorDelta = new Vector2(cursor.X, cursor.Y);
            }
            _ecs.RegisterEntity(_ecs.CreateEntity(attack.Projectile,
                                                  position: new Vector2Ref(attack.SourcePos.Vector2 + new Coord2(cursorDelta).ChangePolarLength(attack.PosOffsetInDirection).Cartesian),
                                                  speed: new Coord2(cursorDelta).ChangePolarLength(attack.StartSpeed),
                                                  gameTime: gameTime, allegiance: attack.Allegiance));


            attackBehavior.RemainingAttackCooldownMilliseconds = attack.AttackCooldownMilliseconds;

            if (attack.BlockInput)
            {
                BlockInput(input, gameTime, attack.BlockInputDurationMilliseconds);
            }
            if (attack.SelfKnockback != 0)
            {
                ApplySelfKnockback(input, attack.SelfKnockback, cursorDelta);
            }

            attackBehavior.DelayedAttack = null;
        }
Пример #3
0
 public override void Activate()
 {
     if (Bindings.TryGetValue(typeof(InputComponent), out var binding))
     {
         Input = binding as InputComponent;
     }
 }
Пример #4
0
        private static bool ExecuteBlink(BlinkComponent blink, GameTime gameTime)
        {
            InputComponent input = blink.Input;

            return(ExecuteMovementBlink(blink, input, gameTime) ||
                   ExecuteAttackBlink(blink, input));
        }
Пример #5
0
 private void TrySpawnDelayedAttack(InputComponent input, AttackBehaviorComponent attackBehavior, GameTime gameTime)
 {
     if (attackBehavior.DelayedAttack.RemainingAttackDelayMilliseconds <= 0)
     {
         SpawnAttackProjectile(input, attackBehavior.DelayedAttack.Cursor, attackBehavior, attackBehavior.DelayedAttack.Attack, gameTime);
     }
 }
Пример #6
0
 private void ApplySelfKnockback(InputComponent input, int knockback, Vector2 cursorDelta)
 {
     if (input.Bindings.TryGetValue(typeof(MovementComponent), out var binding))
     {
         MovementComponent movement = binding as MovementComponent;
         movement.Speed.SetVector2(new Coord2(-cursorDelta).ChangePolarLength(knockback).Cartesian);
     }
 }
Пример #7
0
        private static bool ExecuteAttackBlink(BlinkComponent blink, InputComponent input)
        {
            if (blink.Bindings.TryGetValue(typeof(AttackBehaviorComponent), out var attackBinding))
            {
                AttackBehaviorComponent attackBehavior = attackBinding as AttackBehaviorComponent;
            }

            return(false);
        }
Пример #8
0
        private void MovementLogic(InputComponent input)
        {
            if (input.Bindings.TryGetValue(typeof(MovementComponent), out var binding))
            {
                MovementComponent movement = binding as MovementComponent;

                movement.Acceleration.Cartesian.X = input.MovementDirection.X * movement.AccelerationBase;
                movement.Acceleration.Cartesian.Y = input.MovementDirection.Y * movement.AccelerationBase;
            }
        }
Пример #9
0
 private void FindAndStartTriggeredAttack(InputComponent input, AttackBehaviorComponent attackBehavior, GameTime gameTime)
 {
     foreach (var attack in attackBehavior.AttackComponents)
     {
         if (AttackTriggered(input, attack)) // && same attackState
         {
             StartAttack(input, attackBehavior, attack, gameTime);
             break;
         }
     }
 }
Пример #10
0
        private static void ResetInput(InputComponent component)
        {
            component.MovementDirection.X = 0;
            component.MovementDirection.Y = 0;

            component.PrimaryAttack   = false;
            component.SecondaryAttack = false;
            component.SwitchWeapons   = false;
            component.Action          = false;
            component.Blink           = false;
        }
Пример #11
0
 private void PlaceCursorInBehavior(InputComponent input, AttackBehaviorComponent attackBehavior, AttackComponent attack)
 {
     if (attack.CursorType == CursorType.Absolute)
     {
         attackBehavior.Cursor = input.CursorPoint;
     }
     else //Relative
     {
         Point cursor = input.CursorPoint;
         Point source = new Point((int)attack.SourcePos.Vector2.X, (int)attack.SourcePos.Vector2.Y);
         Point delta  = cursor - source;
         attackBehavior.Cursor = delta;
     }
 }
Пример #12
0
        private static bool ExecuteMovementBlink(BlinkComponent blink, InputComponent input, GameTime gameTime)
        {
            if (blink.Bindings.TryGetValue(typeof(MovementComponent), out var movementBinding))
            {
                MovementComponent movement = movementBinding as MovementComponent;
                if (!input.MovementDirection.Equals(Vector2.Zero))
                {
                    SetMovementVariables(blink, movement, input, gameTime);
                    SetMovementBlinkSpeed(blink, movement);
                    return(true);
                }
            }

            return(false);
        }
Пример #13
0
        private void StartAttack(InputComponent input, AttackBehaviorComponent attackBehavior, AttackComponent attack, GameTime gameTime)
        {
            PlaceCursorInBehavior(input, attackBehavior, attack);

            if (attack.IsDelayedAttack)
            {
                attackBehavior.DelayedAttack = new AttackBehaviorComponent.DelayedAttackClass(attack.AttackDelayMilliseconds, attack, attackBehavior.Cursor);
                if (attack.BlockInput)
                {
                    BlockInput(input, gameTime, attack.BlockInputDurationMilliseconds);
                }
            }
            else
            {
                SpawnAttackProjectile(input, attackBehavior.Cursor, attackBehavior, attack, gameTime);
            }
        }
Пример #14
0
        private void ExecuteOrder(IntelligenceComponent intelligence, IntelligenceOrder order, IntelligenceNode node)
        {
            InputComponent input = null;

            if (intelligence.Bindings.TryGetValue(typeof(InputComponent), out var binding))
            {
                input = binding as InputComponent;
            }
            if (input.Blocked)
            {
                return;
            }

            intelligence.State = order.Type;


            if (order.Type == OrderType.AttackPrimary || order.Type == OrderType.AttackSecondary)
            {
                input.CursorPoint      = node.Pos;
                intelligence.TargetPos = node.Pos;
                if (order.Type == OrderType.AttackPrimary)
                {
                    input.PrimaryAttack = true;
                }
                if (order.Type == OrderType.AttackSecondary)
                {
                    input.SecondaryAttack = true;
                }
            }

            if (order.Type == OrderType.Follow || order.Type == OrderType.Move)
            {
                input.MovementDirection = VectorDirection(intelligence.Pos, node.Pos);
                if (order.Type == OrderType.Follow)
                {
                    intelligence.TargetPos = node.Pos;
                }
                if (order.Type == OrderType.Move)
                {
                    intelligence.TargetPos = new Vector2Ref(node.Pos);
                }
            }

            intelligence.UpdateCooldownMilliseconds = order.UpdateCooldownMilliseconds;
        }
Пример #15
0
        private void ResetInputs(IntelligenceComponent intelligence)
        {
            intelligence.TargetPos = null;
            intelligence.State     = OrderType.Null;

            InputComponent input = null;

            if (intelligence.Bindings.TryGetValue(typeof(InputComponent), out var binding))
            {
                input = binding as InputComponent;
            }

            input.MovementDirection.X = 0;
            input.MovementDirection.Y = 0;
            input.PrimaryAttack       = false;
            input.SecondaryAttack     = false;
            input.SwitchWeapons       = false;
            input.Action = false;
            input.Blink  = false;
        }
Пример #16
0
        private void ReadInput(InputComponent component)
        {
            component.MovementDirection.X = 0;
            component.MovementDirection.Y = 0;

            if (InputReader.IsKeyPressed(Keys.W))
            {
                component.MovementDirection.Y = -1;
            }
            else if (InputReader.IsKeyPressed(Keys.S))
            {
                component.MovementDirection.Y = 1;
            }

            if (InputReader.IsKeyPressed(Keys.A))
            {
                component.MovementDirection.X = -1;
            }
            else if (InputReader.IsKeyPressed(Keys.D))
            {
                component.MovementDirection.X = 1;
            }

            component.PrimaryAttack   = InputReader.IsMouseButtonPressed(MouseButtons.LMB);
            component.SecondaryAttack = InputReader.IsMouseButtonPressed(MouseButtons.RMB);
            component.SwitchWeapons   = InputReader.IsKeyPressed(Keys.Space);
            component.Action          = InputReader.IsKeyPressed(Keys.F);
            component.Blink           = InputReader.IsKeyPressed(Keys.LeftShift);
            component.CursorPoint     = _camera.ConvertScreenToWorld(InputReader.CurrentCursorPos);
            #region Triggers

            //TODO Breunig save triggers here or use "old" data in components
            component.PrimaryAttackTriggered   = InputReader.IsMouseButtonTriggered(MouseButtons.LMB);
            component.SecondaryAttackTriggered = InputReader.IsMouseButtonTriggered(MouseButtons.RMB);
            component.SwitchWeaponsTriggered   = InputReader.IsKeyTriggered(Keys.Space);
            component.ActionTriggered          = InputReader.IsKeyTriggered(Keys.F);
            component.BlinkTriggered           = InputReader.IsKeyTriggered(Keys.LeftShift);

            #endregion
        }
Пример #17
0
        private void ResetOrderInputs(IntelligenceComponent intelligence, IntelligenceOrder order)
        {
            InputComponent input = null;

            if (intelligence.Bindings.TryGetValue(typeof(InputComponent), out var binding))
            {
                input = binding as InputComponent;
            }

            if (order.Type == OrderType.AttackPrimary)
            {
                input.PrimaryAttack = false;
            }
            if (order.Type == OrderType.AttackSecondary)
            {
                input.SecondaryAttack = false;
            }
            if (order.Type == OrderType.Follow || order.Type == OrderType.Move)
            {
                input.MovementDirection = Vector2.Zero;
            }
        }
Пример #18
0
 private void HandleInputLogic(InputComponent input, GameTime gameTime)
 {
     MovementLogic(input);
     _attackSubsystem.AttackLogic(input, gameTime);
 }
Пример #19
0
 private void BlockInput(InputComponent input, GameTime gameTime, double milliseconds)
 {
     input.Blocked = true;
     input.BlockedTimer.SetTimer(gameTime, milliseconds);
 }
Пример #20
0
 private static bool BlockedTimerIsOver(InputComponent component)
 {
     return(component.Blocked && component.BlockedTimer.Over);
 }
Пример #21
0
 private static bool AttackTriggered(InputComponent input, AttackComponent attack)
 {
     return(input.PrimaryAttack && attack.Type == AttackType.Primary || input.SecondaryAttack && attack.Type == AttackType.Secondary);
 }
Пример #22
0
        private static void SetMovementVariables(BlinkComponent blink, MovementComponent movement, InputComponent input, GameTime gameTime)
        {
            blink.MovementDurationTimer.SetTimer(gameTime, blink.BlinkMovementDurationInMilliseconds);
            blink.MovementDirection = input.MovementDirection;
            blink.MovementExitSpeed = movement.Speed;

            SetMovementVariablesForBindings(blink);

            blink.CurrentEntityState.Blinking = true;
        }