Terraria.Player.DashMovement C# (CSharp) Method

DashMovement() public method

public DashMovement ( ) : void
return void
        public void DashMovement()
        {
            if (this.dash == 2 && this.eocDash > 0)
            {
                if (this.eocHit < 0)
                {
                    Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)this.position.X + (double)this.velocity.X * 0.5 - 4.0), (int)((double)this.position.Y + (double)this.velocity.Y * 0.5 - 4.0), this.width + 8, this.height + 8);
                    for (int number = 0; number < 200; ++number)
                    {
                        if (Main.npc[number].active && !Main.npc[number].dontTakeDamage && !Main.npc[number].friendly)
                        {
                            NPC npc = Main.npc[number];
                            Microsoft.Xna.Framework.Rectangle rect = npc.getRect();
                            if (rectangle.Intersects(rect) && (npc.noTileCollide || Collision.CanHit(this.position, this.width, this.height, npc.position, npc.width, npc.height)))
                            {
                                float number2 = 30f * this.meleeDamage;
                                float num = 9f;
                                bool crit = false;
                                if (this.kbGlove)
                                    num *= 2f;
                                if (this.kbBuff)
                                    num *= 1.5f;
                                if (Main.rand.Next(100) < this.meleeCrit)
                                    crit = true;
                                int hitDirection = this.direction;
                                if ((double)this.velocity.X < 0.0)
                                    hitDirection = -1;
                                if ((double)this.velocity.X > 0.0)
                                    hitDirection = 1;
                                if (this.whoAmI == Main.myPlayer)
                                {
                                    npc.StrikeNPC((int)number2, num, hitDirection, crit, false, false);
                                    if (Main.netMode != 0)
                                        NetMessage.SendData(28, -1, -1, "", number, number2, num, (float)hitDirection, 0, 0, 0);
                                }
                                this.eocDash = 10;
                                this.dashDelay = 30;
                                this.velocity.X = (float)(-hitDirection * 9);
                                this.velocity.Y = -4f;
                                this.immune = true;
                                this.immuneTime = 4;
                                this.eocHit = number;
                            }
                        }
                    }
                }
                else if ((!this.controlLeft || (double)this.velocity.X >= 0.0) && (!this.controlRight || (double)this.velocity.X <= 0.0))
                    this.velocity.X *= 0.95f;
            }
            if (this.dash == 3 && this.dashDelay < 0 && this.whoAmI == Main.myPlayer)
            {
                Microsoft.Xna.Framework.Rectangle rectangle = new Microsoft.Xna.Framework.Rectangle((int)((double)this.position.X + (double)this.velocity.X * 0.5 - 4.0), (int)((double)this.position.Y + (double)this.velocity.Y * 0.5 - 4.0), this.width + 8, this.height + 8);
                for (int number = 0; number < 200; ++number)
                {
                    if (Main.npc[number].active && !Main.npc[number].dontTakeDamage && (!Main.npc[number].friendly && Main.npc[number].immune[this.whoAmI] <= 0))
                    {
                        NPC npc = Main.npc[number];
                        Microsoft.Xna.Framework.Rectangle rect = npc.getRect();
                        if (rectangle.Intersects(rect) && (npc.noTileCollide || Collision.CanHit(this.position, this.width, this.height, npc.position, npc.width, npc.height)))
                        {
                            float number2 = 150f * this.meleeDamage;
                            float num = 9f;
                            bool crit = false;
                            if (this.kbGlove)
                                num *= 2f;
                            if (this.kbBuff)
                                num *= 1.5f;
                            if (Main.rand.Next(100) < this.meleeCrit)
                                crit = true;
                            int hitDirection = this.direction;
                            if ((double)this.velocity.X < 0.0)
                                hitDirection = -1;
                            if ((double)this.velocity.X > 0.0)
                                hitDirection = 1;
                            if (this.whoAmI == Main.myPlayer)
                            {
                                npc.StrikeNPC((int)number2, num, hitDirection, crit, false, false);
                                if (Main.netMode != 0)
                                    NetMessage.SendData(28, -1, -1, "", number, number2, num, (float)hitDirection, 0, 0, 0);
                            }
                            npc.immune[this.whoAmI] = 6;
                            this.immune = true;
                            this.immuneTime = 4;
                        }
                    }
                }
            }
            if (this.dashDelay > 0)
            {
                if (this.eocDash > 0)
                    --this.eocDash;
                if (this.eocDash == 0)
                    this.eocHit = -1;
                --this.dashDelay;
            }
            else if (this.dashDelay < 0)
            {
                float num1 = 12f;
                float num2 = 0.992f;
                float num3 = Math.Max(this.accRunSpeed, this.maxRunSpeed);
                float num4 = 0.96f;
                int num5 = 20;
                if (this.dash == 1)
                {
                    for (int index1 = 0; index1 < 2; ++index1)
                    {
                        int index2 = (double)this.velocity.Y != 0.0 ? Dust.NewDust(new Vector2(this.position.X, (float)((double)this.position.Y + (double)(this.height / 2) - 8.0)), this.width, 16, 31, 0.0f, 0.0f, 100, new Color(), 1.4f) : Dust.NewDust(new Vector2(this.position.X, (float)((double)this.position.Y + (double)this.height - 4.0)), this.width, 8, 31, 0.0f, 0.0f, 100, new Color(), 1.4f);
                        Main.dust[index2].velocity *= 0.1f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                    }
                }
                else if (this.dash == 2)
                {
                    for (int index1 = 0; index1 < 0; ++index1)
                    {
                        int index2 = (double)this.velocity.Y != 0.0 ? Dust.NewDust(new Vector2(this.position.X, (float)((double)this.position.Y + (double)(this.height / 2) - 8.0)), this.width, 16, 31, 0.0f, 0.0f, 100, new Color(), 1.4f) : Dust.NewDust(new Vector2(this.position.X, (float)((double)this.position.Y + (double)this.height - 4.0)), this.width, 8, 31, 0.0f, 0.0f, 100, new Color(), 1.4f);
                        Main.dust[index2].velocity *= 0.1f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                    }
                    num2 = 0.985f;
                    num4 = 0.94f;
                    num5 = 30;
                }
                else if (this.dash == 3)
                {
                    for (int index1 = 0; index1 < 4; ++index1)
                    {
                        int index2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + 4f), this.width, this.height - 8, 6, 0.0f, 0.0f, 100, new Color(), 1.7f);
                        Main.dust[index2].velocity *= 0.1f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.ArmorSetDye(), this);
                        Main.dust[index2].noGravity = true;
                        if (Main.rand.Next(2) == 0)
                            Main.dust[index2].fadeIn = 0.5f;
                    }
                    num1 = 14f;
                    num2 = 0.985f;
                    num4 = 0.94f;
                    num5 = 20;
                }
                else if (this.dash == 4)
                {
                    for (int index1 = 0; index1 < 2; ++index1)
                    {
                        int index2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + 4f), this.width, this.height - 8, 229, 0.0f, 0.0f, 100, new Color(), 1.2f);
                        Main.dust[index2].velocity *= 0.1f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cWings, this);
                        Main.dust[index2].noGravity = true;
                        if (Main.rand.Next(2) == 0)
                            Main.dust[index2].fadeIn = 0.3f;
                    }
                    num2 = 0.985f;
                    num4 = 0.94f;
                    num5 = 20;
                }
                if (this.dash <= 0)
                    return;
                this.vortexStealthActive = false;
                if ((double)this.velocity.X > (double)num1 || (double)this.velocity.X < -(double)num1)
                    this.velocity.X *= num2;
                else if ((double)this.velocity.X > (double)num3 || (double)this.velocity.X < -(double)num3)
                {
                    this.velocity.X *= num4;
                }
                else
                {
                    this.dashDelay = num5;
                    if ((double)this.velocity.X < 0.0)
                    {
                        this.velocity.X = -num3;
                    }
                    else
                    {
                        if ((double)this.velocity.X <= 0.0)
                            return;
                        this.velocity.X = num3;
                    }
                }
            }
            else
            {
                if (this.dash <= 0 || this.mount.Active)
                    return;
                if (this.dash == 1)
                {
                    int num = 0;
                    bool flag = false;
                    if (this.dashTime > 0)
                        --this.dashTime;
                    if (this.dashTime < 0)
                        ++this.dashTime;
                    if (this.controlRight && this.releaseRight)
                    {
                        if (this.dashTime > 0)
                        {
                            num = 1;
                            flag = true;
                            this.dashTime = 0;
                        }
                        else
                            this.dashTime = 15;
                    }
                    else if (this.controlLeft && this.releaseLeft)
                    {
                        if (this.dashTime < 0)
                        {
                            num = -1;
                            flag = true;
                            this.dashTime = 0;
                        }
                        else
                            this.dashTime = -15;
                    }
                    if (!flag)
                        return;
                    this.velocity.X = 16.9f * (float)num;
                    Point point1 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), (float)((double)this.gravDir * (double)-this.height / 2.0 + (double)this.gravDir * 2.0)));
                    Point point2 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), 0.0f));
                    if (WorldGen.SolidTile(point1.X, point1.Y) || WorldGen.SolidTile(point2.X, point2.Y))
                        this.velocity.X /= 2f;
                    this.dashDelay = -1;
                    for (int index1 = 0; index1 < 20; ++index1)
                    {
                        int index2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0.0f, 0.0f, 100, new Color(), 2f);
                        Main.dust[index2].position.X += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].position.Y += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].velocity *= 0.2f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShoe, this);
                    }
                    int index3 = Gore.NewGore(new Vector2((float)((double)this.position.X + (double)(this.width / 2) - 24.0), (float)((double)this.position.Y + (double)(this.height / 2) - 34.0)), new Vector2(), Main.rand.Next(61, 64), 1f);
                    Main.gore[index3].velocity.X = (float)Main.rand.Next(-50, 51) * 0.01f;
                    Main.gore[index3].velocity.Y = (float)Main.rand.Next(-50, 51) * 0.01f;
                    Main.gore[index3].velocity *= 0.4f;
                    int index4 = Gore.NewGore(new Vector2((float)((double)this.position.X + (double)(this.width / 2) - 24.0), (float)((double)this.position.Y + (double)(this.height / 2) - 14.0)), new Vector2(), Main.rand.Next(61, 64), 1f);
                    Main.gore[index4].velocity.X = (float)Main.rand.Next(-50, 51) * 0.01f;
                    Main.gore[index4].velocity.Y = (float)Main.rand.Next(-50, 51) * 0.01f;
                    Main.gore[index4].velocity *= 0.4f;
                }
                else if (this.dash == 2)
                {
                    int num = 0;
                    bool flag = false;
                    if (this.dashTime > 0)
                        --this.dashTime;
                    if (this.dashTime < 0)
                        ++this.dashTime;
                    if (this.controlRight && this.releaseRight)
                    {
                        if (this.dashTime > 0)
                        {
                            num = 1;
                            flag = true;
                            this.dashTime = 0;
                        }
                        else
                            this.dashTime = 15;
                    }
                    else if (this.controlLeft && this.releaseLeft)
                    {
                        if (this.dashTime < 0)
                        {
                            num = -1;
                            flag = true;
                            this.dashTime = 0;
                        }
                        else
                            this.dashTime = -15;
                    }
                    if (!flag)
                        return;
                    this.velocity.X = 14.5f * (float)num;
                    Point point1 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), (float)((double)this.gravDir * (double)-this.height / 2.0 + (double)this.gravDir * 2.0)));
                    Point point2 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), 0.0f));
                    if (WorldGen.SolidTile(point1.X, point1.Y) || WorldGen.SolidTile(point2.X, point2.Y))
                        this.velocity.X /= 2f;
                    this.dashDelay = -1;
                    this.eocDash = 15;
                    for (int index1 = 0; index1 < 0; ++index1)
                    {
                        int index2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0.0f, 0.0f, 100, new Color(), 2f);
                        Main.dust[index2].position.X += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].position.Y += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].velocity *= 0.2f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.cShield, this);
                    }
                }
                else if (this.dash == 3)
                {
                    int num = 0;
                    bool flag = false;
                    if (this.dashTime > 0)
                        --this.dashTime;
                    if (this.dashTime < 0)
                        ++this.dashTime;
                    if (this.controlRight && this.releaseRight)
                    {
                        if (this.dashTime > 0)
                        {
                            num = 1;
                            flag = true;
                            this.dashTime = 0;
                            this.ConsumeSolarFlare();
                            this.solarDashing = true;
                        }
                        else
                            this.dashTime = 15;
                    }
                    else if (this.controlLeft && this.releaseLeft)
                    {
                        if (this.dashTime < 0)
                        {
                            num = -1;
                            flag = true;
                            this.dashTime = 0;
                            this.ConsumeSolarFlare();
                            this.solarDashing = true;
                        }
                        else
                            this.dashTime = -15;
                    }
                    if (!flag)
                        return;
                    this.velocity.X = 21.9f * (float)num;
                    Point point1 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), (float)((double)this.gravDir * (double)-this.height / 2.0 + (double)this.gravDir * 2.0)));
                    Point point2 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), 0.0f));
                    if (WorldGen.SolidTile(point1.X, point1.Y) || WorldGen.SolidTile(point2.X, point2.Y))
                        this.velocity.X /= 2f;
                    this.dashDelay = -1;
                    for (int index1 = 0; index1 < 20; ++index1)
                    {
                        int index2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0.0f, 0.0f, 100, new Color(), 2f);
                        Main.dust[index2].position.X += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].position.Y += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].velocity *= 0.2f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.ArmorSetDye(), this);
                        Main.dust[index2].noGravity = true;
                        Main.dust[index2].fadeIn = 0.5f;
                    }
                }
                else
                {
                    if (this.dash != 4)
                        return;
                    int num = 0;
                    bool flag = false;
                    if (this.dashTime > 0)
                        --this.dashTime;
                    if (this.dashTime < 0)
                        ++this.dashTime;
                    if (this.controlRight && this.releaseRight)
                    {
                        if (this.dashTime > 0)
                        {
                            num = 1;
                            flag = true;
                            this.dashTime = 0;
                            this.ConsumeSolarFlare();
                            this.solarDashing = true;
                        }
                        else
                            this.dashTime = 15;
                    }
                    else if (this.controlLeft && this.releaseLeft)
                    {
                        if (this.dashTime < 0)
                        {
                            num = -1;
                            flag = true;
                            this.dashTime = 0;
                            this.ConsumeSolarFlare();
                            this.solarDashing = true;
                        }
                        else
                            this.dashTime = -15;
                    }
                    if (!flag)
                        return;
                    this.velocity.X = 21.9f * (float)num;
                    this.dashDelay = -1;
                    Point point1 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2 * num), (float)((double)this.gravDir * (double)-this.height / 2.0 + (double)this.gravDir * 2.0)));
                    Point point2 = Utils.ToTileCoordinates(this.Center + new Vector2((float)(num * this.width / 2 + 2), 0.0f));
                    if (WorldGen.SolidTile(point1.X, point1.Y) || WorldGen.SolidTile(point2.X, point2.Y))
                        this.velocity.X /= 2f;
                    for (int index1 = 0; index1 < 20; ++index1)
                    {
                        int index2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 229, 0.0f, 0.0f, 100, new Color(), 2f);
                        Main.dust[index2].position.X += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].position.Y += (float)Main.rand.Next(-5, 6);
                        Main.dust[index2].velocity *= 0.2f;
                        Main.dust[index2].scale *= (float)(1.0 + (double)Main.rand.Next(20) * 0.00999999977648258);
                        Main.dust[index2].shader = GameShaders.Armor.GetSecondaryShader(this.ArmorSetDye(), this);
                        Main.dust[index2].noGravity = true;
                        Main.dust[index2].fadeIn = 0.5f;
                    }
                }
            }
        }
Player