public void Vector2_Rotate_45_Degrees_Test()
        {
            var a = new Vector2(0, -10);
            var b = a.Rotate(MathHelper.ToRadians(45));

            Assert.IsTrue(new Vector2(7.071068f, -7.071068f).EqualsWithTolerance(b));
        }
Esempio n. 2
0
   public static Vector2 BodyToWorldPoint(
 Vector2 bodyPosition,
 Vector2 bodyFacing,
 Vector2 vector)
   {
       return vector.Rotate(bodyFacing) + bodyPosition;
   }
        public void Vector2_Rotate_360_Degrees_Test()
        {
            var a = new Vector2(0, 10);
            var b = a.Rotate(MathHelper.ToRadians(360));

            Assert.IsTrue(new Vector2(0, 10).EqualsWithTolerance(b));
        }
Esempio n. 4
0
    void OnGUI()
    {



        EditorGUILayout.HelpBox("村长:", MessageType.Info);
        //EditorGUILayout.BeginHorizontal();
        firstObject = EditorGUILayout.Vector2Field("param1", firstObject);
        secondObject = EditorGUILayout.Vector2Field("param2", secondObject);

        if (lastFirstObject != firstObject || lastSecondObject != secondObject)
        {
            lastFirstObject = firstObject;
            lastSecondObject = secondObject;

            dis = Vector2.Distance(firstObject, secondObject);
            dot = Vector2.Dot(firstObject, secondObject);
            angle = Vector2.Angle(firstObject, secondObject);
            det = firstObject.x * secondObject.y - firstObject.y * secondObject.x;

            if (angle > 90)
            {
                if (det > 0)//param2 is unclockwise
                {

                    verticalObject = secondObject.Rotate(-(angle-90) );
                }
                else if (det == 0)
                {

                }
                else
                {
                    verticalObject = secondObject.Rotate( (angle-90));
                }
            }
            //verticalObject = secondObject.Rotate(45);

        }
        dis = EditorGUILayout.FloatField("Distance:", dis);
        dot = EditorGUILayout.FloatField("Dot:", dot);
        angle = EditorGUILayout.FloatField("Angle:", angle);
        det = EditorGUILayout.FloatField("Determinant:", det);
        verticalObject = EditorGUILayout.Vector2Field("Vertical", verticalObject);
        //EditorGUILayout.EndHorizontal();
    }
Esempio n. 5
0
    public void Initialize(Vector2 dir)
    {
        float rand = Random.value;
        if (rand < SmallRatio)
        {
            dir = dir.Rotate((Random.value - 0.5f) * 90);
            transform.localScale *= Random.Range(0.1f, 0.2f);
            transform.localPosition += new Vector3(0, Random.Range(-1.0f, 1));
            _rb.velocity = 05 * dir * Random.Range(0.95f, 1.05f);
            _rb.drag = Random.Range(0f, 1.0f);
            GetComponent<Renderer>().material = DropletSmall;
            Lifetime = Random.Range(Lifetime, Lifetime * 3);

        }
        else if (rand < MediumRatio + SmallRatio)
        {
            dir = dir.Rotate((Random.value - 0.5f) * 8);
            transform.localScale *= Random.Range(0.2f, 1.2f);
            transform.localPosition += new Vector3(0, Random.Range(-1.0f, 1));
            _rb.velocity = 40 * dir * Random.Range(0.95f, 1.05f);
            _rb.drag = Random.Range(0.1f, 0.3f);
            GetComponent<Renderer>().material = DropletMedium;
            Lifetime = Random.Range(Lifetime, Lifetime * 2);
        }
        else
        {
            dir = dir.Rotate((Random.value - 0.5f) * 5);
            transform.localScale *= Random.Range(1.2f, 1.8f);
            transform.localPosition += new Vector3(0, Random.Range(-1.0f, 1));
            _rb.velocity = 50 * dir * Random.Range(0.95f, 1.05f);
            _rb.drag = Random.Range(0f, 0.2f);
            GetComponent<Renderer>().material = DropletLarge;
            Lifetime = Random.Range(Lifetime, Lifetime * 1.5f);
        }

        StartCoroutine(dieAfterLifetime());
    }
		public void Leveling7PointsNeverGetsTooHigh()
		{
			StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
			MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

			var levelingData = new PrintLevelingData(ActiveSliceSettings.Instance);

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			levelingData.SampledPositions.Add(new Vector3(130.00, 0.00, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, 112.58, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, 112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(-130.00, 0.00, 10));
			levelingData.SampledPositions.Add(new Vector3(-65.00, -112.58, 0));
			levelingData.SampledPositions.Add(new Vector3(65.00, -112.58, 10));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 0));

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			int totalPoints = 2000;
			for (int curPoint = 0; curPoint < totalPoints; curPoint++)
			{
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / totalPoints * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);

				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.IsTrue(outPosition.z <= 10);

				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				double outZ = 0;
				Assert.IsTrue(GCodeFile.GetFirstNumberAfter("Z", outPositionString, ref outZ));
				Assert.IsTrue(outZ <= 10);
			}
		}
Esempio n. 7
0
        private Object3D GetTab(bool calibrateX)
        {
            var content = new Object3D();

            var spaceBetween = NozzleWidth * tabScale;

            var shape = new VertexStorage();

            shape.MoveTo(0, 0);
            // left + spaces + blocks + right
            var sampleCount = 7;
            var baseWidth   = (2 * spaceBetween) + ((sampleCount - 1) * spaceBetween) + (sampleCount * TabWidth) + (2 * spaceBetween);

            shape.LineTo(baseWidth, 0);
            if (calibrateX)
            {
                var origin = new Vector2(baseWidth, TabDepth / 2);
                var delta  = new Vector2(0, -TabDepth / 2);
                var count  = 15;
                for (int i = 0; i < count; i++)
                {
                    delta.Rotate(MathHelper.Tau / 2 / count);
                    shape.LineTo(origin + delta);
                }
            }
            else
            {
                shape.LineTo(baseWidth + TabDepth, TabDepth / 2);                 // a point on the left
            }
            shape.LineTo(baseWidth, TabDepth);
            shape.LineTo(0, TabDepth);

            content.Children.Add(new Object3D()
            {
                Mesh  = shape.Extrude(ChangeHeight),
                Color = Color.LightBlue
            });

            var position = new Vector2(TabWidth / 2 + 2 * spaceBetween, TabDepth / 2 - Offset * ((sampleCount - 1) / 2));
            var step     = new Vector2(spaceBetween + TabWidth, Offset);

            for (int i = 0; i < sampleCount; i++)
            {
                var cube = PlatonicSolids.CreateCube();
                content.Children.Add(new Object3D()
                {
                    Mesh   = cube,
                    Color  = Color.Yellow,
                    Matrix = Matrix4X4.CreateScale(TabWidth, TabDepth, ChangeHeight)
                             // translate by 1.5 as it is a centered cube (.5) plus the base (1) = 1.5
                             * Matrix4X4.CreateTranslation(position.X, position.Y, ChangeHeight * 1.5),
                    MaterialIndex = CalibrationMaterialIndex
                });
                position += step;
            }

            if (calibrateX)
            {
                content.Matrix = Matrix4X4.CreateRotationZ(MathHelper.Tau / 4) * Matrix4X4.CreateTranslation(0, TabDepth, 0);
            }

            return(content);
        }
Esempio n. 8
0
        /// <summary>
        /// Moves, scales, and/or rotates the current entity given a 3x3 transformation matrix and a translation vector.
        /// </summary>
        /// <param name="transformation">Transformation matrix.</param>
        /// <param name="translation">Translation vector.</param>
        public override void TransformBy(Matrix3 transformation, Vector3 translation)
        {
            Vector3 newNormal;
            double  newScale;
            double  newAngle;

            newNormal = transformation * this.Normal;

            Matrix3 transOW = MathHelper.ArbitraryAxis(this.Normal);
            Matrix3 transWO = MathHelper.ArbitraryAxis(newNormal).Transpose();

            List <HatchBoundaryPath> paths = new List <HatchBoundaryPath>();

            foreach (HatchBoundaryPath path in this.BoundaryPaths)
            {
                List <EntityObject> data = new List <EntityObject>();

                foreach (HatchBoundaryPath.Edge edge in path.Edges)
                {
                    EntityObject entity = edge.ConvertTo();

                    switch (entity.Type)
                    {
                    case EntityType.Arc:
                        entity = ProcessArc((Arc)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation));
                        break;

                    case EntityType.Circle:
                        entity = ProcessCircle((Circle)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation));
                        break;

                    case EntityType.Ellipse:
                        entity = ProcessEllipse((Ellipse)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation));
                        break;

                    case EntityType.Line:
                        entity = ProcessLine((Line)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation));
                        break;

                    case EntityType.LwPolyline:
                        entity = ProcessLwPolyline((LwPolyline)entity, this.Normal, this.Elevation);
                        break;

                    case EntityType.Spline:
                        entity = ProcessSpline((Spline)entity, transOW, transOW * new Vector3(0.0, 0.0, this.Elevation));
                        break;
                    }
                    entity.TransformBy(transformation, translation);
                    data.Add(entity);
                }
                paths.Add(new HatchBoundaryPath(data));
            }

            Vector3 position = transOW * new Vector3(0.0, 0.0, this.Elevation);

            position = transformation * position + translation;
            position = transWO * position;

            Vector2 refAxis = Vector2.Rotate(Vector2.UnitX, this.Pattern.Angle * MathHelper.DegToRad);

            refAxis = this.Pattern.Scale * refAxis;
            Vector3 v = transOW * new Vector3(refAxis.X, refAxis.Y, 0.0);

            v = transformation * v;
            v = transWO * v;
            Vector2 axis = new Vector2(v.X, v.Y);

            newAngle = Vector2.Angle(axis) * MathHelper.RadToDeg;

            newScale = axis.Modulus();
            newScale = MathHelper.IsZero(newScale) ? MathHelper.Epsilon : newScale;

            this.Pattern.Scale = newScale;
            this.Pattern.Angle = newAngle;
            this.Elevation     = position.Z;

            this.Normal = newNormal;
            this.BoundaryPaths.Clear();
            this.BoundaryPaths.AddRange(paths);
        }
Esempio n. 9
0
        /// <summary>
        /// Resets the annotation position according to the leader hook.
        /// </summary>
        private void ResetAnnotationPosition()
        {
            DimensionStyleOverride styleOverride;

            DimensionStyleTextVerticalPlacement textVerticalPlacement = this.Style.TextVerticalPlacement;

            if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextVerticalPlacement, out styleOverride))
            {
                textVerticalPlacement = (DimensionStyleTextVerticalPlacement)styleOverride.Value;
            }

            double textGap = this.Style.TextOffset;

            if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextOffset, out styleOverride))
            {
                textGap = (double)styleOverride.Value;
            }

            double dimScale = this.Style.DimScaleOverall;

            if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.DimScaleOverall, out styleOverride))
            {
                dimScale = (double)styleOverride.Value;
            }

            double textHeight = this.Style.TextHeight;

            if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextHeight, out styleOverride))
            {
                textHeight = (double)styleOverride.Value;
            }

            AciColor textColor = this.Style.TextColor;

            if (this.StyleOverrides.TryGetValue(DimensionStyleOverrideType.TextColor, out styleOverride))
            {
                textColor = (AciColor)styleOverride.Value;
            }

            Vector2 hook = this.Hook;
            Vector2 position;
            Vector2 textOffset;
            Vector2 dir = this.Direction;
            int     side;

            textGap *= dimScale;

            switch (this.annotation.Type)
            {
            case EntityType.MText:
                MText mText = (MText)this.annotation;
                side = MathHelper.Sign(dir.X);
                if (side == 0)
                {
                    side = MathHelper.Sign(dir.Y);
                }
                if (mText.Rotation > 90.0 && mText.Rotation <= 270.0)
                {
                    side *= -1;
                }

                if (side >= 0)
                {
                    switch (mText.AttachmentPoint)
                    {
                    case MTextAttachmentPoint.TopRight:
                        mText.AttachmentPoint = MTextAttachmentPoint.TopLeft;
                        break;

                    case MTextAttachmentPoint.MiddleRight:
                        mText.AttachmentPoint = MTextAttachmentPoint.MiddleLeft;
                        break;

                    case MTextAttachmentPoint.BottomRight:
                        mText.AttachmentPoint = MTextAttachmentPoint.BottomLeft;
                        break;
                    }
                }
                else
                {
                    switch (mText.AttachmentPoint)
                    {
                    case MTextAttachmentPoint.TopLeft:
                        mText.AttachmentPoint = MTextAttachmentPoint.TopRight;
                        break;

                    case MTextAttachmentPoint.MiddleLeft:
                        mText.AttachmentPoint = MTextAttachmentPoint.MiddleRight;
                        break;

                    case MTextAttachmentPoint.BottomLeft:
                        mText.AttachmentPoint = MTextAttachmentPoint.BottomRight;
                        break;
                    }
                }

                textOffset = textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered ?
                             new Vector2(side * textGap, 0.0) :
                             new Vector2(side * textGap, textGap);

                position = hook + this.offset + Vector2.Rotate(textOffset, mText.Rotation * MathHelper.DegToRad);

                mText.Position = MathHelper.Transform(position, Normal, this.elevation);
                mText.Height   = textHeight * dimScale;
                mText.Color    = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            case EntityType.Text:
                Text text = (Text)this.annotation;
                side = MathHelper.Sign(dir.X);
                if (side == 0)
                {
                    side = MathHelper.Sign(dir.Y);
                }
                if (text.Rotation > 90.0 && text.Rotation <= 270.0)
                {
                    side *= -1;
                }

                if (side >= 0)
                {
                    switch (text.Alignment)
                    {
                    case TextAlignment.TopRight:
                        text.Alignment = TextAlignment.TopLeft;
                        break;

                    case TextAlignment.MiddleRight:
                        text.Alignment = TextAlignment.MiddleLeft;
                        break;

                    case TextAlignment.BottomRight:
                        text.Alignment = TextAlignment.BottomLeft;
                        break;

                    case TextAlignment.BaselineRight:
                        text.Alignment = TextAlignment.BaselineLeft;
                        break;
                    }
                }
                else
                {
                    switch (text.Alignment)
                    {
                    case TextAlignment.TopLeft:
                        text.Alignment = TextAlignment.TopRight;
                        break;

                    case TextAlignment.MiddleLeft:
                        text.Alignment = TextAlignment.MiddleRight;
                        break;

                    case TextAlignment.BottomLeft:
                        text.Alignment = TextAlignment.BottomRight;
                        break;

                    case TextAlignment.BaselineLeft:
                        text.Alignment = TextAlignment.BaselineRight;
                        break;
                    }
                }

                textOffset = textVerticalPlacement == DimensionStyleTextVerticalPlacement.Centered ?
                             new Vector2(side * textGap, 0.0) :
                             new Vector2(side * textGap, textGap);

                position      = hook + this.offset + Vector2.Rotate(textOffset, text.Rotation * MathHelper.DegToRad);
                text.Position = MathHelper.Transform(position, this.Normal, this.elevation);
                text.Height   = textHeight * dimScale;
                text.Color    = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            case EntityType.Insert:
                Insert ins = (Insert)this.annotation;
                position     = hook + this.offset;
                ins.Position = MathHelper.Transform(position, this.Normal, this.elevation);
                ins.Color    = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            case EntityType.Tolerance:
                Tolerance tol = (Tolerance)this.annotation;
                position     = hook + this.offset;
                tol.Position = MathHelper.Transform(position, this.Normal, this.elevation);
                tol.Color    = textColor.IsByBlock ? AciColor.ByLayer : textColor;
                break;

            default:
                throw new Exception(string.Format("The entity type: {0} not supported as a leader annotation.", this.annotation.Type));
            }
        }
Esempio n. 10
0
		public void ItemCheck(int i)
		{
			if (this.frozen)
			{
				return;
			}
			bool flag = false;
			float num = 5E-06f;
			int num2 = this.inventory[this.selectedItem].damage;
			if (num2 > 0)
			{
				if (this.inventory[this.selectedItem].melee)
				{
					num2 = (int)((float)num2 * this.meleeDamage + num);
				}
				else if (this.inventory[this.selectedItem].ranged)
				{
					num2 = (int)((float)num2 * this.rangedDamage + num);
					if (this.inventory[this.selectedItem].useAmmo == 1 || this.inventory[this.selectedItem].useAmmo == 323)
					{
						num2 = (int)((float)num2 * this.arrowDamage + num);
					}
					if (this.inventory[this.selectedItem].useAmmo == 14 || this.inventory[this.selectedItem].useAmmo == 311)
					{
						num2 = (int)((float)num2 * this.bulletDamage + num);
					}
					if (this.inventory[this.selectedItem].useAmmo == 771 || this.inventory[this.selectedItem].useAmmo == 246 || this.inventory[this.selectedItem].useAmmo == 312)
					{
						num2 = (int)((float)num2 * this.rocketDamage + num);
					}
				}
				else if (this.inventory[this.selectedItem].magic)
				{
					num2 = (int)((float)num2 * this.magicDamage + num);
				}
			}
			if (this.inventory[this.selectedItem].autoReuse && !this.noItems)
			{
				this.releaseUseItem = true;
				if (this.itemAnimation == 1 && this.inventory[this.selectedItem].stack > 0)
				{
					if (this.inventory[this.selectedItem].shoot > 0 && this.whoAmi != Main.myPlayer && this.controlUseItem && this.inventory[this.selectedItem].useStyle == 5)
					{
						this.itemAnimation = 2;
					}
					else
					{
						this.itemAnimation = 0;
					}
				}
			}
			if (this.inventory[this.selectedItem].fishingPole > 0)
			{
				this.inventory[this.selectedItem].holdStyle = 0;
				if (this.itemTime == 0 && this.itemAnimation == 0)
				{
					for (int j = 0; j < 1000; j++)
					{
						if (Main.projectile[j].active && Main.projectile[j].owner == this.whoAmi && Main.projectile[j].bobber)
						{
							this.inventory[this.selectedItem].holdStyle = 1;
						}
					}
				}
			}
			if (this.whoAmi == Main.myPlayer && this.mount.Active)
			{
				if (this.inventory[this.selectedItem].mountType != this.mount.Type && this.itemAnimation > 0)
				{
					this.mount.Dismount(this);
				}
				if (this.gravDir == -1f)
				{
					this.mount.Dismount(this);
				}
			}
			if (this.itemAnimation == 0 && this.reuseDelay > 0)
			{
				this.itemAnimation = this.reuseDelay;
				this.itemTime = this.reuseDelay;
				this.reuseDelay = 0;
			}
			if (this.controlUseItem && this.releaseUseItem && (this.inventory[this.selectedItem].headSlot > 0 || this.inventory[this.selectedItem].bodySlot > 0 || this.inventory[this.selectedItem].legSlot > 0))
			{
				if (this.inventory[this.selectedItem].useStyle == 0)
				{
					this.releaseUseItem = false;
				}
				if (this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f >= (float)Player.tileTargetY)
				{
					int num3 = Player.tileTargetX;
					int num4 = Player.tileTargetY;
					if (Main.tile[num3, num4].active() && (Main.tile[num3, num4].type == 128 || Main.tile[num3, num4].type == 269))
					{
						int num5 = (int)Main.tile[num3, num4].frameY;
						int k = 0;
						if (this.inventory[this.selectedItem].bodySlot >= 0)
						{
							k = 1;
						}
						if (this.inventory[this.selectedItem].legSlot >= 0)
						{
							k = 2;
						}
						num5 /= 18;
						while (k > num5)
						{
							num4++;
							num5 = (int)Main.tile[num3, num4].frameY;
							num5 /= 18;
						}
						while (k < num5)
						{
							num4--;
							num5 = (int)Main.tile[num3, num4].frameY;
							num5 /= 18;
						}
						int l;
						for (l = (int)Main.tile[num3, num4].frameX; l >= 100; l -= 100)
						{
						}
						if (l >= 36)
						{
							l -= 36;
						}
						num3 -= l / 18;
						int m = (int)Main.tile[num3, num4].frameX;
						WorldGen.KillTile(num3, num4, true, false, false);
						if (Main.netMode == 1)
						{
							NetMessage.SendData(17, -1, -1, "", 0, (float)num3, (float)num4, 1f, 0);
						}
						while (m >= 100)
						{
							m -= 100;
						}
						if (num5 == 0 && this.inventory[this.selectedItem].headSlot >= 0)
						{
							Main.blockMouse = true;
							Main.tile[num3, num4].frameX = (short)(m + this.inventory[this.selectedItem].headSlot * 100);
							if (Main.netMode == 1)
							{
								NetMessage.SendTileSquare(-1, num3, num4, 1);
							}
							this.inventory[this.selectedItem].stack--;
							if (this.inventory[this.selectedItem].stack <= 0)
							{
								this.inventory[this.selectedItem].SetDefaults(0, false);
								Main.mouseItem.SetDefaults(0, false);
							}
							if (this.selectedItem == 58)
							{
								Main.mouseItem = this.inventory[this.selectedItem].Clone();
							}
							this.releaseUseItem = false;
							this.mouseInterface = true;
						}
						else if (num5 == 1 && this.inventory[this.selectedItem].bodySlot >= 0)
						{
							Main.blockMouse = true;
							Main.tile[num3, num4].frameX = (short)(m + this.inventory[this.selectedItem].bodySlot * 100);
							if (Main.netMode == 1)
							{
								NetMessage.SendTileSquare(-1, num3, num4, 1);
							}
							this.inventory[this.selectedItem].stack--;
							if (this.inventory[this.selectedItem].stack <= 0)
							{
								this.inventory[this.selectedItem].SetDefaults(0, false);
								Main.mouseItem.SetDefaults(0, false);
							}
							if (this.selectedItem == 58)
							{
								Main.mouseItem = this.inventory[this.selectedItem].Clone();
							}
							this.releaseUseItem = false;
							this.mouseInterface = true;
						}
						else if (num5 == 2 && this.inventory[this.selectedItem].legSlot >= 0)
						{
							Main.blockMouse = true;
							Main.tile[num3, num4].frameX = (short)(m + this.inventory[this.selectedItem].legSlot * 100);
							if (Main.netMode == 1)
							{
								NetMessage.SendTileSquare(-1, num3, num4, 1);
							}
							this.inventory[this.selectedItem].stack--;
							if (this.inventory[this.selectedItem].stack <= 0)
							{
								this.inventory[this.selectedItem].SetDefaults(0, false);
								Main.mouseItem.SetDefaults(0, false);
							}
							if (this.selectedItem == 58)
							{
								Main.mouseItem = this.inventory[this.selectedItem].Clone();
							}
							this.releaseUseItem = false;
							this.mouseInterface = true;
						}
					}
				}
			}
			if (this.controlUseItem && this.itemAnimation == 0 && this.releaseUseItem && this.inventory[this.selectedItem].useStyle > 0)
			{
				bool flag2 = true;
				if (this.inventory[this.selectedItem].shoot == 0)
				{
					this.itemRotation = 0f;
				}
				if (this.pulley && this.inventory[this.selectedItem].fishingPole > 0)
				{
					flag2 = false;
				}
				if (this.wet && (this.inventory[this.selectedItem].shoot == 85 || this.inventory[this.selectedItem].shoot == 15 || this.inventory[this.selectedItem].shoot == 34))
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].makeNPC > 0 && !NPC.CanReleaseNPCs(this.whoAmi))
				{
					flag2 = false;
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 603 && !Main.cEd)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 1071 || this.inventory[this.selectedItem].type == 1072)
				{
					bool flag3 = false;
					for (int n = 0; n < 58; n++)
					{
						if (this.inventory[n].paint > 0)
						{
							flag3 = true;
							break;
						}
					}
					if (!flag3)
					{
						flag2 = false;
					}
				}
				if (this.noItems)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].tileWand > 0)
				{
					int tileWand = this.inventory[this.selectedItem].tileWand;
					flag2 = false;
					for (int num6 = 0; num6 < 58; num6++)
					{
						if (tileWand == this.inventory[num6].type && this.inventory[num6].stack > 0)
						{
							flag2 = true;
							break;
						}
					}
				}
				if (this.inventory[this.selectedItem].fishingPole > 0)
				{
					for (int num7 = 0; num7 < 1000; num7++)
					{
						if (Main.projectile[num7].active && Main.projectile[num7].owner == this.whoAmi && Main.projectile[num7].bobber)
						{
							flag2 = false;
							if (this.whoAmi == Main.myPlayer && Main.projectile[num7].ai[0] == 0f)
							{
								Main.projectile[num7].ai[0] = 1f;
								float num8 = -10f;
								if (Main.projectile[num7].wet && Main.projectile[num7].velocity.Y > num8)
								{
									Main.projectile[num7].velocity.Y = num8;
								}
								Main.projectile[num7].netUpdate2 = true;
								if (Main.projectile[num7].ai[1] < 0f && Main.projectile[num7].localAI[1] != 0f)
								{
									bool flag4 = false;
									int num9 = 0;
									for (int num10 = 0; num10 < 58; num10++)
									{
										if (this.inventory[num10].stack > 0 && this.inventory[num10].bait > 0)
										{
											bool flag5 = false;
											int num11 = this.inventory[num10].bait / 5;
											if (num11 < 1)
											{
												num11 = 1;
											}
											if (this.accTackleBox)
											{
												num11++;
											}
											if (Main.rand.Next(num11) == 0)
											{
												flag5 = true;
											}
											if (Main.projectile[num7].localAI[1] < 0f)
											{
												flag5 = true;
											}
											if (Main.projectile[num7].localAI[1] > 0f)
											{
												Item item = new Item();
												item.SetDefaults((int)Main.projectile[num7].localAI[1], false);
												if (item.rare < 0)
												{
													flag5 = false;
												}
											}
											if (flag5)
											{
												num9 = this.inventory[num10].type;
												this.inventory[num10].stack--;
												if (this.inventory[num10].stack <= 0)
												{
													this.inventory[num10].SetDefaults(0, false);
												}
											}
											flag4 = true;
											break;
										}
									}
									if (flag4)
									{
										if (num9 == 2673)
										{
											if (Main.netMode != 1)
											{
												NPC.SpawnOnPlayer(this.whoAmi, 370);
											}
											else
											{
												NetMessage.SendData(61, -1, -1, "", this.whoAmi, 370f, 0f, 0f, 0);
											}
											Main.projectile[num7].ai[0] = 2f;
										}
										else if (Main.rand.Next(7) == 0 && !this.accFishingLine)
										{
											Main.projectile[num7].ai[0] = 2f;
										}
										else
										{
											Main.projectile[num7].ai[1] = Main.projectile[num7].localAI[1];
										}
										Main.projectile[num7].netUpdate = true;
									}
								}
							}
						}
					}
				}
				if (this.inventory[this.selectedItem].shoot == 6 || this.inventory[this.selectedItem].shoot == 19 || this.inventory[this.selectedItem].shoot == 33 || this.inventory[this.selectedItem].shoot == 52 || this.inventory[this.selectedItem].shoot == 113 || this.inventory[this.selectedItem].shoot == 182 || this.inventory[this.selectedItem].shoot == 320 || this.inventory[this.selectedItem].shoot == 333 || this.inventory[this.selectedItem].shoot == 383)
				{
					for (int num12 = 0; num12 < 1000; num12++)
					{
						if (Main.projectile[num12].active && Main.projectile[num12].owner == Main.myPlayer && Main.projectile[num12].type == this.inventory[this.selectedItem].shoot)
						{
							flag2 = false;
						}
					}
				}
				if (this.inventory[this.selectedItem].shoot == 106)
				{
					int num13 = 0;
					for (int num14 = 0; num14 < 1000; num14++)
					{
						if (Main.projectile[num14].active && Main.projectile[num14].owner == Main.myPlayer && Main.projectile[num14].type == this.inventory[this.selectedItem].shoot)
						{
							num13++;
						}
					}
					if (num13 >= this.inventory[this.selectedItem].stack)
					{
						flag2 = false;
					}
				}
				if (this.inventory[this.selectedItem].shoot == 272)
				{
					int num15 = 0;
					for (int num16 = 0; num16 < 1000; num16++)
					{
						if (Main.projectile[num16].active && Main.projectile[num16].owner == Main.myPlayer && Main.projectile[num16].type == this.inventory[this.selectedItem].shoot)
						{
							num15++;
						}
					}
					if (num15 >= this.inventory[this.selectedItem].stack)
					{
						flag2 = false;
					}
				}
				if (this.inventory[this.selectedItem].shoot == 13 || this.inventory[this.selectedItem].shoot == 32 || (this.inventory[this.selectedItem].shoot >= 230 && this.inventory[this.selectedItem].shoot <= 235) || this.inventory[this.selectedItem].shoot == 315 || this.inventory[this.selectedItem].shoot == 331 || this.inventory[this.selectedItem].shoot == 372)
				{
					for (int num17 = 0; num17 < 1000; num17++)
					{
						if (Main.projectile[num17].active && Main.projectile[num17].owner == Main.myPlayer && Main.projectile[num17].type == this.inventory[this.selectedItem].shoot && Main.projectile[num17].ai[0] != 2f)
						{
							flag2 = false;
						}
					}
				}
				if (this.inventory[this.selectedItem].shoot == 332)
				{
					int num18 = 0;
					for (int num19 = 0; num19 < 1000; num19++)
					{
						if (Main.projectile[num19].active && Main.projectile[num19].owner == Main.myPlayer && Main.projectile[num19].type == this.inventory[this.selectedItem].shoot && Main.projectile[num19].ai[0] != 2f)
						{
							num18++;
						}
					}
					if (num18 >= 3)
					{
						flag2 = false;
					}
				}
				if (this.inventory[this.selectedItem].potion && flag2)
				{
					if (this.potionDelay <= 0)
					{
						this.potionDelay = this.potionDelayTime;
						this.AddBuff(21, this.potionDelay, true);
					}
					else
					{
						flag2 = false;
					}
				}
				if (this.inventory[this.selectedItem].mana > 0 && this.silence)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].mana > 0 && flag2)
				{
					if (this.inventory[this.selectedItem].type != 127 || !this.spaceGun)
					{
						if (this.statMana >= (int)((float)this.inventory[this.selectedItem].mana * this.manaCost))
						{
							this.statMana -= (int)((float)this.inventory[this.selectedItem].mana * this.manaCost);
						}
						else if (this.manaFlower)
						{
							this.QuickMana();
							if (this.statMana >= (int)((float)this.inventory[this.selectedItem].mana * this.manaCost))
							{
								this.statMana -= (int)((float)this.inventory[this.selectedItem].mana * this.manaCost);
							}
							else
							{
								flag2 = false;
							}
						}
						else
						{
							flag2 = false;
						}
					}
					if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].buffType != 0 && flag2)
					{
						this.AddBuff(this.inventory[this.selectedItem].buffType, this.inventory[this.selectedItem].buffTime, true);
					}
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 603 && Main.cEd)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 669)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 115)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 425)
				{
					int num20 = Main.rand.Next(3);
					if (num20 == 0)
					{
						num20 = 27;
					}
					if (num20 == 1)
					{
						num20 = 101;
					}
					if (num20 == 2)
					{
						num20 = 102;
					}
					for (int num21 = 0; num21 < 22; num21++)
					{
						if (this.buffType[num21] == 27 || this.buffType[num21] == 101 || this.buffType[num21] == 102)
						{
							this.DelBuff(num21);
							num21--;
						}
					}
					this.AddBuff(num20, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 753)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 994)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1169)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1170)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1171)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1172)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1180)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1181)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1182)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1183)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1242)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1157)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1309)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1311)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1837)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1312)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1798)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1799)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1802)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1810)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1927)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 1959)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2364)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2365)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2420)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2535)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2551)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2584)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2587)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].type == 2621)
				{
					this.AddBuff(this.inventory[this.selectedItem].buffType, 3600, true);
				}
				if (this.whoAmi == Main.myPlayer && this.gravDir == 1f && this.inventory[this.selectedItem].mountType != -1)
				{
					this.mount.SetMount(this.inventory[this.selectedItem].mountType, this, false);
				}
				if (this.inventory[this.selectedItem].type == 43 && Main.dayTime)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 544 && Main.dayTime)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 556 && Main.dayTime)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 557 && Main.dayTime)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 70 && !this.zoneEvil)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 1133 && !this.zoneJungle)
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 1844 && (Main.dayTime || Main.pumpkinMoon || Main.snowMoon))
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].type == 1958 && (Main.dayTime || Main.pumpkinMoon || Main.snowMoon))
				{
					flag2 = false;
				}
				if (!this.SummonItemCheck())
				{
					flag2 = false;
				}
				if (this.inventory[this.selectedItem].shoot == 17 && flag2 && i == Main.myPlayer)
				{
					int num22 = (int)((float)Main.mouseX + Main.screenPosition.X) / 16;
					int num23 = (int)((float)Main.mouseY + Main.screenPosition.Y) / 16;
					if (this.gravDir == -1f)
					{
						num23 = (int)(Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY) / 16;
					}
					Tile tile = Main.tile[num22, num23];
					if (tile.active() && (tile.type == 0 || tile.type == 2 || tile.type == 23 || tile.type == 109 || tile.type == 199))
					{
						WorldGen.KillTile(num22, num23, false, false, true);
						if (!Main.tile[num22, num23].active())
						{
							if (Main.netMode == 1)
							{
								NetMessage.SendData(17, -1, -1, "", 4, (float)num22, (float)num23, 0f, 0);
							}
						}
						else
						{
							flag2 = false;
						}
					}
					else
					{
						flag2 = false;
					}
				}
				if (flag2 && this.inventory[this.selectedItem].useAmmo > 0)
				{
					flag2 = false;
					for (int num24 = 0; num24 < 58; num24++)
					{
						if (this.inventory[num24].ammo == this.inventory[this.selectedItem].useAmmo && this.inventory[num24].stack > 0)
						{
							flag2 = true;
							break;
						}
					}
				}
				if (flag2)
				{
					if (this.inventory[this.selectedItem].pick > 0 || this.inventory[this.selectedItem].axe > 0 || this.inventory[this.selectedItem].hammer > 0)
					{
						this.toolTime = 1;
					}
					if (this.grappling[0] > -1)
					{
						this.pulley = false;
						this.pulleyDir = 1;
						if (this.controlRight)
						{
							this.direction = 1;
						}
						else if (this.controlLeft)
						{
							this.direction = -1;
						}
					}
					this.channel = this.inventory[this.selectedItem].channel;
					this.attackCD = 0;
					if (this.inventory[this.selectedItem].melee)
					{
						this.itemAnimation = (int)((float)this.inventory[this.selectedItem].useAnimation * this.meleeSpeed);
						this.itemAnimationMax = (int)((float)this.inventory[this.selectedItem].useAnimation * this.meleeSpeed);
					}
					else if (this.inventory[this.selectedItem].createTile >= 0)
					{
						this.itemAnimation = (int)((float)this.inventory[this.selectedItem].useAnimation * this.tileSpeed);
						this.itemAnimationMax = (int)((float)this.inventory[this.selectedItem].useAnimation * this.tileSpeed);
					}
					else if (this.inventory[this.selectedItem].createWall >= 0)
					{
						this.itemAnimation = (int)((float)this.inventory[this.selectedItem].useAnimation * this.wallSpeed);
						this.itemAnimationMax = (int)((float)this.inventory[this.selectedItem].useAnimation * this.wallSpeed);
					}
					else
					{
						this.itemAnimation = this.inventory[this.selectedItem].useAnimation;
						this.itemAnimationMax = this.inventory[this.selectedItem].useAnimation;
						this.reuseDelay = this.inventory[this.selectedItem].reuseDelay;
					}
					if (this.inventory[this.selectedItem].useSound > 0)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, this.inventory[this.selectedItem].useSound);
					}
				}
				if (flag2 && this.whoAmi == Main.myPlayer && (this.inventory[this.selectedItem].shoot == 18 || this.inventory[this.selectedItem].shoot == 72 || this.inventory[this.selectedItem].shoot == 86 || this.inventory[this.selectedItem].shoot == 87 || Main.projPet[this.inventory[this.selectedItem].shoot]))
				{
					if ((this.inventory[this.selectedItem].shoot >= 191 && this.inventory[this.selectedItem].shoot <= 194) || this.inventory[this.selectedItem].shoot == 266 || this.inventory[this.selectedItem].shoot == 317 || this.inventory[this.selectedItem].shoot == 373 || this.inventory[this.selectedItem].shoot == 375 || this.inventory[this.selectedItem].shoot == 387 || this.inventory[this.selectedItem].shoot == 390 || this.inventory[this.selectedItem].shoot == 393 || this.inventory[this.selectedItem].shoot == 407)
					{
						List<int> list = new List<int>();
						float num25 = 0f;
						for (int num26 = 0; num26 < 1000; num26++)
						{
							if (Main.projectile[num26].active && Main.projectile[num26].owner == i && Main.projectile[num26].minion)
							{
								int num27;
								for (num27 = 0; num27 < list.Count; num27++)
								{
									if (Main.projectile[list[num27]].minionSlots > Main.projectile[num26].minionSlots)
									{
										list.Insert(num27, num26);
										break;
									}
								}
								if (num27 == list.Count)
								{
									list.Add(num26);
								}
								num25 += Main.projectile[num26].minionSlots;
							}
						}
						int arg_24AB_0 = this.inventory[this.selectedItem].shoot;
						float num28 = 1f;
						float num29 = 0f;
						int num30 = 388;
						int num31 = 0;
						while (num31 < list.Count && num25 - num29 > (float)this.maxMinions - num28)
						{
							int type = Main.projectile[list[num31]].type;
							if (type != num30)
							{
								num29 += Main.projectile[list[num31]].minionSlots;
								if (type == 388 && num30 == 387)
								{
									num30 = 388;
								}
								if (type == 387 && num30 == 388)
								{
									num30 = 387;
								}
								Main.projectile[list[num31]].Kill();
							}
							num31++;
						}
						list.Clear();
					}
					else
					{
						for (int num32 = 0; num32 < 1000; num32++)
						{
							if (Main.projectile[num32].active && Main.projectile[num32].owner == i && Main.projectile[num32].type == this.inventory[this.selectedItem].shoot)
							{
								Main.projectile[num32].Kill();
							}
							if (this.inventory[this.selectedItem].shoot == 72)
							{
								if (Main.projectile[num32].active && Main.projectile[num32].owner == i && Main.projectile[num32].type == 86)
								{
									Main.projectile[num32].Kill();
								}
								if (Main.projectile[num32].active && Main.projectile[num32].owner == i && Main.projectile[num32].type == 87)
								{
									Main.projectile[num32].Kill();
								}
							}
						}
					}
				}
			}
			if (!this.controlUseItem)
			{
				bool arg_267A_0 = this.channel;
				this.channel = false;
			}
			if (this.itemAnimation > 0)
			{
				if (this.inventory[this.selectedItem].melee)
				{
					this.itemAnimationMax = (int)((float)this.inventory[this.selectedItem].useAnimation * this.meleeSpeed);
				}
				else
				{
					this.itemAnimationMax = this.inventory[this.selectedItem].useAnimation;
				}
				if (this.inventory[this.selectedItem].mana > 0 && !flag && (this.inventory[this.selectedItem].type != 127 || !this.spaceGun))
				{
					this.manaRegenDelay = (int)this.maxRegenDelay;
				}
				if (Main.dedServ)
				{
					this.itemHeight = this.inventory[this.selectedItem].height;
					this.itemWidth = this.inventory[this.selectedItem].width;
				}
				else
				{
					this.itemHeight = Main.itemTexture[this.inventory[this.selectedItem].type].Height;
					this.itemWidth = Main.itemTexture[this.inventory[this.selectedItem].type].Width;
				}
				this.itemAnimation--;
				if (!Main.dedServ)
				{
					if (this.inventory[this.selectedItem].useStyle == 1)
					{
						if (this.inventory[this.selectedItem].type == 1827)
						{
							if ((double)this.itemAnimation < (double)this.itemAnimationMax * 0.333)
							{
								float num33 = 10f;
								this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - num33) * (float)this.direction;
								this.itemLocation.Y = this.position.Y + 26f;
							}
							else if ((double)this.itemAnimation < (double)this.itemAnimationMax * 0.666)
							{
								float num34 = 8f;
								this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - num34) * (float)this.direction;
								num34 = 24f;
								this.itemLocation.Y = this.position.Y + num34;
							}
							else
							{
								float num35 = 6f;
								this.itemLocation.X = this.position.X + (float)this.width * 0.5f - ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - num35) * (float)this.direction;
								num35 = 20f;
								this.itemLocation.Y = this.position.Y + num35;
							}
							this.itemRotation = ((float)this.itemAnimation / (float)this.itemAnimationMax - 0.5f) * (float)(-(float)this.direction) * 3.5f - (float)this.direction * 0.3f;
						}
						else
						{
							if ((double)this.itemAnimation < (double)this.itemAnimationMax * 0.333)
							{
								float num36 = 10f;
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width > 32)
								{
									num36 = 14f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 52)
								{
									num36 = 24f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 64)
								{
									num36 = 28f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 92)
								{
									num36 = 38f;
								}
								if (this.inventory[this.selectedItem].type == 2330 || this.inventory[this.selectedItem].type == 2320 || this.inventory[this.selectedItem].type == 2341)
								{
									num36 += 8f;
								}
								this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - num36) * (float)this.direction;
								this.itemLocation.Y = this.position.Y + 24f;
							}
							else if ((double)this.itemAnimation < (double)this.itemAnimationMax * 0.666)
							{
								float num37 = 10f;
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width > 32)
								{
									num37 = 18f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 52)
								{
									num37 = 24f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 64)
								{
									num37 = 28f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 92)
								{
									num37 = 38f;
								}
								if (this.inventory[this.selectedItem].type == 2330 || this.inventory[this.selectedItem].type == 2320 || this.inventory[this.selectedItem].type == 2341)
								{
									num37 += 4f;
								}
								this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - num37) * (float)this.direction;
								num37 = 10f;
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Height > 32)
								{
									num37 = 8f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Height >= 32)
								{
									num37 = 12f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Height > 64)
								{
									num37 = 14f;
								}
								if (this.inventory[this.selectedItem].type == 2330 || this.inventory[this.selectedItem].type == 2320 || this.inventory[this.selectedItem].type == 2341)
								{
									num37 += 4f;
								}
								this.itemLocation.Y = this.position.Y + num37;
							}
							else
							{
								float num38 = 6f;
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width > 32)
								{
									num38 = 14f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 48)
								{
									num38 = 18f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 52)
								{
									num38 = 24f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 64)
								{
									num38 = 28f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Width >= 92)
								{
									num38 = 38f;
								}
								if (this.inventory[this.selectedItem].type == 2330 || this.inventory[this.selectedItem].type == 2320 || this.inventory[this.selectedItem].type == 2341)
								{
									num38 += 4f;
								}
								this.itemLocation.X = this.position.X + (float)this.width * 0.5f - ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - num38) * (float)this.direction;
								num38 = 10f;
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Height > 32)
								{
									num38 = 10f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Height > 52)
								{
									num38 = 12f;
								}
								if (Main.itemTexture[this.inventory[this.selectedItem].type].Height > 64)
								{
									num38 = 14f;
								}
								if (this.inventory[this.selectedItem].type == 2330 || this.inventory[this.selectedItem].type == 2320 || this.inventory[this.selectedItem].type == 2341)
								{
									num38 += 4f;
								}
								this.itemLocation.Y = this.position.Y + num38;
							}
							this.itemRotation = ((float)this.itemAnimation / (float)this.itemAnimationMax - 0.5f) * (float)(-(float)this.direction) * 3.5f - (float)this.direction * 0.3f;
						}
						if (this.gravDir == -1f)
						{
							this.itemRotation = -this.itemRotation;
							this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
						}
					}
					else if (this.inventory[this.selectedItem].useStyle == 2)
					{
						this.itemRotation = (float)this.itemAnimation / (float)this.itemAnimationMax * (float)this.direction * 2f + -1.4f * (float)this.direction;
						if ((double)this.itemAnimation < (double)this.itemAnimationMax * 0.5)
						{
							this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - 9f - this.itemRotation * 12f * (float)this.direction) * (float)this.direction;
							this.itemLocation.Y = this.position.Y + 38f + this.itemRotation * (float)this.direction * 4f;
						}
						else
						{
							this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - 9f - this.itemRotation * 16f * (float)this.direction) * (float)this.direction;
							this.itemLocation.Y = this.position.Y + 38f + this.itemRotation * (float)this.direction;
						}
						if (this.gravDir == -1f)
						{
							this.itemRotation = -this.itemRotation;
							this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
						}
					}
					else if (this.inventory[this.selectedItem].useStyle == 3)
					{
						if ((double)this.itemAnimation > (double)this.itemAnimationMax * 0.666)
						{
							this.itemLocation.X = -1000f;
							this.itemLocation.Y = -1000f;
							this.itemRotation = -1.3f * (float)this.direction;
						}
						else
						{
							this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - 4f) * (float)this.direction;
							this.itemLocation.Y = this.position.Y + 24f;
							float num39 = (float)this.itemAnimation / (float)this.itemAnimationMax * (float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * (float)this.direction * this.inventory[this.selectedItem].scale * 1.2f - (float)(10 * this.direction);
							if (num39 > -4f && this.direction == -1)
							{
								num39 = -8f;
							}
							if (num39 < 4f && this.direction == 1)
							{
								num39 = 8f;
							}
							this.itemLocation.X = this.itemLocation.X - num39;
							this.itemRotation = 0.8f * (float)this.direction;
						}
						if (this.gravDir == -1f)
						{
							this.itemRotation = -this.itemRotation;
							this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
						}
					}
					else if (this.inventory[this.selectedItem].useStyle == 4)
					{
						this.itemRotation = 0f;
						this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - 9f - this.itemRotation * 14f * (float)this.direction - 4f) * (float)this.direction;
						this.itemLocation.Y = this.position.Y + (float)Main.itemTexture[this.inventory[this.selectedItem].type].Height * 0.5f + 4f;
						if (this.gravDir == -1f)
						{
							this.itemRotation = -this.itemRotation;
							this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
						}
					}
					else if (this.inventory[this.selectedItem].useStyle == 5)
					{
						this.itemLocation.X = this.position.X + (float)this.width * 0.5f - (float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - (float)(this.direction * 2);
						this.itemLocation.Y = this.position.Y + (float)this.height * 0.5f - (float)Main.itemTexture[this.inventory[this.selectedItem].type].Height * 0.5f;
					}
				}
			}
			else if (this.inventory[this.selectedItem].holdStyle == 1 && !this.pulley && !this.mount.Active)
			{
				if (Main.dedServ)
				{
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f + 20f * (float)this.direction;
				}
				else if (this.inventory[this.selectedItem].type == 930)
				{
					this.itemLocation.X = this.position.X + (float)(this.width / 2) * 0.5f - 12f - (float)(2 * this.direction);
					float num40 = this.position.X + (float)(this.width / 2) + (float)(38 * this.direction);
					if (this.direction == 1)
					{
						num40 -= 10f;
					}
					float num41 = this.position.Y + (float)(this.height / 2) - 4f * this.gravDir;
					if (this.gravDir == -1f)
					{
						num41 -= 8f;
					}
					int num42 = 0;
					for (int num43 = 54; num43 < 58; num43++)
					{
						if (this.inventory[num43].stack > 0 && this.inventory[num43].ammo == 931)
						{
							num42 = this.inventory[num43].type;
							break;
						}
					}
					if (num42 == 0)
					{
						for (int num44 = 0; num44 < 54; num44++)
						{
							if (this.inventory[num44].stack > 0 && this.inventory[num44].ammo == 931)
							{
								num42 = this.inventory[num44].type;
								break;
							}
						}
					}
					if (num42 == 931)
					{
						num42 = 127;
					}
					else if (num42 == 1614)
					{
						num42 = 187;
					}
					if (num42 > 0)
					{
						int num45 = Dust.NewDust(new Vector2(num40, num41 + this.gfxOffY), 6, 6, num42, 0f, 0f, 100, default(Color), 1.6f);
						Main.dust[num45].noGravity = true;
						Dust expr_38C3_cp_0 = Main.dust[num45];
						expr_38C3_cp_0.velocity.Y = expr_38C3_cp_0.velocity.Y - 4f * this.gravDir;
					}
				}
				else if (this.inventory[this.selectedItem].type == 968)
				{
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f + (float)(8 * this.direction);
					if (this.whoAmi == Main.myPlayer)
					{
						int num46 = (int)(this.itemLocation.X + (float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.8f * (float)this.direction) / 16;
						int num47 = (int)(this.itemLocation.Y + (float)(Main.itemTexture[this.inventory[this.selectedItem].type].Height / 2)) / 16;
						if (Main.tile[num46, num47] == null)
						{
							Main.tile[num46, num47] = new Tile();
						}
						if (Main.tile[num46, num47].active() && Main.tile[num46, num47].type == 215)
						{
							this.miscTimer++;
							if (Main.rand.Next(5) == 0)
							{
								this.miscTimer++;
							}
							if (this.miscTimer > 900)
							{
								this.miscTimer = 0;
								this.inventory[this.selectedItem].SetDefaults(969, false);
								if (this.selectedItem == 58)
								{
									Main.mouseItem.SetDefaults(969, false);
								}
								for (int num48 = 0; num48 < 58; num48++)
								{
									if (this.inventory[num48].type == this.inventory[this.selectedItem].type && num48 != this.selectedItem && this.inventory[num48].stack < this.inventory[num48].maxStack)
									{
										Main.PlaySound(7, -1, -1, 1);
										this.inventory[num48].stack++;
										this.inventory[this.selectedItem].SetDefaults(0, false);
										if (this.selectedItem == 58)
										{
											Main.mouseItem.SetDefaults(0, false);
										}
									}
								}
							}
						}
						else
						{
							this.miscTimer = 0;
						}
					}
				}
				else if (this.inventory[this.selectedItem].type == 856)
				{
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f + (float)(4 * this.direction);
				}
				else if (this.inventory[this.selectedItem].fishingPole > 0)
				{
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f + (float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.18f * (float)this.direction;
				}
				else
				{
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f + ((float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f + 2f) * (float)this.direction;
					if (this.inventory[this.selectedItem].type == 282 || this.inventory[this.selectedItem].type == 286)
					{
						this.itemLocation.X = this.itemLocation.X - (float)(this.direction * 2);
						this.itemLocation.Y = this.itemLocation.Y + 4f;
					}
				}
				this.itemLocation.Y = this.position.Y + 24f;
				if (this.inventory[this.selectedItem].type == 856)
				{
					this.itemLocation.Y = this.position.Y + 34f;
				}
				if (this.inventory[this.selectedItem].type == 930)
				{
					this.itemLocation.Y = this.position.Y + 9f;
				}
				if (this.inventory[this.selectedItem].fishingPole > 0)
				{
					this.itemLocation.Y = this.itemLocation.Y + 4f;
				}
				this.itemRotation = 0f;
				if (this.gravDir == -1f)
				{
					this.itemRotation = -this.itemRotation;
					this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
					if (this.inventory[this.selectedItem].type == 930)
					{
						this.itemLocation.Y = this.itemLocation.Y - 24f;
					}
				}
			}
			else if (this.inventory[this.selectedItem].holdStyle == 2 && !this.pulley && !this.mount.Active)
			{
				if (this.inventory[this.selectedItem].type == 946)
				{
					this.itemRotation = 0f;
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f - (float)(16 * this.direction);
					this.itemLocation.Y = this.position.Y + 22f;
					this.fallStart = (int)(this.position.Y / 16f);
					if (this.gravDir == -1f)
					{
						this.itemRotation = -this.itemRotation;
						this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
						if (this.velocity.Y < -2f)
						{
							this.velocity.Y = -2f;
						}
					}
					else if (this.velocity.Y > 2f)
					{
						this.velocity.Y = 2f;
					}
				}
				else
				{
					this.itemLocation.X = this.position.X + (float)this.width * 0.5f + (float)(6 * this.direction);
					this.itemLocation.Y = this.position.Y + 16f;
					this.itemRotation = 0.79f * (float)(-(float)this.direction);
					if (this.gravDir == -1f)
					{
						this.itemRotation = -this.itemRotation;
						this.itemLocation.Y = this.position.Y + (float)this.height + (this.position.Y - this.itemLocation.Y);
					}
				}
			}
			else if (this.inventory[this.selectedItem].holdStyle == 3 && !this.pulley && !this.mount.Active && !Main.dedServ)
			{
				this.itemLocation.X = this.position.X + (float)this.width * 0.5f - (float)Main.itemTexture[this.inventory[this.selectedItem].type].Width * 0.5f - (float)(this.direction * 2);
				this.itemLocation.Y = this.position.Y + (float)this.height * 0.5f - (float)Main.itemTexture[this.inventory[this.selectedItem].type].Height * 0.5f;
				this.itemRotation = 0f;
			}
			if ((((this.inventory[this.selectedItem].type == 974 || this.inventory[this.selectedItem].type == 8 || this.inventory[this.selectedItem].type == 1245 || this.inventory[this.selectedItem].type == 2274 || (this.inventory[this.selectedItem].type >= 427 && this.inventory[this.selectedItem].type <= 433)) && !this.wet) || this.inventory[this.selectedItem].type == 523 || this.inventory[this.selectedItem].type == 1333) && !this.pulley && !this.mount.Active)
			{
				float num49 = 1f;
				float num50 = 0.95f;
				float num51 = 0.8f;
				int num52 = 0;
				if (this.inventory[this.selectedItem].type == 523)
				{
					num52 = 8;
				}
				else if (this.inventory[this.selectedItem].type == 974)
				{
					num52 = 9;
				}
				else if (this.inventory[this.selectedItem].type == 1245)
				{
					num52 = 10;
				}
				else if (this.inventory[this.selectedItem].type == 1333)
				{
					num52 = 11;
				}
				else if (this.inventory[this.selectedItem].type == 2274)
				{
					num52 = 12;
				}
				else if (this.inventory[this.selectedItem].type >= 427)
				{
					num52 = this.inventory[this.selectedItem].type - 426;
				}
				if (num52 == 1)
				{
					num49 = 0f;
					num50 = 0.1f;
					num51 = 1.3f;
				}
				else if (num52 == 2)
				{
					num49 = 1f;
					num50 = 0.1f;
					num51 = 0.1f;
				}
				else if (num52 == 3)
				{
					num49 = 0f;
					num50 = 1f;
					num51 = 0.1f;
				}
				else if (num52 == 4)
				{
					num49 = 0.9f;
					num50 = 0f;
					num51 = 0.9f;
				}
				else if (num52 == 5)
				{
					num49 = 1.3f;
					num50 = 1.3f;
					num51 = 1.3f;
				}
				else if (num52 == 6)
				{
					num49 = 0.9f;
					num50 = 0.9f;
					num51 = 0f;
				}
				else if (num52 == 7)
				{
					num49 = 0.5f * Main.demonTorch + 1f * (1f - Main.demonTorch);
					num50 = 0.3f;
					num51 = 1f * Main.demonTorch + 0.5f * (1f - Main.demonTorch);
				}
				else if (num52 == 8)
				{
					num51 = 0.7f;
					num49 = 0.85f;
					num50 = 1f;
				}
				else if (num52 == 9)
				{
					num51 = 1f;
					num49 = 0.7f;
					num50 = 0.85f;
				}
				else if (num52 == 10)
				{
					num51 = 0f;
					num49 = 1f;
					num50 = 0.5f;
				}
				else if (num52 == 11)
				{
					num51 = 0.8f;
					num49 = 1.25f;
					num50 = 1.25f;
				}
				else if (num52 == 12)
				{
					num49 *= 0.75f;
					num50 *= 1.3499999f;
					num51 *= 1.5f;
				}
				int num53 = num52;
				if (num53 == 0)
				{
					num53 = 6;
				}
				else if (num53 == 8)
				{
					num53 = 75;
				}
				else if (num53 == 9)
				{
					num53 = 135;
				}
				else if (num53 == 10)
				{
					num53 = 158;
				}
				else if (num53 == 11)
				{
					num53 = 169;
				}
				else if (num53 == 12)
				{
					num53 = 156;
				}
				else
				{
					num53 = 58 + num53;
				}
				int maxValue = 30;
				if (this.itemAnimation > 0)
				{
					maxValue = 7;
				}
				if (this.direction == -1)
				{
					if (Main.rand.Next(maxValue) == 0)
					{
						int num54 = Dust.NewDust(new Vector2(this.itemLocation.X - 16f, this.itemLocation.Y - 14f * this.gravDir), 4, 4, num53, 0f, 0f, 100, default(Color), 1f);
						if (Main.rand.Next(3) != 0)
						{
							Main.dust[num54].noGravity = true;
						}
						Main.dust[num54].velocity *= 0.3f;
						Dust expr_457E_cp_0 = Main.dust[num54];
						expr_457E_cp_0.velocity.Y = expr_457E_cp_0.velocity.Y - 1.5f;
					}
					Lighting.addLight((int)((this.itemLocation.X - 12f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f + this.velocity.Y) / 16f), num49, num50, num51);
				}
				else
				{
					if (Main.rand.Next(maxValue) == 0)
					{
						int num55 = Dust.NewDust(new Vector2(this.itemLocation.X + 6f, this.itemLocation.Y - 14f * this.gravDir), 4, 4, num53, 0f, 0f, 100, default(Color), 1f);
						if (Main.rand.Next(3) != 0)
						{
							Main.dust[num55].noGravity = true;
						}
						Main.dust[num55].velocity *= 0.3f;
						Dust expr_4695_cp_0 = Main.dust[num55];
						expr_4695_cp_0.velocity.Y = expr_4695_cp_0.velocity.Y - 1.5f;
					}
					Lighting.addLight((int)((this.itemLocation.X + 12f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f + this.velocity.Y) / 16f), num49, num50, num51);
				}
			}
			if ((this.inventory[this.selectedItem].type == 105 || this.inventory[this.selectedItem].type == 713) && !this.wet && !this.pulley)
			{
				int maxValue2 = 20;
				if (this.itemAnimation > 0)
				{
					maxValue2 = 7;
				}
				if (this.direction == -1)
				{
					if (Main.rand.Next(maxValue2) == 0)
					{
						int num56 = Dust.NewDust(new Vector2(this.itemLocation.X - 12f, this.itemLocation.Y - 20f * this.gravDir), 4, 4, 6, 0f, 0f, 100, default(Color), 1f);
						if (Main.rand.Next(3) != 0)
						{
							Main.dust[num56].noGravity = true;
						}
						Main.dust[num56].velocity *= 0.3f;
						Dust expr_480A_cp_0 = Main.dust[num56];
						expr_480A_cp_0.velocity.Y = expr_480A_cp_0.velocity.Y - 1.5f;
					}
					Lighting.addLight((int)((this.itemLocation.X - 16f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 1f, 0.95f, 0.8f);
				}
				else
				{
					if (Main.rand.Next(maxValue2) == 0)
					{
						int num57 = Dust.NewDust(new Vector2(this.itemLocation.X + 4f, this.itemLocation.Y - 20f * this.gravDir), 4, 4, 6, 0f, 0f, 100, default(Color), 1f);
						if (Main.rand.Next(3) != 0)
						{
							Main.dust[num57].noGravity = true;
						}
						Main.dust[num57].velocity *= 0.3f;
						Dust expr_491D_cp_0 = Main.dust[num57];
						expr_491D_cp_0.velocity.Y = expr_491D_cp_0.velocity.Y - 1.5f;
					}
					Lighting.addLight((int)((this.itemLocation.X + 6f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 1f, 0.95f, 0.8f);
				}
			}
			else if (this.inventory[this.selectedItem].type == 148 && !this.wet)
			{
				int maxValue3 = 10;
				if (this.itemAnimation > 0)
				{
					maxValue3 = 7;
				}
				if (this.direction == -1)
				{
					if (Main.rand.Next(maxValue3) == 0)
					{
						int num58 = Dust.NewDust(new Vector2(this.itemLocation.X - 12f, this.itemLocation.Y - 20f * this.gravDir), 4, 4, 172, 0f, 0f, 100, default(Color), 1f);
						if (Main.rand.Next(3) != 0)
						{
							Main.dust[num58].noGravity = true;
						}
						Main.dust[num58].velocity *= 0.3f;
						Dust expr_4A77_cp_0 = Main.dust[num58];
						expr_4A77_cp_0.velocity.Y = expr_4A77_cp_0.velocity.Y - 1.5f;
					}
					Lighting.addLight((int)((this.itemLocation.X - 16f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 0f, 0.5f, 1f);
				}
				else
				{
					if (Main.rand.Next(maxValue3) == 0)
					{
						int num59 = Dust.NewDust(new Vector2(this.itemLocation.X + 4f, this.itemLocation.Y - 20f * this.gravDir), 4, 4, 172, 0f, 0f, 100, default(Color), 1f);
						if (Main.rand.Next(3) != 0)
						{
							Main.dust[num59].noGravity = true;
						}
						Main.dust[num59].velocity *= 0.3f;
						Dust expr_4B8E_cp_0 = Main.dust[num59];
						expr_4B8E_cp_0.velocity.Y = expr_4B8E_cp_0.velocity.Y - 1.5f;
					}
					Lighting.addLight((int)((this.itemLocation.X + 6f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 0f, 0.5f, 1f);
				}
			}
			if (this.inventory[this.selectedItem].type == 282 && !this.pulley)
			{
				if (this.direction == -1)
				{
					Lighting.addLight((int)((this.itemLocation.X - 16f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 0.7f, 1f, 0.8f);
				}
				else
				{
					Lighting.addLight((int)((this.itemLocation.X + 6f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 0.7f, 1f, 0.8f);
				}
			}
			if (this.inventory[this.selectedItem].type == 286 && !this.pulley)
			{
				if (this.direction == -1)
				{
					Lighting.addLight((int)((this.itemLocation.X - 16f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 0.7f, 0.8f, 1f);
				}
				else
				{
					Lighting.addLight((int)((this.itemLocation.X + 6f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), 0.7f, 0.8f, 1f);
				}
			}
			if (this.controlUseItem)
			{
				this.releaseUseItem = false;
			}
			else
			{
				this.releaseUseItem = true;
			}
			if (this.itemTime > 0)
			{
				this.itemTime--;
				if (this.itemTime == 0 && this.whoAmi == Main.myPlayer)
				{
					int type2 = this.inventory[this.selectedItem].type;
					if (type2 == 65 || type2 == 676 || type2 == 723 || type2 == 724 || type2 == 989 || type2 == 1226 || type2 == 1227)
					{
						Main.PlaySound(25, -1, -1, 1);
						for (int num60 = 0; num60 < 5; num60++)
						{
							int num61 = Dust.NewDust(this.position, this.width, this.height, 45, 0f, 0f, 255, default(Color), (float)Main.rand.Next(20, 26) * 0.1f);
							Main.dust[num61].noLight = true;
							Main.dust[num61].noGravity = true;
							Main.dust[num61].velocity *= 0.5f;
						}
					}
				}
			}
			if (i == Main.myPlayer)
			{
				bool flag6 = true;
				int type3 = this.inventory[this.selectedItem].type;
				if ((type3 == 65 || type3 == 676 || type3 == 723 || type3 == 724 || type3 == 757 || type3 == 674 || type3 == 675 || type3 == 989 || type3 == 1226 || type3 == 1227) && this.itemAnimation != this.itemAnimationMax - 1)
				{
					flag6 = false;
				}
				if (this.inventory[this.selectedItem].shoot > 0 && this.itemAnimation > 0 && this.itemTime == 0 && flag6)
				{
					int num62 = this.inventory[this.selectedItem].shoot;
					float num63 = this.inventory[this.selectedItem].shootSpeed;
					if (this.inventory[this.selectedItem].melee && num62 != 25 && num62 != 26 && num62 != 35)
					{
						num63 /= this.meleeSpeed;
					}
					bool flag7 = false;
					int num64 = num2;
					float num65 = this.inventory[this.selectedItem].knockBack;
					if (num62 == 13 || num62 == 32 || num62 == 315 || (num62 >= 230 && num62 <= 235) || num62 == 331)
					{
						this.grappling[0] = -1;
						this.grapCount = 0;
						for (int num66 = 0; num66 < 1000; num66++)
						{
							if (Main.projectile[num66].active && Main.projectile[num66].owner == i)
							{
								if (Main.projectile[num66].type == 13)
								{
									Main.projectile[num66].Kill();
								}
								if (Main.projectile[num66].type == 331)
								{
									Main.projectile[num66].Kill();
								}
								if (Main.projectile[num66].type == 315)
								{
									Main.projectile[num66].Kill();
								}
								if (Main.projectile[num66].type >= 230 && Main.projectile[num66].type <= 235)
								{
									Main.projectile[num66].Kill();
								}
							}
						}
					}
					if (this.inventory[this.selectedItem].useAmmo > 0)
					{
						Item item2 = new Item();
						bool flag8 = false;
						for (int num67 = 54; num67 < 58; num67++)
						{
							if (this.inventory[num67].ammo == this.inventory[this.selectedItem].useAmmo && this.inventory[num67].stack > 0)
							{
								item2 = this.inventory[num67];
								flag7 = true;
								flag8 = true;
								break;
							}
						}
						if (!flag8)
						{
							for (int num68 = 0; num68 < 54; num68++)
							{
								if (this.inventory[num68].ammo == this.inventory[this.selectedItem].useAmmo && this.inventory[num68].stack > 0)
								{
									item2 = this.inventory[num68];
									flag7 = true;
									break;
								}
							}
						}
						if (flag7)
						{
							if (this.inventory[this.selectedItem].type == 1946)
							{
								num62 = 338 + item2.type - 771;
							}
							else if (this.inventory[this.selectedItem].useAmmo == 771)
							{
								num62 += item2.shoot;
							}
							else if (this.inventory[this.selectedItem].useAmmo == 780)
							{
								num62 += item2.shoot;
							}
							else if (item2.shoot > 0)
							{
								num62 = item2.shoot;
							}
							if (num62 == 42)
							{
								if (item2.type == 370)
								{
									num62 = 65;
									num64 += 5;
								}
								else if (item2.type == 408)
								{
									num62 = 68;
									num64 += 5;
								}
								else if (item2.type == 1246)
								{
									num62 = 354;
									num64 += 5;
								}
							}
							if (this.magicQuiver && (this.inventory[this.selectedItem].useAmmo == 1 || this.inventory[this.selectedItem].useAmmo == 323))
							{
								num65 = (float)((int)((double)num65 * 1.1));
								num63 *= 1.1f;
							}
							num63 += item2.shootSpeed;
							if (item2.ranged)
							{
								if (item2.damage > 0)
								{
									num64 += (int)((float)item2.damage * this.rangedDamage);
								}
							}
							else
							{
								num64 += item2.damage;
							}
							if (this.inventory[this.selectedItem].useAmmo == 1 && this.archery)
							{
								if (num63 < 20f)
								{
									num63 *= 1.2f;
									if (num63 > 20f)
									{
										num63 = 20f;
									}
								}
								num64 = (int)((double)((float)num64) * 1.2);
							}
							num65 += item2.knockBack;
							bool flag9 = false;
							if (this.magicQuiver && this.inventory[this.selectedItem].useAmmo == 1 && Main.rand.Next(5) == 0)
							{
								flag9 = true;
							}
							if (this.ammoBox && Main.rand.Next(5) == 0)
							{
								flag9 = true;
							}
							if (this.ammoPotion && Main.rand.Next(5) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 1782 && Main.rand.Next(3) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 98 && Main.rand.Next(3) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 2270 && Main.rand.Next(2) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 533 && Main.rand.Next(2) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 1929 && Main.rand.Next(2) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 1553 && Main.rand.Next(2) == 0)
							{
								flag9 = true;
							}
							if (this.inventory[this.selectedItem].type == 434 && this.itemAnimation < this.inventory[this.selectedItem].useAnimation - 2)
							{
								flag9 = true;
							}
							if (this.ammoCost80 && Main.rand.Next(5) == 0)
							{
								flag9 = true;
							}
							if (this.ammoCost75 && Main.rand.Next(4) == 0)
							{
								flag9 = true;
							}
							if (num62 == 85 && this.itemAnimation < this.itemAnimationMax - 6)
							{
								flag9 = true;
							}
							if ((num62 == 145 || num62 == 146 || num62 == 147 || num62 == 148 || num62 == 149) && this.itemAnimation < this.itemAnimationMax - 5)
							{
								flag9 = true;
							}
							if (!flag9)
							{
								item2.stack--;
								if (item2.stack <= 0)
								{
									item2.active = false;
									item2.name = "";
									item2.type = 0;
								}
							}
						}
					}
					else
					{
						flag7 = true;
					}
					if (this.inventory[this.selectedItem].type == 71)
					{
						flag7 = false;
					}
					if (this.inventory[this.selectedItem].type == 72)
					{
						flag7 = false;
					}
					if (this.inventory[this.selectedItem].type == 73)
					{
						flag7 = false;
					}
					if (this.inventory[this.selectedItem].type == 74)
					{
						flag7 = false;
					}
					if (this.inventory[this.selectedItem].type == 1254 && num62 == 14)
					{
						num62 = 242;
					}
					if (this.inventory[this.selectedItem].type == 1255 && num62 == 14)
					{
						num62 = 242;
					}
					if (this.inventory[this.selectedItem].type == 1265 && num62 == 14)
					{
						num62 = 242;
					}
					if (num62 == 73)
					{
						for (int num69 = 0; num69 < 1000; num69++)
						{
							if (Main.projectile[num69].active && Main.projectile[num69].owner == i)
							{
								if (Main.projectile[num69].type == 73)
								{
									num62 = 74;
								}
								if (num62 == 74 && Main.projectile[num69].type == 74)
								{
									flag7 = false;
								}
							}
						}
					}
					if (flag7)
					{
						if (this.inventory[this.selectedItem].summon)
						{
							num65 += this.minionKB;
							num64 = (int)((float)num64 * this.minionDamage);
						}
						if (num62 == 228)
						{
							num65 = 0f;
						}
						if (this.inventory[this.selectedItem].melee && this.kbGlove)
						{
							num65 *= 2f;
						}
						if (this.kbBuff)
						{
							num65 *= 1.5f;
						}
						if (this.inventory[this.selectedItem].ranged && this.armorSteath)
						{
							num65 *= 1f + (1f - this.stealth) * 0.5f;
						}
						if (num62 == 1 && this.inventory[this.selectedItem].type == 120)
						{
							num62 = 2;
						}
						if (this.inventory[this.selectedItem].type == 682)
						{
							num62 = 117;
						}
						if (this.inventory[this.selectedItem].type == 725)
						{
							num62 = 120;
						}
						if (this.inventory[this.selectedItem].type == 2223)
						{
							num62 = 357;
						}
						this.itemTime = this.inventory[this.selectedItem].useTime;
						if ((float)Main.mouseX + Main.screenPosition.X > this.position.X + (float)this.width * 0.5f)
						{
							this.ChangeDir(1);
						}
						else
						{
							this.ChangeDir(-1);
						}
						Vector2 vector = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						if (num62 == 9)
						{
							vector = new Vector2(this.position.X + (float)this.width * 0.5f + (float)(Main.rand.Next(201) * -(float)this.direction) + ((float)Main.mouseX + Main.screenPosition.X - this.position.X), this.position.Y + (float)this.height * 0.5f - 600f);
							num65 = 0f;
							num64 *= 2;
						}
						else if (num62 == 51)
						{
							vector.Y -= 6f * this.gravDir;
						}
						float num70 = (float)Main.mouseX + Main.screenPosition.X - vector.X;
						float num71 = (float)Main.mouseY + Main.screenPosition.Y - vector.Y;
						if (this.gravDir == -1f)
						{
							num71 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector.Y;
						}
						float num72 = (float)Math.Sqrt((double)(num70 * num70 + num71 * num71));
						float num73 = num72;
						num72 = num63 / num72;
						if (this.inventory[this.selectedItem].type == 1929 || this.inventory[this.selectedItem].type == 2270)
						{
							num70 += (float)Main.rand.Next(-50, 51) * 0.03f / num72;
							num71 += (float)Main.rand.Next(-50, 51) * 0.03f / num72;
						}
						num70 *= num72;
						num71 *= num72;
						if (this.inventory[this.selectedItem].type == 757)
						{
							num64 = (int)((float)num64 * 1.25f);
						}
						if (num62 == 250)
						{
							for (int num74 = 0; num74 < 1000; num74++)
							{
								if (Main.projectile[num74].active && Main.projectile[num74].owner == this.whoAmi && (Main.projectile[num74].type == 250 || Main.projectile[num74].type == 251))
								{
									Main.projectile[num74].Kill();
								}
							}
						}
						if (num62 == 12)
						{
							vector.X += num70 * 3f;
							vector.Y += num71 * 3f;
						}
						if (this.inventory[this.selectedItem].useStyle == 5)
						{
							this.itemRotation = (float)Math.Atan2((double)(num71 * (float)this.direction), (double)(num70 * (float)this.direction));
							NetMessage.SendData(13, -1, -1, "", this.whoAmi, 0f, 0f, 0f, 0);
							NetMessage.SendData(41, -1, -1, "", this.whoAmi, 0f, 0f, 0f, 0);
						}
						if (num62 == 17)
						{
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							if (this.gravDir == -1f)
							{
								vector.Y = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY;
							}
						}
						if (num62 == 76)
						{
							num62 += Main.rand.Next(3);
							num73 /= (float)(Main.screenHeight / 2);
							if (num73 > 1f)
							{
								num73 = 1f;
							}
							float num75 = num70 + (float)Main.rand.Next(-40, 41) * 0.01f;
							float num76 = num71 + (float)Main.rand.Next(-40, 41) * 0.01f;
							num75 *= num73 + 0.25f;
							num76 *= num73 + 0.25f;
							int num77 = Projectile.NewProjectile(vector.X, vector.Y, num75, num76, num62, num64, num65, i, 0f, 0f);
							Main.projectile[num77].ai[1] = 1f;
							num73 = num73 * 2f - 1f;
							if (num73 < -1f)
							{
								num73 = -1f;
							}
							if (num73 > 1f)
							{
								num73 = 1f;
							}
							Main.projectile[num77].ai[0] = num73;
							NetMessage.SendData(27, -1, -1, "", num77, 0f, 0f, 0f, 0);
						}
						else if (this.inventory[this.selectedItem].type == 98 || this.inventory[this.selectedItem].type == 533)
						{
							float speedX = num70 + (float)Main.rand.Next(-40, 41) * 0.01f;
							float speedY = num71 + (float)Main.rand.Next(-40, 41) * 0.01f;
							Projectile.NewProjectile(vector.X, vector.Y, speedX, speedY, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 2270)
						{
							float num78 = num70 + (float)Main.rand.Next(-40, 41) * 0.05f;
							float num79 = num71 + (float)Main.rand.Next(-40, 41) * 0.05f;
							if (Main.rand.Next(3) == 0)
							{
								num78 *= 1f + (float)Main.rand.Next(-30, 31) * 0.02f;
								num79 *= 1f + (float)Main.rand.Next(-30, 31) * 0.02f;
							}
							Projectile.NewProjectile(vector.X, vector.Y, num78, num79, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 1930)
						{
							int num80 = 2 + Main.rand.Next(3);
							for (int num81 = 0; num81 < num80; num81++)
							{
								float num82 = num70;
								float num83 = num71;
								float num84 = 0.025f * (float)num81;
								num82 += (float)Main.rand.Next(-35, 36) * num84;
								num83 += (float)Main.rand.Next(-35, 36) * num84;
								num72 = (float)Math.Sqrt((double)(num82 * num82 + num83 * num83));
								num72 = num63 / num72;
								num82 *= num72;
								num83 *= num72;
								float x = vector.X + num70 * (float)(num80 - num81) * 1.75f;
								float y = vector.Y + num71 * (float)(num80 - num81) * 1.75f;
								Projectile.NewProjectile(x, y, num82, num83, num62, num64, num65, i, (float)Main.rand.Next(0, 10 * (num81 + 1)), 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 1931)
						{
							int num85 = 2;
							for (int num86 = 0; num86 < num85; num86++)
							{
								vector = new Vector2(this.position.X + (float)this.width * 0.5f + (float)(Main.rand.Next(201) * -(float)this.direction) + ((float)Main.mouseX + Main.screenPosition.X - this.position.X), this.position.Y + (float)this.height * 0.5f - 600f);
								vector.X = (vector.X + this.center().X) / 2f + (float)Main.rand.Next(-200, 201);
								vector.Y -= (float)(100 * num86);
								num70 = (float)Main.mouseX + Main.screenPosition.X - vector.X;
								num71 = (float)Main.mouseY + Main.screenPosition.Y - vector.Y;
								if (num71 < 0f)
								{
									num71 *= -1f;
								}
								if (num71 < 20f)
								{
									num71 = 20f;
								}
								num72 = (float)Math.Sqrt((double)(num70 * num70 + num71 * num71));
								num72 = num63 / num72;
								num70 *= num72;
								num71 *= num72;
								float speedX2 = num70 + (float)Main.rand.Next(-40, 41) * 0.02f;
								float speedY2 = num71 + (float)Main.rand.Next(-40, 41) * 0.02f;
								Projectile.NewProjectile(vector.X, vector.Y, speedX2, speedY2, num62, num64, num65, i, 0f, (float)Main.rand.Next(5));
							}
						}
						else if (this.inventory[this.selectedItem].type == 2624)
						{
							float num87 = 0.314159274f;
							int num88 = 5;
							Vector2 vector2 = new Vector2(num70, num71);
							vector2.Normalize();
							vector2 *= 40f;
							for (int num89 = 0; num89 < num88; num89++)
							{
								float num90 = (float)num89 - ((float)num88 - 1f) / 2f;
								Vector2 vector3 = vector2.Rotate((double)(num87 * num90), default(Vector2));
								int num91 = Projectile.NewProjectile(vector.X + vector3.X, vector.Y + vector3.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
								Main.projectile[num91].noDropItem = true;
							}
						}
						else if (this.inventory[this.selectedItem].type == 1929)
						{
							float speedX3 = num70 + (float)Main.rand.Next(-40, 41) * 0.03f;
							float speedY3 = num71 + (float)Main.rand.Next(-40, 41) * 0.03f;
							Projectile.NewProjectile(vector.X, vector.Y, speedX3, speedY3, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 1553)
						{
							float speedX4 = num70 + (float)Main.rand.Next(-40, 41) * 0.005f;
							float speedY4 = num71 + (float)Main.rand.Next(-40, 41) * 0.005f;
							Projectile.NewProjectile(vector.X, vector.Y, speedX4, speedY4, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 518)
						{
							float num92 = num70;
							float num93 = num71;
							num92 += (float)Main.rand.Next(-40, 41) * 0.04f;
							num93 += (float)Main.rand.Next(-40, 41) * 0.04f;
							Projectile.NewProjectile(vector.X, vector.Y, num92, num93, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 1265)
						{
							float num94 = num70;
							float num95 = num71;
							num94 += (float)Main.rand.Next(-30, 31) * 0.03f;
							num95 += (float)Main.rand.Next(-30, 31) * 0.03f;
							Projectile.NewProjectile(vector.X, vector.Y, num94, num95, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 534)
						{
							for (int num96 = 0; num96 < 4; num96++)
							{
								float num97 = num70;
								float num98 = num71;
								num97 += (float)Main.rand.Next(-40, 41) * 0.05f;
								num98 += (float)Main.rand.Next(-40, 41) * 0.05f;
								Projectile.NewProjectile(vector.X, vector.Y, num97, num98, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 2188)
						{
							int num99 = 4;
							if (Main.rand.Next(3) == 0)
							{
								num99++;
							}
							if (Main.rand.Next(4) == 0)
							{
								num99++;
							}
							if (Main.rand.Next(5) == 0)
							{
								num99++;
							}
							for (int num100 = 0; num100 < num99; num100++)
							{
								float num101 = num70;
								float num102 = num71;
								float num103 = 0.05f * (float)num100;
								num101 += (float)Main.rand.Next(-35, 36) * num103;
								num102 += (float)Main.rand.Next(-35, 36) * num103;
								num72 = (float)Math.Sqrt((double)(num101 * num101 + num102 * num102));
								num72 = num63 / num72;
								num101 *= num72;
								num102 *= num72;
								float x2 = vector.X;
								float y2 = vector.Y;
								Projectile.NewProjectile(x2, y2, num101, num102, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 1308)
						{
							int num104 = 3;
							if (Main.rand.Next(3) == 0)
							{
								num104++;
							}
							for (int num105 = 0; num105 < num104; num105++)
							{
								float num106 = num70;
								float num107 = num71;
								float num108 = 0.05f * (float)num105;
								num106 += (float)Main.rand.Next(-35, 36) * num108;
								num107 += (float)Main.rand.Next(-35, 36) * num108;
								num72 = (float)Math.Sqrt((double)(num106 * num106 + num107 * num107));
								num72 = num63 / num72;
								num106 *= num72;
								num107 *= num72;
								float x3 = vector.X;
								float y3 = vector.Y;
								Projectile.NewProjectile(x3, y3, num106, num107, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 1258)
						{
							float num109 = num70;
							float num110 = num71;
							num109 += (float)Main.rand.Next(-40, 41) * 0.01f;
							num110 += (float)Main.rand.Next(-40, 41) * 0.01f;
							vector.X += (float)Main.rand.Next(-40, 41) * 0.05f;
							vector.Y += (float)Main.rand.Next(-45, 36) * 0.05f;
							Projectile.NewProjectile(vector.X, vector.Y, num109, num110, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 964)
						{
							for (int num111 = 0; num111 < 3; num111++)
							{
								float num112 = num70;
								float num113 = num71;
								num112 += (float)Main.rand.Next(-35, 36) * 0.04f;
								num113 += (float)Main.rand.Next(-35, 36) * 0.04f;
								Projectile.NewProjectile(vector.X, vector.Y, num112, num113, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 1569)
						{
							int num114 = 4;
							if (Main.rand.Next(2) == 0)
							{
								num114++;
							}
							if (Main.rand.Next(4) == 0)
							{
								num114++;
							}
							if (Main.rand.Next(8) == 0)
							{
								num114++;
							}
							if (Main.rand.Next(16) == 0)
							{
								num114++;
							}
							for (int num115 = 0; num115 < num114; num115++)
							{
								float num116 = num70;
								float num117 = num71;
								float num118 = 0.05f * (float)num115;
								num116 += (float)Main.rand.Next(-35, 36) * num118;
								num117 += (float)Main.rand.Next(-35, 36) * num118;
								num72 = (float)Math.Sqrt((double)(num116 * num116 + num117 * num117));
								num72 = num63 / num72;
								num116 *= num72;
								num117 *= num72;
								float x4 = vector.X;
								float y4 = vector.Y;
								Projectile.NewProjectile(x4, y4, num116, num117, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 1572 || this.inventory[this.selectedItem].type == 2366)
						{
							int num119 = 308;
							if (this.inventory[this.selectedItem].type == 2366)
							{
								num119 = 377;
							}
							for (int num120 = 0; num120 < 1000; num120++)
							{
								if (Main.projectile[num120].owner == this.whoAmi && Main.projectile[num120].type == num119)
								{
									Main.projectile[num120].Kill();
								}
							}
							int num121 = (int)((float)Main.mouseX + Main.screenPosition.X) / 16;
							int num122 = (int)((float)Main.mouseY + Main.screenPosition.Y) / 16;
							if (this.gravDir == -1f)
							{
								num122 = (int)(Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY) / 16;
							}
							while (num122 < Main.maxTilesY - 10 && Main.tile[num121, num122] != null && !WorldGen.SolidTile(num121, num122) && Main.tile[num121 - 1, num122] != null && !WorldGen.SolidTile(num121 - 1, num122) && Main.tile[num121 + 1, num122] != null && !WorldGen.SolidTile(num121 + 1, num122))
							{
								num122++;
							}
							num122--;
							Projectile.NewProjectile((float)Main.mouseX + Main.screenPosition.X, (float)(num122 * 16 - 24), 0f, 15f, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 1244 || this.inventory[this.selectedItem].type == 1256)
						{
							int num123 = Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
							Main.projectile[num123].ai[0] = (float)Main.mouseX + Main.screenPosition.X;
							Main.projectile[num123].ai[1] = (float)Main.mouseY + Main.screenPosition.Y;
						}
						else if (this.inventory[this.selectedItem].type == 1229)
						{
							int num124 = Main.rand.Next(2, 4);
							if (Main.rand.Next(5) == 0)
							{
								num124++;
							}
							for (int num125 = 0; num125 < num124; num125++)
							{
								float num126 = num70;
								float num127 = num71;
								if (num125 > 0)
								{
									num126 += (float)Main.rand.Next(-35, 36) * 0.04f;
									num127 += (float)Main.rand.Next(-35, 36) * 0.04f;
								}
								if (num125 > 1)
								{
									num126 += (float)Main.rand.Next(-35, 36) * 0.04f;
									num127 += (float)Main.rand.Next(-35, 36) * 0.04f;
								}
								if (num125 > 2)
								{
									num126 += (float)Main.rand.Next(-35, 36) * 0.04f;
									num127 += (float)Main.rand.Next(-35, 36) * 0.04f;
								}
								int num128 = Projectile.NewProjectile(vector.X, vector.Y, num126, num127, num62, num64, num65, i, 0f, 0f);
								Main.projectile[num128].noDropItem = true;
							}
						}
						else if (this.inventory[this.selectedItem].type == 1121 || this.inventory[this.selectedItem].type == 1155)
						{
							int num129;
							if (this.inventory[this.selectedItem].type == 1121)
							{
								num129 = Main.rand.Next(1, 4);
								if (Main.rand.Next(6) == 0)
								{
									num129++;
								}
								if (Main.rand.Next(6) == 0)
								{
									num129++;
								}
							}
							else
							{
								num129 = Main.rand.Next(2, 5);
								if (Main.rand.Next(5) == 0)
								{
									num129++;
								}
								if (Main.rand.Next(5) == 0)
								{
									num129++;
								}
							}
							for (int num130 = 0; num130 < num129; num130++)
							{
								float num131 = num70;
								float num132 = num71;
								num131 += (float)Main.rand.Next(-35, 36) * 0.02f;
								num132 += (float)Main.rand.Next(-35, 36) * 0.02f;
								Projectile.NewProjectile(vector.X, vector.Y, num131, num132, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 1801)
						{
							int num133 = Main.rand.Next(1, 4);
							for (int num134 = 0; num134 < num133; num134++)
							{
								float num135 = num70;
								float num136 = num71;
								num135 += (float)Main.rand.Next(-35, 36) * 0.05f;
								num136 += (float)Main.rand.Next(-35, 36) * 0.05f;
								Projectile.NewProjectile(vector.X, vector.Y, num135, num136, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 679)
						{
							for (int num137 = 0; num137 < 6; num137++)
							{
								float num138 = num70;
								float num139 = num71;
								num138 += (float)Main.rand.Next(-40, 41) * 0.05f;
								num139 += (float)Main.rand.Next(-40, 41) * 0.05f;
								Projectile.NewProjectile(vector.X, vector.Y, num138, num139, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 2623)
						{
							for (int num140 = 0; num140 < 3; num140++)
							{
								float num141 = num70;
								float num142 = num71;
								num141 += (float)Main.rand.Next(-40, 41) * 0.1f;
								num142 += (float)Main.rand.Next(-40, 41) * 0.1f;
								Projectile.NewProjectile(vector.X, vector.Y, num141, num142, num62, num64, num65, i, 0f, 0f);
							}
						}
						else if (this.inventory[this.selectedItem].type == 434)
						{
							float num143 = num70;
							float num144 = num71;
							if (this.itemAnimation < 5)
							{
								num143 += (float)Main.rand.Next(-40, 41) * 0.01f;
								num144 += (float)Main.rand.Next(-40, 41) * 0.01f;
								num143 *= 1.1f;
								num144 *= 1.1f;
							}
							else if (this.itemAnimation < 10)
							{
								num143 += (float)Main.rand.Next(-20, 21) * 0.01f;
								num144 += (float)Main.rand.Next(-20, 21) * 0.01f;
								num143 *= 1.05f;
								num144 *= 1.05f;
							}
							Projectile.NewProjectile(vector.X, vector.Y, num143, num144, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 1157)
						{
							num62 = Main.rand.Next(191, 195);
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							int num145 = Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
							Main.projectile[num145].localAI[0] = 30f;
						}
						else if (this.inventory[this.selectedItem].type == 1802)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 2364 || this.inventory[this.selectedItem].type == 2365)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 2535)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Vector2 spinningpoint = new Vector2(num70, num71);
							spinningpoint = spinningpoint.Rotate(1.5707963705062866, default(Vector2));
							Projectile.NewProjectile(vector.X + spinningpoint.X, vector.Y + spinningpoint.Y, spinningpoint.X, spinningpoint.Y, num62, num64, num65, i, 0f, 0f);
							spinningpoint = spinningpoint.Rotate(-3.1415927410125732, default(Vector2));
							Projectile.NewProjectile(vector.X + spinningpoint.X, vector.Y + spinningpoint.Y, spinningpoint.X, spinningpoint.Y, num62 + 1, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 2551)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62 + Main.rand.Next(3), num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 2584)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62 + Main.rand.Next(3), num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 2621)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].type == 1309)
						{
							num70 = 0f;
							num71 = 0f;
							vector.X = (float)Main.mouseX + Main.screenPosition.X;
							vector.Y = (float)Main.mouseY + Main.screenPosition.Y;
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
						}
						else if (this.inventory[this.selectedItem].shoot > 0 && (Main.projPet[this.inventory[this.selectedItem].shoot] || this.inventory[this.selectedItem].shoot == 72 || this.inventory[this.selectedItem].shoot == 18) && !this.inventory[this.selectedItem].summon)
						{
							for (int num146 = 0; num146 < 1000; num146++)
							{
								if (Main.projectile[num146].active && Main.projectile[num146].owner == this.whoAmi)
								{
									if (this.inventory[this.selectedItem].shoot == 72)
									{
										if (Main.projectile[num146].type == 72 || Main.projectile[num146].type == 86 || Main.projectile[num146].type == 87)
										{
											Main.projectile[num146].Kill();
										}
									}
									else if (this.inventory[this.selectedItem].shoot == Main.projectile[num146].type)
									{
										Main.projectile[num146].Kill();
									}
								}
							}
							Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
						}
						else
						{
							int num147 = Projectile.NewProjectile(vector.X, vector.Y, num70, num71, num62, num64, num65, i, 0f, 0f);
							if (this.inventory[this.selectedItem].type == 726)
							{
								Main.projectile[num147].magic = true;
							}
							if (this.inventory[this.selectedItem].type == 724 || this.inventory[this.selectedItem].type == 676)
							{
								Main.projectile[num147].melee = true;
							}
							if (num62 == 80)
							{
								Main.projectile[num147].ai[0] = (float)Player.tileTargetX;
								Main.projectile[num147].ai[1] = (float)Player.tileTargetY;
							}
						}
					}
					else if (this.inventory[this.selectedItem].useStyle == 5)
					{
						this.itemRotation = 0f;
						NetMessage.SendData(41, -1, -1, "", this.whoAmi, 0f, 0f, 0f, 0);
					}
				}
				if (this.whoAmi == Main.myPlayer && (this.inventory[this.selectedItem].type == 509 || this.inventory[this.selectedItem].type == 510 || this.inventory[this.selectedItem].type == 849 || this.inventory[this.selectedItem].type == 850 || this.inventory[this.selectedItem].type == 851) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f + (float)this.blockRange >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost - (float)this.blockRange <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f + (float)this.blockRange >= (float)Player.tileTargetY)
				{
					this.showItemIcon = true;
					if (this.itemAnimation > 0 && this.itemTime == 0 && this.controlUseItem)
					{
						int i2 = Player.tileTargetX;
						int j2 = Player.tileTargetY;
						if (this.inventory[this.selectedItem].type == 509)
						{
							int num148 = -1;
							for (int num149 = 0; num149 < 58; num149++)
							{
								if (this.inventory[num149].stack > 0 && this.inventory[num149].type == 530)
								{
									num148 = num149;
									break;
								}
							}
							if (num148 >= 0 && WorldGen.PlaceWire(i2, j2))
							{
								this.inventory[num148].stack--;
								if (this.inventory[num148].stack <= 0)
								{
									this.inventory[num148].SetDefaults(0, false);
								}
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 5, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
						}
						else if (this.inventory[this.selectedItem].type == 850)
						{
							int num150 = -1;
							for (int num151 = 0; num151 < 58; num151++)
							{
								if (this.inventory[num151].stack > 0 && this.inventory[num151].type == 530)
								{
									num150 = num151;
									break;
								}
							}
							if (num150 >= 0 && WorldGen.PlaceWire2(i2, j2))
							{
								this.inventory[num150].stack--;
								if (this.inventory[num150].stack <= 0)
								{
									this.inventory[num150].SetDefaults(0, false);
								}
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 10, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
						}
						if (this.inventory[this.selectedItem].type == 851)
						{
							int num152 = -1;
							for (int num153 = 0; num153 < 58; num153++)
							{
								if (this.inventory[num153].stack > 0 && this.inventory[num153].type == 530)
								{
									num152 = num153;
									break;
								}
							}
							if (num152 >= 0 && WorldGen.PlaceWire3(i2, j2))
							{
								this.inventory[num152].stack--;
								if (this.inventory[num152].stack <= 0)
								{
									this.inventory[num152].SetDefaults(0, false);
								}
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 12, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
						}
						else if (this.inventory[this.selectedItem].type == 510)
						{
							if (WorldGen.KillActuator(i2, j2))
							{
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 9, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
							else if (WorldGen.KillWire3(i2, j2))
							{
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 13, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
							else if (WorldGen.KillWire2(i2, j2))
							{
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 11, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
							else if (WorldGen.KillWire(i2, j2))
							{
								this.itemTime = this.inventory[this.selectedItem].useTime;
								NetMessage.SendData(17, -1, -1, "", 6, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							}
						}
						else if (this.inventory[this.selectedItem].type == 849 && this.inventory[this.selectedItem].stack > 0 && WorldGen.PlaceActuator(i2, j2))
						{
							this.itemTime = this.inventory[this.selectedItem].useTime;
							NetMessage.SendData(17, -1, -1, "", 8, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
							this.inventory[this.selectedItem].stack--;
							if (this.inventory[this.selectedItem].stack <= 0)
							{
								this.inventory[this.selectedItem].SetDefaults(0, false);
							}
						}
					}
				}
				if (this.itemAnimation > 0 && this.itemTime == 0 && (this.inventory[this.selectedItem].type == 507 || this.inventory[this.selectedItem].type == 508))
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Vector2 vector4 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num154 = (float)Main.mouseX + Main.screenPosition.X - vector4.X;
					float num155 = (float)Main.mouseY + Main.screenPosition.Y - vector4.Y;
					float num156 = (float)Math.Sqrt((double)(num154 * num154 + num155 * num155));
					num156 /= (float)(Main.screenHeight / 2);
					if (num156 > 1f)
					{
						num156 = 1f;
					}
					num156 = num156 * 2f - 1f;
					if (num156 < -1f)
					{
						num156 = -1f;
					}
					if (num156 > 1f)
					{
						num156 = 1f;
					}
					Main.harpNote = num156;
					int style = 26;
					if (this.inventory[this.selectedItem].type == 507)
					{
						style = 35;
					}
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, style);
					NetMessage.SendData(58, -1, -1, "", this.whoAmi, num156, 0f, 0f, 0);
				}
				if (((this.inventory[this.selectedItem].type >= 205 && this.inventory[this.selectedItem].type <= 207) || this.inventory[this.selectedItem].type == 1128) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f >= (float)Player.tileTargetY)
				{
					this.showItemIcon = true;
					if (this.itemTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
					{
						if (this.inventory[this.selectedItem].type == 205)
						{
							int num157 = (int)Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType();
							int num158 = 0;
							for (int num159 = Player.tileTargetX - 1; num159 <= Player.tileTargetX + 1; num159++)
							{
								for (int num160 = Player.tileTargetY - 1; num160 <= Player.tileTargetY + 1; num160++)
								{
									if ((int)Main.tile[num159, num160].liquidType() == num157)
									{
										num158 += (int)Main.tile[num159, num160].liquid;
									}
								}
							}
							if (Main.tile[Player.tileTargetX, Player.tileTargetY].liquid > 0 && num158 > 100)
							{
								int liquidType = (int)Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType();
								if (!Main.tile[Player.tileTargetX, Player.tileTargetY].lava())
								{
									if (Main.tile[Player.tileTargetX, Player.tileTargetY].honey())
									{
										this.inventory[this.selectedItem].stack--;
										this.PutItemInInventory(1128, this.selectedItem);
									}
									else
									{
										this.inventory[this.selectedItem].stack--;
										this.PutItemInInventory(206, this.selectedItem);
									}
								}
								else
								{
									this.inventory[this.selectedItem].stack--;
									this.PutItemInInventory(207, this.selectedItem);
								}
								Main.PlaySound(19, (int)this.position.X, (int)this.position.Y, 1);
								this.itemTime = this.inventory[this.selectedItem].useTime;
								int num161 = (int)Main.tile[Player.tileTargetX, Player.tileTargetY].liquid;
								Main.tile[Player.tileTargetX, Player.tileTargetY].liquid = 0;
								Main.tile[Player.tileTargetX, Player.tileTargetY].lava(false);
								Main.tile[Player.tileTargetX, Player.tileTargetY].honey(false);
								WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, false);
								if (Main.netMode == 1)
								{
									NetMessage.sendWater(Player.tileTargetX, Player.tileTargetY);
								}
								else
								{
									Liquid.AddWater(Player.tileTargetX, Player.tileTargetY);
								}
								for (int num162 = Player.tileTargetX - 1; num162 <= Player.tileTargetX + 1; num162++)
								{
									for (int num163 = Player.tileTargetY - 1; num163 <= Player.tileTargetY + 1; num163++)
									{
										if (num161 < 256 && (int)Main.tile[num162, num163].liquidType() == num157)
										{
											int num164 = (int)Main.tile[num162, num163].liquid;
											if (num164 + num161 > 255)
											{
												num164 = 255 - num161;
											}
											num161 += num164;
											Tile expr_859A = Main.tile[num162, num163];
											expr_859A.liquid = (byte)(expr_859A.liquid - (byte)num164);
											Main.tile[num162, num163].liquidType(liquidType);
											if (Main.tile[num162, num163].liquid == 0)
											{
												Main.tile[num162, num163].lava(false);
												Main.tile[num162, num163].honey(false);
											}
											WorldGen.SquareTileFrame(num162, num163, false);
											if (Main.netMode == 1)
											{
												NetMessage.sendWater(num162, num163);
											}
											else
											{
												Liquid.AddWater(num162, num163);
											}
										}
									}
								}
							}
						}
						else if (Main.tile[Player.tileTargetX, Player.tileTargetY].liquid < 200 && (!Main.tile[Player.tileTargetX, Player.tileTargetY].nactive() || !Main.tileSolid[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] || Main.tileSolidTop[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type]))
						{
							if (this.inventory[this.selectedItem].type == 207)
							{
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].liquid == 0 || Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType() == 1)
								{
									Main.PlaySound(19, (int)this.position.X, (int)this.position.Y, 1);
									Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType(1);
									Main.tile[Player.tileTargetX, Player.tileTargetY].liquid = 255;
									WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
									this.inventory[this.selectedItem].stack--;
									this.PutItemInInventory(205, this.selectedItem);
									this.itemTime = this.inventory[this.selectedItem].useTime;
									if (Main.netMode == 1)
									{
										NetMessage.sendWater(Player.tileTargetX, Player.tileTargetY);
									}
								}
							}
							else if (this.inventory[this.selectedItem].type == 206)
							{
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].liquid == 0 || Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType() == 0)
								{
									Main.PlaySound(19, (int)this.position.X, (int)this.position.Y, 1);
									Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType(0);
									Main.tile[Player.tileTargetX, Player.tileTargetY].liquid = 255;
									WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
									this.inventory[this.selectedItem].stack--;
									this.PutItemInInventory(205, this.selectedItem);
									this.itemTime = this.inventory[this.selectedItem].useTime;
									if (Main.netMode == 1)
									{
										NetMessage.sendWater(Player.tileTargetX, Player.tileTargetY);
									}
								}
							}
							else if (this.inventory[this.selectedItem].type == 1128 && (Main.tile[Player.tileTargetX, Player.tileTargetY].liquid == 0 || Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType() == 2))
							{
								Main.PlaySound(19, (int)this.position.X, (int)this.position.Y, 1);
								Main.tile[Player.tileTargetX, Player.tileTargetY].liquidType(2);
								Main.tile[Player.tileTargetX, Player.tileTargetY].liquid = 255;
								WorldGen.SquareTileFrame(Player.tileTargetX, Player.tileTargetY, true);
								this.inventory[this.selectedItem].stack--;
								this.PutItemInInventory(205, this.selectedItem);
								this.itemTime = this.inventory[this.selectedItem].useTime;
								if (Main.netMode == 1)
								{
									NetMessage.sendWater(Player.tileTargetX, Player.tileTargetY);
								}
							}
						}
					}
				}
				if (!this.channel)
				{
					this.toolTime = this.itemTime;
				}
				else
				{
					this.toolTime--;
					if (this.toolTime < 0)
					{
						if (this.inventory[this.selectedItem].pick > 0)
						{
							this.toolTime = this.inventory[this.selectedItem].useTime;
						}
						else
						{
							this.toolTime = (int)((float)this.inventory[this.selectedItem].useTime * this.pickSpeed);
						}
					}
				}
				if ((this.inventory[this.selectedItem].pick > 0 || this.inventory[this.selectedItem].axe > 0 || this.inventory[this.selectedItem].hammer > 0) && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f >= (float)Player.tileTargetY)
				{
					int num165 = 0;
					bool flag10 = true;
					this.showItemIcon = true;
					if (this.toolTime == 0 && this.itemAnimation > 0 && this.controlUseItem && (!Main.tile[Player.tileTargetX, Player.tileTargetY].active() || (!Main.tileHammer[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] && !Main.tileSolid[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] && Main.tile[Player.tileTargetX, Player.tileTargetY].type != 314)))
					{
						this.poundRelease = false;
					}
					if (Main.tile[Player.tileTargetX, Player.tileTargetY].active())
					{
						if ((this.inventory[this.selectedItem].pick > 0 && !Main.tileAxe[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] && !Main.tileHammer[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type]) || (this.inventory[this.selectedItem].axe > 0 && Main.tileAxe[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type]) || (this.inventory[this.selectedItem].hammer > 0 && Main.tileHammer[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type]))
						{
							flag10 = false;
						}
						if (this.toolTime == 0 && this.itemAnimation > 0 && this.controlUseItem)
						{
							int tileId = this.hitTile.HitObject(Player.tileTargetX, Player.tileTargetY, 1);
							if (Main.tileNoFail[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type])
							{
								num165 = 100;
							}
							if (Main.tileHammer[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type])
							{
								flag10 = false;
								if (this.inventory[this.selectedItem].hammer > 0)
								{
									num165 += this.inventory[this.selectedItem].hammer;
									if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 26 && (this.inventory[this.selectedItem].hammer < 80 || !Main.hardMode))
									{
										num165 = 0;
										this.Hurt(this.statLife / 2, -this.direction, false, false, Lang.deathMsg(-1, -1, -1, 4), false);
									}
									if (this.hitTile.AddDamage(tileId, num165, true) >= 100)
									{
										this.hitTile.Clear(tileId);
										WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
										}
									}
									else
									{
										WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, true, false, false);
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
										}
									}
									if (num165 != 0)
									{
										this.hitTile.Prune();
									}
									this.itemTime = this.inventory[this.selectedItem].useTime;
								}
							}
							else if (Main.tileAxe[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type])
							{
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 80)
								{
									num165 += this.inventory[this.selectedItem].axe * 3;
								}
								else
								{
									num165 += this.inventory[this.selectedItem].axe;
								}
								if (this.inventory[this.selectedItem].axe > 0)
								{
									if (this.hitTile.AddDamage(tileId, num165, true) >= 100)
									{
										this.hitTile.Clear(tileId);
										WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, false, false, false);
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
										}
									}
									else
									{
										WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, true, false, false);
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
										}
									}
									if (num165 != 0)
									{
										this.hitTile.Prune();
									}
									this.itemTime = this.inventory[this.selectedItem].useTime;
								}
							}
							else if (this.inventory[this.selectedItem].pick > 0)
							{
								if (Main.tileDungeon[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 25 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 58 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 117 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 203)
								{
									num165 += this.inventory[this.selectedItem].pick / 2;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 48 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 232)
								{
									num165 += this.inventory[this.selectedItem].pick / 4;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 226)
								{
									num165 += this.inventory[this.selectedItem].pick / 4;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 107 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 221)
								{
									num165 += this.inventory[this.selectedItem].pick / 2;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 108 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 222)
								{
									num165 += this.inventory[this.selectedItem].pick / 3;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 111 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 223)
								{
									num165 += this.inventory[this.selectedItem].pick / 4;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 211)
								{
									num165 += this.inventory[this.selectedItem].pick / 5;
								}
								else
								{
									num165 += this.inventory[this.selectedItem].pick;
								}
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 211 && this.inventory[this.selectedItem].pick < 200)
								{
									num165 = 0;
								}
								if ((Main.tile[Player.tileTargetX, Player.tileTargetY].type == 25 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 203) && this.inventory[this.selectedItem].pick < 65)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 117 && this.inventory[this.selectedItem].pick < 65)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 37 && this.inventory[this.selectedItem].pick < 50)
								{
									num165 = 0;
								}
								else if ((Main.tile[Player.tileTargetX, Player.tileTargetY].type == 22 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 204) && (double)Player.tileTargetY > Main.worldSurface && this.inventory[this.selectedItem].pick < 55)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 56 && this.inventory[this.selectedItem].pick < 65)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 58 && this.inventory[this.selectedItem].pick < 65)
								{
									num165 = 0;
								}
								else if ((Main.tile[Player.tileTargetX, Player.tileTargetY].type == 226 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 237) && this.inventory[this.selectedItem].pick < 210)
								{
									num165 = 0;
								}
								else if (Main.tileDungeon[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] && this.inventory[this.selectedItem].pick < 65)
								{
									if ((double)Player.tileTargetX < (double)Main.maxTilesX * 0.35 || (double)Player.tileTargetX > (double)Main.maxTilesX * 0.65)
									{
										num165 = 0;
									}
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 107 && this.inventory[this.selectedItem].pick < 100)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 108 && this.inventory[this.selectedItem].pick < 110)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 111 && this.inventory[this.selectedItem].pick < 150)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 221 && this.inventory[this.selectedItem].pick < 100)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 222 && this.inventory[this.selectedItem].pick < 110)
								{
									num165 = 0;
								}
								else if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 223 && this.inventory[this.selectedItem].pick < 150)
								{
									num165 = 0;
								}
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 147 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 0 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 40 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 53 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 57 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 59 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 123 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 224)
								{
									num165 += this.inventory[this.selectedItem].pick;
								}
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 165 || Main.tileRope[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 199 || Main.tileMoss[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type])
								{
									num165 = 100;
								}
								if (this.hitTile.AddDamage(tileId, num165, false) >= 100 && (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 2 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 23 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 60 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 70 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 109 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 71 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 199 || Main.tileMoss[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type]))
								{
									num165 = 0;
								}
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 128 || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 269)
								{
									if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX == 18 || Main.tile[Player.tileTargetX, Player.tileTargetY].frameX == 54)
									{
										Player.tileTargetX--;
										this.hitTile.UpdatePosition(tileId, Player.tileTargetX, Player.tileTargetY);
									}
									if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX >= 100)
									{
										num165 = 0;
										Main.blockMouse = true;
									}
								}
								if (Main.tile[Player.tileTargetX, Player.tileTargetY].type == 334)
								{
									if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 0)
									{
										Player.tileTargetY++;
										this.hitTile.UpdatePosition(tileId, Player.tileTargetX, Player.tileTargetY);
									}
									if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameY == 36)
									{
										Player.tileTargetY--;
										this.hitTile.UpdatePosition(tileId, Player.tileTargetX, Player.tileTargetY);
									}
									int num166 = (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
									bool flag11 = num166 >= 5000;
									bool flag12 = false;
									if (!flag11)
									{
										int num167 = num166 / 18;
										num167 %= 3;
										Player.tileTargetX -= num167;
										if (Main.tile[Player.tileTargetX, Player.tileTargetY].frameX >= 5000)
										{
											flag11 = true;
										}
									}
									if (flag11)
									{
										num166 = (int)Main.tile[Player.tileTargetX, Player.tileTargetY].frameX;
										int num168 = 0;
										while (num166 >= 5000)
										{
											num166 -= 5000;
											num168++;
										}
										if (num168 != 0)
										{
											flag12 = true;
										}
									}
									if (flag12)
									{
										num165 = 0;
										Main.blockMouse = true;
									}
								}
								if (this.hitTile.AddDamage(tileId, num165, true) >= 100)
								{
									this.hitTile.Clear(tileId);
									if (Main.netMode == 1 && Main.tile[Player.tileTargetX, Player.tileTargetY].type == 21)
									{
										WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, true, false, false);
										NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
										NetMessage.SendData(34, -1, -1, "", 1, (float)Player.tileTargetX, (float)Player.tileTargetY, 0f, 0);
									}
									else
									{
										int num169 = Player.tileTargetY;
										WorldGen.KillTile(Player.tileTargetX, num169, false, false, false);
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)num169, 0f, 0);
										}
									}
								}
								else
								{
									WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, true, false, false);
									if (Main.netMode == 1)
									{
										NetMessage.SendData(17, -1, -1, "", 0, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
									}
								}
								if (num165 != 0)
								{
									this.hitTile.Prune();
								}
								this.itemTime = (int)((float)this.inventory[this.selectedItem].useTime * this.pickSpeed);
							}
							if (this.inventory[this.selectedItem].hammer > 0 && Main.tile[Player.tileTargetX, Player.tileTargetY].active() && ((Main.tileSolid[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type] && Main.tile[Player.tileTargetX, Player.tileTargetY].type != 10) || Main.tile[Player.tileTargetX, Player.tileTargetY].type == 314) && this.poundRelease)
							{
								flag10 = false;
								this.itemTime = this.inventory[this.selectedItem].useTime;
								num165 += (int)((double)this.inventory[this.selectedItem].hammer * 1.25);
								num165 = 100;
								if (Main.tile[Player.tileTargetX, Player.tileTargetY - 1].active() && Main.tile[Player.tileTargetX, Player.tileTargetY - 1].type == 10)
								{
									num165 = 0;
								}
								if (Main.tile[Player.tileTargetX, Player.tileTargetY + 1].active() && Main.tile[Player.tileTargetX, Player.tileTargetY + 1].type == 10)
								{
									num165 = 0;
								}
								if (this.hitTile.AddDamage(tileId, num165, true) >= 100)
								{
									this.hitTile.Clear(tileId);
									if (this.poundRelease)
									{
										int num170 = Player.tileTargetX;
										int num171 = Player.tileTargetY;
										if (Main.tile[num170, num171].type == 19)
										{
											if (Main.tile[num170, num171].halfBrick())
											{
												WorldGen.PoundTile(num170, num171);
												if (Main.netMode == 1)
												{
													NetMessage.SendData(17, -1, -1, "", 7, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
												}
											}
											else
											{
												int num172 = 1;
												int slope = 2;
												if (Main.tile[num170 + 1, num171 - 1].type == 19 || Main.tile[num170 - 1, num171 + 1].type == 19 || (WorldGen.SolidTile(num170 + 1, num171) && !WorldGen.SolidTile(num170 - 1, num171)))
												{
													num172 = 2;
													slope = 1;
												}
												if (Main.tile[num170, num171].slope() == 0)
												{
													WorldGen.SlopeTile(num170, num171, num172);
													int num173 = (int)Main.tile[num170, num171].slope();
													if (Main.netMode == 1)
													{
														NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num173, 0);
													}
												}
												else if ((int)Main.tile[num170, num171].slope() == num172)
												{
													WorldGen.SlopeTile(num170, num171, slope);
													int num174 = (int)Main.tile[num170, num171].slope();
													if (Main.netMode == 1)
													{
														NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num174, 0);
													}
												}
												else
												{
													WorldGen.SlopeTile(num170, num171, 0);
													int num175 = (int)Main.tile[num170, num171].slope();
													if (Main.netMode == 1)
													{
														NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num175, 0);
													}
													WorldGen.PoundTile(num170, num171);
													if (Main.netMode == 1)
													{
														NetMessage.SendData(17, -1, -1, "", 7, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
													}
												}
											}
										}
										else if (Main.tile[num170, num171].type == 314)
										{
											if (Minecart.FrameTrack(num170, num171, true, false) && Main.netMode == 1)
											{
												NetMessage.SendData(17, -1, -1, "", 15, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
											}
										}
										else if ((Main.tile[num170, num171].halfBrick() || Main.tile[num170, num171].slope() != 0) && !Main.tileSolidTop[(int)Main.tile[Player.tileTargetX, Player.tileTargetY].type])
										{
											int num176 = 1;
											int num177 = 1;
											int num178 = 2;
											if ((WorldGen.SolidTile(num170 + 1, num171) || Main.tile[num170 + 1, num171].slope() == 1 || Main.tile[num170 + 1, num171].slope() == 3) && !WorldGen.SolidTile(num170 - 1, num171))
											{
												num177 = 2;
												num178 = 1;
											}
											if (WorldGen.SolidTile(num170, num171 - 1) && !WorldGen.SolidTile(num170, num171 + 1))
											{
												num176 = -1;
											}
											if (num176 == 1)
											{
												if (Main.tile[num170, num171].slope() == 0)
												{
													WorldGen.SlopeTile(num170, num171, num177);
												}
												else if ((int)Main.tile[num170, num171].slope() == num177)
												{
													WorldGen.SlopeTile(num170, num171, num178);
												}
												else if ((int)Main.tile[num170, num171].slope() == num178)
												{
													WorldGen.SlopeTile(num170, num171, num177 + 2);
												}
												else if ((int)Main.tile[num170, num171].slope() == num177 + 2)
												{
													WorldGen.SlopeTile(num170, num171, num178 + 2);
												}
												else
												{
													WorldGen.SlopeTile(num170, num171, 0);
												}
											}
											else if (Main.tile[num170, num171].slope() == 0)
											{
												WorldGen.SlopeTile(num170, num171, num177 + 2);
											}
											else if ((int)Main.tile[num170, num171].slope() == num177 + 2)
											{
												WorldGen.SlopeTile(num170, num171, num178 + 2);
											}
											else if ((int)Main.tile[num170, num171].slope() == num178 + 2)
											{
												WorldGen.SlopeTile(num170, num171, num177);
											}
											else if ((int)Main.tile[num170, num171].slope() == num177)
											{
												WorldGen.SlopeTile(num170, num171, num178);
											}
											else
											{
												WorldGen.SlopeTile(num170, num171, 0);
											}
											int num179 = (int)Main.tile[num170, num171].slope();
											if (Main.netMode == 1)
											{
												NetMessage.SendData(17, -1, -1, "", 14, (float)Player.tileTargetX, (float)Player.tileTargetY, (float)num179, 0);
											}
										}
										else
										{
											WorldGen.PoundTile(num170, num171);
											if (Main.netMode == 1)
											{
												NetMessage.SendData(17, -1, -1, "", 7, (float)Player.tileTargetX, (float)Player.tileTargetY, 1f, 0);
											}
										}
										this.poundRelease = false;
									}
								}
								else
								{
									WorldGen.KillTile(Player.tileTargetX, Player.tileTargetY, true, true, false);
									Main.PlaySound(0, Player.tileTargetX * 16, Player.tileTargetY * 16, 1);
								}
							}
							else
							{
								this.poundRelease = false;
							}
						}
					}
					if (this.releaseUseItem)
					{
						this.poundRelease = true;
					}
					int num180 = Player.tileTargetX;
					int num181 = Player.tileTargetY;
					bool flag13 = true;
					if (Main.tile[num180, num181].wall > 0)
					{
						if (!Main.wallHouse[(int)Main.tile[num180, num181].wall])
						{
							for (int num182 = num180 - 1; num182 < num180 + 2; num182++)
							{
								for (int num183 = num181 - 1; num183 < num181 + 2; num183++)
								{
									if (Main.tile[num182, num183].wall != Main.tile[num180, num181].wall)
									{
										flag13 = false;
										break;
									}
								}
							}
						}
						else
						{
							flag13 = false;
						}
					}
					if (flag13 && !Main.tile[num180, num181].active())
					{
						int num184 = -1;
						if ((double)(((float)Main.mouseX + Main.screenPosition.X) / 16f) < Math.Round((double)(((float)Main.mouseX + Main.screenPosition.X) / 16f)))
						{
							num184 = 0;
						}
						int num185 = -1;
						if ((double)(((float)Main.mouseY + Main.screenPosition.Y) / 16f) < Math.Round((double)(((float)Main.mouseY + Main.screenPosition.Y) / 16f)))
						{
							num185 = 0;
						}
						for (int num186 = Player.tileTargetX + num184; num186 <= Player.tileTargetX + num184 + 1; num186++)
						{
							for (int num187 = Player.tileTargetY + num185; num187 <= Player.tileTargetY + num185 + 1; num187++)
							{
								if (flag13)
								{
									num180 = num186;
									num181 = num187;
									if (Main.tile[num180, num181].wall > 0)
									{
										if (!Main.wallHouse[(int)Main.tile[num180, num181].wall])
										{
											for (int num188 = num180 - 1; num188 < num180 + 2; num188++)
											{
												for (int num189 = num181 - 1; num189 < num181 + 2; num189++)
												{
													if (Main.tile[num188, num189].wall != Main.tile[num180, num181].wall)
													{
														flag13 = false;
														break;
													}
												}
											}
										}
										else
										{
											flag13 = false;
										}
									}
								}
							}
						}
					}
					if (flag10 && Main.tile[num180, num181].wall > 0 && (!Main.tile[num180, num181].active() || num180 != Player.tileTargetX || num181 != Player.tileTargetY || (!Main.tileHammer[(int)Main.tile[num180, num181].type] && !this.poundRelease)) && this.toolTime == 0 && this.itemAnimation > 0 && this.controlUseItem && this.inventory[this.selectedItem].hammer > 0)
					{
						bool flag14 = true;
						if (!Main.wallHouse[(int)Main.tile[num180, num181].wall])
						{
							flag14 = false;
							for (int num190 = num180 - 1; num190 < num180 + 2; num190++)
							{
								for (int num191 = num181 - 1; num191 < num181 + 2; num191++)
								{
									if (Main.tile[num190, num191].wall == 0 || Main.wallHouse[(int)Main.tile[num190, num191].wall])
									{
										flag14 = true;
										break;
									}
								}
							}
						}
						if (flag14)
						{
							int tileId = this.hitTile.HitObject(num180, num181, 2);
							num165 += (int)((float)this.inventory[this.selectedItem].hammer * 1.5f);
							if (this.hitTile.AddDamage(tileId, num165, true) >= 100)
							{
								this.hitTile.Clear(tileId);
								WorldGen.KillWall(num180, num181, false);
								if (Main.netMode == 1)
								{
									NetMessage.SendData(17, -1, -1, "", 2, (float)num180, (float)num181, 0f, 0);
								}
							}
							else
							{
								WorldGen.KillWall(num180, num181, true);
								if (Main.netMode == 1)
								{
									NetMessage.SendData(17, -1, -1, "", 2, (float)num180, (float)num181, 1f, 0);
								}
							}
							if (num165 != 0)
							{
								this.hitTile.Prune();
							}
							this.itemTime = this.inventory[this.selectedItem].useTime / 2;
						}
					}
				}
				if (Main.myPlayer == this.whoAmi && this.inventory[this.selectedItem].type == 1326 && this.itemAnimation > 0 && this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Vector2 newPos;
					newPos.X = (float)Main.mouseX + Main.screenPosition.X;
					if (this.gravDir == 1f)
					{
						newPos.Y = (float)Main.mouseY + Main.screenPosition.Y - (float)this.height;
					}
					else
					{
						newPos.Y = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY;
					}
					newPos.X -= (float)(this.width / 2);
					if (newPos.X > 50f && newPos.X < (float)(Main.maxTilesX * 16 - 50) && newPos.Y > 50f && newPos.Y < (float)(Main.maxTilesY * 16 - 50))
					{
						int num192 = (int)(newPos.X / 16f);
						int num193 = (int)(newPos.Y / 16f);
						if ((Main.tile[num192, num193].wall != 87 || (double)num193 <= Main.worldSurface || NPC.downedPlantBoss) && !Collision.SolidCollision(newPos, this.width, this.height))
						{
							this.Teleport(newPos, 1);
							NetMessage.SendData(65, -1, -1, "", 0, (float)this.whoAmi, newPos.X, newPos.Y, 1);
							if (this.chaosState)
							{
								this.statLife -= this.statLifeMax2 / 6;
								if (Lang.lang <= 1)
								{
									string deathText = " didn't materialize";
									if (Main.rand.Next(2) == 0)
									{
										if (this.male)
										{
											deathText = "'s legs appeared where his head should be";
										}
										else
										{
											deathText = "'s legs appeared where her head should be";
										}
									}
									if (this.statLife <= 0)
									{
										this.KillMe(1.0, 0, false, deathText);
									}
								}
								else if (this.statLife <= 0)
								{
									this.KillMe(1.0, 0, false, "");
								}
								this.lifeRegenCount = 0;
								this.lifeRegenTime = 0;
							}
							this.AddBuff(88, 480, true);
						}
					}
				}
				if (this.inventory[this.selectedItem].type == 29 && this.itemAnimation > 0 && this.statLifeMax < 400 && this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					this.statLifeMax += 20;
					this.statLifeMax2 += 20;
					this.statLife += 20;
					if (Main.myPlayer == this.whoAmi)
					{
						this.HealEffect(20, true);
					}
				}
				if (this.inventory[this.selectedItem].type == 1291 && this.itemAnimation > 0 && this.statLifeMax >= 400 && this.statLifeMax < 500 && this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					this.statLifeMax += 5;
					this.statLifeMax2 += 5;
					this.statLife += 5;
					if (Main.myPlayer == this.whoAmi)
					{
						this.HealEffect(5, true);
					}
				}
				if (this.inventory[this.selectedItem].type == 109 && this.itemAnimation > 0 && this.statManaMax < 200 && this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					this.statManaMax += 20;
					this.statManaMax2 += 20;
					this.statMana += 20;
					if (Main.myPlayer == this.whoAmi)
					{
						this.ManaEffect(20);
					}
				}
				this.PlaceThing();
			}
			if (((this.inventory[this.selectedItem].damage >= 0 && this.inventory[this.selectedItem].type > 0 && !this.inventory[this.selectedItem].noMelee) || this.inventory[this.selectedItem].type == 1450 || this.inventory[this.selectedItem].type == 1991) && this.itemAnimation > 0)
			{
				bool flag15 = false;
				Rectangle rectangle = new Rectangle((int)this.itemLocation.X, (int)this.itemLocation.Y, 32, 32);
				if (!Main.dedServ)
				{
					rectangle = new Rectangle((int)this.itemLocation.X, (int)this.itemLocation.Y, Main.itemTexture[this.inventory[this.selectedItem].type].Width, Main.itemTexture[this.inventory[this.selectedItem].type].Height);
				}
				rectangle.Width = (int)((float)rectangle.Width * this.inventory[this.selectedItem].scale);
				rectangle.Height = (int)((float)rectangle.Height * this.inventory[this.selectedItem].scale);
				if (this.direction == -1)
				{
					rectangle.X -= rectangle.Width;
				}
				if (this.gravDir == 1f)
				{
					rectangle.Y -= rectangle.Height;
				}
				if (this.inventory[this.selectedItem].useStyle == 1)
				{
					if ((double)this.itemAnimation < (double)this.itemAnimationMax * 0.333)
					{
						if (this.direction == -1)
						{
							rectangle.X -= (int)((double)rectangle.Width * 1.4 - (double)rectangle.Width);
						}
						rectangle.Width = (int)((double)rectangle.Width * 1.4);
						rectangle.Y += (int)((double)rectangle.Height * 0.5 * (double)this.gravDir);
						rectangle.Height = (int)((double)rectangle.Height * 1.1);
					}
					else if ((double)this.itemAnimation >= (double)this.itemAnimationMax * 0.666)
					{
						if (this.direction == 1)
						{
							rectangle.X -= (int)((double)rectangle.Width * 1.2);
						}
						rectangle.Width *= 2;
						rectangle.Y -= (int)(((double)rectangle.Height * 1.4 - (double)rectangle.Height) * (double)this.gravDir);
						rectangle.Height = (int)((double)rectangle.Height * 1.4);
					}
				}
				else if (this.inventory[this.selectedItem].useStyle == 3)
				{
					if ((double)this.itemAnimation > (double)this.itemAnimationMax * 0.666)
					{
						flag15 = true;
					}
					else
					{
						if (this.direction == -1)
						{
							rectangle.X -= (int)((double)rectangle.Width * 1.4 - (double)rectangle.Width);
						}
						rectangle.Width = (int)((double)rectangle.Width * 1.4);
						rectangle.Y += (int)((double)rectangle.Height * 0.6);
						rectangle.Height = (int)((double)rectangle.Height * 0.6);
					}
				}
				float arg_B0B8_0 = this.gravDir;
				if (this.inventory[this.selectedItem].type == 1450 && Main.rand.Next(3) == 0)
				{
					int num194 = -1;
					float x5 = (float)(rectangle.X + Main.rand.Next(rectangle.Width));
					float y5 = (float)(rectangle.Y + Main.rand.Next(rectangle.Height));
					if (Main.rand.Next(500) == 0)
					{
						num194 = Gore.NewGore(new Vector2(x5, y5), default(Vector2), 415, (float)Main.rand.Next(51, 101) * 0.01f);
					}
					else if (Main.rand.Next(250) == 0)
					{
						num194 = Gore.NewGore(new Vector2(x5, y5), default(Vector2), 414, (float)Main.rand.Next(51, 101) * 0.01f);
					}
					else if (Main.rand.Next(80) == 0)
					{
						num194 = Gore.NewGore(new Vector2(x5, y5), default(Vector2), 413, (float)Main.rand.Next(51, 101) * 0.01f);
					}
					else if (Main.rand.Next(10) == 0)
					{
						num194 = Gore.NewGore(new Vector2(x5, y5), default(Vector2), 412, (float)Main.rand.Next(51, 101) * 0.01f);
					}
					else if (Main.rand.Next(3) == 0)
					{
						num194 = Gore.NewGore(new Vector2(x5, y5), default(Vector2), 411, (float)Main.rand.Next(51, 101) * 0.01f);
					}
					if (num194 >= 0)
					{
						Gore expr_B2B2_cp_0 = Main.gore[num194];
						expr_B2B2_cp_0.velocity.X = expr_B2B2_cp_0.velocity.X + (float)(this.direction * 2);
						Gore expr_B2D4_cp_0 = Main.gore[num194];
						expr_B2D4_cp_0.velocity.Y = expr_B2D4_cp_0.velocity.Y * 0.3f;
					}
				}
				if (!flag15)
				{
					if (this.inventory[this.selectedItem].type == 989 && Main.rand.Next(5) == 0)
					{
						int num195 = Main.rand.Next(3);
						if (num195 == 0)
						{
							num195 = 15;
						}
						else if (num195 == 1)
						{
							num195 = 57;
						}
						else
						{
							num195 = 58;
						}
						int num196 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, num195, (float)(this.direction * 2), 0f, 150, default(Color), 1.3f);
						Main.dust[num196].velocity *= 0.2f;
					}
					if ((this.inventory[this.selectedItem].type == 44 || this.inventory[this.selectedItem].type == 45 || this.inventory[this.selectedItem].type == 46 || this.inventory[this.selectedItem].type == 103 || this.inventory[this.selectedItem].type == 104) && Main.rand.Next(15) == 0)
					{
						Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 14, (float)(this.direction * 2), 0f, 150, default(Color), 1.3f);
					}
					if (this.inventory[this.selectedItem].type == 273 || this.inventory[this.selectedItem].type == 675)
					{
						if (Main.rand.Next(5) == 0)
						{
							Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 14, (float)(this.direction * 2), 0f, 150, default(Color), 1.4f);
						}
						int num197 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 27, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 1.2f);
						Main.dust[num197].noGravity = true;
						Dust expr_B5AD_cp_0 = Main.dust[num197];
						expr_B5AD_cp_0.velocity.X = expr_B5AD_cp_0.velocity.X / 2f;
						Dust expr_B5CD_cp_0 = Main.dust[num197];
						expr_B5CD_cp_0.velocity.Y = expr_B5CD_cp_0.velocity.Y / 2f;
					}
					if (this.inventory[this.selectedItem].type == 723 && Main.rand.Next(2) == 0)
					{
						int num198 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 64, 0f, 0f, 150, default(Color), 1.2f);
						Main.dust[num198].noGravity = true;
					}
					if (this.inventory[this.selectedItem].type == 65)
					{
						if (Main.rand.Next(5) == 0)
						{
							Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 58, 0f, 0f, 150, default(Color), 1.2f);
						}
						if (Main.rand.Next(10) == 0)
						{
							Gore.NewGore(new Vector2((float)rectangle.X, (float)rectangle.Y), default(Vector2), Main.rand.Next(16, 18), 1f);
						}
					}
					if (this.inventory[this.selectedItem].type == 190 || this.inventory[this.selectedItem].type == 213)
					{
						int num199 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 40, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 0, default(Color), 1.2f);
						Main.dust[num199].noGravity = true;
					}
					if (this.inventory[this.selectedItem].type == 121)
					{
						for (int num200 = 0; num200 < 2; num200++)
						{
							int num201 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 6, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 2.5f);
							Main.dust[num201].noGravity = true;
							Dust expr_B881_cp_0 = Main.dust[num201];
							expr_B881_cp_0.velocity.X = expr_B881_cp_0.velocity.X * 2f;
							Dust expr_B8A1_cp_0 = Main.dust[num201];
							expr_B8A1_cp_0.velocity.Y = expr_B8A1_cp_0.velocity.Y * 2f;
						}
					}
					if (this.inventory[this.selectedItem].type == 122 || this.inventory[this.selectedItem].type == 217)
					{
						int num202 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 6, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 1.9f);
						Main.dust[num202].noGravity = true;
					}
					if (this.inventory[this.selectedItem].type == 155)
					{
						int num203 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 172, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 0.9f);
						Main.dust[num203].noGravity = true;
						Main.dust[num203].velocity *= 0.1f;
					}
					if (this.inventory[this.selectedItem].type == 676 && Main.rand.Next(3) == 0)
					{
						int num204 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 67, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 90, default(Color), 1.5f);
						Main.dust[num204].noGravity = true;
						Main.dust[num204].velocity *= 0.2f;
					}
					if (this.inventory[this.selectedItem].type == 724 && Main.rand.Next(5) == 0)
					{
						int num205 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 67, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 90, default(Color), 1.5f);
						Main.dust[num205].noGravity = true;
						Main.dust[num205].velocity *= 0.2f;
					}
					if (this.inventory[this.selectedItem].type >= 795 && this.inventory[this.selectedItem].type <= 802 && Main.rand.Next(3) == 0)
					{
						int num206 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 115, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 140, default(Color), 1.5f);
						Main.dust[num206].noGravity = true;
						Main.dust[num206].velocity *= 0.25f;
					}
					if (this.inventory[this.selectedItem].type == 367 || this.inventory[this.selectedItem].type == 368 || this.inventory[this.selectedItem].type == 674)
					{
						if (Main.rand.Next(3) == 0)
						{
							int num207 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 57, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 1.1f);
							Main.dust[num207].noGravity = true;
							Dust expr_BD9E_cp_0 = Main.dust[num207];
							expr_BD9E_cp_0.velocity.X = expr_BD9E_cp_0.velocity.X / 2f;
							Dust expr_BDBE_cp_0 = Main.dust[num207];
							expr_BDBE_cp_0.velocity.Y = expr_BDBE_cp_0.velocity.Y / 2f;
							Dust expr_BDDE_cp_0 = Main.dust[num207];
							expr_BDDE_cp_0.velocity.X = expr_BDDE_cp_0.velocity.X + (float)(this.direction * 2);
						}
						if (Main.rand.Next(4) == 0)
						{
							int num207 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 43, 0f, 0f, 254, default(Color), 0.3f);
							Main.dust[num207].velocity *= 0f;
						}
					}
					if (this.inventory[this.selectedItem].type >= 198 && this.inventory[this.selectedItem].type <= 203)
					{
						float num208 = 0.5f;
						float num209 = 0.5f;
						float num210 = 0.5f;
						if (this.inventory[this.selectedItem].type == 198)
						{
							num208 *= 0.1f;
							num209 *= 0.5f;
							num210 *= 1.2f;
						}
						else if (this.inventory[this.selectedItem].type == 199)
						{
							num208 *= 1f;
							num209 *= 0.2f;
							num210 *= 0.1f;
						}
						else if (this.inventory[this.selectedItem].type == 200)
						{
							num208 *= 0.1f;
							num209 *= 1f;
							num210 *= 0.2f;
						}
						else if (this.inventory[this.selectedItem].type == 201)
						{
							num208 *= 0.8f;
							num209 *= 0.1f;
							num210 *= 1f;
						}
						else if (this.inventory[this.selectedItem].type == 202)
						{
							num208 *= 0.8f;
							num209 *= 0.9f;
							num210 *= 1f;
						}
						else if (this.inventory[this.selectedItem].type == 203)
						{
							num208 *= 0.9f;
							num209 *= 0.9f;
							num210 *= 0.1f;
						}
						Lighting.addLight((int)((this.itemLocation.X + 6f + this.velocity.X) / 16f), (int)((this.itemLocation.Y - 14f) / 16f), num208, num209, num210);
					}
					if (this.frostBurn && this.inventory[this.selectedItem].melee && !this.inventory[this.selectedItem].noMelee && !this.inventory[this.selectedItem].noUseGraphic && Main.rand.Next(2) == 0)
					{
						int num211 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 135, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 2.5f);
						Main.dust[num211].noGravity = true;
						Main.dust[num211].velocity *= 0.7f;
						Dust expr_C1C7_cp_0 = Main.dust[num211];
						expr_C1C7_cp_0.velocity.Y = expr_C1C7_cp_0.velocity.Y - 0.5f;
					}
					if (this.inventory[this.selectedItem].melee && !this.inventory[this.selectedItem].noMelee && !this.inventory[this.selectedItem].noUseGraphic && this.meleeEnchant > 0)
					{
						if (this.meleeEnchant == 1)
						{
							if (Main.rand.Next(3) == 0)
							{
								int num212 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 171, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num212].noGravity = true;
								Main.dust[num212].fadeIn = 1.5f;
								Main.dust[num212].velocity *= 0.25f;
							}
						}
						else if (this.meleeEnchant == 2)
						{
							if (Main.rand.Next(2) == 0)
							{
								int num213 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 75, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 2.5f);
								Main.dust[num213].noGravity = true;
								Main.dust[num213].velocity *= 0.7f;
								Dust expr_C3A6_cp_0 = Main.dust[num213];
								expr_C3A6_cp_0.velocity.Y = expr_C3A6_cp_0.velocity.Y - 0.5f;
							}
						}
						else if (this.meleeEnchant == 3)
						{
							if (Main.rand.Next(2) == 0)
							{
								int num214 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 6, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 2.5f);
								Main.dust[num214].noGravity = true;
								Main.dust[num214].velocity *= 0.7f;
								Dust expr_C484_cp_0 = Main.dust[num214];
								expr_C484_cp_0.velocity.Y = expr_C484_cp_0.velocity.Y - 0.5f;
							}
						}
						else if (this.meleeEnchant == 4)
						{
							if (Main.rand.Next(2) == 0)
							{
								int num215 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 57, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 1.1f);
								Main.dust[num215].noGravity = true;
								Dust expr_C549_cp_0 = Main.dust[num215];
								expr_C549_cp_0.velocity.X = expr_C549_cp_0.velocity.X / 2f;
								Dust expr_C569_cp_0 = Main.dust[num215];
								expr_C569_cp_0.velocity.Y = expr_C569_cp_0.velocity.Y / 2f;
							}
						}
						else if (this.meleeEnchant == 5)
						{
							if (Main.rand.Next(2) == 0)
							{
								int num216 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 169, 0f, 0f, 100, default(Color), 1f);
								Dust expr_C5FA_cp_0 = Main.dust[num216];
								expr_C5FA_cp_0.velocity.X = expr_C5FA_cp_0.velocity.X + (float)this.direction;
								Dust expr_C61C_cp_0 = Main.dust[num216];
								expr_C61C_cp_0.velocity.Y = expr_C61C_cp_0.velocity.Y + 0.2f;
								Main.dust[num216].noGravity = true;
							}
						}
						else if (this.meleeEnchant == 6)
						{
							if (Main.rand.Next(2) == 0)
							{
								int num217 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 135, 0f, 0f, 100, default(Color), 1f);
								Dust expr_C6BD_cp_0 = Main.dust[num217];
								expr_C6BD_cp_0.velocity.X = expr_C6BD_cp_0.velocity.X + (float)this.direction;
								Dust expr_C6DF_cp_0 = Main.dust[num217];
								expr_C6DF_cp_0.velocity.Y = expr_C6DF_cp_0.velocity.Y + 0.2f;
								Main.dust[num217].noGravity = true;
							}
						}
						else if (this.meleeEnchant == 7)
						{
							if (Main.rand.Next(20) == 0)
							{
								int type4 = Main.rand.Next(139, 143);
								int num218 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, type4, this.velocity.X, this.velocity.Y, 0, default(Color), 1.2f);
								Dust expr_C7A3_cp_0 = Main.dust[num218];
								expr_C7A3_cp_0.velocity.X = expr_C7A3_cp_0.velocity.X * (1f + (float)Main.rand.Next(-50, 51) * 0.01f);
								Dust expr_C7D9_cp_0 = Main.dust[num218];
								expr_C7D9_cp_0.velocity.Y = expr_C7D9_cp_0.velocity.Y * (1f + (float)Main.rand.Next(-50, 51) * 0.01f);
								Dust expr_C80F_cp_0 = Main.dust[num218];
								expr_C80F_cp_0.velocity.X = expr_C80F_cp_0.velocity.X + (float)Main.rand.Next(-50, 51) * 0.05f;
								Dust expr_C83F_cp_0 = Main.dust[num218];
								expr_C83F_cp_0.velocity.Y = expr_C83F_cp_0.velocity.Y + (float)Main.rand.Next(-50, 51) * 0.05f;
								Main.dust[num218].scale *= 1f + (float)Main.rand.Next(-30, 31) * 0.01f;
							}
							if (Main.rand.Next(40) == 0)
							{
								int type5 = Main.rand.Next(276, 283);
								int num219 = Gore.NewGore(new Vector2((float)rectangle.X, (float)rectangle.Y), this.velocity, type5, 1f);
								Gore expr_C8F6_cp_0 = Main.gore[num219];
								expr_C8F6_cp_0.velocity.X = expr_C8F6_cp_0.velocity.X * (1f + (float)Main.rand.Next(-50, 51) * 0.01f);
								Gore expr_C92C_cp_0 = Main.gore[num219];
								expr_C92C_cp_0.velocity.Y = expr_C92C_cp_0.velocity.Y * (1f + (float)Main.rand.Next(-50, 51) * 0.01f);
								Main.gore[num219].scale *= 1f + (float)Main.rand.Next(-20, 21) * 0.01f;
								Gore expr_C993_cp_0 = Main.gore[num219];
								expr_C993_cp_0.velocity.X = expr_C993_cp_0.velocity.X + (float)Main.rand.Next(-50, 51) * 0.05f;
								Gore expr_C9C3_cp_0 = Main.gore[num219];
								expr_C9C3_cp_0.velocity.Y = expr_C9C3_cp_0.velocity.Y + (float)Main.rand.Next(-50, 51) * 0.05f;
							}
						}
						else if (this.meleeEnchant == 8 && Main.rand.Next(4) == 0)
						{
							int num220 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 46, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num220].noGravity = true;
							Main.dust[num220].fadeIn = 1.5f;
							Main.dust[num220].velocity *= 0.25f;
						}
					}
					if (this.magmaStone && this.inventory[this.selectedItem].melee && !this.inventory[this.selectedItem].noMelee && !this.inventory[this.selectedItem].noUseGraphic && Main.rand.Next(3) != 0)
					{
						int num221 = Dust.NewDust(new Vector2((float)rectangle.X, (float)rectangle.Y), rectangle.Width, rectangle.Height, 6, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 2.5f);
						Main.dust[num221].noGravity = true;
						Dust expr_CB82_cp_0 = Main.dust[num221];
						expr_CB82_cp_0.velocity.X = expr_CB82_cp_0.velocity.X * 2f;
						Dust expr_CBA2_cp_0 = Main.dust[num221];
						expr_CBA2_cp_0.velocity.Y = expr_CBA2_cp_0.velocity.Y * 2f;
					}
					if (Main.myPlayer == i && this.inventory[this.selectedItem].type == 1991)
					{
						for (int num222 = 0; num222 < 200; num222++)
						{
							if (Main.npc[num222].active && Main.npc[num222].catchItem > 0)
							{
								Rectangle value = new Rectangle((int)Main.npc[num222].position.X, (int)Main.npc[num222].position.Y, Main.npc[num222].width, Main.npc[num222].height);
								if (rectangle.Intersects(value) && (Main.npc[num222].noTileCollide || Collision.CanHit(this.position, this.width, this.height, Main.npc[num222].position, Main.npc[num222].width, Main.npc[num222].height)))
								{
									NPC.CatchNPC(num222, i);
								}
							}
						}
					}
					else if (Main.myPlayer == i && this.inventory[this.selectedItem].damage > 0)
					{
						int num223 = (int)((float)this.inventory[this.selectedItem].damage * this.meleeDamage);
						float num224 = this.inventory[this.selectedItem].knockBack;
						float num225 = 1f;
						if (this.kbGlove)
						{
							num225 += 1f;
						}
						if (this.kbBuff)
						{
							num225 += 0.5f;
						}
						num224 *= num225;
						int num226 = rectangle.X / 16;
						int num227 = (rectangle.X + rectangle.Width) / 16 + 1;
						int num228 = rectangle.Y / 16;
						int num229 = (rectangle.Y + rectangle.Height) / 16 + 1;
						for (int num230 = num226; num230 < num227; num230++)
						{
							for (int num231 = num228; num231 < num229; num231++)
							{
								if (Main.tile[num230, num231] != null && Main.tileCut[(int)Main.tile[num230, num231].type] && Main.tile[num230, num231 + 1] != null && Main.tile[num230, num231 + 1].type != 78)
								{
									if (this.inventory[this.selectedItem].type == 1786)
									{
										int type6 = (int)Main.tile[num230, num231].type;
										WorldGen.KillTile(num230, num231, false, false, false);
										if (!Main.tile[num230, num231].active())
										{
											int num232 = 0;
											if (type6 == 3 || type6 == 24 || type6 == 61 || type6 == 110 || type6 == 201)
											{
												num232 = Main.rand.Next(1, 3);
											}
											if (type6 == 73 || type6 == 74 || type6 == 113)
											{
												num232 = Main.rand.Next(2, 5);
											}
											if (num232 > 0)
											{
												int number = Item.NewItem(num230 * 16, num231 * 16, 16, 16, 1727, num232, false, 0, false);
												if (Main.netMode == 1)
												{
													NetMessage.SendData(21, -1, -1, "", number, 1f, 0f, 0f, 0);
												}
											}
										}
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)num230, (float)num231, 0f, 0);
										}
									}
									else
									{
										WorldGen.KillTile(num230, num231, false, false, false);
										if (Main.netMode == 1)
										{
											NetMessage.SendData(17, -1, -1, "", 0, (float)num230, (float)num231, 0f, 0);
										}
									}
								}
							}
						}
						for (int num233 = 0; num233 < 200; num233++)
						{
							if (Main.npc[num233].active && Main.npc[num233].immune[i] == 0 && this.attackCD == 0 && !Main.npc[num233].dontTakeDamage && (!Main.npc[num233].friendly || (Main.npc[num233].type == 22 && this.killGuide) || (Main.npc[num233].type == 54 && this.killClothier)))
							{
								Rectangle value2 = new Rectangle((int)Main.npc[num233].position.X, (int)Main.npc[num233].position.Y, Main.npc[num233].width, Main.npc[num233].height);
								if (rectangle.Intersects(value2) && (Main.npc[num233].noTileCollide || Collision.CanHit(this.position, this.width, this.height, Main.npc[num233].position, Main.npc[num233].width, Main.npc[num233].height)))
								{
									bool flag16 = false;
									if (Main.rand.Next(1, 101) <= this.meleeCrit)
									{
										flag16 = true;
									}
									int num234 = Main.DamageVar((float)num223);
									this.StatusNPC(this.inventory[this.selectedItem].type, num233);
									this.onHit(Main.npc[num233].center().X, Main.npc[num233].center().Y);
									int num235 = (int)Main.npc[num233].StrikeNPC(num234, num224, this.direction, flag16, false);
									if (this.beetleOffense)
									{
										this.beetleCounter += (float)num235;
										this.beetleCountdown = 0;
									}
									if (this.inventory[this.selectedItem].type == 1826)
									{
										this.pumpkinSword(num233, (int)((double)num223 * 1.5), num224);
									}
									if (this.meleeEnchant == 7)
									{
										Projectile.NewProjectile(Main.npc[num233].center().X, Main.npc[num233].center().Y, Main.npc[num233].velocity.X, Main.npc[num233].velocity.Y, 289, 0, 0f, this.whoAmi, 0f, 0f);
									}
									if (this.inventory[this.selectedItem].type == 1123)
									{
										int num236 = Main.rand.Next(1, 4);
										for (int num237 = 0; num237 < num236; num237++)
										{
											float num238 = (float)(this.direction * 2) + (float)Main.rand.Next(-35, 36) * 0.02f;
											float num239 = (float)Main.rand.Next(-35, 36) * 0.02f;
											num238 *= 0.2f;
											num239 *= 0.2f;
											Projectile.NewProjectile((float)(rectangle.X + rectangle.Width / 2), (float)(rectangle.Y + rectangle.Height / 2), num238, num239, 181, num234 / 3, 0f, i, 0f, 0f);
										}
									}
									if (Main.npc[num233].value > 0f && this.coins && Main.rand.Next(5) == 0)
									{
										int type7 = 71;
										if (Main.rand.Next(10) == 0)
										{
											type7 = 72;
										}
										if (Main.rand.Next(100) == 0)
										{
											type7 = 73;
										}
										int num240 = Item.NewItem((int)Main.npc[num233].position.X, (int)Main.npc[num233].position.Y, Main.npc[num233].width, Main.npc[num233].height, type7, 1, false, 0, false);
										Main.item[num240].stack = Main.rand.Next(1, 11);
										Main.item[num240].velocity.Y = (float)Main.rand.Next(-20, 1) * 0.2f;
										Main.item[num240].velocity.X = (float)Main.rand.Next(10, 31) * 0.2f * (float)this.direction;
										if (Main.netMode == 1)
										{
											NetMessage.SendData(21, -1, -1, "", num240, 0f, 0f, 0f, 0);
										}
									}
									if (Main.netMode != 0)
									{
										if (flag16)
										{
											NetMessage.SendData(28, -1, -1, "", num233, (float)num234, num224, (float)this.direction, 1);
										}
										else
										{
											NetMessage.SendData(28, -1, -1, "", num233, (float)num234, num224, (float)this.direction, 0);
										}
									}
									Main.npc[num233].immune[i] = this.itemAnimation;
									this.attackCD = (int)((double)this.itemAnimationMax * 0.33);
								}
							}
						}
						if (this.hostile)
						{
							for (int num241 = 0; num241 < 255; num241++)
							{
								if (num241 != i && Main.player[num241].active && Main.player[num241].hostile && !Main.player[num241].immune && !Main.player[num241].dead && (Main.player[i].team == 0 || Main.player[i].team != Main.player[num241].team))
								{
									Rectangle value3 = new Rectangle((int)Main.player[num241].position.X, (int)Main.player[num241].position.Y, Main.player[num241].width, Main.player[num241].height);
									if (rectangle.Intersects(value3) && Collision.CanHit(this.position, this.width, this.height, Main.player[num241].position, Main.player[num241].width, Main.player[num241].height))
									{
										bool flag17 = false;
										if (Main.rand.Next(1, 101) <= 10)
										{
											flag17 = true;
										}
										int num242 = Main.DamageVar((float)num223);
										this.StatusPvP(this.inventory[this.selectedItem].type, num241);
										this.onHit(Main.player[num241].center().X, Main.player[num241].center().Y);
										Main.player[num241].Hurt(num242, this.direction, true, false, "", flag17);
										if (this.meleeEnchant == 7)
										{
											Projectile.NewProjectile(Main.player[num241].center().X, Main.player[num241].center().Y, Main.player[num241].velocity.X, Main.player[num241].velocity.Y, 289, 0, 0f, this.whoAmi, 0f, 0f);
										}
										if (this.inventory[this.selectedItem].type == 1123)
										{
											int num243 = Main.rand.Next(1, 4);
											for (int num244 = 0; num244 < num243; num244++)
											{
												float num245 = (float)(this.direction * 2) + (float)Main.rand.Next(-35, 36) * 0.02f;
												float num246 = (float)Main.rand.Next(-35, 36) * 0.02f;
												num245 *= 0.2f;
												num246 *= 0.2f;
												Projectile.NewProjectile((float)(rectangle.X + rectangle.Width / 2), (float)(rectangle.Y + rectangle.Height / 2), num245, num246, 181, num242 / 3, 0f, i, 0f, 0f);
											}
										}
										if (Main.netMode != 0)
										{
											if (flag17)
											{
												NetMessage.SendData(26, -1, -1, Lang.deathMsg(this.whoAmi, -1, -1, -1), num241, (float)this.direction, (float)num242, 1f, 1);
											}
											else
											{
												NetMessage.SendData(26, -1, -1, Lang.deathMsg(this.whoAmi, -1, -1, -1), num241, (float)this.direction, (float)num242, 1f, 0);
											}
										}
										this.attackCD = (int)((double)this.itemAnimationMax * 0.33);
									}
								}
							}
						}
						if (this.inventory[this.selectedItem].type == 787 && (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.1) || this.itemAnimation == (int)((double)this.itemAnimationMax * 0.3) || this.itemAnimation == (int)((double)this.itemAnimationMax * 0.5) || this.itemAnimation == (int)((double)this.itemAnimationMax * 0.7) || this.itemAnimation == (int)((double)this.itemAnimationMax * 0.9)))
						{
							float num247 = 0f;
							float num248 = 0f;
							float num249 = 0f;
							float num250 = 0f;
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.9))
							{
								num247 = -7f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.7))
							{
								num247 = -6f;
								num248 = 2f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.5))
							{
								num247 = -4f;
								num248 = 4f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.3))
							{
								num247 = -2f;
								num248 = 6f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.1))
							{
								num248 = 7f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.7))
							{
								num250 = 26f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.3))
							{
								num250 -= 4f;
								num249 -= 20f;
							}
							if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.1))
							{
								num249 += 6f;
							}
							if (this.direction == -1)
							{
								if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.9))
								{
									num250 -= 8f;
								}
								if (this.itemAnimation == (int)((double)this.itemAnimationMax * 0.7))
								{
									num250 -= 6f;
								}
							}
							num247 *= 1.5f;
							num248 *= 1.5f;
							num250 *= (float)this.direction;
							num249 *= this.gravDir;
							Projectile.NewProjectile((float)(rectangle.X + rectangle.Width / 2) + num250, (float)(rectangle.Y + rectangle.Height / 2) + num249, (float)this.direction * num248, num247 * this.gravDir, 131, num223 / 2, 0f, i, 0f, 0f);
						}
					}
				}
			}
			if (this.itemTime == 0 && this.itemAnimation > 0)
			{
				if (this.inventory[this.selectedItem].hairDye >= 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					if (this.whoAmi == Main.myPlayer)
					{
						this.hairDye = (byte)this.inventory[this.selectedItem].hairDye;
						NetMessage.SendData(4, -1, -1, Main.player[this.whoAmi].name, this.whoAmi, 0f, 0f, 0f, 0);
					}
				}
				if (this.inventory[this.selectedItem].healLife > 0)
				{
					this.statLife += this.inventory[this.selectedItem].healLife;
					this.itemTime = this.inventory[this.selectedItem].useTime;
					if (Main.myPlayer == this.whoAmi)
					{
						this.HealEffect(this.inventory[this.selectedItem].healLife, true);
					}
				}
				if (this.inventory[this.selectedItem].healMana > 0)
				{
					this.statMana += this.inventory[this.selectedItem].healMana;
					this.itemTime = this.inventory[this.selectedItem].useTime;
					if (Main.myPlayer == this.whoAmi)
					{
						this.AddBuff(94, Player.manaSickTime, true);
						this.ManaEffect(this.inventory[this.selectedItem].healMana);
					}
				}
				if (this.inventory[this.selectedItem].buffType > 0)
				{
					if (this.whoAmi == Main.myPlayer && this.inventory[this.selectedItem].buffType != 90)
					{
						this.AddBuff(this.inventory[this.selectedItem].buffType, this.inventory[this.selectedItem].buffTime, true);
					}
					this.itemTime = this.inventory[this.selectedItem].useTime;
				}
				if (this.inventory[this.selectedItem].type == 678)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					if (this.whoAmi == Main.myPlayer)
					{
						this.AddBuff(20, 216000, true);
						this.AddBuff(22, 216000, true);
						this.AddBuff(23, 216000, true);
						this.AddBuff(24, 216000, true);
						this.AddBuff(30, 216000, true);
						this.AddBuff(31, 216000, true);
						this.AddBuff(32, 216000, true);
						this.AddBuff(33, 216000, true);
						this.AddBuff(35, 216000, true);
						this.AddBuff(36, 216000, true);
						this.AddBuff(68, 216000, true);
					}
				}
			}
			if (this.whoAmi == Main.myPlayer)
			{
				if (this.itemTime == 0 && this.itemAnimation > 0 && this.inventory[this.selectedItem].type == 361 && Main.CanStartInvasion(1, true))
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
					if (Main.netMode != 1)
					{
						if (Main.invasionType == 0)
						{
							Main.invasionDelay = 0;
							Main.StartInvasion(1);
						}
					}
					else
					{
						NetMessage.SendData(61, -1, -1, "", this.whoAmi, -1f, 0f, 0f, 0);
					}
				}
				if (this.itemTime == 0 && this.itemAnimation > 0 && this.inventory[this.selectedItem].type == 602 && Main.CanStartInvasion(2, true))
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
					if (Main.netMode != 1)
					{
						if (Main.invasionType == 0)
						{
							Main.invasionDelay = 0;
							Main.StartInvasion(2);
						}
					}
					else
					{
						NetMessage.SendData(61, -1, -1, "", this.whoAmi, -2f, 0f, 0f, 0);
					}
				}
				if (this.itemTime == 0 && this.itemAnimation > 0 && this.inventory[this.selectedItem].type == 1315 && Main.CanStartInvasion(3, true))
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
					if (Main.netMode != 1)
					{
						if (Main.invasionType == 0)
						{
							Main.invasionDelay = 0;
							Main.StartInvasion(3);
						}
					}
					else
					{
						NetMessage.SendData(61, -1, -1, "", this.whoAmi, -3f, 0f, 0f, 0);
					}
				}
				if (this.itemTime == 0 && this.itemAnimation > 0 && this.inventory[this.selectedItem].type == 1844 && !Main.dayTime && !Main.pumpkinMoon && !Main.snowMoon)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
					if (Main.netMode != 1)
					{
						Main.NewText(Lang.misc[31], 50, 255, 130, false);
						Main.startPumpkinMoon();
					}
					else
					{
						NetMessage.SendData(61, -1, -1, "", this.whoAmi, -4f, 0f, 0f, 0);
					}
				}
				if (this.itemTime == 0 && this.itemAnimation > 0 && this.inventory[this.selectedItem].type == 1958 && !Main.dayTime && !Main.pumpkinMoon && !Main.snowMoon)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
					if (Main.netMode != 1)
					{
						Main.NewText(Lang.misc[34], 50, 255, 130, false);
						Main.startSnowMoon();
					}
					else
					{
						NetMessage.SendData(61, -1, -1, "", this.whoAmi, -5f, 0f, 0f, 0);
					}
				}
				if (this.itemTime == 0 && this.itemAnimation > 0 && this.inventory[this.selectedItem].makeNPC > 0 && this.controlUseItem && this.position.X / 16f - (float)Player.tileRangeX - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetX && (this.position.X + (float)this.width) / 16f + (float)Player.tileRangeX + (float)this.inventory[this.selectedItem].tileBoost - 1f >= (float)Player.tileTargetX && this.position.Y / 16f - (float)Player.tileRangeY - (float)this.inventory[this.selectedItem].tileBoost <= (float)Player.tileTargetY && (this.position.Y + (float)this.height) / 16f + (float)Player.tileRangeY + (float)this.inventory[this.selectedItem].tileBoost - 2f >= (float)Player.tileTargetY)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
					int x6 = Main.mouseX + (int)Main.screenPosition.X;
					int y6 = Main.mouseY + (int)Main.screenPosition.Y;
					NPC.ReleaseNPC(x6, y6, (int)this.inventory[this.selectedItem].makeNPC, this.inventory[this.selectedItem].placeStyle, this.whoAmi);
				}
				if (this.itemTime == 0 && this.itemAnimation > 0 && (this.inventory[this.selectedItem].type == 43 || this.inventory[this.selectedItem].type == 70 || this.inventory[this.selectedItem].type == 544 || this.inventory[this.selectedItem].type == 556 || this.inventory[this.selectedItem].type == 557 || this.inventory[this.selectedItem].type == 560 || this.inventory[this.selectedItem].type == 1133 || this.inventory[this.selectedItem].type == 1331) && this.SummonItemCheck())
				{
					if (this.inventory[this.selectedItem].type == 560)
					{
						this.itemTime = this.inventory[this.selectedItem].useTime;
						Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
						if (Main.netMode != 1)
						{
							NPC.SpawnOnPlayer(i, 50);
						}
						else
						{
							NetMessage.SendData(61, -1, -1, "", this.whoAmi, 50f, 0f, 0f, 0);
						}
					}
					else if (this.inventory[this.selectedItem].type == 43)
					{
						if (!Main.dayTime)
						{
							this.itemTime = this.inventory[this.selectedItem].useTime;
							Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
							if (Main.netMode != 1)
							{
								NPC.SpawnOnPlayer(i, 4);
							}
							else
							{
								NetMessage.SendData(61, -1, -1, "", this.whoAmi, 4f, 0f, 0f, 0);
							}
						}
					}
					else if (this.inventory[this.selectedItem].type == 70)
					{
						if (this.zoneEvil)
						{
							this.itemTime = this.inventory[this.selectedItem].useTime;
							Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
							if (Main.netMode != 1)
							{
								NPC.SpawnOnPlayer(i, 13);
							}
							else
							{
								NetMessage.SendData(61, -1, -1, "", this.whoAmi, 13f, 0f, 0f, 0);
							}
						}
					}
					else if (this.inventory[this.selectedItem].type == 544)
					{
						if (!Main.dayTime)
						{
							this.itemTime = this.inventory[this.selectedItem].useTime;
							Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
							if (Main.netMode != 1)
							{
								NPC.SpawnOnPlayer(i, 125);
								NPC.SpawnOnPlayer(i, 126);
							}
							else
							{
								NetMessage.SendData(61, -1, -1, "", this.whoAmi, 125f, 0f, 0f, 0);
								NetMessage.SendData(61, -1, -1, "", this.whoAmi, 126f, 0f, 0f, 0);
							}
						}
					}
					else if (this.inventory[this.selectedItem].type == 556)
					{
						if (!Main.dayTime)
						{
							this.itemTime = this.inventory[this.selectedItem].useTime;
							Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
							if (Main.netMode != 1)
							{
								NPC.SpawnOnPlayer(i, 134);
							}
							else
							{
								NetMessage.SendData(61, -1, -1, "", this.whoAmi, 134f, 0f, 0f, 0);
							}
						}
					}
					else if (this.inventory[this.selectedItem].type == 557)
					{
						if (!Main.dayTime)
						{
							this.itemTime = this.inventory[this.selectedItem].useTime;
							Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
							if (Main.netMode != 1)
							{
								NPC.SpawnOnPlayer(i, 127);
							}
							else
							{
								NetMessage.SendData(61, -1, -1, "", this.whoAmi, 127f, 0f, 0f, 0);
							}
						}
					}
					else if (this.inventory[this.selectedItem].type == 1133)
					{
						this.itemTime = this.inventory[this.selectedItem].useTime;
						Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
						if (Main.netMode != 1)
						{
							NPC.SpawnOnPlayer(i, 222);
						}
						else
						{
							NetMessage.SendData(61, -1, -1, "", this.whoAmi, 222f, 0f, 0f, 0);
						}
					}
					else if (this.inventory[this.selectedItem].type == 1331 && this.zoneBlood)
					{
						this.itemTime = this.inventory[this.selectedItem].useTime;
						Main.PlaySound(15, (int)this.position.X, (int)this.position.Y, 0);
						if (Main.netMode != 1)
						{
							NPC.SpawnOnPlayer(i, 266);
						}
						else
						{
							NetMessage.SendData(61, -1, -1, "", this.whoAmi, 266f, 0f, 0f, 0);
						}
					}
				}
			}
			if (this.inventory[this.selectedItem].type == 50 && this.itemAnimation > 0)
			{
				if (Main.rand.Next(2) == 0)
				{
					Dust.NewDust(this.position, this.width, this.height, 15, 0f, 0f, 150, default(Color), 1.1f);
				}
				if (this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
				}
				else if (this.itemTime == this.inventory[this.selectedItem].useTime / 2)
				{
					for (int num251 = 0; num251 < 70; num251++)
					{
						Dust.NewDust(this.position, this.width, this.height, 15, this.velocity.X * 0.5f, this.velocity.Y * 0.5f, 150, default(Color), 1.5f);
					}
					this.grappling[0] = -1;
					this.grapCount = 0;
					for (int num252 = 0; num252 < 1000; num252++)
					{
						if (Main.projectile[num252].active && Main.projectile[num252].owner == i && Main.projectile[num252].aiStyle == 7)
						{
							Main.projectile[num252].Kill();
						}
					}
					this.Spawn();
					for (int num253 = 0; num253 < 70; num253++)
					{
						Dust.NewDust(this.position, this.width, this.height, 15, 0f, 0f, 150, default(Color), 1.5f);
					}
				}
			}
			if (this.inventory[this.selectedItem].type == 2350 && this.itemAnimation > 0)
			{
				if (this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
				}
				else if (this.itemTime == 2)
				{
					for (int num254 = 0; num254 < 70; num254++)
					{
						Main.dust[Dust.NewDust(this.position, this.width, this.height, 15, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 150, Color.Cyan, 1.2f)].velocity *= 0.5f;
					}
					this.grappling[0] = -1;
					this.grapCount = 0;
					for (int num255 = 0; num255 < 1000; num255++)
					{
						if (Main.projectile[num255].active && Main.projectile[num255].owner == i && Main.projectile[num255].aiStyle == 7)
						{
							Main.projectile[num255].Kill();
						}
					}
					bool flag18 = this.immune;
					int num256 = this.immuneTime;
					this.Spawn();
					this.immune = flag18;
					this.immuneTime = num256;
					for (int num257 = 0; num257 < 70; num257++)
					{
						Main.dust[Dust.NewDust(this.position, this.width, this.height, 15, 0f, 0f, 150, Color.Cyan, 1.2f)].velocity *= 0.5f;
					}
					if (this.inventory[this.selectedItem].stack > 0)
					{
						this.inventory[this.selectedItem].stack--;
					}
				}
			}
			if (this.inventory[this.selectedItem].type == 2351 && this.itemAnimation > 0)
			{
				if (this.itemTime == 0)
				{
					this.itemTime = this.inventory[this.selectedItem].useTime;
				}
				else if (this.itemTime == 2)
				{
					if (Main.netMode == 0)
					{
						this.TeleportationPotion();
					}
					else if (Main.netMode == 1 && this.whoAmi == Main.myPlayer)
					{
						NetMessage.SendData(73, -1, -1, "", 0, 0f, 0f, 0f, 0);
					}
					if (this.inventory[this.selectedItem].stack > 0)
					{
						this.inventory[this.selectedItem].stack--;
					}
				}
			}
			if (i == Main.myPlayer)
			{
				if (this.itemTime == (int)((float)this.inventory[this.selectedItem].useTime * this.tileSpeed) && this.inventory[this.selectedItem].tileWand > 0)
				{
					int tileWand2 = this.inventory[this.selectedItem].tileWand;
					int num258 = 0;
					while (num258 < 58)
					{
						if (tileWand2 == this.inventory[num258].type && this.inventory[num258].stack > 0)
						{
							this.inventory[num258].stack--;
							if (this.inventory[num258].stack <= 0)
							{
								this.inventory[num258] = new Item();
								break;
							}
							break;
						}
						else
						{
							num258++;
						}
					}
				}
				int num259;
				if (this.inventory[this.selectedItem].createTile >= 0)
				{
					num259 = (int)((float)this.inventory[this.selectedItem].useTime * this.tileSpeed);
				}
				else if (this.inventory[this.selectedItem].createWall > 0)
				{
					num259 = (int)((float)this.inventory[this.selectedItem].useTime * this.wallSpeed);
				}
				else
				{
					num259 = this.inventory[this.selectedItem].useTime;
				}
				if (this.itemTime == num259 && this.inventory[this.selectedItem].consumable)
				{
					bool flag19 = true;
					if (this.inventory[this.selectedItem].type == 2350 || this.inventory[this.selectedItem].type == 2351)
					{
						flag19 = false;
					}
					if (this.inventory[this.selectedItem].ranged)
					{
						if (this.ammoCost80 && Main.rand.Next(5) == 0)
						{
							flag19 = false;
						}
						if (this.ammoCost75 && Main.rand.Next(4) == 0)
						{
							flag19 = false;
						}
					}
					if (this.inventory[this.selectedItem].type >= 71 && this.inventory[this.selectedItem].type <= 74)
					{
						flag19 = true;
					}
					if (flag19)
					{
						if (this.inventory[this.selectedItem].stack > 0)
						{
							this.inventory[this.selectedItem].stack--;
						}
						if (this.inventory[this.selectedItem].stack <= 0)
						{
							this.itemTime = this.itemAnimation;
						}
					}
				}
				if (this.inventory[this.selectedItem].stack <= 0 && this.itemAnimation == 0)
				{
					this.inventory[this.selectedItem] = new Item();
				}
				if (this.selectedItem == 58)
				{
					if (this.itemAnimation == 0)
					{
						return;
					}
					Main.mouseItem = this.inventory[this.selectedItem].Clone();
				}
			}
		}
Esempio n. 11
0
        public void Leveling7PointsCorectInterpolation()
        {
            PrintLevelingData levelingData = new PrintLevelingData();

            double radius = 100;

            levelingData.SampledPositions = new List <Vector3>();
            Vector2 currentEdgePoint = new Vector2(radius, 0);

            for (int i = 0; i < 6; i++)
            {
                levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
                currentEdgePoint.Rotate(MathHelper.Tau / 6);
            }

            levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

            Vector2 bedCenter = Vector2.Zero;

            RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);

            for (int curPoint = 0; curPoint < 6; curPoint++)
            {
                int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

                // test actual sample position
                Vector2 currentTestPoint = new Vector2(radius, 0);
                currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
                Vector3 destPosition = new Vector3(currentTestPoint, 0);
                Vector3 outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);
                string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test mid point between samples
                Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
                currentTestPoint = new Vector2(midPoint.x, midPoint.y);
                destPosition     = new Vector3(currentTestPoint, 0);
                outPosition      = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, midPoint.z, .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test mid point between samples with offset
                Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
                currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
                destPosition     = new Vector3(currentTestPoint, 3);
                outPosition      = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test 1/2 angles (mid way between samples on radius)
                currentTestPoint = new Vector2(radius, 0);
                currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
                destPosition = new Vector3(currentTestPoint, 0);
                outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                // the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
                Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

                // test 1/2 to center
                currentTestPoint = new Vector2(radius / 2, 0);
                currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
                destPosition = new Vector3(currentTestPoint, 0);
                outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
                Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
                outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
                Assert.AreEqual(GetGCodeString(outPosition), outPositionString);
            }

            // prove that relative offsets work
            {
                Vector2 prevTestPoint         = new Vector2(radius, 0);
                Vector3 prevDestPosition      = new Vector3(prevTestPoint, 0);
                Vector3 prevOutPosition       = levelingFunctions7Point.GetPositionWithZOffset(prevDestPosition);
                string  prevOutPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(prevDestPosition), prevDestPosition, PrinterMachineInstruction.MovementTypes.Absolute);

                for (int curPoint = 1; curPoint < 6; curPoint++)
                {
                    // test actual sample position
                    Vector2 currentTestPoint = new Vector2(radius, 0);
                    currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
                    Vector3 destPosition = new Vector3(currentTestPoint, 0);
                    Vector3 outPosition  = levelingFunctions7Point.GetPositionWithZOffset(destPosition);

                    string  outPositionString      = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Relative);
                    Vector3 delatFromPrevToCurrent = outPosition - prevOutPosition;
                    Assert.AreEqual(GetGCodeString(delatFromPrevToCurrent), outPositionString);

                    prevTestPoint    = currentTestPoint;
                    prevDestPosition = destPosition;
                    prevOutPosition  = outPosition;
                }
            }

            Vector3 outPosition2 = levelingFunctions7Point.GetPositionWithZOffset(Vector3.Zero);

            Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
        }
Esempio n. 12
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            bool valuesChanged = false;

            if (Angle < 1 || Angle > 100000)
            {
                Angle         = Math.Min(100000, Math.Max(1, Angle));
                valuesChanged = true;
            }

            if (MinCutsPerRotation < 3 || MinCutsPerRotation > 360)
            {
                MinCutsPerRotation = Math.Min(360, Math.Max(3, MinCutsPerRotation));
                valuesChanged      = true;
            }

            if (EndHeightPercent < 1 || EndHeightPercent > 100)
            {
                EndHeightPercent = Math.Min(100, Math.Max(1, EndHeightPercent));
                valuesChanged    = true;
            }

            if (StartHeightPercent < 0 || StartHeightPercent > EndHeightPercent - 1)
            {
                StartHeightPercent = Math.Min(EndHeightPercent - 1, Math.Max(0, StartHeightPercent));
                valuesChanged      = true;
            }

            var rebuildLocks = this.RebuilLockAll();

            return(ApplicationController.Instance.Tasks.Execute(
                       "Twist".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var sourceAabb = this.SourceContainer.GetAxisAlignedBoundingBox();

                var bottom = sourceAabb.MinXYZ.Z;
                var top = sourceAabb.ZSize * EndHeightPercent / 100.0;
                var size = sourceAabb.ZSize;
                if (Advanced)
                {
                    bottom += sourceAabb.ZSize * StartHeightPercent / 100.0;
                    size = top - bottom;
                }

                double numberOfCuts = MinCutsPerRotation * (Angle / 360.0);
                double cutSize = size / numberOfCuts;
                var cuts = new List <double>();
                for (int i = 0; i < numberOfCuts + 1; i++)
                {
                    var ratio = i / numberOfCuts;
                    if (Advanced)
                    {
                        var goal = ratio;
                        var current = .5;
                        var next = .25;
                        // look for an x value that equals the goal
                        for (int j = 0; j < 64; j++)
                        {
                            var xAtY = Easing.Specify(EasingType, EasingOption, current);
                            if (xAtY < goal)
                            {
                                current += next;
                            }
                            else if (xAtY > goal)
                            {
                                current -= next;
                            }

                            next *= .5;
                        }

                        ratio = current;
                    }

                    cuts.Add(bottom - cutSize + (size * ratio));
                }

                // get the rotation from the center of the circumscribed circle of the convex hull
                var rotationCenter = SourceContainer.GetSmallestEnclosingCircleAlongZ().Center + RotationOffset;

                var twistedChildren = new List <IObject3D>();

                var status = new ProgressStatus();

                foreach (var sourceItem in SourceContainer.VisibleMeshes())
                {
                    var originalMesh = sourceItem.Mesh;
                    status.Status = "Copy Mesh".Localize();
                    reporter.Report(status);
                    var transformedMesh = originalMesh.Copy(CancellationToken.None);
                    var itemMatrix = sourceItem.WorldMatrix(SourceContainer);

                    // transform into this space
                    transformedMesh.Transform(itemMatrix);

                    status.Status = "Split Mesh".Localize();
                    reporter.Report(status);

                    // split the mesh along the z axis
                    transformedMesh.SplitOnPlanes(Vector3.UnitZ, cuts, cutSize / 8);

                    for (int i = 0; i < transformedMesh.Vertices.Count; i++)
                    {
                        var position = transformedMesh.Vertices[i];

                        var ratio = (position.Z - bottom) / size;

                        if (Advanced)
                        {
                            if (position.Z < bottom)
                            {
                                ratio = 0;
                            }
                            else if (position.Z > top)
                            {
                                ratio = 1;
                            }
                            else
                            {
                                ratio = (position.Z - bottom) / size;
                                ratio = Easing.Specify(EasingType, EasingOption, ratio);
                            }
                        }

                        var angleToRotate = ratio * Angle / 360.0 * MathHelper.Tau;

                        if (!TwistCw)
                        {
                            angleToRotate = -angleToRotate;
                        }

                        var positionXy = new Vector2(position) - rotationCenter;
                        positionXy.Rotate(angleToRotate);
                        positionXy += rotationCenter;
                        transformedMesh.Vertices[i] = new Vector3Float(positionXy.X, positionXy.Y, position.Z);
                    }

                    // transform back into item local space
                    transformedMesh.Transform(itemMatrix.Inverted);

                    //transformedMesh.MergeVertices(.1);
                    transformedMesh.CalculateNormals();

                    var twistedChild = new Object3D()
                    {
                        Mesh = transformedMesh
                    };
                    twistedChild.CopyWorldProperties(sourceItem, SourceContainer, Object3DPropertyFlags.All);
                    twistedChild.Visible = true;

                    twistedChildren.Add(twistedChild);
                }

                RemoveAllButSource();
                this.SourceContainer.Visible = false;

                this.Children.Modify((list) =>
                {
                    list.AddRange(twistedChildren);
                });

                rebuildLocks.Dispose();

                if (valuesChanged)
                {
                    Invalidate(InvalidateType.DisplayValues);
                }

                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));

                return Task.CompletedTask;
            }));
        }
        //  Moves and rotates player by specified vector and angles
        public override void MoveAndRotate(Vector3 moveIndicator, Vector2 rotationIndicator, float rollIndicator)
        {
            switch (SpectatorCameraMovement)
            {
            case MySpectatorCameraMovementEnum.None:
                return;

                break;

            case MySpectatorCameraMovementEnum.ConstantDelta:
            {
                if (!MyInput.Static.IsAnyAltKeyPressed() && !MyInput.Static.IsAnyCtrlKeyPressed() && !MyInput.Static.IsAnyShiftKeyPressed())
                {
                    if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                    {
                        ThirdPersonCameraDelta /= 1.1f;
                    }
                    else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                    {
                        ThirdPersonCameraDelta *= 1.1f;
                    }
                }

                if (MySession.ControlledEntity != null)
                {
                    Position = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition() + ThirdPersonCameraDelta;
                    Target   = (Vector3D)MySession.ControlledEntity.Entity.PositionComp.GetPosition();
                }
            }
            break;

            case MySpectatorCameraMovementEnum.UserControlled:
            {
                if (MyInput.Static.IsAnyCtrlKeyPressed())
                {
                    if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                    {
                        SpeedModeAngular = Math.Min(SpeedModeAngular * 1.5f, MAX_SPECTATOR_ANGULAR_SPEED);
                    }
                    else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                    {
                        SpeedModeAngular = Math.Max(SpeedModeAngular / 1.5f, MIN_SPECTATOR_ANGULAR_SPEED);
                    }
                }
                else
                {
                    if (MyInput.Static.PreviousMouseScrollWheelValue() < MyInput.Static.MouseScrollWheelValue())
                    {
                        SpeedModeLinear = Math.Min(SpeedModeLinear * 1.5f, MAX_SPECTATOR_LINEAR_SPEED);
                    }
                    else if (MyInput.Static.PreviousMouseScrollWheelValue() > MyInput.Static.MouseScrollWheelValue())
                    {
                        SpeedModeLinear = Math.Max(SpeedModeLinear / 1.5f, MIN_SPECTATOR_LINEAR_SPEED);
                    }
                }

                //  Physical movement and rotation is based on constant time, therefore is indepedent of time delta
                //  This formulas works even if FPS is low or high, or if step size is 1/10 or 1/10000
                float amountOfMovement = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS * 100;
                float amountOfRotation = 0.0025f * m_speedModeAngular;

                if (MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS)
                {
                    rollIndicator = MyInput.Static.GetDeveloperRoll();
                }

                float rollAmount = 0;
                if (rollIndicator != 0)
                {
                    Vector3D r, u;
                    rollAmount = rollIndicator * m_speedModeAngular * 0.1f;
                    rollAmount = MathHelper.Clamp(rollAmount, -0.02f, 0.02f);
                    MyUtils.VectorPlaneRotation(m_orientation.Up, m_orientation.Right, out u, out r, rollAmount);
                    m_orientation.Right = r;
                    m_orientation.Up    = u;
                }

                Vector3 moveVector;

                if (MyPerGameSettings.RestrictSpectatorFlyMode && !MyFakes.ENABLE_DEVELOPER_SPECTATOR_CONTROLS)
                {
                    // Spectator has constatnt speed (reset speed to default value)
                    SpeedModeLinear = 11 * MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;
                    if (MyInput.Static.IsAnyShiftKeyPressed())
                    {
                        SpeedModeLinear *= 5;
                    }

                    Vector3D forward = m_orientation.Forward;
                    double   sinX    = forward.Dot(ref Vector3D.Up);
                    double   angleX  = Math.Asin(sinX);
                    double   angleY;
                    if (MyUtils.IsZero(sinX - 1f))
                    {
                        // Looking up
                        var up = m_orientation.Up;
                        angleY = Math.Atan2(up.Dot(ref Vector3D.Right), up.Dot(ref Vector3D.Backward));
                    }
                    else if (MyUtils.IsZero(sinX + 1f))
                    {
                        // Looking down
                        var up = m_orientation.Up;
                        angleY = Math.Atan2(up.Dot(ref Vector3D.Left), up.Dot(ref Vector3D.Forward));
                    }
                    else
                    {
                        // non-degenerate case
                        forward.Y = 0.0;
                        forward.Normalize();
                        angleY = Math.Atan2(forward.Dot(ref Vector3D.Left), forward.Dot(ref Vector3D.Forward));
                    }

                    angleX = MathHelper.Clamp(angleX - rotationIndicator.X * amountOfRotation, -MathHelper.PiOver2, MathHelper.PiOver2);

                    angleY -= rotationIndicator.Y * amountOfRotation;
                    if (angleY > MathHelper.Pi)
                    {
                        angleY -= MathHelper.TwoPi;
                    }
                    if (angleY < -MathHelper.Pi)
                    {
                        angleY += MathHelper.TwoPi;
                    }

                    m_orientation = MatrixD.CreateRotationX(angleX) * MatrixD.CreateRotationY(angleY);

                    moveIndicator *= SpeedModeLinear;
                    moveVector     = moveIndicator * amountOfMovement;
                }
                else
                {
                    if (!MyFakes.ENABLE_SPECTATOR_ROLL_MOVEMENT)
                    {
                        // TODO: compute from current orientation matrix yaw/pitch/roll

                        rotationIndicator.Rotate(m_roll);

                        m_yaw   -= rotationIndicator.Y * amountOfRotation;
                        m_pitch -= rotationIndicator.X * amountOfRotation;
                        m_roll  -= rollAmount;

                        MathHelper.LimitRadians2PI(ref m_yaw);
                        m_pitch = MathHelper.Clamp(m_pitch, -Math.PI * 0.5f, Math.PI * 0.5f);
                        MathHelper.LimitRadians2PI(ref m_roll);

                        m_orientation = MatrixD.CreateFromYawPitchRoll(m_yaw, m_pitch, m_roll);
                    }
                    else
                    {
                        if (rotationIndicator.Y != 0)
                        {
                            Vector3D r, f;
                            MyUtils.VectorPlaneRotation(m_orientation.Right, m_orientation.Forward, out r, out f, -rotationIndicator.Y * amountOfRotation);

                            m_orientation.Right   = r;
                            m_orientation.Forward = f;
                        }

                        if (rotationIndicator.X != 0)
                        {
                            Vector3D u, f;
                            MyUtils.VectorPlaneRotation(m_orientation.Up, m_orientation.Forward, out u, out f, rotationIndicator.X * amountOfRotation);
                            m_orientation.Up      = u;
                            m_orientation.Forward = f;
                        }
                    }

                    float afterburner = (MyInput.Static.IsAnyShiftKeyPressed() ? 1.0f : 0.35f) * (MyInput.Static.IsAnyCtrlKeyPressed() ? 0.3f : 1);
                    moveIndicator *= afterburner * SpeedModeLinear;
                    moveVector     = moveIndicator * amountOfMovement;
                }


                Position += Vector3.Transform(moveVector, m_orientation);
            }
            break;
            }
        }
Esempio n. 14
0
    protected override void HoldingItem(bool use, bool startUse, bool endUse, bool doubleUse)
    {
        //update the time before the next missle can be shot
        if (shotTimer > 0)
        {
            shotTimer--;
        }
        //if its time to shoot the next missle and the holder is pressing this Item's key,
        //then create a new missle infront of the holder
        else if (use)
        {
            //create the missle infront of the holder
            HomingMissile missile = (HomingMissile)level.CreateObject("HomingMissilePF",
                                                                      holder.position + offset.Rotate(holder.angle), holder.angle, holder.velocity);

            //set the missle's initial settings
            missile.damage         = missileDamge;
            missile.acceleration   = missileAcceleration;
            missile.turnSpeed      = missileTurnSpeed;
            missile.timeToLiveSecs = missleLifeTimeSecs;
            missile.team           = holder.team;
            missile.color          = color;
            missile.maxSpeed       = missileMaxSpeed;

            //reset the timer to shoot the next missle
            shotTimer = (int)(shootTimeSecs * level.updatesPerSec);

            level.score += USE_POINTS;
        }
    }
Esempio n. 15
0
        private Object3D GetTab(bool calibrateX)
        {
            var content = new Object3D();

            var spaceBetween = NozzleWidth * tabScale;

            var shape = new VertexStorage();

            shape.MoveTo(0, 0);
            // left + spaces + blocks + right
            var sampleCount = 7;
            var baseWidth   = (2 * spaceBetween) + ((sampleCount - 1) * spaceBetween) + (sampleCount * TabWidth) + (2 * spaceBetween);

            shape.LineTo(baseWidth, 0);
            if (calibrateX)
            {
                var origin = new Vector2(baseWidth, TabDepth / 2);
                var delta  = new Vector2(0, -TabDepth / 2);
                var count  = 15;
                for (int i = 0; i < count; i++)
                {
                    delta.Rotate(MathHelper.Tau / 2 / count);
                    shape.LineTo(origin + delta);
                }
            }
            else
            {
                shape.LineTo(baseWidth + TabDepth, TabDepth / 2);                 // a point on the left
            }
            shape.LineTo(baseWidth, TabDepth);
            shape.LineTo(0, TabDepth);

            content.Children.Add(new Object3D()
            {
                Mesh  = shape.Extrude(BaseHeight),
                Color = Color.LightBlue
            });

            var position = new Vector2(TabWidth / 2 + 2 * spaceBetween, TabDepth / 2);
            var step     = new Vector2(spaceBetween + TabWidth, 0);

            for (int i = 0; i < sampleCount; i++)
            {
                var offsetMultiple = i - 3;
                for (int j = 0; j < Layers; j++)
                {
                    var calibrationMaterial = (j % 2 == 0);
                    var cube = PlatonicSolids.CreateCube();
                    var item = new Object3D()
                    {
                        Mesh = cube,
                    };
                    content.Children.Add(item);
                    if (calibrationMaterial)
                    {
                        item.MaterialIndex = CalibrationMaterialIndex;
                        item.Color         = Color.Yellow;
                        item.Matrix        = Matrix4X4.CreateScale(TabWidth, TabDepth, ChangingHeight) * Matrix4X4.CreateTranslation(position.X, position.Y + Offset * offsetMultiple, BaseHeight + .5 * ChangingHeight + j * ChangingHeight);
                    }
                    else
                    {
                        item.Color  = Color.LightBlue;
                        item.Matrix = Matrix4X4.CreateScale(TabWidth + spaceBetween * 2, TabDepth, ChangingHeight) * Matrix4X4.CreateTranslation(position.X, position.Y, BaseHeight + .5 * ChangingHeight + j * ChangingHeight);
                    }
                }
                position += step;
            }

            if (calibrateX)
            {
                content.Matrix = Matrix4X4.CreateRotationZ(MathHelper.Tau / 4) * Matrix4X4.CreateTranslation(0, TabDepth, 0);
            }

            return(content);
        }
Esempio n. 16
0
 public void ApplyRelativeLinearImpulse( Vector2 impulse )
 {
     Body.ApplyLinearImpulse( impulse.Rotate( Rotation ) );
 }
Esempio n. 17
0
    protected override void UpdateDestructableObject()
    {
        emitTimer--;

        //emit Lazers if it is time to
        if (emitTimer <= 0)
        {
            emitTimer = (int)(lazerEmitSecs * level.updatesPerSec);

            //create LazerShots around the this LazerEmitter equally spaced angles
            for (int i = 0; i < numLazers * difficultyModifier; i++)
            {
                float     currentAngle = angle + i * 360f / numLazers;
                LazerShot current      = (LazerShot)level.CreateObject("LazerShotPF", position + lazerOffset.Rotate(currentAngle), currentAngle, new Vector2(lazerSpeed, 0).ToAngle(currentAngle) + velocity);
                current.damage         = damage;
                current.timeToLiveSecs = lazerLifeSecs;
                current.color          = lazerColor;
                current.team           = team;
            }
        }
    }
Esempio n. 18
0
 public override Vector2 GetRelativeOffset(Vector2 vector)
 {
     return(vector.Rotate(-InitAngle));
 }
Esempio n. 19
0
        public static void ExtrudePolygon(Polygon sourcePolygon, out Polygon[] outputPolygons, out Quaternion rotation)
        {
            float extrusionDistance = 1;

            Polygon basePolygon = sourcePolygon.DeepCopy();

            basePolygon.UniqueIndex = -1;

            rotation = Quaternion.LookRotation(basePolygon.Plane.normal);
            Quaternion cancellingRotation = Quaternion.Inverse(rotation);

            Vertex[] vertices = basePolygon.Vertices;
//			Vector3 offsetPosition = vertices[0].Position;

            for (int i = 0; i < vertices.Length; i++)
            {
//				vertices[i].Position -= offsetPosition;
                vertices[i].Position = cancellingRotation * vertices[i].Position;

                vertices[i].Normal = cancellingRotation * vertices[i].Normal;
            }

//			Vector3 newOffsetPosition = vertices[0].Position;
//			Vector3 delta = newOffsetPosition - offsetPosition;
//			for (int i = 0; i < vertices.Length; i++)
//			{
//				vertices[i].Position += delta;
//			}

            basePolygon.SetVertices(vertices);

            Vector3 normal          = basePolygon.Plane.normal;
            Polygon oppositePolygon = basePolygon.DeepCopy();

            oppositePolygon.UniqueIndex = -1;

            basePolygon.Flip();

            vertices = oppositePolygon.Vertices;
            for (int i = 0; i < vertices.Length; i++)
            {
                vertices[i].Position += normal;
            }
            oppositePolygon.SetVertices(vertices);

            Polygon[] brushSides = new Polygon[sourcePolygon.Vertices.Length];

            for (int i = 0; i < basePolygon.Vertices.Length; i++)
            {
                Vertex vertex1 = basePolygon.Vertices[i].DeepCopy();
                Vertex vertex2 = basePolygon.Vertices[(i + 1) % basePolygon.Vertices.Length].DeepCopy();

                Vector2 uvDelta = vertex2.UV - vertex1.UV;

                float sourceDistance = Vector3.Distance(vertex1.Position, vertex2.Position);

                Vector2 rotatedUVDelta = uvDelta.Rotate(90) * (extrusionDistance / sourceDistance);

                Vertex vertex3 = vertex1.DeepCopy();
                vertex3.Position += normal * extrusionDistance;
                vertex3.UV       += rotatedUVDelta;

                Vertex vertex4 = vertex2.DeepCopy();
                vertex4.Position += normal * extrusionDistance;
                vertex4.UV       += rotatedUVDelta;

                Vertex[] newVertices = new Vertex[] { vertex1, vertex2, vertex4, vertex3 };

                brushSides[i] = new Polygon(newVertices, sourcePolygon.Material, false, false);
                brushSides[i].Flip();
                brushSides[i].ResetVertexNormals();
            }

            List <Polygon> polygons = new List <Polygon>();

            polygons.Add(basePolygon);
            polygons.Add(oppositePolygon);
            polygons.AddRange(brushSides);

            outputPolygons = polygons.ToArray();
        }
Esempio n. 20
0
        // shoutouts to Jasmine Mickle for your insight and UV texture coordinates code.
        private static void CalculateTextureCoordinates(PrimitiveBrush pr, Polygon polygon, int textureWidth, int textureHeight, Vector2 offset, Vector2 scale, float rotation)
        {
            // feel free to improve this uv mapping code, it has some issues.
            // • 45 degree angled walls may not have correct UV texture coordinates (are not correctly picking the dominant axis because there are two).
            // • negative vertex coordinates may not have correct UV texture coordinates.

            // calculate texture coordinates.
            for (int i = 0; i < polygon.Vertices.Length; i++)
            {
                // we scaled down the level so scale up the math here.
                var vertex = (pr.transform.position + polygon.Vertices[i].Position) * s_Scale;

                Vector2 uv = new Vector2(0, 0);

                int dominantAxis = 0; // 0 == x, 1 == y, 2 == z

                // find the axis closest to the polygon's normal.
                float[] axes =
                {
                    Mathf.Abs(polygon.Plane.normal.x),
                    Mathf.Abs(polygon.Plane.normal.z),
                    Mathf.Abs(polygon.Plane.normal.y)
                };

                // defaults to use x-axis.
                dominantAxis = 0;
                // check whether the y-axis is more likely.
                if (axes[1] > axes[dominantAxis])
                {
                    dominantAxis = 1;
                }
                // check whether the z-axis is more likely.
                if (axes[2] >= axes[dominantAxis])
                {
                    dominantAxis = 2;
                }

                // x-axis:
                if (dominantAxis == 0)
                {
                    uv.x = vertex.z;
                    uv.y = vertex.y;
                }

                // y-axis:
                if (dominantAxis == 1)
                {
                    uv.x = vertex.x;
                    uv.y = vertex.y;
                }

                // z-axis:
                if (dominantAxis == 2)
                {
                    uv.x = vertex.x;
                    uv.y = vertex.z;
                }

                // rotate the texture coordinates.
                uv = uv.Rotate(-rotation);
                // scale the texture coordinates.
                uv = uv.Divide(scale);
                // move the texture coordinates.
                uv += offset;
                // finally divide the result by the texture size.
                uv = uv.Divide(new Vector2(textureWidth, textureHeight));

                polygon.Vertices[i].UV = uv;
            }
        }
Esempio n. 21
0
    private void HitBoxLaser()
    {
        // 1 coord y equivale a 18 angle.
        // x ----- 9 angle
        if (_laserCharged)
        {
            //var angleLine = _angle/_angleCte;
            var position       = laserEyePosition.position;
            var positionTop    = new Vector3(position.x, position.y + (laserRange.y / 2), 0);
            var positionBottom = new Vector3(position.x, position.y - (laserRange.y / 2), 0);

            _dir = _dir.Rotate(_angle);

            RaycastHit2D centerLineHit = Physics2D.Raycast(position, _dir, laserRange.x, layerMask);
            RaycastHit2D topLineHit    = Physics2D.Raycast(positionTop, _dir, laserRange.x, layerMask);
            RaycastHit2D bottomLineHit = Physics2D.Raycast(positionBottom, _dir, laserRange.x, layerMask);

            if (centerLineHit)
            {
                centerLineHit.collider.GetComponent <StatusComponent>().TakeDamage(laserDamage);
                _hitted = true;
            }
            else if (topLineHit)
            {
                topLineHit.collider.GetComponent <StatusComponent>().TakeDamage(laserDamage);
                _hitted = true;
            }
            else if (bottomLineHit)
            {
                bottomLineHit.collider.GetComponent <StatusComponent>().TakeDamage(laserDamage);
                _hitted = true;
            }

            Vector3[] positions = new[] { new Vector3(0, 0, 0), new Vector3((laserRange.x * _dir.x), (_dir.y) * laserRange.x, 0f) };
            _lineRenderer.SetPositions(positions);
            _lineRenderer.enabled = true;

            if (((timeLaserAttack - _timeLaserAttack) / timeFrame) > _timeCte)
            {
                _timeCte++;
                var playerDir   = PlayerDirection(position);
                var angle       = Vector2.SignedAngle(new Vector2(playerDir.x, playerDir.y), _dir);
                var actualAngle = Mathf.Min(Mathf.Abs(angle), anglePerFrame);

                if ((angle < 0))
                {
                    if (!_hitted && _waitHit < _timeCte)
                    {
                        _angle = actualAngle;
                    }

                    if (_hitted && _waitHit < _timeCte)
                    {
                        _angle   = angleAfterHitted;
                        _waitHit = _timeCte + howManyFramesSlowedAfterHit;
                    }
                    else if (_hitted)
                    {
                        _angle = angleAfterHitted;
                    }
                }
                else if ((angle > 0))
                {
                    if (!_hitted && _waitHit < _timeCte)
                    {
                        _angle = -actualAngle;
                    }

                    if (_hitted && _waitHit < _timeCte)
                    {
                        _angle   = -angleAfterHitted;
                        _waitHit = _timeCte + howManyFramesSlowedAfterHit;
                    }
                    else if (_hitted)
                    {
                        _angle = -angleAfterHitted;
                    }
                }
                else
                {
                    if (_hitted && _waitHit < _timeCte)
                    {
                        _waitHit = _timeCte + howManyFramesSlowedAfterHit;
                    }

                    _angle = 0;
                }


                if (_waitHit <= _timeCte && _hitted)
                {
                    _hitted = false;
                    print("finish it");
                }


                flipStaticEnemy(_dir);
            }
        }
    }
Esempio n. 22
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            // TODO: Add your update logic here
            if (gameTime.TotalGameTime.Milliseconds > 100)
            {
                transport.Update();
            }

            var obstaclePos = proximity.GetObstacles();
            for (int i = 0; i < obstaclePos.Length; i++)
            {
                var pos = new Vector2(obstaclePos[i].X, obstaclePos[i].Y);
                obstacleFrames[i].Position = pos.Rotate(botFrame.Rotation) + botFrame.Position;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Up))
            {
                vel = Math.Min(0.05f, vel + 0.001f);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Down))
            {
                vel = Math.Max(-0.05f, vel - 0.001f);
            }

            if (Keyboard.GetState().IsKeyDown(Keys.Left))
            {
                rot = (float)(4 * Math.PI / 360);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.Right))
            {
                rot = -(float)(4 * Math.PI / 360);
            }
            else rot = 0;

            redLed.SetValue(Mouse.GetState().LeftButton == ButtonState.Pressed ? 0 : 1);
            greenLed.SetValue(Mouse.GetState().MiddleButton == ButtonState.Pressed ? 0 : 1);
            blueLed.SetValue(Mouse.GetState().RightButton == ButtonState.Pressed ? 0 : 1);

            leftVel = MathHelper.SmoothStep(leftVel, wheels.GetLeftVelocity(), 0.05f);
            rightVel = MathHelper.SmoothStep(rightVel, wheels.GetRightVelocity(), 0.05f);

            if (Keyboard.GetState().IsKeyDown(Keys.Back))
            {
                vel = 0;
                rot = 0;
                wheels.SetTargetVelocity(vel, rot);
            }
            else drive.SetTargetVelocity(vel, rot);

            base.Update(gameTime);
        }
Esempio n. 23
0
 private void Shoot()
 {
     ShootVec = ShootVec.Rotate(0.5f);
     Scene.Add(Bullet.CreateEnemyBullet(Position, ShootVec * 3.0f));
 }
Esempio n. 24
0
        Geometry CreateTaperedLineGeometry(Point c0, double r0, Point c1, double r1)
        {
            // Swap the centers and radii so that c0 is
            //      center of the the smaller circle.
            if (r1 < r0)
            {
                Point point = c0;
                c0 = c1;
                c1 = point;

                double radius = r0;
                r0 = r1;
                r1 = radius;
            }

            // Get vector from c1 to c0
            Vector2 vCenters = new Vector2(c0) - new Vector2(c1);

            // Get length and normalized version
            double d = vCenters.Length;

            vCenters = vCenters.Normalized;

            // Determine if one circle is enclosed in the other
            bool enclosed = r0 + d < r1;

            // Define tangent points derived in both algorithms
            Point t0R = new Point();
            Point t0L = new Point();
            Point t1R = new Point();
            Point t1L = new Point();

            // Case for two circles of same size
            if (r0 == r1 || enclosed)
            {
                // Rotate centers vector 90 degrees
                Vector2 vLeft = new Vector2(-vCenters.Y, vCenters.X);

                // Rotate -90 degrees
                Vector2 vRight = -vLeft;

                // Find tangent points
                t0R = c0 + r0 * vRight;
                t0L = c0 + r0 * vLeft;
                t1R = c1 + r1 * vRight;
                t1L = c1 + r1 * vLeft;
            }
            // A bit more difficult for two circles of unequal size
            else
            {
                // Create focal point F extending from c0
                double e = d * r0 / (r1 - r0);
                Point  F = c0 + e * vCenters;

                // Find angle and length of right-triangle legs
                double alpha = 180 * Math.Asin(r0 / e) / Math.PI;
                double leg0  = Math.Sqrt(e * e - r0 * r0);
                double leg1  = Math.Sqrt((e + d) * (e + d) - r1 * r1);

                // Vectors of tangent lines
                Vector2 vRight = -vCenters.Rotate(alpha);
                Vector2 vLeft  = -vCenters.Rotate(-alpha);

                // Find tangent points
                t0R = F + leg0 * vRight;
                t0L = F + leg0 * vLeft;
                t1R = F + leg1 * vRight;
                t1L = F + leg1 * vLeft;
            }

            // Create PathGeometry with implied closing line
            PathGeometry pathGeometry = new PathGeometry();
            PathFigure   pathFigure   = new PathFigure
            {
                StartPoint = t0R,
                IsClosed   = true,
                IsFilled   = true
            };

            pathGeometry.Figures.Add(pathFigure);

            // Arc around smaller circle
            ArcSegment arc0Segment = new ArcSegment
            {
                Point          = t0L,
                Size           = new Size(r0, r0),
                SweepDirection = SweepDirection.Clockwise,
                IsLargeArc     = false
            };

            pathFigure.Segments.Add(arc0Segment);

            // Line connecting smaller circle to larger circle
            LineSegment lineSegment = new LineSegment
            {
                Point = t1L
            };

            pathFigure.Segments.Add(lineSegment);

            // Arc around larger circle
            ArcSegment arc1Segment = new ArcSegment
            {
                Point          = t1R,
                Size           = new Size(r1, r1),
                SweepDirection = SweepDirection.Clockwise,
                IsLargeArc     = true
            };

            pathFigure.Segments.Add(arc1Segment);

            return(pathGeometry);
        }
Esempio n. 25
0
 public void AddParticlesCone(int count, Vector2 position, Vector2 velocity, Vector4 color, float spread, float scale_multiplier = 1.0f)
 {
     for (int i = 0; i < count; ++i)
     {
         Vector2 p = position + (velocity * (float)Game.Instance.Random.NextDouble());
         Vector2 v = velocity + velocity.Rotate((float)Game.Instance.Random.NextDouble() * spread);
         AddParticle(p, v, color, scale_multiplier);
     }
 }
Esempio n. 26
0
    public void OnCastComplete()
    {
        float distanceFromFrontToMouse, distanceFromBackToMouse;

        CheckDistancesToMouse(out distanceFromFrontToMouse, out distanceFromBackToMouse);

        SoundManager.instance.PlayCombatSound("bow");

        var startPos = projectilePoint.transform.position;

        // create a direction vector from Hit position of the mouse and the projectiles original position
        Vector2 direction = new Vector2(mousePosition.x - startPos.x, mousePosition.y - startPos.y);

        direction.Normalize();

        // Determine the correct angle to turn the projectile
        float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;

        GameObject projectile = pooledArrows.GetPooledArrow();

        var projectileScript = projectile.GetComponent <Projectile>();

        projectileScript.PrepareProjectileState();

        projectile.transform.position   = projectilePoint.transform.position;
        projectile.transform.rotation   = Quaternion.identity;
        projectile.transform.localScale = new Vector3(1, 1, 1);


        projectile.transform.Rotate(0, 0, angle, Space.World);

        if (maxChargedHit)
        {
            //----------------------------------------------------------------

            GameObject projectile1 = pooledArrows.GetPooledArrow();

            var projectileScript1 = projectile1.GetComponent <Projectile>();

            projectileScript1.PrepareProjectileState();
            PositionAndTurnProjectile(angle, projectile1);

            //----------------------------------------------------------------

            GameObject projectile2 = pooledArrows.GetPooledArrow();

            var projectileScript2 = projectile2.GetComponent <Projectile>();
            projectileScript2.PrepareProjectileState();
            PositionAndTurnProjectile(angle, projectile2);

            // addforce force to the projectiles rigidbody in that direction.
            projectile.GetComponent <Rigidbody2D>().AddForce(direction * projectileSpeed);
            projectile1.GetComponent <Rigidbody2D>().AddForce(direction.Rotate(5f) * projectileSpeed);
            projectile2.GetComponent <Rigidbody2D>().AddForce(direction.Rotate(355f) * projectileSpeed);

            Instantiate(ParticleSystemHolder.instance.ChargedBowShot, projectile.transform);
            Instantiate(ParticleSystemHolder.instance.ChargedBowShot, projectile1.transform);
            Instantiate(ParticleSystemHolder.instance.ChargedBowShot, projectile2.transform);

            GameDetails.arrowsFired++;

            return;
        }

        // addforce force to the projectiles rigidbody in that direction.
        projectile.GetComponent <Rigidbody2D>().AddForce(direction * projectileSpeed);

        GameDetails.arrowsFired++;
    }
    //There's probably some formula for this but I couldn't think of one...
    public void CalculateAndDrawBezier(Vector2 current, Vector2 target, NodeJoint.NodeInfo jointInfo, NodeJoint.NodeInfo connectedJointInfo)
    {
        float dist = Vector2.Distance(current, target) / 2f;
        float currentDeg = 0, targetDeg = 0;

        switch (jointInfo)
        {
        case NodeJoint.NodeInfo.Top:
            if (connectedJointInfo == NodeJoint.NodeInfo.Top)
            {
                currentDeg = 270;
                targetDeg  = 90;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Bottom)
            {
                currentDeg = 270;
                targetDeg  = 270;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Left)
            {
                currentDeg = 270;
                targetDeg  = 0;
            }
            else
            {
                currentDeg = 270;
                targetDeg  = 180;
            }
            break;

        case NodeJoint.NodeInfo.Bottom:
            if (connectedJointInfo == NodeJoint.NodeInfo.Top)
            {
                currentDeg = 90;
                targetDeg  = 90;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Bottom)
            {
                currentDeg = 90;
                targetDeg  = 270;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Left)
            {
                currentDeg = 90;
                targetDeg  = 0;
            }
            else
            {
                currentDeg = 90;
                targetDeg  = 180;
            }
            break;

        case NodeJoint.NodeInfo.Left:
            if (connectedJointInfo == NodeJoint.NodeInfo.Top)
            {
                currentDeg = 180;
                targetDeg  = 90;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Bottom)
            {
                currentDeg = 180;
                targetDeg  = 270;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Left)
            {
                currentDeg = 180;
                targetDeg  = 0;
            }
            else
            {
                currentDeg = 180;
                targetDeg  = 180;
            }
            break;

        default:
            if (connectedJointInfo == NodeJoint.NodeInfo.Top)
            {
                currentDeg = 0;
                targetDeg  = 90;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Bottom)
            {
                currentDeg = 0;
                targetDeg  = 270;
            }
            else if (connectedJointInfo == NodeJoint.NodeInfo.Left)
            {
                currentDeg = 0;
                targetDeg  = 0;
            }
            else
            {
                currentDeg = 0;
                targetDeg  = 180;
            }
            break;
        }

        Vector2 currentTan = Vector2.zero;

        currentTan = currentTan.Rotate(current + Vector2.right * dist, current, Mathf.Deg2Rad * currentDeg);
        Vector2 targetTan = Vector2.zero;

        targetTan = targetTan.Rotate(target + Vector2.left * dist, target, Mathf.Deg2Rad * targetDeg);

        Handles.DrawBezier(current, target, currentTan, targetTan, Color.green, null, 5f);

        if (VisualNovelEditor.DrawTangents)
        {
            Handles.DrawBezier(current, currentTan, current, currentTan, Color.yellow, null, 3f);
            Handles.DrawBezier(target, targetTan, target, targetTan, Color.yellow, null, 3f);
        }
    }
Esempio n. 28
0
 /// <summary>
 /// Calculates the position of the particle's point taking into account rotation angle.
 /// </summary>
 /// <param name="particle"></param>
 /// <param name="point"></param>
 /// <remarks>This value is \f$\vec{R}\f$ in the math.</remarks>
 /// <returns></returns>
 private Vector2 PointRelativePosition(PhysicalParticle particle, Vector2 point)
 {
     return(point.Rotate(particle.Angle));
 }
Esempio n. 29
0
        private bool HandleToolAction(ToolId id)
        {
            switch (id)
            {
            case ToolId.Open:
                if (LoadFile())
                {
                    searchDlg.InitializeAutocomplete();
                    goto case ToolId.Home;
                }
                break;

            case ToolId.RotateCCW:
                Root.Renderer.Turn += Math.PI / 2;
                RedrawScene();
                break;

            case ToolId.RotateCW:
                Root.Renderer.Turn -= Math.PI / 2;
                RedrawScene();
                break;

            case ToolId.ChangeSide:
            {
                btnSide.ImageIndex = (btnSide.ImageIndex + 1) % 2;
                bool topSide = btnSide.ImageIndex == 0;
                Root.Scene.Side = topSide ? BoardSide.Top : BoardSide.Bottom;
                if (Root.Scene.TopContour != null)
                {
                    double yOffset = Root.Scene.TopContour.GetBBox().Height;
                    if (topSide)
                    {
                        yOffset *= -1;
                    }
                    var vec = new Vector2(0, yOffset);
                    vec.Rotate(Root.Renderer.Turn.Radians);
                    ApplyPan(vec, false);
                }
                break;
            }

            case ToolId.Home:
                var contour = Root.Scene.Side == BoardSide.Top ? Root.Scene.TopContour : Root.Scene.BottomContour;
                if (contour == null)
                {
                    break;
                }
                Root.Renderer.FitToScreenTransform(contour.GetBBox());
                RedrawScene();
                break;

            case ToolId.ToggleNames:
                btnNames.ImageIndex          = (btnNames.ImageIndex + 1) % 2;
                Root.Scene.Options.ShowNames = btnNames.ImageIndex == 0;
                RedrawScene();
                break;

            case ToolId.ToggleHeurShapes:
                btnHeurShapes.ImageIndex      = (btnHeurShapes.ImageIndex + 1) % 2;
                Root.Scene.Options.HeurShapes = btnHeurShapes.ImageIndex == 0;
                RedrawScene();
                break;

            // XXX: refactor copypasted code
            case ToolId.FindPart:
                searchDlg.Setup(QuerySubject.Part, 3, (string[] q, out bool found) =>
                {
                    Root.Scene.ResetSearchResults();
                    foreach (var query in q)
                    {
                        if (!string.IsNullOrEmpty(query))
                        {
                            var fp = Root.Scene.Parts.Find(p => string.Equals(p.Name, query, StringComparison.OrdinalIgnoreCase));
                            Root.Scene.UpdateSearchResults(fp);
                        }
                    }
                    found = Root.Scene.SearchResults.Count > 0;
                    if (found && Root.Scene.SearchResults.Find(obj => obj.Side == Root.Scene.Side) == null)
                    {
                        HandleToolAction(ToolId.ChangeSide);
                    }
                    else
                    {
                        RedrawScene();
                    }
                });
                searchDlg.ShowDialog(this);
                break;

            case ToolId.FindPin:
                searchDlg.Setup(QuerySubject.Pin, 1, (string[] q, out bool found) =>
                {
                    Root.Scene.ResetSearchResults();
                    found = false;
                    if (string.IsNullOrEmpty(q[0]))
                    {
                        return;
                    }
                    char[] splitChars = { '.' };
                    var sq            = q[0].Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
                    if (sq.Length != 2)
                    {
                        return;
                    }
                    var pin = int.Parse(sq[1]);
                    if (pin <= 0)
                    {
                        return;
                    }
                    var fp = Root.Scene.Parts.Find(p => string.Equals(p.Name, sq[0], StringComparison.OrdinalIgnoreCase));
                    if (fp == null)
                    {
                        return;
                    }
                    if (fp.PinCount < pin)
                    {
                        return;
                    }
                    Root.Scene.SearchResults.Add(fp);
                    Root.Scene.SearchResults.Add(Root.Scene.Pins[fp.FirstPin + pin - 1]);
                    found = true;
                    if (fp.HasSide && fp.Side != Root.Scene.Side)
                    {
                        HandleToolAction(ToolId.ChangeSide);
                    }
                    else
                    {
                        RedrawScene();
                    }
                    //Root.Renderer.FitToScreenTransform(fp.GetBBox());
                });
                searchDlg.ShowDialog(this);
                break;

            case ToolId.FindNet:
                searchDlg.Setup(QuerySubject.Net, 1, (string[] q, out bool found) =>
                {
                    Root.Scene.ResetSearchResults();
                    foreach (var query in q)
                    {
                        if (!string.IsNullOrEmpty(query))
                        {
                            var fp = Root.Scene.Pins.FindAll(p => string.Equals(p.Name, query, StringComparison.OrdinalIgnoreCase));
                            var fn = Root.Scene.Nails.FindAll(n => string.Equals(n.Name, query, StringComparison.OrdinalIgnoreCase));
                            foreach (var p in fp)
                            {
                                Root.Scene.UpdateSearchResults(p);
                            }
                            foreach (var n in fn)
                            {
                                Root.Scene.UpdateSearchResults(n);
                            }
                        }
                    }
                    found = Root.Scene.SearchResults.Count > 0;
                    if (found && Root.Scene.SearchResults.Find(obj => obj.Side == Root.Scene.Side) == null)
                    {
                        HandleToolAction(ToolId.ChangeSide);
                    }
                    else
                    {
                        RedrawScene();
                    }
                });
                searchDlg.ShowDialog(this);
                break;

            case ToolId.FindNail:
                searchDlg.Setup(QuerySubject.Nail, 3, (string[] q, out bool found) =>
                {
                    Root.Scene.ResetSearchResults();
                    foreach (var query in q)
                    {
                        if (!string.IsNullOrEmpty(query))
                        {
                            var fn = Root.Scene.Nails.FindAll(n => string.Equals(n.Name, query, StringComparison.OrdinalIgnoreCase));
                            foreach (var n in fn)
                            {
                                Root.Scene.UpdateSearchResults(n);
                            }
                        }
                    }
                    found = Root.Scene.SearchResults.Count > 0;
                    if (found && Root.Scene.SearchResults.Find(obj => obj.Side == Root.Scene.Side) == null)
                    {
                        HandleToolAction(ToolId.ChangeSide);
                    }
                    else
                    {
                        RedrawScene();
                    }
                });
                searchDlg.ShowDialog(this);
                break;

            case ToolId.ZoomIn:
                ApplyZoom(1);
                break;

            case ToolId.ZoomOut:
                ApplyZoom(-1);
                break;

            case ToolId.PanLeft:
                ApplyPan(new Vector2(+1, 0) * PanScale);
                break;

            case ToolId.PanRight:
                ApplyPan(new Vector2(-1, 0) * PanScale);
                break;

            case ToolId.PanUp:
                ApplyPan(new Vector2(0, -1) * PanScale);
                break;

            case ToolId.PanDown:
                ApplyPan(new Vector2(0, +1) * PanScale);
                break;

            case ToolId.About:
                if (aboutDlg.IsDisposed) // just in case...
                {
                    aboutDlg = new AboutDialog();
                }
                aboutDlg.ShowDialog(this);
                break;
            }
            return(true);
        }
Esempio n. 30
0
    //this.audios = audios;

    protected override void Shoot(ProjectilePool pool, Vector2 position, Vector2 direction)
    {
        pool.GetProjectile(this._transform.position, direction);
        pool.GetProjectile(this._transform.position, direction.Rotate(20f));
        pool.GetProjectile(this._transform.position, direction.Rotate(-20f));
    }
Esempio n. 31
0
		public void AI()
		{
			if(ServerApi.Hooks.InvokeProjectileAIUpdate(this))
			{
				return;
			}

			if (this.aiStyle == 1)
			{
				if (this.type == 323)
				{
					this.alpha -= 50;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 408)
				{
					this.alpha -= 40;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					this.spriteDirection = this.direction;
				}
				if (this.type == 282)
				{
					int num = Dust.NewDust(this.position, this.width, this.height, 171, 0f, 0f, 100, default(Color), 1f);
					Main.dust[num].scale = (float)Main.rand.Next(1, 10) * 0.1f;
					Main.dust[num].noGravity = true;
					Main.dust[num].fadeIn = 1.5f;
					Main.dust[num].velocity *= 0.25f;
					Main.dust[num].velocity += this.velocity * 0.25f;
				}
				if (this.type == 275 || this.type == 276)
				{
					this.frameCounter++;
					if (this.frameCounter > 1)
					{
						this.frameCounter = 0;
						this.frame++;
						if (this.frame > 1)
						{
							this.frame = 0;
						}
					}
				}
				if (this.type == 225)
				{
					int num2 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 40, 0f, 0f, 0, default(Color), 1f);
					Main.dust[num2].noGravity = true;
					Main.dust[num2].scale = 1.3f;
					Main.dust[num2].velocity *= 0.5f;
				}
				if (this.type == 174)
				{
					if (this.alpha == 0)
					{
						int num3 = Dust.NewDust(this.lastPosition - this.velocity * 3f, this.width, this.height, 76, 0f, 0f, 50, default(Color), 1f);
						Main.dust[num3].noGravity = true;
						Main.dust[num3].noLight = true;
						Main.dust[num3].velocity *= 0.5f;
					}
					this.alpha -= 50;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
					}
				}
				else if (this.type == 176)
				{
					if (this.alpha == 0)
					{
						int num4 = Dust.NewDust(this.lastPosition, this.width, this.height, 22, 0f, 0f, 100, default(Color), 0.5f);
						Main.dust[num4].noGravity = true;
						Main.dust[num4].noLight = true;
						Main.dust[num4].velocity *= 0.15f;
						Main.dust[num4].fadeIn = 0.8f;
					}
					this.alpha -= 50;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
					}
				}
				if (this.type == 350)
				{
					this.alpha -= 100;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					Lighting.addLight((int)this.center().X / 16, (int)this.center().Y / 16, 0.9f, 0.6f, 0.2f);
					if (this.alpha == 0)
					{
						int num5 = 2;
						if (Main.rand.Next(2) == 0)
						{
							int num6 = Dust.NewDust(new Vector2(this.center().X - (float)num5, this.center().Y - (float)num5 - 2f) - this.velocity * 0.5f, num5 * 2, num5 * 2, 6, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num6].scale *= 1.8f + (float)Main.rand.Next(10) * 0.1f;
							Main.dust[num6].velocity *= 0.2f;
							Main.dust[num6].noGravity = true;
						}
						if (Main.rand.Next(4) == 0)
						{
							int num7 = Dust.NewDust(new Vector2(this.center().X - (float)num5, this.center().Y - (float)num5 - 2f) - this.velocity * 0.5f, num5 * 2, num5 * 2, 31, 0f, 0f, 100, default(Color), 0.5f);
							Main.dust[num7].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f;
							Main.dust[num7].velocity *= 0.05f;
						}
					}
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 42);
					}
				}
				if (this.type == 325)
				{
					this.alpha -= 100;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					Lighting.addLight((int)this.center().X / 16, (int)this.center().Y / 16, 0.9f, 0.6f, 0.2f);
					if (this.alpha == 0)
					{
						int num8 = 2;
						if (Main.rand.Next(2) == 0)
						{
							int num9 = Dust.NewDust(new Vector2(this.center().X - (float)num8, this.center().Y - (float)num8 - 2f) - this.velocity * 0.5f, num8 * 2, num8 * 2, 6, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num9].scale *= 1.8f + (float)Main.rand.Next(10) * 0.1f;
							Main.dust[num9].velocity *= 0.2f;
							Main.dust[num9].noGravity = true;
						}
						if (Main.rand.Next(4) == 0)
						{
							int num10 = Dust.NewDust(new Vector2(this.center().X - (float)num8, this.center().Y - (float)num8 - 2f) - this.velocity * 0.5f, num8 * 2, num8 * 2, 31, 0f, 0f, 100, default(Color), 0.5f);
							Main.dust[num10].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f;
							Main.dust[num10].velocity *= 0.05f;
						}
					}
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 42);
					}
				}
				if (this.type == 83 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 33);
				}
				if (this.type == 408 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(4, (int)this.position.X, (int)this.position.Y, 19);
				}
				if (this.type == 259 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 33);
				}
				if (this.type == 110 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 11);
				}
				if (this.type == 302 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 11);
				}
				if (this.type == 84 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 12);
				}
				if (this.type == 389 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 12);
				}
				if (this.type == 257 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 12);
				}
				if (this.type == 100 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 33);
				}
				if (this.type == 98 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
				}
				if (this.type == 184 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
				}
				if (this.type == 195 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
				}
				if (this.type == 275 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
				}
				if (this.type == 276 && this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
				}
				if ((this.type == 81 || this.type == 82) && this.ai[1] == 0f)
				{
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 5);
					this.ai[1] = 1f;
				}
				if (this.type == 180 && this.ai[1] == 0f)
				{
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 11);
					this.ai[1] = 1f;
				}
				if (this.type == 248 && this.ai[1] == 0f)
				{
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
					this.ai[1] = 1f;
				}
				if (this.type == 41)
				{
					int num11 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1.6f);
					Main.dust[num11].noGravity = true;
					num11 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 2f);
					Main.dust[num11].noGravity = true;
				}
				else if (this.type == 55)
				{
					int num12 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 18, 0f, 0f, 0, default(Color), 0.9f);
					Main.dust[num12].noGravity = true;
				}
				else if (this.type == 374)
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
						this.localAI[0] = 1f;
					}
					if (Main.rand.Next(2) == 0)
					{
						int num13 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 18, 0f, 0f, 0, default(Color), 0.9f);
						Main.dust[num13].noGravity = true;
						Main.dust[num13].velocity *= 0.5f;
					}
				}
				else if (this.type == 376)
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 20);
					}
					this.localAI[0] += 1f;
					if (this.localAI[0] > 3f)
					{
						int num14 = 1;
						if (this.localAI[0] > 5f)
						{
							num14 = 2;
						}
						for (int i = 0; i < num14; i++)
						{
							int num15 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + 2f), this.width, this.height, 6, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 2f);
							Main.dust[num15].noGravity = true;
							Dust expr_109A_cp_0 = Main.dust[num15];
							expr_109A_cp_0.velocity.X = expr_109A_cp_0.velocity.X * 0.3f;
							Dust expr_10B8_cp_0 = Main.dust[num15];
							expr_10B8_cp_0.velocity.Y = expr_10B8_cp_0.velocity.Y * 0.3f;
							Main.dust[num15].noLight = true;
						}
						if (this.wet && !this.lavaWet)
						{
							this.Kill();
							return;
						}
					}
				}
				else if (this.type == 91 && Main.rand.Next(2) == 0)
				{
					int num16;
					if (Main.rand.Next(2) == 0)
					{
						num16 = 15;
					}
					else
					{
						num16 = 58;
					}
					int num17 = Dust.NewDust(this.position, this.width, this.height, num16, this.velocity.X * 0.25f, this.velocity.Y * 0.25f, 150, default(Color), 0.9f);
					Main.dust[num17].velocity *= 0.25f;
				}
				if (this.type == 163 || this.type == 310)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 25;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 20 || this.type == 14 || this.type == 36 || this.type == 83 || this.type == 84 || this.type == 389 || this.type == 89 || this.type == 100 || this.type == 104 || this.type == 110 || this.type == 180 || this.type == 279 || (this.type >= 158 && this.type <= 161) || (this.type >= 283 && this.type <= 287))
				{
					if (this.alpha > 0)
					{
						this.alpha -= 15;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 242 || this.type == 302)
				{
					float num18 = (float)Math.Sqrt((double)(this.velocity.X * this.velocity.X + this.velocity.Y * this.velocity.Y));
					if (this.alpha > 0)
					{
						this.alpha -= (int)((byte)((double)num18 * 0.9));
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 257)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 10;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 88)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 10;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type != 376 && this.type != 350 && this.type != 349 && this.type != 348 && this.type != 5 && this.type != 325 && this.type != 323 && this.type != 14 && this.type != 270 && this.type != 180 && this.type != 259 && this.type != 242 && this.type != 302 && this.type != 20 && this.type != 36 && this.type != 38 && this.type != 55 && this.type != 83 && this.type != 84 && this.type != 389 && this.type != 88 && this.type != 89 && this.type != 98 && this.type != 100 && this.type != 265 && this.type != 104 && this.type != 110 && this.type != 184 && this.type != 257 && this.type != 248 && (this.type < 283 || this.type > 287) && this.type != 279 && this.type != 299 && this.type != 355 && (this.type < 158 || this.type > 161) && this.type != 374)
				{
					this.ai[0] += 1f;
				}
				if (this.type == 349)
				{
					this.frame = (int)this.ai[0];
					this.velocity.Y = this.velocity.Y + 0.2f;
					if (this.localAI[0] == 0f || this.localAI[0] == 2f)
					{
						this.scale += 0.01f;
						this.alpha -= 50;
						if (this.alpha <= 0)
						{
							this.localAI[0] = 1f;
							this.alpha = 0;
						}
					}
					else if (this.localAI[0] == 1f)
					{
						this.scale -= 0.01f;
						this.alpha += 50;
						if (this.alpha >= 255)
						{
							this.localAI[0] = 2f;
							this.alpha = 255;
						}
					}
				}
				if (this.type == 348)
				{
					if (this.localAI[1] == 0f)
					{
						this.localAI[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
					}
					if (this.ai[0] == 0f || this.ai[0] == 2f)
					{
						this.scale += 0.01f;
						this.alpha -= 50;
						if (this.alpha <= 0)
						{
							this.ai[0] = 1f;
							this.alpha = 0;
						}
					}
					else if (this.ai[0] == 1f)
					{
						this.scale -= 0.01f;
						this.alpha += 50;
						if (this.alpha >= 255)
						{
							this.ai[0] = 2f;
							this.alpha = 255;
						}
					}
				}
				if (this.type == 299)
				{
					if (this.localAI[0] == 6f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
						for (int j = 0; j < 40; j++)
						{
							int num19 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 181, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num19].velocity *= 3f;
							Main.dust[num19].velocity += this.velocity * 0.75f;
							Main.dust[num19].scale *= 1.2f;
							Main.dust[num19].noGravity = true;
						}
					}
					this.localAI[0] += 1f;
					if (this.localAI[0] > 6f)
					{
						for (int k = 0; k < 3; k++)
						{
							int num20 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 181, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 1f);
							Main.dust[num20].velocity *= 0.6f;
							Main.dust[num20].scale *= 1.4f;
							Main.dust[num20].noGravity = true;
						}
					}
				}
				else if (this.type == 270)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 50;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					this.frame++;
					if (this.frame > 2)
					{
						this.frame = 0;
					}
					for (int l = 0; l < 2; l++)
					{
						int num21 = Dust.NewDust(new Vector2(this.position.X + 4f, this.position.Y + 4f), this.width - 8, this.height - 8, 6, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 2f);
						Main.dust[num21].position -= this.velocity * 2f;
						Main.dust[num21].noGravity = true;
						Dust expr_1B0E_cp_0 = Main.dust[num21];
						expr_1B0E_cp_0.velocity.X = expr_1B0E_cp_0.velocity.X * 0.3f;
						Dust expr_1B2C_cp_0 = Main.dust[num21];
						expr_1B2C_cp_0.velocity.Y = expr_1B2C_cp_0.velocity.Y * 0.3f;
					}
				}
				if (this.type == 259)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 10;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 265)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 50;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					if (this.alpha == 0)
					{
						int num22 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 163, this.velocity.X, this.velocity.Y, 100, default(Color), 1.2f);
						Main.dust[num22].noGravity = true;
						Main.dust[num22].velocity *= 0.3f;
						Main.dust[num22].velocity -= this.velocity * 0.4f;
					}
				}
				if (this.type == 355)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 50;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					if (this.alpha == 0)
					{
						int num23 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 205, this.velocity.X, this.velocity.Y, 100, default(Color), 1.2f);
						Main.dust[num23].noGravity = true;
						Main.dust[num23].velocity *= 0.3f;
						Main.dust[num23].velocity -= this.velocity * 0.4f;
					}
				}
				if (this.type == 357)
				{
					if (this.alpha < 170)
					{
						for (int m = 0; m < 10; m++)
						{
							float x = this.position.X - this.velocity.X / 10f * (float)m;
							float y = this.position.Y - this.velocity.Y / 10f * (float)m;
							int num24 = Dust.NewDust(new Vector2(x, y), 1, 1, 206, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num24].alpha = this.alpha;
							Main.dust[num24].position.X = x;
							Main.dust[num24].position.Y = y;
							Main.dust[num24].velocity *= 0f;
							Main.dust[num24].noGravity = true;
						}
					}
					if (this.alpha > 0)
					{
						this.alpha -= 25;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				else if (this.type == 207)
				{
					if (this.alpha < 170)
					{
						for (int n = 0; n < 10; n++)
						{
							float x2 = this.position.X - this.velocity.X / 10f * (float)n;
							float y2 = this.position.Y - this.velocity.Y / 10f * (float)n;
							int num25 = Dust.NewDust(new Vector2(x2, y2), 1, 1, 75, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num25].alpha = this.alpha;
							Main.dust[num25].position.X = x2;
							Main.dust[num25].position.Y = y2;
							Main.dust[num25].velocity *= 0f;
							Main.dust[num25].noGravity = true;
						}
					}
					float num26 = (float)Math.Sqrt((double)(this.velocity.X * this.velocity.X + this.velocity.Y * this.velocity.Y));
					float num27 = this.localAI[0];
					if (num27 == 0f)
					{
						this.localAI[0] = num26;
						num27 = num26;
					}
					if (this.alpha > 0)
					{
						this.alpha -= 25;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					float num28 = this.position.X;
					float num29 = this.position.Y;
					float num30 = 300f;
					bool flag = false;
					int num31 = 0;
					if (this.ai[1] == 0f)
					{
						for (int num32 = 0; num32 < 200; num32++)
						{
							if (Main.npc[num32].active && !Main.npc[num32].dontTakeDamage && !Main.npc[num32].friendly && Main.npc[num32].lifeMax > 5 && (this.ai[1] == 0f || this.ai[1] == (float)(num32 + 1)))
							{
								float num33 = Main.npc[num32].position.X + (float)(Main.npc[num32].width / 2);
								float num34 = Main.npc[num32].position.Y + (float)(Main.npc[num32].height / 2);
								float num35 = Math.Abs(this.position.X + (float)(this.width / 2) - num33) + Math.Abs(this.position.Y + (float)(this.height / 2) - num34);
								if (num35 < num30 && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num32].position, Main.npc[num32].width, Main.npc[num32].height))
								{
									num30 = num35;
									num28 = num33;
									num29 = num34;
									flag = true;
									num31 = num32;
								}
							}
						}
						if (flag)
						{
							this.ai[1] = (float)(num31 + 1);
						}
						flag = false;
					}
					if (this.ai[1] != 0f)
					{
						int num36 = (int)(this.ai[1] - 1f);
						if (Main.npc[num36].active)
						{
							float num37 = Main.npc[num36].position.X + (float)(Main.npc[num36].width / 2);
							float num38 = Main.npc[num36].position.Y + (float)(Main.npc[num36].height / 2);
							float num39 = Math.Abs(this.position.X + (float)(this.width / 2) - num37) + Math.Abs(this.position.Y + (float)(this.height / 2) - num38);
							if (num39 < 1000f)
							{
								flag = true;
								num28 = Main.npc[num36].position.X + (float)(Main.npc[num36].width / 2);
								num29 = Main.npc[num36].position.Y + (float)(Main.npc[num36].height / 2);
							}
						}
					}
					if (flag)
					{
						float num40 = num27;
						Vector2 vector = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num41 = num28 - vector.X;
						float num42 = num29 - vector.Y;
						float num43 = (float)Math.Sqrt((double)(num41 * num41 + num42 * num42));
						num43 = num40 / num43;
						num41 *= num43;
						num42 *= num43;
						int num44 = 8;
						this.velocity.X = (this.velocity.X * (float)(num44 - 1) + num41) / (float)num44;
						this.velocity.Y = (this.velocity.Y * (float)(num44 - 1) + num42) / (float)num44;
					}
				}
				else if (this.type == 81 || this.type == 91)
				{
					if (this.ai[0] >= 20f)
					{
						this.ai[0] = 20f;
						this.velocity.Y = this.velocity.Y + 0.07f;
					}
				}
				else if (this.type == 174)
				{
					if (this.ai[0] >= 5f)
					{
						this.ai[0] = 5f;
						this.velocity.Y = this.velocity.Y + 0.15f;
					}
				}
				else if (this.type == 337)
				{
					if (this.position.Y > Main.player[this.owner].position.Y - 300f)
					{
						this.tileCollide = true;
					}
					if ((double)this.position.Y < Main.worldSurface * 16.0)
					{
						this.tileCollide = true;
					}
					this.frame = (int)this.ai[1];
					if (Main.rand.Next(2) == 0)
					{
						int num45 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 197, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num45].velocity *= 0.5f;
						Main.dust[num45].noGravity = true;
					}
				}
				else if (this.type == 344)
				{
					this.localAI[1] += 1f;
					if (this.localAI[1] > 5f)
					{
						this.alpha -= 50;
						if (this.alpha < 0)
						{
							this.alpha = 0;
						}
					}
					this.frame = (int)this.ai[1];
					if (this.localAI[1] > 20f)
					{
						this.localAI[1] = 20f;
						this.velocity.Y = this.velocity.Y + 0.15f;
					}
					this.rotation += Main.windSpeed * 0.2f;
					this.velocity.X = this.velocity.X + Main.windSpeed * 0.1f;
				}
				else if (this.type == 336 || this.type == 345)
				{
					if (this.type == 345 && this.localAI[0] == 0f)
					{
						this.localAI[0] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 1);
					}
					if (this.ai[0] >= 50f)
					{
						this.ai[0] = 50f;
						this.velocity.Y = this.velocity.Y + 0.5f;
					}
				}
				else if (this.type == 246)
				{
					this.alpha -= 20;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					if (this.ai[0] >= 60f)
					{
						this.ai[0] = 60f;
						this.velocity.Y = this.velocity.Y + 0.15f;
					}
				}
				else if (this.type == 311)
				{
					if (this.alpha > 0)
					{
						this.alpha -= 50;
					}
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					if (this.ai[0] >= 30f)
					{
						this.ai[0] = 30f;
						if (this.ai[1] == 0f)
						{
							this.ai[1] = 1f;
						}
						this.velocity.Y = this.velocity.Y + 0.5f;
					}
				}
				else if (this.type == 312)
				{
					if (this.ai[0] >= 5f)
					{
						this.alpha = 0;
					}
					if (this.ai[0] >= 20f)
					{
						this.ai[0] = 30f;
						this.velocity.Y = this.velocity.Y + 0.5f;
					}
				}
				else if (this.type != 239 && this.type != 264)
				{
					if (this.type == 176)
					{
						if (this.ai[0] >= 15f)
						{
							this.ai[0] = 15f;
							this.velocity.Y = this.velocity.Y + 0.05f;
						}
					}
					else if (this.type == 275 || this.type == 276)
					{
						if (this.alpha > 0)
						{
							this.alpha -= 30;
						}
						if (this.alpha < 0)
						{
							this.alpha = 0;
						}
						if (this.ai[0] >= 35f)
						{
							this.ai[0] = 35f;
							this.velocity.Y = this.velocity.Y + 0.025f;
						}
					}
					else if (this.type == 172)
					{
						if (this.ai[0] >= 17f)
						{
							this.ai[0] = 17f;
							this.velocity.Y = this.velocity.Y + 0.085f;
						}
					}
					else if (this.type == 117)
					{
						if (this.ai[0] >= 35f)
						{
							this.ai[0] = 35f;
							this.velocity.Y = this.velocity.Y + 0.06f;
						}
					}
					else if (this.type == 120)
					{
						int num46 = Dust.NewDust(new Vector2(this.position.X - this.velocity.X, this.position.Y - this.velocity.Y), this.width, this.height, 67, this.velocity.X, this.velocity.Y, 100, default(Color), 1.2f);
						Main.dust[num46].noGravity = true;
						Main.dust[num46].velocity *= 0.3f;
						if (this.ai[0] >= 30f)
						{
							this.ai[0] = 30f;
							this.velocity.Y = this.velocity.Y + 0.05f;
						}
					}
					else if (this.type == 195)
					{
						if (this.ai[0] >= 20f)
						{
							this.ai[0] = 20f;
							this.velocity.Y = this.velocity.Y + 0.075f;
						}
					}
					else if (this.type == 267)
					{
						this.localAI[0] += 1f;
						if (this.localAI[0] > 3f)
						{
							this.alpha = 0;
						}
						if (this.ai[0] >= 20f)
						{
							this.ai[0] = 20f;
							this.velocity.Y = this.velocity.Y + 0.075f;
						}
					}
					else if (this.type == 408)
					{
						if (this.ai[0] >= 45f)
						{
							this.ai[0] = 45f;
							this.velocity.Y = this.velocity.Y + 0.05f;
						}
					}
					else if (this.ai[0] >= 15f)
					{
						this.ai[0] = 15f;
						this.velocity.Y = this.velocity.Y + 0.1f;
					}
				}
				if (this.type == 248)
				{
					if (this.velocity.X < 0f)
					{
						this.rotation -= (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.05f;
					}
					else
					{
						this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.05f;
					}
				}
				if (this.type == 270)
				{
					this.spriteDirection = this.direction;
					if (this.direction < 0)
					{
						this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
					}
					else
					{
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
					}
				}
				else if (this.type == 311)
				{
					if (this.ai[1] != 0f)
					{
						this.rotation += this.velocity.X * 0.1f + (float)Main.rand.Next(-10, 11) * 0.025f;
					}
					else
					{
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
					}
				}
				else if (this.type == 312)
				{
					this.rotation += this.velocity.X * 0.02f;
				}
				else if (this.type == 408)
				{
					this.rotation = this.velocity.ToRotation();
					if (this.direction == -1)
					{
						this.rotation += 3.14159274f;
					}
				}
				else if (this.type != 344)
				{
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
				}
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
			}
			else if (this.aiStyle == 2)
			{
				if (this.type == 93 && Main.rand.Next(5) == 0)
				{
					int num47 = Dust.NewDust(this.position, this.width, this.height, 57, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 0.3f);
					Dust expr_2EC9_cp_0 = Main.dust[num47];
					expr_2EC9_cp_0.velocity.X = expr_2EC9_cp_0.velocity.X * 0.3f;
					Dust expr_2EE7_cp_0 = Main.dust[num47];
					expr_2EE7_cp_0.velocity.Y = expr_2EE7_cp_0.velocity.Y * 0.3f;
				}
				if (this.type == 304 && this.localAI[0] == 0f)
				{
					this.localAI[0] += 1f;
					this.alpha = 0;
				}
				if (this.type == 335)
				{
					this.frame = (int)this.ai[1];
				}
				this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.03f * (float)this.direction;
				if (this.type == 162)
				{
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 14);
					}
					this.ai[0] += 1f;
					if (this.ai[0] >= 18f)
					{
						this.velocity.Y = this.velocity.Y + 0.28f;
						this.velocity.X = this.velocity.X * 0.99f;
					}
					if (this.ai[0] > 2f)
					{
						this.alpha = 0;
						if (this.ai[0] == 3f)
						{
							for (int num48 = 0; num48 < 10; num48++)
							{
								int num49 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1.5f);
								Main.dust[num49].velocity *= 0.5f;
								Main.dust[num49].velocity += this.velocity * 0.1f;
							}
							for (int num50 = 0; num50 < 5; num50++)
							{
								int num51 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 2f);
								Main.dust[num51].noGravity = true;
								Main.dust[num51].velocity *= 3f;
								Main.dust[num51].velocity += this.velocity * 0.2f;
								num51 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num51].velocity *= 2f;
								Main.dust[num51].velocity += this.velocity * 0.3f;
							}
							for (int num52 = 0; num52 < 1; num52++)
							{
								int num53 = Gore.NewGore(new Vector2(this.position.X - 10f, this.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
								Main.gore[num53].position += this.velocity * 1.25f;
								Main.gore[num53].scale = 1.5f;
								Main.gore[num53].velocity += this.velocity * 0.5f;
								Main.gore[num53].velocity *= 0.02f;
							}
						}
					}
				}
				else if (this.type == 281)
				{
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 14);
					}
					this.ai[0] += 1f;
					if (this.ai[0] >= 18f)
					{
						this.velocity.Y = this.velocity.Y + 0.28f;
						this.velocity.X = this.velocity.X * 0.99f;
					}
					if (this.ai[0] > 2f)
					{
						this.alpha = 0;
						if (this.ai[0] == 3f)
						{
							for (int num54 = 0; num54 < 10; num54++)
							{
								int num55 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1.5f);
								Main.dust[num55].velocity *= 0.5f;
								Main.dust[num55].velocity += this.velocity * 0.1f;
							}
							for (int num56 = 0; num56 < 5; num56++)
							{
								int num57 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 2f);
								Main.dust[num57].noGravity = true;
								Main.dust[num57].velocity *= 3f;
								Main.dust[num57].velocity += this.velocity * 0.2f;
								num57 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num57].velocity *= 2f;
								Main.dust[num57].velocity += this.velocity * 0.3f;
							}
							for (int num58 = 0; num58 < 1; num58++)
							{
								int num59 = Gore.NewGore(new Vector2(this.position.X - 10f, this.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
								Main.gore[num59].position += this.velocity * 1.25f;
								Main.gore[num59].scale = 1.5f;
								Main.gore[num59].velocity += this.velocity * 0.5f;
								Main.gore[num59].velocity *= 0.02f;
							}
						}
					}
				}
				else if (this.type == 240)
				{
					if (this.ai[1] == 0f)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 14);
					}
					this.ai[0] += 1f;
					if (this.ai[0] >= 16f)
					{
						this.velocity.Y = this.velocity.Y + 0.18f;
						this.velocity.X = this.velocity.X * 0.991f;
					}
					if (this.ai[0] > 2f)
					{
						this.alpha = 0;
						if (this.ai[0] == 3f)
						{
							for (int num60 = 0; num60 < 7; num60++)
							{
								int num61 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1.5f);
								Main.dust[num61].velocity *= 0.5f;
								Main.dust[num61].velocity += this.velocity * 0.1f;
							}
							for (int num62 = 0; num62 < 3; num62++)
							{
								int num63 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 2f);
								Main.dust[num63].noGravity = true;
								Main.dust[num63].velocity *= 3f;
								Main.dust[num63].velocity += this.velocity * 0.2f;
								num63 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num63].velocity *= 2f;
								Main.dust[num63].velocity += this.velocity * 0.3f;
							}
							for (int num64 = 0; num64 < 1; num64++)
							{
								int num65 = Gore.NewGore(new Vector2(this.position.X - 10f, this.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
								Main.gore[num65].position += this.velocity * 1.25f;
								Main.gore[num65].scale = 1.25f;
								Main.gore[num65].velocity += this.velocity * 0.5f;
								Main.gore[num65].velocity *= 0.02f;
							}
						}
					}
				}
				else if (this.type == 249)
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 0f)
					{
						this.velocity.Y = this.velocity.Y + 0.25f;
					}
				}
				else if (this.type == 347)
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 5f)
					{
						this.velocity.Y = this.velocity.Y + 0.25f;
					}
				}
				else if (this.type == 69 || this.type == 70)
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 10f)
					{
						this.velocity.Y = this.velocity.Y + 0.25f;
						this.velocity.X = this.velocity.X * 0.99f;
					}
				}
				else if (this.type == 166)
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 20f)
					{
						this.velocity.Y = this.velocity.Y + 0.3f;
						this.velocity.X = this.velocity.X * 0.98f;
					}
				}
				else if (this.type == 300)
				{
					if (this.ai[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 1);
					}
					this.ai[0] += 1f;
					if (this.ai[0] >= 60f)
					{
						this.velocity.Y = this.velocity.Y + 0.2f;
						this.velocity.X = this.velocity.X * 0.99f;
					}
				}
				else if (this.type == 306)
				{
					if (this.alpha <= 200)
					{
						for (int num66 = 0; num66 < 4; num66++)
						{
							float num67 = this.velocity.X / 4f * (float)num66;
							float num68 = this.velocity.Y / 4f * (float)num66;
							int num69 = Dust.NewDust(this.position, this.width, this.height, 184, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num69].position.X = this.center().X - num67;
							Main.dust[num69].position.Y = this.center().Y - num68;
							Main.dust[num69].velocity *= 0f;
							Main.dust[num69].scale = 0.7f;
						}
					}
					this.alpha -= 50;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 0.785f;
				}
				else if (this.type == 304)
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 30f)
					{
						this.alpha += 10;
						this.damage = (int)((double)this.damage * 0.9);
						this.knockBack = (float)((int)((double)this.knockBack * 0.9));
						if (this.alpha >= 255)
						{
							this.active = false;
						}
					}
					if (this.ai[0] < 30f)
					{
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
					}
				}
				else if (this.type == 370 || this.type == 371)
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 15f)
					{
						this.velocity.Y = this.velocity.Y + 0.3f;
						this.velocity.X = this.velocity.X * 0.98f;
					}
				}
				else
				{
					this.ai[0] += 1f;
					if (this.ai[0] >= 20f)
					{
						this.velocity.Y = this.velocity.Y + 0.4f;
						this.velocity.X = this.velocity.X * 0.97f;
					}
					else if (this.type == 48 || this.type == 54 || this.type == 93)
					{
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
					}
				}
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
				if (this.type == 54 && Main.rand.Next(20) == 0)
				{
					Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 40, this.velocity.X * 0.1f, this.velocity.Y * 0.1f, 0, default(Color), 0.75f);
				}
			}
			else if (this.aiStyle == 3)
			{
				if (this.soundDelay == 0 && this.type != 383)
				{
					this.soundDelay = 8;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 7);
				}
				if (this.type == 19)
				{
					for (int num70 = 0; num70 < 2; num70++)
					{
						int num71 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 2f);
						Main.dust[num71].noGravity = true;
						Dust expr_41A6_cp_0 = Main.dust[num71];
						expr_41A6_cp_0.velocity.X = expr_41A6_cp_0.velocity.X * 0.3f;
						Dust expr_41C4_cp_0 = Main.dust[num71];
						expr_41C4_cp_0.velocity.Y = expr_41C4_cp_0.velocity.Y * 0.3f;
					}
				}
				else if (this.type == 33)
				{
					if (Main.rand.Next(1) == 0)
					{
						int num72 = Dust.NewDust(this.position, this.width, this.height, 40, this.velocity.X * 0.25f, this.velocity.Y * 0.25f, 0, default(Color), 1.4f);
						Main.dust[num72].noGravity = true;
					}
				}
				else if (this.type == 320)
				{
					if (Main.rand.Next(3) == 0)
					{
						int num73 = Dust.NewDust(this.position, this.width, this.height, 5, this.velocity.X * 0.25f, this.velocity.Y * 0.25f, 0, default(Color), 1.1f);
						if (Main.rand.Next(2) == 0)
						{
							Main.dust[num73].scale = 0.9f;
							Main.dust[num73].velocity *= 0.2f;
						}
						else
						{
							Main.dust[num73].noGravity = true;
						}
					}
				}
				else if (this.type == 6)
				{
					if (Main.rand.Next(5) == 0)
					{
						int num74 = Main.rand.Next(3);
						if (num74 == 0)
						{
							num74 = 15;
						}
						else if (num74 == 1)
						{
							num74 = 57;
						}
						else
						{
							num74 = 58;
						}
						Dust.NewDust(this.position, this.width, this.height, num74, this.velocity.X * 0.25f, this.velocity.Y * 0.25f, 150, default(Color), 0.7f);
					}
				}
				else if (this.type == 113 && Main.rand.Next(1) == 0)
				{
					int num75 = Dust.NewDust(this.position, this.width, this.height, 76, this.velocity.X * 0.15f, this.velocity.Y * 0.15f, 0, default(Color), 1.1f);
					Main.dust[num75].noGravity = true;
					Dust.NewDust(this.position, this.width, this.height, 15, this.velocity.X * 0.05f, this.velocity.Y * 0.05f, 150, default(Color), 0.6f);
				}
				if (this.ai[0] == 0f)
				{
					this.ai[1] += 1f;
					if (this.type == 106 && this.ai[1] >= 45f)
					{
						this.ai[0] = 1f;
						this.ai[1] = 0f;
						this.netUpdate = true;
					}
					if (this.type == 320 || this.type == 383)
					{
						if (this.ai[1] >= 10f)
						{
							this.velocity.Y = this.velocity.Y + 0.5f;
							if (this.type == 383 && this.velocity.Y < 0f)
							{
								this.velocity.Y = this.velocity.Y + 0.35f;
							}
							this.velocity.X = this.velocity.X * 0.95f;
							if (this.velocity.Y > 16f)
							{
								this.velocity.Y = 16f;
							}
							if (this.type == 383 && Vector2.Distance(this.center(), Main.player[this.owner].center()) > 800f)
							{
								this.ai[0] = 1f;
							}
						}
					}
					else if (this.type == 182)
					{
						if (Main.rand.Next(2) == 0)
						{
							int num76 = Dust.NewDust(this.position, this.width, this.height, 57, 0f, 0f, 255, default(Color), 0.75f);
							Main.dust[num76].velocity *= 0.1f;
							Main.dust[num76].noGravity = true;
						}
						if (this.velocity.X > 0f)
						{
							this.spriteDirection = 1;
						}
						else if (this.velocity.X < 0f)
						{
							this.spriteDirection = -1;
						}
						float num77 = this.position.X;
						float num78 = this.position.Y;
						bool flag2 = false;
						if (this.ai[1] > 10f)
						{
							for (int num79 = 0; num79 < 200; num79++)
							{
								if (Main.npc[num79].active && !Main.npc[num79].dontTakeDamage && !Main.npc[num79].friendly && Main.npc[num79].lifeMax > 5)
								{
									float num80 = Main.npc[num79].position.X + (float)(Main.npc[num79].width / 2);
									float num81 = Main.npc[num79].position.Y + (float)(Main.npc[num79].height / 2);
									float num82 = Math.Abs(this.position.X + (float)(this.width / 2) - num80) + Math.Abs(this.position.Y + (float)(this.height / 2) - num81);
									if (num82 < 800f && Collision.CanHit(new Vector2(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2)), 1, 1, Main.npc[num79].position, Main.npc[num79].width, Main.npc[num79].height))
									{
										num77 = num80;
										num78 = num81;
										flag2 = true;
									}
								}
							}
						}
						if (!flag2)
						{
							num77 = this.position.X + (float)(this.width / 2) + this.velocity.X * 100f;
							num78 = this.position.Y + (float)(this.height / 2) + this.velocity.Y * 100f;
							if (this.ai[1] >= 30f)
							{
								this.ai[0] = 1f;
								this.ai[1] = 0f;
								this.netUpdate = true;
							}
						}
						float num83 = 12f;
						float num84 = 0.25f;
						Vector2 vector2 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num85 = num77 - vector2.X;
						float num86 = num78 - vector2.Y;
						float num87 = (float)Math.Sqrt((double)(num85 * num85 + num86 * num86));
						num87 = num83 / num87;
						num85 *= num87;
						num86 *= num87;
						if (this.velocity.X < num85)
						{
							this.velocity.X = this.velocity.X + num84;
							if (this.velocity.X < 0f && num85 > 0f)
							{
								this.velocity.X = this.velocity.X + num84 * 2f;
							}
						}
						else if (this.velocity.X > num85)
						{
							this.velocity.X = this.velocity.X - num84;
							if (this.velocity.X > 0f && num85 < 0f)
							{
								this.velocity.X = this.velocity.X - num84 * 2f;
							}
						}
						if (this.velocity.Y < num86)
						{
							this.velocity.Y = this.velocity.Y + num84;
							if (this.velocity.Y < 0f && num86 > 0f)
							{
								this.velocity.Y = this.velocity.Y + num84 * 2f;
							}
						}
						else if (this.velocity.Y > num86)
						{
							this.velocity.Y = this.velocity.Y - num84;
							if (this.velocity.Y > 0f && num86 < 0f)
							{
								this.velocity.Y = this.velocity.Y - num84 * 2f;
							}
						}
					}
					else if (this.type == 301)
					{
						if (this.ai[1] >= 20f)
						{
							this.ai[0] = 1f;
							this.ai[1] = 0f;
							this.netUpdate = true;
						}
					}
					else if (this.ai[1] >= 30f)
					{
						this.ai[0] = 1f;
						this.ai[1] = 0f;
						this.netUpdate = true;
					}
				}
				else
				{
					this.tileCollide = false;
					float num88 = 9f;
					float num89 = 0.4f;
					if (this.type == 19)
					{
						num88 = 13f;
						num89 = 0.6f;
					}
					else if (this.type == 33)
					{
						num88 = 15f;
						num89 = 0.8f;
					}
					else if (this.type == 182)
					{
						num88 = 16f;
						num89 = 1.2f;
					}
					else if (this.type == 106)
					{
						num88 = 16f;
						num89 = 1.2f;
					}
					else if (this.type == 272)
					{
						num88 = 15f;
						num89 = 1f;
					}
					else if (this.type == 333)
					{
						num88 = 12f;
						num89 = 0.6f;
					}
					else if (this.type == 301)
					{
						num88 = 15f;
						num89 = 3f;
					}
					else if (this.type == 320)
					{
						num88 = 15f;
						num89 = 3f;
					}
					else if (this.type == 383)
					{
						num88 = 16f;
						num89 = 4f;
					}
					Vector2 vector3 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num90 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector3.X;
					float num91 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector3.Y;
					float num92 = (float)Math.Sqrt((double)(num90 * num90 + num91 * num91));
					if (num92 > 3000f)
					{
						this.Kill();
					}
					num92 = num88 / num92;
					num90 *= num92;
					num91 *= num92;
					if (this.type == 383)
					{
						Vector2 vector4 = new Vector2(num90, num91) - this.velocity;
						if (vector4 != Vector2.Zero)
						{
							Vector2 value = vector4;
							value.Normalize();
							this.velocity += value * Math.Min(num89, vector4.Length());
						}
					}
					else if (this.velocity.X < num90)
					{
						this.velocity.X = this.velocity.X + num89;
						if (this.velocity.X < 0f && num90 > 0f)
						{
							this.velocity.X = this.velocity.X + num89;
						}
					}
					else if (this.velocity.X > num90)
					{
						this.velocity.X = this.velocity.X - num89;
						if (this.velocity.X > 0f && num90 < 0f)
						{
							this.velocity.X = this.velocity.X - num89;
						}
					}
					if (this.velocity.Y < num91)
					{
						this.velocity.Y = this.velocity.Y + num89;
						if (this.velocity.Y < 0f && num91 > 0f)
						{
							this.velocity.Y = this.velocity.Y + num89;
						}
					}
					else if (this.velocity.Y > num91)
					{
						this.velocity.Y = this.velocity.Y - num89;
						if (this.velocity.Y > 0f && num91 < 0f)
						{
							this.velocity.Y = this.velocity.Y - num89;
						}
					}
					if (Main.myPlayer == this.owner)
					{
						Rectangle rectangle = new Rectangle((int)this.position.X, (int)this.position.Y, this.width, this.height);
						Rectangle value2 = new Rectangle((int)Main.player[this.owner].position.X, (int)Main.player[this.owner].position.Y, Main.player[this.owner].width, Main.player[this.owner].height);
						if (rectangle.Intersects(value2))
						{
							this.Kill();
						}
					}
				}
				if (this.type == 106)
				{
					this.rotation += 0.3f * (float)this.direction;
				}
				else if (this.type == 383)
				{
					if (this.ai[0] == 0f)
					{
						Vector2 vector5 = this.velocity;
						vector5.Normalize();
						this.rotation = (float)Math.Atan2((double)vector5.Y, (double)vector5.X) + 1.57f;
					}
					else
					{
						Vector2 vector6 = this.center() - Main.player[this.owner].center();
						vector6.Normalize();
						this.rotation = (float)Math.Atan2((double)vector6.Y, (double)vector6.X) + 1.57f;
					}
				}
				else
				{
					this.rotation += 0.4f * (float)this.direction;
				}
			}
			else if (this.aiStyle == 4)
			{
				this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
				if (this.ai[0] == 0f)
				{
					if (this.type >= 150 && this.type <= 152 && this.ai[1] == 0f && this.alpha == 255 && Main.rand.Next(2) == 0)
					{
						this.type++;
						this.netUpdate = true;
					}
					this.alpha -= 50;
					if (this.type >= 150 && this.type <= 152)
					{
						this.alpha -= 25;
					}
					if (this.alpha <= 0)
					{
						this.alpha = 0;
						this.ai[0] = 1f;
						if (this.ai[1] == 0f)
						{
							this.ai[1] += 1f;
							this.position += this.velocity * 1f;
						}
						if (this.type == 7 && Main.myPlayer == this.owner)
						{
							int num93 = this.type;
							if (this.ai[1] >= 6f)
							{
								num93++;
							}
							int num94 = Projectile.NewProjectile(this.position.X + this.velocity.X + (float)(this.width / 2), this.position.Y + this.velocity.Y + (float)(this.height / 2), this.velocity.X, this.velocity.Y, num93, this.damage, this.knockBack, this.owner, 0f, 0f);
							Main.projectile[num94].damage = this.damage;
							Main.projectile[num94].ai[1] = this.ai[1] + 1f;
							NetMessage.SendData(27, -1, -1, "", num94, 0f, 0f, 0f, 0);
						}
						else if ((this.type == 150 || this.type == 151) && Main.myPlayer == this.owner)
						{
							int num95 = this.type;
							if (this.type == 150)
							{
								num95 = 151;
							}
							else if (this.type == 151)
							{
								num95 = 150;
							}
							if (this.ai[1] >= 10f && this.type == 151)
							{
								num95 = 152;
							}
							int num96 = Projectile.NewProjectile(this.position.X + this.velocity.X + (float)(this.width / 2), this.position.Y + this.velocity.Y + (float)(this.height / 2), this.velocity.X, this.velocity.Y, num95, this.damage, this.knockBack, this.owner, 0f, 0f);
							Main.projectile[num96].damage = this.damage;
							Main.projectile[num96].ai[1] = this.ai[1] + 1f;
							NetMessage.SendData(27, -1, -1, "", num96, 0f, 0f, 0f, 0);
						}
					}
				}
				else
				{
					if (this.alpha < 170 && this.alpha + 5 >= 170)
					{
						if (this.type >= 150 && this.type <= 152)
						{
							for (int num97 = 0; num97 < 8; num97++)
							{
								int num98 = Dust.NewDust(this.position, this.width, this.height, 7, this.velocity.X * 0.025f, this.velocity.Y * 0.025f, 200, default(Color), 1.3f);
								Main.dust[num98].noGravity = true;
								Main.dust[num98].velocity *= 0.5f;
							}
						}
						else
						{
							for (int num99 = 0; num99 < 3; num99++)
							{
								Dust.NewDust(this.position, this.width, this.height, 18, this.velocity.X * 0.025f, this.velocity.Y * 0.025f, 170, default(Color), 1.2f);
							}
							Dust.NewDust(this.position, this.width, this.height, 14, 0f, 0f, 170, default(Color), 1.1f);
						}
					}
					if (this.type >= 150 && this.type <= 152)
					{
						this.alpha += 3;
					}
					else
					{
						this.alpha += 5;
					}
					if (this.alpha >= 255)
					{
						this.Kill();
					}
				}
			}
			else if (this.aiStyle == 5)
			{
				if (this.type == 92)
				{
					if (this.position.Y > this.ai[1])
					{
						this.tileCollide = true;
					}
				}
				else
				{
					if (this.ai[1] == 0f && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[1] = 1f;
						this.netUpdate = true;
					}
					if (this.ai[1] != 0f)
					{
						this.tileCollide = true;
					}
				}
				if (this.soundDelay == 0)
				{
					this.soundDelay = 20 + Main.rand.Next(40);
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 9);
				}
				if (this.localAI[0] == 0f)
				{
					this.localAI[0] = 1f;
				}
				this.alpha += (int)(25f * this.localAI[0]);
				if (this.alpha > 200)
				{
					this.alpha = 200;
					this.localAI[0] = -1f;
				}
				if (this.alpha < 0)
				{
					this.alpha = 0;
					this.localAI[0] = 1f;
				}
				this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.01f * (float)this.direction;
				if (this.ai[1] == 1f || this.type == 92)
				{
					this.light = 0.9f;
					if (Main.rand.Next(10) == 0)
					{
						Dust.NewDust(this.position, this.width, this.height, 58, this.velocity.X * 0.5f, this.velocity.Y * 0.5f, 150, default(Color), 1.2f);
					}
					if (Main.rand.Next(20) == 0)
					{
						Gore.NewGore(this.position, new Vector2(this.velocity.X * 0.2f, this.velocity.Y * 0.2f), Main.rand.Next(16, 18), 1f);
					}
				}
			}
			else if (this.aiStyle == 6)
			{
				this.velocity *= 0.95f;
				this.ai[0] += 1f;
				if (this.ai[0] == 180f)
				{
					this.Kill();
				}
				if (this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					for (int num100 = 0; num100 < 30; num100++)
					{
						Dust.NewDust(this.position, this.width, this.height, 10 + this.type, this.velocity.X, this.velocity.Y, 50, default(Color), 1f);
					}
				}
				if (this.type == 10 || this.type == 11)
				{
					int num101 = (int)(this.position.X / 16f) - 1;
					int num102 = (int)((this.position.X + (float)this.width) / 16f) + 2;
					int num103 = (int)(this.position.Y / 16f) - 1;
					int num104 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
					if (num101 < 0)
					{
						num101 = 0;
					}
					if (num102 > Main.maxTilesX)
					{
						num102 = Main.maxTilesX;
					}
					if (num103 < 0)
					{
						num103 = 0;
					}
					if (num104 > Main.maxTilesY)
					{
						num104 = Main.maxTilesY;
					}
					for (int num105 = num101; num105 < num102; num105++)
					{
						for (int num106 = num103; num106 < num104; num106++)
						{
							Vector2 vector7;
							vector7.X = (float)(num105 * 16);
							vector7.Y = (float)(num106 * 16);
							if (this.position.X + (float)this.width > vector7.X && this.position.X < vector7.X + 16f && this.position.Y + (float)this.height > vector7.Y && this.position.Y < vector7.Y + 16f && Main.myPlayer == this.owner && Main.tile[num105, num106].active())
							{
								if (this.type == 10)
								{
									if (Main.tile[num105, num106].type == 23 || Main.tile[num105, num106].type == 199)
									{
										Main.tile[num105, num106].type = 2;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
									if (Main.tile[num105, num106].type == 25 || Main.tile[num105, num106].type == 203)
									{
										Main.tile[num105, num106].type = 1;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
									if (Main.tile[num105, num106].type == 112 || Main.tile[num105, num106].type == 234)
									{
										Main.tile[num105, num106].type = 53;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
									if (Main.tile[num105, num106].type == 163 || Main.tile[num105, num106].type == 200)
									{
										Main.tile[num105, num106].type = 161;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
								}
								else if (this.type == 11)
								{
									if (Main.tile[num105, num106].type == 109)
									{
										Main.tile[num105, num106].type = 2;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
									if (Main.tile[num105, num106].type == 116)
									{
										Main.tile[num105, num106].type = 53;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
									if (Main.tile[num105, num106].type == 117)
									{
										Main.tile[num105, num106].type = 1;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
									if (Main.tile[num105, num106].type == 164)
									{
										Main.tile[num105, num106].type = 161;
										WorldGen.SquareTileFrame(num105, num106, true);
										if (Main.netMode == 1)
										{
											NetMessage.SendTileSquare(-1, num105, num106, 1);
										}
									}
								}
							}
						}
					}
				}
			}
			else if (this.aiStyle == 7)
			{
				if (Main.player[this.owner].dead)
				{
					this.Kill();
					return;
				}
				Vector2 vector8 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
				float num107 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector8.X;
				float num108 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector8.Y;
				float num109 = (float)Math.Sqrt((double)(num107 * num107 + num108 * num108));
				this.rotation = (float)Math.Atan2((double)num108, (double)num107) - 1.57f;
				if (this.type == 256)
				{
					this.rotation = (float)Math.Atan2((double)num108, (double)num107) + 3.92500019f;
				}
				if (this.ai[0] == 0f)
				{
					if ((num109 > 300f && this.type == 13) || (num109 > 400f && this.type == 32) || (num109 > 440f && this.type == 73) || (num109 > 440f && this.type == 74) || (num109 > 250f && this.type == 165) || (num109 > 350f && this.type == 256) || (num109 > 500f && this.type == 315) || (num109 > 550f && this.type == 322) || (num109 > 400f && this.type == 331) || (num109 > 550f && this.type == 332) || (num109 > 400f && this.type == 372) || (num109 > 400f && this.type == 396))
					{
						this.ai[0] = 1f;
					}
					else if (this.type >= 230 && this.type <= 235)
					{
						int num110 = 300 + (this.type - 230) * 30;
						if (num109 > (float)num110)
						{
							this.ai[0] = 1f;
						}
					}
					int num111 = (int)(this.position.X / 16f) - 1;
					int num112 = (int)((this.position.X + (float)this.width) / 16f) + 2;
					int num113 = (int)(this.position.Y / 16f) - 1;
					int num114 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
					if (num111 < 0)
					{
						num111 = 0;
					}
					if (num112 > Main.maxTilesX)
					{
						num112 = Main.maxTilesX;
					}
					if (num113 < 0)
					{
						num113 = 0;
					}
					if (num114 > Main.maxTilesY)
					{
						num114 = Main.maxTilesY;
					}
					for (int num115 = num111; num115 < num112; num115++)
					{
						int num116 = num113;
						while (num116 < num114)
						{
							if (Main.tile[num115, num116] == null)
							{
								Main.tile[num115, num116] = new Tile();
							}
							Vector2 vector9;
							vector9.X = (float)(num115 * 16);
							vector9.Y = (float)(num116 * 16);
							if (this.position.X + (float)this.width > vector9.X && this.position.X < vector9.X + 16f && this.position.Y + (float)this.height > vector9.Y && this.position.Y < vector9.Y + 16f && Main.tile[num115, num116].nactive() && (Main.tileSolid[(int)Main.tile[num115, num116].type] || Main.tile[num115, num116].type == 314) && (this.type != 403 || Main.tile[num115, num116].type == 314))
							{
								if (Main.player[this.owner].grapCount < 10)
								{
									Main.player[this.owner].grappling[Main.player[this.owner].grapCount] = this.whoAmI;
									Main.player[this.owner].grapCount++;
								}
								if (Main.myPlayer == this.owner)
								{
									int num117 = 0;
									int num118 = -1;
									int num119 = 100000;
									if (this.type == 73 || this.type == 74)
									{
										for (int num120 = 0; num120 < 1000; num120++)
										{
											if (num120 != this.whoAmI && Main.projectile[num120].active && Main.projectile[num120].owner == this.owner && Main.projectile[num120].aiStyle == 7 && Main.projectile[num120].ai[0] == 2f)
											{
												Main.projectile[num120].Kill();
											}
										}
									}
									else
									{
										int num121 = 3;
										if (this.type == 165)
										{
											num121 = 8;
										}
										if (this.type == 256)
										{
											num121 = 2;
										}
										if (this.type == 372)
										{
											num121 = 1;
										}
										for (int num122 = 0; num122 < 1000; num122++)
										{
											if (Main.projectile[num122].active && Main.projectile[num122].owner == this.owner && Main.projectile[num122].aiStyle == 7)
											{
												if (Main.projectile[num122].timeLeft < num119)
												{
													num118 = num122;
													num119 = Main.projectile[num122].timeLeft;
												}
												num117++;
											}
										}
										if (num117 > num121)
										{
											Main.projectile[num118].Kill();
										}
									}
								}
								WorldGen.KillTile(num115, num116, true, true, false);
								Main.PlaySound(0, num115 * 16, num116 * 16, 1);
								this.velocity.X = 0f;
								this.velocity.Y = 0f;
								this.ai[0] = 2f;
								this.position.X = (float)(num115 * 16 + 8 - this.width / 2);
								this.position.Y = (float)(num116 * 16 + 8 - this.height / 2);
								this.damage = 0;
								this.netUpdate = true;
								if (Main.myPlayer == this.owner)
								{
									NetMessage.SendData(13, -1, -1, "", this.owner, 0f, 0f, 0f, 0);
									break;
								}
								break;
							}
							else
							{
								num116++;
							}
						}
						if (this.ai[0] == 2f)
						{
							break;
						}
					}
				}
				else if (this.ai[0] == 1f)
				{
					float num123 = 11f;
					if (this.type == 32)
					{
						num123 = 15f;
					}
					if (this.type == 73 || this.type == 74)
					{
						num123 = 17f;
					}
					if (this.type == 315)
					{
						num123 = 20f;
					}
					if (this.type == 322)
					{
						num123 = 22f;
					}
					if (this.type >= 230 && this.type <= 235)
					{
						num123 = 11f + (float)(this.type - 230) * 0.75f;
					}
					if (this.type == 332)
					{
						num123 = 17f;
					}
					if (num109 < 24f)
					{
						this.Kill();
					}
					num109 = num123 / num109;
					num107 *= num109;
					num108 *= num109;
					this.velocity.X = num107;
					this.velocity.Y = num108;
				}
				else if (this.ai[0] == 2f)
				{
					int num124 = (int)(this.position.X / 16f) - 1;
					int num125 = (int)((this.position.X + (float)this.width) / 16f) + 2;
					int num126 = (int)(this.position.Y / 16f) - 1;
					int num127 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
					if (num124 < 0)
					{
						num124 = 0;
					}
					if (num125 > Main.maxTilesX)
					{
						num125 = Main.maxTilesX;
					}
					if (num126 < 0)
					{
						num126 = 0;
					}
					if (num127 > Main.maxTilesY)
					{
						num127 = Main.maxTilesY;
					}
					bool flag3 = true;
					for (int num128 = num124; num128 < num125; num128++)
					{
						for (int num129 = num126; num129 < num127; num129++)
						{
							if (Main.tile[num128, num129] == null)
							{
								Main.tile[num128, num129] = new Tile();
							}
							Vector2 vector10;
							vector10.X = (float)(num128 * 16);
							vector10.Y = (float)(num129 * 16);
							if (this.position.X + (float)(this.width / 2) > vector10.X && this.position.X + (float)(this.width / 2) < vector10.X + 16f && this.position.Y + (float)(this.height / 2) > vector10.Y && this.position.Y + (float)(this.height / 2) < vector10.Y + 16f && Main.tile[num128, num129].nactive() && (Main.tileSolid[(int)Main.tile[num128, num129].type] || Main.tile[num128, num129].type == 314))
							{
								flag3 = false;
							}
						}
					}
					if (flag3)
					{
						this.ai[0] = 1f;
					}
					else if (Main.player[this.owner].grapCount < 10)
					{
						Main.player[this.owner].grappling[Main.player[this.owner].grapCount] = this.whoAmI;
						Main.player[this.owner].grapCount++;
					}
				}
			}
			else if (this.aiStyle == 8)
			{
				if (this.type == 258 && this.localAI[0] == 0f)
				{
					this.localAI[0] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 20);
				}
				if (this.type == 96 && this.localAI[0] == 0f)
				{
					this.localAI[0] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 20);
				}
				if (this.type == 27)
				{
					for (int num130 = 0; num130 < 5; num130++)
					{
						float num131 = this.velocity.X / 3f * (float)num130;
						float num132 = this.velocity.Y / 3f * (float)num130;
						int num133 = 4;
						int num134 = Dust.NewDust(new Vector2(this.position.X + (float)num133, this.position.Y + (float)num133), this.width - num133 * 2, this.height - num133 * 2, 172, 0f, 0f, 100, default(Color), 1.2f);
						Main.dust[num134].noGravity = true;
						Main.dust[num134].velocity *= 0.1f;
						Main.dust[num134].velocity += this.velocity * 0.1f;
						Dust expr_692D_cp_0 = Main.dust[num134];
						expr_692D_cp_0.position.X = expr_692D_cp_0.position.X - num131;
						Dust expr_6948_cp_0 = Main.dust[num134];
						expr_6948_cp_0.position.Y = expr_6948_cp_0.position.Y - num132;
					}
					if (Main.rand.Next(5) == 0)
					{
						int num135 = 4;
						int num136 = Dust.NewDust(new Vector2(this.position.X + (float)num135, this.position.Y + (float)num135), this.width - num135 * 2, this.height - num135 * 2, 172, 0f, 0f, 100, default(Color), 0.6f);
						Main.dust[num136].velocity *= 0.25f;
						Main.dust[num136].velocity += this.velocity * 0.5f;
					}
				}
				else if (this.type == 95 || this.type == 96)
				{
					int num137 = Dust.NewDust(new Vector2(this.position.X + this.velocity.X, this.position.Y + this.velocity.Y), this.width, this.height, 75, this.velocity.X, this.velocity.Y, 100, default(Color), 3f * this.scale);
					Main.dust[num137].noGravity = true;
				}
				else if (this.type == 253)
				{
					for (int num138 = 0; num138 < 2; num138++)
					{
						int num139 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 135, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 2f);
						Main.dust[num139].noGravity = true;
						Dust expr_6B66_cp_0 = Main.dust[num139];
						expr_6B66_cp_0.velocity.X = expr_6B66_cp_0.velocity.X * 0.3f;
						Dust expr_6B84_cp_0 = Main.dust[num139];
						expr_6B84_cp_0.velocity.Y = expr_6B84_cp_0.velocity.Y * 0.3f;
					}
				}
				else
				{
					for (int num140 = 0; num140 < 2; num140++)
					{
						int num141 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 2f);
						Main.dust[num141].noGravity = true;
						Dust expr_6C31_cp_0 = Main.dust[num141];
						expr_6C31_cp_0.velocity.X = expr_6C31_cp_0.velocity.X * 0.3f;
						Dust expr_6C4F_cp_0 = Main.dust[num141];
						expr_6C4F_cp_0.velocity.Y = expr_6C4F_cp_0.velocity.Y * 0.3f;
					}
				}
				if (this.type != 27 && this.type != 96 && this.type != 258)
				{
					this.ai[1] += 1f;
				}
				if (this.ai[1] >= 20f)
				{
					this.velocity.Y = this.velocity.Y + 0.2f;
				}
				this.rotation += 0.3f * (float)this.direction;
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
			}
			else if (this.aiStyle == 9)
			{
				if (this.type == 34)
				{
					int num142 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 3.5f);
					Main.dust[num142].noGravity = true;
					Main.dust[num142].velocity *= 1.4f;
					num142 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 1.5f);
				}
				else if (this.type == 79)
				{
					if (this.soundDelay == 0 && Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) > 2f)
					{
						this.soundDelay = 10;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 9);
					}
					for (int num143 = 0; num143 < 1; num143++)
					{
						int num144 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 66, 0f, 0f, 100, new Color(Main.DiscoR, Main.DiscoG, Main.DiscoB), 2.5f);
						Main.dust[num144].velocity *= 0.1f;
						Main.dust[num144].velocity += this.velocity * 0.2f;
						Main.dust[num144].position.X = this.position.X + (float)(this.width / 2) + 4f + (float)Main.rand.Next(-2, 3);
						Main.dust[num144].position.Y = this.position.Y + (float)(this.height / 2) + (float)Main.rand.Next(-2, 3);
						Main.dust[num144].noGravity = true;
					}
				}
				else
				{
					if (this.soundDelay == 0 && Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) > 2f)
					{
						this.soundDelay = 10;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 9);
					}
					int num145 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 15, 0f, 0f, 100, default(Color), 2f);
					Main.dust[num145].velocity *= 0.3f;
					Main.dust[num145].position.X = this.position.X + (float)(this.width / 2) + 4f + (float)Main.rand.Next(-4, 5);
					Main.dust[num145].position.Y = this.position.Y + (float)(this.height / 2) + (float)Main.rand.Next(-4, 5);
					Main.dust[num145].noGravity = true;
				}
				if (Main.myPlayer == this.owner && this.ai[0] == 0f)
				{
					if (Main.player[this.owner].channel)
					{
						float num146 = 12f;
						if (this.type == 16)
						{
							num146 = 15f;
						}
						Vector2 vector11 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num147 = (float)Main.mouseX + Main.screenPosition.X - vector11.X;
						float num148 = (float)Main.mouseY + Main.screenPosition.Y - vector11.Y;
						if (Main.player[this.owner].gravDir == -1f)
						{
							num148 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector11.Y;
						}
						float num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
						num149 = (float)Math.Sqrt((double)(num147 * num147 + num148 * num148));
						if (num149 > num146)
						{
							num149 = num146 / num149;
							num147 *= num149;
							num148 *= num149;
							int num150 = (int)(num147 * 1000f);
							int num151 = (int)(this.velocity.X * 1000f);
							int num152 = (int)(num148 * 1000f);
							int num153 = (int)(this.velocity.Y * 1000f);
							if (num150 != num151 || num152 != num153)
							{
								this.netUpdate = true;
							}
							this.velocity.X = num147;
							this.velocity.Y = num148;
						}
						else
						{
							int num154 = (int)(num147 * 1000f);
							int num155 = (int)(this.velocity.X * 1000f);
							int num156 = (int)(num148 * 1000f);
							int num157 = (int)(this.velocity.Y * 1000f);
							if (num154 != num155 || num156 != num157)
							{
								this.netUpdate = true;
							}
							this.velocity.X = num147;
							this.velocity.Y = num148;
						}
					}
					else if (this.ai[0] == 0f)
					{
						this.ai[0] = 1f;
						this.netUpdate = true;
						float num158 = 12f;
						Vector2 vector12 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num159 = (float)Main.mouseX + Main.screenPosition.X - vector12.X;
						float num160 = (float)Main.mouseY + Main.screenPosition.Y - vector12.Y;
						if (Main.player[this.owner].gravDir == -1f)
						{
							num160 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector12.Y;
						}
						float num161 = (float)Math.Sqrt((double)(num159 * num159 + num160 * num160));
						if (num161 == 0f)
						{
							vector12 = new Vector2(Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2), Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2));
							num159 = this.position.X + (float)this.width * 0.5f - vector12.X;
							num160 = this.position.Y + (float)this.height * 0.5f - vector12.Y;
							num161 = (float)Math.Sqrt((double)(num159 * num159 + num160 * num160));
						}
						num161 = num158 / num161;
						num159 *= num161;
						num160 *= num161;
						this.velocity.X = num159;
						this.velocity.Y = num160;
						if (this.velocity.X == 0f && this.velocity.Y == 0f)
						{
							this.Kill();
						}
					}
				}
				if (this.type == 34)
				{
					this.rotation += 0.3f * (float)this.direction;
				}
				else if (this.velocity.X != 0f || this.velocity.Y != 0f)
				{
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) - 2.355f;
				}
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
			}
			else if (this.aiStyle == 10)
			{
				if (this.type == 31 && this.ai[0] != 2f)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num162 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 32, 0f, this.velocity.Y / 2f, 0, default(Color), 1f);
						Dust expr_7670_cp_0 = Main.dust[num162];
						expr_7670_cp_0.velocity.X = expr_7670_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type == 39)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num163 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 38, 0f, this.velocity.Y / 2f, 0, default(Color), 1f);
						Dust expr_770A_cp_0 = Main.dust[num163];
						expr_770A_cp_0.velocity.X = expr_770A_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type >= 411 && this.type <= 414)
				{
					if (Main.rand.Next(3) == 0)
					{
						int num164 = 9;
						if (this.type == 412 || this.type == 414)
						{
							num164 = 11;
						}
						if (this.type == 413)
						{
							num164 = 19;
						}
						int num165 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, num164, 0f, this.velocity.Y / 2f, 0, default(Color), 1f);
						Main.dust[num165].noGravity = true;
						Main.dust[num165].velocity -= this.velocity * 0.5f;
					}
				}
				else if (this.type == 40)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num166 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 36, 0f, this.velocity.Y / 2f, 0, default(Color), 1f);
						Main.dust[num166].velocity *= 0.4f;
					}
				}
				else if (this.type == 42 || this.type == 31)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num167 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 32, 0f, 0f, 0, default(Color), 1f);
						Dust expr_7933_cp_0 = Main.dust[num167];
						expr_7933_cp_0.velocity.X = expr_7933_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type == 56 || this.type == 65)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num168 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 14, 0f, 0f, 0, default(Color), 1f);
						Dust expr_79CB_cp_0 = Main.dust[num168];
						expr_79CB_cp_0.velocity.X = expr_79CB_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type == 67 || this.type == 68)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num169 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 51, 0f, 0f, 0, default(Color), 1f);
						Dust expr_7A63_cp_0 = Main.dust[num169];
						expr_7A63_cp_0.velocity.X = expr_7A63_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type == 71)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num170 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 53, 0f, 0f, 0, default(Color), 1f);
						Dust expr_7AF1_cp_0 = Main.dust[num170];
						expr_7AF1_cp_0.velocity.X = expr_7AF1_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type == 179)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num171 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 149, 0f, 0f, 0, default(Color), 1f);
						Dust expr_7B85_cp_0 = Main.dust[num171];
						expr_7B85_cp_0.velocity.X = expr_7B85_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type == 241 || this.type == 354)
				{
					if (Main.rand.Next(2) == 0)
					{
						int num172 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 36, 0f, 0f, 0, default(Color), 1f);
						Dust expr_7C20_cp_0 = Main.dust[num172];
						expr_7C20_cp_0.velocity.X = expr_7C20_cp_0.velocity.X * 0.4f;
					}
				}
				else if (this.type != 109 && Main.rand.Next(20) == 0)
				{
					Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 0, 0f, 0f, 0, default(Color), 1f);
				}
				if (Main.myPlayer == this.owner && this.ai[0] == 0f)
				{
					if (Main.player[this.owner].channel)
					{
						float num173 = 12f;
						Vector2 vector13 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num174 = (float)Main.mouseX + Main.screenPosition.X - vector13.X;
						float num175 = (float)Main.mouseY + Main.screenPosition.Y - vector13.Y;
						if (Main.player[this.owner].gravDir == -1f)
						{
							num175 = Main.screenPosition.Y + (float)Main.screenHeight - (float)Main.mouseY - vector13.Y;
						}
						float num176 = (float)Math.Sqrt((double)(num174 * num174 + num175 * num175));
						num176 = (float)Math.Sqrt((double)(num174 * num174 + num175 * num175));
						if (num176 > num173)
						{
							num176 = num173 / num176;
							num174 *= num176;
							num175 *= num176;
							if (num174 != this.velocity.X || num175 != this.velocity.Y)
							{
								this.netUpdate = true;
							}
							this.velocity.X = num174;
							this.velocity.Y = num175;
						}
						else
						{
							if (num174 != this.velocity.X || num175 != this.velocity.Y)
							{
								this.netUpdate = true;
							}
							this.velocity.X = num174;
							this.velocity.Y = num175;
						}
					}
					else
					{
						this.ai[0] = 1f;
						this.netUpdate = true;
					}
				}
				if (this.ai[0] == 1f && this.type != 109)
				{
					if (this.type == 42 || this.type == 65 || this.type == 68 || this.type == 354)
					{
						this.ai[1] += 1f;
						if (this.ai[1] >= 60f)
						{
							this.ai[1] = 60f;
							this.velocity.Y = this.velocity.Y + 0.2f;
						}
					}
					else
					{
						this.velocity.Y = this.velocity.Y + 0.41f;
					}
				}
				else if (this.ai[0] == 2f && this.type != 109)
				{
					this.velocity.Y = this.velocity.Y + 0.2f;
					if ((double)this.velocity.X < -0.04)
					{
						this.velocity.X = this.velocity.X + 0.04f;
					}
					else if ((double)this.velocity.X > 0.04)
					{
						this.velocity.X = this.velocity.X - 0.04f;
					}
					else
					{
						this.velocity.X = 0f;
					}
				}
				this.rotation += 0.1f;
				if (this.velocity.Y > 10f)
				{
					this.velocity.Y = 10f;
				}
			}
			else if (this.aiStyle == 11)
			{
				if (this.type == 72 || this.type == 86 || this.type == 87)
				{
					if (this.velocity.X > 0f)
					{
						this.spriteDirection = -1;
					}
					else if (this.velocity.X < 0f)
					{
						this.spriteDirection = 1;
					}
					this.rotation = this.velocity.X * 0.1f;
					this.frameCounter++;
					if (this.frameCounter >= 4)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame >= 4)
					{
						this.frame = 0;
					}
					if (Main.rand.Next(6) == 0)
					{
						int num177 = 56;
						if (this.type == 86)
						{
							num177 = 73;
						}
						else if (this.type == 87)
						{
							num177 = 74;
						}
						int num178 = Dust.NewDust(this.position, this.width, this.height, num177, 0f, 0f, 200, default(Color), 0.8f);
						Main.dust[num178].velocity *= 0.3f;
					}
				}
				else
				{
					this.rotation += 0.02f;
				}
				if (Main.myPlayer == this.owner)
				{
					if (this.type == 72)
					{
						if (Main.player[Main.myPlayer].blueFairy)
						{
							this.timeLeft = 2;
						}
					}
					else if (this.type == 86)
					{
						if (Main.player[Main.myPlayer].redFairy)
						{
							this.timeLeft = 2;
						}
					}
					else if (this.type == 87)
					{
						if (Main.player[Main.myPlayer].greenFairy)
						{
							this.timeLeft = 2;
						}
					}
					else if (Main.player[Main.myPlayer].lightOrb)
					{
						this.timeLeft = 2;
					}
				}
				if (!Main.player[this.owner].dead)
				{
					float num179 = 3f;
					if (this.type == 72 || this.type == 86 || this.type == 87)
					{
						num179 = 3.75f;
					}
					Vector2 vector14 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num180 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector14.X;
					float num181 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector14.Y;
					int num182 = 70;
					if (this.type == 18)
					{
						if (Main.player[this.owner].controlUp)
						{
							num181 = Main.player[this.owner].position.Y - 40f - vector14.Y;
							num180 -= 6f;
							num182 = 4;
						}
						else if (Main.player[this.owner].controlDown)
						{
							num181 = Main.player[this.owner].position.Y + (float)Main.player[this.owner].height + 40f - vector14.Y;
							num180 -= 6f;
							num182 = 4;
						}
					}
					float num183 = (float)Math.Sqrt((double)(num180 * num180 + num181 * num181));
					num183 = (float)Math.Sqrt((double)(num180 * num180 + num181 * num181));
					if (this.type == 72 || this.type == 86 || this.type == 87)
					{
						num182 = 40;
					}
					if (num183 > 800f)
					{
						this.position.X = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - (float)(this.width / 2);
						this.position.Y = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - (float)(this.height / 2);
					}
					else if (num183 > (float)num182)
					{
						num183 = num179 / num183;
						num180 *= num183;
						num181 *= num183;
						this.velocity.X = num180;
						this.velocity.Y = num181;
					}
					else
					{
						this.velocity.X = 0f;
						this.velocity.Y = 0f;
					}
				}
				else
				{
					this.Kill();
				}
			}
			else if (this.aiStyle == 12)
			{
				if (this.type == 288 && this.localAI[0] == 0f)
				{
					this.localAI[0] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
				}
				if (this.type == 280 || this.type == 288)
				{
					this.scale -= 0.002f;
					if (this.scale <= 0f)
					{
						this.Kill();
					}
					if (this.type == 288)
					{
						this.ai[0] = 4f;
					}
					if (this.ai[0] > 3f)
					{
						this.velocity.Y = this.velocity.Y + 0.075f;
						for (int num184 = 0; num184 < 3; num184++)
						{
							float num185 = this.velocity.X / 3f * (float)num184;
							float num186 = this.velocity.Y / 3f * (float)num184;
							int num187 = 14;
							int num188 = Dust.NewDust(new Vector2(this.position.X + (float)num187, this.position.Y + (float)num187), this.width - num187 * 2, this.height - num187 * 2, 170, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num188].noGravity = true;
							Main.dust[num188].velocity *= 0.1f;
							Main.dust[num188].velocity += this.velocity * 0.5f;
							Dust expr_869B_cp_0 = Main.dust[num188];
							expr_869B_cp_0.position.X = expr_869B_cp_0.position.X - num185;
							Dust expr_86B6_cp_0 = Main.dust[num188];
							expr_86B6_cp_0.position.Y = expr_86B6_cp_0.position.Y - num186;
						}
						if (Main.rand.Next(8) == 0)
						{
							int num189 = 16;
							int num190 = Dust.NewDust(new Vector2(this.position.X + (float)num189, this.position.Y + (float)num189), this.width - num189 * 2, this.height - num189 * 2, 170, 0f, 0f, 100, default(Color), 0.5f);
							Main.dust[num190].velocity *= 0.25f;
							Main.dust[num190].velocity += this.velocity * 0.5f;
						}
					}
					else
					{
						this.ai[0] += 1f;
					}
				}
				else
				{
					this.scale -= 0.02f;
					if (this.scale <= 0f)
					{
						this.Kill();
					}
					if (this.ai[0] > 3f)
					{
						this.velocity.Y = this.velocity.Y + 0.2f;
						for (int num191 = 0; num191 < 1; num191++)
						{
							for (int num192 = 0; num192 < 3; num192++)
							{
								float num193 = this.velocity.X / 3f * (float)num192;
								float num194 = this.velocity.Y / 3f * (float)num192;
								int num195 = 6;
								int num196 = Dust.NewDust(new Vector2(this.position.X + (float)num195, this.position.Y + (float)num195), this.width - num195 * 2, this.height - num195 * 2, 172, 0f, 0f, 100, default(Color), 1.2f);
								Main.dust[num196].noGravity = true;
								Main.dust[num196].velocity *= 0.3f;
								Main.dust[num196].velocity += this.velocity * 0.5f;
								Dust expr_8909_cp_0 = Main.dust[num196];
								expr_8909_cp_0.position.X = expr_8909_cp_0.position.X - num193;
								Dust expr_8924_cp_0 = Main.dust[num196];
								expr_8924_cp_0.position.Y = expr_8924_cp_0.position.Y - num194;
							}
							if (Main.rand.Next(8) == 0)
							{
								int num197 = 6;
								int num198 = Dust.NewDust(new Vector2(this.position.X + (float)num197, this.position.Y + (float)num197), this.width - num197 * 2, this.height - num197 * 2, 172, 0f, 0f, 100, default(Color), 0.75f);
								Main.dust[num198].velocity *= 0.5f;
								Main.dust[num198].velocity += this.velocity * 0.5f;
							}
						}
					}
					else
					{
						this.ai[0] += 1f;
					}
				}
			}
			else if (this.aiStyle == 13)
			{
				if (Main.player[this.owner].dead)
				{
					this.Kill();
					return;
				}
				Main.player[this.owner].itemAnimation = 5;
				Main.player[this.owner].itemTime = 5;
				if (this.alpha == 0)
				{
					if (this.position.X + (float)(this.width / 2) > Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2))
					{
						Main.player[this.owner].ChangeDir(1);
					}
					else
					{
						Main.player[this.owner].ChangeDir(-1);
					}
				}
				Vector2 vector15 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
				float num199 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector15.X;
				float num200 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector15.Y;
				float num201 = (float)Math.Sqrt((double)(num199 * num199 + num200 * num200));
				if (this.ai[0] == 0f)
				{
					if (num201 > 700f)
					{
						this.ai[0] = 1f;
					}
					else if (this.type == 262 && num201 > 500f)
					{
						this.ai[0] = 1f;
					}
					else if (this.type == 271 && num201 > 200f)
					{
						this.ai[0] = 1f;
					}
					else if (this.type == 273 && num201 > 150f)
					{
						this.ai[0] = 1f;
					}
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
					this.ai[1] += 1f;
					if (this.ai[1] > 5f)
					{
						this.alpha = 0;
					}
					if (this.type == 262 && this.ai[1] > 8f)
					{
						this.ai[1] = 8f;
					}
					if (this.type == 271 && this.ai[1] > 8f)
					{
						this.ai[1] = 8f;
					}
					if (this.type == 273 && this.ai[1] > 8f)
					{
						this.ai[1] = 8f;
					}
					if (this.type == 404 && this.ai[1] > 8f)
					{
						this.ai[1] = 0f;
					}
					if (this.ai[1] >= 10f)
					{
						this.ai[1] = 15f;
						this.velocity.Y = this.velocity.Y + 0.3f;
					}
					if (this.type == 262 && this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
					}
					else if (this.type == 262)
					{
						this.spriteDirection = 1;
					}
					if (this.type == 271 && this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
					}
					else if (this.type == 271)
					{
						this.spriteDirection = 1;
					}
				}
				else if (this.ai[0] == 1f)
				{
					this.tileCollide = false;
					this.rotation = (float)Math.Atan2((double)num200, (double)num199) - 1.57f;
					float num202 = 20f;
					if (this.type == 262)
					{
						num202 = 30f;
					}
					if (num201 < 50f)
					{
						this.Kill();
					}
					num201 = num202 / num201;
					num199 *= num201;
					num200 *= num201;
					this.velocity.X = num199;
					this.velocity.Y = num200;
					if (this.type == 262 && this.velocity.X < 0f)
					{
						this.spriteDirection = 1;
					}
					else if (this.type == 262)
					{
						this.spriteDirection = -1;
					}
					if (this.type == 271 && this.velocity.X < 0f)
					{
						this.spriteDirection = 1;
					}
					else if (this.type == 271)
					{
						this.spriteDirection = -1;
					}
				}
			}
			else if (this.aiStyle == 14)
			{
				if (this.type == 352)
				{
					if (this.localAI[1] == 0f)
					{
						this.localAI[1] = 1f;
					}
					this.alpha += (int)(25f * this.localAI[1]);
					if (this.alpha <= 0)
					{
						this.alpha = 0;
						this.localAI[1] = 1f;
					}
					else if (this.alpha >= 255)
					{
						this.alpha = 255;
						this.localAI[1] = -1f;
					}
					this.scale += this.localAI[1] * 0.01f;
				}
				if (this.type == 346)
				{
					if (this.localAI[0] == 0f)
					{
						this.localAI[0] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 1);
					}
					this.frame = (int)this.ai[1];
					if (this.owner == Main.myPlayer && this.timeLeft == 1)
					{
						for (int num203 = 0; num203 < 5; num203++)
						{
							float num204 = 10f;
							Vector2 vector16 = new Vector2(this.center().X, this.center().Y);
							float num205 = (float)Main.rand.Next(-20, 21);
							float num206 = (float)Main.rand.Next(-20, 0);
							float num207 = (float)Math.Sqrt((double)(num205 * num205 + num206 * num206));
							num207 = num204 / num207;
							num205 *= num207;
							num206 *= num207;
							num205 *= 1f + (float)Main.rand.Next(-30, 31) * 0.01f;
							num206 *= 1f + (float)Main.rand.Next(-30, 31) * 0.01f;
							Projectile.NewProjectile(vector16.X, vector16.Y, num205, num206, 347, 40, 0f, Main.myPlayer, 0f, this.ai[1]);
						}
					}
				}
				if (this.type == 196)
				{
					int num208 = Main.rand.Next(1, 3);
					for (int num209 = 0; num209 < num208; num209++)
					{
						int num210 = Dust.NewDust(this.position, this.width, this.height, 31, 0f, 0f, 100, default(Color), 1f);
						Main.dust[num210].alpha += Main.rand.Next(100);
						Main.dust[num210].velocity *= 0.3f;
						Dust expr_91CC_cp_0 = Main.dust[num210];
						expr_91CC_cp_0.velocity.X = expr_91CC_cp_0.velocity.X + (float)Main.rand.Next(-10, 11) * 0.025f;
						Dust expr_91FA_cp_0 = Main.dust[num210];
						expr_91FA_cp_0.velocity.Y = expr_91FA_cp_0.velocity.Y - (0.4f + (float)Main.rand.Next(-3, 14) * 0.15f);
						Main.dust[num210].fadeIn = 1.25f + (float)Main.rand.Next(20) * 0.15f;
					}
				}
				if (this.type == 53)
				{
					try
					{
						Vector2 value3 = Collision.TileCollision(this.position, this.velocity, this.width, this.height, false, false, 1);
						//this.velocity != value3; TODO:DECOMPILER BS
						int num211 = (int)(this.position.X / 16f) - 1;
						int num212 = (int)((this.position.X + (float)this.width) / 16f) + 2;
						int num213 = (int)(this.position.Y / 16f) - 1;
						int num214 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
						if (num211 < 0)
						{
							num211 = 0;
						}
						if (num212 > Main.maxTilesX)
						{
							num212 = Main.maxTilesX;
						}
						if (num213 < 0)
						{
							num213 = 0;
						}
						if (num214 > Main.maxTilesY)
						{
							num214 = Main.maxTilesY;
						}
						for (int num215 = num211; num215 < num212; num215++)
						{
							for (int num216 = num213; num216 < num214; num216++)
							{
								if (Main.tile[num215, num216] != null && Main.tile[num215, num216].nactive() && (Main.tileSolid[(int)Main.tile[num215, num216].type] || (Main.tileSolidTop[(int)Main.tile[num215, num216].type] && Main.tile[num215, num216].frameY == 0)))
								{
									Vector2 vector17;
									vector17.X = (float)(num215 * 16);
									vector17.Y = (float)(num216 * 16);
									if (this.position.X + (float)this.width > vector17.X && this.position.X < vector17.X + 16f && this.position.Y + (float)this.height > vector17.Y && this.position.Y < vector17.Y + 16f)
									{
										this.velocity.X = 0f;
										this.velocity.Y = -0.2f;
									}
								}
							}
						}
					}
					catch
					{
					}
				}
				if (this.type == 277 && this.alpha > 0)
				{
					this.alpha -= 30;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.type == 261 || this.type == 277)
				{
					this.ai[0] += 1f;
					if (this.ai[0] > 15f)
					{
						this.ai[0] = 15f;
						if (this.velocity.Y == 0f && this.velocity.X != 0f)
						{
							this.velocity.X = this.velocity.X * 0.97f;
							if ((double)this.velocity.X > -0.01 && (double)this.velocity.X < 0.01)
							{
								this.Kill();
							}
						}
						this.velocity.Y = this.velocity.Y + 0.2f;
					}
					this.rotation += this.velocity.X * 0.05f;
				}
				else if (this.type == 378)
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
						this.localAI[0] += 1f;
					}
					Rectangle rectangle2 = new Rectangle((int)this.position.X, (int)this.position.Y, this.width, this.height);
					for (int num217 = 0; num217 < 200; num217++)
					{
						if (Main.npc[num217].active && !Main.npc[num217].friendly && Main.npc[num217].lifeMax > 5)
						{
							Rectangle value4 = new Rectangle((int)Main.npc[num217].position.X, (int)Main.npc[num217].position.Y, Main.npc[num217].width, Main.npc[num217].height);
							if (rectangle2.Intersects(value4))
							{
								this.Kill();
								return;
							}
						}
					}
					this.ai[0] += 1f;
					if (this.ai[0] > 10f)
					{
						this.ai[0] = 90f;
						if (this.velocity.Y == 0f && this.velocity.X != 0f)
						{
							this.velocity.X = this.velocity.X * 0.96f;
							if ((double)this.velocity.X > -0.01 && (double)this.velocity.X < 0.01)
							{
								this.Kill();
							}
						}
						this.velocity.Y = this.velocity.Y + 0.2f;
					}
					this.rotation += this.velocity.X * 0.1f;
				}
				else
				{
					this.ai[0] += 1f;
					if (this.ai[0] > 5f)
					{
						this.ai[0] = 5f;
						if (this.velocity.Y == 0f && this.velocity.X != 0f)
						{
							this.velocity.X = this.velocity.X * 0.97f;
							if ((double)this.velocity.X > -0.01 && (double)this.velocity.X < 0.01)
							{
								this.velocity.X = 0f;
								this.netUpdate = true;
							}
						}
						this.velocity.Y = this.velocity.Y + 0.2f;
					}
					this.rotation += this.velocity.X * 0.1f;
				}
				if ((this.type >= 326 && this.type <= 328) || (this.type >= 400 && this.type <= 402))
				{
					if (this.wet)
					{
						this.Kill();
					}
					if (this.ai[1] == 0f && this.type >= 326 && this.type <= 328)
					{
						this.ai[1] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 13);
					}
					int num218 = Dust.NewDust(this.position, this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
					Dust expr_999B_cp_0 = Main.dust[num218];
					expr_999B_cp_0.position.X = expr_999B_cp_0.position.X - 2f;
					Dust expr_99B9_cp_0 = Main.dust[num218];
					expr_99B9_cp_0.position.Y = expr_99B9_cp_0.position.Y + 2f;
					Main.dust[num218].scale += (float)Main.rand.Next(50) * 0.01f;
					Main.dust[num218].noGravity = true;
					Dust expr_9A0C_cp_0 = Main.dust[num218];
					expr_9A0C_cp_0.velocity.Y = expr_9A0C_cp_0.velocity.Y - 2f;
					if (Main.rand.Next(2) == 0)
					{
						int num219 = Dust.NewDust(this.position, this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
						Dust expr_9A73_cp_0 = Main.dust[num219];
						expr_9A73_cp_0.position.X = expr_9A73_cp_0.position.X - 2f;
						Dust expr_9A91_cp_0 = Main.dust[num219];
						expr_9A91_cp_0.position.Y = expr_9A91_cp_0.position.Y + 2f;
						Main.dust[num219].scale += 0.3f + (float)Main.rand.Next(50) * 0.01f;
						Main.dust[num219].noGravity = true;
						Main.dust[num219].velocity *= 0.1f;
					}
					if ((double)this.velocity.Y < 0.25 && (double)this.velocity.Y > 0.15)
					{
						this.velocity.X = this.velocity.X * 0.8f;
					}
					this.rotation = -this.velocity.X * 0.05f;
				}
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
			}
			else if (this.aiStyle == 15)
			{
				if (this.type == 25)
				{
					if (Main.rand.Next(15) == 0)
					{
						Dust.NewDust(this.position, this.width, this.height, 14, 0f, 0f, 150, default(Color), 1.3f);
					}
				}
				else if (this.type == 26)
				{
					int num220 = Dust.NewDust(this.position, this.width, this.height, 172, this.velocity.X * 0.4f, this.velocity.Y * 0.4f, 100, default(Color), 1.5f);
					Main.dust[num220].noGravity = true;
					Dust expr_9C67_cp_0 = Main.dust[num220];
					expr_9C67_cp_0.velocity.X = expr_9C67_cp_0.velocity.X / 2f;
					Dust expr_9C85_cp_0 = Main.dust[num220];
					expr_9C85_cp_0.velocity.Y = expr_9C85_cp_0.velocity.Y / 2f;
				}
				else if (this.type == 35)
				{
					int num221 = Dust.NewDust(this.position, this.width, this.height, 6, this.velocity.X * 0.4f, this.velocity.Y * 0.4f, 100, default(Color), 3f);
					Main.dust[num221].noGravity = true;
					Dust expr_9D1A_cp_0 = Main.dust[num221];
					expr_9D1A_cp_0.velocity.X = expr_9D1A_cp_0.velocity.X * 2f;
					Dust expr_9D3A_cp_0 = Main.dust[num221];
					expr_9D3A_cp_0.velocity.Y = expr_9D3A_cp_0.velocity.Y * 2f;
				}
				else if (this.type == 154)
				{
					int num222 = Dust.NewDust(this.position, this.width, this.height, 115, this.velocity.X * 0.4f, this.velocity.Y * 0.4f, 140, default(Color), 1.5f);
					Main.dust[num222].noGravity = true;
					Main.dust[num222].velocity *= 0.25f;
				}
				if (Main.player[this.owner].dead)
				{
					this.Kill();
					return;
				}
				Main.player[this.owner].itemAnimation = 10;
				Main.player[this.owner].itemTime = 10;
				if (this.position.X + (float)(this.width / 2) > Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2))
				{
					Main.player[this.owner].ChangeDir(1);
					this.direction = 1;
				}
				else
				{
					Main.player[this.owner].ChangeDir(-1);
					this.direction = -1;
				}
				Vector2 vector18 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
				float num223 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector18.X;
				float num224 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector18.Y;
				float num225 = (float)Math.Sqrt((double)(num223 * num223 + num224 * num224));
				if (this.ai[0] == 0f)
				{
					float num226 = 160f;
					if (this.type == 63)
					{
						num226 *= 1.5f;
					}
					if (this.type == 247)
					{
						num226 *= 1.5f;
					}
					this.tileCollide = true;
					if (num225 > num226)
					{
						this.ai[0] = 1f;
						this.netUpdate = true;
					}
					else if (!Main.player[this.owner].channel)
					{
						if (this.velocity.Y < 0f)
						{
							this.velocity.Y = this.velocity.Y * 0.9f;
						}
						this.velocity.Y = this.velocity.Y + 1f;
						this.velocity.X = this.velocity.X * 0.9f;
					}
				}
				else if (this.ai[0] == 1f)
				{
					float num227 = 14f / Main.player[this.owner].meleeSpeed;
					float num228 = 0.9f / Main.player[this.owner].meleeSpeed;
					float num229 = 300f;
					if (this.type == 63)
					{
						num229 *= 1.5f;
						num227 *= 1.5f;
						num228 *= 1.5f;
					}
					if (this.type == 247)
					{
						num229 *= 1.5f;
						num227 = 15.9f;
						num228 *= 2f;
					}
					Math.Abs(num223);
					Math.Abs(num224);
					if (this.ai[1] == 1f)
					{
						this.tileCollide = false;
					}
					if (!Main.player[this.owner].channel || num225 > num229 || !this.tileCollide)
					{
						this.ai[1] = 1f;
						if (this.tileCollide)
						{
							this.netUpdate = true;
						}
						this.tileCollide = false;
						if (num225 < 20f)
						{
							this.Kill();
						}
					}
					if (!this.tileCollide)
					{
						num228 *= 2f;
					}
					int num230 = 60;
					if (this.type == 247)
					{
						num230 = 100;
					}
					if (num225 > (float)num230 || !this.tileCollide)
					{
						num225 = num227 / num225;
						num223 *= num225;
						num224 *= num225;
						new Vector2(this.velocity.X, this.velocity.Y);
						float num231 = num223 - this.velocity.X;
						float num232 = num224 - this.velocity.Y;
						float num233 = (float)Math.Sqrt((double)(num231 * num231 + num232 * num232));
						num233 = num228 / num233;
						num231 *= num233;
						num232 *= num233;
						this.velocity.X = this.velocity.X * 0.98f;
						this.velocity.Y = this.velocity.Y * 0.98f;
						this.velocity.X = this.velocity.X + num231;
						this.velocity.Y = this.velocity.Y + num232;
					}
					else
					{
						if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) < 6f)
						{
							this.velocity.X = this.velocity.X * 0.96f;
							this.velocity.Y = this.velocity.Y + 0.2f;
						}
						if (Main.player[this.owner].velocity.X == 0f)
						{
							this.velocity.X = this.velocity.X * 0.96f;
						}
					}
				}
				if (this.type == 247)
				{
					if (this.velocity.X < 0f)
					{
						this.rotation -= (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.01f;
					}
					else
					{
						this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.01f;
					}
					float num234 = this.position.X;
					float num235 = this.position.Y;
					float num236 = 600f;
					bool flag4 = false;
					if (this.owner == Main.myPlayer)
					{
						this.localAI[1] += 1f;
						if (this.localAI[1] > 20f)
						{
							this.localAI[1] = 20f;
							for (int num237 = 0; num237 < 200; num237++)
							{
								if (Main.npc[num237].active && !Main.npc[num237].dontTakeDamage && !Main.npc[num237].friendly && Main.npc[num237].lifeMax > 5)
								{
									float num238 = Main.npc[num237].position.X + (float)(Main.npc[num237].width / 2);
									float num239 = Main.npc[num237].position.Y + (float)(Main.npc[num237].height / 2);
									float num240 = Math.Abs(this.position.X + (float)(this.width / 2) - num238) + Math.Abs(this.position.Y + (float)(this.height / 2) - num239);
									if (num240 < num236 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num237].position, Main.npc[num237].width, Main.npc[num237].height))
									{
										num236 = num240;
										num234 = num238;
										num235 = num239;
										flag4 = true;
									}
								}
							}
						}
					}
					if (flag4)
					{
						this.localAI[1] = 0f;
						float num241 = 14f;
						vector18 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						num223 = num234 - vector18.X;
						num224 = num235 - vector18.Y;
						num225 = (float)Math.Sqrt((double)(num223 * num223 + num224 * num224));
						num225 = num241 / num225;
						num223 *= num225;
						num224 *= num225;
						Projectile.NewProjectile(vector18.X, vector18.Y, num223, num224, 248, (int)((double)this.damage / 1.5), this.knockBack / 2f, Main.myPlayer, 0f, 0f);
					}
				}
				else
				{
					this.rotation = (float)Math.Atan2((double)num224, (double)num223) - this.velocity.X * 0.1f;
				}
			}
			else if (this.aiStyle == 16)
			{
				if (this.type == 108 || this.type == 164)
				{
					this.ai[0] += 1f;
					if (this.ai[0] > 3f)
					{
						this.Kill();
					}
				}
				if (this.type != 37)
				{
					if (this.type != 397)
					{
						goto IL_A9FB;
					}
				}
				try
				{
					int num242 = (int)(this.position.X / 16f) - 1;
					int num243 = (int)((this.position.X + (float)this.width) / 16f) + 2;
					int num244 = (int)(this.position.Y / 16f) - 1;
					int num245 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
					if (num242 < 0)
					{
						num242 = 0;
					}
					if (num243 > Main.maxTilesX)
					{
						num243 = Main.maxTilesX;
					}
					if (num244 < 0)
					{
						num244 = 0;
					}
					if (num245 > Main.maxTilesY)
					{
						num245 = Main.maxTilesY;
					}
					for (int num246 = num242; num246 < num243; num246++)
					{
						for (int num247 = num244; num247 < num245; num247++)
						{
							if (Main.tile[num246, num247] != null && Main.tile[num246, num247].nactive() && (Main.tileSolid[(int)Main.tile[num246, num247].type] || (Main.tileSolidTop[(int)Main.tile[num246, num247].type] && Main.tile[num246, num247].frameY == 0)))
							{
								Vector2 vector19;
								vector19.X = (float)(num246 * 16);
								vector19.Y = (float)(num247 * 16);
								if (this.position.X + (float)this.width - 4f > vector19.X && this.position.X + 4f < vector19.X + 16f && this.position.Y + (float)this.height - 4f > vector19.Y && this.position.Y + 4f < vector19.Y + 16f)
								{
									this.velocity.X = 0f;
									this.velocity.Y = -0.2f;
								}
							}
						}
					}
				}
				catch
				{
				}
				IL_A9FB:
				if (this.type == 102)
				{
					if (this.velocity.Y > 10f)
					{
						this.velocity.Y = 10f;
					}
					if (this.localAI[0] == 0f)
					{
						this.localAI[0] = 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 10);
					}
					this.frameCounter++;
					if (this.frameCounter > 3)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame > 1)
					{
						this.frame = 0;
					}
					if (this.velocity.Y == 0f)
					{
						this.position.X = this.position.X + (float)(this.width / 2);
						this.position.Y = this.position.Y + (float)(this.height / 2);
						this.width = 128;
						this.height = 128;
						this.position.X = this.position.X - (float)(this.width / 2);
						this.position.Y = this.position.Y - (float)(this.height / 2);
						this.damage = 40;
						this.knockBack = 8f;
						this.timeLeft = 3;
						this.netUpdate = true;
					}
				}
				if (this.type == 303 && this.timeLeft <= 3 && this.hostile)
				{
					this.position.X = this.position.X + (float)(this.width / 2);
					this.position.Y = this.position.Y + (float)(this.height / 2);
					this.width = 128;
					this.height = 128;
					this.position.X = this.position.X - (float)(this.width / 2);
					this.position.Y = this.position.Y - (float)(this.height / 2);
				}
				if (this.owner == Main.myPlayer && this.timeLeft <= 3)
				{
					this.tileCollide = false;
					this.ai[1] = 0f;
					this.alpha = 255;
					if (this.type == 28 || this.type == 37 || this.type == 75)
					{
						this.position.X = this.position.X + (float)(this.width / 2);
						this.position.Y = this.position.Y + (float)(this.height / 2);
						this.width = 128;
						this.height = 128;
						this.position.X = this.position.X - (float)(this.width / 2);
						this.position.Y = this.position.Y - (float)(this.height / 2);
						this.damage = 100;
						this.knockBack = 8f;
					}
					else if (this.type == 29)
					{
						this.position.X = this.position.X + (float)(this.width / 2);
						this.position.Y = this.position.Y + (float)(this.height / 2);
						this.width = 250;
						this.height = 250;
						this.position.X = this.position.X - (float)(this.width / 2);
						this.position.Y = this.position.Y - (float)(this.height / 2);
						this.damage = 250;
						this.knockBack = 10f;
					}
					else if (this.type == 30 || this.type == 397)
					{
						this.position.X = this.position.X + (float)(this.width / 2);
						this.position.Y = this.position.Y + (float)(this.height / 2);
						this.width = 128;
						this.height = 128;
						this.position.X = this.position.X - (float)(this.width / 2);
						this.position.Y = this.position.Y - (float)(this.height / 2);
						this.knockBack = 8f;
					}
					else if (this.type == 133 || this.type == 134 || this.type == 135 || this.type == 136 || this.type == 137 || this.type == 138 || this.type == 338 || this.type == 339)
					{
						this.position.X = this.position.X + (float)(this.width / 2);
						this.position.Y = this.position.Y + (float)(this.height / 2);
						this.width = 128;
						this.height = 128;
						this.position.X = this.position.X - (float)(this.width / 2);
						this.position.Y = this.position.Y - (float)(this.height / 2);
						this.knockBack = 8f;
					}
					else if (this.type == 139 || this.type == 140 || this.type == 141 || this.type == 142 || this.type == 143 || this.type == 144 || this.type == 340 || this.type == 341)
					{
						this.position.X = this.position.X + (float)(this.width / 2);
						this.position.Y = this.position.Y + (float)(this.height / 2);
						this.width = 200;
						this.height = 200;
						this.position.X = this.position.X - (float)(this.width / 2);
						this.position.Y = this.position.Y - (float)(this.height / 2);
						this.knockBack = 10f;
					}
				}
				else
				{
					if (this.type != 30 && this.type != 397 && this.type != 108 && this.type != 133 && this.type != 134 && this.type != 135 && this.type != 136 && this.type != 137 && this.type != 138 && this.type != 139 && this.type != 140 && this.type != 141 && this.type != 142 && this.type != 143 && this.type != 144 && this.type != 164 && this.type != 303 && this.type < 338 && this.type < 341)
					{
						this.damage = 0;
					}
					if (this.type == 338 || this.type == 339 || this.type == 340 || this.type == 341)
					{
						this.localAI[1] += 1f;
						if (this.localAI[1] > 6f)
						{
							this.alpha = 0;
						}
						else
						{
							this.alpha = (int)(255f - 42f * this.localAI[1]) + 100;
							if (this.alpha > 255)
							{
								this.alpha = 255;
							}
						}
						for (int num248 = 0; num248 < 2; num248++)
						{
							float num249 = 0f;
							float num250 = 0f;
							if (num248 == 1)
							{
								num249 = this.velocity.X * 0.5f;
								num250 = this.velocity.Y * 0.5f;
							}
							if (this.localAI[1] > 9f)
							{
								if (Main.rand.Next(2) == 0)
								{
									int num251 = Dust.NewDust(new Vector2(this.position.X + 3f + num249, this.position.Y + 3f + num250) - this.velocity * 0.5f, this.width - 8, this.height - 8, 6, 0f, 0f, 100, default(Color), 1f);
									Main.dust[num251].scale *= 1.4f + (float)Main.rand.Next(10) * 0.1f;
									Main.dust[num251].velocity *= 0.2f;
									Main.dust[num251].noGravity = true;
								}
								if (Main.rand.Next(2) == 0)
								{
									int num252 = Dust.NewDust(new Vector2(this.position.X + 3f + num249, this.position.Y + 3f + num250) - this.velocity * 0.5f, this.width - 8, this.height - 8, 31, 0f, 0f, 100, default(Color), 0.5f);
									Main.dust[num252].fadeIn = 0.5f + (float)Main.rand.Next(5) * 0.1f;
									Main.dust[num252].velocity *= 0.05f;
								}
							}
						}
						float num253 = this.position.X;
						float num254 = this.position.Y;
						float num255 = 600f;
						bool flag5 = false;
						this.ai[0] += 1f;
						if (this.ai[0] > 30f)
						{
							this.ai[0] = 30f;
							for (int num256 = 0; num256 < 200; num256++)
							{
								if (Main.npc[num256].active && !Main.npc[num256].dontTakeDamage && !Main.npc[num256].friendly && Main.npc[num256].lifeMax > 5)
								{
									float num257 = Main.npc[num256].position.X + (float)(Main.npc[num256].width / 2);
									float num258 = Main.npc[num256].position.Y + (float)(Main.npc[num256].height / 2);
									float num259 = Math.Abs(this.position.X + (float)(this.width / 2) - num257) + Math.Abs(this.position.Y + (float)(this.height / 2) - num258);
									if (num259 < num255 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num256].position, Main.npc[num256].width, Main.npc[num256].height))
									{
										num255 = num259;
										num253 = num257;
										num254 = num258;
										flag5 = true;
									}
								}
							}
						}
						if (!flag5)
						{
							num253 = this.position.X + (float)(this.width / 2) + this.velocity.X * 100f;
							num254 = this.position.Y + (float)(this.height / 2) + this.velocity.Y * 100f;
						}
						float num260 = 16f;
						Vector2 vector20 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num261 = num253 - vector20.X;
						float num262 = num254 - vector20.Y;
						float num263 = (float)Math.Sqrt((double)(num261 * num261 + num262 * num262));
						num263 = num260 / num263;
						num261 *= num263;
						num262 *= num263;
						this.velocity.X = (this.velocity.X * 11f + num261) / 12f;
						this.velocity.Y = (this.velocity.Y * 11f + num262) / 12f;
					}
					else if (this.type == 134 || this.type == 137 || this.type == 140 || this.type == 143 || this.type == 303)
					{
						if (Math.Abs(this.velocity.X) >= 8f || Math.Abs(this.velocity.Y) >= 8f)
						{
							for (int num264 = 0; num264 < 2; num264++)
							{
								float num265 = 0f;
								float num266 = 0f;
								if (num264 == 1)
								{
									num265 = this.velocity.X * 0.5f;
									num266 = this.velocity.Y * 0.5f;
								}
								int num267 = Dust.NewDust(new Vector2(this.position.X + 3f + num265, this.position.Y + 3f + num266) - this.velocity * 0.5f, this.width - 8, this.height - 8, 6, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num267].scale *= 2f + (float)Main.rand.Next(10) * 0.1f;
								Main.dust[num267].velocity *= 0.2f;
								Main.dust[num267].noGravity = true;
								num267 = Dust.NewDust(new Vector2(this.position.X + 3f + num265, this.position.Y + 3f + num266) - this.velocity * 0.5f, this.width - 8, this.height - 8, 31, 0f, 0f, 100, default(Color), 0.5f);
								Main.dust[num267].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f;
								Main.dust[num267].velocity *= 0.05f;
							}
						}
						if (Math.Abs(this.velocity.X) < 15f && Math.Abs(this.velocity.Y) < 15f)
						{
							this.velocity *= 1.1f;
						}
					}
					else if (this.type == 133 || this.type == 136 || this.type == 139 || this.type == 142)
					{
						int num268 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1f);
						Main.dust[num268].scale *= 1f + (float)Main.rand.Next(10) * 0.1f;
						Main.dust[num268].velocity *= 0.2f;
						Main.dust[num268].noGravity = true;
					}
					else if (this.type == 135 || this.type == 138 || this.type == 141 || this.type == 144)
					{
						if ((double)this.velocity.X > -0.2 && (double)this.velocity.X < 0.2 && (double)this.velocity.Y > -0.2 && (double)this.velocity.Y < 0.2)
						{
							this.alpha += 2;
							if (this.alpha > 200)
							{
								this.alpha = 200;
							}
						}
						else
						{
							this.alpha = 0;
							int num269 = Dust.NewDust(new Vector2(this.position.X + 3f, this.position.Y + 3f) - this.velocity * 0.5f, this.width - 8, this.height - 8, 31, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num269].scale *= 1.6f + (float)Main.rand.Next(5) * 0.1f;
							Main.dust[num269].velocity *= 0.05f;
							Main.dust[num269].noGravity = true;
						}
					}
					else if (this.type != 30 && this.type != 397 && Main.rand.Next(2) == 0)
					{
						int num270 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1f);
						Main.dust[num270].scale = 0.1f + (float)Main.rand.Next(5) * 0.1f;
						Main.dust[num270].fadeIn = 1.5f + (float)Main.rand.Next(5) * 0.1f;
						Main.dust[num270].noGravity = true;
						Main.dust[num270].position = this.center() + new Vector2(0f, (float)(-(float)this.height / 2)).Rotate((double)this.rotation, default(Vector2)) * 1.1f;
						Main.rand.Next(2);
						num270 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
						Main.dust[num270].scale = 1f + (float)Main.rand.Next(5) * 0.1f;
						Main.dust[num270].noGravity = true;
						Main.dust[num270].position = this.center() + new Vector2(0f, (float)(-(float)this.height / 2 - 6)).Rotate((double)this.rotation, default(Vector2)) * 1.1f;
					}
				}
				this.ai[0] += 1f;
				if (this.type == 338 || this.type == 339 || this.type == 340 || this.type == 341)
				{
					if (this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
						this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X)) - 1.57f;
					}
					else
					{
						this.spriteDirection = 1;
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
					}
				}
				else if (this.type == 134 || this.type == 137 || this.type == 140 || this.type == 143 || this.type == 303)
				{
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
				}
				else if (this.type == 135 || this.type == 138 || this.type == 141 || this.type == 144)
				{
					this.velocity.Y = this.velocity.Y + 0.2f;
					this.velocity *= 0.97f;
					if ((double)this.velocity.X > -0.1 && (double)this.velocity.X < 0.1)
					{
						this.velocity.X = 0f;
					}
					if ((double)this.velocity.Y > -0.1 && (double)this.velocity.Y < 0.1)
					{
						this.velocity.Y = 0f;
					}
				}
				else if (this.type == 133 || this.type == 136 || this.type == 139 || this.type == 142)
				{
					if (this.ai[0] > 15f)
					{
						if (this.velocity.Y == 0f)
						{
							this.velocity.X = this.velocity.X * 0.95f;
						}
						this.velocity.Y = this.velocity.Y + 0.2f;
					}
				}
				else if (((this.type == 30 || this.type == 397) && this.ai[0] > 10f) || (this.type != 30 && this.type != 397 && this.ai[0] > 5f))
				{
					this.ai[0] = 10f;
					if (this.velocity.Y == 0f && this.velocity.X != 0f)
					{
						this.velocity.X = this.velocity.X * 0.97f;
						if (this.type == 29)
						{
							this.velocity.X = this.velocity.X * 0.99f;
						}
						if ((double)this.velocity.X > -0.01 && (double)this.velocity.X < 0.01)
						{
							this.velocity.X = 0f;
							this.netUpdate = true;
						}
					}
					this.velocity.Y = this.velocity.Y + 0.2f;
				}
				if (this.type != 134 && this.type != 137 && this.type != 140 && this.type != 143 && this.type != 303 && (this.type < 338 || this.type > 341))
				{
					this.rotation += this.velocity.X * 0.1f;
				}
			}
			else if (this.aiStyle == 17)
			{
				if (this.velocity.Y == 0f)
				{
					this.velocity.X = this.velocity.X * 0.98f;
				}
				this.rotation += this.velocity.X * 0.1f;
				this.velocity.Y = this.velocity.Y + 0.2f;
				if (this.owner == Main.myPlayer)
				{
					int num271 = (int)((this.position.X + (float)(this.width / 2)) / 16f);
					int num272 = (int)((this.position.Y + (float)this.height - 4f) / 16f);
					if (Main.tile[num271, num272] != null && !Main.tile[num271, num272].active())
					{
						int num273 = 0;
						if (this.type >= 201 && this.type <= 205)
						{
							num273 = this.type - 200;
						}
						WorldGen.PlaceTile(num271, num272, 85, false, false, this.owner, num273);
						if (Main.tile[num271, num272].active())
						{
							if (Main.netMode != 0)
							{
								NetMessage.SendData(17, -1, -1, "", 1, (float)num271, (float)num272, 85f, num273);
							}
							int num274 = Sign.ReadSign(num271, num272);
							if (num274 >= 0)
							{
								Sign.TextSign(num274, this.miscText);
							}
							this.Kill();
						}
					}
				}
			}
			else if (this.aiStyle == 18)
			{
				if (this.ai[1] == 0f && this.type == 44)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
				}
				if (this.type == 263 || this.type == 274)
				{
					if (this.type == 274 && this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
					}
					this.rotation += (float)this.direction * 0.05f;
					this.rotation += (float)this.direction * 0.5f * ((float)this.timeLeft / 180f);
					if (this.type == 274)
					{
						this.velocity *= 0.96f;
					}
					else
					{
						this.velocity *= 0.95f;
					}
				}
				else
				{
					this.rotation += (float)this.direction * 0.8f;
					this.ai[0] += 1f;
					if (this.ai[0] >= 30f)
					{
						if (this.ai[0] < 100f)
						{
							this.velocity *= 1.06f;
						}
						else
						{
							this.ai[0] = 200f;
						}
					}
					for (int num275 = 0; num275 < 2; num275++)
					{
						int num276 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 27, 0f, 0f, 100, default(Color), 1f);
						Main.dust[num276].noGravity = true;
					}
				}
			}
			else if (this.aiStyle == 19)
			{
				this.direction = Main.player[this.owner].direction;
				Main.player[this.owner].heldProj = this.whoAmI;
				Main.player[this.owner].itemTime = Main.player[this.owner].itemAnimation;
				this.position.X = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - (float)(this.width / 2);
				this.position.Y = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - (float)(this.height / 2);
				if (!Main.player[this.owner].frozen)
				{
					if (this.type == 46)
					{
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.6f;
						}
						else
						{
							this.ai[0] += 1.4f;
						}
					}
					else if (this.type == 105)
					{
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 2.4f;
						}
						else
						{
							this.ai[0] += 2.1f;
						}
					}
					else if (this.type == 367)
					{
						this.spriteDirection = -this.direction;
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.6f;
						}
						else
						{
							this.ai[0] += 1.5f;
						}
					}
					else if (this.type == 368)
					{
						this.spriteDirection = -this.direction;
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.5f;
						}
						else
						{
							this.ai[0] += 1.4f;
						}
					}
					else if (this.type == 222)
					{
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 2.4f;
							if (this.localAI[0] == 0f && Main.myPlayer == this.owner)
							{
								this.localAI[0] = 1f;
								Projectile.NewProjectile(this.center().X + this.velocity.X * this.ai[0], this.center().Y + this.velocity.Y * this.ai[0], this.velocity.X, this.velocity.Y, 228, this.damage, this.knockBack, this.owner, 0f, 0f);
							}
						}
						else
						{
							this.ai[0] += 2.1f;
						}
					}
					else if (this.type == 342)
					{
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 2.4f;
							if (this.localAI[0] == 0f && Main.myPlayer == this.owner)
							{
								this.localAI[0] = 1f;
								if (Collision.CanHit(Main.player[this.owner].position, Main.player[this.owner].width, Main.player[this.owner].height, new Vector2(this.center().X + this.velocity.X * this.ai[0], this.center().Y + this.velocity.Y * this.ai[0]), this.width, this.height))
								{
									Projectile.NewProjectile(this.center().X + this.velocity.X * this.ai[0], this.center().Y + this.velocity.Y * this.ai[0], this.velocity.X * 2.4f, this.velocity.Y * 2.4f, 343, (int)((double)this.damage * 0.8), this.knockBack * 0.85f, this.owner, 0f, 0f);
								}
							}
						}
						else
						{
							this.ai[0] += 2.1f;
						}
					}
					else if (this.type == 47)
					{
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 4f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.2f;
						}
						else
						{
							this.ai[0] += 0.9f;
						}
					}
					else if (this.type == 153)
					{
						this.spriteDirection = -this.direction;
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 4f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.5f;
						}
						else
						{
							this.ai[0] += 1.3f;
						}
					}
					else if (this.type == 49)
					{
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 4f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.1f;
						}
						else
						{
							this.ai[0] += 0.85f;
						}
					}
					else if (this.type == 64 || this.type == 215)
					{
						this.spriteDirection = -this.direction;
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.9f;
						}
						else
						{
							this.ai[0] += 1.7f;
						}
					}
					else if (this.type == 66 || this.type == 97 || this.type == 212 || this.type == 218)
					{
						this.spriteDirection = -this.direction;
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 2.1f;
						}
						else
						{
							this.ai[0] += 1.9f;
						}
					}
					else if (this.type == 130)
					{
						this.spriteDirection = -this.direction;
						if (this.ai[0] == 0f)
						{
							this.ai[0] = 3f;
							this.netUpdate = true;
						}
						if (Main.player[this.owner].itemAnimation < Main.player[this.owner].itemAnimationMax / 3)
						{
							this.ai[0] -= 1.3f;
						}
						else
						{
							this.ai[0] += 1f;
						}
					}
				}
				this.position += this.velocity * this.ai[0];
				if (this.type == 130)
				{
					if (this.ai[1] == 0f || this.ai[1] == 4f || this.ai[1] == 8f || this.ai[1] == 12f || this.ai[1] == 16f || this.ai[1] == 20f || this.ai[1] == 24f)
					{
						Projectile.NewProjectile(this.position.X + (float)(this.width / 2), this.position.Y + (float)(this.height / 2), this.velocity.X, this.velocity.Y, 131, this.damage / 3, 0f, this.owner, 0f, 0f);
					}
					this.ai[1] += 1f;
				}
				if (Main.player[this.owner].itemAnimation == 0)
				{
					this.Kill();
				}
				this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 2.355f;
				if (this.spriteDirection == -1)
				{
					this.rotation -= 1.57f;
				}
				if (this.type == 46)
				{
					if (Main.rand.Next(5) == 0)
					{
						Dust.NewDust(this.position, this.width, this.height, 14, 0f, 0f, 150, default(Color), 1.4f);
					}
					int num277 = Dust.NewDust(this.position, this.width, this.height, 27, this.velocity.X * 0.2f + (float)(this.direction * 3), this.velocity.Y * 0.2f, 100, default(Color), 1.2f);
					Main.dust[num277].noGravity = true;
					Dust expr_D417_cp_0 = Main.dust[num277];
					expr_D417_cp_0.velocity.X = expr_D417_cp_0.velocity.X / 2f;
					Dust expr_D437_cp_0 = Main.dust[num277];
					expr_D437_cp_0.velocity.Y = expr_D437_cp_0.velocity.Y / 2f;
					num277 = Dust.NewDust(this.position - this.velocity * 2f, this.width, this.height, 27, 0f, 0f, 150, default(Color), 1.4f);
					Dust expr_D4AB_cp_0 = Main.dust[num277];
					expr_D4AB_cp_0.velocity.X = expr_D4AB_cp_0.velocity.X / 5f;
					Dust expr_D4CB_cp_0 = Main.dust[num277];
					expr_D4CB_cp_0.velocity.Y = expr_D4CB_cp_0.velocity.Y / 5f;
				}
				else if (this.type == 105)
				{
					if (Main.rand.Next(3) == 0)
					{
						int num278 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 57, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 200, default(Color), 1.2f);
						Main.dust[num278].velocity += this.velocity * 0.3f;
						Main.dust[num278].velocity *= 0.2f;
					}
					if (Main.rand.Next(4) == 0)
					{
						int num279 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 43, 0f, 0f, 254, default(Color), 0.3f);
						Main.dust[num279].velocity += this.velocity * 0.5f;
						Main.dust[num279].velocity *= 0.5f;
					}
				}
				else if (this.type == 153)
				{
					int num280 = Dust.NewDust(this.position - this.velocity * 3f, this.width, this.height, 115, this.velocity.X * 0.4f, this.velocity.Y * 0.4f, 140, default(Color), 1f);
					Main.dust[num280].noGravity = true;
					Main.dust[num280].fadeIn = 1.25f;
					Main.dust[num280].velocity *= 0.25f;
				}
			}
			else if (this.aiStyle == 20)
			{
				if (this.type == 252)
				{
					this.frameCounter++;
					if (this.frameCounter >= 4)
					{
						this.frameCounter = 0;
						this.frame++;
					}
					if (this.frame > 3)
					{
						this.frame = 0;
					}
				}
				if (this.soundDelay <= 0)
				{
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 22);
					this.soundDelay = 30;
				}
				if (Main.myPlayer == this.owner)
				{
					if (Main.player[this.owner].channel)
					{
						float num281 = Main.player[this.owner].inventory[Main.player[this.owner].selectedItem].shootSpeed * this.scale;
						Vector2 vector21 = new Vector2(Main.player[this.owner].position.X + (float)Main.player[this.owner].width * 0.5f, Main.player[this.owner].position.Y + (float)Main.player[this.owner].height * 0.5f);
						float num282 = (float)Main.mouseX + Main.screenPosition.X - vector21.X;
						float num283 = (float)Main.mouseY + Main.screenPosition.Y - vector21.Y;
						if (Main.player[this.owner].gravDir == -1f)
						{
							num283 = (float)(Main.screenHeight - Main.mouseY) + Main.screenPosition.Y - vector21.Y;
						}
						float num284 = (float)Math.Sqrt((double)(num282 * num282 + num283 * num283));
						num284 = (float)Math.Sqrt((double)(num282 * num282 + num283 * num283));
						num284 = num281 / num284;
						num282 *= num284;
						num283 *= num284;
						if (num282 != this.velocity.X || num283 != this.velocity.Y)
						{
							this.netUpdate = true;
						}
						this.velocity.X = num282;
						this.velocity.Y = num283;
					}
					else
					{
						this.Kill();
					}
				}
				if (this.velocity.X > 0f)
				{
					Main.player[this.owner].ChangeDir(1);
				}
				else if (this.velocity.X < 0f)
				{
					Main.player[this.owner].ChangeDir(-1);
				}
				this.spriteDirection = this.direction;
				Main.player[this.owner].ChangeDir(this.direction);
				Main.player[this.owner].heldProj = this.whoAmI;
				Main.player[this.owner].itemTime = 2;
				Main.player[this.owner].itemAnimation = 2;
				this.position.X = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - (float)(this.width / 2);
				this.position.Y = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - (float)(this.height / 2);
				this.rotation = (float)(Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.5700000524520874);
				if (Main.player[this.owner].direction == 1)
				{
					Main.player[this.owner].itemRotation = (float)Math.Atan2((double)(this.velocity.Y * (float)this.direction), (double)(this.velocity.X * (float)this.direction));
				}
				else
				{
					Main.player[this.owner].itemRotation = (float)Math.Atan2((double)(this.velocity.Y * (float)this.direction), (double)(this.velocity.X * (float)this.direction));
				}
				this.velocity.X = this.velocity.X * (1f + (float)Main.rand.Next(-3, 4) * 0.01f);
				if (Main.rand.Next(6) == 0)
				{
					int num285 = Dust.NewDust(this.position + this.velocity * (float)Main.rand.Next(6, 10) * 0.1f, this.width, this.height, 31, 0f, 0f, 80, default(Color), 1.4f);
					Dust expr_DC36_cp_0 = Main.dust[num285];
					expr_DC36_cp_0.position.X = expr_DC36_cp_0.position.X - 4f;
					Main.dust[num285].noGravity = true;
					Main.dust[num285].velocity *= 0.2f;
					Main.dust[num285].velocity.Y = (float)(-(float)Main.rand.Next(7, 13)) * 0.15f;
				}
			}
			else if (this.aiStyle == 21)
			{
				this.rotation = this.velocity.X * 0.1f;
				this.spriteDirection = -this.direction;
				if (Main.rand.Next(3) == 0)
				{
					int num286 = Dust.NewDust(this.position, this.width, this.height, 27, 0f, 0f, 80, default(Color), 1f);
					Main.dust[num286].noGravity = true;
					Main.dust[num286].velocity *= 0.2f;
				}
				if (this.ai[1] == 1f)
				{
					this.ai[1] = 0f;
					Main.harpNote = this.ai[0];
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 26);
				}
			}
			else if (this.aiStyle == 22)
			{
				if (this.velocity.X == 0f && this.velocity.Y == 0f)
				{
					this.alpha = 255;
				}
				if (this.ai[1] < 0f)
				{
					if (this.velocity.X > 0f)
					{
						this.rotation += 0.3f;
					}
					else
					{
						this.rotation -= 0.3f;
					}
					int num287 = (int)(this.position.X / 16f) - 1;
					int num288 = (int)((this.position.X + (float)this.width) / 16f) + 2;
					int num289 = (int)(this.position.Y / 16f) - 1;
					int num290 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
					if (num287 < 0)
					{
						num287 = 0;
					}
					if (num288 > Main.maxTilesX)
					{
						num288 = Main.maxTilesX;
					}
					if (num289 < 0)
					{
						num289 = 0;
					}
					if (num290 > Main.maxTilesY)
					{
						num290 = Main.maxTilesY;
					}
					int num291 = (int)this.position.X + 4;
					int num292 = (int)this.position.Y + 4;
					for (int num293 = num287; num293 < num288; num293++)
					{
						for (int num294 = num289; num294 < num290; num294++)
						{
							if (Main.tile[num293, num294] != null && Main.tile[num293, num294].active() && Main.tile[num293, num294].type != 127 && Main.tileSolid[(int)Main.tile[num293, num294].type] && !Main.tileSolidTop[(int)Main.tile[num293, num294].type])
							{
								Vector2 vector22;
								vector22.X = (float)(num293 * 16);
								vector22.Y = (float)(num294 * 16);
								if ((float)(num291 + 8) > vector22.X && (float)num291 < vector22.X + 16f && (float)(num292 + 8) > vector22.Y && (float)num292 < vector22.Y + 16f)
								{
									this.Kill();
								}
							}
						}
					}
					int num295 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 67, 0f, 0f, 0, default(Color), 1f);
					Main.dust[num295].noGravity = true;
					Main.dust[num295].velocity *= 0.3f;
				}
				else if (this.ai[0] < 0f)
				{
					if (this.ai[0] == -1f)
					{
						for (int num296 = 0; num296 < 10; num296++)
						{
							int num297 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 67, 0f, 0f, 0, default(Color), 1.1f);
							Main.dust[num297].noGravity = true;
							Main.dust[num297].velocity *= 1.3f;
						}
					}
					else if (Main.rand.Next(30) == 0)
					{
						int num298 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 67, 0f, 0f, 100, default(Color), 1f);
						Main.dust[num298].velocity *= 0.2f;
					}
					int num299 = (int)this.position.X / 16;
					int num300 = (int)this.position.Y / 16;
					if (Main.tile[num299, num300] == null || !Main.tile[num299, num300].active())
					{
						this.Kill();
					}
					this.ai[0] -= 1f;
					if (this.ai[0] <= -300f && (Main.myPlayer == this.owner || Main.netMode == 2) && Main.tile[num299, num300].active() && Main.tile[num299, num300].type == 127)
					{
						WorldGen.KillTile(num299, num300, false, false, false);
						if (Main.netMode == 1)
						{
							NetMessage.SendData(17, -1, -1, "", 0, (float)num299, (float)num300, 0f, 0);
						}
						this.Kill();
					}
				}
				else
				{
					int num301 = (int)(this.position.X / 16f) - 1;
					int num302 = (int)((this.position.X + (float)this.width) / 16f) + 2;
					int num303 = (int)(this.position.Y / 16f) - 1;
					int num304 = (int)((this.position.Y + (float)this.height) / 16f) + 2;
					if (num301 < 0)
					{
						num301 = 0;
					}
					if (num302 > Main.maxTilesX)
					{
						num302 = Main.maxTilesX;
					}
					if (num303 < 0)
					{
						num303 = 0;
					}
					if (num304 > Main.maxTilesY)
					{
						num304 = Main.maxTilesY;
					}
					int num305 = (int)this.position.X + 4;
					int num306 = (int)this.position.Y + 4;
					for (int num307 = num301; num307 < num302; num307++)
					{
						for (int num308 = num303; num308 < num304; num308++)
						{
							if (Main.tile[num307, num308] != null && Main.tile[num307, num308].nactive() && Main.tile[num307, num308].type != 127 && Main.tileSolid[(int)Main.tile[num307, num308].type] && !Main.tileSolidTop[(int)Main.tile[num307, num308].type])
							{
								Vector2 vector23;
								vector23.X = (float)(num307 * 16);
								vector23.Y = (float)(num308 * 16);
								if ((float)(num305 + 8) > vector23.X && (float)num305 < vector23.X + 16f && (float)(num306 + 8) > vector23.Y && (float)num306 < vector23.Y + 16f)
								{
									this.Kill();
								}
							}
						}
					}
					if (this.lavaWet)
					{
						this.Kill();
					}
					if (this.active)
					{
						int num309 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 67, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num309].noGravity = true;
						Main.dust[num309].velocity *= 0.3f;
						int num310 = (int)this.ai[0];
						int num311 = (int)this.ai[1];
						if (this.velocity.X > 0f)
						{
							this.rotation += 0.3f;
						}
						else
						{
							this.rotation -= 0.3f;
						}
						if (Main.myPlayer == this.owner)
						{
							int num312 = (int)((this.position.X + (float)(this.width / 2)) / 16f);
							int num313 = (int)((this.position.Y + (float)(this.height / 2)) / 16f);
							bool flag6 = false;
							if (num312 == num310 && num313 == num311)
							{
								flag6 = true;
							}
							if (((this.velocity.X <= 0f && num312 <= num310) || (this.velocity.X >= 0f && num312 >= num310)) && ((this.velocity.Y <= 0f && num313 <= num311) || (this.velocity.Y >= 0f && num313 >= num311)))
							{
								flag6 = true;
							}
							if (flag6)
							{
								if (WorldGen.PlaceTile(num310, num311, 127, false, false, this.owner, 0))
								{
									if (Main.netMode == 1)
									{
										NetMessage.SendData(17, -1, -1, "", 1, (float)((int)this.ai[0]), (float)((int)this.ai[1]), 127f, 0);
									}
									this.damage = 0;
									this.ai[0] = -1f;
									this.velocity *= 0f;
									this.alpha = 255;
									this.position.X = (float)(num310 * 16);
									this.position.Y = (float)(num311 * 16);
									this.netUpdate = true;
								}
								else
								{
									this.ai[1] = -1f;
								}
							}
						}
					}
				}
			}
			else if (this.aiStyle == 23)
			{
				if (this.type == 188 && this.ai[0] < 8f)
				{
					this.ai[0] = 8f;
				}
				if (this.timeLeft > 60)
				{
					this.timeLeft = 60;
				}
				if (this.ai[0] > 7f)
				{
					float num314 = 1f;
					if (this.ai[0] == 8f)
					{
						num314 = 0.25f;
					}
					else if (this.ai[0] == 9f)
					{
						num314 = 0.5f;
					}
					else if (this.ai[0] == 10f)
					{
						num314 = 0.75f;
					}
					this.ai[0] += 1f;
					int num315 = 6;
					if (this.type == 101)
					{
						num315 = 75;
					}
					if (num315 == 6 || Main.rand.Next(2) == 0)
					{
						for (int num316 = 0; num316 < 1; num316++)
						{
							int num317 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, num315, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 1f);
							if (Main.rand.Next(3) != 0 || (num315 == 75 && Main.rand.Next(3) == 0))
							{
								Main.dust[num317].noGravity = true;
								Main.dust[num317].scale *= 3f;
								Dust expr_E9B8_cp_0 = Main.dust[num317];
								expr_E9B8_cp_0.velocity.X = expr_E9B8_cp_0.velocity.X * 2f;
								Dust expr_E9D8_cp_0 = Main.dust[num317];
								expr_E9D8_cp_0.velocity.Y = expr_E9D8_cp_0.velocity.Y * 2f;
							}
							if (this.type == 188)
							{
								Main.dust[num317].scale *= 1.25f;
							}
							else
							{
								Main.dust[num317].scale *= 1.5f;
							}
							Dust expr_EA3D_cp_0 = Main.dust[num317];
							expr_EA3D_cp_0.velocity.X = expr_EA3D_cp_0.velocity.X * 1.2f;
							Dust expr_EA5D_cp_0 = Main.dust[num317];
							expr_EA5D_cp_0.velocity.Y = expr_EA5D_cp_0.velocity.Y * 1.2f;
							Main.dust[num317].scale *= num314;
							if (num315 == 75)
							{
								Main.dust[num317].velocity += this.velocity;
								if (!Main.dust[num317].noGravity)
								{
									Main.dust[num317].velocity *= 0.5f;
								}
							}
						}
					}
				}
				else
				{
					this.ai[0] += 1f;
				}
				this.rotation += 0.3f * (float)this.direction;
			}
			else if (this.aiStyle == 24)
			{
				this.light = this.scale * 0.5f;
				this.rotation += this.velocity.X * 0.2f;
				this.ai[1] += 1f;
				if (this.type == 94)
				{
					if (Main.rand.Next(4) == 0)
					{
						int num318 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 70, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num318].noGravity = true;
						Main.dust[num318].velocity *= 0.5f;
						Main.dust[num318].scale *= 0.9f;
					}
					this.velocity *= 0.985f;
					if (this.ai[1] > 130f)
					{
						this.scale -= 0.05f;
						if ((double)this.scale <= 0.2)
						{
							this.scale = 0.2f;
							this.Kill();
						}
					}
				}
				else
				{
					this.velocity *= 0.96f;
					if (this.ai[1] > 15f)
					{
						this.scale -= 0.05f;
						if ((double)this.scale <= 0.2)
						{
							this.scale = 0.2f;
							this.Kill();
						}
					}
				}
			}
			else if (this.aiStyle == 25)
			{
				if (this.ai[0] != 0f && this.velocity.Y <= 0f && this.velocity.X == 0f)
				{
					float num319 = 0.5f;
					int i2 = (int)((this.position.X - 8f) / 16f);
					int num320 = (int)(this.position.Y / 16f);
					bool flag7 = false;
					bool flag8 = false;
					if (WorldGen.SolidTile(i2, num320) || WorldGen.SolidTile(i2, num320 + 1))
					{
						flag7 = true;
					}
					i2 = (int)((this.position.X + (float)this.width + 8f) / 16f);
					if (WorldGen.SolidTile(i2, num320) || WorldGen.SolidTile(i2, num320 + 1))
					{
						flag8 = true;
					}
					if (flag7)
					{
						this.velocity.X = num319;
					}
					else if (flag8)
					{
						this.velocity.X = -num319;
					}
					else
					{
						i2 = (int)((this.position.X - 8f - 16f) / 16f);
						num320 = (int)(this.position.Y / 16f);
						flag7 = false;
						flag8 = false;
						if (WorldGen.SolidTile(i2, num320) || WorldGen.SolidTile(i2, num320 + 1))
						{
							flag7 = true;
						}
						i2 = (int)((this.position.X + (float)this.width + 8f + 16f) / 16f);
						if (WorldGen.SolidTile(i2, num320) || WorldGen.SolidTile(i2, num320 + 1))
						{
							flag8 = true;
						}
						if (flag7)
						{
							this.velocity.X = num319;
						}
						else if (flag8)
						{
							this.velocity.X = -num319;
						}
						else
						{
							i2 = (int)((this.position.X + 4f) / 16f);
							num320 = (int)((this.position.Y + (float)this.height + 8f) / 16f);
							if (WorldGen.SolidTile(i2, num320) || WorldGen.SolidTile(i2, num320 + 1))
							{
								flag7 = true;
							}
							if (!flag7)
							{
								this.velocity.X = num319;
							}
							else
							{
								this.velocity.X = -num319;
							}
						}
					}
				}
				this.rotation += this.velocity.X * 0.06f;
				this.ai[0] = 1f;
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
				if (this.velocity.Y <= 6f)
				{
					if (this.velocity.X > 0f && this.velocity.X < 7f)
					{
						this.velocity.X = this.velocity.X + 0.05f;
					}
					if (this.velocity.X < 0f && this.velocity.X > -7f)
					{
						this.velocity.X = this.velocity.X - 0.05f;
					}
				}
				this.velocity.Y = this.velocity.Y + 0.3f;
			}
			else if (this.aiStyle == 26)
			{
				if (!Main.player[this.owner].active)
				{
					this.active = false;
					return;
				}
				bool flag9 = false;
				bool flag10 = false;
				bool flag11 = false;
				bool flag12 = false;
				int num321 = 85;
				if (this.type == 324)
				{
					num321 = 120;
				}
				if (this.type == 112)
				{
					num321 = 100;
				}
				if (this.type == 127)
				{
					num321 = 50;
				}
				if (this.type >= 191 && this.type <= 194)
				{
					if (this.lavaWet)
					{
						this.ai[0] = 1f;
						this.ai[1] = 0f;
					}
					num321 = 60 + 30 * this.minionPos;
				}
				else if (this.type == 266)
				{
					num321 = 60 + 30 * this.minionPos;
				}
				if (this.type == 111)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].bunny = false;
					}
					if (Main.player[this.owner].bunny)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 112)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].penguin = false;
					}
					if (Main.player[this.owner].penguin)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 334)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].puppy = false;
					}
					if (Main.player[this.owner].puppy)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 353)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].grinch = false;
					}
					if (Main.player[this.owner].grinch)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 127)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].turtle = false;
					}
					if (Main.player[this.owner].turtle)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 175)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].eater = false;
					}
					if (Main.player[this.owner].eater)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 197)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].skeletron = false;
					}
					if (Main.player[this.owner].skeletron)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 198)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].hornet = false;
					}
					if (Main.player[this.owner].hornet)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 199)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].tiki = false;
					}
					if (Main.player[this.owner].tiki)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 200)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].lizard = false;
					}
					if (Main.player[this.owner].lizard)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 208)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].parrot = false;
					}
					if (Main.player[this.owner].parrot)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 209)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].truffle = false;
					}
					if (Main.player[this.owner].truffle)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 210)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].sapling = false;
					}
					if (Main.player[this.owner].sapling)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 324)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].cSapling = false;
					}
					if (Main.player[this.owner].cSapling)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 313)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].spider = false;
					}
					if (Main.player[this.owner].spider)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 314)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].squashling = false;
					}
					if (Main.player[this.owner].squashling)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 211)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].wisp = false;
					}
					if (Main.player[this.owner].wisp)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 236)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].dino = false;
					}
					if (Main.player[this.owner].dino)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 266)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].slime = false;
					}
					if (Main.player[this.owner].slime)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 268)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].eyeSpring = false;
					}
					if (Main.player[this.owner].eyeSpring)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 269)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].snowman = false;
					}
					if (Main.player[this.owner].snowman)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 319)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].blackCat = false;
					}
					if (Main.player[this.owner].blackCat)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 380)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].zephyrfish = false;
					}
					if (Main.player[this.owner].zephyrfish)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type >= 191 && this.type <= 194)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].pygmy = false;
					}
					if (Main.player[this.owner].pygmy)
					{
						this.timeLeft = Main.rand.Next(2, 10);
					}
				}
				if (this.type >= 390 && this.type <= 392)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].spiderMinion = false;
					}
					if (Main.player[this.owner].spiderMinion)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 398)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].miniMinotaur = false;
					}
					if (Main.player[this.owner].miniMinotaur)
					{
						this.timeLeft = 2;
					}
				}
				if ((this.type >= 191 && this.type <= 194) || this.type == 266 || (this.type >= 390 && this.type <= 392))
				{
					num321 = 10;
					int num322 = 40 * (this.minionPos + 1) * Main.player[this.owner].direction;
					if (Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) < this.position.X + (float)(this.width / 2) - (float)num321 + (float)num322)
					{
						flag9 = true;
					}
					else if (Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) > this.position.X + (float)(this.width / 2) + (float)num321 + (float)num322)
					{
						flag10 = true;
					}
				}
				else if (Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) < this.position.X + (float)(this.width / 2) - (float)num321)
				{
					flag9 = true;
				}
				else if (Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) > this.position.X + (float)(this.width / 2) + (float)num321)
				{
					flag10 = true;
				}
				if (this.type == 175)
				{
					float num323 = 0.1f;
					this.tileCollide = false;
					int num324 = 300;
					Vector2 vector24 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num325 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector24.X;
					float num326 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector24.Y;
					if (this.type == 127)
					{
						num326 = Main.player[this.owner].position.Y - vector24.Y;
					}
					float num327 = (float)Math.Sqrt((double)(num325 * num325 + num326 * num326));
					float num328 = 7f;
					if (num327 < (float)num324 && Main.player[this.owner].velocity.Y == 0f && this.position.Y + (float)this.height <= Main.player[this.owner].position.Y + (float)Main.player[this.owner].height && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						if (this.velocity.Y < -6f)
						{
							this.velocity.Y = -6f;
						}
					}
					if (num327 < 150f)
					{
						if (Math.Abs(this.velocity.X) > 2f || Math.Abs(this.velocity.Y) > 2f)
						{
							this.velocity *= 0.99f;
						}
						num323 = 0.01f;
						if (num325 < -2f)
						{
							num325 = -2f;
						}
						if (num325 > 2f)
						{
							num325 = 2f;
						}
						if (num326 < -2f)
						{
							num326 = -2f;
						}
						if (num326 > 2f)
						{
							num326 = 2f;
						}
					}
					else
					{
						if (num327 > 300f)
						{
							num323 = 0.2f;
						}
						num327 = num328 / num327;
						num325 *= num327;
						num326 *= num327;
					}
					if (Math.Abs(num325) > Math.Abs(num326) || num323 == 0.05f)
					{
						if (this.velocity.X < num325)
						{
							this.velocity.X = this.velocity.X + num323;
							if (num323 > 0.05f && this.velocity.X < 0f)
							{
								this.velocity.X = this.velocity.X + num323;
							}
						}
						if (this.velocity.X > num325)
						{
							this.velocity.X = this.velocity.X - num323;
							if (num323 > 0.05f && this.velocity.X > 0f)
							{
								this.velocity.X = this.velocity.X - num323;
							}
						}
					}
					if (Math.Abs(num325) <= Math.Abs(num326) || num323 == 0.05f)
					{
						if (this.velocity.Y < num326)
						{
							this.velocity.Y = this.velocity.Y + num323;
							if (num323 > 0.05f && this.velocity.Y < 0f)
							{
								this.velocity.Y = this.velocity.Y + num323;
							}
						}
						if (this.velocity.Y > num326)
						{
							this.velocity.Y = this.velocity.Y - num323;
							if (num323 > 0.05f && this.velocity.Y > 0f)
							{
								this.velocity.Y = this.velocity.Y - num323;
							}
						}
					}
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) - 1.57f;
					this.frameCounter++;
					if (this.frameCounter > 6)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame > 1)
					{
						this.frame = 0;
					}
				}
				else if (this.type == 197)
				{
					float num329 = 0.1f;
					this.tileCollide = false;
					int num330 = 300;
					Vector2 vector25 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num331 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector25.X;
					float num332 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector25.Y;
					if (this.type == 127)
					{
						num332 = Main.player[this.owner].position.Y - vector25.Y;
					}
					float num333 = (float)Math.Sqrt((double)(num331 * num331 + num332 * num332));
					float num334 = 3f;
					if (num333 > 500f)
					{
						this.localAI[0] = 10000f;
					}
					if (this.localAI[0] >= 10000f)
					{
						num334 = 14f;
					}
					if (num333 < (float)num330 && Main.player[this.owner].velocity.Y == 0f && this.position.Y + (float)this.height <= Main.player[this.owner].position.Y + (float)Main.player[this.owner].height && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						if (this.velocity.Y < -6f)
						{
							this.velocity.Y = -6f;
						}
					}
					if (num333 < 150f)
					{
						if (Math.Abs(this.velocity.X) > 2f || Math.Abs(this.velocity.Y) > 2f)
						{
							this.velocity *= 0.99f;
						}
						num329 = 0.01f;
						if (num331 < -2f)
						{
							num331 = -2f;
						}
						if (num331 > 2f)
						{
							num331 = 2f;
						}
						if (num332 < -2f)
						{
							num332 = -2f;
						}
						if (num332 > 2f)
						{
							num332 = 2f;
						}
					}
					else
					{
						if (num333 > 300f)
						{
							num329 = 0.2f;
						}
						num333 = num334 / num333;
						num331 *= num333;
						num332 *= num333;
					}
					if (this.velocity.X < num331)
					{
						this.velocity.X = this.velocity.X + num329;
						if (num329 > 0.05f && this.velocity.X < 0f)
						{
							this.velocity.X = this.velocity.X + num329;
						}
					}
					if (this.velocity.X > num331)
					{
						this.velocity.X = this.velocity.X - num329;
						if (num329 > 0.05f && this.velocity.X > 0f)
						{
							this.velocity.X = this.velocity.X - num329;
						}
					}
					if (this.velocity.Y < num332)
					{
						this.velocity.Y = this.velocity.Y + num329;
						if (num329 > 0.05f && this.velocity.Y < 0f)
						{
							this.velocity.Y = this.velocity.Y + num329;
						}
					}
					if (this.velocity.Y > num332)
					{
						this.velocity.Y = this.velocity.Y - num329;
						if (num329 > 0.05f && this.velocity.Y > 0f)
						{
							this.velocity.Y = this.velocity.Y - num329;
						}
					}
					this.localAI[0] += (float)Main.rand.Next(10);
					if (this.localAI[0] > 10000f)
					{
						if (this.localAI[1] == 0f)
						{
							if (this.velocity.X < 0f)
							{
								this.localAI[1] = -1f;
							}
							else
							{
								this.localAI[1] = 1f;
							}
						}
						this.rotation += 0.25f * this.localAI[1];
						if (this.localAI[0] > 12000f)
						{
							this.localAI[0] = 0f;
						}
					}
					else
					{
						this.localAI[1] = 0f;
						float num335 = this.velocity.X * 0.1f;
						if (this.rotation > num335)
						{
							this.rotation -= (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.01f;
							if (this.rotation < num335)
							{
								this.rotation = num335;
							}
						}
						if (this.rotation < num335)
						{
							this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.01f;
							if (this.rotation > num335)
							{
								this.rotation = num335;
							}
						}
					}
					if ((double)this.rotation > 6.28)
					{
						this.rotation -= 6.28f;
					}
					if ((double)this.rotation < -6.28)
					{
						this.rotation += 6.28f;
					}
				}
				else if (this.type == 198 || this.type == 380)
				{
					float num336 = 0.4f;
					if (this.type == 380)
					{
						num336 = 0.3f;
					}
					this.tileCollide = false;
					int num337 = 100;
					Vector2 vector26 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num338 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector26.X;
					float num339 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector26.Y;
					num339 += (float)Main.rand.Next(-10, 21);
					num338 += (float)Main.rand.Next(-10, 21);
					num338 += (float)(60 * -(float)Main.player[this.owner].direction);
					num339 -= 60f;
					if (this.type == 127)
					{
						num339 = Main.player[this.owner].position.Y - vector26.Y;
					}
					float num340 = (float)Math.Sqrt((double)(num338 * num338 + num339 * num339));
					float num341 = 14f;
					if (this.type == 380)
					{
						num341 = 6f;
					}
					if (num340 < (float)num337 && Main.player[this.owner].velocity.Y == 0f && this.position.Y + (float)this.height <= Main.player[this.owner].position.Y + (float)Main.player[this.owner].height && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						if (this.velocity.Y < -6f)
						{
							this.velocity.Y = -6f;
						}
					}
					if (num340 < 50f)
					{
						if (Math.Abs(this.velocity.X) > 2f || Math.Abs(this.velocity.Y) > 2f)
						{
							this.velocity *= 0.99f;
						}
						num336 = 0.01f;
					}
					else
					{
						if (this.type == 380)
						{
							if (num340 < 100f)
							{
								num336 = 0.1f;
							}
							if (num340 > 300f)
							{
								num336 = 0.4f;
							}
						}
						else if (this.type == 198)
						{
							if (num340 < 100f)
							{
								num336 = 0.1f;
							}
							if (num340 > 300f)
							{
								num336 = 0.6f;
							}
						}
						num340 = num341 / num340;
						num338 *= num340;
						num339 *= num340;
					}
					if (this.velocity.X < num338)
					{
						this.velocity.X = this.velocity.X + num336;
						if (num336 > 0.05f && this.velocity.X < 0f)
						{
							this.velocity.X = this.velocity.X + num336;
						}
					}
					if (this.velocity.X > num338)
					{
						this.velocity.X = this.velocity.X - num336;
						if (num336 > 0.05f && this.velocity.X > 0f)
						{
							this.velocity.X = this.velocity.X - num336;
						}
					}
					if (this.velocity.Y < num339)
					{
						this.velocity.Y = this.velocity.Y + num336;
						if (num336 > 0.05f && this.velocity.Y < 0f)
						{
							this.velocity.Y = this.velocity.Y + num336 * 2f;
						}
					}
					if (this.velocity.Y > num339)
					{
						this.velocity.Y = this.velocity.Y - num336;
						if (num336 > 0.05f && this.velocity.Y > 0f)
						{
							this.velocity.Y = this.velocity.Y - num336 * 2f;
						}
					}
					if ((double)this.velocity.X > 0.25)
					{
						this.direction = -1;
					}
					else if ((double)this.velocity.X < -0.25)
					{
						this.direction = 1;
					}
					this.spriteDirection = this.direction;
					this.rotation = this.velocity.X * 0.05f;
					this.frameCounter++;
					int num342 = 2;
					if (this.type == 380)
					{
						num342 = 5;
					}
					if (this.frameCounter > num342)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame > 3)
					{
						this.frame = 0;
					}
				}
				else if (this.type == 211)
				{
					float num343 = 0.2f;
					float num344 = 5f;
					this.tileCollide = false;
					Vector2 vector27 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num345 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector27.X;
					float num346 = Main.player[this.owner].position.Y + Main.player[this.owner].gfxOffY + (float)(Main.player[this.owner].height / 2) - vector27.Y;
					if (Main.player[this.owner].controlLeft)
					{
						num345 -= 120f;
					}
					else if (Main.player[this.owner].controlRight)
					{
						num345 += 120f;
					}
					if (Main.player[this.owner].controlDown)
					{
						num346 += 120f;
					}
					else
					{
						if (Main.player[this.owner].controlUp)
						{
							num346 -= 120f;
						}
						num346 -= 60f;
					}
					float num347 = (float)Math.Sqrt((double)(num345 * num345 + num346 * num346));
					if (num347 > 1000f)
					{
						this.position.X = this.position.X + num345;
						this.position.Y = this.position.Y + num346;
					}
					if (this.localAI[0] == 1f)
					{
						if (num347 < 10f && Math.Abs(Main.player[this.owner].velocity.X) + Math.Abs(Main.player[this.owner].velocity.Y) < num344 && Main.player[this.owner].velocity.Y == 0f)
						{
							this.localAI[0] = 0f;
						}
						num344 = 12f;
						if (num347 < num344)
						{
							this.velocity.X = num345;
							this.velocity.Y = num346;
						}
						else
						{
							num347 = num344 / num347;
							this.velocity.X = num345 * num347;
							this.velocity.Y = num346 * num347;
						}
						if ((double)this.velocity.X > 0.5)
						{
							this.direction = -1;
						}
						else if ((double)this.velocity.X < -0.5)
						{
							this.direction = 1;
						}
						this.spriteDirection = this.direction;
						this.rotation -= (0.2f + Math.Abs(this.velocity.X) * 0.025f) * (float)this.direction;
						this.frameCounter++;
						if (this.frameCounter > 3)
						{
							this.frame++;
							this.frameCounter = 0;
						}
						if (this.frame < 5)
						{
							this.frame = 5;
						}
						if (this.frame > 9)
						{
							this.frame = 5;
						}
						for (int num348 = 0; num348 < 2; num348++)
						{
							int num349 = Dust.NewDust(new Vector2(this.position.X + 3f, this.position.Y + 4f), 14, 14, 156, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num349].velocity *= 0.2f;
							Main.dust[num349].noGravity = true;
							Main.dust[num349].scale = 1.25f;
						}
					}
					else
					{
						if (num347 > 200f)
						{
							this.localAI[0] = 1f;
						}
						if ((double)this.velocity.X > 0.5)
						{
							this.direction = -1;
						}
						else if ((double)this.velocity.X < -0.5)
						{
							this.direction = 1;
						}
						this.spriteDirection = this.direction;
						if (num347 < 10f)
						{
							this.velocity.X = num345;
							this.velocity.Y = num346;
							this.rotation = this.velocity.X * 0.05f;
							if (num347 < num344)
							{
								this.position += this.velocity;
								this.velocity *= 0f;
								num343 = 0f;
							}
							this.direction = -Main.player[this.owner].direction;
						}
						num347 = num344 / num347;
						num345 *= num347;
						num346 *= num347;
						if (this.velocity.X < num345)
						{
							this.velocity.X = this.velocity.X + num343;
							if (this.velocity.X < 0f)
							{
								this.velocity.X = this.velocity.X * 0.99f;
							}
						}
						if (this.velocity.X > num345)
						{
							this.velocity.X = this.velocity.X - num343;
							if (this.velocity.X > 0f)
							{
								this.velocity.X = this.velocity.X * 0.99f;
							}
						}
						if (this.velocity.Y < num346)
						{
							this.velocity.Y = this.velocity.Y + num343;
							if (this.velocity.Y < 0f)
							{
								this.velocity.Y = this.velocity.Y * 0.99f;
							}
						}
						if (this.velocity.Y > num346)
						{
							this.velocity.Y = this.velocity.Y - num343;
							if (this.velocity.Y > 0f)
							{
								this.velocity.Y = this.velocity.Y * 0.99f;
							}
						}
						if (this.velocity.X != 0f || this.velocity.Y != 0f)
						{
							this.rotation = this.velocity.X * 0.05f;
						}
						this.frameCounter++;
						if (this.frameCounter > 3)
						{
							this.frame++;
							this.frameCounter = 0;
						}
						if (this.frame > 4)
						{
							this.frame = 0;
						}
					}
				}
				else if (this.type == 199)
				{
					float num350 = 0.1f;
					this.tileCollide = false;
					int num351 = 200;
					Vector2 vector28 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num352 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector28.X;
					float num353 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector28.Y;
					num353 -= 60f;
					num352 -= 2f;
					if (this.type == 127)
					{
						num353 = Main.player[this.owner].position.Y - vector28.Y;
					}
					float num354 = (float)Math.Sqrt((double)(num352 * num352 + num353 * num353));
					float num355 = 4f;
					float num356 = num354;
					if (num354 < (float)num351 && Main.player[this.owner].velocity.Y == 0f && this.position.Y + (float)this.height <= Main.player[this.owner].position.Y + (float)Main.player[this.owner].height && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						if (this.velocity.Y < -6f)
						{
							this.velocity.Y = -6f;
						}
					}
					if (num354 < 4f)
					{
						this.velocity.X = num352;
						this.velocity.Y = num353;
						num350 = 0f;
					}
					else
					{
						if (num354 > 350f)
						{
							num350 = 0.2f;
							num355 = 10f;
						}
						num354 = num355 / num354;
						num352 *= num354;
						num353 *= num354;
					}
					if (this.velocity.X < num352)
					{
						this.velocity.X = this.velocity.X + num350;
						if (this.velocity.X < 0f)
						{
							this.velocity.X = this.velocity.X + num350;
						}
					}
					if (this.velocity.X > num352)
					{
						this.velocity.X = this.velocity.X - num350;
						if (this.velocity.X > 0f)
						{
							this.velocity.X = this.velocity.X - num350;
						}
					}
					if (this.velocity.Y < num353)
					{
						this.velocity.Y = this.velocity.Y + num350;
						if (this.velocity.Y < 0f)
						{
							this.velocity.Y = this.velocity.Y + num350;
						}
					}
					if (this.velocity.Y > num353)
					{
						this.velocity.Y = this.velocity.Y - num350;
						if (this.velocity.Y > 0f)
						{
							this.velocity.Y = this.velocity.Y - num350;
						}
					}
					this.direction = -Main.player[this.owner].direction;
					this.spriteDirection = 1;
					this.rotation = this.velocity.Y * 0.05f * (float)(-(float)this.direction);
					if (num356 >= 50f)
					{
						this.frameCounter++;
						if (this.frameCounter > 6)
						{
							this.frameCounter = 0;
							if (this.velocity.X < 0f)
							{
								if (this.frame < 2)
								{
									this.frame++;
								}
								if (this.frame > 2)
								{
									this.frame--;
								}
							}
							else
							{
								if (this.frame < 6)
								{
									this.frame++;
								}
								if (this.frame > 6)
								{
									this.frame--;
								}
							}
						}
					}
					else
					{
						this.frameCounter++;
						if (this.frameCounter > 6)
						{
							this.frame += this.direction;
							this.frameCounter = 0;
						}
						if (this.frame > 7)
						{
							this.frame = 0;
						}
						if (this.frame < 0)
						{
							this.frame = 7;
						}
					}
				}
				else
				{
					if (this.ai[1] == 0f)
					{
						int num357 = 500;
						if (this.type == 127)
						{
							num357 = 200;
						}
						if (this.type == 208)
						{
							num357 = 300;
						}
						if ((this.type >= 191 && this.type <= 194) || this.type == 266 || (this.type >= 390 && this.type <= 392))
						{
							num357 += 40 * this.minionPos;
							if (this.localAI[0] > 0f)
							{
								num357 += 500;
							}
							if (this.type == 266 && this.localAI[0] > 0f)
							{
								num357 += 100;
							}
						}
						if (Main.player[this.owner].rocketDelay2 > 0)
						{
							this.ai[0] = 1f;
						}
						Vector2 vector29 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num358 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector29.X;
						if (this.type >= 191)
						{
							int arg_11967_0 = this.type;
						}
						float num359 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector29.Y;
						float num360 = (float)Math.Sqrt((double)(num358 * num358 + num359 * num359));
						if (num360 > 2000f)
						{
							this.position.X = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - (float)(this.width / 2);
							this.position.Y = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - (float)(this.height / 2);
						}
						else if (num360 > (float)num357 || (Math.Abs(num359) > 300f && (((this.type < 191 || this.type > 194) && this.type != 266 && (this.type < 390 || this.type > 392)) || this.localAI[0] <= 0f)))
						{
							if (this.type != 324)
							{
								if (num359 > 0f && this.velocity.Y < 0f)
								{
									this.velocity.Y = 0f;
								}
								if (num359 < 0f && this.velocity.Y > 0f)
								{
									this.velocity.Y = 0f;
								}
							}
							this.ai[0] = 1f;
						}
					}
					if (this.type == 209 && this.ai[0] != 0f)
					{
						if (Main.player[this.owner].velocity.Y == 0f && this.alpha >= 100)
						{
							this.position.X = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - (float)(this.width / 2);
							this.position.Y = Main.player[this.owner].position.Y + (float)Main.player[this.owner].height - (float)this.height;
							this.ai[0] = 0f;
						}
						else
						{
							this.velocity.X = 0f;
							this.velocity.Y = 0f;
							this.alpha += 5;
							if (this.alpha > 255)
							{
								this.alpha = 255;
							}
						}
					}
					else if (this.ai[0] != 0f)
					{
						float num361 = 0.2f;
						int num362 = 200;
						if (this.type == 127)
						{
							num362 = 100;
						}
						if (this.type >= 191 && this.type <= 194)
						{
							num361 = 0.5f;
							num362 = 100;
						}
						this.tileCollide = false;
						Vector2 vector30 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num363 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector30.X;
						if ((this.type >= 191 && this.type <= 194) || this.type == 266 || (this.type >= 390 && this.type <= 392))
						{
							num363 -= (float)(40 * Main.player[this.owner].direction);
							float num364 = 600f;
							bool flag13 = false;
							for (int num365 = 0; num365 < 200; num365++)
							{
								if (Main.npc[num365].active && !Main.npc[num365].dontTakeDamage && !Main.npc[num365].friendly && Main.npc[num365].lifeMax > 5)
								{
									float num366 = Main.npc[num365].position.X + (float)(Main.npc[num365].width / 2);
									float num367 = Main.npc[num365].position.Y + (float)(Main.npc[num365].height / 2);
									float num368 = Math.Abs(Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - num366) + Math.Abs(Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - num367);
									if (num368 < num364)
									{
										flag13 = true;
										break;
									}
								}
							}
							if (!flag13)
							{
								num363 -= (float)(40 * this.minionPos * Main.player[this.owner].direction);
							}
						}
						float num369 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector30.Y;
						if (this.type == 127)
						{
							num369 = Main.player[this.owner].position.Y - vector30.Y;
						}
						float num370 = (float)Math.Sqrt((double)(num363 * num363 + num369 * num369));
						float num371 = 10f;
						float num372 = num370;
						if (this.type == 111)
						{
							num371 = 11f;
						}
						if (this.type == 127)
						{
							num371 = 9f;
						}
						if (this.type == 324)
						{
							num371 = 20f;
						}
						if (this.type >= 191 && this.type <= 194)
						{
							num361 = 0.4f;
							num371 = 12f;
							if (num371 < Math.Abs(Main.player[this.owner].velocity.X) + Math.Abs(Main.player[this.owner].velocity.Y))
							{
								num371 = Math.Abs(Main.player[this.owner].velocity.X) + Math.Abs(Main.player[this.owner].velocity.Y);
							}
						}
						if (this.type == 208 && Math.Abs(Main.player[this.owner].velocity.X) + Math.Abs(Main.player[this.owner].velocity.Y) > 4f)
						{
							num362 = -1;
						}
						if (num370 < (float)num362 && Main.player[this.owner].velocity.Y == 0f && this.position.Y + (float)this.height <= Main.player[this.owner].position.Y + (float)Main.player[this.owner].height && !Collision.SolidCollision(this.position, this.width, this.height))
						{
							this.ai[0] = 0f;
							if (this.velocity.Y < -6f)
							{
								this.velocity.Y = -6f;
							}
						}
						if (num370 < 60f)
						{
							num363 = this.velocity.X;
							num369 = this.velocity.Y;
						}
						else
						{
							num370 = num371 / num370;
							num363 *= num370;
							num369 *= num370;
						}
						if (this.type == 324)
						{
							if (num372 > 1000f)
							{
								if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) < (double)num371 - 1.25)
								{
									this.velocity *= 1.025f;
								}
								if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) > (double)num371 + 1.25)
								{
									this.velocity *= 0.975f;
								}
							}
							else if (num372 > 600f)
							{
								if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) < num371 - 1f)
								{
									this.velocity *= 1.05f;
								}
								if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) > num371 + 1f)
								{
									this.velocity *= 0.95f;
								}
							}
							else if (num372 > 400f)
							{
								if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) < (double)num371 - 0.5)
								{
									this.velocity *= 1.075f;
								}
								if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) > (double)num371 + 0.5)
								{
									this.velocity *= 0.925f;
								}
							}
							else
							{
								if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) < (double)num371 - 0.25)
								{
									this.velocity *= 1.1f;
								}
								if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) > (double)num371 + 0.25)
								{
									this.velocity *= 0.9f;
								}
							}
							this.velocity.X = (this.velocity.X * 34f + num363) / 35f;
							this.velocity.Y = (this.velocity.Y * 34f + num369) / 35f;
						}
						else
						{
							if (this.velocity.X < num363)
							{
								this.velocity.X = this.velocity.X + num361;
								if (this.velocity.X < 0f)
								{
									this.velocity.X = this.velocity.X + num361 * 1.5f;
								}
							}
							if (this.velocity.X > num363)
							{
								this.velocity.X = this.velocity.X - num361;
								if (this.velocity.X > 0f)
								{
									this.velocity.X = this.velocity.X - num361 * 1.5f;
								}
							}
							if (this.velocity.Y < num369)
							{
								this.velocity.Y = this.velocity.Y + num361;
								if (this.velocity.Y < 0f)
								{
									this.velocity.Y = this.velocity.Y + num361 * 1.5f;
								}
							}
							if (this.velocity.Y > num369)
							{
								this.velocity.Y = this.velocity.Y - num361;
								if (this.velocity.Y > 0f)
								{
									this.velocity.Y = this.velocity.Y - num361 * 1.5f;
								}
							}
						}
						if (this.type == 111)
						{
							this.frame = 7;
						}
						if (this.type == 112)
						{
							this.frame = 2;
						}
						if (this.type >= 191 && this.type <= 194 && this.frame < 12)
						{
							this.frame = Main.rand.Next(12, 18);
							this.frameCounter = 0;
						}
						if (this.type != 313)
						{
							if ((double)this.velocity.X > 0.5)
							{
								this.spriteDirection = -1;
							}
							else if ((double)this.velocity.X < -0.5)
							{
								this.spriteDirection = 1;
							}
						}
						if (this.type == 398)
						{
							if ((double)this.velocity.X > 0.5)
							{
								this.spriteDirection = 1;
							}
							else if ((double)this.velocity.X < -0.5)
							{
								this.spriteDirection = -1;
							}
						}
						if (this.type == 112)
						{
							if (this.spriteDirection == -1)
							{
								this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
							}
							else
							{
								this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
							}
						}
						else if (this.type >= 390 && this.type <= 392)
						{
							int num373 = (int)(this.center().X / 16f);
							int num374 = (int)(this.center().Y / 16f);
							if (Main.tile[num373, num374] != null && Main.tile[num373, num374].wall > 0)
							{
								this.rotation = this.velocity.ToRotation() + 1.57079637f;
								this.frameCounter += (int)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y));
								if (this.frameCounter > 5)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame > 7)
								{
									this.frame = 4;
								}
								if (this.frame < 4)
								{
									this.frame = 7;
								}
							}
							else
							{
								this.frameCounter++;
								if (this.frameCounter > 2)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame < 8 || this.frame > 10)
								{
									this.frame = 8;
								}
								this.rotation = this.velocity.X * 0.1f;
							}
						}
						else if (this.type == 334)
						{
							this.frameCounter++;
							if (this.frameCounter > 1)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame < 7 || this.frame > 10)
							{
								this.frame = 7;
							}
							this.rotation = this.velocity.X * 0.1f;
						}
						else if (this.type == 353)
						{
							this.frameCounter++;
							if (this.frameCounter > 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame < 10 || this.frame > 13)
							{
								this.frame = 10;
							}
							this.rotation = this.velocity.X * 0.05f;
						}
						else if (this.type == 127)
						{
							this.frameCounter += 3;
							if (this.frameCounter > 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame <= 5 || this.frame > 15)
							{
								this.frame = 6;
							}
							this.rotation = this.velocity.X * 0.1f;
						}
						else if (this.type == 269)
						{
							if (this.frame == 6)
							{
								this.frameCounter = 0;
							}
							else if (this.frame < 4 || this.frame > 6)
							{
								this.frameCounter = 0;
								this.frame = 4;
							}
							else
							{
								this.frameCounter++;
								if (this.frameCounter > 6)
								{
									this.frame++;
									this.frameCounter = 0;
								}
							}
							this.rotation = this.velocity.X * 0.05f;
						}
						else if (this.type == 266)
						{
							this.frameCounter++;
							if (this.frameCounter > 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame < 2 || this.frame > 5)
							{
								this.frame = 2;
							}
							this.rotation = this.velocity.X * 0.1f;
						}
						else if (this.type == 324)
						{
							this.frameCounter++;
							if (this.frameCounter > 1)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame < 6 || this.frame > 9)
							{
								this.frame = 6;
							}
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.58f;
							Lighting.addLight((int)this.center().X / 16, (int)this.center().Y / 16, 0.9f, 0.6f, 0.2f);
							for (int num375 = 0; num375 < 2; num375++)
							{
								int num376 = 4;
								int num377 = Dust.NewDust(new Vector2(this.center().X - (float)num376, this.center().Y - (float)num376) - this.velocity * 0f, num376 * 2, num376 * 2, 6, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num377].scale *= 1.8f + (float)Main.rand.Next(10) * 0.1f;
								Main.dust[num377].velocity *= 0.2f;
								if (num375 == 1)
								{
									Main.dust[num377].position -= this.velocity * 0.5f;
								}
								Main.dust[num377].noGravity = true;
								num377 = Dust.NewDust(new Vector2(this.center().X - (float)num376, this.center().Y - (float)num376) - this.velocity * 0f, num376 * 2, num376 * 2, 31, 0f, 0f, 100, default(Color), 0.5f);
								Main.dust[num377].fadeIn = 1f + (float)Main.rand.Next(5) * 0.1f;
								Main.dust[num377].velocity *= 0.05f;
								if (num375 == 1)
								{
									Main.dust[num377].position -= this.velocity * 0.5f;
								}
							}
						}
						else if (this.type == 268)
						{
							this.frameCounter++;
							if (this.frameCounter > 4)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame < 6 || this.frame > 7)
							{
								this.frame = 6;
							}
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.58f;
						}
						else if (this.type == 200)
						{
							this.frameCounter += 3;
							if (this.frameCounter > 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame <= 5 || this.frame > 9)
							{
								this.frame = 6;
							}
							this.rotation = this.velocity.X * 0.1f;
						}
						else if (this.type == 208)
						{
							this.rotation = this.velocity.X * 0.075f;
							this.frameCounter++;
							if (this.frameCounter > 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame > 4)
							{
								this.frame = 1;
							}
							if (this.frame < 1)
							{
								this.frame = 1;
							}
						}
						else if (this.type == 236)
						{
							this.rotation = this.velocity.Y * 0.05f * (float)this.direction;
							if (this.velocity.Y < 0f)
							{
								this.frameCounter += 2;
							}
							else
							{
								this.frameCounter++;
							}
							if (this.frameCounter >= 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame > 12)
							{
								this.frame = 9;
							}
							if (this.frame < 9)
							{
								this.frame = 9;
							}
						}
						else if (this.type == 314)
						{
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.58f;
							this.frameCounter++;
							if (this.frameCounter >= 3)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame > 12)
							{
								this.frame = 7;
							}
							if (this.frame < 7)
							{
								this.frame = 7;
							}
						}
						else if (this.type == 319)
						{
							this.rotation = this.velocity.X * 0.05f;
							this.frameCounter++;
							if (this.frameCounter >= 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame > 10)
							{
								this.frame = 6;
							}
							if (this.frame < 6)
							{
								this.frame = 6;
							}
						}
						else if (this.type == 210)
						{
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.58f;
							this.frameCounter += 3;
							if (this.frameCounter > 6)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame > 11)
							{
								this.frame = 7;
							}
							if (this.frame < 7)
							{
								this.frame = 7;
							}
						}
						else if (this.type == 313)
						{
							this.position.Y = this.position.Y + (float)this.height;
							this.height = 54;
							this.position.Y = this.position.Y - (float)this.height;
							this.position.X = this.position.X + (float)(this.width / 2);
							this.width = 54;
							this.position.X = this.position.X - (float)(this.width / 2);
							this.rotation += this.velocity.X * 0.01f;
							this.frameCounter = 0;
							this.frame = 11;
						}
						else if (this.type == 398)
						{
							this.frameCounter++;
							if (this.frameCounter > 1)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame < 6 || this.frame > 9)
							{
								this.frame = 6;
							}
							this.rotation = this.velocity.X * 0.1f;
						}
						else if (this.spriteDirection == -1)
						{
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
						}
						else
						{
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 3.14f;
						}
						if ((this.type < 191 || this.type > 194) && this.type != 398 && this.type != 390 && this.type != 391 && this.type != 392 && this.type != 127 && this.type != 200 && this.type != 208 && this.type != 210 && this.type != 236 && this.type != 266 && this.type != 268 && this.type != 269 && this.type != 313 && this.type != 314 && this.type != 319 && this.type != 324 && this.type != 334 && this.type != 353)
						{
							int num378 = Dust.NewDust(new Vector2(this.position.X + (float)(this.width / 2) - 4f, this.position.Y + (float)(this.height / 2) - 4f) - this.velocity, 8, 8, 16, -this.velocity.X * 0.5f, this.velocity.Y * 0.5f, 50, default(Color), 1.7f);
							Main.dust[num378].velocity.X = Main.dust[num378].velocity.X * 0.2f;
							Main.dust[num378].velocity.Y = Main.dust[num378].velocity.Y * 0.2f;
							Main.dust[num378].noGravity = true;
						}
					}
					else
					{
						if (this.type >= 191 && this.type <= 194)
						{
							float num379 = (float)(40 * this.minionPos);
							int num380 = 30;
							int num381 = 60;
							this.localAI[0] -= 1f;
							if (this.localAI[0] < 0f)
							{
								this.localAI[0] = 0f;
							}
							if (this.ai[1] > 0f)
							{
								this.ai[1] -= 1f;
							}
							else
							{
								float num382 = this.position.X;
								float num383 = this.position.Y;
								float num384 = 100000f;
								float num385 = num384;
								int num386 = -1;
								for (int num387 = 0; num387 < 200; num387++)
								{
									if (Main.npc[num387].active && !Main.npc[num387].dontTakeDamage && !Main.npc[num387].friendly && Main.npc[num387].lifeMax > 5)
									{
										float num388 = Main.npc[num387].position.X + (float)(Main.npc[num387].width / 2);
										float num389 = Main.npc[num387].position.Y + (float)(Main.npc[num387].height / 2);
										float num390 = Math.Abs(this.position.X + (float)(this.width / 2) - num388) + Math.Abs(this.position.Y + (float)(this.height / 2) - num389);
										if (num390 < num384)
										{
											if (num386 == -1 && num390 <= num385)
											{
												num385 = num390;
												num382 = num388;
												num383 = num389;
											}
											if (Collision.CanHit(this.position, this.width, this.height, Main.npc[num387].position, Main.npc[num387].width, Main.npc[num387].height))
											{
												num384 = num390;
												num382 = num388;
												num383 = num389;
												num386 = num387;
											}
										}
									}
								}
								if (num386 == -1 && num385 < num384)
								{
									num384 = num385;
								}
								float num391 = 400f;
								if ((double)this.position.Y > Main.worldSurface * 16.0)
								{
									num391 = 200f;
								}
								if (num384 < num391 + num379 && num386 == -1)
								{
									float num392 = num382 - (this.position.X + (float)(this.width / 2));
									if (num392 < -5f)
									{
										flag9 = true;
										flag10 = false;
									}
									else if (num392 > 5f)
									{
										flag10 = true;
										flag9 = false;
									}
								}
								else if (num386 >= 0 && num384 < 800f + num379)
								{
									this.localAI[0] = (float)num381;
									float num393 = num382 - (this.position.X + (float)(this.width / 2));
									if (num393 > 300f || num393 < -300f)
									{
										if (num393 < -50f)
										{
											flag9 = true;
											flag10 = false;
										}
										else if (num393 > 50f)
										{
											flag10 = true;
											flag9 = false;
										}
									}
									else if (this.owner == Main.myPlayer)
									{
										this.ai[1] = (float)num380;
										float num394 = 12f;
										Vector2 vector31 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)(this.height / 2) - 8f);
										float num395 = num382 - vector31.X + (float)Main.rand.Next(-20, 21);
										float num396 = Math.Abs(num395) * 0.1f;
										num396 = num396 * (float)Main.rand.Next(0, 100) * 0.001f;
										float num397 = num383 - vector31.Y + (float)Main.rand.Next(-20, 21) - num396;
										float num398 = (float)Math.Sqrt((double)(num395 * num395 + num397 * num397));
										num398 = num394 / num398;
										num395 *= num398;
										num397 *= num398;
										int num399 = this.damage;
										int num400 = 195;
										int num401 = Projectile.NewProjectile(vector31.X, vector31.Y, num395, num397, num400, num399, this.knockBack, Main.myPlayer, 0f, 0f);
										Main.projectile[num401].timeLeft = 300;
										if (num395 < 0f)
										{
											this.direction = -1;
										}
										if (num395 > 0f)
										{
											this.direction = 1;
										}
										this.netUpdate = true;
									}
								}
							}
						}
						bool flag14 = false;
						Vector2 vector32 = Vector2.Zero;
						if (this.type == 266 || (this.type >= 390 && this.type <= 392))
						{
							float num402 = (float)(40 * this.minionPos);
							int num403 = 60;
							this.localAI[0] -= 1f;
							if (this.localAI[0] < 0f)
							{
								this.localAI[0] = 0f;
							}
							if (this.ai[1] > 0f)
							{
								this.ai[1] -= 1f;
							}
							else
							{
								float num404 = this.position.X;
								float num405 = this.position.Y;
								float num406 = 100000f;
								float num407 = num406;
								int num408 = -1;
								for (int num409 = 0; num409 < 200; num409++)
								{
									if (Main.npc[num409].active && !Main.npc[num409].dontTakeDamage && !Main.npc[num409].friendly && Main.npc[num409].lifeMax > 5)
									{
										float num410 = Main.npc[num409].position.X + (float)(Main.npc[num409].width / 2);
										float num411 = Main.npc[num409].position.Y + (float)(Main.npc[num409].height / 2);
										float num412 = Math.Abs(this.position.X + (float)(this.width / 2) - num410) + Math.Abs(this.position.Y + (float)(this.height / 2) - num411);
										if (num412 < num406)
										{
											if (num408 == -1 && num412 <= num407)
											{
												num407 = num412;
												num404 = num410;
												num405 = num411;
											}
											if (Collision.CanHit(this.position, this.width, this.height, Main.npc[num409].position, Main.npc[num409].width, Main.npc[num409].height))
											{
												num406 = num412;
												num404 = num410;
												num405 = num411;
												num408 = num409;
											}
										}
									}
								}
								if (num408 == -1 && num407 < num406)
								{
									num406 = num407;
								}
								else if (num408 >= 0)
								{
									flag14 = true;
									vector32 = new Vector2(num404, num405) - this.center();
								}
								float num413 = 300f;
								if ((double)this.position.Y > Main.worldSurface * 16.0)
								{
									num413 = 150f;
								}
								if (this.type >= 390 && this.type <= 392)
								{
									num413 = 500f;
									if ((double)this.position.Y > Main.worldSurface * 16.0)
									{
										num413 = 250f;
									}
								}
								if (num406 < num413 + num402 && num408 == -1)
								{
									float num414 = num404 - (this.position.X + (float)(this.width / 2));
									if (num414 < -5f)
									{
										flag9 = true;
										flag10 = false;
									}
									else if (num414 > 5f)
									{
										flag10 = true;
										flag9 = false;
									}
								}
								bool flag15 = false;
								if (this.type >= 390 && this.type <= 392 && this.localAI[1] > 0f)
								{
									flag15 = true;
									this.localAI[1] -= 1f;
								}
								if (num408 >= 0 && num406 < 800f + num402)
								{
									this.friendly = true;
									this.localAI[0] = (float)num403;
									float num415 = num404 - (this.position.X + (float)(this.width / 2));
									if (num415 < -10f)
									{
										flag9 = true;
										flag10 = false;
									}
									else if (num415 > 10f)
									{
										flag10 = true;
										flag9 = false;
									}
									if (num405 < this.center().Y - 100f && num415 > -50f && num415 < 50f && this.velocity.Y == 0f)
									{
										float num416 = Math.Abs(num405 - this.center().Y);
										if (num416 < 120f)
										{
											this.velocity.Y = -10f;
										}
										else if (num416 < 210f)
										{
											this.velocity.Y = -13f;
										}
										else if (num416 < 270f)
										{
											this.velocity.Y = -15f;
										}
										else if (num416 < 310f)
										{
											this.velocity.Y = -17f;
										}
										else if (num416 < 380f)
										{
											this.velocity.Y = -18f;
										}
									}
									if (flag15)
									{
										this.friendly = false;
										if (this.velocity.X < 0f)
										{
											flag9 = true;
										}
										else if (this.velocity.X > 0f)
										{
											flag10 = true;
										}
									}
								}
								else
								{
									this.friendly = false;
								}
							}
						}
						if (this.ai[1] != 0f)
						{
							flag9 = false;
							flag10 = false;
						}
						else if (this.type >= 191 && this.type <= 194 && this.localAI[0] == 0f)
						{
							this.direction = Main.player[this.owner].direction;
						}
						else if (this.type >= 390 && this.type <= 392)
						{
							int num417 = (int)(this.center().X / 16f);
							int num418 = (int)(this.center().Y / 16f);
							if (Main.tile[num417, num418] != null && Main.tile[num417, num418].wall > 0)
							{
								flag10 = (flag9 = false);
							}
						}
						if (this.type == 127)
						{
							if ((double)this.rotation > -0.1 && (double)this.rotation < 0.1)
							{
								this.rotation = 0f;
							}
							else if (this.rotation < 0f)
							{
								this.rotation += 0.1f;
							}
							else
							{
								this.rotation -= 0.1f;
							}
						}
						else if (this.type != 313)
						{
							this.rotation = 0f;
						}
						this.tileCollide = true;
						float num419 = 0.08f;
						float num420 = 6.5f;
						if (this.type == 127)
						{
							num420 = 2f;
							num419 = 0.04f;
						}
						if (this.type == 112)
						{
							num420 = 6f;
							num419 = 0.06f;
						}
						if (this.type == 334)
						{
							num420 = 8f;
							num419 = 0.08f;
						}
						if (this.type == 268)
						{
							num420 = 8f;
							num419 = 0.4f;
						}
						if (this.type == 324)
						{
							num419 = 0.1f;
							num420 = 3f;
						}
						if ((this.type >= 191 && this.type <= 194) || this.type == 266 || (this.type >= 390 && this.type <= 392))
						{
							num420 = 6f;
							num419 = 0.2f;
							if (num420 < Math.Abs(Main.player[this.owner].velocity.X) + Math.Abs(Main.player[this.owner].velocity.Y))
							{
								num420 = Math.Abs(Main.player[this.owner].velocity.X) + Math.Abs(Main.player[this.owner].velocity.Y);
								num419 = 0.3f;
							}
						}
						if (this.type >= 390 && this.type <= 392)
						{
							num419 *= 2f;
						}
						if (flag9)
						{
							if ((double)this.velocity.X > -3.5)
							{
								this.velocity.X = this.velocity.X - num419;
							}
							else
							{
								this.velocity.X = this.velocity.X - num419 * 0.25f;
							}
						}
						else if (flag10)
						{
							if ((double)this.velocity.X < 3.5)
							{
								this.velocity.X = this.velocity.X + num419;
							}
							else
							{
								this.velocity.X = this.velocity.X + num419 * 0.25f;
							}
						}
						else
						{
							this.velocity.X = this.velocity.X * 0.9f;
							if (this.velocity.X >= -num419 && this.velocity.X <= num419)
							{
								this.velocity.X = 0f;
							}
						}
						if (this.type == 208)
						{
							this.velocity.X = this.velocity.X * 0.95f;
							if ((double)this.velocity.X > -0.1 && (double)this.velocity.X < 0.1)
							{
								this.velocity.X = 0f;
							}
							flag9 = false;
							flag10 = false;
						}
						if (flag9 || flag10)
						{
							int num421 = (int)(this.position.X + (float)(this.width / 2)) / 16;
							int j2 = (int)(this.position.Y + (float)(this.height / 2)) / 16;
							if (this.type == 236)
							{
								num421 += this.direction;
							}
							if (flag9)
							{
								num421--;
							}
							if (flag10)
							{
								num421++;
							}
							num421 += (int)this.velocity.X;
							if (WorldGen.SolidTile(num421, j2))
							{
								flag12 = true;
							}
						}
						if (Main.player[this.owner].position.Y + (float)Main.player[this.owner].height - 8f > this.position.Y + (float)this.height)
						{
							flag11 = true;
						}
						if (this.type == 268 && this.frameCounter < 10)
						{
							flag12 = false;
						}
						Collision.StepUp(ref this.position, ref this.velocity, this.width, this.height, ref this.stepSpeed, ref this.gfxOffY, 1, false);
						if (this.velocity.Y == 0f || this.type == 200)
						{
							if (!flag11 && (this.velocity.X < 0f || this.velocity.X > 0f))
							{
								int num422 = (int)(this.position.X + (float)(this.width / 2)) / 16;
								int j3 = (int)(this.position.Y + (float)(this.height / 2)) / 16 + 1;
								if (flag9)
								{
									num422--;
								}
								if (flag10)
								{
									num422++;
								}
								WorldGen.SolidTile(num422, j3);
							}
							if (flag12)
							{
								int num423 = (int)(this.position.X + (float)(this.width / 2)) / 16;
								int num424 = (int)(this.position.Y + (float)this.height) / 16 + 1;
								if (WorldGen.SolidTile(num423, num424) || Main.tile[num423, num424].halfBrick() || Main.tile[num423, num424].slope() > 0 || this.type == 200)
								{
									if (this.type == 200)
									{
										this.velocity.Y = -3.1f;
									}
									else
									{
										try
										{
											num423 = (int)(this.position.X + (float)(this.width / 2)) / 16;
											num424 = (int)(this.position.Y + (float)(this.height / 2)) / 16;
											if (flag9)
											{
												num423--;
											}
											if (flag10)
											{
												num423++;
											}
											num423 += (int)this.velocity.X;
											if (!WorldGen.SolidTile(num423, num424 - 1) && !WorldGen.SolidTile(num423, num424 - 2))
											{
												this.velocity.Y = -5.1f;
											}
											else if (!WorldGen.SolidTile(num423, num424 - 2))
											{
												this.velocity.Y = -7.1f;
											}
											else if (WorldGen.SolidTile(num423, num424 - 5))
											{
												this.velocity.Y = -11.1f;
											}
											else if (WorldGen.SolidTile(num423, num424 - 4))
											{
												this.velocity.Y = -10.1f;
											}
											else
											{
												this.velocity.Y = -9.1f;
											}
										}
										catch
										{
											this.velocity.Y = -9.1f;
										}
									}
									if (this.type == 127)
									{
										this.ai[0] = 1f;
									}
								}
							}
							else if (this.type == 266 && (flag9 || flag10))
							{
								this.velocity.Y = this.velocity.Y - 6f;
							}
						}
						if (this.velocity.X > num420)
						{
							this.velocity.X = num420;
						}
						if (this.velocity.X < -num420)
						{
							this.velocity.X = -num420;
						}
						if (this.velocity.X < 0f)
						{
							this.direction = -1;
						}
						if (this.velocity.X > 0f)
						{
							this.direction = 1;
						}
						if (this.velocity.X > num419 && flag10)
						{
							this.direction = 1;
						}
						if (this.velocity.X < -num419 && flag9)
						{
							this.direction = -1;
						}
						if (this.type != 313)
						{
							if (this.direction == -1)
							{
								this.spriteDirection = 1;
							}
							if (this.direction == 1)
							{
								this.spriteDirection = -1;
							}
						}
						if (this.type == 398)
						{
							this.spriteDirection = this.direction;
						}
						if (this.type >= 191 && this.type <= 194)
						{
							if (this.ai[1] > 0f)
							{
								if (this.localAI[1] == 0f)
								{
									this.localAI[1] = 1f;
									this.frame = 1;
								}
								if (this.frame != 0)
								{
									this.frameCounter++;
									if (this.frameCounter > 4)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame == 4)
									{
										this.frame = 0;
									}
								}
							}
							else if (this.velocity.Y == 0f)
							{
								this.localAI[1] = 0f;
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame < 5)
									{
										this.frame = 5;
									}
									if (this.frame >= 11)
									{
										this.frame = 5;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else if (this.velocity.Y < 0f)
							{
								this.frameCounter = 0;
								this.frame = 4;
							}
							else if (this.velocity.Y > 0f)
							{
								this.frameCounter = 0;
								this.frame = 4;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 268)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.frame > 5)
								{
									this.frameCounter = 0;
								}
								if (this.velocity.X == 0f)
								{
									int num425 = 3;
									this.frameCounter++;
									if (this.frameCounter < num425)
									{
										this.frame = 0;
									}
									else if (this.frameCounter < num425 * 2)
									{
										this.frame = 1;
									}
									else if (this.frameCounter < num425 * 3)
									{
										this.frame = 2;
									}
									else if (this.frameCounter < num425 * 4)
									{
										this.frame = 3;
									}
									else
									{
										this.frameCounter = num425 * 4;
									}
								}
								else
								{
									this.velocity.X = this.velocity.X * 0.8f;
									this.frameCounter++;
									int num426 = 3;
									if (this.frameCounter < num426)
									{
										this.frame = 0;
									}
									else if (this.frameCounter < num426 * 2)
									{
										this.frame = 1;
									}
									else if (this.frameCounter < num426 * 3)
									{
										this.frame = 2;
									}
									else if (this.frameCounter < num426 * 4)
									{
										this.frame = 3;
									}
									else if (flag9 || flag10)
									{
										this.velocity.X = this.velocity.X * 2f;
										this.frame = 4;
										this.velocity.Y = -6.1f;
										this.frameCounter = 0;
										for (int num427 = 0; num427 < 4; num427++)
										{
											int num428 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + (float)this.height - 2f), this.width, 4, 5, 0f, 0f, 0, default(Color), 1f);
											Main.dust[num428].velocity += this.velocity;
											Main.dust[num428].velocity *= 0.4f;
										}
									}
									else
									{
										this.frameCounter = num426 * 4;
									}
								}
							}
							else if (this.velocity.Y < 0f)
							{
								this.frameCounter = 0;
								this.frame = 5;
							}
							else
							{
								this.frame = 4;
								this.frameCounter = 3;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 269)
						{
							if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									int num429 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + (float)this.height - 2f), this.width, 6, 76, 0f, 0f, 0, default(Color), 1f);
									Main.dust[num429].noGravity = true;
									Main.dust[num429].velocity *= 0.3f;
									Main.dust[num429].noLight = true;
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 3)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frameCounter = 0;
								this.frame = 2;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 313)
						{
							int num430 = (int)(this.center().X / 16f);
							int num431 = (int)(this.center().Y / 16f);
							if (Main.tile[num430, num431] != null && Main.tile[num430, num431].wall > 0)
							{
								this.position.Y = this.position.Y + (float)this.height;
								this.height = 34;
								this.position.Y = this.position.Y - (float)this.height;
								this.position.X = this.position.X + (float)(this.width / 2);
								this.width = 34;
								this.position.X = this.position.X - (float)(this.width / 2);
								float num432 = 4f;
								Vector2 vector33 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
								float num433 = Main.player[this.owner].center().X - vector33.X;
								float num434 = Main.player[this.owner].center().Y - vector33.Y;
								float num435 = (float)Math.Sqrt((double)(num433 * num433 + num434 * num434));
								float num436 = num432 / num435;
								num433 *= num436;
								num434 *= num436;
								if (num435 < 120f)
								{
									this.velocity.X = this.velocity.X * 0.9f;
									this.velocity.Y = this.velocity.Y * 0.9f;
									if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) < 0.1)
									{
										this.velocity *= 0f;
									}
								}
								else
								{
									this.velocity.X = (this.velocity.X * 9f + num433) / 10f;
									this.velocity.Y = (this.velocity.Y * 9f + num434) / 10f;
								}
								if (num435 >= 120f)
								{
									this.spriteDirection = this.direction;
									this.rotation = (float)Math.Atan2((double)(this.velocity.Y * (float)(-(float)this.direction)), (double)(this.velocity.X * (float)(-(float)this.direction)));
								}
								this.frameCounter += (int)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y));
								if (this.frameCounter > 6)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame > 10)
								{
									this.frame = 5;
								}
								if (this.frame < 5)
								{
									this.frame = 10;
								}
							}
							else
							{
								this.rotation = 0f;
								if (this.direction == -1)
								{
									this.spriteDirection = 1;
								}
								if (this.direction == 1)
								{
									this.spriteDirection = -1;
								}
								this.position.Y = this.position.Y + (float)this.height;
								this.height = 30;
								this.position.Y = this.position.Y - (float)this.height;
								this.position.X = this.position.X + (float)(this.width / 2);
								this.width = 30;
								this.position.X = this.position.X - (float)(this.width / 2);
								if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
								{
									if (this.velocity.X == 0f)
									{
										this.frame = 0;
										this.frameCounter = 0;
									}
									else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
									{
										this.frameCounter += (int)Math.Abs(this.velocity.X);
										this.frameCounter++;
										if (this.frameCounter > 6)
										{
											this.frame++;
											this.frameCounter = 0;
										}
										if (this.frame > 3)
										{
											this.frame = 0;
										}
									}
									else
									{
										this.frame = 0;
										this.frameCounter = 0;
									}
								}
								else
								{
									this.frameCounter = 0;
									this.frame = 4;
								}
								this.velocity.Y = this.velocity.Y + 0.4f;
								if (this.velocity.Y > 10f)
								{
									this.velocity.Y = 10f;
								}
							}
						}
						else if (this.type >= 390 && this.type <= 392)
						{
							int num437 = (int)(this.center().X / 16f);
							int num438 = (int)(this.center().Y / 16f);
							if (Main.tile[num437, num438] != null && Main.tile[num437, num438].wall > 0)
							{
								this.position.Y = this.position.Y + (float)this.height;
								this.height = 34;
								this.position.Y = this.position.Y - (float)this.height;
								this.position.X = this.position.X + (float)(this.width / 2);
								this.width = 34;
								this.position.X = this.position.X - (float)(this.width / 2);
								float scaleFactor = 9f;
								float num439 = (float)(40 * (this.minionPos + 1));
								Vector2 vector34 = Main.player[this.owner].center() - this.center();
								if (flag14)
								{
									vector34 = vector32;
									num439 = 10f;
								}
								if (vector34.Length() < num439)
								{
									this.velocity *= 0.9f;
									if ((double)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) < 0.1)
									{
										this.velocity *= 0f;
									}
								}
								else if (vector34.Length() < 800f || !flag14)
								{
									this.velocity = (this.velocity * 9f + Vector2.Normalize(vector34) * scaleFactor) / 10f;
								}
								if (vector34.Length() >= num439)
								{
									this.spriteDirection = this.direction;
									this.rotation = this.velocity.ToRotation() + 1.57079637f;
								}
								else
								{
									this.rotation = vector34.ToRotation() + 1.57079637f;
								}
								this.frameCounter += (int)(Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y));
								if (this.frameCounter > 5)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame > 7)
								{
									this.frame = 4;
								}
								if (this.frame < 4)
								{
									this.frame = 7;
								}
							}
							else
							{
								this.rotation = 0f;
								if (this.direction == -1)
								{
									this.spriteDirection = 1;
								}
								if (this.direction == 1)
								{
									this.spriteDirection = -1;
								}
								this.position.Y = this.position.Y + (float)this.height;
								this.height = 30;
								this.position.Y = this.position.Y - (float)this.height;
								this.position.X = this.position.X + (float)(this.width / 2);
								this.width = 30;
								this.position.X = this.position.X - (float)(this.width / 2);
								if (this.frame >= 4 && this.frame <= 7)
								{
									Vector2 vector35 = Main.player[this.owner].center() - this.center();
									if (flag14)
									{
										vector35 = vector32;
									}
									float num440 = -vector35.Y;
									if (vector35.Y <= 0f)
									{
										if (num440 < 120f)
										{
											this.velocity.Y = -10f;
										}
										else if (num440 < 210f)
										{
											this.velocity.Y = -13f;
										}
										else if (num440 < 270f)
										{
											this.velocity.Y = -15f;
										}
										else if (num440 < 310f)
										{
											this.velocity.Y = -17f;
										}
										else if (num440 < 380f)
										{
											this.velocity.Y = -18f;
										}
									}
								}
								if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
								{
									if (this.velocity.X == 0f)
									{
										this.frame = 0;
										this.frameCounter = 0;
									}
									else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
									{
										this.frameCounter += (int)Math.Abs(this.velocity.X);
										this.frameCounter++;
										if (this.frameCounter > 5)
										{
											this.frame++;
											this.frameCounter = 0;
										}
										if (this.frame > 2)
										{
											this.frame = 0;
										}
									}
									else
									{
										this.frame = 0;
										this.frameCounter = 0;
									}
								}
								else
								{
									this.frameCounter = 0;
									this.frame = 3;
								}
								this.velocity.Y = this.velocity.Y + 0.4f;
								if (this.velocity.Y > 10f)
								{
									this.velocity.Y = 10f;
								}
							}
						}
						else if (this.type == 314)
						{
							if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 6)
									{
										this.frame = 1;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frameCounter = 0;
								this.frame = 7;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 319)
						{
							if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 8)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 5)
									{
										this.frame = 2;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frameCounter = 0;
								this.frame = 1;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 236)
						{
							if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									if (this.frame < 2)
									{
										this.frame = 2;
									}
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 8)
									{
										this.frame = 2;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frameCounter = 0;
								this.frame = 1;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 266)
						{
							if (this.velocity.Y >= 0f && (double)this.velocity.Y <= 0.8)
							{
								if (this.velocity.X == 0f)
								{
									this.frameCounter++;
								}
								else
								{
									this.frameCounter += 3;
								}
							}
							else
							{
								this.frameCounter += 5;
							}
							if (this.frameCounter >= 20)
							{
								this.frameCounter -= 20;
								this.frame++;
							}
							if (this.frame > 1)
							{
								this.frame = 0;
							}
							if (this.wet && Main.player[this.owner].position.Y + (float)Main.player[this.owner].height < this.position.Y + (float)this.height && this.localAI[0] == 0f)
							{
								if (this.velocity.Y > -4f)
								{
									this.velocity.Y = this.velocity.Y - 0.2f;
								}
								if (this.velocity.Y > 0f)
								{
									this.velocity.Y = this.velocity.Y * 0.95f;
								}
							}
							else
							{
								this.velocity.Y = this.velocity.Y + 0.4f;
							}
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 334)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									if (this.frame > 0)
									{
										this.frameCounter += 2;
										if (this.frameCounter > 6)
										{
											this.frame++;
											this.frameCounter = 0;
										}
										if (this.frame >= 7)
										{
											this.frame = 0;
										}
									}
									else
									{
										this.frame = 0;
										this.frameCounter = 0;
									}
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs((double)this.velocity.X * 0.75);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame >= 7 || this.frame < 1)
									{
										this.frame = 1;
									}
								}
								else if (this.frame > 0)
								{
									this.frameCounter += 2;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame >= 7)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else if (this.velocity.Y < 0f)
							{
								this.frameCounter = 0;
								this.frame = 2;
							}
							else if (this.velocity.Y > 0f)
							{
								this.frameCounter = 0;
								this.frame = 4;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 353)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 9)
									{
										this.frame = 2;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else if (this.velocity.Y < 0f)
							{
								this.frameCounter = 0;
								this.frame = 1;
							}
							else if (this.velocity.Y > 0f)
							{
								this.frameCounter = 0;
								this.frame = 1;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 111)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame >= 7)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else if (this.velocity.Y < 0f)
							{
								this.frameCounter = 0;
								this.frame = 4;
							}
							else if (this.velocity.Y > 0f)
							{
								this.frameCounter = 0;
								this.frame = 6;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 112)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame >= 3)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else if (this.velocity.Y < 0f)
							{
								this.frameCounter = 0;
								this.frame = 2;
							}
							else if (this.velocity.Y > 0f)
							{
								this.frameCounter = 0;
								this.frame = 2;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 127)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.1 || (double)this.velocity.X > 0.1)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 5)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frame = 0;
								this.frameCounter = 0;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 200)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.1 || (double)this.velocity.X > 0.1)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 5)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.rotation = this.velocity.X * 0.1f;
								this.frameCounter++;
								if (this.velocity.Y < 0f)
								{
									this.frameCounter += 2;
								}
								if (this.frameCounter > 6)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame > 9)
								{
									this.frame = 6;
								}
								if (this.frame < 6)
								{
									this.frame = 6;
								}
							}
							this.velocity.Y = this.velocity.Y + 0.1f;
							if (this.velocity.Y > 4f)
							{
								this.velocity.Y = 4f;
							}
						}
						else if (this.type == 208)
						{
							if (this.velocity.Y == 0f && this.velocity.X == 0f)
							{
								if (Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) < this.position.X + (float)(this.width / 2))
								{
									this.direction = -1;
								}
								else if (Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) > this.position.X + (float)(this.width / 2))
								{
									this.direction = 1;
								}
								this.rotation = 0f;
								this.frame = 0;
							}
							else
							{
								this.rotation = this.velocity.X * 0.075f;
								this.frameCounter++;
								if (this.frameCounter > 6)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame > 4)
								{
									this.frame = 1;
								}
								if (this.frame < 1)
								{
									this.frame = 1;
								}
							}
							this.velocity.Y = this.velocity.Y + 0.1f;
							if (this.velocity.Y > 4f)
							{
								this.velocity.Y = 4f;
							}
						}
						else if (this.type == 209)
						{
							if (this.alpha > 0)
							{
								this.alpha -= 5;
								if (this.alpha < 0)
								{
									this.alpha = 0;
								}
							}
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.1 || (double)this.velocity.X > 0.1)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 11)
									{
										this.frame = 2;
									}
									if (this.frame < 2)
									{
										this.frame = 2;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frame = 1;
								this.frameCounter = 0;
								this.rotation = 0f;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 324)
						{
							if (this.velocity.Y == 0f)
							{
								if ((double)this.velocity.X < -0.1 || (double)this.velocity.X > 0.1)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 5)
									{
										this.frame = 2;
									}
									if (this.frame < 2)
									{
										this.frame = 2;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.frameCounter = 0;
								this.frame = 1;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 14f)
							{
								this.velocity.Y = 14f;
							}
						}
						else if (this.type == 210)
						{
							if (this.velocity.Y == 0f)
							{
								if ((double)this.velocity.X < -0.1 || (double)this.velocity.X > 0.1)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame > 6)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else
							{
								this.rotation = this.velocity.X * 0.05f;
								this.frameCounter++;
								if (this.frameCounter > 6)
								{
									this.frame++;
									this.frameCounter = 0;
								}
								if (this.frame > 11)
								{
									this.frame = 7;
								}
								if (this.frame < 7)
								{
									this.frame = 7;
								}
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
						else if (this.type == 398)
						{
							if (this.velocity.Y == 0f)
							{
								if (this.velocity.X == 0f)
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
								else if ((double)this.velocity.X < -0.8 || (double)this.velocity.X > 0.8)
								{
									this.frameCounter += (int)Math.Abs(this.velocity.X);
									this.frameCounter++;
									if (this.frameCounter > 6)
									{
										this.frame++;
										this.frameCounter = 0;
									}
									if (this.frame >= 5)
									{
										this.frame = 0;
									}
								}
								else
								{
									this.frame = 0;
									this.frameCounter = 0;
								}
							}
							else if (this.velocity.Y != 0f)
							{
								this.frameCounter = 0;
								this.frame = 5;
							}
							this.velocity.Y = this.velocity.Y + 0.4f;
							if (this.velocity.Y > 10f)
							{
								this.velocity.Y = 10f;
							}
						}
					}
				}
			}
			else if (this.aiStyle == 27)
			{
				if (this.type == 115)
				{
					this.ai[0] += 1f;
					if (this.ai[0] < 30f)
					{
						this.velocity *= 1.125f;
					}
				}
				if (this.type == 115 && this.localAI[1] < 5f)
				{
					this.localAI[1] = 5f;
					for (int num441 = 5; num441 < 25; num441++)
					{
						float num442 = this.velocity.X * (30f / (float)num441);
						float num443 = this.velocity.Y * (30f / (float)num441);
						num442 *= 80f;
						num443 *= 80f;
						int num444 = Dust.NewDust(new Vector2(this.position.X - num442, this.position.Y - num443), 8, 8, 27, this.lastVelocity.X, this.lastVelocity.Y, 100, default(Color), 0.9f);
						Main.dust[num444].velocity *= 0.25f;
						Main.dust[num444].velocity -= this.velocity * 5f;
					}
				}
				if (this.localAI[1] > 7f && this.type == 173)
				{
					int num445 = Main.rand.Next(3);
					if (num445 == 0)
					{
						num445 = 15;
					}
					else if (num445 == 1)
					{
						num445 = 57;
					}
					else
					{
						num445 = 58;
					}
					int num446 = Dust.NewDust(new Vector2(this.position.X - this.velocity.X * 4f + 2f, this.position.Y + 2f - this.velocity.Y * 4f), 8, 8, num445, 0f, 0f, 100, default(Color), 1.25f);
					Main.dust[num446].velocity *= 0.1f;
				}
				if (this.localAI[1] > 7f && this.type == 132)
				{
					int num447 = Dust.NewDust(new Vector2(this.position.X - this.velocity.X * 4f + 2f, this.position.Y + 2f - this.velocity.Y * 4f), 8, 8, 107, this.lastVelocity.X, this.lastVelocity.Y, 100, default(Color), 1.25f);
					Main.dust[num447].velocity *= -0.25f;
					num447 = Dust.NewDust(new Vector2(this.position.X - this.velocity.X * 4f + 2f, this.position.Y + 2f - this.velocity.Y * 4f), 8, 8, 107, this.lastVelocity.X, this.lastVelocity.Y, 100, default(Color), 1.25f);
					Main.dust[num447].velocity *= -0.25f;
					Main.dust[num447].position -= this.velocity * 0.5f;
				}
				if (this.localAI[1] < 15f)
				{
					this.localAI[1] += 1f;
				}
				else
				{
					if (this.type == 114 || this.type == 115)
					{
						int num448 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + 4f), 8, 8, 27, this.lastVelocity.X, this.lastVelocity.Y, 100, default(Color), 0.6f);
						Main.dust[num448].velocity *= -0.25f;
					}
					else if (this.type == 116)
					{
						int num449 = Dust.NewDust(new Vector2(this.position.X - this.velocity.X * 5f + 2f, this.position.Y + 2f - this.velocity.Y * 5f), 8, 8, 64, this.lastVelocity.X, this.lastVelocity.Y, 100, default(Color), 1.5f);
						Main.dust[num449].velocity *= -0.25f;
						Main.dust[num449].noGravity = true;
					}
					if (this.localAI[0] == 0f)
					{
						this.scale -= 0.02f;
						this.alpha += 30;
						if (this.alpha >= 250)
						{
							this.alpha = 255;
							this.localAI[0] = 1f;
						}
					}
					else if (this.localAI[0] == 1f)
					{
						this.scale += 0.02f;
						this.alpha -= 30;
						if (this.alpha <= 0)
						{
							this.alpha = 0;
							this.localAI[0] = 0f;
						}
					}
				}
				if (this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
				}
				if (this.type == 157)
				{
					this.rotation += (float)this.direction * 0.4f;
					this.spriteDirection = this.direction;
				}
				else
				{
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 0.785f;
				}
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
			}
			else if (this.aiStyle == 28)
			{
				if (this.type == 177)
				{
					for (int num450 = 0; num450 < 3; num450++)
					{
						int num451 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 137, this.velocity.X, this.velocity.Y, Main.rand.Next(0, 101), default(Color), 1f + (float)Main.rand.Next(-20, 40) * 0.01f);
						Main.dust[num451].noGravity = true;
						Main.dust[num451].velocity *= 0.3f;
					}
				}
				if (this.type == 118)
				{
					for (int num452 = 0; num452 < 2; num452++)
					{
						int num453 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 92, this.velocity.X, this.velocity.Y, 50, default(Color), 1.2f);
						Main.dust[num453].noGravity = true;
						Main.dust[num453].velocity *= 0.3f;
					}
				}
				if (this.type == 119 || this.type == 128 || this.type == 359)
				{
					for (int num454 = 0; num454 < 3; num454++)
					{
						int num455 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 92, this.velocity.X, this.velocity.Y, 50, default(Color), 1.2f);
						Main.dust[num455].noGravity = true;
						Main.dust[num455].velocity *= 0.3f;
					}
				}
				if (this.type == 309)
				{
					for (int num456 = 0; num456 < 3; num456++)
					{
						int num457 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 185, this.velocity.X, this.velocity.Y, 50, default(Color), 1.2f);
						Main.dust[num457].noGravity = true;
						Main.dust[num457].velocity *= 0.3f;
					}
				}
				if (this.type == 129)
				{
					for (int num458 = 0; num458 < 6; num458++)
					{
						int num459 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 106, this.velocity.X, this.velocity.Y, 100, default(Color), 1f);
						Main.dust[num459].noGravity = true;
						Main.dust[num459].velocity *= 0.1f + (float)Main.rand.Next(4) * 0.1f;
						Main.dust[num459].scale *= 1f + (float)Main.rand.Next(5) * 0.1f;
					}
				}
				if (this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 28);
				}
			}
			else if (this.aiStyle == 29)
			{
				int num460 = this.type - 121 + 86;
				for (int num461 = 0; num461 < 2; num461++)
				{
					int num462 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, num460, this.velocity.X, this.velocity.Y, 50, default(Color), 1.2f);
					Main.dust[num462].noGravity = true;
					Main.dust[num462].velocity *= 0.3f;
				}
				if (this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
				}
			}
			else if (this.aiStyle == 30)
			{
				this.velocity *= 0.8f;
				this.rotation += 0.2f;
				this.alpha += 4;
				if (this.alpha >= 255)
				{
					this.Kill();
				}
			}
			else if (this.aiStyle == 31)
			{
				int num463 = 110;
				int num464 = 0;
				if (this.type == 146)
				{
					num463 = 111;
					num464 = 2;
				}
				if (this.type == 147)
				{
					num463 = 112;
					num464 = 1;
				}
				if (this.type == 148)
				{
					num463 = 113;
					num464 = 3;
				}
				if (this.type == 149)
				{
					num463 = 114;
					num464 = 4;
				}
				if (this.owner == Main.myPlayer)
				{
					WorldGen.Convert((int)(this.position.X + (float)(this.width / 2)) / 16, (int)(this.position.Y + (float)(this.height / 2)) / 16, num464, 2);
				}
				if (this.timeLeft > 133)
				{
					this.timeLeft = 133;
				}
				if (this.ai[0] > 7f)
				{
					float num465 = 1f;
					if (this.ai[0] == 8f)
					{
						num465 = 0.2f;
					}
					else if (this.ai[0] == 9f)
					{
						num465 = 0.4f;
					}
					else if (this.ai[0] == 10f)
					{
						num465 = 0.6f;
					}
					else if (this.ai[0] == 11f)
					{
						num465 = 0.8f;
					}
					this.ai[0] += 1f;
					for (int num466 = 0; num466 < 1; num466++)
					{
						int num467 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, num463, this.velocity.X * 0.2f, this.velocity.Y * 0.2f, 100, default(Color), 1f);
						Main.dust[num467].noGravity = true;
						Main.dust[num467].scale *= 1.75f;
						Dust expr_18033_cp_0 = Main.dust[num467];
						expr_18033_cp_0.velocity.X = expr_18033_cp_0.velocity.X * 2f;
						Dust expr_18053_cp_0 = Main.dust[num467];
						expr_18053_cp_0.velocity.Y = expr_18053_cp_0.velocity.Y * 2f;
						Main.dust[num467].scale *= num465;
					}
				}
				else
				{
					this.ai[0] += 1f;
				}
				this.rotation += 0.3f * (float)this.direction;
			}
			else if (this.aiStyle == 32)
			{
				this.timeLeft = 10;
				this.ai[0] += 1f;
				if (this.ai[0] >= 20f)
				{
					this.ai[0] = 15f;
					for (int num468 = 0; num468 < 255; num468++)
					{
						Rectangle rectangle3 = new Rectangle((int)this.position.X, (int)this.position.Y, this.width, this.height);
						if (Main.player[num468].active)
						{
							Rectangle value5 = new Rectangle((int)Main.player[num468].position.X, (int)Main.player[num468].position.Y, Main.player[num468].width, Main.player[num468].height);
							if (rectangle3.Intersects(value5))
							{
								this.ai[0] = 0f;
								this.velocity.Y = -4.5f;
								if (this.velocity.X > 2f)
								{
									this.velocity.X = 2f;
								}
								if (this.velocity.X < -2f)
								{
									this.velocity.X = -2f;
								}
								this.velocity.X = (this.velocity.X + (float)Main.player[num468].direction * 1.75f) / 2f;
								this.velocity.X = this.velocity.X + Main.player[num468].velocity.X * 3f;
								this.velocity.Y = this.velocity.Y + Main.player[num468].velocity.Y;
								if (this.velocity.X > 6f)
								{
									this.velocity.X = 6f;
								}
								if (this.velocity.X < -6f)
								{
									this.velocity.X = -6f;
								}
								this.netUpdate = true;
								this.ai[1] += 1f;
							}
						}
					}
				}
				if (this.velocity.X == 0f && this.velocity.Y == 0f)
				{
					this.Kill();
				}
				this.rotation += 0.02f * this.velocity.X;
				if (this.velocity.Y == 0f)
				{
					this.velocity.X = this.velocity.X * 0.98f;
				}
				else if (this.wet)
				{
					this.velocity.X = this.velocity.X * 0.99f;
				}
				else
				{
					this.velocity.X = this.velocity.X * 0.995f;
				}
				if ((double)this.velocity.X > -0.03 && (double)this.velocity.X < 0.03)
				{
					this.velocity.X = 0f;
				}
				if (this.wet)
				{
					this.ai[1] = 0f;
					if (this.velocity.Y > 0f)
					{
						this.velocity.Y = this.velocity.Y * 0.95f;
					}
					this.velocity.Y = this.velocity.Y - 0.1f;
					if (this.velocity.Y < -4f)
					{
						this.velocity.Y = -4f;
					}
					if (this.velocity.X == 0f)
					{
						this.Kill();
					}
				}
				else
				{
					this.velocity.Y = this.velocity.Y + 0.1f;
				}
				if (this.velocity.Y > 10f)
				{
					this.velocity.Y = 10f;
				}
			}
			else if (this.aiStyle == 33)
			{
				if (this.alpha > 0)
				{
					this.alpha -= 50;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				float num469 = 4f;
				float num470 = this.ai[0];
				float num471 = this.ai[1];
				if (num470 == 0f && num471 == 0f)
				{
					num470 = 1f;
				}
				float num472 = (float)Math.Sqrt((double)(num470 * num470 + num471 * num471));
				num472 = num469 / num472;
				num470 *= num472;
				num471 *= num472;
				if (this.alpha < 70)
				{
					int num473 = 127;
					if (this.type == 310)
					{
						num473 = 187;
					}
					int num474 = Dust.NewDust(new Vector2(this.position.X, this.position.Y - 2f), 6, 6, num473, this.velocity.X, this.velocity.Y, 100, default(Color), 1.6f);
					Main.dust[num474].noGravity = true;
					Dust expr_18650_cp_0 = Main.dust[num474];
					expr_18650_cp_0.position.X = expr_18650_cp_0.position.X - num470 * 1f;
					Dust expr_18675_cp_0 = Main.dust[num474];
					expr_18675_cp_0.position.Y = expr_18675_cp_0.position.Y - num471 * 1f;
					Dust expr_1869A_cp_0 = Main.dust[num474];
					expr_1869A_cp_0.velocity.X = expr_1869A_cp_0.velocity.X - num470;
					Dust expr_186B9_cp_0 = Main.dust[num474];
					expr_186B9_cp_0.velocity.Y = expr_186B9_cp_0.velocity.Y - num471;
				}
				if (this.localAI[0] == 0f)
				{
					this.ai[0] = this.velocity.X;
					this.ai[1] = this.velocity.Y;
					this.localAI[1] += 1f;
					if (this.localAI[1] >= 30f)
					{
						this.velocity.Y = this.velocity.Y + 0.09f;
						this.localAI[1] = 30f;
					}
				}
				else
				{
					if (!Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.localAI[0] = 0f;
						this.localAI[1] = 30f;
					}
					this.damage = 0;
				}
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
				this.rotation = (float)Math.Atan2((double)this.ai[1], (double)this.ai[0]) + 1.57f;
			}
			else if (this.aiStyle == 34)
			{
				if (this.type >= 415 && this.type <= 418)
				{
					this.ai[0] += 1f;
					if (this.ai[0] > 4f)
					{
						int num475 = Dust.NewDust(new Vector2(this.position.X + 2f, this.position.Y + 20f), 8, 8, 6, this.velocity.X, this.velocity.Y, 100, default(Color), 1.2f);
						Main.dust[num475].noGravity = true;
						Main.dust[num475].velocity *= 0.2f;
					}
				}
				else
				{
					int num476 = Dust.NewDust(new Vector2(this.position.X + 2f, this.position.Y + 20f), 8, 8, 6, this.velocity.X, this.velocity.Y, 100, default(Color), 1.2f);
					Main.dust[num476].noGravity = true;
					Main.dust[num476].velocity *= 0.2f;
				}
			}
			else if (this.aiStyle == 35)
			{
				this.ai[0] += 1f;
				if (this.ai[0] > 30f)
				{
					this.velocity.Y = this.velocity.Y + 0.2f;
					this.velocity.X = this.velocity.X * 0.985f;
					if (this.velocity.Y > 14f)
					{
						this.velocity.Y = 14f;
					}
				}
				this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * (float)this.direction * 0.02f;
				if (this.owner == Main.myPlayer)
				{
					Vector2 vector36 = Collision.TileCollision(this.position, this.velocity, this.width, this.height, true, true, 1);
					bool flag16 = false;
					if (vector36 != this.velocity)
					{
						flag16 = true;
					}
					else
					{
						int num477 = (int)(this.center().X + this.velocity.X) / 16;
						int num478 = (int)(this.center().Y + this.velocity.Y) / 16;
						if (Main.tile[num477, num478] != null && Main.tile[num477, num478].active() && Main.tile[num477, num478].bottomSlope())
						{
							flag16 = true;
							this.position.Y = (float)(num478 * 16 + 16 + 8);
							this.position.X = (float)(num477 * 16 + 8);
						}
					}
					if (flag16)
					{
						int num479 = (int)(this.position.X + (float)(this.width / 2)) / 16;
						int num480 = (int)(this.position.Y + (float)(this.height / 2)) / 16;
						this.position += vector36;
						int num481 = 10;
						if (Main.tile[num479, num480] != null)
						{
							while (Main.tile[num479, num480] != null && Main.tile[num479, num480].active())
							{
								if (!Main.tileRope[(int)Main.tile[num479, num480].type])
								{
									break;
								}
								num480++;
							}
							while (num481 > 0)
							{
								num481--;
								if (Main.tile[num479, num480] == null)
								{
									break;
								}
								if (Main.tile[num479, num480].active() && (Main.tileCut[(int)Main.tile[num479, num480].type] || Main.tile[num479, num480].type == 165))
								{
									WorldGen.KillTile(num479, num480, false, false, false);
									NetMessage.SendData(17, -1, -1, "", 0, (float)num479, (float)num480, 0f, 0);
								}
								if (!Main.tile[num479, num480].active())
								{
									WorldGen.PlaceTile(num479, num480, 213, false, false, -1, 0);
									NetMessage.SendData(17, -1, -1, "", 1, (float)num479, (float)num480, 213f, 0);
									this.ai[1] += 1f;
								}
								else
								{
									num481 = 0;
								}
								num480++;
							}
							this.Kill();
						}
					}
				}
			}
			else if (this.aiStyle == 36)
			{
				if (this.type != 307 && this.wet && !this.honeyWet)
				{
					this.Kill();
				}
				if (this.alpha > 0)
				{
					this.alpha -= 50;
				}
				else
				{
					this.maxUpdates = 0;
				}
				if (this.alpha < 0)
				{
					this.alpha = 0;
				}
				if (this.type == 307)
				{
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) - 1.57f;
					this.frameCounter++;
					if (this.frameCounter >= 6)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame >= 2)
					{
						this.frame = 0;
					}
					for (int num482 = 0; num482 < 3; num482++)
					{
						float num483 = this.velocity.X / 3f * (float)num482;
						float num484 = this.velocity.Y / 3f * (float)num482;
						int num485 = Dust.NewDust(this.position, this.width, this.height, 184, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num485].position.X = this.center().X - num483;
						Main.dust[num485].position.Y = this.center().Y - num484;
						Main.dust[num485].velocity *= 0f;
						Main.dust[num485].scale = 0.5f;
					}
				}
				else
				{
					if (this.type == 316)
					{
						if (this.velocity.X > 0f)
						{
							this.spriteDirection = -1;
						}
						else if (this.velocity.X < 0f)
						{
							this.spriteDirection = 1;
						}
					}
					else if (this.velocity.X > 0f)
					{
						this.spriteDirection = 1;
					}
					else if (this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
					}
					this.rotation = this.velocity.X * 0.1f;
					this.frameCounter++;
					if (this.frameCounter >= 3)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame >= 3)
					{
						this.frame = 0;
					}
				}
				float num486 = this.position.X;
				float num487 = this.position.Y;
				float num488 = 100000f;
				bool flag17 = false;
				this.ai[0] += 1f;
				if (this.ai[0] > 30f)
				{
					this.ai[0] = 30f;
					for (int num489 = 0; num489 < 200; num489++)
					{
						if (Main.npc[num489].active && !Main.npc[num489].dontTakeDamage && !Main.npc[num489].friendly && Main.npc[num489].lifeMax > 5 && (!Main.npc[num489].wet || this.type == 307))
						{
							float num490 = Main.npc[num489].position.X + (float)(Main.npc[num489].width / 2);
							float num491 = Main.npc[num489].position.Y + (float)(Main.npc[num489].height / 2);
							float num492 = Math.Abs(this.position.X + (float)(this.width / 2) - num490) + Math.Abs(this.position.Y + (float)(this.height / 2) - num491);
							if (num492 < 800f && num492 < num488 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num489].position, Main.npc[num489].width, Main.npc[num489].height))
							{
								num488 = num492;
								num486 = num490;
								num487 = num491;
								flag17 = true;
							}
						}
					}
				}
				if (!flag17)
				{
					num486 = this.position.X + (float)(this.width / 2) + this.velocity.X * 100f;
					num487 = this.position.Y + (float)(this.height / 2) + this.velocity.Y * 100f;
				}
				else if (this.type == 307)
				{
					this.friendly = true;
				}
				float num493 = 6f;
				float num494 = 0.1f;
				if (this.type == 189)
				{
					num493 = 7f;
					num494 = 0.15f;
				}
				if (this.type == 307)
				{
					num493 = 9f;
					num494 = 0.2f;
				}
				if (this.type == 316)
				{
					num493 = 10f;
					num494 = 0.25f;
				}
				Vector2 vector37 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
				float num495 = num486 - vector37.X;
				float num496 = num487 - vector37.Y;
				float num497 = (float)Math.Sqrt((double)(num495 * num495 + num496 * num496));
				num497 = num493 / num497;
				num495 *= num497;
				num496 *= num497;
				if (this.velocity.X < num495)
				{
					this.velocity.X = this.velocity.X + num494;
					if (this.velocity.X < 0f && num495 > 0f)
					{
						this.velocity.X = this.velocity.X + num494 * 2f;
					}
				}
				else if (this.velocity.X > num495)
				{
					this.velocity.X = this.velocity.X - num494;
					if (this.velocity.X > 0f && num495 < 0f)
					{
						this.velocity.X = this.velocity.X - num494 * 2f;
					}
				}
				if (this.velocity.Y < num496)
				{
					this.velocity.Y = this.velocity.Y + num494;
					if (this.velocity.Y < 0f && num496 > 0f)
					{
						this.velocity.Y = this.velocity.Y + num494 * 2f;
					}
				}
				else if (this.velocity.Y > num496)
				{
					this.velocity.Y = this.velocity.Y - num494;
					if (this.velocity.Y > 0f && num496 < 0f)
					{
						this.velocity.Y = this.velocity.Y - num494 * 2f;
					}
				}
			}
			else if (this.aiStyle == 37)
			{
				if (this.ai[1] == 0f)
				{
					this.ai[1] = this.position.Y - 5f;
				}
				if (this.ai[0] == 0f)
				{
					if (Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.velocity.Y = this.velocity.Y * -1f;
						this.ai[0] += 1f;
					}
					else
					{
						float num498 = this.position.Y - this.ai[1];
						if (num498 > 300f)
						{
							this.velocity.Y = this.velocity.Y * -1f;
							this.ai[0] += 1f;
						}
					}
				}
				else if (Collision.SolidCollision(this.position, this.width, this.height) || this.position.Y < this.ai[1])
				{
					this.Kill();
				}
			}
			else if (this.aiStyle == 38)
			{
				this.ai[0] += 1f;
				if (this.ai[0] >= 6f)
				{
					this.ai[0] = 0f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 34);
					if (Main.myPlayer == this.owner)
					{
						Projectile.NewProjectile(this.position.X, this.position.Y, this.velocity.X, this.velocity.Y, 188, this.damage, this.knockBack, this.owner, 0f, 0f);
					}
				}
			}
			else if (this.aiStyle == 39)
			{
				this.alpha -= 50;
				if (this.alpha < 0)
				{
					this.alpha = 0;
				}
				if (Main.player[this.owner].dead)
				{
					this.Kill();
					return;
				}
				if (this.alpha == 0)
				{
					Main.player[this.owner].itemAnimation = 5;
					Main.player[this.owner].itemTime = 5;
					if (this.position.X + (float)(this.width / 2) > Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2))
					{
						Main.player[this.owner].ChangeDir(1);
					}
					else
					{
						Main.player[this.owner].ChangeDir(-1);
					}
				}
				Vector2 vector38 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
				float num499 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector38.X;
				float num500 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector38.Y;
				float num501 = (float)Math.Sqrt((double)(num499 * num499 + num500 * num500));
				if (!Main.player[this.owner].channel && this.alpha == 0)
				{
					this.ai[0] = 1f;
					this.ai[1] = -1f;
				}
				if (this.ai[1] > 0f && num501 > 1500f)
				{
					this.ai[1] = 0f;
					this.ai[0] = 1f;
				}
				if (this.ai[1] > 0f)
				{
					this.tileCollide = false;
					int num502 = (int)this.ai[1] - 1;
					if (Main.npc[num502].active && Main.npc[num502].life > 0)
					{
						float num503 = 16f;
						vector38 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						num499 = Main.npc[num502].position.X + (float)(Main.npc[num502].width / 2) - vector38.X;
						num500 = Main.npc[num502].position.Y + (float)(Main.npc[num502].height / 2) - vector38.Y;
						num501 = (float)Math.Sqrt((double)(num499 * num499 + num500 * num500));
						if (num501 < num503)
						{
							this.velocity.X = num499;
							this.velocity.Y = num500;
							if (num501 > num503 / 2f)
							{
								if (this.velocity.X < 0f)
								{
									this.spriteDirection = -1;
									this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
								}
								else
								{
									this.spriteDirection = 1;
									this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
								}
							}
						}
						else
						{
							num501 = num503 / num501;
							num499 *= num501;
							num500 *= num501;
							this.velocity.X = num499;
							this.velocity.Y = num500;
							if (this.velocity.X < 0f)
							{
								this.spriteDirection = -1;
								this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
							}
							else
							{
								this.spriteDirection = 1;
								this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
							}
						}
						this.ai[0] = 1f;
					}
					else
					{
						this.ai[1] = 0f;
						float num504 = this.position.X;
						float num505 = this.position.Y;
						float num506 = 3000f;
						int num507 = -1;
						for (int num508 = 0; num508 < 200; num508++)
						{
							if (Main.npc[num508].active && !Main.npc[num508].friendly && Main.npc[num508].lifeMax > 5 && !Main.npc[num508].dontTakeDamage)
							{
								float num509 = Main.npc[num508].position.X + (float)(Main.npc[num508].width / 2);
								float num510 = Main.npc[num508].position.Y + (float)(Main.npc[num508].height / 2);
								float num511 = Math.Abs(this.position.X + (float)(this.width / 2) - num509) + Math.Abs(this.position.Y + (float)(this.height / 2) - num510);
								if (num511 < num506 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num508].position, Main.npc[num508].width, Main.npc[num508].height))
								{
									num506 = num511;
									num504 = num509;
									num505 = num510;
									num507 = num508;
								}
							}
						}
						if (num507 >= 0)
						{
							float num512 = 16f;
							vector38 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
							num499 = num504 - vector38.X;
							num500 = num505 - vector38.Y;
							num501 = (float)Math.Sqrt((double)(num499 * num499 + num500 * num500));
							num501 = num512 / num501;
							num499 *= num501;
							num500 *= num501;
							this.velocity.X = num499;
							this.velocity.Y = num500;
							this.ai[0] = 0f;
							this.ai[1] = (float)(num507 + 1);
						}
					}
				}
				else if (this.ai[0] == 0f)
				{
					if (num501 > 700f)
					{
						this.ai[0] = 1f;
					}
					if (this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
						this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
					}
					else
					{
						this.spriteDirection = 1;
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
					}
				}
				else if (this.ai[0] == 1f)
				{
					this.tileCollide = false;
					if (this.velocity.X < 0f)
					{
						this.spriteDirection = 1;
						this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
					}
					else
					{
						this.spriteDirection = -1;
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
					}
					if (this.velocity.X < 0f)
					{
						this.spriteDirection = -1;
						this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
					}
					else
					{
						this.spriteDirection = 1;
						this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
					}
					float num513 = 20f;
					if (num501 < 70f)
					{
						this.Kill();
					}
					num501 = num513 / num501;
					num499 *= num501;
					num500 *= num501;
					this.velocity.X = num499;
					this.velocity.Y = num500;
				}
				this.frameCounter++;
				if (this.frameCounter >= 4)
				{
					this.frame++;
					this.frameCounter = 0;
				}
				if (this.frame >= 4)
				{
					this.frame = 0;
				}
			}
			else if (this.aiStyle == 40)
			{
				this.localAI[0] += 1f;
				if (this.localAI[0] > 3f)
				{
					this.localAI[0] = 100f;
					this.alpha -= 50;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				this.frameCounter++;
				if (this.frameCounter >= 3)
				{
					this.frame++;
					this.frameCounter = 0;
				}
				if (this.frame >= 5)
				{
					this.frame = 0;
				}
				this.velocity.X = this.velocity.X + this.ai[0];
				this.velocity.Y = this.velocity.Y + this.ai[1];
				this.localAI[1] += 1f;
				if (this.localAI[1] == 50f)
				{
					this.localAI[1] = 51f;
					this.ai[0] = (float)Main.rand.Next(-100, 101) * 6E-05f;
					this.ai[1] = (float)Main.rand.Next(-100, 101) * 6E-05f;
				}
				if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) > 16f)
				{
					this.velocity.X = this.velocity.X * 0.95f;
					this.velocity.Y = this.velocity.Y * 0.95f;
				}
				if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) < 12f)
				{
					this.velocity.X = this.velocity.X * 1.05f;
					this.velocity.Y = this.velocity.Y * 1.05f;
				}
				this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 3.14f;
			}
			else if (this.aiStyle == 41)
			{
				if (this.localAI[0] == 0f)
				{
					this.localAI[0] = 1f;
					this.frame = Main.rand.Next(3);
				}
				this.rotation += this.velocity.X * 0.01f;
			}
			else if (this.aiStyle == 42)
			{
				if (!Main.player[this.owner].crystalLeaf)
				{
					this.Kill();
					return;
				}
				this.position.X = Main.player[this.owner].center().X - (float)(this.width / 2);
				this.position.Y = Main.player[this.owner].center().Y - (float)(this.height / 2) + Main.player[this.owner].gfxOffY - 60f;
				if (Main.player[this.owner].gravDir == -1f)
				{
					this.position.Y = this.position.Y + 120f;
					this.rotation = 3.14f;
				}
				else
				{
					this.rotation = 0f;
				}
				this.position.X = (float)((int)this.position.X);
				this.position.Y = (float)((int)this.position.Y);
				float num514 = (float)Main.mouseTextColor / 200f - 0.35f;
				num514 *= 0.2f;
				this.scale = num514 + 0.95f;
				if (this.owner == Main.myPlayer)
				{
					if (this.ai[0] == 0f)
					{
						float num515 = this.position.X;
						float num516 = this.position.Y;
						float num517 = 700f;
						bool flag18 = false;
						for (int num518 = 0; num518 < 200; num518++)
						{
							if (Main.npc[num518].active && !Main.npc[num518].friendly && Main.npc[num518].lifeMax > 5)
							{
								float num519 = Main.npc[num518].position.X + (float)(Main.npc[num518].width / 2);
								float num520 = Main.npc[num518].position.Y + (float)(Main.npc[num518].height / 2);
								float num521 = Math.Abs(this.position.X + (float)(this.width / 2) - num519) + Math.Abs(this.position.Y + (float)(this.height / 2) - num520);
								if (num521 < num517 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num518].position, Main.npc[num518].width, Main.npc[num518].height))
								{
									num517 = num521;
									num515 = num519;
									num516 = num520;
									flag18 = true;
								}
							}
						}
						if (flag18)
						{
							float num522 = 12f;
							Vector2 vector39 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
							float num523 = num515 - vector39.X;
							float num524 = num516 - vector39.Y;
							float num525 = (float)Math.Sqrt((double)(num523 * num523 + num524 * num524));
							num525 = num522 / num525;
							num523 *= num525;
							num524 *= num525;
							Projectile.NewProjectile(this.center().X - 4f, this.center().Y, num523, num524, 227, 50, 5f, this.owner, 0f, 0f);
							this.ai[0] = 50f;
						}
					}
					else
					{
						this.ai[0] -= 1f;
					}
				}
			}
			else if (this.aiStyle == 43)
			{
				if (this.localAI[1] == 0f)
				{
					Main.PlaySound(6, (int)this.position.X, (int)this.position.Y, 1);
					this.localAI[1] += 1f;
					for (int num526 = 0; num526 < 5; num526++)
					{
						int num527 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 157, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num527].noGravity = true;
						Main.dust[num527].velocity *= 3f;
						Main.dust[num527].scale = 1.5f;
					}
				}
				this.ai[0] = (float)Main.rand.Next(-100, 101) * 0.0025f;
				this.ai[1] = (float)Main.rand.Next(-100, 101) * 0.0025f;
				if (this.localAI[0] == 0f)
				{
					this.scale += 0.05f;
					if ((double)this.scale > 1.2)
					{
						this.localAI[0] = 1f;
					}
				}
				else
				{
					this.scale -= 0.05f;
					if ((double)this.scale < 0.8)
					{
						this.localAI[0] = 0f;
					}
				}
				this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 3.14f;
				int num528 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 157, 0f, 0f, 0, default(Color), 1f);
				Main.dust[num528].noGravity = true;
				Main.dust[num528].velocity *= 0.1f;
				Main.dust[num528].scale = 1.5f;
			}
			else if (this.aiStyle == 44)
			{
				if (this.type == 228)
				{
					this.velocity *= 0.96f;
					this.alpha += 4;
					if (this.alpha > 255)
					{
						this.Kill();
					}
				}
				else if (this.type == 229)
				{
					if (this.ai[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
					}
					this.ai[0] += 1f;
					if (this.ai[0] > 20f)
					{
						this.velocity.Y = this.velocity.Y + 0.3f;
						this.velocity.X = this.velocity.X * 0.98f;
					}
				}
				this.frameCounter++;
				if (this.frameCounter > 5)
				{
					this.frame++;
					this.frameCounter = 0;
				}
				if (this.frame >= Main.projFrames[this.type])
				{
					this.frame = 0;
				}
			}
			else if (this.aiStyle == 45)
			{
				if (this.type == 237 || this.type == 243)
				{
					float num529 = this.ai[0];
					float num530 = this.ai[1];
					if (num529 != 0f && num530 != 0f)
					{
						bool flag19 = false;
						bool flag20 = false;
						if ((this.velocity.X < 0f && this.center().X < num529) || (this.velocity.X > 0f && this.center().X > num529))
						{
							flag19 = true;
						}
						if ((this.velocity.Y < 0f && this.center().Y < num530) || (this.velocity.Y > 0f && this.center().Y > num530))
						{
							flag20 = true;
						}
						if (flag19 && flag20)
						{
							this.Kill();
						}
					}
					this.rotation += this.velocity.X * 0.02f;
					this.frameCounter++;
					if (this.frameCounter > 4)
					{
						this.frameCounter = 0;
						this.frame++;
						if (this.frame > 3)
						{
							this.frame = 0;
						}
					}
				}
				else if (this.type == 238 || this.type == 244)
				{
					this.frameCounter++;
					if (this.frameCounter > 8)
					{
						this.frameCounter = 0;
						this.frame++;
						if (this.frame > 5)
						{
							this.frame = 0;
						}
					}
					this.ai[1] += 1f;
					if (this.type == 244 && this.ai[1] >= 1800f)
					{
						this.alpha += 5;
						if (this.alpha > 255)
						{
							this.alpha = 255;
							this.Kill();
						}
					}
					else if (this.type == 238 && this.ai[1] >= 3600f)
					{
						this.alpha += 5;
						if (this.alpha > 255)
						{
							this.alpha = 255;
							this.Kill();
						}
					}
					else
					{
						this.ai[0] += 1f;
						if (this.type == 244)
						{
							if (this.ai[0] > 10f)
							{
								this.ai[0] = 0f;
								if (this.owner == Main.myPlayer)
								{
									int num531 = (int)(this.position.X + 14f + (float)Main.rand.Next(this.width - 28));
									int num532 = (int)(this.position.Y + (float)this.height + 4f);
									Projectile.NewProjectile((float)num531, (float)num532, 0f, 5f, 245, this.damage, 0f, this.owner, 0f, 0f);
								}
							}
						}
						else if (this.ai[0] > 8f)
						{
							this.ai[0] = 0f;
							if (this.owner == Main.myPlayer)
							{
								int num533 = (int)(this.position.X + 14f + (float)Main.rand.Next(this.width - 28));
								int num534 = (int)(this.position.Y + (float)this.height + 4f);
								Projectile.NewProjectile((float)num533, (float)num534, 0f, 5f, 239, this.damage, 0f, this.owner, 0f, 0f);
							}
						}
					}
					this.localAI[0] += 1f;
					if (this.localAI[0] >= 10f)
					{
						this.localAI[0] = 0f;
						int num535 = 0;
						int num536 = 0;
						float num537 = 0f;
						int num538 = this.type;
						for (int num539 = 0; num539 < 1000; num539++)
						{
							if (Main.projectile[num539].active && Main.projectile[num539].owner == this.owner && Main.projectile[num539].type == num538 && Main.projectile[num539].ai[1] < 3600f)
							{
								num535++;
								if (Main.projectile[num539].ai[1] > num537)
								{
									num536 = num539;
									num537 = Main.projectile[num539].ai[1];
								}
							}
						}
						if (this.type == 244)
						{
							if (num535 > 1)
							{
								Main.projectile[num536].netUpdate = true;
								Main.projectile[num536].ai[1] = 36000f;
							}
						}
						else if (num535 > 2)
						{
							Main.projectile[num536].netUpdate = true;
							Main.projectile[num536].ai[1] = 36000f;
						}
					}
				}
				else if (this.type == 239)
				{
					this.alpha = 50;
				}
				else if (this.type == 245)
				{
					this.alpha = 100;
				}
				else if (this.type == 264)
				{
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
				}
			}
			else if (this.aiStyle == 46)
			{
				int num540 = 600;
				if (this.type == 250)
				{
					if (this.owner == Main.myPlayer)
					{
						this.localAI[0] += 1f;
						if (this.localAI[0] > 4f)
						{
							this.localAI[0] = 3f;
							Projectile.NewProjectile(this.center().X, this.center().Y, this.velocity.X * 0.001f, this.velocity.Y * 0.001f, 251, this.damage, this.knockBack, this.owner, 0f, 0f);
						}
						if (this.timeLeft > num540)
						{
							this.timeLeft = num540;
						}
					}
					float num541 = 1f;
					if (this.velocity.Y < 0f)
					{
						num541 -= this.velocity.Y / 3f;
					}
					this.ai[0] += num541;
					if (this.ai[0] > 30f)
					{
						this.velocity.Y = this.velocity.Y + 0.5f;
						if (this.velocity.Y > 0f)
						{
							this.velocity.X = this.velocity.X * 0.95f;
						}
						else
						{
							this.velocity.X = this.velocity.X * 1.05f;
						}
					}
					float num542 = this.velocity.X;
					float num543 = this.velocity.Y;
					float num544 = (float)Math.Sqrt((double)(num542 * num542 + num543 * num543));
					num544 = 15.95f * this.scale / num544;
					num542 *= num544;
					num543 *= num544;
					this.velocity.X = num542;
					this.velocity.Y = num543;
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) - 1.57f;
				}
				else
				{
					if (this.localAI[0] == 0f)
					{
						if (this.velocity.X > 0f)
						{
							this.spriteDirection = -1;
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) - 1.57f;
						}
						else
						{
							this.spriteDirection = 1;
							this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) - 1.57f;
						}
						this.localAI[0] = 1f;
						this.timeLeft = num540;
					}
					this.velocity.X = this.velocity.X * 0.98f;
					this.velocity.Y = this.velocity.Y * 0.98f;
					if (this.rotation == 0f)
					{
						this.alpha = 255;
					}
					else if (this.timeLeft < 10)
					{
						this.alpha = 255 - (int)(255f * (float)this.timeLeft / 10f);
					}
					else if (this.timeLeft > num540 - 10)
					{
						int num545 = num540 - this.timeLeft;
						this.alpha = 255 - (int)(255f * (float)num545 / 10f);
					}
					else
					{
						this.alpha = 0;
					}
				}
			}
			else if (this.aiStyle == 47)
			{
				if (this.ai[0] == 0f)
				{
					this.ai[0] = this.velocity.X;
					this.ai[1] = this.velocity.Y;
				}
				if (this.velocity.X > 0f)
				{
					this.rotation += (Math.Abs(this.velocity.Y) + Math.Abs(this.velocity.X)) * 0.001f;
				}
				else
				{
					this.rotation -= (Math.Abs(this.velocity.Y) + Math.Abs(this.velocity.X)) * 0.001f;
				}
				this.frameCounter++;
				if (this.frameCounter > 6)
				{
					this.frameCounter = 0;
					this.frame++;
					if (this.frame > 4)
					{
						this.frame = 0;
					}
				}
				if (Math.Sqrt((double)(this.velocity.X * this.velocity.X + this.velocity.Y * this.velocity.Y)) > 2.0)
				{
					this.velocity *= 0.98f;
				}
				for (int num546 = 0; num546 < 1000; num546++)
				{
					if (num546 != this.whoAmI && Main.projectile[num546].active && Main.projectile[num546].owner == this.owner && Main.projectile[num546].type == this.type && this.timeLeft > Main.projectile[num546].timeLeft && Main.projectile[num546].timeLeft > 30)
					{
						Main.projectile[num546].timeLeft = 30;
					}
				}
				int[] array = new int[20];
				int num547 = 0;
				float num548 = 300f;
				bool flag21 = false;
				for (int num549 = 0; num549 < 200; num549++)
				{
					if (Main.npc[num549].active && !Main.npc[num549].dontTakeDamage && !Main.npc[num549].friendly && Main.npc[num549].lifeMax > 5)
					{
						float num550 = Main.npc[num549].position.X + (float)(Main.npc[num549].width / 2);
						float num551 = Main.npc[num549].position.Y + (float)(Main.npc[num549].height / 2);
						float num552 = Math.Abs(this.position.X + (float)(this.width / 2) - num550) + Math.Abs(this.position.Y + (float)(this.height / 2) - num551);
						if (num552 < num548 && Collision.CanHit(this.center(), 1, 1, Main.npc[num549].center(), 1, 1))
						{
							if (num547 < 20)
							{
								array[num547] = num549;
								num547++;
							}
							flag21 = true;
						}
					}
				}
				if (this.timeLeft < 30)
				{
					flag21 = false;
				}
				if (flag21)
				{
					int num553 = Main.rand.Next(num547);
					num553 = array[num553];
					float num554 = Main.npc[num553].position.X + (float)(Main.npc[num553].width / 2);
					float num555 = Main.npc[num553].position.Y + (float)(Main.npc[num553].height / 2);
					this.localAI[0] += 1f;
					if (this.localAI[0] > 8f)
					{
						this.localAI[0] = 0f;
						float num556 = 6f;
						Vector2 value6 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						value6 += this.velocity * 4f;
						float num557 = num554 - value6.X;
						float num558 = num555 - value6.Y;
						float num559 = (float)Math.Sqrt((double)(num557 * num557 + num558 * num558));
						num559 = num556 / num559;
						num557 *= num559;
						num558 *= num559;
						Projectile.NewProjectile(value6.X, value6.Y, num557, num558, 255, this.damage, this.knockBack, this.owner, 0f, 0f);
					}
				}
			}
			else if (this.aiStyle == 48)
			{
				if (this.type == 255)
				{
					for (int num560 = 0; num560 < 4; num560++)
					{
						Vector2 value7 = this.position;
						value7 -= this.velocity * ((float)num560 * 0.25f);
						this.alpha = 255;
						int num561 = Dust.NewDust(value7, 1, 1, 160, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num561].position = value7;
						Dust expr_1BAF2_cp_0 = Main.dust[num561];
						expr_1BAF2_cp_0.position.X = expr_1BAF2_cp_0.position.X + (float)(this.width / 2);
						Dust expr_1BB16_cp_0 = Main.dust[num561];
						expr_1BB16_cp_0.position.Y = expr_1BB16_cp_0.position.Y + (float)(this.height / 2);
						Main.dust[num561].scale = (float)Main.rand.Next(70, 110) * 0.013f;
						Main.dust[num561].velocity *= 0.2f;
					}
				}
				else if (this.type == 290)
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
					}
					this.localAI[0] += 1f;
					if (this.localAI[0] > 3f)
					{
						for (int num562 = 0; num562 < 3; num562++)
						{
							Vector2 value8 = this.position;
							value8 -= this.velocity * ((float)num562 * 0.3334f);
							this.alpha = 255;
							int num563 = Dust.NewDust(value8, 1, 1, 173, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num563].position = value8;
							Main.dust[num563].scale = (float)Main.rand.Next(70, 110) * 0.013f;
							Main.dust[num563].velocity *= 0.2f;
						}
					}
				}
				else if (this.type == 294)
				{
					this.localAI[0] += 1f;
					if (this.localAI[0] > 9f)
					{
						for (int num564 = 0; num564 < 4; num564++)
						{
							Vector2 value9 = this.position;
							value9 -= this.velocity * ((float)num564 * 0.25f);
							this.alpha = 255;
							int num565 = Dust.NewDust(value9, 1, 1, 173, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num565].position = value9;
							Main.dust[num565].scale = (float)Main.rand.Next(70, 110) * 0.013f;
							Main.dust[num565].velocity *= 0.2f;
						}
					}
				}
				else
				{
					this.localAI[0] += 1f;
					if (this.localAI[0] > 3f)
					{
						for (int num566 = 0; num566 < 4; num566++)
						{
							Vector2 value10 = this.position;
							value10 -= this.velocity * ((float)num566 * 0.25f);
							this.alpha = 255;
							int num567 = Dust.NewDust(value10, 1, 1, 162, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num567].position = value10;
							Dust expr_1BEBE_cp_0 = Main.dust[num567];
							expr_1BEBE_cp_0.position.X = expr_1BEBE_cp_0.position.X + (float)(this.width / 2);
							Dust expr_1BEE2_cp_0 = Main.dust[num567];
							expr_1BEE2_cp_0.position.Y = expr_1BEE2_cp_0.position.Y + (float)(this.height / 2);
							Main.dust[num567].scale = (float)Main.rand.Next(70, 110) * 0.013f;
							Main.dust[num567].velocity *= 0.2f;
						}
					}
				}
			}
			else if (this.aiStyle == 49)
			{
				if (this.ai[1] == 0f)
				{
					this.ai[1] = 1f;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 14);
				}
				if (this.ai[1] == 1f)
				{
					if (this.velocity.X > 0f)
					{
						this.direction = 1;
					}
					else if (this.velocity.X < 0f)
					{
						this.direction = -1;
					}
					this.spriteDirection = this.direction;
					this.ai[0] += 1f;
					this.rotation += this.velocity.X * 0.05f + (float)this.direction * 0.05f;
					if (this.ai[0] >= 18f)
					{
						this.velocity.Y = this.velocity.Y + 0.28f;
						this.velocity.X = this.velocity.X * 0.99f;
					}
					if ((double)this.velocity.Y > 15.9)
					{
						this.velocity.Y = 15.9f;
					}
					if (this.ai[0] > 2f)
					{
						this.alpha = 0;
						if (this.ai[0] == 3f)
						{
							for (int num568 = 0; num568 < 10; num568++)
							{
								int num569 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 31, 0f, 0f, 100, default(Color), 1.5f);
								Main.dust[num569].velocity *= 0.5f;
								Main.dust[num569].velocity += this.velocity * 0.1f;
							}
							for (int num570 = 0; num570 < 5; num570++)
							{
								int num571 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 2f);
								Main.dust[num571].noGravity = true;
								Main.dust[num571].velocity *= 3f;
								Main.dust[num571].velocity += this.velocity * 0.2f;
								num571 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 1f);
								Main.dust[num571].velocity *= 2f;
								Main.dust[num571].velocity += this.velocity * 0.3f;
							}
							for (int num572 = 0; num572 < 1; num572++)
							{
								int num573 = Gore.NewGore(new Vector2(this.position.X - 10f, this.position.Y - 10f), default(Vector2), Main.rand.Next(61, 64), 1f);
								Main.gore[num573].position += this.velocity * 1.25f;
								Main.gore[num573].scale = 1.5f;
								Main.gore[num573].velocity += this.velocity * 0.5f;
								Main.gore[num573].velocity *= 0.02f;
							}
						}
					}
				}
				else if (this.ai[1] == 2f)
				{
					this.rotation = 0f;
					this.velocity.X = this.velocity.X * 0.95f;
					this.velocity.Y = this.velocity.Y + 0.2f;
				}
			}
			else if (this.aiStyle == 50)
			{
				if (this.type == 291)
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 20);
						this.localAI[0] += 1f;
					}
					bool flag22 = false;
					bool flag23 = false;
					if (this.velocity.X < 0f && this.position.X < this.ai[0])
					{
						flag22 = true;
					}
					if (this.velocity.X > 0f && this.position.X > this.ai[0])
					{
						flag22 = true;
					}
					if (this.velocity.Y < 0f && this.position.Y < this.ai[1])
					{
						flag23 = true;
					}
					if (this.velocity.Y > 0f && this.position.Y > this.ai[1])
					{
						flag23 = true;
					}
					if (flag22 && flag23)
					{
						this.Kill();
					}
					for (int num574 = 0; num574 < 10; num574++)
					{
						int num575 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 174, 0f, 0f, 100, default(Color), 1.2f);
						Main.dust[num575].noGravity = true;
						Main.dust[num575].velocity *= 0.5f;
						Main.dust[num575].velocity += this.velocity * 0.1f;
					}
				}
				else if (this.type == 295)
				{
					for (int num576 = 0; num576 < 8; num576++)
					{
						int num577 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 174, 0f, 0f, 100, default(Color), 1.2f);
						Main.dust[num577].noGravity = true;
						Main.dust[num577].velocity *= 0.5f;
						Main.dust[num577].velocity += this.velocity * 0.1f;
					}
				}
				else
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 10);
						this.localAI[0] += 1f;
					}
					this.ai[0] += 1f;
					if (this.type == 296)
					{
						this.ai[0] += 3f;
					}
					float num578 = 25f;
					if (this.ai[0] > 180f)
					{
						num578 -= (this.ai[0] - 180f) / 2f;
					}
					if (num578 <= 0f)
					{
						num578 = 0f;
						this.Kill();
					}
					if (this.type == 296)
					{
						num578 *= 0.7f;
					}
					int num579 = 0;
					while ((float)num579 < num578)
					{
						float num580 = (float)Main.rand.Next(-10, 11);
						float num581 = (float)Main.rand.Next(-10, 11);
						float num582 = (float)Main.rand.Next(3, 9);
						float num583 = (float)Math.Sqrt((double)(num580 * num580 + num581 * num581));
						num583 = num582 / num583;
						num580 *= num583;
						num581 *= num583;
						int num584 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 174, 0f, 0f, 100, default(Color), 1.5f);
						Main.dust[num584].noGravity = true;
						Main.dust[num584].position.X = this.center().X;
						Main.dust[num584].position.Y = this.center().Y;
						Dust expr_1C945_cp_0 = Main.dust[num584];
						expr_1C945_cp_0.position.X = expr_1C945_cp_0.position.X + (float)Main.rand.Next(-10, 11);
						Dust expr_1C96F_cp_0 = Main.dust[num584];
						expr_1C96F_cp_0.position.Y = expr_1C96F_cp_0.position.Y + (float)Main.rand.Next(-10, 11);
						Main.dust[num584].velocity.X = num580;
						Main.dust[num584].velocity.Y = num581;
						num579++;
					}
				}
			}
			else if (this.aiStyle == 51)
			{
				if (this.type == 297)
				{
					this.localAI[0] += 1f;
					if (this.localAI[0] > 4f)
					{
						for (int num585 = 0; num585 < 5; num585++)
						{
							int num586 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 175, 0f, 0f, 100, default(Color), 2f);
							Main.dust[num586].noGravity = true;
							Main.dust[num586].velocity *= 0f;
						}
					}
				}
				else
				{
					if (this.localAI[0] == 0f)
					{
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 8);
						this.localAI[0] += 1f;
					}
					for (int num587 = 0; num587 < 9; num587++)
					{
						int num588 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 175, 0f, 0f, 100, default(Color), 1.3f);
						Main.dust[num588].noGravity = true;
						Main.dust[num588].velocity *= 0f;
					}
				}
				float num589 = this.center().X;
				float num590 = this.center().Y;
				float num591 = 400f;
				bool flag24 = false;
				if (this.type == 297)
				{
					for (int num592 = 0; num592 < 200; num592++)
					{
						if (Main.npc[num592].active && !Main.npc[num592].dontTakeDamage && !Main.npc[num592].friendly && Main.npc[num592].lifeMax > 5 && Collision.CanHit(this.center(), 1, 1, Main.npc[num592].center(), 1, 1))
						{
							float num593 = Main.npc[num592].position.X + (float)(Main.npc[num592].width / 2);
							float num594 = Main.npc[num592].position.Y + (float)(Main.npc[num592].height / 2);
							float num595 = Math.Abs(this.position.X + (float)(this.width / 2) - num593) + Math.Abs(this.position.Y + (float)(this.height / 2) - num594);
							if (num595 < num591)
							{
								num591 = num595;
								num589 = num593;
								num590 = num594;
								flag24 = true;
							}
						}
					}
				}
				else
				{
					num591 = 200f;
					for (int num596 = 0; num596 < 255; num596++)
					{
						if (Main.player[num596].active && !Main.player[num596].dead)
						{
							float num597 = Main.player[num596].position.X + (float)(Main.player[num596].width / 2);
							float num598 = Main.player[num596].position.Y + (float)(Main.player[num596].height / 2);
							float num599 = Math.Abs(this.position.X + (float)(this.width / 2) - num597) + Math.Abs(this.position.Y + (float)(this.height / 2) - num598);
							if (num599 < num591)
							{
								num591 = num599;
								num589 = num597;
								num590 = num598;
								flag24 = true;
							}
						}
					}
				}
				if (flag24)
				{
					float num600 = 3f;
					if (this.type == 297)
					{
						num600 = 6f;
					}
					Vector2 vector40 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num601 = num589 - vector40.X;
					float num602 = num590 - vector40.Y;
					float num603 = (float)Math.Sqrt((double)(num601 * num601 + num602 * num602));
					num603 = num600 / num603;
					num601 *= num603;
					num602 *= num603;
					if (this.type == 297)
					{
						this.velocity.X = (this.velocity.X * 20f + num601) / 21f;
						this.velocity.Y = (this.velocity.Y * 20f + num602) / 21f;
					}
					else
					{
						this.velocity.X = (this.velocity.X * 100f + num601) / 101f;
						this.velocity.Y = (this.velocity.Y * 100f + num602) / 101f;
					}
				}
			}
			else if (this.aiStyle == 52)
			{
				int num604 = (int)this.ai[0];
				float num605 = 4f;
				Vector2 vector41 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
				float num606 = Main.player[num604].center().X - vector41.X;
				float num607 = Main.player[num604].center().Y - vector41.Y;
				float num608 = (float)Math.Sqrt((double)(num606 * num606 + num607 * num607));
				if (num608 < 50f && this.position.X < Main.player[num604].position.X + (float)Main.player[num604].width && this.position.X + (float)this.width > Main.player[num604].position.X && this.position.Y < Main.player[num604].position.Y + (float)Main.player[num604].height && this.position.Y + (float)this.height > Main.player[num604].position.Y)
				{
					if (this.owner == Main.myPlayer)
					{
						int num609 = (int)this.ai[1];
						Main.player[num604].HealEffect(num609, false);
						Main.player[num604].statLife += num609;
						if (Main.player[num604].statLife > Main.player[num604].statLifeMax2)
						{
							Main.player[num604].statLife = Main.player[num604].statLifeMax2;
						}
						NetMessage.SendData(66, -1, -1, "", num604, (float)num609, 0f, 0f, 0);
					}
					this.Kill();
				}
				num608 = num605 / num608;
				num606 *= num608;
				num607 *= num608;
				this.velocity.X = (this.velocity.X * 15f + num606) / 16f;
				this.velocity.Y = (this.velocity.Y * 15f + num607) / 16f;
				if (this.type == 305)
				{
					for (int num610 = 0; num610 < 3; num610++)
					{
						float num611 = this.velocity.X * 0.334f * (float)num610;
						float num612 = -(this.velocity.Y * 0.334f) * (float)num610;
						int num613 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 183, 0f, 0f, 100, default(Color), 1.1f);
						Main.dust[num613].noGravity = true;
						Main.dust[num613].velocity *= 0f;
						Dust expr_1D378_cp_0 = Main.dust[num613];
						expr_1D378_cp_0.position.X = expr_1D378_cp_0.position.X - num611;
						Dust expr_1D397_cp_0 = Main.dust[num613];
						expr_1D397_cp_0.position.Y = expr_1D397_cp_0.position.Y - num612;
					}
				}
				else
				{
					for (int num614 = 0; num614 < 5; num614++)
					{
						float num615 = this.velocity.X * 0.2f * (float)num614;
						float num616 = -(this.velocity.Y * 0.2f) * (float)num614;
						int num617 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 175, 0f, 0f, 100, default(Color), 1.3f);
						Main.dust[num617].noGravity = true;
						Main.dust[num617].velocity *= 0f;
						Dust expr_1D493_cp_0 = Main.dust[num617];
						expr_1D493_cp_0.position.X = expr_1D493_cp_0.position.X - num615;
						Dust expr_1D4B2_cp_0 = Main.dust[num617];
						expr_1D4B2_cp_0.position.Y = expr_1D4B2_cp_0.position.Y - num616;
					}
				}
			}
			else if (this.aiStyle == 53)
			{
				if (this.localAI[0] == 0f)
				{
					this.localAI[1] = 1f;
					this.localAI[0] = 1f;
					this.ai[0] = 120f;
					int num618 = 80;
					Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 46);
					if (this.type == 308)
					{
						for (int num619 = 0; num619 < num618; num619++)
						{
							int num620 = Dust.NewDust(new Vector2(this.position.X, this.position.Y + 16f), this.width, this.height - 16, 185, 0f, 0f, 0, default(Color), 1f);
							Main.dust[num620].velocity *= 2f;
							Main.dust[num620].noGravity = true;
							Main.dust[num620].scale *= 1.15f;
						}
					}
					if (this.type == 377)
					{
						this.frame = 4;
						num618 = 40;
						for (int num621 = 0; num621 < num618; num621++)
						{
							int num622 = Dust.NewDust(this.position + Vector2.UnitY * 16f, this.width, this.height - 16, 171, 0f, 0f, 100, default(Color), 1f);
							Main.dust[num622].scale = (float)Main.rand.Next(1, 10) * 0.1f;
							Main.dust[num622].noGravity = true;
							Main.dust[num622].fadeIn = 1.5f;
							Main.dust[num622].velocity *= 0.75f;
						}
					}
				}
				this.velocity.X = 0f;
				this.velocity.Y = this.velocity.Y + 0.2f;
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
				bool flag25 = false;
				float num623 = this.center().X;
				float num624 = this.center().Y;
				float num625 = 1000f;
				for (int num626 = 0; num626 < 200; num626++)
				{
					if (Main.npc[num626].active && !Main.npc[num626].dontTakeDamage && !Main.npc[num626].friendly && Main.npc[num626].lifeMax > 5)
					{
						float num627 = Main.npc[num626].position.X + (float)(Main.npc[num626].width / 2);
						float num628 = Main.npc[num626].position.Y + (float)(Main.npc[num626].height / 2);
						float num629 = Math.Abs(this.position.X + (float)(this.width / 2) - num627) + Math.Abs(this.position.Y + (float)(this.height / 2) - num628);
						if (num629 < num625 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num626].position, Main.npc[num626].width, Main.npc[num626].height))
						{
							num625 = num629;
							num623 = num627;
							num624 = num628;
							flag25 = true;
						}
					}
				}
				if (flag25)
				{
					float num630 = num623;
					float num631 = num624;
					num623 -= this.center().X;
					num624 -= this.center().Y;
					if (num623 < 0f)
					{
						this.spriteDirection = -1;
					}
					else
					{
						this.spriteDirection = 1;
					}
					int num632;
					if (num624 > 0f)
					{
						num632 = 0;
					}
					else if (Math.Abs(num624) > Math.Abs(num623) * 3f)
					{
						num632 = 4;
					}
					else if (Math.Abs(num624) > Math.Abs(num623) * 2f)
					{
						num632 = 3;
					}
					else if (Math.Abs(num623) > Math.Abs(num624) * 3f)
					{
						num632 = 0;
					}
					else if (Math.Abs(num623) > Math.Abs(num624) * 2f)
					{
						num632 = 1;
					}
					else
					{
						num632 = 2;
					}
					if (this.type == 308)
					{
						this.frame = num632 * 2;
					}
					else if (this.type == 377)
					{
						this.frame = num632;
					}
					if (this.ai[0] > 40f && this.localAI[1] == 0f && this.type == 308)
					{
						this.frame++;
					}
					if (this.ai[0] <= 0f)
					{
						this.localAI[1] = 0f;
						this.ai[0] = 60f;
						if (Main.myPlayer == this.owner)
						{
							float num633 = 6f;
							int num634 = 309;
							if (this.type == 377)
							{
								num634 = 378;
								num633 = 9f;
							}
							Vector2 vector42 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
							if (num632 == 0)
							{
								vector42.Y += 12f;
								vector42.X += (float)(24 * this.spriteDirection);
							}
							else if (num632 == 1)
							{
								vector42.Y += 0f;
								vector42.X += (float)(24 * this.spriteDirection);
							}
							else if (num632 == 2)
							{
								vector42.Y -= 2f;
								vector42.X += (float)(24 * this.spriteDirection);
							}
							else if (num632 == 3)
							{
								vector42.Y -= 6f;
								vector42.X += (float)(14 * this.spriteDirection);
							}
							else if (num632 == 4)
							{
								vector42.Y -= 14f;
								vector42.X += (float)(2 * this.spriteDirection);
							}
							if (this.spriteDirection < 0)
							{
								vector42.X += 10f;
							}
							float num635 = num630 - vector42.X;
							float num636 = num631 - vector42.Y;
							float num637 = (float)Math.Sqrt((double)(num635 * num635 + num636 * num636));
							num637 = num633 / num637;
							num635 *= num637;
							num636 *= num637;
							int num638 = this.damage;
							Projectile.NewProjectile(vector42.X, vector42.Y, num635, num636, num634, num638, this.knockBack, Main.myPlayer, 0f, 0f);
						}
					}
				}
				else if (this.ai[0] <= 60f && (this.frame == 1 || this.frame == 3 || this.frame == 5 || this.frame == 7 || this.frame == 9))
				{
					this.frame--;
				}
				if (this.ai[0] > 0f)
				{
					this.ai[0] -= 1f;
				}
			}
			else if (this.aiStyle == 54)
			{
				if (this.type == 317)
				{
					if (Main.player[Main.myPlayer].dead)
					{
						Main.player[Main.myPlayer].raven = false;
					}
					if (Main.player[Main.myPlayer].raven)
					{
						this.timeLeft = 2;
					}
				}
				for (int num639 = 0; num639 < 1000; num639++)
				{
					if (num639 != this.whoAmI && Main.projectile[num639].active && Main.projectile[num639].owner == this.owner && Main.projectile[num639].type == this.type && Math.Abs(this.position.X - Main.projectile[num639].position.X) + Math.Abs(this.position.Y - Main.projectile[num639].position.Y) < (float)this.width)
					{
						if (this.position.X < Main.projectile[num639].position.X)
						{
							this.velocity.X = this.velocity.X - 0.05f;
						}
						else
						{
							this.velocity.X = this.velocity.X + 0.05f;
						}
						if (this.position.Y < Main.projectile[num639].position.Y)
						{
							this.velocity.Y = this.velocity.Y - 0.05f;
						}
						else
						{
							this.velocity.Y = this.velocity.Y + 0.05f;
						}
					}
				}
				float num640 = this.position.X;
				float num641 = this.position.Y;
				float num642 = 800f;
				bool flag26 = false;
				int num643 = 500;
				if (this.ai[1] != 0f || this.friendly)
				{
					num643 = 1400;
				}
				if (Math.Abs(this.center().X - Main.player[this.owner].center().X) + Math.Abs(this.center().Y - Main.player[this.owner].center().Y) > (float)num643)
				{
					this.ai[0] = 1f;
				}
				if (this.ai[0] == 0f)
				{
					this.tileCollide = true;
					for (int num644 = 0; num644 < 200; num644++)
					{
						if (Main.npc[num644].active && !Main.npc[num644].dontTakeDamage && !Main.npc[num644].friendly && Main.npc[num644].lifeMax > 5)
						{
							float num645 = Main.npc[num644].position.X + (float)(Main.npc[num644].width / 2);
							float num646 = Main.npc[num644].position.Y + (float)(Main.npc[num644].height / 2);
							float num647 = Math.Abs(this.position.X + (float)(this.width / 2) - num645) + Math.Abs(this.position.Y + (float)(this.height / 2) - num646);
							if (num647 < num642 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num644].position, Main.npc[num644].width, Main.npc[num644].height))
							{
								num642 = num647;
								num640 = num645;
								num641 = num646;
								flag26 = true;
							}
						}
					}
				}
				else
				{
					this.tileCollide = false;
				}
				if (!flag26)
				{
					this.friendly = true;
					float num648 = 8f;
					if (this.ai[0] == 1f)
					{
						num648 = 12f;
					}
					Vector2 vector43 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num649 = Main.player[this.owner].center().X - vector43.X;
					float num650 = Main.player[this.owner].center().Y - vector43.Y - 60f;
					float num651 = (float)Math.Sqrt((double)(num649 * num649 + num650 * num650));
					if (num651 < 100f && this.ai[0] == 1f && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
					}
					if (num651 > 2000f)
					{
						this.position.X = Main.player[this.owner].center().X - (float)(this.width / 2);
						this.position.Y = Main.player[this.owner].center().Y - (float)(this.width / 2);
					}
					if (num651 > 70f)
					{
						num651 = num648 / num651;
						num649 *= num651;
						num650 *= num651;
						this.velocity.X = (this.velocity.X * 20f + num649) / 21f;
						this.velocity.Y = (this.velocity.Y * 20f + num650) / 21f;
					}
					else
					{
						if (this.velocity.X == 0f && this.velocity.Y == 0f)
						{
							this.velocity.X = -0.15f;
							this.velocity.Y = -0.05f;
						}
						this.velocity *= 1.01f;
					}
					this.friendly = false;
					this.rotation = this.velocity.X * 0.05f;
					this.frameCounter++;
					if (this.frameCounter >= 4)
					{
						this.frameCounter = 0;
						this.frame++;
					}
					if (this.frame > 3)
					{
						this.frame = 0;
					}
					if ((double)Math.Abs(this.velocity.X) > 0.2)
					{
						this.spriteDirection = -this.direction;
					}
				}
				else
				{
					if (this.ai[1] == -1f)
					{
						this.ai[1] = 17f;
					}
					if (this.ai[1] > 0f)
					{
						this.ai[1] -= 1f;
					}
					if (this.ai[1] == 0f)
					{
						this.friendly = true;
						float num652 = 8f;
						Vector2 vector44 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num653 = num640 - vector44.X;
						float num654 = num641 - vector44.Y;
						float num655 = (float)Math.Sqrt((double)(num653 * num653 + num654 * num654));
						if (num655 < 100f)
						{
							num652 = 10f;
						}
						num655 = num652 / num655;
						num653 *= num655;
						num654 *= num655;
						this.velocity.X = (this.velocity.X * 14f + num653) / 15f;
						this.velocity.Y = (this.velocity.Y * 14f + num654) / 15f;
					}
					else
					{
						this.friendly = false;
						if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) < 10f)
						{
							this.velocity *= 1.05f;
						}
					}
					this.rotation = this.velocity.X * 0.05f;
					this.frameCounter++;
					if (this.frameCounter >= 4)
					{
						this.frameCounter = 0;
						this.frame++;
					}
					if (this.frame < 4)
					{
						this.frame = 4;
					}
					if (this.frame > 7)
					{
						this.frame = 4;
					}
					if ((double)Math.Abs(this.velocity.X) > 0.2)
					{
						this.spriteDirection = -this.direction;
					}
				}
			}
			else if (this.aiStyle == 55)
			{
				this.frameCounter++;
				if (this.frameCounter > 0)
				{
					this.frame++;
					this.frameCounter = 0;
					if (this.frame > 2)
					{
						this.frame = 0;
					}
				}
				if (this.velocity.X < 0f)
				{
					this.spriteDirection = -1;
					this.rotation = (float)Math.Atan2((double)(-(double)this.velocity.Y), (double)(-(double)this.velocity.X));
				}
				else
				{
					this.spriteDirection = 1;
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X);
				}
				if (this.ai[0] >= 0f && this.ai[0] < 200f)
				{
					int num656 = (int)this.ai[0];
					if (Main.npc[num656].active)
					{
						float num657 = 8f;
						Vector2 vector45 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
						float num658 = Main.npc[num656].position.X - vector45.X;
						float num659 = Main.npc[num656].position.Y - vector45.Y;
						float num660 = (float)Math.Sqrt((double)(num658 * num658 + num659 * num659));
						num660 = num657 / num660;
						num658 *= num660;
						num659 *= num660;
						this.velocity.X = (this.velocity.X * 14f + num658) / 15f;
						this.velocity.Y = (this.velocity.Y * 14f + num659) / 15f;
					}
					else
					{
						float num661 = 1000f;
						for (int num662 = 0; num662 < 200; num662++)
						{
							if (Main.npc[num662].active && !Main.npc[num662].dontTakeDamage && !Main.npc[num662].friendly && Main.npc[num662].lifeMax > 5)
							{
								float num663 = Main.npc[num662].position.X + (float)(Main.npc[num662].width / 2);
								float num664 = Main.npc[num662].position.Y + (float)(Main.npc[num662].height / 2);
								float num665 = Math.Abs(this.position.X + (float)(this.width / 2) - num663) + Math.Abs(this.position.Y + (float)(this.height / 2) - num664);
								if (num665 < num661 && Collision.CanHit(this.position, this.width, this.height, Main.npc[num662].position, Main.npc[num662].width, Main.npc[num662].height))
								{
									num661 = num665;
									this.ai[0] = (float)num662;
								}
							}
						}
					}
					int num666 = 8;
					int num667 = Dust.NewDust(new Vector2(this.position.X + (float)num666, this.position.Y + (float)num666), this.width - num666 * 2, this.height - num666 * 2, 6, 0f, 0f, 0, default(Color), 1f);
					Main.dust[num667].velocity *= 0.5f;
					Main.dust[num667].velocity += this.velocity * 0.5f;
					Main.dust[num667].noGravity = true;
					Main.dust[num667].noLight = true;
					Main.dust[num667].scale = 1.4f;
				}
				else
				{
					this.Kill();
				}
			}
			else if (this.aiStyle == 56)
			{
				if (this.localAI[0] == 0f)
				{
					this.localAI[0] = 1f;
					this.rotation = this.ai[0];
					this.spriteDirection = -(int)this.ai[1];
				}
				if (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y) < 16f)
				{
					this.velocity *= 1.05f;
				}
				if (this.velocity.X < 0f)
				{
					this.direction = -1;
				}
				else
				{
					this.direction = 1;
				}
				this.rotation += (Math.Abs(this.velocity.X) + Math.Abs(this.velocity.Y)) * 0.025f * (float)this.direction;
			}
			else if (this.aiStyle == 57)
			{
				this.ai[0] += 1f;
				if (this.ai[0] > 30f)
				{
					this.ai[0] = 30f;
					this.velocity.Y = this.velocity.Y + 0.25f;
					if (this.velocity.Y > 16f)
					{
						this.velocity.Y = 16f;
					}
					this.velocity.X = this.velocity.X * 0.995f;
				}
				this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
				this.alpha -= 50;
				if (this.alpha < 0)
				{
					this.alpha = 0;
				}
				if (this.owner == Main.myPlayer)
				{
					this.localAI[0] += 1f;
					if (this.localAI[0] >= 4f)
					{
						this.localAI[0] = 0f;
						int num668 = 0;
						for (int num669 = 0; num669 < 1000; num669++)
						{
							if (Main.projectile[num669].active && Main.projectile[num669].owner == this.owner && Main.projectile[num669].type == 344)
							{
								num668++;
							}
						}
						float num670 = (float)this.damage * 0.8f;
						if (num668 > 100)
						{
							float num671 = (float)(num668 - 100);
							num671 = 1f - num671 / 100f;
							num670 *= num671;
						}
						if (num668 > 100)
						{
							this.localAI[0] -= 1f;
						}
						if (num668 > 120)
						{
							this.localAI[0] -= 1f;
						}
						if (num668 > 140)
						{
							this.localAI[0] -= 1f;
						}
						if (num668 > 150)
						{
							this.localAI[0] -= 1f;
						}
						if (num668 > 160)
						{
							this.localAI[0] -= 1f;
						}
						if (num668 > 165)
						{
							this.localAI[0] -= 1f;
						}
						if (num668 > 170)
						{
							this.localAI[0] -= 2f;
						}
						if (num668 > 175)
						{
							this.localAI[0] -= 3f;
						}
						if (num668 > 180)
						{
							this.localAI[0] -= 4f;
						}
						if (num668 > 185)
						{
							this.localAI[0] -= 5f;
						}
						if (num668 > 190)
						{
							this.localAI[0] -= 6f;
						}
						if (num668 > 195)
						{
							this.localAI[0] -= 7f;
						}
						if (num670 > (float)this.damage * 0.1f)
						{
							Projectile.NewProjectile(this.center().X, this.center().Y, 0f, 0f, 344, (int)num670, this.knockBack * 0.55f, this.owner, 0f, (float)Main.rand.Next(3));
						}
					}
				}
			}
			else if (this.aiStyle == 58)
			{
				this.alpha -= 50;
				if (this.alpha < 0)
				{
					this.alpha = 0;
				}
				if (this.ai[0] == 0f)
				{
					this.frame = 0;
					this.ai[1] += 1f;
					if (this.ai[1] > 30f)
					{
						this.velocity.Y = this.velocity.Y + 0.1f;
					}
					if (this.velocity.Y >= 0f)
					{
						this.ai[0] = 1f;
					}
				}
				if (this.ai[0] == 1f)
				{
					this.frame = 1;
					this.velocity.Y = this.velocity.Y + 0.1f;
					if (this.velocity.Y > 3f)
					{
						this.velocity.Y = 3f;
					}
					this.velocity.X = this.velocity.X * 0.99f;
				}
				this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
			}
			else if (this.aiStyle == 59)
			{
				this.ai[1] += 1f;
				if (this.ai[1] >= 60f)
				{
					this.friendly = true;
					int num672 = (int)this.ai[0];
					if (!Main.npc[num672].active)
					{
						int[] array2 = new int[200];
						int num673 = 0;
						for (int num674 = 0; num674 < 200; num674++)
						{
							if (Main.npc[num674].active && !Main.npc[num674].friendly && Main.npc[num674].lifeMax > 5 && !Main.npc[num674].dontTakeDamage)
							{
								float num675 = Math.Abs(Main.npc[num674].position.X + (float)(Main.npc[num674].width / 2) - this.position.X + (float)(this.width / 2)) + Math.Abs(Main.npc[num674].position.Y + (float)(Main.npc[num674].height / 2) - this.position.Y + (float)(this.height / 2));
								if (num675 < 800f)
								{
									array2[num673] = num674;
									num673++;
								}
							}
						}
						if (num673 == 0)
						{
							this.Kill();
							return;
						}
						num672 = array2[Main.rand.Next(num673)];
						this.ai[0] = (float)num672;
					}
					float num676 = 4f;
					Vector2 vector46 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num677 = Main.npc[num672].center().X - vector46.X;
					float num678 = Main.npc[num672].center().Y - vector46.Y;
					float num679 = (float)Math.Sqrt((double)(num677 * num677 + num678 * num678));
					num679 = num676 / num679;
					num677 *= num679;
					num678 *= num679;
					int num680 = 30;
					this.velocity.X = (this.velocity.X * (float)(num680 - 1) + num677) / (float)num680;
					this.velocity.Y = (this.velocity.Y * (float)(num680 - 1) + num678) / (float)num680;
				}
				for (int num681 = 0; num681 < 5; num681++)
				{
					float num682 = this.velocity.X * 0.2f * (float)num681;
					float num683 = -(this.velocity.Y * 0.2f) * (float)num681;
					int num684 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 175, 0f, 0f, 100, default(Color), 1.3f);
					Main.dust[num684].noGravity = true;
					Main.dust[num684].velocity *= 0f;
					Dust expr_1F565_cp_0 = Main.dust[num684];
					expr_1F565_cp_0.position.X = expr_1F565_cp_0.position.X - num682;
					Dust expr_1F584_cp_0 = Main.dust[num684];
					expr_1F584_cp_0.position.Y = expr_1F584_cp_0.position.Y - num683;
				}
			}
			else if (this.aiStyle == 60)
			{
				this.scale -= 0.015f;
				if (this.scale <= 0f)
				{
					this.velocity *= 5f;
					this.lastVelocity = this.velocity;
					this.Kill();
				}
				if (this.ai[0] > 3f)
				{
					int num685 = 103;
					if (this.type == 406)
					{
						num685 = 137;
					}
					if (this.owner == Main.myPlayer)
					{
						Rectangle rectangle4 = new Rectangle((int)this.position.X, (int)this.position.Y, this.width, this.height);
						for (int num686 = 0; num686 < 200; num686++)
						{
							if (Main.npc[num686].active && !Main.npc[num686].dontTakeDamage && Main.npc[num686].lifeMax > 1)
							{
								Rectangle value11 = new Rectangle((int)Main.npc[num686].position.X, (int)Main.npc[num686].position.Y, Main.npc[num686].width, Main.npc[num686].height);
								if (rectangle4.Intersects(value11))
								{
									Main.npc[num686].AddBuff(num685, 1500, false);
									this.Kill();
								}
							}
						}
						for (int num687 = 0; num687 < 255; num687++)
						{
							if (num687 != this.owner && Main.player[num687].active && !Main.player[num687].dead)
							{
								Rectangle value12 = new Rectangle((int)Main.player[num687].position.X, (int)Main.player[num687].position.Y, Main.player[num687].width, Main.player[num687].height);
								if (rectangle4.Intersects(value12))
								{
									Main.player[num687].AddBuff(num685, 1500, false);
									this.Kill();
								}
							}
						}
					}
					this.ai[0] += this.ai[1];
					if (this.ai[0] > 30f)
					{
						this.velocity.Y = this.velocity.Y + 0.1f;
					}
					if (this.type == 358)
					{
						for (int num688 = 0; num688 < 1; num688++)
						{
							for (int num689 = 0; num689 < 6; num689++)
							{
								float num690 = this.velocity.X / 6f * (float)num689;
								float num691 = this.velocity.Y / 6f * (float)num689;
								int num692 = 6;
								int num693 = Dust.NewDust(new Vector2(this.position.X + (float)num692, this.position.Y + (float)num692), this.width - num692 * 2, this.height - num692 * 2, 211, 0f, 0f, 75, default(Color), 1.2f);
								if (Main.rand.Next(2) == 0)
								{
									Main.dust[num693].alpha += 25;
								}
								if (Main.rand.Next(2) == 0)
								{
									Main.dust[num693].alpha += 25;
								}
								if (Main.rand.Next(2) == 0)
								{
									Main.dust[num693].alpha += 25;
								}
								Main.dust[num693].noGravity = true;
								Main.dust[num693].velocity *= 0.3f;
								Main.dust[num693].velocity += this.velocity * 0.5f;
								Main.dust[num693].position = this.center();
								Dust expr_1FA1B_cp_0 = Main.dust[num693];
								expr_1FA1B_cp_0.position.X = expr_1FA1B_cp_0.position.X - num690;
								Dust expr_1FA3A_cp_0 = Main.dust[num693];
								expr_1FA3A_cp_0.position.Y = expr_1FA3A_cp_0.position.Y - num691;
								Main.dust[num693].velocity *= 0.2f;
							}
							if (Main.rand.Next(4) == 0)
							{
								int num694 = 6;
								int num695 = Dust.NewDust(new Vector2(this.position.X + (float)num694, this.position.Y + (float)num694), this.width - num694 * 2, this.height - num694 * 2, 211, 0f, 0f, 75, default(Color), 0.65f);
								Main.dust[num695].velocity *= 0.5f;
								Main.dust[num695].velocity += this.velocity * 0.5f;
							}
						}
					}
					if (this.type == 406)
					{
						int num696 = 175;
						Color newColor = new Color(0, 80, 255, 100);
						for (int num697 = 0; num697 < 6; num697++)
						{
							Vector2 vector47 = this.velocity * (float)num697 / 6f;
							int num698 = 6;
							int num699 = Dust.NewDust(this.position + Vector2.One * 6f, this.width - num698 * 2, this.height - num698 * 2, 4, 0f, 0f, num696, newColor, 1.2f);
							if (Main.rand.Next(2) == 0)
							{
								Main.dust[num699].alpha += 25;
							}
							if (Main.rand.Next(2) == 0)
							{
								Main.dust[num699].alpha += 25;
							}
							if (Main.rand.Next(2) == 0)
							{
								Main.dust[num699].alpha += 25;
							}
							Main.dust[num699].noGravity = true;
							Main.dust[num699].velocity *= 0.3f;
							Main.dust[num699].velocity += this.velocity * 0.5f;
							Main.dust[num699].position = this.center();
							Dust expr_1FCF7_cp_0 = Main.dust[num699];
							expr_1FCF7_cp_0.position.X = expr_1FCF7_cp_0.position.X - vector47.X;
							Dust expr_1FD1B_cp_0 = Main.dust[num699];
							expr_1FD1B_cp_0.position.Y = expr_1FD1B_cp_0.position.Y - vector47.Y;
							Main.dust[num699].velocity *= 0.2f;
						}
						if (Main.rand.Next(4) == 0)
						{
							int num700 = 6;
							int num701 = Dust.NewDust(this.position + Vector2.One * 6f, this.width - num700 * 2, this.height - num700 * 2, 4, 0f, 0f, num696, newColor, 1.2f);
							Main.dust[num701].velocity *= 0.5f;
							Main.dust[num701].velocity += this.velocity * 0.5f;
						}
					}
				}
				else
				{
					this.ai[0] += 1f;
				}
			}
			else if (this.aiStyle == 61)
			{
				this.timeLeft = 60;
				if (Main.player[this.owner].inventory[Main.player[this.owner].selectedItem].fishingPole == 0)
				{
					this.Kill();
				}
				else if (Main.player[this.owner].inventory[Main.player[this.owner].selectedItem].shoot != this.type)
				{
					this.Kill();
				}
				else if (Main.player[this.owner].pulley)
				{
					this.Kill();
				}
				else if (Main.player[this.owner].mount.Active)
				{
					this.Kill();
				}
				else if (Main.player[this.owner].dead)
				{
					this.Kill();
				}
				if (this.ai[1] > 0f && this.localAI[1] >= 0f)
				{
					this.localAI[1] = -1f;
					if (!this.lavaWet && !this.honeyWet)
					{
						for (int num702 = 0; num702 < 100; num702++)
						{
							int num703 = Dust.NewDust(new Vector2(this.position.X - 6f, this.position.Y - 10f), this.width + 12, 24, Dust.dustWater(), 0f, 0f, 0, default(Color), 1f);
							Dust expr_1FFB3_cp_0 = Main.dust[num703];
							expr_1FFB3_cp_0.velocity.Y = expr_1FFB3_cp_0.velocity.Y - 4f;
							Dust expr_1FFD3_cp_0 = Main.dust[num703];
							expr_1FFD3_cp_0.velocity.X = expr_1FFD3_cp_0.velocity.X * 2.5f;
							Main.dust[num703].scale = 0.8f;
							Main.dust[num703].alpha = 100;
							Main.dust[num703].noGravity = true;
						}
						Main.PlaySound(19, (int)this.position.X, (int)this.position.Y, 0);
					}
				}
				if (this.ai[0] >= 1f)
				{
					if (this.ai[0] == 2f)
					{
						this.ai[0] += 1f;
						Main.PlaySound(2, (int)this.position.X, (int)this.position.Y, 17);
						if (!this.lavaWet && !this.honeyWet)
						{
							for (int num704 = 0; num704 < 100; num704++)
							{
								int num705 = Dust.NewDust(new Vector2(this.position.X - 6f, this.position.Y - 10f), this.width + 12, 24, Dust.dustWater(), 0f, 0f, 0, default(Color), 1f);
								Dust expr_2013C_cp_0 = Main.dust[num705];
								expr_2013C_cp_0.velocity.Y = expr_2013C_cp_0.velocity.Y - 4f;
								Dust expr_2015C_cp_0 = Main.dust[num705];
								expr_2015C_cp_0.velocity.X = expr_2015C_cp_0.velocity.X * 2.5f;
								Main.dust[num705].scale = 0.8f;
								Main.dust[num705].alpha = 100;
								Main.dust[num705].noGravity = true;
							}
							Main.PlaySound(19, (int)this.position.X, (int)this.position.Y, 0);
						}
					}
					if (this.localAI[0] < 100f)
					{
						this.localAI[0] += 1f;
					}
					this.tileCollide = false;
					float num706 = 15.9f;
					int num707 = 10;
					Vector2 vector48 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num708 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector48.X;
					float num709 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector48.Y;
					float num710 = (float)Math.Sqrt((double)(num708 * num708 + num709 * num709));
					if (num710 > 3000f)
					{
						this.Kill();
					}
					num710 = num706 / num710;
					num708 *= num710;
					num709 *= num710;
					this.velocity.X = (this.velocity.X * (float)(num707 - 1) + num708) / (float)num707;
					this.velocity.Y = (this.velocity.Y * (float)(num707 - 1) + num709) / (float)num707;
					if (Main.myPlayer == this.owner)
					{
						Rectangle rectangle5 = new Rectangle((int)this.position.X, (int)this.position.Y, this.width, this.height);
						Rectangle value13 = new Rectangle((int)Main.player[this.owner].position.X, (int)Main.player[this.owner].position.Y, Main.player[this.owner].width, Main.player[this.owner].height);
						if (rectangle5.Intersects(value13))
						{
							if (this.ai[1] > 0f && this.ai[1] < 2749f)
							{
								int num711 = (int)this.ai[1];
								Item item = new Item();
								item.SetDefaults(num711, false);
								Item item2 = Main.player[this.owner].GetItem(this.owner, item, false);
								if (item2.stack > 0)
								{
									int number = Item.NewItem((int)this.position.X, (int)this.position.Y, this.width, this.height, num711, 1, false, 0, true);
									if (Main.netMode == 1)
									{
										NetMessage.SendData(21, -1, -1, "", number, 1f, 0f, 0f, 0);
									}
								}
								else
								{
									item.position.X = this.center().X - (float)(item.width / 2);
									item.position.Y = this.center().Y - (float)(item.height / 2);
									item.active = true;
									//ItemText.NewText(item, 0, false, false);
								}
							}
							this.Kill();
						}
					}
					this.rotation = (float)Math.Atan2((double)this.velocity.Y, (double)this.velocity.X) + 1.57f;
				}
				else
				{
					bool flag27 = false;
					Vector2 vector49 = new Vector2(this.position.X + (float)this.width * 0.5f, this.position.Y + (float)this.height * 0.5f);
					float num712 = Main.player[this.owner].position.X + (float)(Main.player[this.owner].width / 2) - vector49.X;
					float num713 = Main.player[this.owner].position.Y + (float)(Main.player[this.owner].height / 2) - vector49.Y;
					this.rotation = (float)Math.Atan2((double)num713, (double)num712) + 1.57f;
					float num714 = (float)Math.Sqrt((double)(num712 * num712 + num713 * num713));
					if (num714 > 900f)
					{
						this.ai[0] = 1f;
					}
					if (this.wet)
					{
						this.rotation = 0f;
						this.velocity.X = this.velocity.X * 0.9f;
						int num715 = (int)(this.center().X + (float)((this.width / 2 + 8) * this.direction)) / 16;
						int num716 = (int)(this.center().Y / 16f);
						float arg_20703_0 = this.position.Y / 16f;
						int num717 = (int)((this.position.Y + (float)this.height) / 16f);
						if (Main.tile[num715, num716] == null)
						{
							Main.tile[num715, num716] = new Tile();
						}
						if (Main.tile[num715, num717] == null)
						{
							Main.tile[num715, num717] = new Tile();
						}
						if (this.velocity.Y > 0f)
						{
							this.velocity.Y = this.velocity.Y * 0.5f;
						}
						num715 = (int)(this.center().X / 16f);
						num716 = (int)(this.center().Y / 16f);
						float num718 = this.position.Y + (float)this.height;
						if (Main.tile[num715, num716 - 1] == null)
						{
							Main.tile[num715, num716 - 1] = new Tile();
						}
						if (Main.tile[num715, num716] == null)
						{
							Main.tile[num715, num716] = new Tile();
						}
						if (Main.tile[num715, num716 + 1] == null)
						{
							Main.tile[num715, num716 + 1] = new Tile();
						}
						if (Main.tile[num715, num716 - 1].liquid > 0)
						{
							num718 = (float)(num716 * 16);
							num718 -= (float)(Main.tile[num715, num716 - 1].liquid / 16);
						}
						else if (Main.tile[num715, num716].liquid > 0)
						{
							num718 = (float)((num716 + 1) * 16);
							num718 -= (float)(Main.tile[num715, num716].liquid / 16);
						}
						else if (Main.tile[num715, num716 + 1].liquid > 0)
						{
							num718 = (float)((num716 + 2) * 16);
							num718 -= (float)(Main.tile[num715, num716 + 1].liquid / 16);
						}
						if (this.center().Y > num718)
						{
							this.velocity.Y = this.velocity.Y - 0.1f;
							if (this.velocity.Y < -8f)
							{
								this.velocity.Y = -8f;
							}
							if (this.center().Y + this.velocity.Y < num718)
							{
								this.velocity.Y = num718 - this.center().Y;
							}
						}
						else
						{
							this.velocity.Y = num718 - this.center().Y;
						}
						if ((double)this.velocity.Y >= -0.01 && (double)this.velocity.Y <= 0.01)
						{
							flag27 = true;
						}
					}
					else
					{
						if (this.velocity.Y == 0f)
						{
							this.velocity.X = this.velocity.X * 0.95f;
						}
						this.velocity.X = this.velocity.X * 0.98f;
						this.velocity.Y = this.velocity.Y + 0.2f;
						if (this.velocity.Y > 15.9f)
						{
							this.velocity.Y = 15.9f;
						}
					}
					if (this.ai[1] != 0f)
					{
						flag27 = true;
					}
					if (flag27)
					{
						if (this.ai[1] == 0f && Main.myPlayer == this.owner)
						{
							int num719 = Main.player[this.owner].FishingLevel();
							if (num719 == -9000)
							{
								this.localAI[1] += 5f;
								this.localAI[1] += (float)Main.rand.Next(1, 3);
								if (this.localAI[1] > 660f)
								{
									this.localAI[1] = 0f;
									this.FishingCheck();
								}
							}
							else
							{
								if (Main.rand.Next(300) < num719)
								{
									this.localAI[1] += (float)Main.rand.Next(1, 3);
								}
								this.localAI[1] += (float)(num719 / 30);
								this.localAI[1] += (float)Main.rand.Next(1, 3);
								if (Main.rand.Next(60) == 0)
								{
									this.localAI[1] += 60f;
								}
								if (this.localAI[1] > 660f)
								{
									this.localAI[1] = 0f;
									this.FishingCheck();
								}
							}
						}
						else if (this.ai[1] < 0f)
						{
							if (this.velocity.Y == 0f || (this.honeyWet && (double)this.velocity.Y >= -0.01 && (double)this.velocity.Y <= 0.01))
							{
								this.velocity.Y = (float)Main.rand.Next(100, 500) * 0.015f;
								this.velocity.X = (float)Main.rand.Next(-100, 101) * 0.015f;
								this.wet = false;
								this.lavaWet = false;
								this.honeyWet = false;
							}
							this.ai[1] += (float)Main.rand.Next(1, 5);
							if (this.ai[1] >= 0f)
							{
								this.ai[1] = 0f;
								this.localAI[1] = 0f;
								this.netUpdate = true;
							}
						}
					}
				}
			}
			if (this.aiStyle == 62)
			{
				if (this.type == 373)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].hornetMinion = false;
					}
					if (Main.player[this.owner].hornetMinion)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 375)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].impMinion = false;
					}
					if (Main.player[this.owner].impMinion)
					{
						this.timeLeft = 2;
					}
				}
				if (this.type == 407)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].sharknadoMinion = false;
					}
					if (Main.player[this.owner].sharknadoMinion)
					{
						this.timeLeft = 2;
					}
				}
				float num720 = 0.05f;
				float num721 = (float)this.width;
				if (this.type == 407)
				{
					num720 = 0.1f;
					num721 *= 2f;
				}
				for (int num722 = 0; num722 < 1000; num722++)
				{
					if (num722 != this.whoAmI && Main.projectile[num722].active && Main.projectile[num722].owner == this.owner && Main.projectile[num722].type == this.type && Math.Abs(this.position.X - Main.projectile[num722].position.X) + Math.Abs(this.position.Y - Main.projectile[num722].position.Y) < num721)
					{
						if (this.position.X < Main.projectile[num722].position.X)
						{
							this.velocity.X = this.velocity.X - num720;
						}
						else
						{
							this.velocity.X = this.velocity.X + num720;
						}
						if (this.position.Y < Main.projectile[num722].position.Y)
						{
							this.velocity.Y = this.velocity.Y - num720;
						}
						else
						{
							this.velocity.Y = this.velocity.Y + num720;
						}
					}
				}
				Vector2 vector50 = this.position;
				float num723 = 400f;
				bool flag28 = false;
				this.tileCollide = true;
				if (this.type == 407)
				{
					this.tileCollide = false;
					if (Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.alpha += 20;
						if (this.alpha > 150)
						{
							this.alpha = 150;
						}
					}
					else
					{
						this.alpha -= 50;
						if (this.alpha < 60)
						{
							this.alpha = 60;
						}
					}
				}
				if (this.type == 407)
				{
					Vector2 vector51 = Main.player[this.owner].center();
					for (int num724 = 0; num724 < 200; num724++)
					{
						NPC nPC = Main.npc[num724];
						if (nPC.active && !nPC.dontTakeDamage && !nPC.friendly && nPC.lifeMax > 5)
						{
							float num725 = Vector2.Distance(nPC.center(), vector51);
							if (((Vector2.Distance(vector51, vector50) > num725 && num725 < num723) || !flag28) && Collision.CanHitLine(this.position, this.width, this.height, nPC.position, nPC.width, nPC.height))
							{
								num723 = num725;
								vector50 = nPC.center();
								flag28 = true;
							}
						}
					}
				}
				else
				{
					for (int num726 = 0; num726 < 200; num726++)
					{
						NPC nPC2 = Main.npc[num726];
						if (nPC2.active && !nPC2.dontTakeDamage && !nPC2.friendly && nPC2.lifeMax > 5)
						{
							float num727 = Vector2.Distance(nPC2.center(), this.center());
							if (((Vector2.Distance(this.center(), vector50) > num727 && num727 < num723) || !flag28) && Collision.CanHitLine(this.position, this.width, this.height, nPC2.position, nPC2.width, nPC2.height))
							{
								num723 = num727;
								vector50 = nPC2.center();
								flag28 = true;
							}
						}
					}
				}
				int num728 = 500;
				if (flag28)
				{
					num728 = 1000;
				}
				Player player = Main.player[this.owner];
				if (Vector2.Distance(player.center(), this.center()) > (float)num728)
				{
					this.ai[0] = 1f;
					this.netUpdate = true;
				}
				if (this.ai[0] == 1f)
				{
					this.tileCollide = false;
				}
				if (flag28 && this.ai[0] == 0f)
				{
					Vector2 vector52 = vector50 - this.center();
					float num729 = vector52.Length();
					vector52.Normalize();
					if (this.type == 407)
					{
						if (num729 > 400f)
						{
							float scaleFactor2 = 2f;
							vector52 *= scaleFactor2;
							this.velocity = (this.velocity * 20f + vector52) / 21f;
						}
						else
						{
							this.velocity *= 0.96f;
						}
					}
					if (num729 > 200f)
					{
						float scaleFactor3 = 6f;
						vector52 *= scaleFactor3;
						this.velocity.X = (this.velocity.X * 40f + vector52.X) / 41f;
						this.velocity.Y = (this.velocity.Y * 40f + vector52.Y) / 41f;
					}
					else if (this.type == 375)
					{
						if (num729 < 150f)
						{
							float num730 = 4f;
							vector52 *= -num730;
							this.velocity.X = (this.velocity.X * 40f + vector52.X) / 41f;
							this.velocity.Y = (this.velocity.Y * 40f + vector52.Y) / 41f;
						}
						else
						{
							this.velocity *= 0.97f;
						}
					}
					else if (this.velocity.Y > -1f)
					{
						this.velocity.Y = this.velocity.Y - 0.1f;
					}
				}
				else
				{
					if (!Collision.CanHitLine(this.center(), 1, 1, Main.player[this.owner].center(), 1, 1))
					{
						this.ai[0] = 1f;
					}
					float num731 = 6f;
					if (this.ai[0] == 1f)
					{
						num731 = 15f;
					}
					if (this.type == 407)
					{
						num731 = 9f;
					}
					Vector2 value14 = this.center();
					Vector2 vector53 = player.center() - value14 + new Vector2(0f, -60f);
					if (this.type == 407)
					{
						vector53 += new Vector2(0f, 40f);
					}
					if (this.type == 375)
					{
						this.ai[1] = 3600f;
						this.netUpdate = true;
						vector53 = player.center() - value14;
						int num732 = 1;
						for (int num733 = 0; num733 < this.whoAmI; num733++)
						{
							if (Main.projectile[num733].active && Main.projectile[num733].owner == this.owner && Main.projectile[num733].type == this.type)
							{
								num732++;
							}
						}
						vector53.X -= (float)(10 * Main.player[this.owner].direction);
						vector53.X -= (float)(num732 * 40 * Main.player[this.owner].direction);
						vector53.Y -= 10f;
					}
					float num734 = vector53.Length();
					if (num734 > 200f && num731 < 9f)
					{
						num731 = 9f;
					}
					if (this.type == 375)
					{
						num731 = (float)((int)((double)num731 * 0.75));
					}
					if (num734 < 100f && this.ai[0] == 1f && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						this.netUpdate = true;
					}
					if (num734 > 2000f)
					{
						this.position.X = Main.player[this.owner].center().X - (float)(this.width / 2);
						this.position.Y = Main.player[this.owner].center().Y - (float)(this.width / 2);
					}
					if (this.type == 375)
					{
						if (num734 > 10f)
						{
							vector53.Normalize();
							if (num734 < 50f)
							{
								num731 /= 2f;
							}
							vector53 *= num731;
							this.velocity = (this.velocity * 20f + vector53) / 21f;
						}
						else
						{
							this.direction = Main.player[this.owner].direction;
							this.velocity *= 0.9f;
						}
					}
					else if (this.type == 407)
					{
						if (Math.Abs(vector53.X) > 40f || Math.Abs(vector53.Y) > 10f)
						{
							vector53.Normalize();
							vector53 *= num731;
							vector53 *= new Vector2(1.25f, 0.65f);
							this.velocity = (this.velocity * 20f + vector53) / 21f;
						}
						else
						{
							if (this.velocity.X == 0f && this.velocity.Y == 0f)
							{
								this.velocity.X = -0.15f;
								this.velocity.Y = -0.05f;
							}
							this.velocity *= 1.01f;
						}
					}
					else if (num734 > 70f)
					{
						vector53.Normalize();
						vector53 *= num731;
						this.velocity = (this.velocity * 20f + vector53) / 21f;
					}
					else
					{
						if (this.velocity.X == 0f && this.velocity.Y == 0f)
						{
							this.velocity.X = -0.15f;
							this.velocity.Y = -0.05f;
						}
						this.velocity *= 1.01f;
					}
				}
				this.rotation = this.velocity.X * 0.05f;
				this.frameCounter++;
				if (this.type == 373)
				{
					if (this.frameCounter > 1)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame > 2)
					{
						this.frame = 0;
					}
				}
				if (this.type == 375)
				{
					if (this.frameCounter >= 16)
					{
						this.frameCounter = 0;
					}
					this.frame = this.frameCounter / 4;
					if (this.ai[1] > 0f && this.ai[1] < 16f)
					{
						this.frame += 4;
					}
					if (Main.rand.Next(6) == 0)
					{
						int num735 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 6, 0f, 0f, 100, default(Color), 2f);
						Main.dust[num735].velocity *= 0.3f;
						Main.dust[num735].noGravity = true;
						Main.dust[num735].noLight = true;
					}
				}
				if (this.type == 407)
				{
					int num736 = 2;
					if (this.frameCounter >= 6 * num736)
					{
						this.frameCounter = 0;
					}
					this.frame = this.frameCounter / num736;
					if (Main.rand.Next(5) == 0)
					{
						int num737 = Dust.NewDust(new Vector2(this.position.X, this.position.Y), this.width, this.height, 217, 0f, 0f, 100, default(Color), 2f);
						Main.dust[num737].velocity *= 0.3f;
						Main.dust[num737].noGravity = true;
						Main.dust[num737].noLight = true;
					}
				}
				if (this.velocity.X > 0f)
				{
					this.spriteDirection = (this.direction = -1);
				}
				else if (this.velocity.X < 0f)
				{
					this.spriteDirection = (this.direction = 1);
				}
				if (this.type == 373)
				{
					if (this.ai[1] > 0f)
					{
						this.ai[1] += (float)Main.rand.Next(1, 4);
					}
					if (this.ai[1] > 90f)
					{
						this.ai[1] = 0f;
						this.netUpdate = true;
					}
				}
				else if (this.type == 375)
				{
					if (this.ai[1] > 0f)
					{
						this.ai[1] += 1f;
						if (Main.rand.Next(3) == 0)
						{
							this.ai[1] += 1f;
						}
					}
					if (this.ai[1] > (float)Main.rand.Next(180, 900))
					{
						this.ai[1] = 0f;
						this.netUpdate = true;
					}
				}
				else if (this.type == 407)
				{
					if (this.ai[1] > 0f)
					{
						this.ai[1] += 1f;
						if (Main.rand.Next(3) != 0)
						{
							this.ai[1] += 1f;
						}
					}
					if (this.ai[1] > 60f)
					{
						this.ai[1] = 0f;
						this.netUpdate = true;
					}
				}
				if (this.ai[0] == 0f)
				{
					float scaleFactor4 = 0f;
					int num738 = 0;
					if (this.type == 373)
					{
						scaleFactor4 = 10f;
						num738 = 374;
					}
					else if (this.type == 375)
					{
						scaleFactor4 = 11f;
						num738 = 376;
					}
					else if (this.type == 407)
					{
						scaleFactor4 = 14f;
						num738 = 408;
					}
					if (flag28)
					{
						if (this.type == 375)
						{
							if ((vector50 - this.center()).X > 0f)
							{
								this.spriteDirection = (this.direction = -1);
							}
							else if ((vector50 - this.center()).X < 0f)
							{
								this.spriteDirection = (this.direction = 1);
							}
						}
						if ((this.type != 407 || !Collision.SolidCollision(this.position, this.width, this.height)) && this.ai[1] == 0f)
						{
							this.ai[1] += 1f;
							if (Main.myPlayer == this.owner)
							{
								Vector2 value15 = vector50 - this.center();
								value15.Normalize();
								value15 *= scaleFactor4;
								int num739 = Projectile.NewProjectile(this.center().X, this.center().Y, value15.X, value15.Y, num738, this.damage, 0f, Main.myPlayer, 0f, 0f);
								Main.projectile[num739].timeLeft = 300;
								Main.projectile[num739].netUpdate = true;
								this.netUpdate = true;
							}
						}
					}
				}
			}
			if (this.aiStyle == 63)
			{
				if (!Main.player[this.owner].active)
				{
					this.active = false;
					return;
				}
				Vector2 value16 = this.position;
				bool flag29 = false;
				float num740 = 500f;
				for (int num741 = 0; num741 < 200; num741++)
				{
					NPC nPC3 = Main.npc[num741];
					if (nPC3.active && !nPC3.dontTakeDamage && !nPC3.friendly && nPC3.lifeMax > 5)
					{
						float num742 = Vector2.Distance(nPC3.center(), this.center());
						if (((Vector2.Distance(this.center(), value16) > num742 && num742 < num740) || !flag29) && Collision.CanHit(this.position, this.width, this.height, nPC3.position, nPC3.width, nPC3.height))
						{
							num740 = num742;
							value16 = nPC3.center();
							flag29 = true;
						}
					}
				}
				if (!flag29)
				{
					this.velocity.X = this.velocity.X * 0.95f;
				}
				else
				{
					float num743 = 5f;
					float num744 = 0.08f;
					if (this.velocity.Y == 0f)
					{
						bool flag30 = false;
						if (this.center().Y - 50f > value16.Y)
						{
							flag30 = true;
						}
						if (flag30)
						{
							this.velocity.Y = -6f;
						}
					}
					else
					{
						num743 = 8f;
						num744 = 0.12f;
					}
					this.velocity.X = this.velocity.X + (float)Math.Sign(value16.X - this.center().X) * num744;
					if (this.velocity.X < -num743)
					{
						this.velocity.X = -num743;
					}
					if (this.velocity.X > num743)
					{
						this.velocity.X = num743;
					}
				}
				float num745 = 0f;
				Collision.StepUp(ref this.position, ref this.velocity, this.width, this.height, ref num745, ref this.gfxOffY, 1, false);
				if (this.velocity.Y != 0f)
				{
					this.frame = 3;
				}
				else
				{
					if (Math.Abs(this.velocity.X) > 0.2f)
					{
						this.frameCounter++;
					}
					if (this.frameCounter >= 9)
					{
						this.frameCounter = 0;
					}
					if (this.frameCounter >= 6)
					{
						this.frame = 2;
					}
					else if (this.frameCounter >= 3)
					{
						this.frame = 1;
					}
					else
					{
						this.frame = 0;
					}
				}
				if (this.velocity.X != 0f)
				{
					this.direction = Math.Sign(this.velocity.X);
				}
				this.spriteDirection = -this.direction;
				this.velocity.Y = this.velocity.Y + 0.2f;
				if (this.velocity.Y > 16f)
				{
					this.velocity.Y = 16f;
				}
			}
			else if (this.aiStyle == 64)
			{
				int num746 = 10;
				int num747 = 15;
				float num748 = 1f;
				int num749 = 150;
				int num750 = 42;
				if (this.type == 386)
				{
					num746 = 16;
					num747 = 16;
					num748 = 1.5f;
				}
				if (this.velocity.X != 0f)
				{
					this.direction = (this.spriteDirection = -Math.Sign(this.velocity.X));
				}
				this.frameCounter++;
				if (this.frameCounter > 2)
				{
					this.frame++;
					this.frameCounter = 0;
				}
				if (this.frame >= 6)
				{
					this.frame = 0;
				}
				if (this.localAI[0] == 0f && Main.myPlayer == this.owner)
				{
					this.localAI[0] = 1f;
					this.position.X = this.position.X + (float)(this.width / 2);
					this.position.Y = this.position.Y + (float)(this.height / 2);
					this.scale = ((float)(num746 + num747) - this.ai[1]) * num748 / (float)(num747 + num746);
					this.width = (int)((float)num749 * this.scale);
					this.height = (int)((float)num750 * this.scale);
					this.position.X = this.position.X - (float)(this.width / 2);
					this.position.Y = this.position.Y - (float)(this.height / 2);
					this.netUpdate = true;
				}
				if (this.ai[1] != -1f)
				{
					this.scale = ((float)(num746 + num747) - this.ai[1]) * num748 / (float)(num747 + num746);
					this.width = (int)((float)num749 * this.scale);
					this.height = (int)((float)num750 * this.scale);
				}
				if (!Collision.SolidCollision(this.position, this.width, this.height))
				{
					this.alpha -= 30;
					if (this.alpha < 60)
					{
						this.alpha = 60;
					}
					if (this.type == 386 && this.alpha < 100)
					{
						this.alpha = 100;
					}
				}
				else
				{
					this.alpha += 30;
					if (this.alpha > 150)
					{
						this.alpha = 150;
					}
				}
				if (this.ai[0] > 0f)
				{
					this.ai[0] -= 1f;
				}
				if (this.ai[0] == 1f && this.ai[1] > 0f && this.owner == Main.myPlayer)
				{
					this.netUpdate = true;
					Vector2 vector54 = this.center();
					vector54.Y -= (float)num750 * this.scale / 2f;
					float num751 = ((float)(num746 + num747) - this.ai[1] + 1f) * num748 / (float)(num747 + num746);
					vector54.Y -= (float)num750 * num751 / 2f;
					vector54.Y += 2f;
					Projectile.NewProjectile(vector54.X, vector54.Y, this.velocity.X, this.velocity.Y, this.type, this.damage, this.knockBack, this.owner, 10f, this.ai[1] - 1f);
					int num752 = 4;
					if (this.type == 386)
					{
						num752 = 2;
					}
					if ((int)this.ai[1] % num752 == 0 && this.ai[1] != 0f)
					{
						int num753 = 372;
						if (this.type == 386)
						{
							num753 = 373;
						}
						int num754 = NPC.NewNPC((int)vector54.X, (int)vector54.Y, num753, 0);
						Main.npc[num754].velocity = this.velocity;
						Main.npc[num754].netUpdate = true;
						if (this.type == 386)
						{
							Main.npc[num754].ai[2] = (float)this.width;
							Main.npc[num754].ai[3] = -1.5f;
						}
					}
				}
				if (this.ai[0] <= 0f)
				{
					float num755 = 0.104719758f;
					float num756 = (float)this.width / 5f;
					if (this.type == 386)
					{
						num756 *= 2f;
					}
					float num757 = (float)(Math.Cos((double)(num755 * -(double)this.ai[0])) - 0.5) * num756;
					this.position.X = this.position.X - num757 * (float)(-(float)this.direction);
					this.ai[0] -= 1f;
					num757 = (float)(Math.Cos((double)(num755 * -(double)this.ai[0])) - 0.5) * num756;
					this.position.X = this.position.X + num757 * (float)(-(float)this.direction);
				}
			}
			else if (this.aiStyle == 65)
			{
				if (this.ai[1] > 0f)
				{
					int num758 = (int)this.ai[1] - 1;
					if (num758 < 255)
					{
						this.localAI[0] += 1f;
						if (this.localAI[0] > 10f)
						{
							int num759 = 6;
							for (int num760 = 0; num760 < num759; num760++)
							{
								Vector2 vector55 = Vector2.Normalize(this.velocity) * new Vector2((float)this.width / 2f, (float)this.height) * 0.75f;
								vector55 = vector55.Rotate((double)(num760 - (num759 / 2 - 1)) * 3.1415926535897931 / (double)((float)num759), default(Vector2)) + this.center();
								Vector2 value17 = ((float)(Main.rand.NextDouble() * 3.1415927410125732) - 1.57079637f).ToRotationVector2() * (float)Main.rand.Next(3, 8);
								int num761 = Dust.NewDust(vector55 + value17, 0, 0, 172, value17.X * 2f, value17.Y * 2f, 100, default(Color), 1.4f);
								Main.dust[num761].noGravity = true;
								Main.dust[num761].noLight = true;
								Main.dust[num761].velocity /= 4f;
								Main.dust[num761].velocity -= this.velocity;
							}
							this.alpha -= 5;
							if (this.alpha < 100)
							{
								this.alpha = 100;
							}
							this.rotation += this.velocity.X * 0.1f;
							this.frame = (int)(this.localAI[0] / 3f) % 3;
						}
						Vector2 value18 = Main.player[num758].center() - this.center();
						float num762 = 4f;
						num762 += this.localAI[0] / 20f;
						this.velocity = Vector2.Normalize(value18) * num762;
						if (value18.Length() < 50f)
						{
							this.Kill();
						}
					}
				}
				else
				{
					float num763 = 0.209439516f;
					float num764 = 4f;
					float num765 = (float)(Math.Cos((double)(num763 * this.ai[0])) - 0.5) * num764;
					this.velocity.Y = this.velocity.Y - num765;
					this.ai[0] += 1f;
					num765 = (float)(Math.Cos((double)(num763 * this.ai[0])) - 0.5) * num764;
					this.velocity.Y = this.velocity.Y + num765;
					this.localAI[0] += 1f;
					if (this.localAI[0] > 10f)
					{
						this.alpha -= 5;
						if (this.alpha < 100)
						{
							this.alpha = 100;
						}
						this.rotation += this.velocity.X * 0.1f;
						this.frame = (int)(this.localAI[0] / 3f) % 3;
					}
				}
				if (this.wet)
				{
					this.position.Y = this.position.Y - 16f;
					this.Kill();
				}
			}
			else if (this.aiStyle == 66)
			{
				if (this.type == 387 || this.type == 388)
				{
					if (Main.player[this.owner].dead)
					{
						Main.player[this.owner].twinsMinion = false;
					}
					if (Main.player[this.owner].twinsMinion)
					{
						this.timeLeft = 2;
					}
				}
				float num766 = 0.05f;
				for (int num767 = 0; num767 < 1000; num767++)
				{
					if (num767 != this.whoAmI && Main.projectile[num767].active && Main.projectile[num767].owner == this.owner && (Main.projectile[num767].type == 387 || Main.projectile[num767].type == 388) && Math.Abs(this.position.X - Main.projectile[num767].position.X) + Math.Abs(this.position.Y - Main.projectile[num767].position.Y) < (float)this.width)
					{
						if (this.position.X < Main.projectile[num767].position.X)
						{
							this.velocity.X = this.velocity.X - num766;
						}
						else
						{
							this.velocity.X = this.velocity.X + num766;
						}
						if (this.position.Y < Main.projectile[num767].position.Y)
						{
							this.velocity.Y = this.velocity.Y - num766;
						}
						else
						{
							this.velocity.Y = this.velocity.Y + num766;
						}
					}
				}
				if (this.ai[0] == 2f && this.type == 388)
				{
					this.ai[1] += 1f;
					this.maxUpdates = 1;
					this.rotation = this.velocity.ToRotation() + 3.14159274f;
					this.frameCounter++;
					if (this.frameCounter > 1)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame > 2)
					{
						this.frame = 0;
					}
					if (this.ai[1] <= 40f)
					{
						return;
					}
					this.ai[1] = 1f;
					this.ai[0] = 0f;
					this.maxUpdates = 0;
					this.numUpdates = 0;
					this.netUpdate = true;
				}
				Vector2 vector56 = this.position;
				float num768 = 400f;
				bool flag31 = false;
				if (this.ai[0] != 1f)
				{
					this.tileCollide = true;
				}
				for (int num769 = 0; num769 < 200; num769++)
				{
					NPC nPC4 = Main.npc[num769];
					if (nPC4.active && !nPC4.dontTakeDamage && !nPC4.friendly && nPC4.lifeMax > 5)
					{
						float num770 = Vector2.Distance(nPC4.center(), this.center());
						if (((Vector2.Distance(this.center(), vector56) > num770 && num770 < num768) || !flag31) && Collision.CanHitLine(this.position, this.width, this.height, nPC4.position, nPC4.width, nPC4.height))
						{
							num768 = num770;
							vector56 = nPC4.center();
							flag31 = true;
						}
					}
				}
				int num771 = 500;
				if (flag31)
				{
					num771 = 1000;
				}
				Player player2 = Main.player[this.owner];
				if (Vector2.Distance(player2.center(), this.center()) > (float)num771)
				{
					this.ai[0] = 1f;
					this.tileCollide = false;
					this.netUpdate = true;
				}
				if (flag31 && this.ai[0] == 0f)
				{
					Vector2 vector57 = vector56 - this.center();
					float num772 = vector57.Length();
					vector57.Normalize();
					if (num772 > 200f)
					{
						float scaleFactor5 = 6f;
						if (this.type == 388)
						{
							scaleFactor5 = 8f;
						}
						vector57 *= scaleFactor5;
						this.velocity = (this.velocity * 40f + vector57) / 41f;
					}
					else
					{
						float num773 = 4f;
						vector57 *= -num773;
						this.velocity = (this.velocity * 40f + vector57) / 41f;
					}
				}
				else
				{
					float num774 = 6f;
					if (this.ai[0] == 1f)
					{
						num774 = 15f;
					}
					Vector2 value19 = this.center();
					Vector2 vector58 = player2.center() - value19 + new Vector2(0f, -60f);
					float num775 = vector58.Length();
					if (num775 > 200f && num774 < 8f)
					{
						num774 = 8f;
					}
					if (num775 < 150f && this.ai[0] == 1f && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						this.netUpdate = true;
					}
					if (num775 > 2000f)
					{
						this.position.X = Main.player[this.owner].center().X - (float)(this.width / 2);
						this.position.Y = Main.player[this.owner].center().Y - (float)(this.height / 2);
						this.netUpdate = true;
					}
					if (num775 > 70f)
					{
						vector58.Normalize();
						vector58 *= num774;
						this.velocity = (this.velocity * 40f + vector58) / 41f;
					}
					else if (this.velocity.X == 0f && this.velocity.Y == 0f)
					{
						this.velocity.X = -0.15f;
						this.velocity.Y = -0.05f;
					}
				}
				if (this.type == 388)
				{
					this.rotation = this.velocity.ToRotation() + 3.14159274f;
				}
				if (this.type == 387)
				{
					if (flag31)
					{
						this.rotation = (vector56 - this.center()).ToRotation() + 3.14159274f;
					}
					else
					{
						this.rotation = this.velocity.ToRotation() + 3.14159274f;
					}
				}
				this.frameCounter++;
				if (this.frameCounter > 3)
				{
					this.frame++;
					this.frameCounter = 0;
				}
				if (this.frame > 2)
				{
					this.frame = 0;
				}
				if (this.ai[1] > 0f)
				{
					this.ai[1] += (float)Main.rand.Next(1, 4);
				}
				if (this.ai[1] > 90f && this.type == 387)
				{
					this.ai[1] = 0f;
					this.netUpdate = true;
				}
				if (this.ai[1] > 40f && this.type == 388)
				{
					this.ai[1] = 0f;
					this.netUpdate = true;
				}
				if (this.ai[0] == 0f)
				{
					if (this.type == 387)
					{
						float scaleFactor6 = 8f;
						int num776 = 389;
						if (flag31 && this.ai[1] == 0f)
						{
							this.ai[1] += 1f;
							if (Main.myPlayer == this.owner && Collision.CanHitLine(this.position, this.width, this.height, vector56, 0, 0))
							{
								Vector2 value20 = vector56 - this.center();
								value20.Normalize();
								value20 *= scaleFactor6;
								int num777 = Projectile.NewProjectile(this.center().X, this.center().Y, value20.X, value20.Y, num776, (int)((float)this.damage * 0.8f), 0f, Main.myPlayer, 0f, 0f);
								Main.projectile[num777].timeLeft = 300;
								this.netUpdate = true;
							}
						}
					}
					if (this.type == 388 && this.ai[1] == 0f && flag31 && num768 < 500f)
					{
						this.ai[1] += 1f;
						if (Main.myPlayer == this.owner)
						{
							this.ai[0] = 2f;
							Vector2 value21 = vector56 - this.center();
							value21.Normalize();
							this.velocity = value21 * 8f;
							this.netUpdate = true;
						}
					}
				}
			}
			else if (this.aiStyle == 67)
			{
				Player player3 = Main.player[this.owner];
				if (!player3.active)
				{
					this.active = false;
					return;
				}
				if (player3.dead)
				{
					player3.pirateMinion = false;
				}
				if (player3.pirateMinion)
				{
					this.timeLeft = 2;
				}
				Vector2 vector59 = player3.center();
				vector59.X -= (float)((15 + player3.width / 2) * player3.direction);
				vector59.X -= (float)(this.minionPos * 40 * player3.direction);
				if (this.ai[0] == 0f)
				{
					float num778 = 500f;
					if (Main.player[this.owner].rocketDelay2 > 0)
					{
						this.ai[0] = 1f;
						this.netUpdate = true;
					}
					Vector2 vector60 = player3.center() - this.center();
					if (vector60.Length() > 2000f)
					{
						this.position = player3.center() - new Vector2((float)this.width, (float)this.height) / 2f;
					}
					else if (vector60.Length() > num778 || Math.Abs(vector60.Y) > 300f)
					{
						this.ai[0] = 1f;
						this.netUpdate = true;
						if (this.velocity.Y > 0f && vector60.Y < 0f)
						{
							this.velocity.Y = 0f;
						}
						if (this.velocity.Y < 0f && vector60.Y > 0f)
						{
							this.velocity.Y = 0f;
						}
					}
				}
				int num779 = -1;
				float num780 = 450f;
				int num781 = 15;
				if (this.ai[0] == 0f)
				{
					for (int num782 = 0; num782 < 200; num782++)
					{
						NPC nPC5 = Main.npc[num782];
						if (nPC5.active && !nPC5.dontTakeDamage && !nPC5.friendly && nPC5.lifeMax > 5)
						{
							float num783 = (nPC5.center() - this.center()).Length();
							if (num783 < num780)
							{
								num779 = num782;
								num780 = num783;
							}
						}
					}
				}
				if (this.ai[0] == 1f)
				{
					this.tileCollide = false;
					float num784 = 0.2f;
					float num785 = 10f;
					int num786 = 200;
					if (num785 < Math.Abs(player3.velocity.X) + Math.Abs(player3.velocity.Y))
					{
						num785 = Math.Abs(player3.velocity.X) + Math.Abs(player3.velocity.Y);
					}
					Vector2 value22 = player3.center() - this.center();
					float num787 = value22.Length();
					if (num787 > 2000f)
					{
						this.position = player3.center() - new Vector2((float)this.width, (float)this.height) / 2f;
					}
					if (num787 < (float)num786 && player3.velocity.Y == 0f && this.position.Y + (float)this.height <= player3.position.Y + (float)player3.height && !Collision.SolidCollision(this.position, this.width, this.height))
					{
						this.ai[0] = 0f;
						this.netUpdate = true;
						if (this.velocity.Y < -6f)
						{
							this.velocity.Y = -6f;
						}
					}
					if (num787 >= 60f)
					{
						value22.Normalize();
						value22 *= num785;
						if (this.velocity.X < value22.X)
						{
							this.velocity.X = this.velocity.X + num784;
							if (this.velocity.X < 0f)
							{
								this.velocity.X = this.velocity.X + num784 * 1.5f;
							}
						}
						if (this.velocity.X > value22.X)
						{
							this.velocity.X = this.velocity.X - num784;
							if (this.velocity.X > 0f)
							{
								this.velocity.X = this.velocity.X - num784 * 1.5f;
							}
						}
						if (this.velocity.Y < value22.Y)
						{
							this.velocity.Y = this.velocity.Y + num784;
							if (this.velocity.Y < 0f)
							{
								this.velocity.Y = this.velocity.Y + num784 * 1.5f;
							}
						}
						if (this.velocity.Y > value22.Y)
						{
							this.velocity.Y = this.velocity.Y - num784;
							if (this.velocity.Y > 0f)
							{
								this.velocity.Y = this.velocity.Y - num784 * 1.5f;
							}
						}
					}
					if (this.velocity.X != 0f)
					{
						this.spriteDirection = Math.Sign(this.velocity.X);
					}
					this.frameCounter++;
					if (this.frameCounter > 3)
					{
						this.frame++;
						this.frameCounter = 0;
					}
					if (this.frame < 10 | this.frame > 13)
					{
						this.frame = 10;
					}
					this.rotation = this.velocity.X * 0.1f;
				}
				if (this.ai[0] == 2f)
				{
					this.friendly = true;
					this.spriteDirection = this.direction;
					this.rotation = 0f;
					this.frame = 4 + (int)((float)num781 - this.ai[1]) / (num781 / 3);
					if (this.velocity.Y != 0f)
					{
						this.frame += 3;
					}
					this.velocity.Y = this.velocity.Y + 0.4f;
					if (this.velocity.Y > 10f)
					{
						this.velocity.Y = 10f;
					}
					this.ai[1] -= 1f;
					if (this.ai[1] <= 0f)
					{
						this.ai[1] = 0f;
						this.ai[0] = 0f;
						this.friendly = false;
						this.netUpdate = true;
						return;
					}
				}
				if (num779 >= 0)
				{
					float num788 = 400f;
					float num789 = 20f;
					if ((double)this.position.Y > Main.worldSurface * 16.0)
					{
						num788 = 200f;
					}
					NPC nPC6 = Main.npc[num779];
					Vector2 vector61 = nPC6.center();
					float num790 = (vector61 - this.center()).Length();
					Collision.CanHit(this.position, this.width, this.height, nPC6.position, nPC6.width, nPC6.height);
					if (num790 < num788)
					{
						vector59 = vector61;
						if (vector61.Y < this.center().Y - 30f && this.velocity.Y == 0f)
						{
							float num791 = Math.Abs(vector61.Y - this.center().Y);
							if (num791 < 120f)
							{
								this.velocity.Y = -10f;
							}
							else if (num791 < 210f)
							{
								this.velocity.Y = -13f;
							}
							else if (num791 < 270f)
							{
								this.velocity.Y = -15f;
							}
							else if (num791 < 310f)
							{
								this.velocity.Y = -17f;
							}
							else if (num791 < 380f)
							{
								this.velocity.Y = -18f;
							}
						}
					}
					if (num790 < num789)
					{
						this.ai[0] = 2f;
						this.ai[1] = (float)num781;
						this.netUpdate = true;
					}
				}
				if (this.ai[0] == 0f)
				{
					this.tileCollide = true;
					float num792 = 0.5f;
					float num793 = 4f;
					float num794 = 4f;
					float num795 = 0.1f;
					if (num794 < Math.Abs(player3.velocity.X) + Math.Abs(player3.velocity.Y))
					{
						num794 = Math.Abs(player3.velocity.X) + Math.Abs(player3.velocity.Y);
						num792 = 0.7f;
					}
					int num796 = 0;
					bool flag32 = false;
					float num797 = vector59.X - this.center().X;
					if (Math.Abs(num797) > 5f)
					{
						if (num797 < 0f)
						{
							num796 = -1;
							if (this.velocity.X > -num793)
							{
								this.velocity.X = this.velocity.X - num792;
							}
							else
							{
								this.velocity.X = this.velocity.X - num795;
							}
						}
						else
						{
							num796 = 1;
							if (this.velocity.X < num793)
							{
								this.velocity.X = this.velocity.X + num792;
							}
							else
							{
								this.velocity.X = this.velocity.X + num795;
							}
						}
					}
					else
					{
						this.velocity.X = this.velocity.X * 0.9f;
						if (Math.Abs(this.velocity.X) < num792 * 2f)
						{
							this.velocity.X = 0f;
						}
					}
					if (num796 != 0)
					{
						int num798 = (int)(this.position.X + (float)(this.width / 2)) / 16;
						int num799 = (int)this.position.Y / 16;
						num798 += num796;
						num798 += (int)this.velocity.X;
						for (int num800 = num799; num800 < num799 + this.height / 16 + 1; num800++)
						{
							if (WorldGen.SolidTile(num798, num800))
							{
								flag32 = true;
							}
						}
					}
					Collision.StepUp(ref this.position, ref this.velocity, this.width, this.height, ref this.stepSpeed, ref this.gfxOffY, 1, false);
					if (this.velocity.Y == 0f && flag32)
					{
						int num801 = 0;
						while (num801 < 3)
						{
							int num802 = (int)(this.position.X + (float)(this.width / 2)) / 16;
							if (num801 == 0)
							{
								num802 = (int)this.position.X / 16;
							}
							if (num801 == 2)
							{
								num802 = (int)(this.position.X + (float)this.width) / 16;
							}
							int num803 = (int)(this.position.Y + (float)this.height) / 16 + 1;

							if (WorldGen.SolidTile(num802, num803) || Main.tile[num802, num803].halfBrick())
							{
							}
							else
							{
								if (Main.tile[num802, num803].slope() <= 0)
								{
									num801++;
									continue;
								}
							}
							try
							{
								IL_24434:
								num802 = (int)(this.position.X + (float)(this.width / 2)) / 16;
								num803 = (int)(this.position.Y + (float)(this.height / 2)) / 16;
								num802 += num796;
								num802 += (int)this.velocity.X;
								if (!WorldGen.SolidTile(num802, num803 - 1) && !WorldGen.SolidTile(num802, num803 - 2))
								{
									this.velocity.Y = -5.1f;
								}
								else if (!WorldGen.SolidTile(num802, num803 - 2))
								{
									this.velocity.Y = -7.1f;
								}
								else if (WorldGen.SolidTile(num802, num803 - 5))
								{
									this.velocity.Y = -11.1f;
								}
								else if (WorldGen.SolidTile(num802, num803 - 4))
								{
									this.velocity.Y = -10.1f;
								}
								else
								{
									this.velocity.Y = -9.1f;
								}
							}
							catch
							{
								this.velocity.Y = -9.1f;
							}
							num801++;
							continue;
						}
					}
					if (this.velocity.X > num794)
					{
						this.velocity.X = num794;
					}
					if (this.velocity.X < -num794)
					{
						this.velocity.X = -num794;
					}
					if (this.velocity.X < 0f)
					{
						this.direction = -1;
					}
					if (this.velocity.X > 0f)
					{
						this.direction = 1;
					}
					if (this.velocity.X > num792 && num796 == 1)
					{
						this.direction = 1;
					}
					if (this.velocity.X < -num792 && num796 == -1)
					{
						this.direction = -1;
					}
					this.spriteDirection = this.direction;
					this.rotation = 0f;
					if (this.velocity.Y == 0f)
					{
						if (this.velocity.X == 0f)
						{
							this.frame = 0;
							this.frameCounter = 0;
						}
						else if (Math.Abs(this.velocity.X) >= 0.5f)
						{
							this.frameCounter += (int)Math.Abs(this.velocity.X);
							this.frameCounter++;
							if (this.frameCounter > 10)
							{
								this.frame++;
								this.frameCounter = 0;
							}
							if (this.frame >= 4)
							{
								this.frame = 0;
							}
						}
						else
						{
							this.frame = 0;
							this.frameCounter = 0;
						}
					}
					else if (this.velocity.Y != 0f)
					{
						this.frameCounter = 0;
						this.frame = 14;
					}
					this.velocity.Y = this.velocity.Y + 0.4f;
					if (this.velocity.Y > 10f)
					{
						this.velocity.Y = 10f;
					}
				}
				this.localAI[0] += 1f;
				if (this.velocity.X == 0f)
				{
					this.localAI[0] += 1f;
				}
				if (this.localAI[0] >= (float)Main.rand.Next(900, 1200))
				{
					this.localAI[0] = 0f;
					for (int num804 = 0; num804 < 6; num804++)
					{
						int num805 = Dust.NewDust(this.center() + Vector2.UnitX * (float)(-(float)this.direction) * 8f - Vector2.One * 5f + Vector2.UnitY * 8f, 3, 6, 216, (float)(-(float)this.direction), 1f, 0, default(Color), 1f);
						Main.dust[num805].velocity /= 2f;
						Main.dust[num805].scale = 0.8f;
					}
					int num806 = Gore.NewGore(this.center() + Vector2.UnitX * (float)(-(float)this.direction) * 8f, Vector2.Zero, Main.rand.Next(580, 583), 1f);
					Main.gore[num806].velocity /= 2f;
					Main.gore[num806].velocity.Y = Math.Abs(Main.gore[num806].velocity.Y);
					Main.gore[num806].velocity.X = -Math.Abs(Main.gore[num806].velocity.X) * (float)this.direction;
				}
			}
			else if (this.aiStyle == 68)
			{
				this.rotation += 0.25f * (float)this.direction;
				this.ai[0] += 1f;
				if (this.ai[0] >= 3f)
				{
					this.alpha -= 40;
					if (this.alpha < 0)
					{
						this.alpha = 0;
					}
				}
				if (this.ai[0] >= 15f)
				{
					this.velocity.Y = this.velocity.Y + 0.2f;
					if (this.velocity.Y > 16f)
					{
						this.velocity.Y = 16f;
					}
					this.velocity.X = this.velocity.X * 0.99f;
				}
				if (this.alpha == 0)
				{
					Vector2 vector62 = new Vector2(4f, -8f);
					float num807 = this.rotation;
					if (this.direction == -1)
					{
						vector62.X = -4f;
					}
					vector62 = vector62.Rotate((double)num807, default(Vector2));
					for (int num808 = 0; num808 < 1; num808++)
					{
						int num809 = Dust.NewDust(this.center() + vector62 - Vector2.One * 5f, 4, 4, 6, 0f, 0f, 0, default(Color), 1f);
						Main.dust[num809].scale = 1.5f;
						Main.dust[num809].noGravity = true;
						Main.dust[num809].velocity = Main.dust[num809].velocity * 0.25f + Vector2.Normalize(vector62) * 1f;
						Main.dust[num809].velocity = Main.dust[num809].velocity.Rotate((double)(-1.57079637f * (float)this.direction), default(Vector2));
					}
				}
				this.spriteDirection = this.direction;
				if (this.owner == Main.myPlayer && this.timeLeft <= 3)
				{
					this.tileCollide = false;
					this.alpha = 255;
					this.position.X = this.position.X + (float)(this.width / 2);
					this.position.Y = this.position.Y + (float)(this.height / 2);
					this.width = 80;
					this.height = 80;
					this.position.X = this.position.X - (float)(this.width / 2);
					this.position.Y = this.position.Y - (float)(this.height / 2);
					this.knockBack = 8f;
				}
				if (this.wet && this.timeLeft > 3)
				{
					this.timeLeft = 3;
				}
			}
			else if (this.aiStyle == 69)
			{
				Vector2 vector63 = Main.player[this.owner].center() - this.center();
				this.rotation = vector63.ToRotation() - 1.57f;
				if (Main.player[this.owner].dead)
				{
					this.Kill();
					return;
				}
				Main.player[this.owner].itemAnimation = 10;
				Main.player[this.owner].itemTime = 10;
				if (vector63.X < 0f)
				{
					Main.player[this.owner].ChangeDir(1);
					this.direction = 1;
				}
				else
				{
					Main.player[this.owner].ChangeDir(-1);
					this.direction = -1;
				}
				Main.player[this.owner].itemRotation = (vector63 * -1f * (float)this.direction).ToRotation();
				this.spriteDirection = ((vector63.X > 0f) ? -1 : 1);
				if (this.ai[0] == 0f && vector63.Length() > 400f)
				{
					this.ai[0] = 1f;
				}
				if (this.ai[0] == 1f || this.ai[0] == 2f)
				{
					float num810 = vector63.Length();
					if (num810 > 1500f)
					{
						this.Kill();
						return;
					}
					if (num810 > 600f)
					{
						this.ai[0] = 2f;
					}
					this.tileCollide = false;
					float num811 = 20f;
					if (this.ai[0] == 2f)
					{
						num811 = 40f;
					}
					this.velocity = Vector2.Normalize(vector63) * num811;
					if (vector63.Length() < num811)
					{
						this.Kill();
						return;
					}
				}
				this.ai[1] += 1f;
				if (this.ai[1] > 5f)
				{
					this.alpha = 0;
				}
				if ((int)this.ai[1] % 3 == 0 && this.owner == Main.myPlayer)
				{
					Vector2 vector64 = vector63 * -1f;
					vector64.Normalize();
					vector64 *= (float)Main.rand.Next(45, 65) * 0.1f;
					vector64 = vector64.Rotate((Main.rand.NextDouble() - 0.5) * 1.5707963705062866, default(Vector2));
					Projectile.NewProjectile(this.center().X, this.center().Y, vector64.X, vector64.Y, 405, this.damage, this.knockBack, this.owner, -10f, 0f);
				}
			}
			else if (this.aiStyle == 70)
			{
				if (this.ai[0] == 0f)
				{
					float num812 = 500f;
					int num813 = -1;
					for (int num814 = 0; num814 < 200; num814++)
					{
						NPC nPC7 = Main.npc[num814];
						if (nPC7.active && !nPC7.dontTakeDamage && !nPC7.friendly && nPC7.lifeMax > 5 && Collision.CanHit(this.position, this.width, this.height, nPC7.position, nPC7.width, nPC7.height))
						{
							float num815 = (nPC7.center() - this.center()).Length();
							if (num815 < num812)
							{
								num813 = num814;
								num812 = num815;
							}
						}
					}
					this.ai[0] = (float)(num813 + 1);
					if (this.ai[0] == 0f)
					{
						this.ai[0] = -15f;
					}
					if (this.ai[0] > 0f)
					{
						float scaleFactor7 = (float)Main.rand.Next(35, 75) / 10f;
						this.velocity = Vector2.Normalize(Main.npc[(int)this.ai[0] - 1].center() - this.center() + new Vector2((float)Main.rand.Next(-100, 101), (float)Main.rand.Next(-100, 101))) * scaleFactor7;
						this.netUpdate = true;
					}
				}
				else if (this.ai[0] > 0f)
				{
					Vector2 value23 = Vector2.Normalize(Main.npc[(int)this.ai[0] - 1].center() - this.center());
					this.velocity = (this.velocity * 40f + value23 * 12f) / 41f;
				}
				else
				{
					this.ai[0] += 1f;
					this.alpha -= 25;
					if (this.alpha < 50)
					{
						this.alpha = 50;
					}
					this.velocity *= 0.95f;
				}
				if (this.ai[1] == 0f)
				{
					this.ai[1] = (float)Main.rand.Next(80, 121) / 100f;
					this.netUpdate = true;
				}
				this.scale = this.ai[1];
			}
			else if (this.aiStyle == 71)
			{
				this.localAI[1] += 1f;
				if (this.localAI[1] > 10f && Main.rand.Next(3) == 0)
				{
					int num816 = 6;
					for (int num817 = 0; num817 < num816; num817++)
					{
						Vector2 vector65 = Vector2.Normalize(this.velocity) * new Vector2((float)this.width, (float)this.height) / 2f;
						vector65 = vector65.Rotate((double)(num817 - (num816 / 2 - 1)) * 3.1415926535897931 / (double)((float)num816), default(Vector2)) + this.center();
						Vector2 value24 = ((float)(Main.rand.NextDouble() * 3.1415927410125732) - 1.57079637f).ToRotationVector2() * (float)Main.rand.Next(3, 8);
						int num818 = Dust.NewDust(vector65 + value24, 0, 0, 217, value24.X * 2f, value24.Y * 2f, 100, default(Color), 1.4f);
						Main.dust[num818].noGravity = true;
						Main.dust[num818].noLight = true;
						Main.dust[num818].velocity /= 4f;
						Main.dust[num818].velocity -= this.velocity;
					}
					this.alpha -= 5;
					if (this.alpha < 50)
					{
						this.alpha = 50;
					}
					this.rotation += this.velocity.X * 0.1f;
					this.frame = (int)(this.localAI[1] / 3f) % 3;
					Lighting.addLight((int)this.center().X / 16, (int)this.center().Y / 16, 0.1f, 0.4f, 0.6f);
				}
				int num819 = -1;
				Vector2 vector66 = this.center();
				float num820 = 500f;
				if (this.localAI[0] > 0f)
				{
					this.localAI[0] -= 1f;
				}
				if (this.ai[0] == 0f && this.localAI[0] == 0f)
				{
					for (int num821 = 0; num821 < 200; num821++)
					{
						NPC nPC8 = Main.npc[num821];
						if (nPC8.active && !nPC8.dontTakeDamage && !nPC8.friendly && nPC8.lifeMax > 5 && (this.ai[0] == 0f || this.ai[0] == (float)(num821 + 1)))
						{
							Vector2 vector67 = nPC8.center();
							float num822 = Vector2.Distance(vector67, vector66);
							if (num822 < num820 && Collision.CanHit(this.position, this.width, this.height, nPC8.position, nPC8.width, nPC8.height))
							{
								num820 = num822;
								vector66 = vector67;
								num819 = num821;
							}
						}
					}
					if (num819 >= 0)
					{
						this.ai[0] = (float)(num819 + 1);
						this.netUpdate = true;
					}
				}
				if (this.localAI[0] == 0f && this.ai[0] == 0f)
				{
					this.localAI[0] = 30f;
				}
				bool flag33 = false;
				if (this.ai[0] != 0f)
				{
					int num823 = (int)(this.ai[0] - 1f);
					if (Main.npc[num823].active && !Main.npc[num823].dontTakeDamage && Main.npc[num823].immune[this.owner] == 0)
					{
						float num824 = Main.npc[num823].position.X + (float)(Main.npc[num823].width / 2);
						float num825 = Main.npc[num823].position.Y + (float)(Main.npc[num823].height / 2);
						float num826 = Math.Abs(this.position.X + (float)(this.width / 2) - num824) + Math.Abs(this.position.Y + (float)(this.height / 2) - num825);
						if (num826 < 1000f)
						{
							flag33 = true;
							vector66 = Main.npc[num823].center();
						}
					}
					else
					{
						this.ai[0] = 0f;
						flag33 = false;
						this.netUpdate = true;
					}
				}
				if (flag33)
				{
					Vector2 v = vector66 - this.center();
					float num827 = this.velocity.ToRotation();
					float num828 = v.ToRotation();
					double num829 = (double)(num828 - num827);
					if (num829 > 3.1415926535897931)
					{
						num829 -= 6.2831853071795862;
					}
					if (num829 < -3.1415926535897931)
					{
						num829 += 6.2831853071795862;
					}
					this.velocity = this.velocity.Rotate(num829 * 0.10000000149011612, default(Vector2));
				}
				float num830 = this.velocity.Length();
				this.velocity.Normalize();
				this.velocity *= num830 + 0.0025f;
			}
			else if (this.aiStyle == 72)
			{
				this.localAI[0] += 1f;
				if (this.localAI[0] > 5f)
				{
					this.alpha -= 25;
					if (this.alpha < 50)
					{
						this.alpha = 50;
					}
				}
				this.velocity *= 0.96f;
				if (this.ai[1] == 0f)
				{
					this.ai[1] = (float)Main.rand.Next(60, 121) / 100f;
					this.netUpdate = true;
				}
				this.scale = this.ai[1];
				this.position = this.center();
				int num831 = 14;
				int num832 = 14;
				this.width = (int)((float)num831 * this.ai[1]);
				this.height = (int)((float)num832 * this.ai[1]);
				this.position -= new Vector2((float)(this.width / 2), (float)(this.height / 2));
			}
			if (this.aiStyle == 73)
			{
				int num833 = (int)this.ai[0];
				int num834 = (int)this.ai[1];
				Tile tile = Main.tile[num833, num834];
				if (tile == null || !tile.active() || tile.type != 338)
				{
					this.Kill();
					return;
				}
				float num835 = 2f;
				float num836 = (float)this.timeLeft / 60f;
				if (num836 < 1f)
				{
					num835 *= num836;
				}
				if (this.type == 419)
				{
					for (int num837 = 0; num837 < 2; num837++)
					{
						Vector2 vector68 = new Vector2(0f, -num835);
						vector68 *= 0.85f + (float)Main.rand.NextDouble() * 0.2f;
						vector68 = vector68.Rotate((Main.rand.NextDouble() - 0.5) * 1.5707963705062866, default(Vector2));
						int num838 = Dust.NewDust(this.position, this.width, this.height, 222, 0f, 0f, 100, default(Color), 1f);
						Dust dust = Main.dust[num838];
						dust.scale = 1f + (float)Main.rand.NextDouble() * 0.3f;
						dust.velocity *= 0.5f;
						if (dust.velocity.Y > 0f)
						{
							Dust expr_25C1E_cp_0 = dust;
							expr_25C1E_cp_0.velocity.Y = expr_25C1E_cp_0.velocity.Y * -1f;
						}
						dust.position -= new Vector2((float)(2 + Main.rand.Next(-2, 3)), 0f);
						dust.velocity += vector68;
						dust.scale = 0.6f;
						dust.fadeIn = dust.scale + 0.2f;
						Dust expr_25CA4_cp_0 = dust;
						expr_25CA4_cp_0.velocity.Y = expr_25CA4_cp_0.velocity.Y * 2f;
					}
				}
				if (this.type == 420)
				{
					for (int num839 = 0; num839 < 2; num839++)
					{
						Vector2 vector69 = new Vector2(0f, -num835);
						vector69 *= 0.85f + (float)Main.rand.NextDouble() * 0.2f;
						vector69 = vector69.Rotate((Main.rand.NextDouble() - 0.5) * 1.5707963705062866, default(Vector2));
						int num840 = 219;
						if (Main.rand.Next(5) == 0)
						{
							num840 = 222;
						}
						int num841 = Dust.NewDust(this.position, this.width, this.height, num840, 0f, 0f, 100, default(Color), 1f);
						Dust dust2 = Main.dust[num841];
						dust2.scale = 1f + (float)Main.rand.NextDouble() * 0.3f;
						dust2.velocity *= 0.5f;
						if (dust2.velocity.Y > 0f)
						{
							Dust expr_25E15_cp_0 = dust2;
							expr_25E15_cp_0.velocity.Y = expr_25E15_cp_0.velocity.Y * -1f;
						}
						dust2.position -= new Vector2((float)(2 + Main.rand.Next(-2, 3)), 0f);
						dust2.velocity += vector69;
						Dust expr_25E75_cp_0 = dust2;
						expr_25E75_cp_0.velocity.X = expr_25E75_cp_0.velocity.X * 0.5f;
						dust2.scale = 0.6f;
						dust2.fadeIn = dust2.scale + 0.2f;
						Dust expr_25EB5_cp_0 = dust2;
						expr_25EB5_cp_0.velocity.Y = expr_25EB5_cp_0.velocity.Y * 2f;
					}
				}
				if (this.type == 421)
				{
					for (int num842 = 0; num842 < 2; num842++)
					{
						Vector2 vector70 = new Vector2(0f, -num835);
						vector70 *= 0.85f + (float)Main.rand.NextDouble() * 0.2f;
						vector70 = vector70.Rotate((Main.rand.NextDouble() - 0.5) * 0.78539818525314331, default(Vector2));
						int num843 = Dust.NewDust(this.position, this.width, this.height, 221, 0f, 0f, 100, default(Color), 1f);
						Dust dust3 = Main.dust[num843];
						dust3.scale = 1f + (float)Main.rand.NextDouble() * 0.3f;
						dust3.velocity *= 0.1f;
						if (dust3.velocity.Y > 0f)
						{
							Dust expr_26008_cp_0 = dust3;
							expr_26008_cp_0.velocity.Y = expr_26008_cp_0.velocity.Y * -1f;
						}
						dust3.position -= new Vector2((float)(2 + Main.rand.Next(-2, 3)), 0f);
						dust3.velocity += vector70;
						dust3.scale = 0.6f;
						dust3.fadeIn = dust3.scale + 0.2f;
						Dust expr_2608E_cp_0 = dust3;
						expr_2608E_cp_0.velocity.Y = expr_2608E_cp_0.velocity.Y * 2.5f;
					}
					if (this.timeLeft % 10 == 0)
					{
						float num844 = 0.85f + (float)Main.rand.NextDouble() * 0.2f;
						for (int num845 = 0; num845 < 9; num845++)
						{
							Vector2 value25 = new Vector2((float)(num845 - 4) / 5f, -num835 * num844);
							int num846 = Dust.NewDust(this.position, this.width, this.height, 222, 0f, 0f, 100, default(Color), 1f);
							Dust dust4 = Main.dust[num846];
							dust4.scale = 0.7f + (float)Main.rand.NextDouble() * 0.3f;
							dust4.velocity *= 0f;
							if (dust4.velocity.Y > 0f)
							{
								Dust expr_261AA_cp_0 = dust4;
								expr_261AA_cp_0.velocity.Y = expr_261AA_cp_0.velocity.Y * -1f;
							}
							dust4.position -= new Vector2((float)(2 + Main.rand.Next(-2, 3)), 0f);
							dust4.velocity += value25;
							dust4.scale = 0.6f;
							dust4.fadeIn = dust4.scale + 0.2f;
							Dust expr_26230_cp_0 = dust4;
							expr_26230_cp_0.velocity.Y = expr_26230_cp_0.velocity.Y * 2f;
						}
					}
				}
				if (this.type == 422)
				{
					for (int num847 = 0; num847 < 2; num847++)
					{
						Vector2 vector71 = new Vector2(0f, -num835);
						vector71 *= 0.85f + (float)Main.rand.NextDouble() * 0.2f;
						vector71 = vector71.Rotate((Main.rand.NextDouble() - 0.5) * 1.5707963705062866, default(Vector2));
						int num848 = Dust.NewDust(this.position, this.width, this.height, 219 + Main.rand.Next(5), 0f, 0f, 100, default(Color), 1f);
						Dust dust5 = Main.dust[num848];
						dust5.scale = 1f + (float)Main.rand.NextDouble() * 0.3f;
						dust5.velocity *= 0.5f;
						if (dust5.velocity.Y > 0f)
						{
							Dust expr_26390_cp_0 = dust5;
							expr_26390_cp_0.velocity.Y = expr_26390_cp_0.velocity.Y * -1f;
						}
						dust5.position -= new Vector2((float)(2 + Main.rand.Next(-2, 3)), 0f);
						dust5.velocity += vector71;
						dust5.scale = 0.6f;
						dust5.fadeIn = dust5.scale + 0.2f;
						Dust expr_26416_cp_0 = dust5;
						expr_26416_cp_0.velocity.Y = expr_26416_cp_0.velocity.Y * 2f;
					}
				}
			}
		}
Esempio n. 32
0
        static IEnumerable <CodeInstruction> RefreshPreviews(IEnumerable <CodeInstruction> instructions, ILGenerator generator)
        {
            float MirrorBuildingRotation(float yaw, BlueprintBuilding building)
            {
                if (buildingsAxis.ContainsKey(building.modelIndex) && buildingsAxis[building.modelIndex] == MajorAxis.XAXIS)
                {
                    return(MirrorRotation(yaw + 90f) - 90f);
                }

                return(MirrorRotation(yaw));
            }

            CodeMatcher matcher = new CodeMatcher(instructions, generator)
                                  .MatchForward(true,
                                                new CodeMatch(OpCodes.Ldelem, typeof(Vector4)),
                                                new CodeMatch(OpCodes.Stloc_S),
                                                new CodeMatch(OpCodes.Ldloca_S));

            matcher.Advance(1);

            object longAxisVar = matcher.Operand;

            while (matcher.Opcode != OpCodes.Stfld)
            {
                matcher.RemoveInstruction();
            }

            matcher.RemoveInstructions(2);

            object latAxisVar = matcher.Operand;

            while (matcher.Opcode != OpCodes.Stfld)
            {
                matcher.RemoveInstruction();
            }

            matcher.RemoveInstruction()
            .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, longAxisVar))
            .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, latAxisVar))
            .InsertAndAdvance(Transpilers.EmitDelegate <RefAction>(MirrorArea));

            matcher.MatchForward(false,
                                 new CodeMatch(OpCodes.Call, AccessTools.Method(typeof(BlueprintUtils), nameof(BlueprintUtils.TransitionWidthAndHeight))))
            .Advance(-3)
            .RemoveInstruction().RemoveInstruction().RemoveInstruction()
            .SetInstruction(Transpilers.EmitDelegate <Func <float, BlueprintBuilding, Vector2> >((yaw, building) =>
            {
                float x = building.localOffset_x;
                float y = building.localOffset_y;


                if ((mirrorLat && !mirrorLong || !mirrorLat && mirrorLong) && buildingsOffsets.ContainsKey(building.modelIndex))
                {
                    Vector2 offset   = buildingsOffsets[building.modelIndex];
                    float rotatedYaw = MirrorBuildingRotation(building.yaw, building);

                    offset = offset.Rotate(rotatedYaw + (mirrorLong ? 180 : 0));

                    x += offset.x;
                    y += offset.y;
                }

                return(BlueprintUtils.TransitionWidthAndHeight(yaw, x, y));
            }));

            matcher.MatchForward(false,
                                 new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BlueprintBuilding), nameof(BlueprintBuilding.yaw)))
                                 ).Advance(1)
            .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 30))
            .InsertAndAdvance(Transpilers.EmitDelegate <Func <float, BlueprintBuilding, float> >(MirrorBuildingRotation)).Advance(2);

            matcher.MatchForward(false,
                                 new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BlueprintBuilding), nameof(BlueprintBuilding.yaw2)))
                                 ).Advance(1)
            .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, 30))
            .InsertAndAdvance(Transpilers.EmitDelegate <Func <float, BlueprintBuilding, float> >(MirrorBuildingRotation));

            matcher.MatchForward(true,
                                 new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(BuildPreview), nameof(BuildPreview.desc))),
                                 new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(PrefabDesc), nameof(PrefabDesc.isInserter))))
            .Advance(2);

            object previewVar2 = matcher.Operand;

            matcher.Advance(1)
            .InsertAndAdvance(new CodeInstruction(OpCodes.Ldloc_S, previewVar2))
            .InsertAndAdvance(Transpilers.EmitDelegate <Action <BuildPreview> >(preview =>
            {
                if (preview.input != null && preview.input.desc.slotPoses.Length > preview.inputFromSlot &&
                    !preview.input.desc.isBelt)
                {
                    Quaternion invRot       = Quaternion.Inverse(preview.input.lrot);
                    Vector3 slotPosition    = preview.lpos - preview.input.lpos;
                    slotPosition            = invRot * slotPosition;
                    Quaternion slotRotation = invRot * preview.lrot;


                    for (int i = 0; i < preview.input.desc.slotPoses.Length; i++)
                    {
                        Pose slotPose = preview.input.desc.slotPoses[i];
                        if (!((slotPose.position - slotPosition).sqrMagnitude < 0.1f))
                        {
                            continue;
                        }
                        if (!slotPose.rotation.Approximately(slotRotation))
                        {
                            continue;
                        }
                        if (preview.inputFromSlot == i)
                        {
                            break;
                        }

                        preview.inputFromSlot = i;
                        break;
                    }
                }

                if (preview.output != null && preview.output.desc.slotPoses.Length > preview.outputToSlot &&
                    !preview.output.desc.isBelt)
                {
                    Quaternion invRot       = Quaternion.Inverse(preview.output.lrot);
                    Vector3 slotPosition    = preview.lpos2 - preview.output.lpos;
                    slotPosition            = invRot * slotPosition;
                    Quaternion slotRotation = invRot * (preview.lrot2 * Quaternion.Euler(0f, -180f, 0f));

                    for (int i = 0; i < preview.output.desc.slotPoses.Length; i++)
                    {
                        Pose slotPose = preview.output.desc.slotPoses[i];
                        if (!((slotPose.position - slotPosition).sqrMagnitude < 0.1f))
                        {
                            continue;
                        }
                        if (!slotPose.rotation.Approximately(slotRotation))
                        {
                            continue;
                        }
                        if (preview.outputToSlot == i)
                        {
                            break;
                        }

                        preview.outputToSlot = i;
                        break;
                    }
                }
            }));


            return(matcher.InstructionEnumeration());
        }
Esempio n. 33
0
 public static Vector2 SkewDirection(this Vector2 v, int skewDegree)
 {
     return(v.Rotate(Random.Range(-skewDegree, skewDegree)));
 }
Esempio n. 34
0
    private Vector2 RandomizeDirection(Vector2 startingDirection)
    {
        float angleRandomization = ((360 * Random.value) - 180) * movementRandomization;

        return(startingDirection.Rotate(angleRandomization));
    }
Esempio n. 35
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            bool valuesChanged = false;

            var aabb = this.GetAxisAlignedBoundingBox();

            var angle            = Angle.ClampIfNotCalculated(this, 0, 10000, ref valuesChanged);
            var rotationDistance = RotationDistance.ClampIfNotCalculated(this, 0, 10000, ref valuesChanged);
            var rotationSlices   = RotationSlices.ClampIfNotCalculated(this, 3, 300, ref valuesChanged);
            var endHeightPercent = EndHeightPercent.ClampIfNotCalculated(this, 0, 100, ref valuesChanged);

            endHeightPercent = EndHeightPercent.ClampIfNotCalculated(this, 1, 100, ref valuesChanged);
            var startHeightPercent = StartHeightPercent.ClampIfNotCalculated(this, 0, endHeightPercent - 1, ref valuesChanged);

            startHeightPercent = Math.Min(endHeightPercent - 1, startHeightPercent);
            var overrideRadius = OverrideRadius.ClampIfNotCalculated(this, 1, Math.Max(aabb.XSize, aabb.YSize), ref valuesChanged);

            var rebuildLocks = this.RebuilLockAll();

            return(ApplicationController.Instance.Tasks.Execute(
                       "Twist".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var sourceAabb = this.SourceContainer.GetAxisAlignedBoundingBox();

                var bottom = sourceAabb.MinXYZ.Z;
                var top = sourceAabb.ZSize * endHeightPercent / 100.0;
                var size = sourceAabb.ZSize;
                if (Advanced)
                {
                    bottom += sourceAabb.ZSize * startHeightPercent / 100.0;
                    size = top - bottom;
                }

                double numberOfCuts = rotationSlices;

                double cutSize = size / numberOfCuts;
                var cuts = new List <double>();
                for (int i = 0; i < numberOfCuts + 1; i++)
                {
                    var ratio = i / numberOfCuts;
                    if (Advanced)
                    {
                        var goal = ratio;
                        var current = .5;
                        var next = .25;
                        // look for an x value that equals the goal
                        for (int j = 0; j < 64; j++)
                        {
                            var xAtY = Easing.Calculate(EasingType, EasingOption, current);
                            if (xAtY < goal)
                            {
                                current += next;
                            }
                            else if (xAtY > goal)
                            {
                                current -= next;
                            }

                            next *= .5;
                        }

                        ratio = current;
                    }

                    cuts.Add(bottom - cutSize + (size * ratio));
                }

                // get the rotation from the center of the circumscribed circle of the convex hull
                var enclosingCircle = SourceContainer.GetSmallestEnclosingCircleAlongZ();
                var rotationCenter = enclosingCircle.Center + RotationOffset;

                var twistedChildren = new List <IObject3D>();

                var status = new ProgressStatus();

                foreach (var sourceItem in SourceContainer.VisibleMeshes())
                {
                    var originalMesh = sourceItem.Mesh;
                    status.Status = "Copy Mesh".Localize();
                    reporter.Report(status);
                    var transformedMesh = originalMesh.Copy(CancellationToken.None);
                    var itemMatrix = sourceItem.WorldMatrix(SourceContainer);

                    // transform into this space
                    transformedMesh.Transform(itemMatrix);

                    status.Status = "Split Mesh".Localize();
                    reporter.Report(status);

                    // split the mesh along the z axis
                    transformedMesh.SplitOnPlanes(Vector3.UnitZ, cuts, cutSize / 8);

                    for (int i = 0; i < transformedMesh.Vertices.Count; i++)
                    {
                        var position = transformedMesh.Vertices[i];

                        var ratio = (position.Z - bottom) / size;

                        if (Advanced)
                        {
                            if (position.Z < bottom)
                            {
                                ratio = 0;
                            }
                            else if (position.Z > top)
                            {
                                ratio = 1;
                            }
                            else
                            {
                                ratio = (position.Z - bottom) / size;
                                ratio = Easing.Calculate(EasingType, EasingOption, ratio);
                            }
                        }

                        var angleToRotate = ratio * angle / 360.0 * MathHelper.Tau;
                        if (RotationType == RotationTypes.Distance)
                        {
                            IRadiusProvider radiusProvider = RadiusProvider;

                            // start off with assuming we want to set the radius
                            var radius = overrideRadius;
                            if (radiusProvider != null && !this.EditRadius)
                            {
                                // have a radius provider and not wanting to edit
                                radius = radiusProvider.Radius;
                            }
                            else if (!this.EditRadius)
                            {
                                // not wanting to edit
                                radius = enclosingCircle.Radius;
                            }

                            if (this.PreferedRadius != radius)
                            {
                                this.PreferedRadius = radius;
                                this.OverrideRadius.ClampIfNotCalculated(this, radius, radius, ref valuesChanged);
                                UiThread.RunOnIdle(() => Invalidate(InvalidateType.DisplayValues));
                            }

                            angleToRotate = ratio * (rotationDistance / radius);
                        }

                        if (!TwistCw)
                        {
                            angleToRotate = -angleToRotate;
                        }

                        var positionXy = new Vector2(position) - rotationCenter;
                        positionXy.Rotate(angleToRotate);
                        positionXy += rotationCenter;
                        transformedMesh.Vertices[i] = new Vector3Float(positionXy.X, positionXy.Y, position.Z);
                    }

                    // transform back into item local space
                    transformedMesh.Transform(itemMatrix.Inverted);

                    //transformedMesh.MergeVertices(.1);
                    transformedMesh.CalculateNormals();

                    var twistedChild = new Object3D()
                    {
                        Mesh = transformedMesh
                    };
                    twistedChild.CopyWorldProperties(sourceItem, SourceContainer, Object3DPropertyFlags.All, false);
                    twistedChild.Visible = true;

                    twistedChildren.Add(twistedChild);
                }

                RemoveAllButSource();
                this.SourceContainer.Visible = false;

                this.Children.Modify((list) =>
                {
                    list.AddRange(twistedChildren);
                });

                UiThread.RunOnIdle(() =>
                {
                    rebuildLocks.Dispose();
                    Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                    Invalidate(InvalidateType.DisplayValues);
                });

                return Task.CompletedTask;
            }));
        }
Esempio n. 36
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify((list) =>
                    {
                        list.Clear();
                    });

                    var content = new Object3D();

                    var scale        = 3.0;
                    var width        = NozzleWidth * scale * 3;
                    var depth        = NozzleWidth * scale * 5;
                    var spaceBetween = NozzleWidth * scale;

                    var shape = new VertexStorage();
                    shape.MoveTo(0, 0);
                    // left + spaces + blocks + right
                    var baseWidth = (2 * spaceBetween) + (4 * spaceBetween) + (5 * width) + (2 * spaceBetween);
                    shape.LineTo(baseWidth, 0);
                    shape.LineTo(baseWidth, depth);
                    shape.LineTo(0, depth);
                    if (Direction == Layout.Vertical)
                    {
                        var origin = new Vector2(0, depth / 2);
                        var delta  = new Vector2(0, depth / 2);
                        var count  = 15;
                        for (int i = 0; i < count; i++)
                        {
                            delta.Rotate(MathHelper.Tau / 2 / count);
                            shape.LineTo(origin + delta);
                        }
                    }
                    else
                    {
                        shape.LineTo(-depth, depth / 2);                         // a point on the left
                    }
                    var baseMesh = shape.Extrude(ChangeHeight);
                    content.Children.Add(new Object3D()
                    {
                        Mesh  = shape.Extrude(ChangeHeight),
                        Color = Color.LightBlue
                    });

                    var position = new Vector2(width / 2 + 2 * spaceBetween, depth / 2 - Offset * 2);
                    var step     = new Vector2(spaceBetween + width, Offset);
                    for (int i = 0; i < 5; i++)
                    {
                        var cube = PlatonicSolids.CreateCube();
                        content.Children.Add(new Object3D()
                        {
                            Mesh   = cube,
                            Color  = Color.Yellow,
                            Matrix = Matrix4X4.CreateScale(width, depth, ChangeHeight)
                                     * Matrix4X4.CreateTranslation(position.X, position.Y, ChangeHeight * 1.5),
                            MaterialIndex = CalibrationMaterialIndex
                        });
                        position += step;
                    }

                    if (Direction == Layout.Vertical)
                    {
                        content.Matrix = Matrix4X4.CreateRotationZ(MathHelper.Tau / 4);
                    }

                    this.Children.Add(content);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Esempio n. 37
0
        /// <summary>
        /// Moves the entity into the direction of the currently Following entity.
        /// </summary>
        /// <param name="gameTime">Current game time.</param>
        /// <param name="map">Current entity map.</param>
        public override void Update(GameTime gameTime, Level level)
        {
            Entity.ChangeWeapon(null, level);

            const float safeXMult = 3;

            if (_dodging && gameTime.TotalGameTime > _startDodge + TimeSpan.FromSeconds(4))
            {
                _dodging = false;
            }

            var entLocation = Entity.CenterPosition;
            var directRoute = CurrentTarget.Position;

            if (directRoute.X < 0)
            {
                Entity.CurrentView = "left";
            }
            else
            {
                Entity.CurrentView = "right";
            }
            Entity.CurrentAnimation = "walking";

            var safeVector = new Vector2(directRoute.X, directRoute.Y * safeXMult);
            var normalized = new Vector2(safeVector.X, safeVector.Y);

            normalized.Normalize();

            if (_dodging)
            {
                if (safeVector.Length() > Distance + _safeDistanceRange)
                {
                    _safeDistanceRange = 0.5;
                    Walk(gameTime, level, normalized);
                }
                else if (safeVector.Length() < Distance - _safeDistanceRange)
                {
                    _safeDistanceRange = 0.5;
                    Walk(gameTime, level, normalized * -1);
                }
                else if (Math.Abs(directRoute.Y) > 0.3 || (directRoute.X > 0 == (CurrentTarget.Entity.CurrentView == "left")))
                {
                    _safeDistanceRange = 1;
                    int angle;

                    if (CurrentTarget.Entity.CurrentView == "right")
                    {
                        if (CurrentTarget.Position.Y > entLocation.Y)
                        {
                            angle = -1;
                        }
                        else
                        {
                            angle = 1;
                        }
                    }
                    else
                    {
                        if (CurrentTarget.Position.Y > entLocation.Y)
                        {
                            angle = 1;
                        }
                        else
                        {
                            angle = -1;
                        }
                    }
                    if (_forcedAngle != null)
                    {
                        angle = _forcedAngle.Value;
                    }

                    var targetRoute = new Vector2(-normalized.X, -normalized.Y);
                    var rotated     = targetRoute.Rotate(angle * MathHelper.ToRadians(30));
                    var rotatedSafe = new Vector2(rotated.X * Distance, rotated.Y * Distance);
                    var walkRoute   = new Vector2(entLocation.X + rotatedSafe.X * safeXMult * 1.05f, entLocation.Y + rotatedSafe.Y * 1.05f) - entLocation;
                    normalized = new Vector2(walkRoute.X, walkRoute.Y);
                    normalized.Normalize();
                    if (!Walk(gameTime, level, normalized * -1))
                    {
                        _forcedAngle = -angle;
                        _dodging     = false;
                    }
                }
                else
                {
                    _dodging     = false;
                    _forcedAngle = null;
                }
            }
            else
            {
                if (!Walk(gameTime, level, normalized) && Math.Abs(directRoute.X) <= Distance)
                {
                    _dodging    = true;
                    _startDodge = gameTime.TotalGameTime;
                }
            }
        }
Esempio n. 38
0
 public static Vector2 Rotate(this Vector2 v, float angle)
 {
     return(v.Rotate(new Vector2(0, 0), angle));
 }
Esempio n. 39
0
        public void Update(GameTime someTime)
        {
            if (myHealth <= 0)
            {
                isAlive = false;
            }

            float movementSpeed = mySpeed * (float)someTime.ElapsedGameTime.TotalMilliseconds;

            myCooldown--;
            myEnemyTimer--;


            MouseState CurMouse = Mouse.GetState();
            Vector2    MouseLoc = new Vector2(CurMouse.X, CurMouse.Y);

            myDirection = MouseLoc - myPosition;
            myAngle     = (float)(Math.Atan2(myDirection.X / 2, myDirection.Y / -2));
            myDirection.Normalize();

            if (Keyboard.GetState().IsKeyDown(Keys.W))
            {
                myPosition += myDirection * movementSpeed;
            }

            for (int i = 0; i < myBullet1List.Count; i++)
            {
                for (int j = 0; j < EnemyManager.AccessEnemies.Count; j++)
                {
                    if (myBullet1List[i].Intersects(EnemyManager.AccessEnemies[j].AccessCollisionBox) == true)
                    {
                        myAmmo += 10;

                        myBullet1List.RemoveAt(i);

                        EnemyManager.AccessEnemies.RemoveAt(j);

                        i--;
                        j--;

                        break;
                    }
                }
            }

            for (int i = 0; i < myBullet2List.Count; i++)
            {
                for (int j = 0; j < EnemyManager.AccessEnemies.Count; j++)
                {
                    if (myBullet2List[i].Intersects(EnemyManager.AccessEnemies[j].AccessCollisionBox) == true)
                    {
                        myBullet2List.RemoveAt(i);
                        EnemyManager.AccessEnemies.RemoveAt(j);


                        i--;
                        j--;
                        break;
                    }
                }
            }


            myCollisionBox.Location = new Point((int)(myPosition.X - mySpriteOrigin.X), (int)(myPosition.Y - mySpriteOrigin.Y));

            if (CurMouse.LeftButton == ButtonState.Pressed && myCooldown <= 0 && myAmmo > 0)
            {
                if (isAlive == true)
                {
                    myBullet1List.Add(new Bullet1(myBullet1sprite, (myPosition), 1000f, myDirection, myWindow));
                }

                myAmmo    -= 1;
                myCooldown = 15;
            }


            if (CurMouse.RightButton == ButtonState.Pressed && myCooldown <= 0 && myAmmo > 0)
            {
                if (isAlive == true)
                {
                    myBullet2List.Add(new Bullet2(myBullet1sprite, (myPosition), 2500f, myDirection, myWindow));
                    myBullet2List.Add(new Bullet2(myBullet1sprite, (myPosition), 2500f, myDirection.Rotate(45), myWindow));
                    myBullet2List.Add(new Bullet2(myBullet1sprite, (myPosition), 2500f, myDirection.Rotate(315), myWindow));
                }
                myAmmo    -= 3;
                myCooldown = 30;
            }

            if (Keyboard.GetState().IsKeyDown(Keys.B) && myAmmo >= 50)
            {
                EnemyManager.Reset();
                myAmmo -= 50;
            }

            for (int i = 0; i < myBullet1List.Count; i++)
            {
                if (myBullet1List[i].Update(someTime) == false)
                {
                    myBullet1List.RemoveAt(i);

                    i--;
                }
            }


            for (int i = 0; i < myBullet2List.Count; i++)
            {
                if (myBullet2List[i].Update(someTime) == false)
                {
                    myBullet2List.RemoveAt(i);

                    i--;
                }
            }
        }
Esempio n. 40
0
    private void RepositionateTeamMembers()
    {
        List <HumanCharacter> charactersToPlace = new List <HumanCharacter>(this.otherCharacters)
        {
            this.player
        };
        float angle = 360 / charactersToPlace.Count;

        for (Vector2 position = this.startPosition; charactersToPlace.Count > 0; position = position.Rotate(angle))
        {
            int            randomCharacterIndex = UnityEngine.Random.Range(0, charactersToPlace.Count);
            HumanCharacter c = charactersToPlace[randomCharacterIndex];
            charactersToPlace.RemoveAt(randomCharacterIndex);
            c.transform.position = position;
        }
    }
Esempio n. 41
0
   public static Vector2 BodyToWorldDirection(
 Vector2 bodyFacing,
 Vector2 vector)
   {
       return vector.Rotate(bodyFacing);
   }
Esempio n. 42
0
        public static void CalculateChainNotes(TargetData data)
        {
            if (data.behavior != TargetBehavior.NR_Pathbuilder)
            {
                return;
            }

            if (data.pathBuilderData.createdNotes)
            {
                data.pathBuilderData.generatedNotes.ForEach(t => {
                    timeline.DeleteTargetFromAction(t);
                });
                data.pathBuilderData.createdNotes = false;
            }

            //No notes can be generated
            if (data.beatLength.tick == 0)
            {
                return;
            }

            data.pathBuilderData.generatedNotes = new List <TargetData>();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            /////////                                            WARNING!                                                      /////////
            /////////       Chainging this calculation breaks backwards compatibility with saves of older NotReaper versions!  /////////
            /////////                    Make sure to update NRCueData.Version, and handle an upgrade path!                    /////////
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //Generate first note at the start
            TargetData firstData = new TargetData();

            firstData.behavior = data.pathBuilderData.behavior;
            firstData.velocity = data.pathBuilderData.velocity;
            firstData.handType = data.pathBuilderData.handType;
            firstData.time     = data.time;
            firstData.position = data.position;
            data.pathBuilderData.generatedNotes.Add(firstData);

            //We increment as if all these values were for 1/4 notes over 4 beats, makes the ui much better
            float quarterIncrConvert = (4.0f / data.pathBuilderData.interval) * (Constants.PulsesPerQuarterNote * 4.0f / data.beatLength.tick);

            //Generate new notes
            Vector2 currentPos   = data.position;
            Vector2 currentDir   = new Vector2(Mathf.Sin(data.pathBuilderData.initialAngle * Mathf.Deg2Rad), Mathf.Cos(data.pathBuilderData.initialAngle * Mathf.Deg2Rad));
            float   currentAngle = (data.pathBuilderData.angle / 4) * quarterIncrConvert;
            float   currentStep  = data.pathBuilderData.stepDistance * quarterIncrConvert;

            TargetBehavior generatedBehavior = data.pathBuilderData.behavior;

            if (generatedBehavior == TargetBehavior.ChainStart)
            {
                generatedBehavior = TargetBehavior.Chain;
            }

            TargetVelocity generatedVelocity = data.pathBuilderData.velocity;

            if (generatedVelocity == TargetVelocity.ChainStart)
            {
                generatedVelocity = TargetVelocity.Chain;
            }

            for (int i = 1; i <= (data.beatLength.tick / (float)Constants.PulsesPerQuarterNote) * (data.pathBuilderData.interval / 4.0f); ++i)
            {
                currentPos += currentDir * currentStep;
                currentDir  = currentDir.Rotate(currentAngle);

                currentAngle += (data.pathBuilderData.angleIncrement / 4) * quarterIncrConvert;
                currentStep  += data.pathBuilderData.stepIncrement * quarterIncrConvert;

                TargetData newData = new TargetData();
                newData.behavior = generatedBehavior;
                newData.velocity = generatedVelocity;
                newData.handType = data.pathBuilderData.handType;
                newData.time     = data.time + QNT_Duration.FromBeatTime(i * (4.0f / data.pathBuilderData.interval));
                newData.position = currentPos;
                data.pathBuilderData.generatedNotes.Add(newData);
            }

            data.pathBuilderData.OnFinishRecalculate();
        }
		public void Leveling7PointsCorectInterpolation()
		{
			StaticData.Instance = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
			MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

			var levelingData = new PrintLevelingData(ActiveSliceSettings.Instance);

			double radius = 100;
			levelingData.SampledPositions = new List<Vector3>();
			Vector2 currentEdgePoint = new Vector2(radius, 0);
			for (int i = 0; i < 6; i++)
			{
				levelingData.SampledPositions.Add(new Vector3(currentEdgePoint, i));
				currentEdgePoint.Rotate(MathHelper.Tau / 6);
			}

			levelingData.SampledPositions.Add(new Vector3(0, 0, 6));

			Vector2 bedCenter = Vector2.Zero;

			RadialLevlingFunctions levelingFunctions7Point = new RadialLevlingFunctions(6, levelingData, bedCenter);
			for (int curPoint = 0; curPoint < 6; curPoint++)
			{
				int nextPoint = curPoint < 5 ? curPoint + 1 : 0;

				// test actual sample position
				Vector2 currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				Vector3 destPosition = new Vector3(currentTestPoint, 0);
				Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, levelingData.SampledPositions[curPoint].z, .001);
				string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test mid point between samples
				Vector3 midPoint = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2;
				currentTestPoint = new Vector2(midPoint.x, midPoint.y);
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, midPoint.z, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test mid point between samples with offset
				Vector3 midPointWithOffset = (levelingData.SampledPositions[curPoint] + levelingData.SampledPositions[nextPoint]) / 2 + new Vector3(0, 0, 3);
				currentTestPoint = new Vector2(midPointWithOffset.x, midPointWithOffset.y);
				destPosition = new Vector3(currentTestPoint, 3);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, midPointWithOffset.z, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test 1/2 angles (mid way between samples on radius)
				currentTestPoint = new Vector2(radius, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * (curPoint + .5));
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				// the center is the higest point so the point on the radius has to be less than the mid point of the sample points (it is lower)
				Assert.IsTrue(outPosition.z < (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[nextPoint].z) / 2 - .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);

				// test 1/2 to center
				currentTestPoint = new Vector2(radius / 2, 0);
				currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
				destPosition = new Vector3(currentTestPoint, 0);
				outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);
				Assert.AreEqual(outPosition.z, (levelingData.SampledPositions[curPoint].z + levelingData.SampledPositions[6].z) / 2, .001);
				outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Absolute);
				Assert.AreEqual(GetGCodeString(outPosition), outPositionString);
			}

			// prove that relative offsets work
			{
				Vector2 prevTestPoint = new Vector2(radius, 0);
				Vector3 prevDestPosition = new Vector3(prevTestPoint, 0);
				Vector3 prevOutPosition = levelingFunctions7Point.GetPositionWithZOffset(prevDestPosition);
				string prevOutPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(prevDestPosition), prevDestPosition, PrinterMachineInstruction.MovementTypes.Absolute);

				for (int curPoint = 1; curPoint < 6; curPoint++)
				{
					// test actual sample position
					Vector2 currentTestPoint = new Vector2(radius, 0);
					currentTestPoint.Rotate(MathHelper.Tau / 6 * curPoint);
					Vector3 destPosition = new Vector3(currentTestPoint, 0);
					Vector3 outPosition = levelingFunctions7Point.GetPositionWithZOffset(destPosition);

					string outPositionString = levelingFunctions7Point.DoApplyLeveling(GetGCodeString(destPosition), destPosition, PrinterMachineInstruction.MovementTypes.Relative);
					Vector3 delatFromPrevToCurrent = outPosition - prevOutPosition;
					Assert.AreEqual(GetGCodeString(delatFromPrevToCurrent), outPositionString);

					prevTestPoint = currentTestPoint;
					prevDestPosition = destPosition;
					prevOutPosition = outPosition;
				}
			}

			Vector3 outPosition2 = levelingFunctions7Point.GetPositionWithZOffset(Vector3.Zero);
			Assert.AreEqual(outPosition2.z, levelingData.SampledPositions[6].z, .001);
		}
Esempio n. 44
0
    private void AddTree(Vector3 root, float radius, float height, Color color, Vector2 biome, bool snow, float rotation = 0)
    {
        int index = vertices.Count;
        vertices.Add(new Vector3(root.x, root.y + height, root.z));
        colors.Add(color);
        uvCoords2.Add(biome);
        uvCoords3.Add(new Vector2(snow ? snowLevel : 0, 0));
        uvCoords.Add(new Vector2(vertices[index].x, vertices[index].z));
        Vector2 spoke = new Vector2(radius, 0);
        spoke = spoke.Rotate(rotation);
        index = vertices.Count;
        for (int i = 0; i < 12; i += 2)
        {
            spoke = spoke.Rotate(360.0f / 6);
            vertices.Add(new Vector3(root.x + spoke.x, root.y + height - (0.577f * radius), root.z + spoke.y));
            vertices.Add(new Vector3(root.x + spoke.x, root.y , root.z + spoke.y));

            colors.Add(color);
            colors.Add(color);
            uvCoords2.Add(biome);
            uvCoords2.Add(biome);
            uvCoords3.Add(new Vector2(snow ? snowLevel : 0, 0));
            uvCoords3.Add(new Vector2(snow ? snowLevel : 0, 0));
            uvCoords.Add(new Vector2(vertices[index + i].x, vertices[index + i].z));
            uvCoords.Add(new Vector2(vertices[index + i + 1].x, vertices[index + i + 1].z));

            triangles.Add(index - 1);
            triangles.Add(index + (i + 2) % 12);
            triangles.Add(index + i);

            triangles.Add(index + (i + 0) % 12);
            triangles.Add(index + (i + 3) % 12);
            triangles.Add(index + (i + 1) % 12);

            triangles.Add(index + (i + 0) % 12);
            triangles.Add(index + (i + 2) % 12);
            triangles.Add(index + (i + 3) % 12);
        }
    }
Esempio n. 45
0
 public static Vector2 applyTransform(scTransform transform, Vector2 vector)
 {
     return transform.position + vector.Rotate(transform.rotation.radians);
 }