Exemple #1
0
        public void ChargeSlashAI(Player player)
        {
            if (targets.Count == 1)
            {
                totalTargetTime = 15;
            }

            setAnimationAndImmunities(player);

            float countf          = targets.Count;
            int   framesPerTarget = (int)Math.Max(1, (float)totalTargetTime / countf);
            float oneFrame        = specialProjFrames / (framesPerTarget * countf); // calculates ro roughly 9 / 30 = 0.3

            // Get current frame, and current target in attack
            int i = (int)(FrameCheck / oneFrame);

            if (i >= framesPerTarget * countf)
            {
                // End frame
                player.Center       = (Vector2)endingPositionCenter;
                player.velocity     = new Vector2(projectile.direction * -7.5f, player.gravDir * -2);
                projectile.timeLeft = 0;

                return;
            }
            else
            {
                // Set camera lerp
                if (player.whoAmI == Main.myPlayer)
                {
                    Main.SetCameraLerp(0.1f, 10);
                }

                // Get the target position, or wait if the target is invalid
                int     iTarget = (int)MathHelper.Clamp((float)i / framesPerTarget, 0, countf - 1);
                NPC     target  = targets[iTarget];
                Vector2 targetBottom;
                if (target == null || !target.active || target.dontTakeDamage)
                {
                    targetBottom = player.Bottom; target = null;
                }
                else
                {
                    // Set target
                    targetBottom = target.Bottom;
                    // and rotate slash
                    Vector2 toTarget = targetBottom - player.Bottom;
                    projectile.rotation = (float)Math.Atan2(toTarget.Y, toTarget.X);
                }

                Vector2 oldBottom = new Vector2(player.Bottom.X, player.Bottom.Y);
                Vector2 vecHeight = new Vector2(0, Player.defaultHeight / -2);

                // Tweening if there is time
                if (framesPerTarget > 1)
                {
                    Vector2 dist = (targetBottom - player.Bottom) * (1f / Math.Max(1, framesPerTarget / 2f));
                    player.Bottom     = player.Bottom + dist;
                    player.velocity.Y = -player.gravDir * 1.5f;

                    int distFactor = (int)(dist.Length() / 4f);
                    RaidenUtils.DrawDustToBetweenVectors(oldBottom + vecHeight, player.Bottom + vecHeight, 106, distFactor, 2f);
                }

                int framesToNextKeyframe = Math.Max(0, ((iTarget + 1) * framesPerTarget - 1) - i);

                //// Snap to target on key frames, assuming they can be reached
                if (framesToNextKeyframe == 0)
                {
                    player.Bottom = targetBottom;

                    RaidenUtils.DrawDustToBetweenVectors(oldBottom + vecHeight, player.Bottom + vecHeight, 106, 2, 2f);
                }

                // Set slash
                ModSabres.RecentreSlash(projectile, player);


                // Clientside unstick code, don't bother for others in MP
                if (player.whoAmI == Main.myPlayer)
                {
                    UpdateValidEndingPosition(player);
                }
                else
                {
                    endingPositionCenter = player.Center;
                }

                FrameCheck += oneFrame;
            }
        }