Terraria.Player.GrappleMovement C# (CSharp) Method

GrappleMovement() public method

public GrappleMovement ( ) : void
return void
        public void GrappleMovement()
        {
            if (this.grappling[0] < 0)
                return;
            if (Main.myPlayer == this.whoAmI && this.mount.Active)
                this.mount.Dismount(this);
            this.canCarpet = true;
            this.carpetFrame = -1;
            this.wingFrame = 1;
            if ((double)this.velocity.Y == 0.0 || this.wet && (double)this.velocity.Y > -0.02 && (double)this.velocity.Y < 0.02)
                this.wingFrame = 0;
            if (this.wings == 4)
                this.wingFrame = 3;
            this.wingTime = (float)this.wingTimeMax;
            this.rocketTime = this.rocketTimeMax;
            this.rocketDelay = 0;
            this.rocketFrame = false;
            this.canRocket = false;
            this.rocketRelease = false;
            this.fallStart = (int)((double)this.position.Y / 16.0);
            int index1 = -1;
            float num1 = 0.0f;
            float num2 = 0.0f;
            for (int index2 = 0; index2 < this.grapCount; ++index2)
            {
                Projectile projectile = Main.projectile[this.grappling[index2]];
                num1 += projectile.position.X + (float)(projectile.width / 2);
                num2 += projectile.position.Y + (float)(projectile.height / 2);
                if (projectile.type == 403)
                    index1 = index2;
                else if (projectile.type == 446)
                {
                    Vector2 vector2_1 = new Vector2((float)(Utils.ToInt(this.controlRight) - Utils.ToInt(this.controlLeft)), (float)(Utils.ToInt(this.controlDown) - Utils.ToInt(this.controlUp)));
                    if (vector2_1 != Vector2.Zero)
                        vector2_1.Normalize();
                    vector2_1 *= 100f;
                    Vector2 vector2_2 = Vector2.Normalize(this.Center - projectile.Center + vector2_1);
                    if (float.IsNaN(vector2_2.X) || float.IsNaN(vector2_2.Y))
                        vector2_2 = -Vector2.UnitY;
                    float num3 = 200f;
                    num1 += vector2_2.X * num3;
                    num2 += vector2_2.Y * num3;
                }
            }
            float num4 = num1 / (float)this.grapCount;
            float num5 = num2 / (float)this.grapCount;
            Vector2 vector2 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
            float num6 = num4 - vector2.X;
            float num7 = num5 - vector2.Y;
            float num8 = (float)Math.Sqrt((double)num6 * (double)num6 + (double)num7 * (double)num7);
            float num9 = 11f;
            if (Main.projectile[this.grappling[0]].type == 315)
                num9 = 16f;
            if (Main.projectile[this.grappling[0]].type >= 646 && Main.projectile[this.grappling[0]].type <= 649)
                num9 = 13f;
            float num10 = (double)num8 <= (double)num9 ? 1f : num9 / num8;
            float num11 = num6 * num10;
            float num12 = num7 * num10;
            if ((double)num12 > 0.0)
                this.GoingDownWithGrapple = true;
            this.velocity.X = num11;
            this.velocity.Y = num12;
            if (index1 != -1)
            {
                Projectile projectile = Main.projectile[this.grappling[index1]];
                if ((double)projectile.position.X < (double)this.position.X + (double)this.width && (double)projectile.position.X + (double)projectile.width >= (double)this.position.X && ((double)projectile.position.Y < (double)this.position.Y + (double)this.height && (double)projectile.position.Y + (double)projectile.height >= (double)this.position.Y))
                {
                    int tileX = (int)((double)projectile.position.X + (double)(projectile.width / 2)) / 16;
                    int tileY = (int)((double)projectile.position.Y + (double)(projectile.height / 2)) / 16;
                    this.velocity = Vector2.Zero;
                    if ((int)Main.tile[tileX, tileY].type == 314)
                    {
                        Vector2 Position;
                        Position.X = projectile.position.X + (float)(projectile.width / 2) - (float)(this.width / 2);
                        Position.Y = projectile.position.Y + (float)(projectile.height / 2) - (float)(this.height / 2);
                        this.grappling[0] = -1;
                        this.grapCount = 0;
                        for (int index2 = 0; index2 < 1000; ++index2)
                        {
                            if (Main.projectile[index2].active && Main.projectile[index2].owner == this.whoAmI && Main.projectile[index2].aiStyle == 7)
                                Main.projectile[index2].Kill();
                        }
                        int num3 = 13;
                        if (this.miscEquips[2].stack > 0 && this.miscEquips[2].mountType >= 0 && MountID.Sets.Cart[this.miscEquips[2].mountType] && (!this.miscEquips[2].expertOnly || Main.expertMode))
                            num3 = this.miscEquips[2].mountType;
                        int Height = this.height + Mount.GetHeightBoost(num3);
                        if (Minecart.GetOnTrack(tileX, tileY, ref Position, this.width, Height) && !Collision.SolidCollision(Position, this.width, Height - 20))
                        {
                            this.position = Position;
                            DelegateMethods.Minecart.rotation = this.fullRotation;
                            DelegateMethods.Minecart.rotationOrigin = this.fullRotationOrigin;
                            this.mount.SetMount(num3, this, this.minecartLeft);
                            Minecart.WheelSparks(this.mount.MinecartDust, this.position, this.width, this.height, 25);
                        }
                    }
                }
            }
            if (this.itemAnimation == 0)
            {
                if ((double)this.velocity.X > 0.0)
                    this.ChangeDir(1);
                if ((double)this.velocity.X < 0.0)
                    this.ChangeDir(-1);
            }
            if (this.controlJump)
            {
                if (!this.releaseJump)
                    return;
                if (((double)this.velocity.Y == 0.0 || this.wet && (double)this.velocity.Y > -0.02 && (double)this.velocity.Y < 0.02) && !this.controlDown)
                {
                    this.velocity.Y = -Player.jumpSpeed;
                    this.jump = Player.jumpHeight / 2;
                    this.releaseJump = false;
                }
                else
                {
                    this.velocity.Y += 0.01f;
                    this.releaseJump = false;
                }
                if (this.doubleJumpCloud)
                    this.jumpAgainCloud = true;
                if (this.doubleJumpSandstorm)
                    this.jumpAgainSandstorm = true;
                if (this.doubleJumpBlizzard)
                    this.jumpAgainBlizzard = true;
                if (this.doubleJumpFart)
                    this.jumpAgainFart = true;
                if (this.doubleJumpSail)
                    this.jumpAgainSail = true;
                if (this.doubleJumpUnicorn)
                    this.jumpAgainUnicorn = true;
                this.grappling[0] = 0;
                this.grapCount = 0;
                for (int index2 = 0; index2 < 1000; ++index2)
                {
                    if (Main.projectile[index2].active && Main.projectile[index2].owner == this.whoAmI && Main.projectile[index2].aiStyle == 7)
                        Main.projectile[index2].Kill();
                }
            }
            else
                this.releaseJump = true;
        }
Player