Example #1
0
        public static void Initialize(ISandbox sandbox)
        {
            var properties = typeof(Location).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var resource   = Properties.Resources.AreaTriggers;
            var entries    = resource.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            int j;

            for (int i = 0; i < entries.Length; i++)
            {
                string[] data = entries[i].Split(',');

                var location = new Location();
                for (j = 0; j < properties.Length; j++)
                {
                    properties[j].SetValueEx(location, data[j + 1]);
                }

                // skip invalid expansions
                if (location.Expansion > sandbox.Expansion)
                {
                    continue;
                }

                // take the most recent variant
                var id = uint.Parse(data[0]);
                if (!Triggers.ContainsKey(id) || Triggers[id].Expansion < location.Expansion)
                {
                    Triggers[id] = location;
                }
            }

            ApplyOverrides(sandbox.Build);
        }
Example #2
0
 public ExecuteStepProcessor(IStepRegistry stepRegistry, IMethodExecutor methodExecutor, ISandbox sandbox)
 {
     _stepRegistry   = stepRegistry;
     _methodExecutor = methodExecutor;
     _sandbox        = sandbox;
     InitializeConverter();
 }
Example #3
0
        public static CallbackResult GetLastError(ISandbox sandbox)
        {
            var pointerSize         = 32;
            var functionReturnValue = B2R2.BitVector.OfInt32(0x57, pointerSize);
            var returnValue         = new Microsoft.FSharp.Core.FSharpOption <B2R2.BitVector>(functionReturnValue);

            return(new CallbackResult(returnValue, CallingConvention.Cdecl));
        }
Example #4
0
 public MessageProcessorFactory(ISandbox sandbox)
 {
     _sandbox = sandbox;
     using (var apiConnection = new GaugeApiConnection(new TcpClientWrapper(Utils.GaugeApiPort)))
     {
         _stepScanner = new MethodScanner(apiConnection, _sandbox);
         InitializeProcessors(_stepScanner);
     }
 }
 public MessageProcessorFactory(IMethodScanner stepScanner, ISandbox sandbox, IAssemblyLoader assemblyLoader, IActivatorWrapper activatorWrapper, ITableFormatter tableFormatter, IReflectionWrapper reflectionWrapper)
 {
     _tableFormatter    = tableFormatter;
     _reflectionWrapper = reflectionWrapper;
     _assemblyLoader    = assemblyLoader;
     _activatorWrapper  = activatorWrapper;
     _stepScanner       = stepScanner;
     _sandbox           = sandbox;
     InitializeProcessors(stepScanner);
 }
Example #6
0
        public ComponentViewModel(ISandbox _sandbox, IFrameworkFacade _frameworkFacade)
        {
            #region Pre-conditions
            Contract.Requires(_sandbox != null);
            Contract.Requires(_frameworkFacade != null);
            #endregion

            this.sandbox         = _sandbox;
            this.frameworkFacade = _frameworkFacade;
        }
Example #7
0
        public ComponentViewModel(ISandbox _sandbox, IFrameworkFacade _frameworkFacade)
        {
            #region Pre-conditions
            Contract.Requires(_sandbox != null);
            Contract.Requires(_frameworkFacade != null);
            #endregion

            this.sandbox = _sandbox;
            this.frameworkFacade = _frameworkFacade;
        }
        public static bool SwitchTiles(Func <Int32, Int32, ITile> TileRefs, ISandbox sandbox, Vector2 Position, int Width, int Height, Vector2 oldPosition, ISender Sender)
        {
            if (TileRefs == null)
            {
                TileRefs = TileCollection.ITileAt;
            }

            int num  = (int)(Position.X / 16f) - 1;
            int num2 = (int)((Position.X + (float)Width) / 16f) + 2;
            int num3 = (int)(Position.Y / 16f) - 1;
            int num4 = (int)((Position.Y + (float)Height) / 16f) + 2;

            if (num < 0)
            {
                num = 0;
            }

            if (num2 > Main.maxTilesX)
            {
                num2 = Main.maxTilesX;
            }

            if (num3 < 0)
            {
                num3 = 0;
            }

            if (num4 > Main.maxTilesY)
            {
                num4 = Main.maxTilesY;
            }

            for (int x = num; x < num2; x++)
            {
                for (int y = num3; y < num4; y++)
                {
                    if (TileRefs(x, y).Active&& TileRefs(x, y).Type == 135)
                    {
                        Vector2 vector;
                        vector.X = (float)(x * 16);
                        vector.Y = (float)(y * 16 + 12);
                        if (Position.X + (float)Width > vector.X && Position.X < vector.X + 16f && Position.Y +
                            (float)Height > vector.Y && (double)Position.Y < (double)vector.Y + 4.01 && (oldPosition.X +
                                                                                                         (float)Width <= vector.X || oldPosition.X >= vector.X + 16f || oldPosition.Y +
                                                                                                         (float)Height <= vector.Y || (double)oldPosition.Y >= (double)vector.Y + 16.01))
                        {
                            WorldModify.hitSwitch(TileRefs, sandbox, x, y, Sender);
                            NetMessage.SendData(59, -1, -1, "", x, (float)y, 0f, 0f, 0);
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Example #9
0
 private static void Run(ISandbox sandbox)
 {
     try
     {
         Console.WriteLine("-=[ Start Emulation ]=-");
         sandbox.Run();
     }
     catch {
         /* Exception due to some limitation in this emulator */
         Console.WriteLine("-=[ Emulation Completed ]=-");
     }
 }
Example #10
0
        public BaseClientProxy(ISandbox _sandbox, Binding _binding, EndpointAddress _endpoint)
        {
            #region Pre-conditions
            Contract.Requires(_sandbox != null);
            Contract.Requires(_binding != null);
            Contract.Requires(_endpoint != null);
            #endregion

            this.sandbox  = _sandbox;
            this.syncroot = new object();
            this.binding  = _binding;
            this.endpoint = _endpoint;

            Initialize();
        }
Example #11
0
        public Engine(ICommandRunner commandRunner, ISandbox sandbox, IHelpProvider helpProvider)
        {
            if (commandRunner == null)
            {
                throw new ArgumentNullException(nameof(commandRunner));
            }

            if (sandbox == null)
            {
                throw new ArgumentNullException(nameof(sandbox));
            }

            this.commandRunner = commandRunner;
            this.sandbox       = sandbox;
            this.helpProvider  = helpProvider;
        }
Example #12
0
 private void Init(ISandbox sandbox, DateTime initialTime, bool keepHistory)
 {
     _sandbox       = sandbox;
     _initialTime   = initialTime;
     LastTime       = initialTime;
     LastCount      = 0;
     TotalIncrement = 0;
     TotalDecrement = 0;
     TotalHours     = 0;
     CumValue       = 0;
     KeepHistory    = keepHistory;
     if (KeepHistory)
     {
         _history = new Dictionary <DateTime, double>();
     }
 }
        public static void AddWater(Func <Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y)
        {
            if (TileRefs == null)
            {
                TileRefs = TileCollection.ITileAt;
            }

            if (TileRefs(x, y).CheckingLiquid || (x >= Main.maxTilesX - 5 || y >= Main.maxTilesY - 5) || (x < 5 || y < 5) || TileRefs(x, y).Liquid == 0)
            {
                return;
            }

            if (Liquid.numLiquid >= Liquid.maxLiquid - 1)
            {
                LiquidBuffer.AddBuffer(TileRefs, x, y);
                return;
            }

            TileRefs(x, y).SetCheckingLiquid(true);
            Main.liquid[Liquid.numLiquid].kill  = 0;
            Main.liquid[Liquid.numLiquid].x     = x;
            Main.liquid[Liquid.numLiquid].y     = y;
            Main.liquid[Liquid.numLiquid].delay = 0;
            TileRefs(x, y).SetSkipLiquid(false);

            Liquid.numLiquid++;

            if (Liquid.numLiquid < Liquid.maxLiquid / 3)
            {
                NetMessage.SendWater(x, y);
            }
            if (TileRefs(x, y).Active&& (Main.tileWaterDeath[(int)TileRefs(x, y).Type] || (TileRefs(x, y).Lava&& Main.tileLavaDeath[(int)TileRefs(x, y).Type])))
            {
                if (TileRefs(x, y).Type == 4 && TileRefs(x, y).FrameY == 176)
                {
                    return;
                }

                if (WorldModify.gen)
                {
                    TileRefs(x, y).SetActive(false);
                    return;
                }
                WorldModify.KillTile(TileRefs, sandbox, x, y);
                NetMessage.SendData(17, -1, -1, "", 0, (float)x, (float)y);
            }
        }
        public static void HitTiles(Func <Int32, Int32, ITile> TileRefs, ISandbox sandbox, Vector2 Position, Vector2 Velocity, int Width, int Height)
        {
            if (TileRefs == null)
            {
                TileRefs = TileCollection.ITileAt;
            }

            Vector2 nextPos = Position + Velocity;
            int     left    = (int)(Position.X / 16f) - 1;
            int     right   = (int)((Position.X + (float)Width) / 16f) + 2;
            int     top     = (int)(Position.Y / 16f) - 1;
            int     bottom  = (int)((Position.Y + (float)Height) / 16f) + 2;

            if (left < 0)
            {
                left = 0;
            }
            if (right > Main.maxTilesX)
            {
                right = Main.maxTilesX;
            }
            if (top < 0)
            {
                top = 0;
            }
            if (bottom > Main.maxTilesY)
            {
                bottom = Main.maxTilesY;
            }
            for (int i = left; i < right; i++)
            {
                for (int j = top; j < bottom; j++)
                {
                    if (TileRefs(i, j).Active&& (Main.tileSolid[(int)TileRefs(i, j).Type] || (Main.tileSolidTop[(int)TileRefs(i, j).Type] && TileRefs(i, j).FrameY == 0)))
                    {
                        Vector2 vector2;
                        vector2.X = (float)(i * 16);
                        vector2.Y = (float)(j * 16);
                        if (nextPos.X + (float)Width >= vector2.X && nextPos.X <= vector2.X + 16f && nextPos.Y + (float)Height >= vector2.Y && nextPos.Y <= vector2.Y + 16f)
                        {
                            WorldModify.KillTile(TileRefs, sandbox, i, j, true, true);
                        }
                    }
                }
            }
        }
        public static void LavaCheck(Func <Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y)
        {
            if (TileRefs == null)
            {
                TileRefs = TileCollection.ITileAt;
            }

            if ((TileRefs(x - 1, y).Liquid > 0 && !TileRefs(x - 1, y).Lava) || (TileRefs(x + 1, y).Liquid > 0 && !TileRefs(x + 1, y).Lava) || (TileRefs(x, y - 1).Liquid > 0 && !TileRefs(x, y - 1).Lava))
            {
                int liq = 0;
                if (!TileRefs(x - 1, y).Lava)
                {
                    liq += (int)TileRefs(x - 1, y).Liquid;
                    TileRefs(x - 1, y).SetLiquid(0);
                }
                if (!TileRefs(x + 1, y).Lava)
                {
                    liq += (int)TileRefs(x + 1, y).Liquid;
                    TileRefs(x + 1, y).SetLiquid(0);
                }
                if (!TileRefs(x, y - 1).Lava)
                {
                    liq += (int)TileRefs(x, y - 1).Liquid;
                    TileRefs(x, y - 1).SetLiquid(0);
                }
                if (liq >= 32 && !TileRefs(x, y).Active)
                {
                    TileRefs(x, y).SetLiquid(0);
                    TileRefs(x, y).SetLava(false);
                    WorldModify.PlaceTile(TileRefs, sandbox, x, y, 56, true, true, -1, 0);
                    WorldModify.SquareTileFrame(TileRefs, sandbox, x, y, true);

                    NetMessage.SendTileSquare(-1, x - 1, y - 1, 3);
                    return;
                }
            }
            else if (TileRefs(x, y + 1).Liquid > 0 && !TileRefs(x, y + 1).Lava&& !TileRefs(x, y + 1).Active)
            {
                TileRefs(x, y).SetLiquid(0);
                TileRefs(x, y).SetLava(false);
                TileRefs(x, y + 1).SetLiquid(0);
                WorldModify.PlaceTile(TileRefs, sandbox, x, y + 1, 56, true, true, -1, 0);
                WorldModify.SquareTileFrame(TileRefs, sandbox, x, y + 1, true);
                NetMessage.SendTileSquare(-1, x - 1, y, 3);
            }
        }
        public object Convert(Parameter parameter, ISandbox sandbox)
        {
            var protoTable = parameter.Table;

            if (protoTable == null || protoTable.Headers == null)
            {
                throw new Exception("Invalid table passed to step");
            }
            var protoTableRow = protoTable.Headers;
            var header        = GetTableRowFor(protoTableRow);
            var type          = sandbox.GetTargetType(typeof(Table).FullName);
            var table         = Activator.CreateInstance(type, header);

            for (var i = 0; i < protoTable.RowsCount; i++)
            {
                var row = GetTableRowFor(protoTable.GetRows(i));
                type.InvokeMember("AddRow", BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, table, new object[] { row });
            }
            return(table);
        }
        public static void AddWater(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (TileRefs(x, y).CheckingLiquid || (x >= Main.maxTilesX - 5 || y >= Main.maxTilesY - 5) || (x < 5 || y < 5) || TileRefs(x, y).Liquid == 0)
                return;

            if (Liquid.numLiquid >= Liquid.maxLiquid - 1)
            {
                LiquidBuffer.AddBuffer(TileRefs, x, y);
                return;
            }

            TileRefs(x, y).SetCheckingLiquid(true);
            Main.liquid[Liquid.numLiquid].kill = 0;
            Main.liquid[Liquid.numLiquid].x = x;
            Main.liquid[Liquid.numLiquid].y = y;
            Main.liquid[Liquid.numLiquid].delay = 0;
            TileRefs(x, y).SetSkipLiquid(false);

            Liquid.numLiquid++;

            if (Liquid.numLiquid < Liquid.maxLiquid / 3)
            {
                NetMessage.SendWater(x, y);
            }
            if (TileRefs(x, y).Active && (Main.tileWaterDeath[(int)TileRefs(x, y).Type] || (TileRefs(x, y).Lava && Main.tileLavaDeath[(int)TileRefs(x, y).Type])))
            {
                if (TileRefs(x, y).Type == 4 && TileRefs(x, y).FrameY == 176)
                    return;

                if (WorldModify.gen)
                {
                    TileRefs(x, y).SetActive(false);
                    return;
                }
                WorldModify.KillTile(TileRefs, sandbox, x, y);
                NetMessage.SendData(17, -1, -1, "", 0, (float)x, (float)y);
            }
        }
Example #18
0
 private static void Run(ISandbox sandbox, Boolean controlledEnv = true)
 {
     Console.WriteLine("-=[ Start Emulation ]=-");
     if (controlledEnv)
     {
         try
         {
             sandbox.Run();
         }
         catch (Exception e)
         {
             Console.WriteLine("EX: " + e.ToString());
             // Exception due to some limitation in this emulator
             Console.WriteLine("-=[ Emulation Completed ]=-");
         }
     }
     else
     {
         sandbox.Run();
     }
 }
Example #19
0
        public static void Initialize(ISandbox sandbox)
        {
            var properties = typeof(Location).GetProperties(BindingFlags.Public | BindingFlags.Instance);
            var resource   = Properties.Resources.Worldports;
            var entries    = resource.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);

            int j;

            for (int i = 0; i < entries.Length; i++)
            {
                string[] data = entries[i].Split(',');

                var location = new Location();
                for (j = 0; j < properties.Length; j++)
                {
                    properties[j].SetValueEx(location, data[j]);
                }

                if (location.Expansion <= sandbox.Expansion)
                {
                    Locations.Add(location);
                }
            }
        }
 public RefactorProcessor(IStepRegistry stepRegistry, ISandbox sandbox)
 {
     _stepRegistry = stepRegistry;
     _sandbox      = sandbox;
 }
        /// <summary>
        /// Destroys the projectile
        /// </summary>
        public void Kill(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (!this.Active)
            {
                return;
            }
            this.timeLeft = 0;
            switch (this.type)
            {
                case ProjectileType.N14_BULLET:
                case ProjectileType.N20_GREEN_LASER:
                case ProjectileType.N36_METEOR_SHOT:
                case ProjectileType.N83_EYE_LASER:
                case ProjectileType.N84_PINK_LASER:
                case ProjectileType.N100_DEATH_LASER:
                    {
                        Collision.HitTiles(TileRefs, sandbox, this.Position, this.Velocity, this.Width, this.Height);
                    }
                    break;

                case ProjectileType.N28_BOMB:
                case ProjectileType.N30_GRENADE:
                case ProjectileType.N37_STICKY_BOMB:
                case ProjectileType.N75_HAPPY_BOMB:
                case ProjectileType.N102_BOMB:
                    {
                        this.Position.X = this.Position.X + (float)(this.Width / 2);
                        this.Position.Y = this.Position.Y + (float)(this.Height / 2);
                        this.Width = 22;
                        this.Height = 22;
                        this.Position.X = this.Position.X - (float)(this.Width / 2);
                        this.Position.Y = this.Position.Y - (float)(this.Height / 2);
                    }
                    break;

                case ProjectileType.N29_DYNAMITE:
                    {
                        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);
                    }
                    break;

                case ProjectileType.N108_EXPLOSIVES:
                    {
                        this.Position.X = this.Position.X + (float)(this.Width / 2);
                        this.Position.Y = this.Position.Y + (float)(this.Height / 2);
                        this.Width = 10;
                        this.Height = 10;
                        this.Position.X = this.Position.X - (float)(this.Width / 2);
                        this.Position.Y = this.Position.Y - (float)(this.Height / 2);
                    }
                    break;

                case ProjectileType.N41_HELLFIRE_ARROW:
                    {
                        if (this.Owner == Main.myPlayer)
                        {
                            this.penetrate = -1;
                            this.Position.X = this.Position.X + (float)(this.Width / 2);
                            this.Position.Y = this.Position.Y + (float)(this.Height / 2);
                            this.Width = 64;
                            this.Height = 64;
                            this.Position.X = this.Position.X - (float)(this.Width / 2);
                            this.Position.Y = this.Position.Y - (float)(this.Height / 2);
                            this.Damage(TileRefs, sandbox);
                        }
                    }
                    break;

                case ProjectileType.N80_ICE_BLOCK:
                    {
                        int num16 = (int)this.Position.X / 16;
                        int num17 = (int)this.Position.Y / 16;
                        if (!TileRefs(num16, num17).Exists)
                        {
                            Main.tile.CreateTileAt(num16, num17);
                        }
                        if (TileRefs(num16, num17).Type == 127 && TileRefs(num16, num17).Active)
                        {
                            WorldModify.KillTile(TileRefs, sandbox, num16, num17);
                        }
                    }
                    break;

                case ProjectileType.N89_CRYSTAL_BULLET:
                    {
                        if (this.Owner == Main.myPlayer)
                        {
                            for (int num12 = 0; num12 < 3; num12++)
                            {
                                float num13 = -this.Velocity.X * (float)Main.rand.Next(40, 70) * 0.01f + (float)Main.rand.Next(-20, 21) * 0.4f;
                                float num14 = -this.Velocity.Y * (float)Main.rand.Next(40, 70) * 0.01f + (float)Main.rand.Next(-20, 21) * 0.4f;
                                Projectile.NewProjectile(this.Position.X + num13, this.Position.Y + num14, num13, num14, 90, (int)((double)this.damage * 0.6), 0f, this.Owner);
                            }
                        }
                    }
                    break;

                case ProjectileType.N91_HOLY_ARROW:
                    {
                        float x = this.Position.X + (float)Main.rand.Next(-400, 400);
                        float y = this.Position.Y - (float)Main.rand.Next(600, 900);
                        Vector2 vector = new Vector2(x, y);
                        float num4 = this.Position.X + (float)(this.Width / 2) - vector.X;
                        float num5 = this.Position.Y + (float)(this.Height / 2) - vector.Y;
                        int num6 = 22;
                        float num7 = (float)Math.Sqrt((double)(num4 * num4 + num5 * num5));
                        num7 = (float)num6 / num7;
                        num4 *= num7;
                        num5 *= num7;
                        int num8 = (int)((float)this.damage * 0.5f);
                        int num9 = Projectile.NewProjectile(x, y, num4, num5, 92, num8, this.knockBack, this.Owner);
                        Main.projectile[num9].ai[1] = this.Position.Y;
                        Main.projectile[num9].ai[0] = 1f;
                    }
                    break;

                case ProjectileType.N92_HALLOW_STAR:
                    {
                        float x_2 = this.Position.X + (float)Main.rand.Next(-400, 400);
                        float y_2 = this.Position.Y - (float)Main.rand.Next(600, 900);
                        Vector2 vector_2 = new Vector2(x_2, y_2);
                        float num4_2 = this.Position.X + (float)(this.Width / 2) - vector_2.X;
                        float num5_2 = this.Position.Y + (float)(this.Height / 2) - vector_2.Y;
                        int num6_2 = 22;
                        float num7_2 = (float)Math.Sqrt((double)(num4_2 * num4_2 + num5_2 * num5_2));
                        num7_2 = (float)num6_2 / num7_2;
                        num4_2 *= num7_2;
                        num5_2 *= num7_2;
                        int num9_2 = Projectile.NewProjectile(x_2, y_2, num4_2, num5_2, 92, this.damage, this.knockBack, this.Owner);
                        Main.projectile[num9_2].ai[1] = this.Position.Y;
                    }
                    break;

                case ProjectileType.N99_BOULDER:
                    this.Velocity *= 1.9f;
                    break;

                default:
                    break;
            }
            if (this.Owner == Main.myPlayer)
            {
                bool explode = false;
                if (this.type == ProjectileType.N28_BOMB ||
                    this.type == ProjectileType.N29_DYNAMITE ||
                    this.type == ProjectileType.N37_STICKY_BOMB ||
                    this.type == ProjectileType.N75_HAPPY_BOMB ||
                    this.type == ProjectileType.N108_EXPLOSIVES)
                {
                    var ctx = new HookContext
                    {
                        Sender = this,
                    };

                    var args = new HookArgs.Explosion
                    {
                        Source = this,
                    };

                    HookPoints.Explosion.Invoke(ref ctx, ref args);

                    if (ctx.Result != HookResult.IGNORE)
                    {
                        explode = true;
                    }
                }

                if (explode)
                {
                    int num38 = 3;
                    if (this.type == ProjectileType.N29_DYNAMITE)
                    {
                        num38 = 7;
                    }
                    if (this.type == ProjectileType.N108_EXPLOSIVES)
                    {
                        num38 = 10;
                    }
                    int num39 = (int)(this.Position.X / 16f - (float)num38);
                    int num40 = (int)(this.Position.X / 16f + (float)num38);
                    int num41 = (int)(this.Position.Y / 16f - (float)num38);
                    int num42 = (int)(this.Position.Y / 16f + (float)num38);
                    if (num39 < 0)
                    {
                        num39 = 0;
                    }
                    if (num40 > Main.maxTilesX)
                    {
                        num40 = Main.maxTilesX;
                    }
                    if (num41 < 0)
                    {
                        num41 = 0;
                    }
                    if (num42 > Main.maxTilesY)
                    {
                        num42 = Main.maxTilesY;
                    }
                    bool flag = false;
                    for (int num43 = num39; num43 <= num40; num43++)
                    {
                        for (int num44 = num41; num44 <= num42; num44++)
                        {
                            float num45 = Math.Abs((float)num43 - this.Position.X / 16f);
                            float num46 = Math.Abs((float)num44 - this.Position.Y / 16f);
                            double num47 = Math.Sqrt((double)(num45 * num45 + num46 * num46));
                            if (num47 < (double)num38 && TileRefs(num43, num44).Exists && TileRefs(num43, num44).Wall == 0)
                            {
                                flag = true;
                                break;
                            }
                        }
                    }
                    for (int num89 = num39; num89 <= num40; num89++)
                    {
                        for (int num90 = num41; num90 <= num42; num90++)
                        {
                            float num50 = Math.Abs((float)num89 - this.Position.X / 16f);
                            float num51 = Math.Abs((float)num90 - this.Position.Y / 16f);
                            double num52 = Math.Sqrt((double)(num50 * num50 + num51 * num51));
                            int alter = -1;
                            if (num52 < (double)num38)
                            {
                                bool flag2 = true;
                                if (TileRefs(num89, num90).Active)
                                {
                                    if (Main.tileDungeon[(int)TileRefs(num89, num90).Type] || TileRefs(num89, num90).Type == 21 ||
                                    TileRefs(num89, num90).Type == 26 || TileRefs(num89, num90).Type == 107 ||
                                    TileRefs(num89, num90).Type == 108 || TileRefs(num89, num90).Type == 111)
                                    {
                                        flag2 = false;
                                    }
                                    if (!Main.hardMode && TileRefs(num89, num90).Type == 58)
                                    {
                                        flag2 = false;
                                    }
                                    if (flag2)
                                    {
                                        alter = 0;
                                    }
                                }
                                if (flag2 && TileRefs(num89, num90).Wall > 0 && flag)
                                {
                                    alter = alter == 0 ? 100 : 2;
                                }
                                if (alter >= 0)
                                {
                                    var plr = Creator as Player;
                                    if (plr == null || WorldModify.InvokeAlterationHook(this, plr, num89, num90, (byte)alter))
                                    {
                                        if (alter == 0 || alter == 100)
                                        {
                                            WorldModify.KillTile(TileRefs, sandbox, num89, num90);
                                            NetMessage.SendData(17, -1, -1, "", 0, (float)num89, (float)num90, 0f, 0);
                                        }
                                        if (alter == 2 || alter == 100)
                                        {
                                            WorldModify.KillWall(TileRefs, sandbox, num89, num90);
                                            NetMessage.SendData(17, -1, -1, "", 2, (float)num89, (float)num90, 0f, 0);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                NetMessage.SendData(29, -1, -1, "", this.identity, (float)this.Owner);

                int num96 = -1;
                if (this.aiStyle == 10)
                {
                    int num54 = (int)(this.Position.X + (float)(this.Width / 2)) / 16;
                    int num55 = (int)(this.Position.Y + (float)(this.Width / 2)) / 16;
                    int num99 = 0;
                    int num100 = 2;
                    if (this.type == ProjectileType.N31_SAND_BALL)
                    {
                        num99 = 53;
                        num100 = 0;
                    }
                    else if (this.type == ProjectileType.N42_SAND_BALL)
                    {
                        num99 = 53;
                        num100 = 0;
                    }
                    else if (this.type == ProjectileType.N39_MUD_BALL)
                    {
                        num99 = 59;
                        num100 = 176;
                    }
                    else if (this.type == ProjectileType.N40_ASH_BALL)
                    {
                        num99 = 57;
                        num100 = 172;
                    }
                    else if (this.type == ProjectileType.N56_EBONSAND_BALL)
                    {
                        num99 = 112;
                        num100 = 0;
                    }
                    else if (this.type == ProjectileType.N65_EBONSAND_BALL)
                    {
                        num99 = 112;
                        num100 = 0;
                    }
                    else if (this.type == ProjectileType.N67_PEARL_SAND_BALL)
                    {
                        num99 = 116;
                        num100 = 0;
                    }
                    else if (this.type == ProjectileType.N68_PEARL_SAND_BALL)
                    {
                        num99 = 116;
                        num100 = 0;
                    }
                    else if (this.type == ProjectileType.N71_GRAVEL_BALL)
                    {
                        num99 = 123;
                        num100 = 0;
                    }
                    if (!TileRefs(num54, num55).Active)
                    {
                        WorldModify.PlaceTile(TileRefs, sandbox, num54, num55, num99, false, true, -1, 0);
                        if (TileRefs(num54, num55).Active && (int)TileRefs(num54, num55).Type == num99)
                        {
                            NetMessage.SendData(17, -1, -1, "", 1, (float)num54, (float)num55, (float)num99);
                        }
                        else
                        {
                            if (num100 > 0)
                            {
                                num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, num100, 1, false);
                            }
                        }
                    }
                    else
                    {
                        if (num100 > 0)
                        {
                            num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, num100, 1, false);
                        }
                    }
                }
                if (this.type == ProjectileType.N1_WOODEN_ARROW && Main.rand.Next(2) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 40, 1, false);
                }
                if (this.type == ProjectileType.N103_CURSED_ARROW && Main.rand.Next(6) == 0)
                {
                    if (Main.rand.Next(3) == 0)
                    {
                        num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 545, 1, false);
                    }
                    else
                    {
                        num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 40, 1, false);
                    }
                }
                if (this.type == ProjectileType.N2_FIRE_ARROW && Main.rand.Next(2) == 0)
                {
                    if (Main.rand.Next(3) == 0)
                    {
                        num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 41, 1, false);
                    }
                    else
                    {
                        num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 40, 1, false);
                    }
                }
                if (this.type == ProjectileType.N91_HOLY_ARROW && Main.rand.Next(6) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 516, 1, false);
                }
                if (this.type == ProjectileType.N50_GLOWSTICK && Main.rand.Next(3) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 282, 1, false);
                }
                if (this.type == ProjectileType.N53_STICKY_GLOWSTICK && Main.rand.Next(3) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 286, 1, false);
                }
                if (this.type == ProjectileType.N48_THROWING_KNIFE && Main.rand.Next(2) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 279, 1, false);
                }
                if (this.type == ProjectileType.N54_POISONED_KNIFE && Main.rand.Next(2) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 287, 1, false);
                }
                if (this.type == ProjectileType.N3_SHURIKEN && Main.rand.Next(2) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 42, 1, false);
                }
                if (this.type == ProjectileType.N4_UNHOLY_ARROW && Main.rand.Next(2) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 47, 1, false);
                }
                if (this.type == ProjectileType.N12_FALLING_STAR && this.damage > 100)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 75, 1, false);
                }
                if (this.type == ProjectileType.N21_BONE && Main.rand.Next(2) == 0)
                {
                    num96 = Item.NewItem((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height, 154, 1, false);
                }

                if (this.type == ProjectileType.N69_HOLY_WATER || this.type == ProjectileType.N70_UNHOLY_WATER)
                {
                    int num101 = (int)(this.Position.X + (float)(this.Width / 2)) / 16;
                    int num102 = (int)(this.Position.Y + (float)(this.Height / 2)) / 16;
                    for (int num103 = num101 - 4; num103 <= num101 + 4; num103++)
                    {
                        for (int num104 = num102 - 4; num104 <= num102 + 4; num104++)
                        {
                            if (Math.Abs(num103 - num101) + Math.Abs(num104 - num102) < 6)
                            {
                                if (this.type == ProjectileType.N69_HOLY_WATER)
                                {
                                    switch (TileRefs(num103, num104).Type)
                                    {
                                        case 2:
                                            {
                                                TileRefs(num103, num104).SetType(109);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;
                                        case 1:
                                            {
                                                TileRefs(num103, num104).SetType(117);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;
                                        case 53:
                                            {
                                                TileRefs(num103, num104).SetType(116);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;
                                        case 23:
                                            {
                                                TileRefs(num103, num104).SetType(109);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;
                                        case 25:
                                            {
                                                TileRefs(num103, num104).SetType(117);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;
                                        case 112:
                                            {
                                                TileRefs(num103, num104).SetType(116);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;

                                        default:
                                            break;
                                    }
                                }
                                else
                                {
                                    switch (TileRefs(num103, num104).Type)
                                    {
                                        case 2:
                                            {
                                                TileRefs(num103, num104).SetType(23);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;

                                        case 1:
                                            {
                                                TileRefs(num103, num104).SetType(25);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;

                                        case 53:
                                            {
                                                TileRefs(num103, num104).SetType(112);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;

                                        case 109:
                                            {
                                                TileRefs(num103, num104).SetType(23);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;

                                        case 117:
                                            {
                                                TileRefs(num103, num104).SetType(25);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;

                                        case 116:
                                            {
                                                TileRefs(num103, num104).SetType(112);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,num103, num104, true);
                                                NetMessage.SendTileSquare(-1, num103, num104, 1);
                                            }
                                            break;
                                        default:
                                            break;
                                    }

                                }
                            }
                        }
                    }
                }

                //if (num96 >= 0)
                // {
                //     NetMessage.SendData(21, -1, -1, "", num96, 0f, 0f, 0f, 0);
                // }
            }
            this.Active = false;
            //Reset(whoAmI);
        }
        public static void Check3x3(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, int type)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (destroyObject)
                return;

            bool flag = false;
            int num = i;
            num = (int)(TileRefs(i, j).FrameX / 18);
            int num2 = i - num;

            if (num >= 3)
                num -= 3;

            num = i - num;
            int num3 = j + (int)(TileRefs(i, j).FrameY / 18 * -1);
            for (int k = num; k < num + 3; k++)
            {
                for (int l = num3; l < num3 + 3; l++)
                {
                    if (!TileRefs(k, l).Active || (int)TileRefs(k, l).Type != type ||
                        (int)TileRefs(k, l).FrameX != (k - num2) * 18 || (int)TileRefs(k, l).FrameY != (l - num3) * 18)
                    {
                        flag = true;
                    }
                }
            }
            if (type == 106)
            {
                for (int m = num; m < num + 3; m++)
                {
                    if (!TileRefs(m, num3 + 3).Active || !Main.tileSolid[(int)TileRefs(m, num3 + 3).Type])
                    {
                        flag = true;
                        break;
                    }
                }
            }
            else if (!TileRefs(num + 1, num3 - 1).Active || !Main.tileSolid[(int)TileRefs(num + 1, num3 - 1).Type] || Main.tileSolidTop[(int)TileRefs(num + 1, num3 - 1).Type])
            {
                flag = true;
            }
            if (flag)
            {
                destroyObject = true;
                for (int n = num; n < num + 3; n++)
                {
                    for (int num4 = num3; num4 < num3 + 3; num4++)
                    {
                        if ((int)TileRefs(n, num4).Type == type && TileRefs(n, num4).Active)
                            KillTile(TileRefs, sandbox, n, num4);
                    }
                }
                if (type == 34)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 106);
                }
                else if (type == 35)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 107);
                }
                else if (type == 36)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 108);
                }
                else if (type == 106)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 363);
                }

                destroyObject = false;

                for (int num5 = num - 1; num5 < num + 4; num5++)
                {
                    for (int num6 = num3 - 1; num6 < num3 + 4; num6++)
                    {
                        TileFrame(TileRefs, sandbox, num5, num6);
                    }
                }
            }
        }
        public static void TileFrame(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, bool resetFrame = false, bool noBreak = false)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            try
            {
                if (i > 5 && j > 5 && i < Main.maxTilesX - 5 && j < Main.maxTilesY - 5)
                {
                    if (TileRefs(i, j).Liquid > 0 && !noLiquidCheck)
                    {
                        Liquid.AddWater(TileRefs, sandbox, i, j);
                    }
                    if (TileRefs(i, j).Active)
                    {
                        if (!noBreak || !Main.tileFrameImportant[(int)TileRefs(i, j).Type] || TileRefs(i, j).Type == 4)
                        {
                            int num = (int)TileRefs(i, j).Type;
                            if (Main.tileStone[num])
                            {
                                num = 1;
                            }
                            int frameX = (int)TileRefs(i, j).FrameX;
                            int frameY = (int)TileRefs(i, j).FrameY;
                            Rectangle rectangle = new Rectangle(-1, -1, 0, 0);
                            if (Main.tileFrameImportant[(int)TileRefs(i, j).Type])
                            {
                                if (num == 4)
                                {
                                    short num2 = 0;
                                    if (TileRefs(i, j).FrameX >= 66)
                                    {
                                        num2 = 66;
                                    }
                                    int num3 = -1;
                                    int num4 = -1;
                                    int num5 = -1;
                                    int num6 = -1;
                                    int num7 = -1;
                                    int num8 = -1;
                                    int num9 = -1;

                                    if (TileRefs(i, j + 1).Active)
                                    {
                                        num3 = (int)TileRefs(i, j + 1).Type;
                                    }
                                    if (TileRefs(i - 1, j).Active)
                                    {
                                        num4 = (int)TileRefs(i - 1, j).Type;
                                    }
                                    if (TileRefs(i + 1, j).Active)
                                    {
                                        num5 = (int)TileRefs(i + 1, j).Type;
                                    }
                                    if (TileRefs(i - 1, j + 1).Active)
                                    {
                                        num6 = (int)TileRefs(i - 1, j + 1).Type;
                                    }
                                    if (TileRefs(i + 1, j + 1).Active)
                                    {
                                        num7 = (int)TileRefs(i + 1, j + 1).Type;
                                    }
                                    if (TileRefs(i - 1, j - 1).Active)
                                    {
                                        num8 = (int)TileRefs(i - 1, j - 1).Type;
                                    }
                                    if (TileRefs(i + 1, j - 1).Active)
                                    {
                                        num9 = (int)TileRefs(i + 1, j - 1).Type;
                                    }
                                    if (num3 >= 0 && Main.tileSolid[num3] && !Main.tileNoAttach[num3])
                                    {
                                        TileRefs(i, j).SetFrameX(num2);
                                    }
                                    else if ((num4 >= 0 && Main.tileSolid[num4] && !Main.tileNoAttach[num4]) || num4 == 124 || (num4 == 5 && num8 == 5 && num6 == 5))
                                    {
                                        TileRefs(i, j).SetFrameX((short)(22 + num2));
                                    }
                                    else if ((num5 >= 0 && Main.tileSolid[num5] && !Main.tileNoAttach[num5]) || num5 == 124 || (num5 == 5 && num9 == 5 && num7 == 5))
                                    {
                                        TileRefs(i, j).SetFrameX((short)(44 + num2));
                                    }
                                    else
                                    {
                                        KillTile(TileRefs, sandbox, i, j);
                                    }
                                }
                                else
                                {
                                    if (num == 136)
                                    {
                                        int num10 = -1;
                                        int num11 = -1;
                                        int num12 = -1;

                                        if (TileRefs(i, j + 1).Active)
                                        {
                                            num10 = (int)TileRefs(i, j + 1).Type;
                                        }
                                        if (TileRefs(i - 1, j).Active)
                                        {
                                            num11 = (int)TileRefs(i - 1, j).Type;
                                        }
                                        if (TileRefs(i + 1, j).Active)
                                        {
                                            num12 = (int)TileRefs(i + 1, j).Type;
                                        }
                                        if (num10 >= 0 && Main.tileSolid[num10] && !Main.tileNoAttach[num10])
                                        {
                                            TileRefs(i, j).SetFrameX(0);
                                        }
                                        else if ((num11 >= 0 && Main.tileSolid[num11] && !Main.tileNoAttach[num11]) || num11 == 124 || num11 == 5)
                                        {
                                            TileRefs(i, j).SetFrameX(18);
                                        }
                                        else if ((num12 >= 0 && Main.tileSolid[num12] && !Main.tileNoAttach[num12]) || num12 == 124 || num12 == 5)
                                        {
                                            TileRefs(i, j).SetFrameX(36);
                                        }
                                        else
                                        {
                                            KillTile(TileRefs, sandbox, i, j);
                                        }
                                    }
                                    else
                                    {
                                        if (num == 129 || num == 149)
                                        {
                                            int num13 = -1;
                                            int num14 = -1;
                                            int num15 = -1;
                                            int num16 = -1;
                                            if (TileRefs(i, j - 1).Active)
                                            {
                                                num14 = (int)TileRefs(i, j - 1).Type;
                                            }
                                            if (TileRefs(i, j + 1).Active)
                                            {
                                                num13 = (int)TileRefs(i, j + 1).Type;
                                            }
                                            if (TileRefs(i - 1, j).Active)
                                            {
                                                num15 = (int)TileRefs(i - 1, j).Type;
                                            }
                                            if (TileRefs(i + 1, j).Active)
                                            {
                                                num16 = (int)TileRefs(i + 1, j).Type;
                                            }
                                            if (num13 >= 0 && Main.tileSolid[num13] && !Main.tileSolidTop[num13])
                                            {
                                                TileRefs(i, j).SetFrameY(0);
                                            }
                                            else if (num15 >= 0 && Main.tileSolid[num15] && !Main.tileSolidTop[num15])
                                            {
                                                TileRefs(i, j).SetFrameY(54);
                                            }
                                            else if (num16 >= 0 && Main.tileSolid[num16] && !Main.tileSolidTop[num16])
                                            {
                                                TileRefs(i, j).SetFrameY(36);
                                            }
                                            else if (num14 >= 0 && Main.tileSolid[num14] && !Main.tileSolidTop[num14])
                                            {
                                                TileRefs(i, j).SetFrameY(18);
                                            }
                                            else
                                            {
                                                KillTile(TileRefs, sandbox, i, j);
                                            }
                                        }
                                        else
                                        {
                                            if (num == 3 || num == 24 || num == 61 || num == 71 || num == 73 || num == 74 || num == 110 || num == 113)
                                            {
                                                PlantCheck(TileRefs, sandbox, i, j);
                                            }
                                            else
                                            {
                                                if (num == 12 || num == 31)
                                                {
                                                    CheckOrb(TileRefs, sandbox, i, j, num);
                                                }
                                                else
                                                {
                                                    if (num == 10)
                                                    {
                                                        if (!destroyObject)
                                                        {
                                                            int frameY2 = (int)TileRefs(i, j).FrameY;
                                                            int num17 = j;
                                                            bool flag = false;
                                                            if (frameY2 == 0)
                                                            {
                                                                num17 = j;
                                                            }
                                                            if (frameY2 == 18)
                                                            {
                                                                num17 = j - 1;
                                                            }
                                                            if (frameY2 == 36)
                                                            {
                                                                num17 = j - 2;
                                                            }

                                                            if (!TileRefs(i, num17 - 1).Active || !Main.tileSolid[(int)TileRefs(i, num17 - 1).Type])
                                                            {
                                                                flag = true;
                                                            }
                                                            if (!TileRefs(i, num17 + 3).Active || !Main.tileSolid[(int)TileRefs(i, num17 + 3).Type])
                                                            {
                                                                flag = true;
                                                            }
                                                            if (!TileRefs(i, num17).Active || (int)TileRefs(i, num17).Type != num)
                                                            {
                                                                flag = true;
                                                            }
                                                            if (!TileRefs(i, num17 + 1).Active || (int)TileRefs(i, num17 + 1).Type != num)
                                                            {
                                                                flag = true;
                                                            }
                                                            if (!TileRefs(i, num17 + 2).Active || (int)TileRefs(i, num17 + 2).Type != num)
                                                            {
                                                                flag = true;
                                                            }
                                                            if (flag)
                                                            {
                                                                destroyObject = true;
                                                                KillTile(TileRefs, sandbox, i, num17);
                                                                KillTile(TileRefs, sandbox, i, num17 + 1);
                                                                KillTile(TileRefs, sandbox, i, num17 + 2);
                                                                StorePlayerItem(sandbox, i * 16, j * 16, 16, 16, 25, 1);
                                                            }
                                                            destroyObject = false;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num == 11)
                                                        {
                                                            if (!destroyObject)
                                                            {
                                                                int num18 = 0;
                                                                int num19 = i;
                                                                int num20 = j;
                                                                int frameX2 = (int)TileRefs(i, j).FrameX;
                                                                int frameY3 = (int)TileRefs(i, j).FrameY;
                                                                bool flag2 = false;
                                                                if (frameX2 == 0)
                                                                {
                                                                    num19 = i;
                                                                    num18 = 1;
                                                                }
                                                                else
                                                                {
                                                                    if (frameX2 == 18)
                                                                    {
                                                                        num19 = i - 1;
                                                                        num18 = 1;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (frameX2 == 36)
                                                                        {
                                                                            num19 = i + 1;
                                                                            num18 = -1;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (frameX2 == 54)
                                                                            {
                                                                                num19 = i;
                                                                                num18 = -1;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                                if (frameY3 == 0)
                                                                {
                                                                    num20 = j;
                                                                }
                                                                else
                                                                {
                                                                    if (frameY3 == 18)
                                                                    {
                                                                        num20 = j - 1;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (frameY3 == 36)
                                                                        {
                                                                            num20 = j - 2;
                                                                        }
                                                                    }
                                                                }

                                                                if (!TileRefs(num19, num20 - 1).Active || !Main.tileSolid[(int)TileRefs(num19, num20 - 1).Type] || !TileRefs(num19, num20 + 3).Active || !Main.tileSolid[(int)TileRefs(num19, num20 + 3).Type])
                                                                {
                                                                    flag2 = true;
                                                                    destroyObject = true;
                                                                    StorePlayerItem(sandbox, i * 16, j * 16, 16, 16, 25, 1, false, 0);
                                                                }
                                                                int num21 = num19;
                                                                if (num18 == -1)
                                                                {
                                                                    num21 = num19 - 1;
                                                                }
                                                                for (int k = num21; k < num21 + 2; k++)
                                                                {
                                                                    for (int l = num20; l < num20 + 3; l++)
                                                                    {
                                                                        if (!flag2 && (TileRefs(k, l).Type != 11 || !TileRefs(k, l).Active))
                                                                        {
                                                                            destroyObject = true;
                                                                            StorePlayerItem(sandbox, i * 16, j * 16, 16, 16, 25, 1, false, 0);
                                                                            flag2 = true;
                                                                            k = num21;
                                                                            l = num20;
                                                                        }
                                                                        if (flag2)
                                                                        {
                                                                            KillTile(TileRefs, sandbox, k, l);
                                                                        }
                                                                    }
                                                                }
                                                                destroyObject = false;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num == 34 || num == 35 || num == 36 || num == 106)
                                                            {
                                                                Check3x3(TileRefs, sandbox, i, j, (int)((byte)num));
                                                            }
                                                            else
                                                            {
                                                                if (num == 15 || num == 20)
                                                                {
                                                                    Check1x2(TileRefs, sandbox, i, j, (byte)num);
                                                                }
                                                                else
                                                                {
                                                                    if (num == 14 || num == 17 || num == 26 || num == 77 || num == 86 || num == 87 || num == 88 || num == 89 || num == 114 || num == 133)
                                                                    {
                                                                        Check3x2(TileRefs, sandbox, i, j, (int)((byte)num));
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num == 135 || num == 144 || num == 141)
                                                                        {
                                                                            Check1x1(TileRefs, sandbox, i, j, num);
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num == 16 || num == 18 || num == 29 || num == 103 || num == 134)
                                                                            {
                                                                                Check2x1(TileRefs, sandbox, i, j, (byte)num);
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num == 13 || num == 33 || num == 50 || num == 78)
                                                                                {
                                                                                    CheckOnTable1x1(TileRefs, sandbox, i, j, (int)((byte)num));
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num == 21)
                                                                                    {
                                                                                        CheckChest(TileRefs, sandbox, i, j, (int)((byte)num));
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num == 128)
                                                                                        {
                                                                                            CheckMan(TileRefs, sandbox, i, j);
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num == 27)
                                                                                            {
                                                                                                CheckSunflower(TileRefs, sandbox, i, j, 27);
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num == 28)
                                                                                                {
                                                                                                    CheckPot(TileRefs, sandbox, i, j, 28);
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (num == 132 || num == 138 || num == 142 || num == 143)
                                                                                                    {
                                                                                                        Check2x2(TileRefs, sandbox, i, j, num);
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        if (num == 91)
                                                                                                        {
                                                                                                            CheckBanner(TileRefs, sandbox, i, j, (byte)num);
                                                                                                        }
                                                                                                        else
                                                                                                        {
                                                                                                            if (num == 139)
                                                                                                            {
                                                                                                                CheckMB(TileRefs, sandbox, i, j, (int)((byte)num));
                                                                                                            }
                                                                                                            else
                                                                                                            {
                                                                                                                if (num == 92 || num == 93)
                                                                                                                {
                                                                                                                    Check1xX(TileRefs, sandbox, i, j, (byte)num);
                                                                                                                }
                                                                                                                else
                                                                                                                {
                                                                                                                    if (num == 104 || num == 105)
                                                                                                                    {
                                                                                                                        Check2xX(TileRefs, sandbox, i, j, (byte)num);
                                                                                                                    }
                                                                                                                    else
                                                                                                                    {
                                                                                                                        if (num == 101 || num == 102)
                                                                                                                        {
                                                                                                                            Check3x4(TileRefs, sandbox, i, j, (int)((byte)num));
                                                                                                                        }
                                                                                                                        else
                                                                                                                        {
                                                                                                                            if (num == 42)
                                                                                                                            {
                                                                                                                                Check1x2Top(TileRefs, sandbox, i, j, (byte)num);
                                                                                                                            }
                                                                                                                            else
                                                                                                                            {
                                                                                                                                if (num == 55 || num == 85)
                                                                                                                                {
                                                                                                                                    CheckSign(TileRefs, sandbox, i, j, num);
                                                                                                                                }
                                                                                                                                else
                                                                                                                                {
                                                                                                                                    if (num == 79 || num == 90)
                                                                                                                                    {
                                                                                                                                        Check4x2(TileRefs, sandbox, i, j, num);
                                                                                                                                    }
                                                                                                                                    else
                                                                                                                                    {
                                                                                                                                        if (num == 85 || num == 94 || num == 95 || num == 96 || num == 97 || num == 98 || num == 99 || num == 100 || num == 125 || num == 126)
                                                                                                                                        {
                                                                                                                                            Check2x2(TileRefs, sandbox, i, j, num);
                                                                                                                                        }
                                                                                                                                        else
                                                                                                                                        {
                                                                                                                                            if (num == 81)
                                                                                                                                            {
                                                                                                                                                int num22 = -1;
                                                                                                                                                int num23 = -1;
                                                                                                                                                int num24 = -1;
                                                                                                                                                int num25 = -1;
                                                                                                                                                if (TileRefs(i, j - 1).Active)
                                                                                                                                                {
                                                                                                                                                    num23 = (int)TileRefs(i, j - 1).Type;
                                                                                                                                                }
                                                                                                                                                if (TileRefs(i, j + 1).Active)
                                                                                                                                                {
                                                                                                                                                    num22 = (int)TileRefs(i, j + 1).Type;
                                                                                                                                                }
                                                                                                                                                if (TileRefs(i - 1, j).Active)
                                                                                                                                                {
                                                                                                                                                    num24 = (int)TileRefs(i - 1, j).Type;
                                                                                                                                                }
                                                                                                                                                if (TileRefs(i + 1, j).Active)
                                                                                                                                                {
                                                                                                                                                    num25 = (int)TileRefs(i + 1, j).Type;
                                                                                                                                                }
                                                                                                                                                if (num24 != -1 || num23 != -1 || num25 != -1)
                                                                                                                                                {
                                                                                                                                                    KillTile(TileRefs, sandbox, i, j);
                                                                                                                                                }
                                                                                                                                                else
                                                                                                                                                {
                                                                                                                                                    if (num22 < 0 || !Main.tileSolid[num22])
                                                                                                                                                    {
                                                                                                                                                        KillTile(TileRefs, sandbox, i, j);
                                                                                                                                                    }
                                                                                                                                                }
                                                                                                                                            }
                                                                                                                                            else
                                                                                                                                            {
                                                                                                                                                if (Main.tileAlch[num])
                                                                                                                                                {
                                                                                                                                                    CheckAlch(TileRefs, sandbox, i, j);
                                                                                                                                                }
                                                                                                                                                else
                                                                                                                                                {
                                                                                                                                                    if (num == 72)
                                                                                                                                                    {
                                                                                                                                                        int num26 = -1;
                                                                                                                                                        int num27 = -1;
                                                                                                                                                        if (TileRefs(i, j - 1).Active)
                                                                                                                                                        {
                                                                                                                                                            num27 = (int)TileRefs(i, j - 1).Type;
                                                                                                                                                        }
                                                                                                                                                        if (TileRefs(i, j + 1).Active)
                                                                                                                                                        {
                                                                                                                                                            num26 = (int)TileRefs(i, j + 1).Type;
                                                                                                                                                        }
                                                                                                                                                        if (num26 != num && num26 != 70)
                                                                                                                                                        {
                                                                                                                                                            KillTile(TileRefs, sandbox, i, j);
                                                                                                                                                        }
                                                                                                                                                        else
                                                                                                                                                        {
                                                                                                                                                            if (num27 != num && TileRefs(i, j).FrameX == 0)
                                                                                                                                                            {
                                                                                                                                                                TileRefs(i, j).SetFrameNumber((byte)genRand.Next(3));
                                                                                                                                                                if (TileRefs(i, j).FrameNumber == 0)
                                                                                                                                                                {
                                                                                                                                                                    TileRefs(i, j).SetFrameX(18);
                                                                                                                                                                    TileRefs(i, j).SetFrameY(0);
                                                                                                                                                                }
                                                                                                                                                                if (TileRefs(i, j).FrameNumber == 1)
                                                                                                                                                                {
                                                                                                                                                                    TileRefs(i, j).SetFrameX(18);
                                                                                                                                                                    TileRefs(i, j).SetFrameY(18);
                                                                                                                                                                }
                                                                                                                                                                if (TileRefs(i, j).FrameNumber == 2)
                                                                                                                                                                {
                                                                                                                                                                    TileRefs(i, j).SetFrameX(18);
                                                                                                                                                                    TileRefs(i, j).SetFrameY(36);
                                                                                                                                                                }
                                                                                                                                                            }
                                                                                                                                                        }
                                                                                                                                                    }
                                                                                                                                                    else
                                                                                                                                                    {
                                                                                                                                                        if (num == 5)
                                                                                                                                                        {
                                                                                                                                                            CheckTree(TileRefs, sandbox, i, j);
                                                                                                                                                        }
                                                                                                                                                    }
                                                                                                                                                }
                                                                                                                                            }
                                                                                                                                        }
                                                                                                                                    }
                                                                                                                                }
                                                                                                                            }
                                                                                                                        }
                                                                                                                    }
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                int num28 = -1;
                                int num29 = -1;
                                int num30 = -1;
                                int num31 = -1;
                                int num32 = -1;
                                int num33 = -1;
                                int num34 = -1;
                                int num35 = -1;
                                if (TileRefs(i - 1, j).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i - 1, j).Type])
                                    {
                                        num31 = 1;
                                    }
                                    else
                                    {
                                        num31 = (int)TileRefs(i - 1, j).Type;
                                    }
                                }
                                if (TileRefs(i + 1, j).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i + 1, j).Type])
                                    {
                                        num32 = 1;
                                    }
                                    else
                                    {
                                        num32 = (int)TileRefs(i + 1, j).Type;
                                    }
                                }
                                if (TileRefs(i, j - 1).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i, j - 1).Type])
                                    {
                                        num29 = 1;
                                    }
                                    else
                                    {
                                        num29 = (int)TileRefs(i, j - 1).Type;
                                    }
                                }
                                if (TileRefs(i, j + 1).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i, j + 1).Type])
                                    {
                                        num34 = 1;
                                    }
                                    else
                                    {
                                        num34 = (int)TileRefs(i, j + 1).Type;
                                    }
                                }
                                if (TileRefs(i - 1, j - 1).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i - 1, j - 1).Type])
                                    {
                                        num28 = 1;
                                    }
                                    else
                                    {
                                        num28 = (int)TileRefs(i - 1, j - 1).Type;
                                    }
                                }
                                if (TileRefs(i + 1, j - 1).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i + 1, j - 1).Type])
                                    {
                                        num30 = 1;
                                    }
                                    else
                                    {
                                        num30 = (int)TileRefs(i + 1, j - 1).Type;
                                    }
                                }
                                if (TileRefs(i - 1, j + 1).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i - 1, j + 1).Type])
                                    {
                                        num33 = 1;
                                    }
                                    else
                                    {
                                        num33 = (int)TileRefs(i - 1, j + 1).Type;
                                    }
                                }
                                if (TileRefs(i + 1, j + 1).Active)
                                {
                                    if (Main.tileStone[(int)TileRefs(i + 1, j + 1).Type])
                                    {
                                        num35 = 1;
                                    }
                                    else
                                    {
                                        num35 = (int)TileRefs(i + 1, j + 1).Type;
                                    }
                                }
                                if (!Main.tileSolid[num])
                                {
                                    if (num == 49)
                                    {
                                        CheckOnTable1x1(TileRefs, sandbox, i, j, (int)((byte)num));
                                        return;
                                    }
                                    if (num == 80)
                                    {
                                        CactusFrame(TileRefs, sandbox, i, j);
                                        return;
                                    }
                                }
                                else
                                {
                                    if (num == 19)
                                    {
                                        if (num32 >= 0 && !Main.tileSolid[num32])
                                        {
                                            num32 = -1;
                                        }
                                        if (num31 >= 0 && !Main.tileSolid[num31])
                                        {
                                            num31 = -1;
                                        }
                                        if (num31 == num && num32 == num)
                                        {
                                            if (TileRefs(i, j).FrameNumber == 0)
                                            {
                                                rectangle.X = 0;
                                                rectangle.Y = 0;
                                            }
                                            else
                                            {
                                                if (TileRefs(i, j).FrameNumber == 1)
                                                {
                                                    rectangle.X = 0;
                                                    rectangle.Y = 18;
                                                }
                                                else
                                                {
                                                    rectangle.X = 0;
                                                    rectangle.Y = 36;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num31 == num && num32 == -1)
                                            {
                                                if (TileRefs(i, j).FrameNumber == 0)
                                                {
                                                    rectangle.X = 18;
                                                    rectangle.Y = 0;
                                                }
                                                else
                                                {
                                                    if (TileRefs(i, j).FrameNumber == 1)
                                                    {
                                                        rectangle.X = 18;
                                                        rectangle.Y = 18;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 18;
                                                        rectangle.Y = 36;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num31 == -1 && num32 == num)
                                                {
                                                    if (TileRefs(i, j).FrameNumber == 0)
                                                    {
                                                        rectangle.X = 36;
                                                        rectangle.Y = 0;
                                                    }
                                                    else
                                                    {
                                                        if (TileRefs(i, j).FrameNumber == 1)
                                                        {
                                                            rectangle.X = 36;
                                                            rectangle.Y = 18;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 36;
                                                            rectangle.Y = 36;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num31 != num && num32 == num)
                                                    {
                                                        if (TileRefs(i, j).FrameNumber == 0)
                                                        {
                                                            rectangle.X = 54;
                                                            rectangle.Y = 0;
                                                        }
                                                        else
                                                        {
                                                            if (TileRefs(i, j).FrameNumber == 1)
                                                            {
                                                                rectangle.X = 54;
                                                                rectangle.Y = 18;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 54;
                                                                rectangle.Y = 36;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num31 == num && num32 != num)
                                                        {
                                                            if (TileRefs(i, j).FrameNumber == 0)
                                                            {
                                                                rectangle.X = 72;
                                                                rectangle.Y = 0;
                                                            }
                                                            else
                                                            {
                                                                if (TileRefs(i, j).FrameNumber == 1)
                                                                {
                                                                    rectangle.X = 72;
                                                                    rectangle.Y = 18;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 72;
                                                                    rectangle.Y = 36;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num31 != num && num31 != -1 && num32 == -1)
                                                            {
                                                                if (TileRefs(i, j).FrameNumber == 0)
                                                                {
                                                                    rectangle.X = 108;
                                                                    rectangle.Y = 0;
                                                                }
                                                                else
                                                                {
                                                                    if (TileRefs(i, j).FrameNumber == 1)
                                                                    {
                                                                        rectangle.X = 108;
                                                                        rectangle.Y = 18;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 108;
                                                                        rectangle.Y = 36;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num31 == -1 && num32 != num && num32 != -1)
                                                                {
                                                                    if (TileRefs(i, j).FrameNumber == 0)
                                                                    {
                                                                        rectangle.X = 126;
                                                                        rectangle.Y = 0;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (TileRefs(i, j).FrameNumber == 1)
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 18;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 36;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (TileRefs(i, j).FrameNumber == 0)
                                                                    {
                                                                        rectangle.X = 90;
                                                                        rectangle.Y = 0;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (TileRefs(i, j).FrameNumber == 1)
                                                                        {
                                                                            rectangle.X = 90;
                                                                            rectangle.Y = 18;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 90;
                                                                            rectangle.Y = 36;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                mergeUp = false;
                                mergeDown = false;
                                mergeLeft = false;
                                mergeRight = false;
                                int num36 = 0;
                                if (resetFrame)
                                {
                                    num36 = genRand.Next(0, 3);
                                    TileRefs(i, j).SetFrameNumber((byte)num36);
                                }
                                else
                                {
                                    num36 = (int)TileRefs(i, j).FrameNumber;
                                }
                                if (num == 0)
                                {
                                    if (num29 >= 0 && Main.tileMergeDirt[num29])
                                    {
                                        TileFrame(TileRefs, sandbox, i, j - 1, false, false);
                                        if (mergeDown)
                                        {
                                            num29 = num;
                                        }
                                    }
                                    if (num34 >= 0 && Main.tileMergeDirt[num34])
                                    {
                                        TileFrame(TileRefs, sandbox, i, j + 1, false, false);
                                        if (mergeUp)
                                        {
                                            num34 = num;
                                        }
                                    }
                                    if (num31 >= 0 && Main.tileMergeDirt[num31])
                                    {
                                        TileFrame(TileRefs, sandbox, i - 1, j, false, false);
                                        if (mergeRight)
                                        {
                                            num31 = num;
                                        }
                                    }
                                    if (num32 >= 0 && Main.tileMergeDirt[num32])
                                    {
                                        TileFrame(TileRefs, sandbox, i + 1, j, false, false);
                                        if (mergeLeft)
                                        {
                                            num32 = num;
                                        }
                                    }
                                    if (num29 == 2 || num29 == 23 || num29 == 109)
                                    {
                                        num29 = num;
                                    }
                                    if (num34 == 2 || num34 == 23 || num34 == 109)
                                    {
                                        num34 = num;
                                    }
                                    if (num31 == 2 || num31 == 23 || num31 == 109)
                                    {
                                        num31 = num;
                                    }
                                    if (num32 == 2 || num32 == 23 || num32 == 109)
                                    {
                                        num32 = num;
                                    }
                                    if (num28 >= 0 && Main.tileMergeDirt[num28])
                                    {
                                        num28 = num;
                                    }
                                    else
                                    {
                                        if (num28 == 2 || num28 == 23 || num28 == 109)
                                        {
                                            num28 = num;
                                        }
                                    }
                                    if (num30 >= 0 && Main.tileMergeDirt[num30])
                                    {
                                        num30 = num;
                                    }
                                    else
                                    {
                                        if (num30 == 2 || num30 == 23 || num30 == 109)
                                        {
                                            num30 = num;
                                        }
                                    }
                                    if (num33 >= 0 && Main.tileMergeDirt[num33])
                                    {
                                        num33 = num;
                                    }
                                    else
                                    {
                                        if (num33 == 2 || num33 == 23 || num30 == 109)
                                        {
                                            num33 = num;
                                        }
                                    }
                                    if (num35 >= 0 && Main.tileMergeDirt[num35])
                                    {
                                        num35 = num;
                                    }
                                    else
                                    {
                                        if (num35 == 2 || num35 == 23 || num35 == 109)
                                        {
                                            num35 = num;
                                        }
                                    }
                                    if ((double)j < Main.rockLayer)
                                    {
                                        if (num29 == 59)
                                        {
                                            num29 = -2;
                                        }
                                        if (num34 == 59)
                                        {
                                            num34 = -2;
                                        }
                                        if (num31 == 59)
                                        {
                                            num31 = -2;
                                        }
                                        if (num32 == 59)
                                        {
                                            num32 = -2;
                                        }
                                        if (num28 == 59)
                                        {
                                            num28 = -2;
                                        }
                                        if (num30 == 59)
                                        {
                                            num30 = -2;
                                        }
                                        if (num33 == 59)
                                        {
                                            num33 = -2;
                                        }
                                        if (num35 == 59)
                                        {
                                            num35 = -2;
                                        }
                                    }
                                }
                                else
                                {
                                    if (Main.tileMergeDirt[num])
                                    {
                                        if (num29 == 0)
                                        {
                                            num29 = -2;
                                        }
                                        if (num34 == 0)
                                        {
                                            num34 = -2;
                                        }
                                        if (num31 == 0)
                                        {
                                            num31 = -2;
                                        }
                                        if (num32 == 0)
                                        {
                                            num32 = -2;
                                        }
                                        if (num28 == 0)
                                        {
                                            num28 = -2;
                                        }
                                        if (num30 == 0)
                                        {
                                            num30 = -2;
                                        }
                                        if (num33 == 0)
                                        {
                                            num33 = -2;
                                        }
                                        if (num35 == 0)
                                        {
                                            num35 = -2;
                                        }
                                        if (num == 1)
                                        {
                                            if ((double)j > Main.rockLayer)
                                            {
                                                if (num29 == 59)
                                                {
                                                    TileFrame(TileRefs, sandbox, i, j - 1, false, false);
                                                    if (mergeDown)
                                                    {
                                                        num29 = num;
                                                    }
                                                }
                                                if (num34 == 59)
                                                {
                                                    TileFrame(TileRefs, sandbox, i, j + 1, false, false);
                                                    if (mergeUp)
                                                    {
                                                        num34 = num;
                                                    }
                                                }
                                                if (num31 == 59)
                                                {
                                                    TileFrame(TileRefs, sandbox, i - 1, j, false, false);
                                                    if (mergeRight)
                                                    {
                                                        num31 = num;
                                                    }
                                                }
                                                if (num32 == 59)
                                                {
                                                    TileFrame(TileRefs, sandbox, i + 1, j, false, false);
                                                    if (mergeLeft)
                                                    {
                                                        num32 = num;
                                                    }
                                                }
                                                if (num28 == 59)
                                                {
                                                    num28 = num;
                                                }
                                                if (num30 == 59)
                                                {
                                                    num30 = num;
                                                }
                                                if (num33 == 59)
                                                {
                                                    num33 = num;
                                                }
                                                if (num35 == 59)
                                                {
                                                    num35 = num;
                                                }
                                            }
                                            if (num29 == 57)
                                            {
                                                TileFrame(TileRefs, sandbox, i, j - 1, false, false);
                                                if (mergeDown)
                                                {
                                                    num29 = num;
                                                }
                                            }
                                            if (num34 == 57)
                                            {
                                                TileFrame(TileRefs, sandbox, i, j + 1, false, false);
                                                if (mergeUp)
                                                {
                                                    num34 = num;
                                                }
                                            }
                                            if (num31 == 57)
                                            {
                                                TileFrame(TileRefs, sandbox, i - 1, j, false, false);
                                                if (mergeRight)
                                                {
                                                    num31 = num;
                                                }
                                            }
                                            if (num32 == 57)
                                            {
                                                TileFrame(TileRefs, sandbox, i + 1, j, false, false);
                                                if (mergeLeft)
                                                {
                                                    num32 = num;
                                                }
                                            }
                                            if (num28 == 57)
                                            {
                                                num28 = num;
                                            }
                                            if (num30 == 57)
                                            {
                                                num30 = num;
                                            }
                                            if (num33 == 57)
                                            {
                                                num33 = num;
                                            }
                                            if (num35 == 57)
                                            {
                                                num35 = num;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num == 58 || num == 76 || num == 75)
                                        {
                                            if (num29 == 57)
                                            {
                                                num29 = -2;
                                            }
                                            if (num34 == 57)
                                            {
                                                num34 = -2;
                                            }
                                            if (num31 == 57)
                                            {
                                                num31 = -2;
                                            }
                                            if (num32 == 57)
                                            {
                                                num32 = -2;
                                            }
                                            if (num28 == 57)
                                            {
                                                num28 = -2;
                                            }
                                            if (num30 == 57)
                                            {
                                                num30 = -2;
                                            }
                                            if (num33 == 57)
                                            {
                                                num33 = -2;
                                            }
                                            if (num35 == 57)
                                            {
                                                num35 = -2;
                                            }
                                        }
                                        else
                                        {
                                            if (num == 59)
                                            {
                                                if ((double)j > Main.rockLayer)
                                                {
                                                    if (num29 == 1)
                                                    {
                                                        num29 = -2;
                                                    }
                                                    if (num34 == 1)
                                                    {
                                                        num34 = -2;
                                                    }
                                                    if (num31 == 1)
                                                    {
                                                        num31 = -2;
                                                    }
                                                    if (num32 == 1)
                                                    {
                                                        num32 = -2;
                                                    }
                                                    if (num28 == 1)
                                                    {
                                                        num28 = -2;
                                                    }
                                                    if (num30 == 1)
                                                    {
                                                        num30 = -2;
                                                    }
                                                    if (num33 == 1)
                                                    {
                                                        num33 = -2;
                                                    }
                                                    if (num35 == 1)
                                                    {
                                                        num35 = -2;
                                                    }
                                                }
                                                if (num29 == 60)
                                                {
                                                    num29 = num;
                                                }
                                                if (num34 == 60)
                                                {
                                                    num34 = num;
                                                }
                                                if (num31 == 60)
                                                {
                                                    num31 = num;
                                                }
                                                if (num32 == 60)
                                                {
                                                    num32 = num;
                                                }
                                                if (num28 == 60)
                                                {
                                                    num28 = num;
                                                }
                                                if (num30 == 60)
                                                {
                                                    num30 = num;
                                                }
                                                if (num33 == 60)
                                                {
                                                    num33 = num;
                                                }
                                                if (num35 == 60)
                                                {
                                                    num35 = num;
                                                }
                                                if (num29 == 70)
                                                {
                                                    num29 = num;
                                                }
                                                if (num34 == 70)
                                                {
                                                    num34 = num;
                                                }
                                                if (num31 == 70)
                                                {
                                                    num31 = num;
                                                }
                                                if (num32 == 70)
                                                {
                                                    num32 = num;
                                                }
                                                if (num28 == 70)
                                                {
                                                    num28 = num;
                                                }
                                                if (num30 == 70)
                                                {
                                                    num30 = num;
                                                }
                                                if (num33 == 70)
                                                {
                                                    num33 = num;
                                                }
                                                if (num35 == 70)
                                                {
                                                    num35 = num;
                                                }
                                                if ((double)j < Main.rockLayer)
                                                {
                                                    if (num29 == 0)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i, j - 1, false, false);
                                                        if (mergeDown)
                                                        {
                                                            num29 = num;
                                                        }
                                                    }
                                                    if (num34 == 0)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i, j + 1, false, false);
                                                        if (mergeUp)
                                                        {
                                                            num34 = num;
                                                        }
                                                    }
                                                    if (num31 == 0)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i - 1, j, false, false);
                                                        if (mergeRight)
                                                        {
                                                            num31 = num;
                                                        }
                                                    }
                                                    if (num32 == 0)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i + 1, j, false, false);
                                                        if (mergeLeft)
                                                        {
                                                            num32 = num;
                                                        }
                                                    }
                                                    if (num28 == 0)
                                                    {
                                                        num28 = num;
                                                    }
                                                    if (num30 == 0)
                                                    {
                                                        num30 = num;
                                                    }
                                                    if (num33 == 0)
                                                    {
                                                        num33 = num;
                                                    }
                                                    if (num35 == 0)
                                                    {
                                                        num35 = num;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num == 57)
                                                {
                                                    if (num29 == 1)
                                                    {
                                                        num29 = -2;
                                                    }
                                                    if (num34 == 1)
                                                    {
                                                        num34 = -2;
                                                    }
                                                    if (num31 == 1)
                                                    {
                                                        num31 = -2;
                                                    }
                                                    if (num32 == 1)
                                                    {
                                                        num32 = -2;
                                                    }
                                                    if (num28 == 1)
                                                    {
                                                        num28 = -2;
                                                    }
                                                    if (num30 == 1)
                                                    {
                                                        num30 = -2;
                                                    }
                                                    if (num33 == 1)
                                                    {
                                                        num33 = -2;
                                                    }
                                                    if (num35 == 1)
                                                    {
                                                        num35 = -2;
                                                    }
                                                    if (num29 == 58 || num29 == 76 || num29 == 75)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i, j - 1, false, false);
                                                        if (mergeDown)
                                                        {
                                                            num29 = num;
                                                        }
                                                    }
                                                    if (num34 == 58 || num34 == 76 || num34 == 75)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i, j + 1, false, false);
                                                        if (mergeUp)
                                                        {
                                                            num34 = num;
                                                        }
                                                    }
                                                    if (num31 == 58 || num31 == 76 || num31 == 75)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i - 1, j, false, false);
                                                        if (mergeRight)
                                                        {
                                                            num31 = num;
                                                        }
                                                    }
                                                    if (num32 == 58 || num32 == 76 || num32 == 75)
                                                    {
                                                        TileFrame(TileRefs, sandbox, i + 1, j, false, false);
                                                        if (mergeLeft)
                                                        {
                                                            num32 = num;
                                                        }
                                                    }
                                                    if (num28 == 58 || num28 == 76 || num28 == 75)
                                                    {
                                                        num28 = num;
                                                    }
                                                    if (num30 == 58 || num30 == 76 || num30 == 75)
                                                    {
                                                        num30 = num;
                                                    }
                                                    if (num33 == 58 || num33 == 76 || num33 == 75)
                                                    {
                                                        num33 = num;
                                                    }
                                                    if (num35 == 58 || num35 == 76 || num35 == 75)
                                                    {
                                                        num35 = num;
                                                    }
                                                }
                                                else
                                                {
                                                    if (num == 32)
                                                    {
                                                        if (num34 == 23)
                                                        {
                                                            num34 = num;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num == 69)
                                                        {
                                                            if (num34 == 60)
                                                            {
                                                                num34 = num;
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num == 51)
                                                            {
                                                                if (num29 > -1 && !Main.tileNoAttach[num29])
                                                                {
                                                                    num29 = num;
                                                                }
                                                                if (num34 > -1 && !Main.tileNoAttach[num34])
                                                                {
                                                                    num34 = num;
                                                                }
                                                                if (num31 > -1 && !Main.tileNoAttach[num31])
                                                                {
                                                                    num31 = num;
                                                                }
                                                                if (num32 > -1 && !Main.tileNoAttach[num32])
                                                                {
                                                                    num32 = num;
                                                                }
                                                                if (num28 > -1 && !Main.tileNoAttach[num28])
                                                                {
                                                                    num28 = num;
                                                                }
                                                                if (num30 > -1 && !Main.tileNoAttach[num30])
                                                                {
                                                                    num30 = num;
                                                                }
                                                                if (num33 > -1 && !Main.tileNoAttach[num33])
                                                                {
                                                                    num33 = num;
                                                                }
                                                                if (num35 > -1 && !Main.tileNoAttach[num35])
                                                                {
                                                                    num35 = num;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                bool flag3 = false;
                                if (num == 2 || num == 23 || num == 60 || num == 70 || num == 109)
                                {
                                    flag3 = true;
                                    if (num29 > -1 && !Main.tileSolid[num29] && num29 != num)
                                    {
                                        num29 = -1;
                                    }
                                    if (num34 > -1 && !Main.tileSolid[num34] && num34 != num)
                                    {
                                        num34 = -1;
                                    }
                                    if (num31 > -1 && !Main.tileSolid[num31] && num31 != num)
                                    {
                                        num31 = -1;
                                    }
                                    if (num32 > -1 && !Main.tileSolid[num32] && num32 != num)
                                    {
                                        num32 = -1;
                                    }
                                    if (num28 > -1 && !Main.tileSolid[num28] && num28 != num)
                                    {
                                        num28 = -1;
                                    }
                                    if (num30 > -1 && !Main.tileSolid[num30] && num30 != num)
                                    {
                                        num30 = -1;
                                    }
                                    if (num33 > -1 && !Main.tileSolid[num33] && num33 != num)
                                    {
                                        num33 = -1;
                                    }
                                    if (num35 > -1 && !Main.tileSolid[num35] && num35 != num)
                                    {
                                        num35 = -1;
                                    }
                                    int num37 = 0;
                                    if (num == 60 || num == 70)
                                    {
                                        num37 = 59;
                                    }
                                    else
                                    {
                                        if (num == 2)
                                        {
                                            if (num29 == 23)
                                            {
                                                num29 = num37;
                                            }
                                            if (num34 == 23)
                                            {
                                                num34 = num37;
                                            }
                                            if (num31 == 23)
                                            {
                                                num31 = num37;
                                            }
                                            if (num32 == 23)
                                            {
                                                num32 = num37;
                                            }
                                            if (num28 == 23)
                                            {
                                                num28 = num37;
                                            }
                                            if (num30 == 23)
                                            {
                                                num30 = num37;
                                            }
                                            if (num33 == 23)
                                            {
                                                num33 = num37;
                                            }
                                            if (num35 == 23)
                                            {
                                                num35 = num37;
                                            }
                                        }
                                        else
                                        {
                                            if (num == 23)
                                            {
                                                if (num29 == 2)
                                                {
                                                    num29 = num37;
                                                }
                                                if (num34 == 2)
                                                {
                                                    num34 = num37;
                                                }
                                                if (num31 == 2)
                                                {
                                                    num31 = num37;
                                                }
                                                if (num32 == 2)
                                                {
                                                    num32 = num37;
                                                }
                                                if (num28 == 2)
                                                {
                                                    num28 = num37;
                                                }
                                                if (num30 == 2)
                                                {
                                                    num30 = num37;
                                                }
                                                if (num33 == 2)
                                                {
                                                    num33 = num37;
                                                }
                                                if (num35 == 2)
                                                {
                                                    num35 = num37;
                                                }
                                            }
                                        }
                                    }
                                    if (num29 != num && num29 != num37 && (num34 == num || num34 == num37))
                                    {
                                        if (num31 == num37 && num32 == num)
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 0;
                                                rectangle.Y = 198;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 18;
                                                    rectangle.Y = 198;
                                                }
                                                else
                                                {
                                                    rectangle.X = 36;
                                                    rectangle.Y = 198;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num31 == num && num32 == num37)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 54;
                                                    rectangle.Y = 198;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 72;
                                                        rectangle.Y = 198;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 90;
                                                        rectangle.Y = 198;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num34 != num && num34 != num37 && (num29 == num || num29 == num37))
                                        {
                                            if (num31 == num37 && num32 == num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 0;
                                                    rectangle.Y = 216;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 18;
                                                        rectangle.Y = 216;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 36;
                                                        rectangle.Y = 216;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num31 == num && num32 == num37)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 54;
                                                        rectangle.Y = 216;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 216;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 216;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num31 != num && num31 != num37 && (num32 == num || num32 == num37))
                                            {
                                                if (num29 == num37 && num34 == num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 72;
                                                        rectangle.Y = 144;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 162;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 180;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num34 == num && num32 == num29)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 90;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 72;
                                                                rectangle.Y = 108;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 72;
                                                                rectangle.Y = 126;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num32 != num && num32 != num37 && (num31 == num || num31 == num37))
                                                {
                                                    if (num29 == num37 && num34 == num)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 144;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 90;
                                                                rectangle.Y = 162;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 90;
                                                                rectangle.Y = 180;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num34 == num && num32 == num29)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 90;
                                                                rectangle.Y = 90;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 90;
                                                                    rectangle.Y = 108;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 90;
                                                                    rectangle.Y = 126;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num29 == num && num34 == num && num31 == num && num32 == num)
                                                    {
                                                        if (num28 != num && num30 != num && num33 != num && num35 != num)
                                                        {
                                                            if (num35 == num37)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 108;
                                                                    rectangle.Y = 324;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 126;
                                                                        rectangle.Y = 324;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 144;
                                                                        rectangle.Y = 324;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num30 == num37)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 108;
                                                                        rectangle.Y = 342;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 342;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 144;
                                                                            rectangle.Y = 342;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (num33 == num37)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 108;
                                                                            rectangle.Y = 360;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 126;
                                                                                rectangle.Y = 360;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 144;
                                                                                rectangle.Y = 360;
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num28 == num37)
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 108;
                                                                                rectangle.Y = 378;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 126;
                                                                                    rectangle.Y = 378;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 144;
                                                                                    rectangle.Y = 378;
                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 144;
                                                                                rectangle.Y = 234;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 198;
                                                                                    rectangle.Y = 234;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 252;
                                                                                    rectangle.Y = 234;
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num28 != num && num35 != num)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 36;
                                                                    rectangle.Y = 306;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 54;
                                                                        rectangle.Y = 306;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 72;
                                                                        rectangle.Y = 306;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num30 != num && num33 != num)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 90;
                                                                        rectangle.Y = 306;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 108;
                                                                            rectangle.Y = 306;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 306;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (num28 != num && num30 == num && num33 == num && num35 == num)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 54;
                                                                            rectangle.Y = 108;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 144;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 180;
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num28 == num && num30 != num && num33 == num && num35 == num)
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 36;
                                                                                rectangle.Y = 108;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 36;
                                                                                    rectangle.Y = 144;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 36;
                                                                                    rectangle.Y = 180;
                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num28 == num && num30 == num && num33 != num && num35 == num)
                                                                            {
                                                                                if (num36 == 0)
                                                                                {
                                                                                    rectangle.X = 54;
                                                                                    rectangle.Y = 90;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num36 == 1)
                                                                                    {
                                                                                        rectangle.X = 54;
                                                                                        rectangle.Y = 126;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        rectangle.X = 54;
                                                                                        rectangle.Y = 162;
                                                                                    }
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num28 == num && num30 == num && num33 == num && num35 != num)
                                                                                {
                                                                                    if (num36 == 0)
                                                                                    {
                                                                                        rectangle.X = 36;
                                                                                        rectangle.Y = 90;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num36 == 1)
                                                                                        {
                                                                                            rectangle.X = 36;
                                                                                            rectangle.Y = 126;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            rectangle.X = 36;
                                                                                            rectangle.Y = 162;
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num29 == num && num34 == num37 && num31 == num && num32 == num && num28 == -1 && num30 == -1)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 108;
                                                                rectangle.Y = 18;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 126;
                                                                    rectangle.Y = 18;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 144;
                                                                    rectangle.Y = 18;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num29 == num37 && num34 == num && num31 == num && num32 == num && num33 == -1 && num35 == -1)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 108;
                                                                    rectangle.Y = 36;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 126;
                                                                        rectangle.Y = 36;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 144;
                                                                        rectangle.Y = 36;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num29 == num && num34 == num && num31 == num37 && num32 == num && num30 == -1 && num35 == -1)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 198;
                                                                        rectangle.Y = 0;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 198;
                                                                            rectangle.Y = 18;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 198;
                                                                            rectangle.Y = 36;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (num29 == num && num34 == num && num31 == num && num32 == num37 && num28 == -1 && num33 == -1)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 180;
                                                                            rectangle.Y = 0;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 180;
                                                                                rectangle.Y = 18;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 180;
                                                                                rectangle.Y = 36;
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num29 == num && num34 == num37 && num31 == num && num32 == num)
                                                                        {
                                                                            if (num30 != -1)
                                                                            {
                                                                                if (num36 == 0)
                                                                                {
                                                                                    rectangle.X = 54;
                                                                                    rectangle.Y = 108;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num36 == 1)
                                                                                    {
                                                                                        rectangle.X = 54;
                                                                                        rectangle.Y = 144;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        rectangle.X = 54;
                                                                                        rectangle.Y = 180;
                                                                                    }
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num28 != -1)
                                                                                {
                                                                                    if (num36 == 0)
                                                                                    {
                                                                                        rectangle.X = 36;
                                                                                        rectangle.Y = 108;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num36 == 1)
                                                                                        {
                                                                                            rectangle.X = 36;
                                                                                            rectangle.Y = 144;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            rectangle.X = 36;
                                                                                            rectangle.Y = 180;
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num29 == num37 && num34 == num && num31 == num && num32 == num)
                                                                            {
                                                                                if (num35 != -1)
                                                                                {
                                                                                    if (num36 == 0)
                                                                                    {
                                                                                        rectangle.X = 54;
                                                                                        rectangle.Y = 90;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num36 == 1)
                                                                                        {
                                                                                            rectangle.X = 54;
                                                                                            rectangle.Y = 126;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            rectangle.X = 54;
                                                                                            rectangle.Y = 162;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num33 != -1)
                                                                                    {
                                                                                        if (num36 == 0)
                                                                                        {
                                                                                            rectangle.X = 36;
                                                                                            rectangle.Y = 90;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num36 == 1)
                                                                                            {
                                                                                                rectangle.X = 36;
                                                                                                rectangle.Y = 126;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                rectangle.X = 36;
                                                                                                rectangle.Y = 162;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num29 == num && num34 == num && num31 == num && num32 == num37)
                                                                                {
                                                                                    if (num28 != -1)
                                                                                    {
                                                                                        if (num36 == 0)
                                                                                        {
                                                                                            rectangle.X = 54;
                                                                                            rectangle.Y = 90;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num36 == 1)
                                                                                            {
                                                                                                rectangle.X = 54;
                                                                                                rectangle.Y = 126;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                rectangle.X = 54;
                                                                                                rectangle.Y = 162;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num33 != -1)
                                                                                        {
                                                                                            if (num36 == 0)
                                                                                            {
                                                                                                rectangle.X = 54;
                                                                                                rectangle.Y = 108;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num36 == 1)
                                                                                                {
                                                                                                    rectangle.X = 54;
                                                                                                    rectangle.Y = 144;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    rectangle.X = 54;
                                                                                                    rectangle.Y = 180;
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num29 == num && num34 == num && num31 == num37 && num32 == num)
                                                                                    {
                                                                                        if (num30 != -1)
                                                                                        {
                                                                                            if (num36 == 0)
                                                                                            {
                                                                                                rectangle.X = 36;
                                                                                                rectangle.Y = 90;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num36 == 1)
                                                                                                {
                                                                                                    rectangle.X = 36;
                                                                                                    rectangle.Y = 126;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    rectangle.X = 36;
                                                                                                    rectangle.Y = 162;
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num35 != -1)
                                                                                            {
                                                                                                if (num36 == 0)
                                                                                                {
                                                                                                    rectangle.X = 36;
                                                                                                    rectangle.Y = 108;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (num36 == 1)
                                                                                                    {
                                                                                                        rectangle.X = 36;
                                                                                                        rectangle.Y = 144;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        rectangle.X = 36;
                                                                                                        rectangle.Y = 180;
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if ((num29 == num37 && num34 == num && num31 == num && num32 == num) || (num29 == num && num34 == num37 && num31 == num && num32 == num) || (num29 == num && num34 == num && num31 == num37 && num32 == num) || (num29 == num && num34 == num && num31 == num && num32 == num37))
                                                                                        {
                                                                                            if (num36 == 0)
                                                                                            {
                                                                                                rectangle.X = 18;
                                                                                                rectangle.Y = 18;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num36 == 1)
                                                                                                {
                                                                                                    rectangle.X = 36;
                                                                                                    rectangle.Y = 18;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    rectangle.X = 54;
                                                                                                    rectangle.Y = 18;
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if ((num29 == num || num29 == num37) && (num34 == num || num34 == num37) && (num31 == num || num31 == num37) && (num32 == num || num32 == num37))
                                    {
                                        if (num28 != num && num28 != num37 && (num30 == num || num30 == num37) && (num33 == num || num33 == num37) && (num35 == num || num35 == num37))
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 54;
                                                rectangle.Y = 108;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 54;
                                                    rectangle.Y = 144;
                                                }
                                                else
                                                {
                                                    rectangle.X = 54;
                                                    rectangle.Y = 180;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num30 != num && num30 != num37 && (num28 == num || num28 == num37) && (num33 == num || num33 == num37) && (num35 == num || num35 == num37))
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 36;
                                                    rectangle.Y = 108;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 36;
                                                        rectangle.Y = 144;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 36;
                                                        rectangle.Y = 180;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num33 != num && num33 != num37 && (num28 == num || num28 == num37) && (num30 == num || num30 == num37) && (num35 == num || num35 == num37))
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 54;
                                                        rectangle.Y = 90;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 54;
                                                            rectangle.Y = 126;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 54;
                                                            rectangle.Y = 162;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num35 != num && num35 != num37 && (num28 == num || num28 == num37) && (num33 == num || num33 == num37) && (num30 == num || num30 == num37))
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 36;
                                                            rectangle.Y = 90;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 126;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 162;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (num29 != num37 && num29 != num && num34 == num && num31 != num37 && num31 != num && num32 == num && num35 != num37 && num35 != num)
                                    {
                                        if (num36 == 0)
                                        {
                                            rectangle.X = 90;
                                            rectangle.Y = 270;
                                        }
                                        else
                                        {
                                            if (num36 == 1)
                                            {
                                                rectangle.X = 108;
                                                rectangle.Y = 270;
                                            }
                                            else
                                            {
                                                rectangle.X = 126;
                                                rectangle.Y = 270;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num29 != num37 && num29 != num && num34 == num && num31 == num && num32 != num37 && num32 != num && num33 != num37 && num33 != num)
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 144;
                                                rectangle.Y = 270;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 162;
                                                    rectangle.Y = 270;
                                                }
                                                else
                                                {
                                                    rectangle.X = 180;
                                                    rectangle.Y = 270;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num34 != num37 && num34 != num && num29 == num && num31 != num37 && num31 != num && num32 == num && num30 != num37 && num30 != num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 90;
                                                    rectangle.Y = 288;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 108;
                                                        rectangle.Y = 288;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 126;
                                                        rectangle.Y = 288;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num34 != num37 && num34 != num && num29 == num && num31 == num && num32 != num37 && num32 != num && num28 != num37 && num28 != num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 144;
                                                        rectangle.Y = 288;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 162;
                                                            rectangle.Y = 288;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 180;
                                                            rectangle.Y = 288;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num29 != num && num29 != num37 && num34 == num && num31 == num && num32 == num && num33 != num && num33 != num37 && num35 != num && num35 != num37)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 144;
                                                            rectangle.Y = 216;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 198;
                                                                rectangle.Y = 216;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 252;
                                                                rectangle.Y = 216;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num34 != num && num34 != num37 && num29 == num && num31 == num && num32 == num && num28 != num && num28 != num37 && num30 != num && num30 != num37)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 144;
                                                                rectangle.Y = 252;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 198;
                                                                    rectangle.Y = 252;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 252;
                                                                    rectangle.Y = 252;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num31 != num && num31 != num37 && num34 == num && num29 == num && num32 == num && num30 != num && num30 != num37 && num35 != num && num35 != num37)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 126;
                                                                    rectangle.Y = 234;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 180;
                                                                        rectangle.Y = 234;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 234;
                                                                        rectangle.Y = 234;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num32 != num && num32 != num37 && num34 == num && num29 == num && num31 == num && num28 != num && num28 != num37 && num33 != num && num33 != num37)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 162;
                                                                        rectangle.Y = 234;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 216;
                                                                            rectangle.Y = 234;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 270;
                                                                            rectangle.Y = 234;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (num29 != num37 && num29 != num && (num34 == num37 || num34 == num) && num31 == num37 && num32 == num37)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 36;
                                                                            rectangle.Y = 270;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 270;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 72;
                                                                                rectangle.Y = 270;
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num34 != num37 && num34 != num && (num29 == num37 || num29 == num) && num31 == num37 && num32 == num37)
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 36;
                                                                                rectangle.Y = 288;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 54;
                                                                                    rectangle.Y = 288;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 72;
                                                                                    rectangle.Y = 288;
                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num31 != num37 && num31 != num && (num32 == num37 || num32 == num) && num29 == num37 && num34 == num37)
                                                                            {
                                                                                if (num36 == 0)
                                                                                {
                                                                                    rectangle.X = 0;
                                                                                    rectangle.Y = 270;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num36 == 1)
                                                                                    {
                                                                                        rectangle.X = 0;
                                                                                        rectangle.Y = 288;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        rectangle.X = 0;
                                                                                        rectangle.Y = 306;
                                                                                    }
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num32 != num37 && num32 != num && (num31 == num37 || num31 == num) && num29 == num37 && num34 == num37)
                                                                                {
                                                                                    if (num36 == 0)
                                                                                    {
                                                                                        rectangle.X = 18;
                                                                                        rectangle.Y = 270;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num36 == 1)
                                                                                        {
                                                                                            rectangle.X = 18;
                                                                                            rectangle.Y = 288;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            rectangle.X = 18;
                                                                                            rectangle.Y = 306;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num29 == num && num34 == num37 && num31 == num37 && num32 == num37)
                                                                                    {
                                                                                        if (num36 == 0)
                                                                                        {
                                                                                            rectangle.X = 198;
                                                                                            rectangle.Y = 288;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num36 == 1)
                                                                                            {
                                                                                                rectangle.X = 216;
                                                                                                rectangle.Y = 288;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                rectangle.X = 234;
                                                                                                rectangle.Y = 288;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num29 == num37 && num34 == num && num31 == num37 && num32 == num37)
                                                                                        {
                                                                                            if (num36 == 0)
                                                                                            {
                                                                                                rectangle.X = 198;
                                                                                                rectangle.Y = 270;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num36 == 1)
                                                                                                {
                                                                                                    rectangle.X = 216;
                                                                                                    rectangle.Y = 270;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    rectangle.X = 234;
                                                                                                    rectangle.Y = 270;
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num29 == num37 && num34 == num37 && num31 == num && num32 == num37)
                                                                                            {
                                                                                                if (num36 == 0)
                                                                                                {
                                                                                                    rectangle.X = 198;
                                                                                                    rectangle.Y = 306;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (num36 == 1)
                                                                                                    {
                                                                                                        rectangle.X = 216;
                                                                                                        rectangle.Y = 306;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        rectangle.X = 234;
                                                                                                        rectangle.Y = 306;
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num29 == num37 && num34 == num37 && num31 == num37 && num32 == num)
                                                                                                {
                                                                                                    if (num36 == 0)
                                                                                                    {
                                                                                                        rectangle.X = 144;
                                                                                                        rectangle.Y = 306;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        if (num36 == 1)
                                                                                                        {
                                                                                                            rectangle.X = 162;
                                                                                                            rectangle.Y = 306;
                                                                                                        }
                                                                                                        else
                                                                                                        {
                                                                                                            rectangle.X = 180;
                                                                                                            rectangle.Y = 306;
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (num29 != num && num29 != num37 && num34 == num && num31 == num && num32 == num)
                                    {
                                        if ((num33 == num37 || num33 == num) && num35 != num37 && num35 != num)
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 0;
                                                rectangle.Y = 324;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 18;
                                                    rectangle.Y = 324;
                                                }
                                                else
                                                {
                                                    rectangle.X = 36;
                                                    rectangle.Y = 324;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ((num35 == num37 || num35 == num) && num33 != num37 && num33 != num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 54;
                                                    rectangle.Y = 324;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 72;
                                                        rectangle.Y = 324;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 90;
                                                        rectangle.Y = 324;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num34 != num && num34 != num37 && num29 == num && num31 == num && num32 == num)
                                        {
                                            if ((num28 == num37 || num28 == num) && num30 != num37 && num30 != num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 0;
                                                    rectangle.Y = 342;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 18;
                                                        rectangle.Y = 342;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 36;
                                                        rectangle.Y = 342;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if ((num30 == num37 || num30 == num) && num28 != num37 && num28 != num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 54;
                                                        rectangle.Y = 342;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 342;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 342;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num31 != num && num31 != num37 && num29 == num && num34 == num && num32 == num)
                                            {
                                                if ((num30 == num37 || num30 == num) && num35 != num37 && num35 != num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 54;
                                                        rectangle.Y = 360;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 360;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 360;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if ((num35 == num37 || num35 == num) && num30 != num37 && num30 != num)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 0;
                                                            rectangle.Y = 360;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 18;
                                                                rectangle.Y = 360;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 360;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num32 != num && num32 != num37 && num29 == num && num34 == num && num31 == num)
                                                {
                                                    if ((num28 == num37 || num28 == num) && num33 != num37 && num33 != num)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 0;
                                                            rectangle.Y = 378;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 18;
                                                                rectangle.Y = 378;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 378;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if ((num33 == num37 || num33 == num) && num28 != num37 && num28 != num)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 54;
                                                                rectangle.Y = 378;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 72;
                                                                    rectangle.Y = 378;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 90;
                                                                    rectangle.Y = 378;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if ((num29 == num || num29 == num37) && (num34 == num || num34 == num37) && (num31 == num || num31 == num37) && (num32 == num || num32 == num37) && num28 != -1 && num30 != -1 && num33 != -1 && num35 != -1)
                                    {
                                        if (num36 == 0)
                                        {
                                            rectangle.X = 18;
                                            rectangle.Y = 18;
                                        }
                                        else
                                        {
                                            if (num36 == 1)
                                            {
                                                rectangle.X = 36;
                                                rectangle.Y = 18;
                                            }
                                            else
                                            {
                                                rectangle.X = 54;
                                                rectangle.Y = 18;
                                            }
                                        }
                                    }
                                    if (num29 == num37)
                                    {
                                        num29 = -2;
                                    }
                                    if (num34 == num37)
                                    {
                                        num34 = -2;
                                    }
                                    if (num31 == num37)
                                    {
                                        num31 = -2;
                                    }
                                    if (num32 == num37)
                                    {
                                        num32 = -2;
                                    }
                                    if (num28 == num37)
                                    {
                                        num28 = -2;
                                    }
                                    if (num30 == num37)
                                    {
                                        num30 = -2;
                                    }
                                    if (num33 == num37)
                                    {
                                        num33 = -2;
                                    }
                                    if (num35 == num37)
                                    {
                                        num35 = -2;
                                    }
                                }
                                if (rectangle.X == -1 && rectangle.Y == -1 && (Main.tileMergeDirt[num] || num == 0 || num == 2 || num == 57 || num == 58 || num == 59 || num == 60 || num == 70 || num == 109 || num == 76 || num == 75))
                                {
                                    if (!flag3)
                                    {
                                        flag3 = true;
                                        if (num29 > -1 && !Main.tileSolid[num29] && num29 != num)
                                        {
                                            num29 = -1;
                                        }
                                        if (num34 > -1 && !Main.tileSolid[num34] && num34 != num)
                                        {
                                            num34 = -1;
                                        }
                                        if (num31 > -1 && !Main.tileSolid[num31] && num31 != num)
                                        {
                                            num31 = -1;
                                        }
                                        if (num32 > -1 && !Main.tileSolid[num32] && num32 != num)
                                        {
                                            num32 = -1;
                                        }
                                        if (num28 > -1 && !Main.tileSolid[num28] && num28 != num)
                                        {
                                            num28 = -1;
                                        }
                                        if (num30 > -1 && !Main.tileSolid[num30] && num30 != num)
                                        {
                                            num30 = -1;
                                        }
                                        if (num33 > -1 && !Main.tileSolid[num33] && num33 != num)
                                        {
                                            num33 = -1;
                                        }
                                        if (num35 > -1 && !Main.tileSolid[num35] && num35 != num)
                                        {
                                            num35 = -1;
                                        }
                                    }
                                    if (num29 >= 0 && num29 != num)
                                    {
                                        num29 = -1;
                                    }
                                    if (num34 >= 0 && num34 != num)
                                    {
                                        num34 = -1;
                                    }
                                    if (num31 >= 0 && num31 != num)
                                    {
                                        num31 = -1;
                                    }
                                    if (num32 >= 0 && num32 != num)
                                    {
                                        num32 = -1;
                                    }
                                    if (num29 != -1 && num34 != -1 && num31 != -1 && num32 != -1)
                                    {
                                        if (num29 == -2 && num34 == num && num31 == num && num32 == num)
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 144;
                                                rectangle.Y = 108;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 162;
                                                    rectangle.Y = 108;
                                                }
                                                else
                                                {
                                                    rectangle.X = 180;
                                                    rectangle.Y = 108;
                                                }
                                            }
                                            mergeUp = true;
                                        }
                                        else
                                        {
                                            if (num29 == num && num34 == -2 && num31 == num && num32 == num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 144;
                                                    rectangle.Y = 90;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 162;
                                                        rectangle.Y = 90;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 180;
                                                        rectangle.Y = 90;
                                                    }
                                                }
                                                mergeDown = true;
                                            }
                                            else
                                            {
                                                if (num29 == num && num34 == num && num31 == -2 && num32 == num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 162;
                                                        rectangle.Y = 126;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 162;
                                                            rectangle.Y = 144;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 162;
                                                            rectangle.Y = 162;
                                                        }
                                                    }
                                                    mergeLeft = true;
                                                }
                                                else
                                                {
                                                    if (num29 == num && num34 == num && num31 == num && num32 == -2)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 144;
                                                            rectangle.Y = 126;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 144;
                                                                rectangle.Y = 144;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 144;
                                                                rectangle.Y = 162;
                                                            }
                                                        }
                                                        mergeRight = true;
                                                    }
                                                    else
                                                    {
                                                        if (num29 == -2 && num34 == num && num31 == -2 && num32 == num)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 90;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 36;
                                                                    rectangle.Y = 126;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 36;
                                                                    rectangle.Y = 162;
                                                                }
                                                            }
                                                            mergeUp = true;
                                                            mergeLeft = true;
                                                        }
                                                        else
                                                        {
                                                            if (num29 == -2 && num34 == num && num31 == num && num32 == -2)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 54;
                                                                    rectangle.Y = 90;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 54;
                                                                        rectangle.Y = 126;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 54;
                                                                        rectangle.Y = 162;
                                                                    }
                                                                }
                                                                mergeUp = true;
                                                                mergeRight = true;
                                                            }
                                                            else
                                                            {
                                                                if (num29 == num && num34 == -2 && num31 == -2 && num32 == num)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 36;
                                                                        rectangle.Y = 108;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 36;
                                                                            rectangle.Y = 144;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 36;
                                                                            rectangle.Y = 180;
                                                                        }
                                                                    }
                                                                    mergeDown = true;
                                                                    mergeLeft = true;
                                                                }
                                                                else
                                                                {
                                                                    if (num29 == num && num34 == -2 && num31 == num && num32 == -2)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 54;
                                                                            rectangle.Y = 108;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 144;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 180;
                                                                            }
                                                                        }
                                                                        mergeDown = true;
                                                                        mergeRight = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num29 == num && num34 == num && num31 == -2 && num32 == -2)
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 180;
                                                                                rectangle.Y = 126;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 180;
                                                                                    rectangle.Y = 144;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 180;
                                                                                    rectangle.Y = 162;
                                                                                }
                                                                            }
                                                                            mergeLeft = true;
                                                                            mergeRight = true;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num29 == -2 && num34 == -2 && num31 == num && num32 == num)
                                                                            {
                                                                                if (num36 == 0)
                                                                                {
                                                                                    rectangle.X = 144;
                                                                                    rectangle.Y = 180;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num36 == 1)
                                                                                    {
                                                                                        rectangle.X = 162;
                                                                                        rectangle.Y = 180;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        rectangle.X = 180;
                                                                                        rectangle.Y = 180;
                                                                                    }
                                                                                }
                                                                                mergeUp = true;
                                                                                mergeDown = true;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num29 == -2 && num34 == num && num31 == -2 && num32 == -2)
                                                                                {
                                                                                    if (num36 == 0)
                                                                                    {
                                                                                        rectangle.X = 198;
                                                                                        rectangle.Y = 90;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num36 == 1)
                                                                                        {
                                                                                            rectangle.X = 198;
                                                                                            rectangle.Y = 108;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            rectangle.X = 198;
                                                                                            rectangle.Y = 126;
                                                                                        }
                                                                                    }
                                                                                    mergeUp = true;
                                                                                    mergeLeft = true;
                                                                                    mergeRight = true;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num29 == num && num34 == -2 && num31 == -2 && num32 == -2)
                                                                                    {
                                                                                        if (num36 == 0)
                                                                                        {
                                                                                            rectangle.X = 198;
                                                                                            rectangle.Y = 144;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num36 == 1)
                                                                                            {
                                                                                                rectangle.X = 198;
                                                                                                rectangle.Y = 162;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                rectangle.X = 198;
                                                                                                rectangle.Y = 180;
                                                                                            }
                                                                                        }
                                                                                        mergeDown = true;
                                                                                        mergeLeft = true;
                                                                                        mergeRight = true;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num29 == -2 && num34 == -2 && num31 == num && num32 == -2)
                                                                                        {
                                                                                            if (num36 == 0)
                                                                                            {
                                                                                                rectangle.X = 216;
                                                                                                rectangle.Y = 144;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num36 == 1)
                                                                                                {
                                                                                                    rectangle.X = 216;
                                                                                                    rectangle.Y = 162;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    rectangle.X = 216;
                                                                                                    rectangle.Y = 180;
                                                                                                }
                                                                                            }
                                                                                            mergeUp = true;
                                                                                            mergeDown = true;
                                                                                            mergeRight = true;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num29 == -2 && num34 == -2 && num31 == -2 && num32 == num)
                                                                                            {
                                                                                                if (num36 == 0)
                                                                                                {
                                                                                                    rectangle.X = 216;
                                                                                                    rectangle.Y = 90;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (num36 == 1)
                                                                                                    {
                                                                                                        rectangle.X = 216;
                                                                                                        rectangle.Y = 108;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        rectangle.X = 216;
                                                                                                        rectangle.Y = 126;
                                                                                                    }
                                                                                                }
                                                                                                mergeUp = true;
                                                                                                mergeDown = true;
                                                                                                mergeLeft = true;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num29 == -2 && num34 == -2 && num31 == -2 && num32 == -2)
                                                                                                {
                                                                                                    if (num36 == 0)
                                                                                                    {
                                                                                                        rectangle.X = 108;
                                                                                                        rectangle.Y = 198;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        if (num36 == 1)
                                                                                                        {
                                                                                                            rectangle.X = 126;
                                                                                                            rectangle.Y = 198;
                                                                                                        }
                                                                                                        else
                                                                                                        {
                                                                                                            rectangle.X = 144;
                                                                                                            rectangle.Y = 198;
                                                                                                        }
                                                                                                    }
                                                                                                    mergeUp = true;
                                                                                                    mergeDown = true;
                                                                                                    mergeLeft = true;
                                                                                                    mergeRight = true;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (num29 == num && num34 == num && num31 == num && num32 == num)
                                                                                                    {
                                                                                                        if (num28 == -2)
                                                                                                        {
                                                                                                            if (num36 == 0)
                                                                                                            {
                                                                                                                rectangle.X = 18;
                                                                                                                rectangle.Y = 108;
                                                                                                            }
                                                                                                            else
                                                                                                            {
                                                                                                                if (num36 == 1)
                                                                                                                {
                                                                                                                    rectangle.X = 18;
                                                                                                                    rectangle.Y = 144;
                                                                                                                }
                                                                                                                else
                                                                                                                {
                                                                                                                    rectangle.X = 18;
                                                                                                                    rectangle.Y = 180;
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                        if (num30 == -2)
                                                                                                        {
                                                                                                            if (num36 == 0)
                                                                                                            {
                                                                                                                rectangle.X = 0;
                                                                                                                rectangle.Y = 108;
                                                                                                            }
                                                                                                            else
                                                                                                            {
                                                                                                                if (num36 == 1)
                                                                                                                {
                                                                                                                    rectangle.X = 0;
                                                                                                                    rectangle.Y = 144;
                                                                                                                }
                                                                                                                else
                                                                                                                {
                                                                                                                    rectangle.X = 0;
                                                                                                                    rectangle.Y = 180;
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                        if (num33 == -2)
                                                                                                        {
                                                                                                            if (num36 == 0)
                                                                                                            {
                                                                                                                rectangle.X = 18;
                                                                                                                rectangle.Y = 90;
                                                                                                            }
                                                                                                            else
                                                                                                            {
                                                                                                                if (num36 == 1)
                                                                                                                {
                                                                                                                    rectangle.X = 18;
                                                                                                                    rectangle.Y = 126;
                                                                                                                }
                                                                                                                else
                                                                                                                {
                                                                                                                    rectangle.X = 18;
                                                                                                                    rectangle.Y = 162;
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                        if (num35 == -2)
                                                                                                        {
                                                                                                            if (num36 == 0)
                                                                                                            {
                                                                                                                rectangle.X = 0;
                                                                                                                rectangle.Y = 90;
                                                                                                            }
                                                                                                            else
                                                                                                            {
                                                                                                                if (num36 == 1)
                                                                                                                {
                                                                                                                    rectangle.X = 0;
                                                                                                                    rectangle.Y = 126;
                                                                                                                }
                                                                                                                else
                                                                                                                {
                                                                                                                    rectangle.X = 0;
                                                                                                                    rectangle.Y = 162;
                                                                                                                }
                                                                                                            }
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num != 2 && num != 23 && num != 60 && num != 70 && num != 109)
                                        {
                                            if (num29 == -1 && num34 == -2 && num31 == num && num32 == num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 234;
                                                    rectangle.Y = 0;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 252;
                                                        rectangle.Y = 0;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 270;
                                                        rectangle.Y = 0;
                                                    }
                                                }
                                                mergeDown = true;
                                            }
                                            else
                                            {
                                                if (num29 == -2 && num34 == -1 && num31 == num && num32 == num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 234;
                                                        rectangle.Y = 18;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 252;
                                                            rectangle.Y = 18;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 270;
                                                            rectangle.Y = 18;
                                                        }
                                                    }
                                                    mergeUp = true;
                                                }
                                                else
                                                {
                                                    if (num29 == num && num34 == num && num31 == -1 && num32 == -2)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 234;
                                                            rectangle.Y = 36;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 252;
                                                                rectangle.Y = 36;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 270;
                                                                rectangle.Y = 36;
                                                            }
                                                        }
                                                        mergeRight = true;
                                                    }
                                                    else
                                                    {
                                                        if (num29 == num && num34 == num && num31 == -2 && num32 == -1)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 234;
                                                                rectangle.Y = 54;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 252;
                                                                    rectangle.Y = 54;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 270;
                                                                    rectangle.Y = 54;
                                                                }
                                                            }
                                                            mergeLeft = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (num29 != -1 && num34 != -1 && num31 == -1 && num32 == num)
                                        {
                                            if (num29 == -2 && num34 == num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 72;
                                                    rectangle.Y = 144;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 72;
                                                        rectangle.Y = 162;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 72;
                                                        rectangle.Y = 180;
                                                    }
                                                }
                                                mergeUp = true;
                                            }
                                            else
                                            {
                                                if (num34 == -2 && num29 == num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 72;
                                                        rectangle.Y = 90;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 108;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 126;
                                                        }
                                                    }
                                                    mergeDown = true;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num29 != -1 && num34 != -1 && num31 == num && num32 == -1)
                                            {
                                                if (num29 == -2 && num34 == num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 90;
                                                        rectangle.Y = 144;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 162;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 180;
                                                        }
                                                    }
                                                    mergeUp = true;
                                                }
                                                else
                                                {
                                                    if (num34 == -2 && num29 == num)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 90;
                                                            rectangle.Y = 90;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 90;
                                                                rectangle.Y = 108;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 90;
                                                                rectangle.Y = 126;
                                                            }
                                                        }
                                                        mergeDown = true;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num29 == -1 && num34 == num && num31 != -1 && num32 != -1)
                                                {
                                                    if (num31 == -2 && num32 == num)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 0;
                                                            rectangle.Y = 198;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 18;
                                                                rectangle.Y = 198;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 198;
                                                            }
                                                        }
                                                        mergeLeft = true;
                                                    }
                                                    else
                                                    {
                                                        if (num32 == -2 && num31 == num)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 54;
                                                                rectangle.Y = 198;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 72;
                                                                    rectangle.Y = 198;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 90;
                                                                    rectangle.Y = 198;
                                                                }
                                                            }
                                                            mergeRight = true;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num29 == num && num34 == -1 && num31 != -1 && num32 != -1)
                                                    {
                                                        if (num31 == -2 && num32 == num)
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 0;
                                                                rectangle.Y = 216;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 18;
                                                                    rectangle.Y = 216;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 36;
                                                                    rectangle.Y = 216;
                                                                }
                                                            }
                                                            mergeLeft = true;
                                                        }
                                                        else
                                                        {
                                                            if (num32 == -2 && num31 == num)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 54;
                                                                    rectangle.Y = 216;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 72;
                                                                        rectangle.Y = 216;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 90;
                                                                        rectangle.Y = 216;
                                                                    }
                                                                }
                                                                mergeRight = true;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num29 != -1 && num34 != -1 && num31 == -1 && num32 == -1)
                                                        {
                                                            if (num29 == -2 && num34 == -2)
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 108;
                                                                    rectangle.Y = 216;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 108;
                                                                        rectangle.Y = 234;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 108;
                                                                        rectangle.Y = 252;
                                                                    }
                                                                }
                                                                mergeUp = true;
                                                                mergeDown = true;
                                                            }
                                                            else
                                                            {
                                                                if (num29 == -2)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 126;
                                                                        rectangle.Y = 144;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 162;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 180;
                                                                        }
                                                                    }
                                                                    mergeUp = true;
                                                                }
                                                                else
                                                                {
                                                                    if (num34 == -2)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 126;
                                                                            rectangle.Y = 90;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 126;
                                                                                rectangle.Y = 108;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 126;
                                                                                rectangle.Y = 126;
                                                                            }
                                                                        }
                                                                        mergeDown = true;
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num29 == -1 && num34 == -1 && num31 != -1 && num32 != -1)
                                                            {
                                                                if (num31 == -2 && num32 == -2)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 162;
                                                                        rectangle.Y = 198;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 180;
                                                                            rectangle.Y = 198;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 198;
                                                                            rectangle.Y = 198;
                                                                        }
                                                                    }
                                                                    mergeLeft = true;
                                                                    mergeRight = true;
                                                                }
                                                                else
                                                                {
                                                                    if (num31 == -2)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 0;
                                                                            rectangle.Y = 252;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 18;
                                                                                rectangle.Y = 252;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 36;
                                                                                rectangle.Y = 252;
                                                                            }
                                                                        }
                                                                        mergeLeft = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num32 == -2)
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 252;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 72;
                                                                                    rectangle.Y = 252;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 90;
                                                                                    rectangle.Y = 252;
                                                                                }
                                                                            }
                                                                            mergeRight = true;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num29 == -2 && num34 == -1 && num31 == -1 && num32 == -1)
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 108;
                                                                        rectangle.Y = 144;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 108;
                                                                            rectangle.Y = 162;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 108;
                                                                            rectangle.Y = 180;
                                                                        }
                                                                    }
                                                                    mergeUp = true;
                                                                }
                                                                else
                                                                {
                                                                    if (num29 == -1 && num34 == -2 && num31 == -1 && num32 == -1)
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 108;
                                                                            rectangle.Y = 90;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 108;
                                                                                rectangle.Y = 108;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 108;
                                                                                rectangle.Y = 126;
                                                                            }
                                                                        }
                                                                        mergeDown = true;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num29 == -1 && num34 == -1 && num31 == -2 && num32 == -1)
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 0;
                                                                                rectangle.Y = 234;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 18;
                                                                                    rectangle.Y = 234;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 36;
                                                                                    rectangle.Y = 234;
                                                                                }
                                                                            }
                                                                            mergeLeft = true;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num29 == -1 && num34 == -1 && num31 == -1 && num32 == -2)
                                                                            {
                                                                                if (num36 == 0)
                                                                                {
                                                                                    rectangle.X = 54;
                                                                                    rectangle.Y = 234;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num36 == 1)
                                                                                    {
                                                                                        rectangle.X = 72;
                                                                                        rectangle.Y = 234;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        rectangle.X = 90;
                                                                                        rectangle.Y = 234;
                                                                                    }
                                                                                }
                                                                                mergeRight = true;
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (rectangle.X < 0 || rectangle.Y < 0)
                                {
                                    if (!flag3)
                                    {
                                        flag3 = true;
                                        if (num29 > -1 && !Main.tileSolid[num29] && num29 != num)
                                        {
                                            num29 = -1;
                                        }
                                        if (num34 > -1 && !Main.tileSolid[num34] && num34 != num)
                                        {
                                            num34 = -1;
                                        }
                                        if (num31 > -1 && !Main.tileSolid[num31] && num31 != num)
                                        {
                                            num31 = -1;
                                        }
                                        if (num32 > -1 && !Main.tileSolid[num32] && num32 != num)
                                        {
                                            num32 = -1;
                                        }
                                        if (num28 > -1 && !Main.tileSolid[num28] && num28 != num)
                                        {
                                            num28 = -1;
                                        }
                                        if (num30 > -1 && !Main.tileSolid[num30] && num30 != num)
                                        {
                                            num30 = -1;
                                        }
                                        if (num33 > -1 && !Main.tileSolid[num33] && num33 != num)
                                        {
                                            num33 = -1;
                                        }
                                        if (num35 > -1 && !Main.tileSolid[num35] && num35 != num)
                                        {
                                            num35 = -1;
                                        }
                                    }
                                    if (num == 2 || num == 23 || num == 60 || num == 70 || num == 109)
                                    {
                                        if (num29 == -2)
                                        {
                                            num29 = num;
                                        }
                                        if (num34 == -2)
                                        {
                                            num34 = num;
                                        }
                                        if (num31 == -2)
                                        {
                                            num31 = num;
                                        }
                                        if (num32 == -2)
                                        {
                                            num32 = num;
                                        }
                                        if (num28 == -2)
                                        {
                                            num28 = num;
                                        }
                                        if (num30 == -2)
                                        {
                                            num30 = num;
                                        }
                                        if (num33 == -2)
                                        {
                                            num33 = num;
                                        }
                                        if (num35 == -2)
                                        {
                                            num35 = num;
                                        }
                                    }
                                    if (num29 == num && num34 == num && (num31 == num & num32 == num))
                                    {
                                        if (num28 != num && num30 != num)
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 108;
                                                rectangle.Y = 18;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 126;
                                                    rectangle.Y = 18;
                                                }
                                                else
                                                {
                                                    rectangle.X = 144;
                                                    rectangle.Y = 18;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num33 != num && num35 != num)
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 108;
                                                    rectangle.Y = 36;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 126;
                                                        rectangle.Y = 36;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 144;
                                                        rectangle.Y = 36;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num28 != num && num33 != num)
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 180;
                                                        rectangle.Y = 0;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 180;
                                                            rectangle.Y = 18;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 180;
                                                            rectangle.Y = 36;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num30 != num && num35 != num)
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 198;
                                                            rectangle.Y = 0;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 198;
                                                                rectangle.Y = 18;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 198;
                                                                rectangle.Y = 36;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 18;
                                                            rectangle.Y = 18;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 36;
                                                                rectangle.Y = 18;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 54;
                                                                rectangle.Y = 18;
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (num29 != num && num34 == num && (num31 == num & num32 == num))
                                        {
                                            if (num36 == 0)
                                            {
                                                rectangle.X = 18;
                                                rectangle.Y = 0;
                                            }
                                            else
                                            {
                                                if (num36 == 1)
                                                {
                                                    rectangle.X = 36;
                                                    rectangle.Y = 0;
                                                }
                                                else
                                                {
                                                    rectangle.X = 54;
                                                    rectangle.Y = 0;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num29 == num && num34 != num && (num31 == num & num32 == num))
                                            {
                                                if (num36 == 0)
                                                {
                                                    rectangle.X = 18;
                                                    rectangle.Y = 36;
                                                }
                                                else
                                                {
                                                    if (num36 == 1)
                                                    {
                                                        rectangle.X = 36;
                                                        rectangle.Y = 36;
                                                    }
                                                    else
                                                    {
                                                        rectangle.X = 54;
                                                        rectangle.Y = 36;
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                if (num29 == num && num34 == num && (num31 != num & num32 == num))
                                                {
                                                    if (num36 == 0)
                                                    {
                                                        rectangle.X = 0;
                                                        rectangle.Y = 0;
                                                    }
                                                    else
                                                    {
                                                        if (num36 == 1)
                                                        {
                                                            rectangle.X = 0;
                                                            rectangle.Y = 18;
                                                        }
                                                        else
                                                        {
                                                            rectangle.X = 0;
                                                            rectangle.Y = 36;
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    if (num29 == num && num34 == num && (num31 == num & num32 != num))
                                                    {
                                                        if (num36 == 0)
                                                        {
                                                            rectangle.X = 72;
                                                            rectangle.Y = 0;
                                                        }
                                                        else
                                                        {
                                                            if (num36 == 1)
                                                            {
                                                                rectangle.X = 72;
                                                                rectangle.Y = 18;
                                                            }
                                                            else
                                                            {
                                                                rectangle.X = 72;
                                                                rectangle.Y = 36;
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (num29 != num && num34 == num && (num31 != num & num32 == num))
                                                        {
                                                            if (num36 == 0)
                                                            {
                                                                rectangle.X = 0;
                                                                rectangle.Y = 54;
                                                            }
                                                            else
                                                            {
                                                                if (num36 == 1)
                                                                {
                                                                    rectangle.X = 36;
                                                                    rectangle.Y = 54;
                                                                }
                                                                else
                                                                {
                                                                    rectangle.X = 72;
                                                                    rectangle.Y = 54;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            if (num29 != num && num34 == num && (num31 == num & num32 != num))
                                                            {
                                                                if (num36 == 0)
                                                                {
                                                                    rectangle.X = 18;
                                                                    rectangle.Y = 54;
                                                                }
                                                                else
                                                                {
                                                                    if (num36 == 1)
                                                                    {
                                                                        rectangle.X = 54;
                                                                        rectangle.Y = 54;
                                                                    }
                                                                    else
                                                                    {
                                                                        rectangle.X = 90;
                                                                        rectangle.Y = 54;
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (num29 == num && num34 != num && (num31 != num & num32 == num))
                                                                {
                                                                    if (num36 == 0)
                                                                    {
                                                                        rectangle.X = 0;
                                                                        rectangle.Y = 72;
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num36 == 1)
                                                                        {
                                                                            rectangle.X = 36;
                                                                            rectangle.Y = 72;
                                                                        }
                                                                        else
                                                                        {
                                                                            rectangle.X = 72;
                                                                            rectangle.Y = 72;
                                                                        }
                                                                    }
                                                                }
                                                                else
                                                                {
                                                                    if (num29 == num && num34 != num && (num31 == num & num32 != num))
                                                                    {
                                                                        if (num36 == 0)
                                                                        {
                                                                            rectangle.X = 18;
                                                                            rectangle.Y = 72;
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num36 == 1)
                                                                            {
                                                                                rectangle.X = 54;
                                                                                rectangle.Y = 72;
                                                                            }
                                                                            else
                                                                            {
                                                                                rectangle.X = 90;
                                                                                rectangle.Y = 72;
                                                                            }
                                                                        }
                                                                    }
                                                                    else
                                                                    {
                                                                        if (num29 == num && num34 == num && (num31 != num & num32 != num))
                                                                        {
                                                                            if (num36 == 0)
                                                                            {
                                                                                rectangle.X = 90;
                                                                                rectangle.Y = 0;
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num36 == 1)
                                                                                {
                                                                                    rectangle.X = 90;
                                                                                    rectangle.Y = 18;
                                                                                }
                                                                                else
                                                                                {
                                                                                    rectangle.X = 90;
                                                                                    rectangle.Y = 36;
                                                                                }
                                                                            }
                                                                        }
                                                                        else
                                                                        {
                                                                            if (num29 != num && num34 != num && (num31 == num & num32 == num))
                                                                            {
                                                                                if (num36 == 0)
                                                                                {
                                                                                    rectangle.X = 108;
                                                                                    rectangle.Y = 72;
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num36 == 1)
                                                                                    {
                                                                                        rectangle.X = 126;
                                                                                        rectangle.Y = 72;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        rectangle.X = 144;
                                                                                        rectangle.Y = 72;
                                                                                    }
                                                                                }
                                                                            }
                                                                            else
                                                                            {
                                                                                if (num29 != num && num34 == num && (num31 != num & num32 != num))
                                                                                {
                                                                                    if (num36 == 0)
                                                                                    {
                                                                                        rectangle.X = 108;
                                                                                        rectangle.Y = 0;
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num36 == 1)
                                                                                        {
                                                                                            rectangle.X = 126;
                                                                                            rectangle.Y = 0;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            rectangle.X = 144;
                                                                                            rectangle.Y = 0;
                                                                                        }
                                                                                    }
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (num29 == num && num34 != num && (num31 != num & num32 != num))
                                                                                    {
                                                                                        if (num36 == 0)
                                                                                        {
                                                                                            rectangle.X = 108;
                                                                                            rectangle.Y = 54;
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num36 == 1)
                                                                                            {
                                                                                                rectangle.X = 126;
                                                                                                rectangle.Y = 54;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                rectangle.X = 144;
                                                                                                rectangle.Y = 54;
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (num29 != num && num34 != num && (num31 != num & num32 == num))
                                                                                        {
                                                                                            if (num36 == 0)
                                                                                            {
                                                                                                rectangle.X = 162;
                                                                                                rectangle.Y = 0;
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num36 == 1)
                                                                                                {
                                                                                                    rectangle.X = 162;
                                                                                                    rectangle.Y = 18;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    rectangle.X = 162;
                                                                                                    rectangle.Y = 36;
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (num29 != num && num34 != num && (num31 == num & num32 != num))
                                                                                            {
                                                                                                if (num36 == 0)
                                                                                                {
                                                                                                    rectangle.X = 216;
                                                                                                    rectangle.Y = 0;
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (num36 == 1)
                                                                                                    {
                                                                                                        rectangle.X = 216;
                                                                                                        rectangle.Y = 18;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        rectangle.X = 216;
                                                                                                        rectangle.Y = 36;
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (num29 != num && num34 != num && (num31 != num & num32 != num))
                                                                                                {
                                                                                                    if (num36 == 0)
                                                                                                    {
                                                                                                        rectangle.X = 162;
                                                                                                        rectangle.Y = 54;
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        if (num36 == 1)
                                                                                                        {
                                                                                                            rectangle.X = 180;
                                                                                                            rectangle.Y = 54;
                                                                                                        }
                                                                                                        else
                                                                                                        {
                                                                                                            rectangle.X = 198;
                                                                                                            rectangle.Y = 54;
                                                                                                        }
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                                if (rectangle.X <= -1 || rectangle.Y <= -1)
                                {
                                    if (num36 <= 0)
                                    {
                                        rectangle.X = 18;
                                        rectangle.Y = 18;
                                    }
                                    else
                                    {
                                        if (num36 == 1)
                                        {
                                            rectangle.X = 36;
                                            rectangle.Y = 18;
                                        }
                                    }
                                    if (num36 >= 2)
                                    {
                                        rectangle.X = 54;
                                        rectangle.Y = 18;
                                    }
                                }
                                TileRefs(i, j).SetFrameX((short)rectangle.X);
                                TileRefs(i, j).SetFrameY((short)rectangle.Y);
                                if (num == 52 || num == 62 || num == 115)
                                {
                                    //if (TileRefs(i, j - 1] != null)
                                    {
                                        if (!TileRefs(i, j - 1).Active)
                                        {
                                            num29 = -1;
                                        }
                                        else
                                        {
                                            num29 = (int)TileRefs(i, j - 1).Type;
                                        }
                                    }
                                    //else
                                    //{
                                    //    num29 = num;
                                    //}
                                    if (num == 52 && (num29 == 109 || num29 == 115))
                                    {
                                        TileRefs(i, j).SetType(115);
                                        SquareTileFrame(TileRefs, sandbox, i, j, true);
                                        return;
                                    }
                                    if (num == 115 && (num29 == 2 || num29 == 52))
                                    {
                                        TileRefs(i, j).SetType(52);
                                        SquareTileFrame(TileRefs, sandbox, i, j, true);
                                        return;
                                    }
                                    if (num29 != num)
                                    {
                                        bool flag4 = false;
                                        if (num29 == -1)
                                        {
                                            flag4 = true;
                                        }
                                        if (num == 52 && num29 != 2)
                                        {
                                            flag4 = true;
                                        }
                                        if (num == 62 && num29 != 60)
                                        {
                                            flag4 = true;
                                        }
                                        if (num == 115 && num29 != 109)
                                        {
                                            flag4 = true;
                                        }
                                        if (flag4)
                                        {
                                            KillTile(TileRefs, sandbox, i, j);
                                        }
                                    }
                                }
                                if (!noTileActions && (num == 53 || num == 112 || num == 116 || num == 123))
                                {
                                    if (!TileRefs(i, j + 1).Active)
                                    {
                                        bool flag6 = true;
                                        if (TileRefs(i, j - 1).Active && TileRefs(i, j - 1).Type == 21)
                                        {
                                            flag6 = false;
                                        }
                                        if (flag6)
                                        {
                                            int type2 = 31;
                                            if (num == 59)
                                            {
                                                type2 = 39;
                                            }
                                            if (num == 57)
                                            {
                                                type2 = 40;
                                            }
                                            if (num == 112)
                                            {
                                                type2 = 56;
                                            }
                                            if (num == 116)
                                            {
                                                type2 = 67;
                                            }
                                            if (num == 123)
                                            {
                                                type2 = 71;
                                            }

                                            TileRefs(i, j).SetActive(false);

                                            /*int num39 = Projectile.NewProjectile((float)(i * 16 + 8), (float)(j * 16 + 8), 0f, 2.5f, type2, 10, 0f, Main.myPlayer);
                                            Main.projectile[num39].Velocity.Y = 0.5f;
                                            Main.projectile[num39].Position.Y += 2f;

                                            Main.projectile[num39].netUpdate = true;
                                            NetMessage.SendTileSquare(-1, i, j, 1);*/

                                            /*lock(WorldModify.playerEditLock)
                                                Terraria_Server.Messages.TileBreakMessage.staticEditor.Sandbox.FallingBlockProjectile(i, j, type2);*/
                                            lock (WorldModify.playerEditLock)
                                                sandbox.FallingBlockProjectile(i, j, type2);

                                            SquareTileFrame(TileRefs, sandbox, i, j, true);
                                        }
                                    }
                                }
                                if (rectangle.X != frameX && rectangle.Y != frameY && frameX >= 0 && frameY >= 0)
                                {
                                    bool flag7 = mergeUp;
                                    bool flag8 = mergeDown;
                                    bool flag9 = mergeLeft;
                                    bool flag10 = mergeRight;
                                    TileFrame(TileRefs, sandbox, i - 1, j, false, false);
                                    TileFrame(TileRefs, sandbox, i + 1, j, false, false);
                                    TileFrame(TileRefs, sandbox, i, j - 1, false, false);
                                    TileFrame(TileRefs, sandbox, i, j + 1, false, false);
                                    mergeUp = flag7;
                                    mergeDown = flag8;
                                    mergeLeft = flag9;
                                    mergeRight = flag10;
                                }
                            }
                        }
                    }
                }
            }
            catch
            { }
        }
        public static void SquareTileFrame(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, bool resetFrame = true)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            TileFrame(TileRefs, sandbox, i - 1, j - 1, false, false);
            TileFrame(TileRefs, sandbox, i - 1, j, false, false);
            TileFrame(TileRefs, sandbox, i - 1, j + 1, false, false);
            TileFrame(TileRefs, sandbox, i, j - 1, false, false);
            TileFrame(TileRefs, sandbox, i, j, resetFrame, false);
            TileFrame(TileRefs, sandbox, i, j + 1, false, false);
            TileFrame(TileRefs, sandbox, i + 1, j - 1, false, false);
            TileFrame(TileRefs, sandbox, i + 1, j, false, false);
            TileFrame(TileRefs, sandbox, i + 1, j + 1, false, false);
        }
        public static void SectionTileFrame(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int startX, int startY, int endX, int endY)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            int num = startX * 200;
            int num2 = (endX + 1) * 200;
            int num3 = startY * 150;
            int num4 = (endY + 1) * 150;
            if (num < 1)
            {
                num = 1;
            }
            if (num3 < 1)
            {
                num3 = 1;
            }
            if (num > Main.maxTilesX - 2)
            {
                num = Main.maxTilesX - 2;
            }
            if (num3 > Main.maxTilesY - 2)
            {
                num3 = Main.maxTilesY - 2;
            }
            for (int i = num - 1; i < num2 + 1; i++)
            {
                for (int j = num3 - 1; j < num4 + 1; j++)
                {
                    TileFrame(TileRefs, sandbox, i, j, true, true);
                }
            }
        }
        public static void PlantCheck(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            int num = -1;
            int num2 = (int)TileRefs(i, j).Type;

            if (j + 1 >= Main.maxTilesY)
            {
                num = num2;
            }

            if (j + 1 < Main.maxTilesY && TileRefs(i, j + 1).Active)
            {
                num = (int)TileRefs(i, j + 1).Type;
            }

            if ((num2 == 3 && num != 2 && num != 78) || (num2 == 24 && num != 23) || (num2 == 61 && num != 60) || (num2 == 71 && num != 70) ||
                (num2 == 73 && num != 2 && num != 78) || (num2 == 74 && num != 60) || (num2 == 110 && num != 109) || (num2 == 113 && num != 109))
            {
                if (num == 23)
                {
                    num2 = 24;
                    if (TileRefs(i, j).FrameX >= 162)
                    {
                        TileRefs(i, j).SetFrameX(126);
                    }
                }
                else if (num == 2)
                {
                    if (num2 == 113)
                    {
                        num2 = 73;
                    }
                    else
                    {
                        num2 = 3;
                    }
                }
                else if (num == 109)
                {
                    if (num2 == 73)
                    {
                        num2 = 113;
                    }
                    else
                    {
                        num2 = 110;
                    }
                }

                if (num2 != (int)TileRefs(i, j).Type)
                {
                    TileRefs(i, j).SetType((byte)num2);
                    return;
                }
                KillTile(TileRefs, sandbox, i, j);
            }
        }
        public static bool KillWire(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (TileRefs(i, j).Wire)
            {
                TileRefs(i, j).SetWire(false);
                StorePlayerItem(sandbox, i * 16, j * 16, 16, 16, 530, 1, false, 0);
                return true;
            }
            return false;
        }
        public static void KillWall(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, bool fail = false)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (i >= 0 && j >= 0 && i < Main.maxTilesX && j < Main.maxTilesY)
            {
                if (TileRefs(i, j).Wall > 0)
                {
                    if (fail)
                    {
                        SquareWallFrame(TileRefs, i, j, true);
                        return;
                    }

                    int num2 = 0;
                    if (TileRefs(i, j).Wall == 1)
                    {
                        num2 = 26;
                    }
                    if (TileRefs(i, j).Wall == 4)
                    {
                        num2 = 93;
                    }
                    if (TileRefs(i, j).Wall == 5)
                    {
                        num2 = 130;
                    }
                    if (TileRefs(i, j).Wall == 6)
                    {
                        num2 = 132;
                    }
                    if (TileRefs(i, j).Wall == 7)
                    {
                        num2 = 135;
                    }
                    if (TileRefs(i, j).Wall == 8)
                    {
                        num2 = 138;
                    }
                    if (TileRefs(i, j).Wall == 9)
                    {
                        num2 = 140;
                    }
                    if (TileRefs(i, j).Wall == 10)
                    {
                        num2 = 142;
                    }
                    if (TileRefs(i, j).Wall == 11)
                    {
                        num2 = 144;
                    }
                    if (TileRefs(i, j).Wall == 12)
                    {
                        num2 = 146;
                    }
                    if (TileRefs(i, j).Wall == 14)
                    {
                        num2 = 330;
                    }
                    if (TileRefs(i, j).Wall == 16)
                    {
                        num2 = 30;
                    }
                    if (TileRefs(i, j).Wall == 17)
                    {
                        num2 = 135;
                    }
                    if (TileRefs(i, j).Wall == 18)
                    {
                        num2 = 138;
                    }
                    if (TileRefs(i, j).Wall == 19)
                    {
                        num2 = 140;
                    }
                    if (TileRefs(i, j).Wall == 20)
                    {
                        num2 = 330;
                    }
                    if (TileRefs(i, j).Wall == 21)
                    {
                        num2 = 392;
                    }
                    if (TileRefs(i, j).Wall == 22)
                    {
                        num2 = 417;
                    }
                    if (TileRefs(i, j).Wall == 23)
                    {
                        num2 = 418;
                    }
                    if (TileRefs(i, j).Wall == 24)
                    {
                        num2 = 419;
                    }
                    if (TileRefs(i, j).Wall == 25)
                    {
                        num2 = 420;
                    }
                    if (TileRefs(i, j).Wall == 26)
                    {
                        num2 = 421;
                    }
                    if (TileRefs(i, j).Wall == 29)
                    {
                        num2 = 587;
                    }
                    if (TileRefs(i, j).Wall == 30)
                    {
                        num2 = 592;
                    }
                    if (TileRefs(i, j).Wall == 31)
                    {
                        num2 = 595;
                    }
                    if (TileRefs(i, j).Wall == 27)
                    {
                        num2 = 479;
                    }
                    if (num2 > 0)
                    {
                        StorePlayerItem(sandbox, i * 16, j * 16, 16, 16, num2, 1, false, 0);
                    }
                    TileRefs(i, j).SetWall(0);
                    SquareWallFrame(TileRefs, i, j, true);
                }
            }
        }
        public static void Check1xX(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int j, byte type)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (destroyObject)
                return;

            int num = j - (int)(TileRefs(x, j).FrameY / 18);
            int frameX = (int)TileRefs(x, j).FrameX;
            int num2 = 3;

            if (type == 92)
                num2 = 6;

            bool flag = false;
            for (int i = 0; i < num2; i++)
            {
                if (!TileRefs(x, num + i).Active)
                {
                    flag = true;
                }
                else if (TileRefs(x, num + i).Type != type)
                {
                    flag = true;
                }
                else if ((int)TileRefs(x, num + i).FrameY != i * 18)
                {
                    flag = true;
                }
                else if ((int)TileRefs(x, num + i).FrameX != frameX)
                {
                    flag = true;
                }
            }
            if (!TileRefs(x, num + num2).Active)
            {
                flag = true;
            }
            if (!Main.tileSolid[(int)TileRefs(x, num + num2).Type])
            {
                flag = true;
            }
            if (flag)
            {
                destroyObject = true;
                for (int k = 0; k < num2; k++)
                {
                    if (TileRefs(x, num + k).Type == type)
                    {
                        KillTile(TileRefs, sandbox, x, num + k);
                    }
                }
                if (type == 92)
                    StorePlayerItem(sandbox, x * 16, j * 16, 32, 32, 341);
                else if (type == 93)
                    StorePlayerItem(sandbox, x * 16, j * 16, 32, 32, 342);
                destroyObject = false;
            }
        }
        public static void Check1x2Top(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, byte type)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (destroyObject)
                return;

            bool flag = true;

            if (TileRefs(x, y).FrameY == 18)
                y--;

            if (TileRefs(x, y).FrameY == 0
                && TileRefs(x, y + 1).FrameY == 18
                && TileRefs(x, y).Type == type
                && TileRefs(x, y + 1).Type == type)
            {
                flag = false;
            }

            if (!TileRefs(x, y - 1).Active
                || !Main.tileSolid[(int)TileRefs(x, y - 1).Type]
                || Main.tileSolidTop[(int)TileRefs(x, y - 1).Type])
            {
                flag = true;
            }

            if (flag)
            {
                destroyObject = true;
                if (TileRefs(x, y).Type == type)
                    KillTile(TileRefs, sandbox, x, y);

                if (TileRefs(x, y + 1).Type == type)
                    KillTile(TileRefs, sandbox, x, y + 1);

                if (type == 42)
                    StorePlayerItem(sandbox, x * 16, y * 16, 32, 32, 136);

                destroyObject = false;
            }
        }
Example #31
0
 public SandboxHost(ISandbox sandbox)
 {
     _instance  = sandbox;
     _realmName = _instance.RealmName[0] == '|' ? _instance.RealmName.Substring(10) : _instance.RealmName; //Remove colour code
 }
Example #32
0
 public ScenarioDataStoreInitProcessor(ISandbox sandbox) : base(sandbox)
 {
     DataStoreType = "Scenario";
 }
Example #33
0
        public void Run()
        {
            EnumerableEx.Repeat(this._sandbox)
                .Do(s => Console.Write("yacq[{0}]> ", s.History.Count))
                .Select(s => (Console.ForegroundColor = ConsoleColor.White)
                    .Let(_ => Console.ReadLine())
                    .Apply(_ => Console.ResetColor())
                    .If(l => l == null, l => ":exit")
                    .If(
                        l => l.FirstOrDefault() == ':' && !l.StartsWith(":<<"),
                        l => l.Substring(1).Split(' ').Let(_ =>
                        {
                            switch (_[0])
                            {
                                case "exit":
                                    Environment.Exit(0);
                                    return "";
                                case "sandbox":
                                    this._manager.Unload(this._sandbox);
                                    this._sandbox = this._manager.CreateSandbox();
                                    return "(type 'System.AppDomain').CurrentDomain.FriendlyName";
                                case "privileged":
                                    this._manager.Unload(this._sandbox);
                                    this._sandbox = this._manager.DefaultSandbox;
                                    return "(type 'System.AppDomain').CurrentDomain.FriendlyName";
                                default:
                                    return "";
                            }
                        })
                    )
                    .If(
                        l => l.StartsWith(":<<"),
                        h => EnumerableEx.Repeat(Unit.Default)
                            .Do(_ => Console.Write("yacq[{0}]| ", _sandbox.History.Count))
                            .Select(_ => (Console.ForegroundColor = ConsoleColor.White)
                                .Let(__ => Console.ReadLine())
                                .Apply(l => Console.ResetColor())
                            )
                            .TakeWhile(l => l != h.Substring(3)),
                        EnumerableEx.Return
                    )
                )
                .Select(ls => String.Join(Environment.NewLine, ls))
                .Where(s => !String.IsNullOrWhiteSpace(s))
                .Select(s => this._sandbox.Evaluate(s))
                .Do(u =>
                {
                    u.Tag = (this._sandbox.History.Count - 1).ToString();
                    u.Logs.Subscribe(e =>
                    {
                        WriteHeader(u.Tag, e.Timestamp);
                        WriteLine(e.Color, e.Body);
                    });
                    u.ParsedExpressions
                        .Subscribe(e =>
                        {
                            WriteHeader(u.Tag, e.Timestamp);
                            Write(ConsoleColor.Gray, "parsed: ");
                            Write(ConsoleColor.DarkCyan, "{0} => {1} = ", e.Node.GetType().Name, e.Type);
                            WriteLine(ConsoleColor.Cyan, e.Node.ToString());
                        });
                    u.ReturnedValues
                        .Catch(Observable.Never<ReturnedValue>())
                        .Subscribe(v =>
                        {
                            WriteHeader(u.Tag, v.Timestamp);
                            Write(ConsoleColor.Gray, "returned: ");
                            if (v.Value != null)
                            {
                                Write(ConsoleColor.DarkGreen, TypeRef.Serialize(v.Value.GetType()).ToString());
                                var stringified = v.Value.GetType().GetMethod("ToString", Type.EmptyTypes).DeclaringType != typeof(Object);
                                if (stringified)
                                {
                                    Write(ConsoleColor.DarkGreen, " = ");
                                    if (v.Value is Expression)
                                    {
                                        Write(ConsoleColor.Green, Node.Serialize((Expression) v.Value).ToString());
                                    }
                                    else
                                    {
                                        Write(ConsoleColor.Green, v.Value.ToString());
                                    }
                                }

                                if (!(v.Value is String) && v.Value.GetType().GetInterface("IEnumerable") != null)
                                {
                                    Write(ConsoleColor.DarkGreen, (stringified ? " [" : " = [") + Environment.NewLine + "    ");
                                    ((IEnumerable) v.Value)
                                        .Cast<Object>()
                                        .Take(ReplSymbols.DumpLimit + 1)
                                        .ToArray()
                                        .ForEach((e, i) =>
                                        {
                                            var line = Console.CursorTop;
                                            if (Console.CursorLeft == 0)
                                            {
                                                Console.Write("    ");
                                            }
                                            if (i < ReplSymbols.DumpLimit)
                                            {
                                                Write(
                                                    ConsoleColor.Green,
                                                    e != null ? e.ToString() : "(null)"
                                                    );
                                                Write(ConsoleColor.DarkGreen, ", ");
                                            }
                                            else
                                            {
                                                Write(ConsoleColor.DarkGreen, "(more...)");
                                            }
                                            if (Console.CursorTop != line || Console.CursorLeft > Console.BufferWidth * 0.8)
                                            {
                                                Console.WriteLine();
                                            }
                                        });
                                    Write(ConsoleColor.DarkGreen, Environment.NewLine + "  ]");
                                }
                            }
                            else
                            {
                                Write(ConsoleColor.DarkGreen, "null");
                            }
                            Console.WriteLine();
                        });
                })
                .ForEach(u => u.Start());
        }
        public static bool meteor(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (x < 50 || x > Main.maxTilesX - 50)
                return false;

            if (y < 50 || y > Main.maxTilesY - 50)
                return false;

            Rectangle rectangle = new Rectangle((x - RECTANGLE_OFFSET) * TILE_SCALE, (y - RECTANGLE_OFFSET) * TILE_SCALE,
                RECTANGLE_OFFSET * 2 * TILE_SCALE, RECTANGLE_OFFSET * 2 * TILE_SCALE);

            BaseEntity entity;
            for (int i = 0; i < Main.MAX_PLAYERS; i++)
            {
                entity = Main.players[i];
                if (entity.Active && entity.Intersects(rectangle))
                    return false;
            }

            for (int i = 0; i < NPC.MAX_NPCS; i++)
            {
                entity = Main.npcs[i];
                if (entity.Active && entity.Intersects(rectangle))
                    return false;
            }

            for (int modX = x - RECTANGLE_OFFSET; modX < x + RECTANGLE_OFFSET; modX++)
            {
                for (int modY = y - RECTANGLE_OFFSET; modY < y + RECTANGLE_OFFSET; modY++)
                {
                    if (TileRefs(modX, modY).Active && TileRefs(modX, modY).Type == 21)
                        return false;
                }
            }

            stopDrops = true;
            for (int num2 = x - TILE_OFFSET; num2 < x + TILE_OFFSET; num2++)
            {
                for (int num3 = y - TILE_OFFSET; num3 < y + TILE_OFFSET; num3++)
                {
                    if (num3 > y + Main.rand.Next(-2, 3) - 5 && (double)(Math.Abs(x - num2) + Math.Abs(y - num3)) < (double)TILE_OFFSET * 1.5 + (double)Main.rand.Next(-5, 5))
                    {
                        if (!Main.tileSolid[(int)TileRefs(num2, num3).Type])
                            TileRefs(num2, num3).SetActive(false);

                        TileRefs(num2, num3).SetType(37);
                    }
                }
            }

            for (int num4 = x - TILES_OFFSET_2; num4 < x + TILES_OFFSET_2; num4++)
            {
                for (int num5 = y - TILES_OFFSET_2; num5 < y + TILES_OFFSET_2; num5++)
                {
                    if (num5 > y + Main.rand.Next(-2, 3) - 5 && Math.Abs(x - num4) + Math.Abs(y - num5) < TILES_OFFSET_2 + Main.rand.Next(-3, 4))
                        TileRefs(num4, num5).SetActive(false);
                }
            }

            for (int num6 = x - TILE_OFFSET_3; num6 < x + TILE_OFFSET_3; num6++)
            {
                for (int num7 = y - TILE_OFFSET_3; num7 < y + TILE_OFFSET_3; num7++)
                {
                    if (TileRefs(num6, num7).Type == 5 || TileRefs(num6, num7).Type == 32)
                        KillTile(TileRefs, sandbox, num6, num7);

                    SquareTileFrame(TileRefs, sandbox, num6, num7, true);
                    SquareWallFrame(TileRefs, num6, num7, true);
                }
            }

            for (int num8 = x - TILE_OFFSET_4; num8 < x + TILE_OFFSET_4; num8++)
            {
                for (int num9 = y - TILE_OFFSET_4; num9 < y + TILE_OFFSET_4; num9++)
                {
                    if (TileRefs(num8, num9).Active && Main.rand.Next(10) == 0 && (double)(Math.Abs(x - num8) + Math.Abs(y - num9)) < (double)TILE_OFFSET_4 * 1.3)
                    {
                        if (TileRefs(num8, num9).Type == 5 || TileRefs(num8, num9).Type == 32)
                            KillTile(TileRefs, sandbox, num8, num9);

                        TileRefs(num8, num9).SetType(37);
                        SquareTileFrame(TileRefs, sandbox, num8, num9, true);
                    }
                }
            }
            stopDrops = false;

            NetMessage.SendData(25, -1, -1, "A meteorite has landed!", 255, 50f, 255f, 130f);
            NetMessage.SendTileSquare(-1, x, y, 30);
            return true;
        }
        public static Vector2 HurtTiles(Func <Int32, Int32, ITile> TileRefs, ISandbox sandbox, Vector2 Position, Vector2 Velocity, int Width, int Height, bool fireImmune = false)
        {
            if (TileRefs == null)
            {
                TileRefs = TileCollection.ITileAt;
            }

            int left   = (int)(Position.X / 16f) - 1;
            int right  = (int)((Position.X + (float)Width) / 16f) + 2;
            int top    = (int)(Position.Y / 16f) - 1;
            int bottom = (int)((Position.Y + (float)Height) / 16f) + 2;

            if (left < 0)
            {
                left = 0;
            }
            if (right > Main.maxTilesX)
            {
                right = Main.maxTilesX;
            }
            if (top < 0)
            {
                top = 0;
            }
            if (bottom > Main.maxTilesY)
            {
                bottom = Main.maxTilesY;
            }
            for (int i = left; i < right; i++)
            {
                for (int j = top; j < bottom; j++)
                {
                    if (TileRefs(i, j).Active&& (TileRefs(i, j).Type == 32 || TileRefs(i, j).Type == 37 || TileRefs(i, j).Type == 48 || TileRefs(i, j).Type == 53 || TileRefs(i, j).Type == 57 || TileRefs(i, j).Type == 58 || TileRefs(i, j).Type == 59 || TileRefs(i, j).Type == 69 || TileRefs(i, j).Type == 76 || TileRefs(i, j).Type == 80))
                    {
                        Vector2 vector2;
                        vector2.X = (float)(i * 16);
                        vector2.Y = (float)(j * 16);
                        int Y    = 0;
                        int type = (int)TileRefs(i, j).Type;
                        if (type == 32 || type == 69 || type == 80)
                        {
                            if (Position.X + (float)Width > vector2.X && Position.X < vector2.X + 16f && Position.Y + (float)Height > vector2.Y && (double)Position.Y < (double)vector2.Y + 16.01)
                            {
                                int directionX = 1;
                                if (Position.X + (float)(Width / 2) < vector2.X + 8f)
                                {
                                    directionX = -1;
                                }

                                Y = 10;
                                if (type == 69)
                                {
                                    Y = 17;
                                }
                                else if (type == 80)
                                {
                                    Y = 6;
                                }
                                if (type == 32 || type == 69)
                                {
                                    WorldModify.KillTile(TileRefs, sandbox, i, j);
                                }

                                return(new Vector2((float)directionX, (float)Y));
                            }
                        }
                        else if (type == 53 || type == 112 || type == 116 || type == 123)
                        {
                            if (Position.X + (float)Width - 2f >= vector2.X && Position.X + 2f <= vector2.X + 16f && Position.Y + (float)Height - 2f >= vector2.Y && Position.Y + 2f <= vector2.Y + 16f)
                            {
                                int directionX = 1;
                                if (Position.X + (float)(Width / 2) < vector2.X + 8f)
                                {
                                    directionX = -1;
                                }

                                Y = 20;
                                return(new Vector2((float)directionX, (float)Y));
                            }
                        }
                        else if (Position.X + (float)Width >= vector2.X && Position.X <= vector2.X + 16f && Position.Y + (float)Height >= vector2.Y && (double)Position.Y <= (double)vector2.Y + 16.01)
                        {
                            int directionX = 1;
                            if (Position.X + (float)(Width / 2) < vector2.X + 8f)
                            {
                                directionX = -1;
                            }

                            if (!fireImmune && (type == 37 || type == 58 || type == 76))
                            {
                                Y = 20;
                            }
                            if (type == 48)
                            {
                                Y = 40;
                            }

                            return(new Vector2((float)directionX, (float)Y));
                        }
                    }
                }
            }
            return(default(Vector2));
        }
        public static void Check2x1(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, byte type)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (destroyObject)
                return;

            bool flag = true;

            if (TileRefs(x, y).FrameX == 18)
                x--;

            if (TileRefs(x, y).FrameX == 0
                && TileRefs(x + 1, y).FrameX == 18
                && TileRefs(x, y).Type == type
                && TileRefs(x + 1, y).Type == type)
            {
                flag = false;
            }

            if (type == 29 || type == 103)
            {
                if (!TileRefs(x, y + 1).Active || !Main.tileTable[(int)TileRefs(x, y + 1).Type])
                {
                    flag = true;
                }
                if (!TileRefs(x + 1, y + 1).Active || !Main.tileTable[(int)TileRefs(x + 1, y + 1).Type])
                {
                    flag = true;
                }
            }
            else
            {
                if (!TileRefs(x, y + 1).Active || !Main.tileSolid[(int)TileRefs(x, y + 1).Type])
                {
                    flag = true;
                }
                if (!TileRefs(x + 1, y + 1).Active || !Main.tileSolid[(int)TileRefs(x + 1, y + 1).Type])
                {
                    flag = true;
                }
            }

            if (flag)
            {
                destroyObject = true;
                if (TileRefs(x, y).Type == type)
                {
                    KillTile(TileRefs, sandbox, x, y);
                }
                if (TileRefs(x + 1, y).Type == type)
                {
                    KillTile(TileRefs, sandbox, x + 1, y);
                }
                if (type == 16)
                {
                    StorePlayerItem(sandbox, x * TILE_OFFSET_3, y * TILE_OFFSET_3, 32, 32, 35, 1, false);
                }
                if (type == 18)
                {
                    StorePlayerItem(sandbox, x * TILE_OFFSET_3, y * TILE_OFFSET_3, 32, 32, 36, 1, false);
                }
                if (type == 29)
                {
                    StorePlayerItem(sandbox, x * TILE_OFFSET_3, y * TILE_OFFSET_3, 32, 32, 87, 1, false);
                }
                if (type == 103)
                {
                    StorePlayerItem(sandbox, x * TILE_OFFSET_3, y * TILE_OFFSET_3, 32, 32, 356, 1, false);
                }
                destroyObject = false;
                SquareTileFrame(TileRefs, sandbox, x, y, true);
                SquareTileFrame(TileRefs, sandbox, x + 1, y, true);
            }
        }
        public static void RangeFrame(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int startX, int startY, int endX, int endY)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            int num = endX + 1;
            int num2 = endY + 1;
            for (int i = startX - 1; i < num + 1; i++)
            {
                for (int j = startY - 1; j < num2 + 1; j++)
                {
                    TileFrame(TileRefs, sandbox, i, j);
                    WallFrame(TileRefs, i, j);
                }
            }
        }
Example #38
0
 public SpecExecutionStartingProcessor(IHookRegistry hookRegistry, IMethodExecutor methodExecutor, ISandbox sandbox)
     : base(hookRegistry, methodExecutor)
 {
     _sandbox = sandbox;
 }
        public static void SmashAltar(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (!Main.hardMode || noTileActions || gen)
                return;

            int num = altarCount % 3;
            int num2 = altarCount / 3 + 1;
            float num3 = (float)(Main.maxTilesX / 4200);
            int num4 = 1 - num;
            num3 = num3 * 310f - (float)(85 * num);
            num3 *= 0.85f;
            num3 /= (float)num2;
            if (num == 0)
            {

                NetMessage.SendData(25, -1, -1, "Your world has been blessed with Cobalt!", 255, 50f, 255f, 130f, 0);
                num = 107;
                num3 *= 1.05f;
            }
            else if (num == 1)
            {
                NetMessage.SendData(25, -1, -1, "Your world has been blessed with Mythril!", 255, 50f, 255f, 130f, 0);
                num = 108;
            }
            else
            {
                NetMessage.SendData(25, -1, -1, "Your world has been blessed with Adamantite!", 255, 50f, 255f, 130f, 0);
                num = 111;
            }

            int num5 = 0;
            while ((float)num5 < num3)
            {
                int i2 = genRand.Next(100, Main.maxTilesX - 100);
                double num6 = Main.worldSurface;
                if (num == 108)
                {
                    num6 = Main.rockLayer;
                }
                if (num == 111)
                {
                    num6 = (Main.rockLayer + Main.rockLayer + (double)Main.maxTilesY) / 3.0;
                }
                int j2 = genRand.Next((int)num6, Main.maxTilesY - 150);
                OreRunner(TileRefs, sandbox, i2, j2, (double)genRand.Next(5, 9 + num4), genRand.Next(5, 9 + num4), num);
                num5++;
            }
            int num7 = genRand.Next(3);
            while (num7 != 2)
            {
                int num8 = genRand.Next(100, Main.maxTilesX - 100);
                int num9 = genRand.Next((int)Main.rockLayer + 50, Main.maxTilesY - 300);
                if (TileRefs(num8, num9).Active && TileRefs(num8, num9).Type == 1)
                {
                    if (num7 == 0)
                    {
                        TileRefs(num8, num9).SetType(25);
                    }
                    else
                    {
                        TileRefs(num8, num9).SetType(117);
                    }

                    NetMessage.SendTileSquare(-1, num8, num9, 1);
                    break;

                }
            }

            int num10 = Main.rand.Next(2) + 1;
            for (int k = 0; k < num10; k++)
            {
                var playerId = (int)Player.FindClosest(new Vector2((float)(i * 16), (float)(j * 16)), 16, 16);
                var player = Main.players[playerId];
                NPC.SpawnOnPlayer(playerId, (int)NPCType.N82_WRAITH);
            }

            altarCount++;
        }
        /// <summary>
        /// Moves the projectile according to the projectile's motion parameters, or AI
        /// </summary>
        public void AI(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            switch (this.aiStyle)
            {
                case 1:
                    {
                        if (this.type == ProjectileType.N20_GREEN_LASER || this.type == ProjectileType.N14_BULLET ||
                            this.type == ProjectileType.N36_METEOR_SHOT || this.type == ProjectileType.N83_EYE_LASER ||
                            this.type == ProjectileType.N84_PINK_LASER || this.type == ProjectileType.N89_CRYSTAL_BULLET ||
                            this.type == ProjectileType.N100_DEATH_LASER || this.type == ProjectileType.N104_CURSED_BULLET)
                        {
                            if (this.alpha > 0)
                            {
                                this.alpha -= 15;
                            }
                            if (this.alpha < 0)
                            {
                                this.alpha = 0;
                            }
                        }
                        if (this.type == ProjectileType.N88_PURPLE_LASER)
                        {
                            if (this.alpha > 0)
                                this.alpha -= 10;
                            if (this.alpha < 0)
                                this.alpha = 0;
                        }
                        if (this.type != ProjectileType.N5_JESTERS_ARROW &&
                            this.type != ProjectileType.N14_BULLET &&
                            this.type != ProjectileType.N20_GREEN_LASER &&
                            this.type != ProjectileType.N36_METEOR_SHOT &&
                            this.type != ProjectileType.N38_HARPY_FEATHER &&
                            this.type != ProjectileType.N83_EYE_LASER &&
                            this.type != ProjectileType.N84_PINK_LASER &&
                            this.type != ProjectileType.N88_PURPLE_LASER &&
                            this.type != ProjectileType.N89_CRYSTAL_BULLET &&
                            this.type != ProjectileType.N98_POISON_DART &&
                            this.type != ProjectileType.N100_DEATH_LASER &&
                            this.type != ProjectileType.N104_CURSED_BULLET)
                        {
                            this.ai[0] += 1f;
                        }
                        if (this.type == ProjectileType.N81_WOODEN_ARROW || this.type == ProjectileType.N91_HOLY_ARROW)
                        {
                            if (this.ai[0] >= 20f)
                            {
                                this.ai[0] = 20f;
                                this.Velocity.Y = this.Velocity.Y + 0.07f;
                            }
                        }
                        else
                        {
                            if (this.ai[0] >= 15f)
                            {
                                this.ai[0] = 15f;
                                this.Velocity.Y = this.Velocity.Y + 0.1f;
                            }
                        }
                        this.rotation = (float)Math.Atan2((double)this.Velocity.Y, (double)this.Velocity.X) + 1.57f;
                        if (this.Velocity.Y > 16f)
                        {
                            this.Velocity.Y = 16f;
                            return;
                        }
                    }
                    break;
                case 2:
                    {
                        this.rotation += (Math.Abs(this.Velocity.X) + Math.Abs(this.Velocity.Y)) * 0.03f * (float)this.direction;

                        if (this.type == ProjectileType.N69_HOLY_WATER || this.type == ProjectileType.N70_UNHOLY_WATER)
                        {
                            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
                        {
                            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 == ProjectileType.N48_THROWING_KNIFE || this.type == ProjectileType.N54_POISONED_KNIFE)
                                {
                                    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 == ProjectileType.N54_POISONED_KNIFE && Main.rand.Next(20) == 0)
                        {
                            return;
                        }
                    }
                    break;
                case 3:
                    {
                        if (this.soundDelay == 0)
                        {
                            this.soundDelay = 8;
                        }
                        if (this.ai[0] == 0f)
                        {
                            this.ai[1] += 1f;
                            if (this.type == ProjectileType.N106_LIGHT_DISC)
                            {
                                if (this.ai[1] >= 45f)
                                {
                                    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 num4 = 9f;
                            float num5 = 0.4f;
                            if (this.type == ProjectileType.N19_FLAMARANG)
                            {
                                num4 = 13f;
                                num5 = 0.6f;
                            }
                            else if (this.type == ProjectileType.N33_THORN_CHAKRUM)
                            {
                                num4 = 15f;
                                num5 = 0.8f;
                            }
                            else if (this.type == ProjectileType.N106_LIGHT_DISC)
                            {
                                num4 = 16f;
                                num5 = 1.2f;
                            }
                            Vector2 vector = new Vector2(this.Position.X + (float)this.Width * 0.5f, this.Position.Y + (float)this.Height * 0.5f);
                            float num6 = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - vector.X;
                            float num7 = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - vector.Y;
                            float num8 = (float)Math.Sqrt((double)(num6 * num6 + num7 * num7));
                            num8 = num4 / num8;
                            num6 *= num8;
                            num7 *= num8;
                            if (num8 > 3000f)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                            if (this.Velocity.X < num6)
                            {
                                this.Velocity.X = this.Velocity.X + num5;
                                if (this.Velocity.X < 0f && num6 > 0f)
                                {
                                    this.Velocity.X = this.Velocity.X + num5;
                                }
                            }
                            else
                            {
                                if (this.Velocity.X > num6)
                                {
                                    this.Velocity.X = this.Velocity.X - num5;
                                    if (this.Velocity.X > 0f && num6 < 0f)
                                    {
                                        this.Velocity.X = this.Velocity.X - num5;
                                    }
                                }
                            }
                            if (this.Velocity.Y < num7)
                            {
                                this.Velocity.Y = this.Velocity.Y + num5;
                                if (this.Velocity.Y < 0f && num7 > 0f)
                                {
                                    this.Velocity.Y = this.Velocity.Y + num5;
                                }
                            }
                            else
                            {
                                if (this.Velocity.Y > num7)
                                {
                                    this.Velocity.Y = this.Velocity.Y - num5;
                                    if (this.Velocity.Y > 0f && num7 < 0f)
                                    {
                                        this.Velocity.Y = this.Velocity.Y - num5;
                                    }
                                }
                            }
                            if (Main.myPlayer == this.Owner)
                            {
                                Rectangle rectangle = new Rectangle((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height);
                                if (Main.players[Owner].Intersects(rectangle))
                                {
                                    this.Kill(TileRefs, sandbox);
                                }
                            }
                        }
                        if (this.type == ProjectileType.N106_LIGHT_DISC)
                        {
                            this.rotation += 0.3f * (float)this.direction;
                            return;
                        }
                        this.rotation += 0.4f * (float)this.direction;
                        return;
                    }
                //break;
                case 4:
                    {
                        this.rotation = (float)Math.Atan2((double)this.Velocity.Y, (double)this.Velocity.X) + 1.57f;
                        if (this.ai[0] == 0f)
                        {
                            this.alpha -= 50;
                            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 == ProjectileType.N7_VILETHORN && Main.myPlayer == this.Owner)
                                {
                                    int num9 = (int)this.type;
                                    if (this.ai[1] >= 6f)
                                    {
                                        num9++;
                                    }
                                    int num10 = 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, (ProjectileType)Enum.ToObject(typeof(ProjectileType), num9), this.damage, this.knockBack, this.Owner);
                                    Main.projectile[num10].damage = this.damage;
                                    Main.projectile[num10].ai[1] = this.ai[1] + 1f;
                                    NetMessage.SendData(27, -1, -1, "", num10);
                                    return;
                                }
                            }
                        }
                        else
                        {
                            this.alpha += 5;
                            if (this.alpha >= 255)
                            {
                                this.Kill(TileRefs, sandbox);
                                return;
                            }
                        }
                    }
                    break;
                case 5:
                    {
                        if (this.type == ProjectileType.N92_HALLOW_STAR)
                        {
                            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);
                        }
                        if (this.ai[0] == 0f)
                        {
                            this.ai[0] = 1f;
                        }
                        this.alpha += (int)(25f * this.ai[0]);
                        if (this.alpha > 200)
                        {
                            this.alpha = 200;
                            this.ai[0] = -1f;
                        }
                        if (this.alpha < 0)
                        {
                            this.alpha = 0;
                            this.ai[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 == ProjectileType.N92_HALLOW_STAR)
                        {
                            this.light = 0.9f;
                        }
                    }
                    break;
                case 6:
                    {
                        this.Velocity *= 0.95f;
                        this.ai[0] += 1f;
                        if (this.ai[0] == 180f)
                        {
                            this.Kill(TileRefs, sandbox);
                        }
                        if (this.ai[1] == 0f)
                        {
                            this.ai[1] = 1f;
                        }
                        if (this.type == ProjectileType.N10_PURIFICATION_POWDER || this.type == ProjectileType.N11_VILE_POWDER)
                        {
                            int num11 = (int)(this.Position.X / 16f) - 1;
                            int num12 = (int)((this.Position.X + (float)this.Width) / 16f) + 2;
                            int num13 = (int)(this.Position.Y / 16f) - 1;
                            int num14 = (int)((this.Position.Y + (float)this.Height) / 16f) + 2;
                            if (num11 < 0)
                            {
                                num11 = 0;
                            }
                            if (num12 > Main.maxTilesX)
                            {
                                num12 = Main.maxTilesX;
                            }
                            if (num13 < 0)
                            {
                                num13 = 0;
                            }
                            if (num14 > Main.maxTilesY)
                            {
                                num14 = Main.maxTilesY;
                            }
                            for (int l = num11; l < num12; l++)
                            {
                                for (int m = num13; m < num14; m++)
                                {
                                    Vector2 vector2;
                                    vector2.X = (float)(l * 16);
                                    vector2.Y = (float)(m * 16);

                                    if (this.Position.X + (float)this.Width > vector2.X && this.Position.X < vector2.X + 16f && this.Position.Y + (float)this.Height > vector2.Y && this.Position.Y < vector2.Y + 16f
                                        && (Program.properties.TileSquareMessages != "accept" || Main.myPlayer == this.Owner)
                                        && TileRefs(l, m).Active)
                                    {
                                        if (this.type == ProjectileType.N10_PURIFICATION_POWDER)
                                        {
                                            if (TileRefs(l, m).Type == 23)
                                            {
                                                TileRefs(l, m).SetType(2);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,l, m, true);
                                                NetMessage.SendTileSquare(-1, l, m, 1);
                                            }
                                            if (TileRefs(l, m).Type == 25)
                                            {
                                                TileRefs(l, m).SetType(1);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,l, m, true);
                                                NetMessage.SendTileSquare(-1, l, m, 1);
                                            }
                                            if (TileRefs(l, m).Type == 112)
                                            {
                                                TileRefs(l, m).SetType(53);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,l, m, true);
                                                NetMessage.SendTileSquare(-1, l, m, 1);
                                            }
                                        }
                                        else if (this.type == ProjectileType.N11_VILE_POWDER)
                                        {
                                            if (TileRefs(l, m).Type == 109)
                                            {
                                                TileRefs(l, m).SetType(2);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,l, m, true);
                                                NetMessage.SendTileSquare(-1, l, m, 1);
                                            }
                                            if (TileRefs(l, m).Type == 116)
                                            {
                                                TileRefs(l, m).SetType(53);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,l, m, true);
                                                NetMessage.SendTileSquare(-1, l, m, 1);
                                            }
                                            if (TileRefs(l, m).Type == 117)
                                            {
                                                TileRefs(l, m).SetType(1);
                                                WorldModify.SquareTileFrame(TileRefs, sandbox,l, m, true);
                                                NetMessage.SendTileSquare(-1, l, m, 1);
                                            }
                                        }
                                    }
                                }
                            }
                            return;
                        }
                    }
                    break;
                case 7:
                    {
                        if (Main.players[this.Owner].dead)
                        {
                            this.Kill(TileRefs, sandbox);
                            return;
                        }
                        Vector2 vector3 = new Vector2(this.Position.X + (float)this.Width * 0.5f, this.Position.Y + (float)this.Height * 0.5f);
                        float num15 = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - vector3.X;
                        float num16 = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - vector3.Y;
                        float num17 = (float)Math.Sqrt((double)(num15 * num15 + num16 * num16));
                        this.rotation = (float)Math.Atan2((double)num16, (double)num15) - 1.57f;
                        if (this.ai[0] == 0f)
                        {
                            if ((num17 > 300f && this.type == ProjectileType.N13_HOOK) || (num17 > 400f && this.type == ProjectileType.N32_IVY_WHIP))
                            {
                                this.ai[0] = 1f;
                            }
                            int num18 = (int)(this.Position.X / 16f) - 1;
                            int num19 = (int)((this.Position.X + (float)this.Width) / 16f) + 2;
                            int num20 = (int)(this.Position.Y / 16f) - 1;
                            int num21 = (int)((this.Position.Y + (float)this.Height) / 16f) + 2;
                            if (num18 < 0)
                            {
                                num18 = 0;
                            }
                            if (num19 > Main.maxTilesX)
                            {
                                num19 = Main.maxTilesX;
                            }
                            if (num20 < 0)
                            {
                                num20 = 0;
                            }
                            if (num21 > Main.maxTilesY)
                            {
                                num21 = Main.maxTilesY;
                            }
                            for (int n = num18; n < num19; n++)
                            {
                                int num22 = num20;
                                while (num22 < num21)
                                {
                                    Vector2 vector4;
                                    vector4.X = (float)(n * 16);
                                    vector4.Y = (float)(num22 * 16);
                                    if (this.Position.X + (float)this.Width > vector4.X && this.Position.X < vector4.X + 16f && this.Position.Y + (float)this.Height > vector4.Y && this.Position.Y < vector4.Y + 16f && TileRefs(n, num22).Active && Main.tileSolid[(int)TileRefs(n, num22).Type])
                                    {
                                        if (Main.players[this.Owner].grapCount < 10)
                                        {
                                            Main.players[this.Owner].grappling[Main.players[this.Owner].grapCount] = this.whoAmI;
                                            Main.players[this.Owner].grapCount++;
                                        }
                                        if (Main.myPlayer == this.Owner)
                                        {
                                            int num23 = 0;
                                            int num24 = -1;
                                            int num25 = 100000;
                                            if (this.type == ProjectileType.N73_HOOK || this.type == ProjectileType.N74_HOOK)
                                            {
                                                for (int num31 = 0; num31 < 1000; num31++)
                                                {
                                                    if (num31 != this.whoAmI && Main.projectile[num31].Active && Main.projectile[num31].Owner == this.Owner &&
                                                        Main.projectile[num31].aiStyle == 7 && Main.projectile[num31].ai[0] == 2f)
                                                    {
                                                        Main.projectile[num31].Kill(TileRefs, sandbox);
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                for (int num26 = 0; num26 < 1000; num26++)
                                                {
                                                    if (Main.projectile[num26].Active && Main.projectile[num26].Owner == this.Owner && Main.projectile[num26].aiStyle == 7)
                                                    {
                                                        if (Main.projectile[num26].timeLeft < num25)
                                                        {
                                                            num24 = num26;
                                                            num25 = Main.projectile[num26].timeLeft;
                                                        }
                                                        num23++;
                                                    }
                                                }
                                                if (num23 > 3)
                                                {
                                                    Main.projectile[num24].Kill(TileRefs, sandbox);
                                                }
                                            }
                                        }
                                        var plr = Creator as Player;
                                        if (plr == null || WorldModify.InvokeAlterationHook(this, plr, n, num22, 0))
                                        {
                                            WorldModify.KillTile(TileRefs, sandbox, n, num22, true, true);
                                        }
                                        this.Velocity.X = 0f;
                                        this.Velocity.Y = 0f;
                                        this.ai[0] = 2f;
                                        this.Position.X = (float)(n * 16 + 8 - this.Width / 2);
                                        this.Position.Y = (float)(num22 * 16 + 8 - this.Height / 2);
                                        this.damage = 0;
                                        this.netUpdate = true;
                                        if (Main.myPlayer == this.Owner)
                                        {
                                            NetMessage.SendData(13, -1, -1, "", this.Owner);
                                            break;
                                        }
                                        break;
                                    }
                                    else
                                    {
                                        num22++;
                                    }
                                }
                                if (this.ai[0] == 2f)
                                {
                                    return;
                                }
                            }
                            return;
                        }
                        if (this.ai[0] == 1f)
                        {
                            float num27 = 11f;
                            if (this.type == ProjectileType.N32_IVY_WHIP)
                            {
                                num27 = 15f;
                            }
                            if (this.type == ProjectileType.N73_HOOK || this.type == ProjectileType.N74_HOOK)
                            {
                                num27 = 17f;
                            }
                            if (num17 < 24f)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                            num17 = num27 / num17;
                            num15 *= num17;
                            num16 *= num17;
                            this.Velocity.X = num15;
                            this.Velocity.Y = num16;
                            return;
                        }
                        if (this.ai[0] == 2f)
                        {
                            int num28 = (int)(this.Position.X / 16f) - 1;
                            int num29 = (int)((this.Position.X + (float)this.Width) / 16f) + 2;
                            int num30 = (int)(this.Position.Y / 16f) - 1;
                            int num31 = (int)((this.Position.Y + (float)this.Height) / 16f) + 2;
                            if (num28 < 0)
                            {
                                num28 = 0;
                            }
                            if (num29 > Main.maxTilesX)
                            {
                                num29 = Main.maxTilesX;
                            }
                            if (num30 < 0)
                            {
                                num30 = 0;
                            }
                            if (num31 > Main.maxTilesY)
                            {
                                num31 = Main.maxTilesY;
                            }
                            bool flag = true;
                            for (int num32 = num28; num32 < num29; num32++)
                            {
                                for (int num33 = num30; num33 < num31; num33++)
                                {
                                    Vector2 vector5;
                                    vector5.X = (float)(num32 * 16);
                                    vector5.Y = (float)(num33 * 16);
                                    if (this.Position.X + (float)(this.Width / 2) > vector5.X && this.Position.X + (float)(this.Width / 2) < vector5.X + 16f && this.Position.Y + (float)(this.Height / 2) > vector5.Y && this.Position.Y + (float)(this.Height / 2) < vector5.Y + 16f && TileRefs(num32, num33).Active && Main.tileSolid[(int)TileRefs(num32, num33).Type])
                                    {
                                        flag = false;
                                    }
                                }
                            }
                            if (flag)
                            {
                                this.ai[0] = 1f;
                                return;
                            }
                            if (Main.players[this.Owner].grapCount < 10)
                            {
                                Main.players[this.Owner].grappling[Main.players[this.Owner].grapCount] = this.whoAmI;
                                Main.players[this.Owner].grapCount++;
                                return;
                            }
                        }
                    }
                    break;
                case 8:
                    {
                        if (this.type == ProjectileType.N96_CURSED_FLAME && this.ai[0] == 0f)
                        {
                            this.ai[0] = 1f;
                        }
                        if (this.type != ProjectileType.N27_WATER_BOLT && this.type != ProjectileType.N96_CURSED_FLAME)
                        {
                            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;
                            return;
                        }
                    }
                    break;
                case 9:
                    {
                        if (Main.myPlayer == this.Owner && this.ai[0] == 0f)
                        {
                            // client-code, not updated from 1.0.6
                            if (!Main.players[this.Owner].channel)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                        }
                        if (this.type == ProjectileType.N34_FLAMELASH)
                        {
                            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;
                            return;
                        }
                    }
                    break;
                case 10:
                    {
                        if (Main.myPlayer == this.Owner && this.ai[0] == 0f)
                        {
                            // client-code, not updated from 1.0.6
                            if (!Main.players[this.Owner].channel)
                            {
                                this.ai[0] = 1f;
                                this.netUpdate = true;
                            }
                        }
                        if (this.ai[0] == 1f)
                        {
                            if (this.type == ProjectileType.N42_SAND_BALL ||
                                this.type == ProjectileType.N65_EBONSAND_BALL ||
                                this.type == ProjectileType.N68_PEARL_SAND_BALL)
                            {
                                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.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;
                            return;
                        }
                    }
                    break;
                case 11:
                    {
                        if (this.type == ProjectileType.N72_BLUE_FAIRY || this.type == ProjectileType.N86_PINK_FAIRY || this.type == ProjectileType.N87_PINK_FAIRY)
                        {
                            if (this.Velocity.X > 0f)
                            {
                                this.direction = -1;
                            }
                            else if (this.Velocity.X < 0f)
                            {
                                this.direction = 1;
                            }
                            this.rotation = this.Velocity.X * 0.1f;
                        }
                        else
                        {
                            this.rotation += 0.02f;
                        }
                        if (Main.myPlayer == this.Owner)
                        {
                            if (this.type == ProjectileType.N72_BLUE_FAIRY || this.type == ProjectileType.N86_PINK_FAIRY || this.type == ProjectileType.N87_PINK_FAIRY)
                            {
                                // [TODO] 1.1 : double check the player class
                                if (Main.players[this.Owner].fairy)
                                {
                                    this.timeLeft = 2;
                                }
                            }
                            else
                            {
                                if (Main.players[this.Owner].lightOrb)
                                {
                                    this.timeLeft = 2;
                                }
                            }
                            if (Main.players[this.Owner].dead)
                            {
                                this.Kill(TileRefs, sandbox);
                                return;
                            }
                            float num51 = 2.5f;
                            int num81 = 70;
                            if (this.type == ProjectileType.N72_BLUE_FAIRY || this.type == ProjectileType.N86_PINK_FAIRY || this.type == ProjectileType.N87_PINK_FAIRY)
                            {
                                num51 = 3.5f;
                                num81 = 40;
                            }
                            Vector2 vector8 = new Vector2(this.Position.X + (float)this.Width * 0.5f, this.Position.Y + (float)this.Height * 0.5f);
                            float num52 = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - vector8.X;
                            float num53 = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - vector8.Y;
                            float num54 = (float)Math.Sqrt((double)(num52 * num52 + num53 * num53));
                            num54 = (float)Math.Sqrt((double)(num52 * num52 + num53 * num53));
                            if (num54 > 800f)
                            {
                                this.Position.X = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - (float)(this.Width / 2);
                                this.Position.Y = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - (float)(this.Height / 2);
                                return;
                            }
                            if (num54 > (float)num81)
                            {
                                num54 = num51 / num54;
                                num52 *= num54;
                                num53 *= num54;
                                // [TODO] 1.1 - double check this area of code in aiStyle 11
                                // Commented out in 1.1
                                //if (num52 != this.Velocity.X || num53 != this.Velocity.Y)
                                //{
                                //   this.netUpdate = true;
                                //}
                                this.Velocity.X = num52;
                                this.Velocity.Y = num53;
                                return;
                            }
                            // Commented out in 1.1
                            //if (this.Velocity.X != 0f || this.Velocity.Y != 0f)
                            //{
                            //    this.netUpdate = true;
                            //}
                            this.Velocity.X = 0f;
                            this.Velocity.Y = 0f;
                            return;
                        }
                    }
                    break;
                case 12:
                    {
                        this.scale -= 0.04f;
                        if (this.scale <= 0f)
                        {
                            this.Kill(TileRefs, sandbox);
                        }
                        if (this.ai[0] > 4f)
                        {
                            this.alpha = 150;
                            this.light = 0.8f;
                        }
                        else
                        {
                            this.ai[0] += 1f;
                        }
                        this.rotation += 0.3f * (float)this.direction;
                        return;
                    }
                //break;
                case 13:
                    {
                        if (Main.players[this.Owner].dead)
                        {
                            this.Kill(TileRefs, sandbox);
                            return;
                        }
                        Main.players[this.Owner].itemAnimation = 5;
                        Main.players[this.Owner].itemTime = 5;
                        if (this.Position.X + (float)(this.Width / 2) > Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2))
                        {
                            Main.players[this.Owner].direction = 1;
                        }
                        else
                        {
                            Main.players[this.Owner].direction = -1;
                        }
                        Vector2 vector9 = new Vector2(this.Position.X + (float)this.Width * 0.5f, this.Position.Y + (float)this.Height * 0.5f);
                        float num56 = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - vector9.X;
                        float num57 = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - vector9.Y;
                        float num58 = (float)Math.Sqrt((double)(num56 * num56 + num57 * num57));
                        if (this.ai[0] == 0f)
                        {
                            if (num58 > 700f)
                            {
                                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] > 2f)
                            {
                                this.alpha = 0;
                            }
                            if (this.ai[1] >= 10f)
                            {
                                this.ai[1] = 15f;
                                this.Velocity.Y = this.Velocity.Y + 0.3f;
                                return;
                            }
                        }
                        else
                        {
                            if (this.ai[0] == 1f)
                            {
                                this.tileCollide = false;
                                this.rotation = (float)Math.Atan2((double)num57, (double)num56) - 1.57f;
                                float num59 = 11f;
                                if (num58 < 50f)
                                {
                                    this.Kill(TileRefs, sandbox);
                                }
                                num58 = num59 / num58;
                                num56 *= num58;
                                num57 *= num58;
                                this.Velocity.X = num56;
                                this.Velocity.Y = num57;
                                return;
                            }
                        }
                    }
                    break;
                case 14:
                    {
                        if (this.type == ProjectileType.N53_STICKY_GLOWSTICK)
                        {
                            try
                            {
                                Vector2 vector10 = Collision.TileCollision(this.Position, this.Velocity, this.Width, this.Height, false, false);
                                bool flag1 = this.Velocity != vector10;
                                int num66 = ((int)(this.Position.X / 16f)) - 1;
                                int num67 = ((int)((this.Position.X + this.Width) / 16f)) + 2;
                                int num68 = ((int)(this.Position.Y / 16f)) - 1;
                                int num69 = ((int)((this.Position.Y + this.Height) / 16f)) + 2;
                                if (num66 < 0)
                                {
                                    num66 = 0;
                                }
                                if (num67 > Main.maxTilesX)
                                {
                                    num67 = Main.maxTilesX;
                                }
                                if (num68 < 0)
                                {
                                    num68 = 0;
                                }
                                if (num69 > Main.maxTilesY)
                                {
                                    num69 = Main.maxTilesY;
                                }
                                for (int num70 = num66; num70 < num67; num70++)
                                {
                                    for (int num71 = num68; num71 < num69; num71++)
                                    {
                                        if ((TileRefs(num70, num71).Active) && (Main.tileSolid[TileRefs(num70, num71).Type] || (Main.tileSolidTop[TileRefs(num70, num71).Type] && (TileRefs(num70, num71).FrameY == 0))))
                                        {
                                            Vector2 vector11;
                                            vector11.X = num70 * 0x10;
                                            vector11.Y = num71 * 0x10;
                                            if ((((this.Position.X + this.Width) > vector11.X) && (this.Position.X < (vector11.X + 16f))) && (((this.Position.Y + this.Height) > vector11.Y) && (this.Position.Y < (vector11.Y + 16f))))
                                            {
                                                this.Velocity.X = 0f;
                                                this.Velocity.Y = -0.2f;
                                            }
                                        }
                                    }
                                }
                            }
                            catch
                            {
                            }
                        }

                        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.Velocity.Y > 16f)
                        {
                            this.Velocity.Y = 16f;
                            return;
                        }
                    }
                    break;
                case 15:
                    {
                        if (Main.players[this.Owner].dead)
                        {
                            this.Kill(TileRefs, sandbox);
                            return;
                        }
                        Main.players[this.Owner].itemAnimation = 10;
                        Main.players[this.Owner].itemTime = 10;
                        if (this.Position.X + (float)(this.Width / 2) > Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2))
                        {
                            Main.players[this.Owner].direction = 1;
                            this.direction = 1;
                        }
                        else
                        {
                            Main.players[this.Owner].direction = -1;
                            this.direction = -1;
                        }
                        Vector2 vector11 = new Vector2(this.Position.X + (float)this.Width * 0.5f, this.Position.Y + (float)this.Height * 0.5f);
                        float num73 = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - vector11.X;
                        float num74 = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - vector11.Y;
                        float num75 = (float)Math.Sqrt((double)(num73 * num73 + num74 * num74));

                        if (this.ai[0] == 0f)
                        {
                            float num98 = 160f;
                            if (this.type == ProjectileType.N63_THE_DAO_OF_POW)
                            {
                                num98 *= 1.5f;
                            }
                            this.tileCollide = true;
                            if (num75 > num98)
                            {
                                this.ai[0] = 1f;
                                this.netUpdate = true;
                            }
                            else
                            {
                                if (!Main.players[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)
                            {
                                var owner = Main.players[this.Owner];
                                float num76 = 14f / owner.meleeSpeed;
                                float num77 = 0.9f / owner.meleeSpeed;
                                float num101 = 300f;
                                if (this.type == ProjectileType.N63_THE_DAO_OF_POW)
                                {
                                    num101 *= 1.5f;
                                    num76 *= 1.5f;
                                    num77 *= 1.5f;
                                }
                                Math.Abs(num73);
                                Math.Abs(num74);
                                if (this.ai[1] == 1f)
                                {
                                    this.tileCollide = false;
                                }
                                if (!owner.channel || num75 > num101 || !this.tileCollide)
                                {
                                    this.ai[1] = 1f;
                                    if (this.tileCollide)
                                    {
                                        this.netUpdate = true;
                                    }
                                    this.tileCollide = false;
                                    if (num75 < 20f)
                                    {
                                        this.Kill(TileRefs, sandbox);
                                    }
                                }
                                if (!this.tileCollide)
                                {
                                    num77 *= 2f;
                                }
                                if (num75 > 60f || !this.tileCollide)
                                {
                                    num75 = num76 / num75;
                                    num73 *= num75;
                                    num74 *= num75;
                                    float num78 = num73 - this.Velocity.X;
                                    float num79 = num74 - this.Velocity.Y;
                                    float num80 = (float)Math.Sqrt((double)(num78 * num78 + num79 * num79));
                                    num80 = num77 / num80;
                                    num78 *= num80;
                                    num79 *= num80;
                                    this.Velocity.X = this.Velocity.X * 0.98f;
                                    this.Velocity.Y = this.Velocity.Y * 0.98f;
                                    this.Velocity.X = this.Velocity.X + num78;
                                    this.Velocity.Y = this.Velocity.Y + num79;
                                }
                                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 (owner.Velocity.X == 0f)
                                    {
                                        this.Velocity.X = this.Velocity.X * 0.96f;
                                    }
                                }
                            }
                        }
                        this.rotation = (float)Math.Atan2((double)num74, (double)num73) - this.Velocity.X * 0.1f;
                        return;
                    }
                //break;
                case 16:
                    {
                        if (this.type == ProjectileType.N108_EXPLOSIVES)
                        {
                            this.ai[0] += 1f;
                            if (this.ai[0] > 3f)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                        }
                        if (this.type == ProjectileType.N37_STICKY_BOMB)
                        {
                            try
                            {
                                int num105 = (int)(this.Position.X / 16f) - 1;
                                int num106 = (int)((this.Position.X + (float)this.Width) / 16f) + 2;
                                int num107 = (int)(this.Position.Y / 16f) - 1;
                                int num108 = (int)((this.Position.Y + (float)this.Height) / 16f) + 2;
                                if (num105 < 0)
                                {
                                    num105 = 0;
                                }
                                if (num106 > Main.maxTilesX)
                                {
                                    num106 = Main.maxTilesX;
                                }
                                if (num107 < 0)
                                {
                                    num107 = 0;
                                }
                                if (num108 > Main.maxTilesY)
                                {
                                    num108 = Main.maxTilesY;
                                }
                                for (int num109 = num105; num109 < num106; num109++)
                                {
                                    for (int num110 = num107; num110 < num108; num110++)
                                    {
                                        var tile = Main.tile.At (num109, num110);
                                        if (tile.Exists && tile.Active && (Main.tileSolid[(int)tile.Type] ||
                                                                       (Main.tileSolidTop[(int)tile.Type] &&
                                     		tile.FrameY == 0)))
                                        {
                                            Vector2 vector14;
                                            vector14.X = (float)(num109 * 16);
                                            vector14.Y = (float)(num110 * 16);
                                            if (this.Position.X + (float)this.Width - 4f > vector14.X &&
                                            this.Position.X + 4f < vector14.X + 16f && this.Position.Y +
                                            (float)this.Height - 4f > vector14.Y && this.Position.Y + 4f < vector14.Y + 16f)
                                            {
                                                this.Velocity.X = 0f;
                                                this.Velocity.Y = -0.2f;
                                            }
                                        }
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                ProgramLog.Log (e);
                            }
                        }
                        if (this.type == ProjectileType.N102_BOMB)
                        {
                            if (this.Velocity.Y > 10f)
                            {
                                this.Velocity.Y = 10f;
                            }
            //		                    if (this.localAI[0] == 0f)
            //		                    {
            //		                        this.localAI[0] = 1f;
            //		                    }
            //		                    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.Owner == Main.myPlayer && this.timeLeft <= 3)
                        {
                            this.ai[1] = 0f;
                            this.alpha = 255;
                            if (this.type == ProjectileType.N28_BOMB || this.type == ProjectileType.N37_STICKY_BOMB ||
                                this.type == ProjectileType.N75_HAPPY_BOMB)
                            {
                                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 == ProjectileType.N29_DYNAMITE)
                                {
                                    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 == ProjectileType.N30_GRENADE)
                                    {
                                        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 != ProjectileType.N30_GRENADE && this.type != ProjectileType.N108_EXPLOSIVES)
                            {
                                this.damage = 0;
                            }
                        }
                        this.ai[0] += 1f;
                        if ((this.type == ProjectileType.N30_GRENADE && this.ai[0] > 10f) ||
                        (this.type != ProjectileType.N30_GRENADE && 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 == ProjectileType.N29_DYNAMITE)
                                {
                                    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;
                        }
                        this.rotation += this.Velocity.X * 0.1f;
                        return;
                }
                //break;
                case 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 num78 = (int)((this.Position.X + (float)this.Width) / 16f);
                            int num79 = (int)((this.Position.Y + (float)this.Height) / 16f);
                            if (TileRefs(num78, num79).Exists && !TileRefs(num78, num79).Active)
                            {
                                WorldModify.PlaceTile(TileRefs, sandbox, num78, num79, 85, false, false, -1, 0);
                                if (TileRefs(num78, num79).Active)
                                {

                                    NetMessage.SendData(17, -1, -1, "", 1, (float)num78, (float)num79, 85f);

                                    int num80 = Sign.ReadSign(num78, num79);
                                    if (num80 >= 0)
                                    {
                                        //Need to check if this works :3
                                        //PlayerEditSignEvent playerEvent = new PlayerEditSignEvent();
                                        //playerEvent.Sender = Main.players[this.Owner];
                                        //playerEvent.Sign = Main.sign[num80];
                                        //playerEvent.Text = this.miscText;
                                        //playerEvent.isPlayer = false;
                                        //Server.PluginManager.processHook(Hooks.PLAYER_EDITSIGN, playerEvent);
                                        //if (playerEvent.Cancelled)
                                        //{
                                        //    return;
                                        //}

                                        Sign.TextSign(num80, this.miscText);
                                    }
                                    this.Kill(TileRefs, sandbox);
                                    return;
                                }
                            }
                        }
                    }
                    break;
                case 18:
                    {
                        if (this.ai[1] == 0f && this.type == ProjectileType.N44_DEMON_SICKLE)
                        {
                            this.ai[1] = 1f;
                        }
                        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;
                            }
                        }
                        return;
                    }
                //break;
                case 19:
                    {
                        this.direction = Main.players[this.Owner].direction;
                        Main.players[this.Owner].heldProj = this.whoAmI;
                        Main.players[this.Owner].itemTime = Main.players[this.Owner].itemAnimation;
                        this.Position.X = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - (float)(this.Width / 2);
                        this.Position.Y = Main.players[this.Owner].Position.Y + (float)(Main.players[this.Owner].Height / 2) - (float)(this.Height / 2);
                        if (this.type == ProjectileType.N46_DARK_LANCE)
                        {
                            if (this.ai[0] == 0f)
                            {
                                this.ai[0] = 3f;
                                this.netUpdate = true;
                            }
                            if (Main.players[this.Owner].itemAnimation < Main.players[this.Owner].itemAnimationMax / 3)
                            {
                                this.ai[0] -= 1.6f;
                            }
                            else
                            {
                                this.ai[0] += 1.4f;
                            }
                        }
                        else
                        {
                            if (this.type == ProjectileType.N105_GUNGNIR)
                            {
                                if (this.ai[0] == 0f)
                                {
                                    this.ai[0] = 3f;
                                    this.netUpdate = true;
                                }
                                if (Main.players[this.Owner].itemAnimation < Main.players[this.Owner].itemAnimationMax / 3)
                                {
                                    this.ai[0] -= 2.4f;
                                }
                                else
                                {
                                    this.ai[0] += 2.1f;
                                }
                            }
                            if (this.type == ProjectileType.N47_TRIDENT)
                            {
                                if (this.ai[0] == 0f)
                                {
                                    this.ai[0] = 4f;
                                    this.netUpdate = true;
                                }
                                if (Main.players[this.Owner].itemAnimation < Main.players[this.Owner].itemAnimationMax / 3)
                                {
                                    this.ai[0] -= 1.2f;
                                }
                                else
                                {
                                    this.ai[0] += 0.9f;
                                }
                            }
                            else if (this.type == ProjectileType.N49_SPEAR)
                            {
                                if (this.ai[0] == 0f)
                                {
                                    this.ai[0] = 4f;
                                    this.netUpdate = true;
                                }
                                if (Main.players[this.Owner].itemAnimation < Main.players[this.Owner].itemAnimationMax / 3)
                                {
                                    this.ai[0] -= 1.1f;
                                }
                                else
                                {
                                    this.ai[0] += 0.85f;
                                }
                            }
                            else if (this.type == ProjectileType.N64_MYTHRIL_HALBERD)
                            {
                                if (this.ai[0] == 0f)
                                {
                                    this.ai[0] = 3f;
                                    this.netUpdate = true;
                                }
                                if (Main.players[this.Owner].itemAnimation < Main.players[this.Owner].itemAnimationMax / 3)
                                {
                                    this.ai[0] -= 1.9f;
                                }
                                else
                                {
                                    this.ai[0] += 1.7f;
                                }
                            }
                            else if (this.type == ProjectileType.N66_ADAMANTITE_GLAIVE || this.type == ProjectileType.N97_COBALT_NAGINATA)
                            {
                                if (this.ai[0] == 0f)
                                {
                                    this.ai[0] = 3f;
                                    this.netUpdate = true;
                                }
                                if (Main.players[this.Owner].itemAnimation < Main.players[this.Owner].itemAnimationMax / 3)
                                {
                                    this.ai[0] -= 2.1f;
                                }
                                else
                                {
                                    this.ai[0] += 1.9f;
                                }
                            }
                        }
                        this.Position += this.Velocity * this.ai[0];
                        if (Main.players[this.Owner].itemAnimation == 0)
                        {
                            this.Kill(TileRefs, sandbox);
                        }
                        this.rotation = (float)Math.Atan2((double)this.Velocity.Y, (double)this.Velocity.X) + 2.355f;
                    }
                    break;
                case 20:
                    {
                        if (this.soundDelay <= 0)
                        {
                            this.soundDelay = 30;
                        }
                        if (Main.myPlayer == this.Owner)
                        {
                            if (!Main.players[this.Owner].channel)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                        }
                        if (this.Velocity.X > 0f)
                        {
                            Main.players[this.Owner].direction = 1;
                        }
                        else
                        {
                            if (this.Velocity.X < 0f)
                            {
                                Main.players[this.Owner].direction = -1;
                            }
                        }
                        Main.players[this.Owner].direction = this.direction;
                        Main.players[this.Owner].heldProj = this.whoAmI;
                        Main.players[this.Owner].itemTime = 2;
                        Main.players[this.Owner].itemAnimation = 2;
                        this.Position.X = Main.players[this.Owner].Position.X + (float)(Main.players[this.Owner].Width / 2) - (float)(this.Width / 2);
                        this.Position.Y = Main.players[this.Owner].Position.Y + (float)(Main.players[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.players[this.Owner].direction == 1)
                        {
                            Main.players[this.Owner].itemRotation = (float)Math.Atan2((double)(this.Velocity.Y * (float)this.direction), (double)(this.Velocity.X * (float)this.direction));
                        }
                        else
                        {
                            Main.players[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)
                        {
                            return;
                        }
                    }
                    break;
                case 21:
                    {
                        this.rotation = this.Velocity.X * 0.1f;
                        if (this.ai[1] == 1f)
                        {
                            this.ai[1] = 0f;
                            Main.harpNote = this.ai[0];
                            return;
                        }
                    }
                    break;
                case 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 num125 = (int)(this.Position.X / 16f) - 1;
                            int num126 = (int)((this.Position.X + (float)this.Width) / 16f) + 2;
                            int num127 = (int)(this.Position.Y / 16f) - 1;
                            int num128 = (int)((this.Position.Y + (float)this.Height) / 16f) + 2;
                            if (num125 < 0)
                            {
                                num125 = 0;
                            }
                            if (num126 > Main.maxTilesX)
                            {
                                num126 = Main.maxTilesX;
                            }
                            if (num127 < 0)
                            {
                                num127 = 0;
                            }
                            if (num128 > Main.maxTilesY)
                            {
                                num128 = Main.maxTilesY;
                            }
                            int num129 = (int)this.Position.X + 4;
                            int num130 = (int)this.Position.Y + 4;
                            for (int num131 = num125; num131 < num126; num131++)
                            {
                                for (int num132 = num127; num132 < num128; num132++)
                                {
                                    if (TileRefs(num131, num132).Exists && TileRefs(num131, num132).Active && TileRefs(num131, num132).Type != 127 &&
                                        Main.tileSolid[(int)TileRefs(num131, num132).Type] && !Main.tileSolidTop[(int)TileRefs(num131, num132).Type])
                                    {
                                        Vector2 vector15;
                                        vector15.X = (float)(num131 * 16);
                                        vector15.Y = (float)(num132 * 16);
                                        if ((float)(num129 + 8) > vector15.X && (float)num129 < vector15.X + 16f &&
                                            (float)(num130 + 8) > vector15.Y && (float)num130 < vector15.Y + 16f)
                                        {
                                            this.Kill(TileRefs, sandbox);
                                        }
                                    }
                                }
                            }
                            return;
                        }
                        if (this.ai[0] < 0f)
                        {
                            int num137 = (int)this.Position.X / 16;
                            int num138 = (int)this.Position.Y / 16;
                            if (!TileRefs(num137, num138).Exists || !TileRefs(num137, num138).Active)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                            this.ai[0] -= 1f;
                            if (this.ai[0] <= -300f && (Main.myPlayer == this.Owner) && TileRefs(num137, num138).Active && TileRefs(num137, num138).Type == 127)
                            {
                                WorldModify.KillTile(TileRefs, sandbox, num137, num138);
                                NetMessage.SendData(17, -1, -1, "", 0, (float)num137, (float)num138, 0f, 0);
                                this.Kill(TileRefs, sandbox);
                                return;
                            }
                        }
                        else
                        {
                            int num139 = (int)(this.Position.X / 16f) - 1;
                            int num140 = (int)((this.Position.X + (float)this.Width) / 16f) + 2;
                            int num141 = (int)(this.Position.Y / 16f) - 1;
                            int num142 = (int)((this.Position.Y + (float)this.Height) / 16f) + 2;
                            if (num139 < 0)
                            {
                                num139 = 0;
                            }
                            if (num140 > Main.maxTilesX)
                            {
                                num140 = Main.maxTilesX;
                            }
                            if (num141 < 0)
                            {
                                num141 = 0;
                            }
                            if (num142 > Main.maxTilesY)
                            {
                                num142 = Main.maxTilesY;
                            }
                            int num143 = (int)this.Position.X + 4;
                            int num144 = (int)this.Position.Y + 4;
                            for (int num145 = num139; num145 < num140; num145++)
                            {
                                for (int num146 = num141; num146 < num142; num146++)
                                {
                                    if (TileRefs(num145, num146).Exists && TileRefs(num145, num146).Active && TileRefs(num145, num146).Type != 127
                                        && Main.tileSolid[(int)TileRefs(num145, num146).Type] && !Main.tileSolidTop[(int)TileRefs(num145, num146).Type])
                                    {
                                        Vector2 vector16;
                                        vector16.X = (float)(num145 * 16);
                                        vector16.Y = (float)(num146 * 16);
                                        if ((float)(num143 + 8) > vector16.X && (float)num143 < vector16.X + 16f &&
                                            (float)(num144 + 8) > vector16.Y && (float)num144 < vector16.Y + 16f)
                                        {
                                            this.Kill(TileRefs, sandbox);
                                        }
                                    }
                                }
                            }
                            if (this.lavaWet)
                            {
                                this.Kill(TileRefs, sandbox);
                            }
                            if (this.Active)
                            {
                                int num148 = (int)this.ai[0];
                                int num149 = (int)this.ai[1];
                                if (this.Velocity.X > 0f)
                                {
                                    this.rotation += 0.3f;
                                }
                                else
                                {
                                    this.rotation -= 0.3f;
                                }
                                if (Main.myPlayer == this.Owner)
                                {
                                    int num150 = (int)((this.Position.X + (float)(this.Width / 2)) / 16f);
                                    int num151 = (int)((this.Position.Y + (float)(this.Height / 2)) / 16f);
                                    bool flag2 = false;
                                    if (num150 == num148 && num151 == num149)
                                    {
                                        flag2 = true;
                                    }
                                    if (((this.Velocity.X <= 0f && num150 <= num148) || (this.Velocity.X >= 0f && num150 >= num148)) &&
                                        ((this.Velocity.Y <= 0f && num151 <= num149) || (this.Velocity.Y >= 0f && num151 >= num149)))
                                    {
                                        flag2 = true;
                                    }
                                    if (flag2)
                                    {
                                        if (WorldModify.PlaceTile(TileRefs, sandbox, num148, num149, 127, false, false, this.Owner, 0))
                                        {
                                            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)(num148 * 16);
                                            this.Position.Y = (float)(num149 * 16);
                                            this.netUpdate = true;
                                            return;
                                        }
                                        this.ai[1] = -1f;
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    break;
                case 23:
                    {
                        if (this.timeLeft > 60)
                        {
                            this.timeLeft = 60;
                        }
                        if (this.ai[0] > 7f)
                        {
                            this.ai[0] += 1f;
                        }
                        else
                        {
                            this.ai[0] += 1f;
                        }
                        this.rotation += 0.3f * (float)this.direction;
                        return;
                    }
                //break;
                case 24:
                    {
                        this.light = this.scale * 0.5f;
                        this.rotation += this.Velocity.X * 0.2f;
                        this.ai[1] += 1f;
                        if (this.type == ProjectileType.N94_CRYSTAL_STORM)
                        {
                            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(TileRefs, sandbox);
                                    return;
                                }
                            }
                        }
                        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(TileRefs, sandbox);
                                    return;
                                }
                            }
                        }
                    }
                    break;
                case 25:
                    {
                        if (this.ai[0] != 0f && this.Velocity.Y <= 0f && this.Velocity.X == 0f)
                        {
                            float num157 = 0.5f;
                            int i2 = (int)((this.Position.X - 8f) / 16f);
                            int num158 = (int)(this.Position.Y / 16f);
                            bool flag3 = false;
                            bool flag4 = false;
                            if (WorldModify.SolidTile(TileRefs, i2, num158) || WorldModify.SolidTile(TileRefs, i2, num158 + 1))
                            {
                                flag3 = true;
                            }
                            i2 = (int)((this.Position.X + (float)this.Width + 8f) / 16f);
                            if (WorldModify.SolidTile(TileRefs, i2, num158) || WorldModify.SolidTile(TileRefs, i2, num158 + 1))
                            {
                                flag4 = true;
                            }
                            if (flag3)
                            {
                                this.Velocity.X = num157;
                            }
                            else
                            {
                                if (flag4)
                                {
                                    this.Velocity.X = -num157;
                                }
                                else
                                {
                                    i2 = (int)((this.Position.X - 8f - 16f) / 16f);
                                    num158 = (int)(this.Position.Y / 16f);
                                    flag3 = false;
                                    flag4 = false;
                                    if (WorldModify.SolidTile(TileRefs, i2, num158) || WorldModify.SolidTile(TileRefs, i2, num158 + 1))
                                    {
                                        flag3 = true;
                                    }
                                    i2 = (int)((this.Position.X + (float)this.Width + 8f + 16f) / 16f);
                                    if (WorldModify.SolidTile(TileRefs, i2, num158) || WorldModify.SolidTile(TileRefs, i2, num158 + 1))
                                    {
                                        flag4 = true;
                                    }
                                    if (flag3)
                                    {
                                        this.Velocity.X = num157;
                                    }
                                    else
                                    {
                                        if (flag4)
                                        {
                                            this.Velocity.X = -num157;
                                        }
                                        else
                                        {
                                            i2 = (int)((this.Position.X + 4f) / 16f);
                                            num158 = (int)((this.Position.Y + (float)this.Height + 8f) / 16f);
                                            if (WorldModify.SolidTile(TileRefs, i2, num158) || WorldModify.SolidTile(TileRefs, i2, num158 + 1))
                                            {
                                                flag3 = true;
                                            }
                                            if (!flag3)
                                            {
                                                this.Velocity.X = num157;
                                            }
                                            else
                                            {
                                                this.Velocity.X = -num157;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        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;
                    }
                    break;
                default:
                    {
                        // there are only aistyles 1 to 25
                    }
                    break;
            }
        }
        public static int StorePlayerItem(ISandbox sandbox, int X, int Y, int Width, int Height, int type, int stack = 1, bool noBroadcast = false, int pfix = 0, int NetID = 255)
        {
            if (sandbox != null)
                sandbox.NewItem(X, Y, Width, Height, type, stack, noBroadcast, pfix, NetID);
            else
                return Item.NewItem(X, Y, Width, Height, type, stack, noBroadcast, pfix, NetID);

            return 0;
        }
Example #42
0
 public MessageProcessorFactory(IMethodScanner stepScanner, ISandbox sandbox)
 {
     _stepScanner = stepScanner;
     _sandbox     = sandbox;
     InitializeProcessors(stepScanner);
 }
        public static void Check3x2(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, int type)
        {
            if (destroyObject)
                return;

            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            bool flag = false;
            int num = i + (int)(TileRefs(i, j).FrameX / 18 * -1);
            int num2 = j + (int)(TileRefs(i, j).FrameY / 18 * -1);
            for (int k = num; k < num + 3; k++)
            {
                for (int l = num2; l < num2 + 2; l++)
                {
                    if (!TileRefs(k, l).Active || (int)TileRefs(k, l).Type != type || (int)TileRefs(k, l).FrameX != (k - num) * 18 ||
                        (int)TileRefs(k, l).FrameY != (l - num2) * 18)
                    {
                        flag = true;
                    }
                }
                if (!TileRefs(k, num2 + 2).Active || !Main.tileSolid[(int)TileRefs(k, num2 + 2).Type])
                {
                    flag = true;
                }
            }
            if (flag)
            {
                destroyObject = true;
                for (int m = num; m < num + 3; m++)
                {
                    for (int n = num2; n < num2 + 3; n++)
                    {
                        if ((int)TileRefs(m, n).Type == type && TileRefs(m, n).Active)
                            KillTile(TileRefs, sandbox, m, n);
                    }
                }
                if (type == 14)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 32, 1, false, 0);
                }
                else if (type == 114)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 398, 1, false, 0);
                }
                else if (type == 26)
                {
                    if (!noTileActions)
                    {
                        SmashAltar(TileRefs, sandbox, i, j);
                    }
                }
                else if (type == 17)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 33, 1, false, 0);
                }
                else if (type == 77)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 221, 1, false, 0);
                }
                else if (type == 86)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 332, 1, false, 0);
                }
                else if (type == 87)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 333, 1, false, 0);
                }
                else if (type == 88)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 334, 1, false, 0);
                }
                else if (type == 89)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 335, 1, false, 0);
                }
                else if (type == 133)
                {
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 524, 1, false, 0);
                }

                destroyObject = false;
                for (int num3 = num - 1; num3 < num + 4; num3++)
                {
                    for (int num4 = num2 - 1; num4 < num2 + 4; num4++)
                        TileFrame(TileRefs, sandbox, num3, num4);
                }
            }
        }
Example #44
0
 private static void EnableStepping(ISandbox sandbox)
 {
     var process = sandbox.GetRunningProcess();
     //process.Step += ProcessStep;
     //process.Step += ProcessStep;
 }
        /// <summary>
        /// Runs damage calculation on hostile mobs and players
        /// </summary>
        public void Damage(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (this.type == ProjectileType.N18_ORB_OF_LIGHT || this.type == ProjectileType.N72_BLUE_FAIRY ||
                this.type == ProjectileType.N86_PINK_FAIRY || this.type == ProjectileType.N87_PINK_FAIRY ||
                this.type == ProjectileType.N111_BUNNY)
            {
                return;
            }
            int playerIndex = Main.myPlayer;
            Player player = Main.players[playerIndex];

            Rectangle rectangle = new Rectangle((int)this.Position.X, (int)this.Position.Y, this.Width, this.Height);
            if (this.type == ProjectileType.N85_FLAMES || this.type == ProjectileType.N101_EYE_FIRE)
            {
                int num = 30;
                rectangle.X -= num;
                rectangle.Y -= num;
                rectangle.Width += num * 2;
                rectangle.Height += num * 2;
            }
            if (this.friendly && this.type != ProjectileType.N18_ORB_OF_LIGHT)
            {
                var creat = Creator as Player;
                if (this.Owner == playerIndex)// || (Owner == 255 && creat != null && creat.whoAmi == playerIndex))
                {
                    if (creat != null) player = creat;
                    if ((this.aiStyle == 16 || this.type == ProjectileType.N41_HELLFIRE_ARROW) && (this.timeLeft <= 1 || this.type == ProjectileType.N108_EXPLOSIVES))
                    {
                        if (player.Active && !player.dead && !player.immune && (!this.ownerHitCheck || Collision.CanHit(Main.players[this.Owner].Position, Main.players[this.Owner].Width, Main.players[this.Owner].Height, player.Position, player.Width, player.Height)))
                        {
                            if (player.Intersects(rectangle))
                            {
                                if (player.Position.X + (float)(player.Width / 2) < this.Position.X + (float)(this.Width / 2))
                                {
                                    this.direction = -1;
                                }
                                else
                                {
                                    this.direction = 1;
                                }
                                int dmg = Main.DamageVar((float)this.damage);
                                this.StatusPlayer(player);

                                player.Hurt(this, dmg, this.direction, true, false, Player.getDeathMessage(this.Owner, -1, this.whoAmI, -1));
                                NetMessage.SendData(26, -1, -1, Player.getDeathMessage(this.Owner, -1, this.whoAmI, -1), playerIndex, (float)this.direction, (float)dmg, 1f);
                            }
                        }
                    }
                    if (this.type != ProjectileType.N69_HOLY_WATER && this.type != ProjectileType.N70_UNHOLY_WATER &&
                        this.type != ProjectileType.N10_PURIFICATION_POWDER && this.type != ProjectileType.N11_VILE_POWDER)
                    {
                        int num = (int)(this.Position.X / 16f);
                        int num2 = (int)((this.Position.X + (float)this.Width) / 16f) + 1;
                        int num3 = (int)(this.Position.Y / 16f);
                        int num4 = (int)((this.Position.Y + (float)this.Height) / 16f) + 1;
                        if (num < 0)
                        {
                            num = 0;
                        }
                        if (num2 > Main.maxTilesX)
                        {
                            num2 = Main.maxTilesX;
                        }
                        if (num3 < 0)
                        {
                            num3 = 0;
                        }
                        if (num4 > Main.maxTilesY)
                        {
                            num4 = Main.maxTilesY;
                        }
                        for (int i = num; i < num2; i++)
                        {
                            for (int j = num3; j < num4; j++)
                            {
                                if (Main.tileCut[(int)TileRefs(i, j).Type] && TileRefs(i, j + 1).Type != 78)
                                {
                                    var plr = Creator as Player;
                                    if (plr == null || WorldModify.InvokeAlterationHook(this, plr, i, j, 0))
                                    {
                                        WorldModify.KillTile(TileRefs, sandbox, i, j);
                                        NetMessage.SendData(17, -1, -1, "", 0, (float)i, (float)j);
                                    }
                                }
                            }
                        }
                    }
                    if (this.damage > 0)
                    {
                        NPC npc;
                        for (int i = 0; i < NPC.MAX_NPCS; i++)
                        {
                            npc = Main.npcs[i];
                            if (npc.Active && !npc.dontTakeDamage && (!npc.friendly || (npc.type == NPCType.N22_GUIDE && this.Owner < 255 && Main.players[this.Owner].killGuide)) && (this.Owner < 0 || npc.immune[this.Owner] == 0))
                            {
                                bool flag = false;
                                if (this.type == ProjectileType.N11_VILE_POWDER &&
                                    (npc.type == NPCType.N47_CORRUPT_BUNNY ||
                                    npc.type == NPCType.N57_CORRUPT_GOLDFISH))
                                {
                                    flag = true;
                                }
                                else
                                {
                                    if (this.type == ProjectileType.N31_SAND_BALL &&
                                        npc.type == NPCType.N69_ANTLION)
                                    {
                                        flag = true;
                                    }
                                }
                                if (!flag && (npc.noTileCollide || !this.ownerHitCheck || Collision.CanHit(Main.players[this.Owner].Position, Main.players[this.Owner].Width, Main.players[this.Owner].Height, npc.Position, npc.Width, npc.Height)))
                                {
                                    if (npc.Intersects(rectangle))
                                    {
                                        if (this.aiStyle == 3)
                                        {
                                            if (this.ai[0] == 0f)
                                            {
                                                this.Velocity.X = -this.Velocity.X;
                                                this.Velocity.Y = -this.Velocity.Y;
                                                this.netUpdate = true;
                                            }
                                            this.ai[0] = 1f;
                                        }
                                        else
                                        {
                                            if (this.aiStyle == 16)
                                            {
                                                if (this.timeLeft > 3)
                                                {
                                                    this.timeLeft = 3;
                                                }
                                                if (npc.Position.X + (float)(npc.Width / 2) < this.Position.X + (float)(this.Width / 2))
                                                {
                                                    this.direction = -1;
                                                }
                                                else
                                                {
                                                    this.direction = 1;
                                                }
                                            }
                                        }
                                        if (this.type == ProjectileType.N41_HELLFIRE_ARROW && this.timeLeft > 1)
                                        {
                                            this.timeLeft = 1;
                                        }
                                        bool crit = false;
                                        if (this.Owner < 255)
                                        {
                                            var owner = Main.players[this.Owner];
                                            var rand = Main.rand.Next(1, 101);
                                            crit = (this.melee && rand <= owner.meleeCrit)
                                                || (this.ranged && rand <= owner.rangedCrit)
                                                || (this.magic && rand <= owner.magicCrit);
                                        }
                                        int dmg = Main.DamageVar(this.damage);

                                        if (npc.StrikeNPC(this, dmg, this.knockBack, this.direction, crit))
                                        {
                                            this.StatusNPC(npc);
                                            NetMessage.SendData(28, -1, -1, "", i, (float)dmg, this.knockBack, (float)this.direction, crit ? 1 : 0);
                                        }

                                        if (this.penetrate != 1)
                                        {
                                            npc.immune[this.Owner] = 10;
                                        }
                                        if (this.penetrate > 0)
                                        {
                                            this.penetrate--;
                                            if (this.penetrate == 0)
                                            {
                                                break;
                                            }
                                        }
                                        if (this.aiStyle == 7)
                                        {
                                            this.ai[0] = 1f;
                                            this.damage = 0;
                                            this.netUpdate = true;
                                        }
                                        else
                                        {
                                            if (this.aiStyle == 13)
                                            {
                                                this.ai[0] = 1f;
                                                this.netUpdate = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    if (this.damage > 0 && player.hostile)
                    {
                        Player playerIt;
                        for (int i = 0; i < Main.MAX_PLAYERS; i++)
                        {
                            playerIt = Main.players[i];
                            if (i != this.Owner && playerIt.Active && !playerIt.dead && !playerIt.immune && playerIt.hostile && this.playerImmune[i] <= 0 && (player.team == 0 || player.team != playerIt.team) && (!this.ownerHitCheck || Collision.CanHit(Main.players[this.Owner].Position, Main.players[this.Owner].Width, Main.players[this.Owner].Height, playerIt.Position, playerIt.Width, playerIt.Height)))
                            {
                                if (playerIt.Intersects(rectangle))
                                {
                                    if (this.aiStyle == 3)
                                    {
                                        if (this.ai[0] == 0f)
                                        {
                                            this.Velocity.X = -this.Velocity.X;
                                            this.Velocity.Y = -this.Velocity.Y;
                                            this.netUpdate = true;
                                        }
                                        this.ai[0] = 1f;
                                    }
                                    else
                                    {
                                        if (this.aiStyle == 16)
                                        {
                                            if (this.timeLeft > 3)
                                            {
                                                this.timeLeft = 3;
                                            }
                                            if (playerIt.Position.X + (float)(playerIt.Width / 2) < this.Position.X + (float)(this.Width / 2))
                                            {
                                                this.direction = -1;
                                            }
                                            else
                                            {
                                                this.direction = 1;
                                            }
                                        }
                                    }
                                    if (this.type == ProjectileType.N41_HELLFIRE_ARROW && this.timeLeft > 1)
                                    {
                                        this.timeLeft = 1;
                                    }
                                    bool crit = false;
                                    if (this.Owner < 255)
                                    {
                                        var owner = Main.players[this.Owner];
                                        var rand = Main.rand.Next(1, 101);
                                        crit = (this.melee && rand <= owner.meleeCrit);
                                    }
                                    int dmg = Main.DamageVar(this.damage);

                                    if (!playerIt.immune) this.StatusPvP(playerIt);

                                    var crea = Creator as Player;
                                    playerIt.Hurt(this, dmg, this.direction, true, false, Player.getDeathMessage(this.Owner < 255 ? this.Owner : (crea == null ? 255 : crea.whoAmi), -1, this.whoAmI, -1), crit);

                                    //NetMessage.SendData(26, -1, -1, Player.getDeathMessage(this.Owner, -1, this.whoAmI, -1), i, (float)this.direction, (float)dmg, 1f, crit ? 1 : 0);

                                    this.playerImmune[i] = 40;
                                    if (this.penetrate > 0)
                                    {
                                        this.penetrate--;
                                        if (this.penetrate == 0)
                                        {
                                            break;
                                        }
                                    }
                                    if (this.aiStyle == 7)
                                    {
                                        this.ai[0] = 1f;
                                        this.damage = 0;
                                        this.netUpdate = true;
                                    }
                                    else
                                    {
                                        if (this.aiStyle == 13)
                                        {
                                            this.ai[0] = 1f;
                                            this.netUpdate = true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (this.type == ProjectileType.N11_VILE_POWDER)
                {
                    NPC npc;
                    for (int i = 0; i < NPC.MAX_NPCS; i++)
                    {
                        npc = Main.npcs[i];
                        if (npc.Active)
                        {
                            if (npc.type == NPCType.N46_BUNNY)
                            {
                                if (npc.Intersects(rectangle))
                                {
                                    npc.Transform(47);
                                }
                            }
                            else
                            {
                                if (npc.type == NPCType.N55_GOLDFISH)
                                {
                                    if (npc.Intersects(rectangle))
                                    {
                                        npc.Transform(57);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            #if CLIENT_CODE
            if (this.hostile && Main.myPlayer < 255 && this.damage > 0) // client-only, but we may use it later
            {
                if (player.Active && !player.dead && !player.immune)
                {
                    if (player.Intersects(rectangle))
                    {
                        int hitDirection = this.direction;
                        if (player.Position.X + (float)(player.Width / 2) < this.Position.X + (float)(this.Width / 2))
                        {
                            hitDirection = -1;
                        }
                        else
                        {
                            hitDirection = 1;
                        }

                        if (! player.immune) this.StatusPlayer (player);

                        int dmg = Main.DamageVar (this.damage);
                        player.Hurt (dmg * 2, hitDirection, false, false, " was slain...");

                        //NetMessage.SendData(26, -1, -1, "", playerIndex, (float)this.direction, (float)(this.damage * 2));
                    }
                }
            }
            #endif //CLIENT_CODE
        }
 public ScenarioExecutionEndingProcessor(IMethodExecutor methodExecutor, ISandbox sandbox)
     : base(methodExecutor)
 {
     _sandbox = sandbox;
 }
 /// <summary>
 /// Updates the projectile's position, damage variables, etc.
 /// </summary>
 /// <param name="TileRefs">Reference to the ITile method, For usage between Sandbox and Realtime</param>
 /// <param name="sandbox">Sandbox instance if needed</param>
 /// <param name="i">Projectile index</param>
 public void Update(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i)
 {
     if (this.Active)
     {
         Vector2 value = this.Velocity;
         if (this.Position.X <= Main.leftWorld || this.Position.X + (float)this.Width >= Main.rightWorld || this.Position.Y <= Main.topWorld || this.Position.Y + (float)this.Height >= Main.bottomWorld)
         {
             this.Active = false;
             Reset(i);
             return;
         }
         this.whoAmI = i;
         if (this.soundDelay > 0)
         {
             this.soundDelay--;
         }
         this.netUpdate = false;
         for (int j = 0; j < 255; j++)
         {
             if (this.playerImmune[j] > 0)
             {
                 this.playerImmune[j]--;
             }
         }
         this.AI(TileRefs, sandbox);
         if (this.Owner < 255 && !Main.players[this.Owner].Active)
         {
             this.Kill(TileRefs, sandbox); // FIXME!
         }
         if (!this.ignoreWater)
         {
             bool flag;
             bool flag2;
             try
             {
                 flag = Collision.LavaCollision(this.Position, this.Width, this.Height);
                 flag2 = Collision.WetCollision(this.Position, this.Width, this.Height);
                 if (flag)
                 {
                     this.lavaWet = true;
                 }
             }
             catch
             {
                 this.Active = false;
                 Reset(i);
                 return;
             }
             if (this.wet && !this.lavaWet)
             {
                 if (this.type == ProjectileType.N85_FLAMES ||
                     this.type == ProjectileType.N15_BALL_OF_FIRE ||
                     this.type == ProjectileType.N34_FLAMELASH)
                 {
                     this.Kill(TileRefs, sandbox);
                 }
                 if (this.type == ProjectileType.N2_FIRE_ARROW)
                 {
                     this.type = ProjectileType.N1_WOODEN_ARROW;
                     this.light = 0f;
                 }
             }
             if (this.type == ProjectileType.N80_ICE_BLOCK)
             {
                 flag2 = false;
                 this.wet = false;
                 if (flag && this.ai[0] >= 0f)
                 {
                     this.Kill(TileRefs, sandbox);
                 }
             }
             if (flag2)
             {
                 if (this.wetCount == 0)
                 {
                     this.wetCount = 10;
                     this.wet = true;
                 }
             }
             else
             {
                 if (this.wet)
                 {
                     this.wet = false;
                     if (this.wetCount == 0)
                     {
                         this.wetCount = 10;
                     }
                 }
             }
             if (!this.wet)
             {
                 this.lavaWet = false;
             }
             if (this.wetCount > 0)
             {
                 this.wetCount -= 1;
             }
         }
         this.lastPosition = this.Position;
         if (this.tileCollide)
         {
             Vector2 value2 = this.Velocity;
             bool flag3 = true;
             if (this.type == ProjectileType.N9_STARFURY ||
                 this.type == ProjectileType.N12_FALLING_STAR ||
                 this.type == ProjectileType.N15_BALL_OF_FIRE ||
                 this.type == ProjectileType.N13_HOOK ||
                 this.type == ProjectileType.N31_SAND_BALL ||
                 this.type == ProjectileType.N39_MUD_BALL ||
                 this.type == ProjectileType.N40_ASH_BALL)
             {
                 flag3 = false;
             }
             if (this.aiStyle == 10)
             {
                 if (this.type == ProjectileType.N42_SAND_BALL ||
                     this.type == ProjectileType.N65_EBONSAND_BALL ||
                     this.type == ProjectileType.N68_PEARL_SAND_BALL ||
                     (this.type == ProjectileType.N31_SAND_BALL && this.ai[0] == 2f))
                 {
                     this.Velocity = Collision.TileCollision(this.Position, this.Velocity, this.Width, this.Height, flag3, flag3);
                 }
                 else
                 {
                     this.Velocity = Collision.AnyCollision(this.Position, this.Velocity, this.Width, this.Height);
                 }
             }
             else
             {
                 if (this.aiStyle == 18)
                 {
                     int num5 = this.Width - 36;
                     int num6 = this.Height - 36;
                     Vector2 vector = new Vector2(this.Position.X + (float)(this.Width / 2) - (float)(num5 / 2), this.Position.Y + (float)(this.Height / 2) - (float)(num6 / 2));
                     this.Velocity = Collision.TileCollision(vector, this.Velocity, num5, num6, flag3, flag3);
                 }
                 else
                 {
                     if (this.wet)
                     {
                         Vector2 vector2 = this.Velocity;
                         this.Velocity = Collision.TileCollision(this.Position, this.Velocity, this.Width, this.Height, flag3, flag3);
                         value = this.Velocity * 0.5f;
                         if (this.Velocity.X != vector2.X)
                         {
                             value.X = this.Velocity.X;
                         }
                         if (this.Velocity.Y != vector2.Y)
                         {
                             value.Y = this.Velocity.Y;
                         }
                     }
                     else
                     {
                         this.Velocity = Collision.TileCollision(this.Position, this.Velocity, this.Width, this.Height, flag3, flag3);
                     }
                 }
             }
             if (value2 != this.Velocity && this.type != ProjectileType.N111_BUNNY)
             {
                 if (this.type == ProjectileType.N94_CRYSTAL_STORM)
                 {
                     if (this.Velocity.X != value2.X)
                     {
                         this.Velocity.X = -value2.X;
                     }
                     if (this.Velocity.Y != value2.Y)
                     {
                         this.Velocity.Y = -value2.Y;
                     }
                 }
                 else if (this.type == ProjectileType.N99_BOULDER)
                 {
                     if (this.Velocity.Y != value2.Y && value2.Y > 5f)
                     {
                         Collision.HitTiles(TileRefs, sandbox, this.Position, this.Velocity, this.Width, this.Height);
                         this.Velocity.Y = -value2.Y * 0.2f;
                     }
                     if (this.Velocity.X != value2.X)
                     {
                         this.Kill(TileRefs, sandbox);
                     }
                 }
                 else if (this.type == ProjectileType.N36_METEOR_SHOT)
                 {
                     if (this.penetrate > 1)
                     {
                         Collision.HitTiles(TileRefs, sandbox, this.Position, this.Velocity, this.Width, this.Height);
                         this.penetrate--;
                         if (this.Velocity.X != value2.X)
                         {
                             this.Velocity.X = -value2.X;
                         }
                         if (this.Velocity.Y != value2.Y)
                         {
                             this.Velocity.Y = -value2.Y;
                         }
                     }
                     else
                     {
                         this.Kill(TileRefs, sandbox);
                     }
                 }
                 else
                 {
                     if (this.aiStyle == 21)
                     {
                         if (this.Velocity.X != value2.X)
                         {
                             this.Velocity.X = -value2.X;
                         }
                         if (this.Velocity.Y != value2.Y)
                         {
                             this.Velocity.Y = -value2.Y;
                         }
                     }
                     if (this.aiStyle == 17)
                     {
                         if (this.Velocity.X != value2.X)
                         {
                             this.Velocity.X = value2.X * -0.75f;
                         }
                         if (this.Velocity.Y != value2.Y && (double)value2.Y > 1.5)
                         {
                             this.Velocity.Y = value2.Y * -0.7f;
                         }
                     }
                     else
                     {
                         if (this.aiStyle == 15)
                         {
                             bool flag4 = false;
                             if (value2.X != this.Velocity.X)
                             {
                                 if (Math.Abs(value2.X) > 4f)
                                 {
                                     flag4 = true;
                                 }
                                 this.Position.X = this.Position.X + this.Velocity.X;
                                 this.Velocity.X = -value2.X * 0.2f;
                             }
                             if (value2.Y != this.Velocity.Y)
                             {
                                 if (Math.Abs(value2.Y) > 4f)
                                 {
                                     flag4 = true;
                                 }
                                 this.Position.Y = this.Position.Y + this.Velocity.Y;
                                 this.Velocity.Y = -value2.Y * 0.2f;
                             }
                             this.ai[0] = 1f;
                             if (flag4)
                             {
                                 this.netUpdate = true;
                                 Collision.HitTiles(TileRefs, sandbox, this.Position, this.Velocity, this.Width, this.Height);
                             }
                         }
                         else if (this.aiStyle == 3 || this.aiStyle == 13)
                         {
                             Collision.HitTiles(TileRefs, sandbox, this.Position, this.Velocity, this.Width, this.Height);
                             if (this.type == ProjectileType.N33_THORN_CHAKRUM)
                             {
                                 if (this.Velocity.X != value2.X)
                                 {
                                     this.Velocity.X = -value2.X;
                                 }
                                 if (this.Velocity.Y != value2.Y)
                                 {
                                     this.Velocity.Y = -value2.Y;
                                 }
                             }
                             else
                             {
                                 this.ai[0] = 1f;
                                 if (this.aiStyle == 3)
                                 {
                                     this.Velocity.X = -value2.X;
                                     this.Velocity.Y = -value2.Y;
                                 }
                             }
                             this.netUpdate = true;
                         }
                         else
                         {
                             if (this.aiStyle == 8 && this.type != ProjectileType.N96_CURSED_FLAME)
                             {
                                 this.ai[0] += 1f;
                                 if (this.ai[0] >= 5f)
                                 {
                                     this.Position += this.Velocity;
                                     this.Kill(TileRefs, sandbox);
                                 }
                                 else
                                 {
                                     if (this.type == ProjectileType.N15_BALL_OF_FIRE && this.Velocity.Y > 4f)
                                     {
                                         if (this.Velocity.Y != value2.Y)
                                         {
                                             this.Velocity.Y = -value2.Y * 0.8f;
                                         }
                                     }
                                     else if (this.Velocity.Y != value2.Y)
                                     {
                                         this.Velocity.Y = -value2.Y;
                                     }
                                     if (this.Velocity.X != value2.X)
                                     {
                                         this.Velocity.X = -value2.X;
                                     }
                                 }
                             }
                             else
                             {
                                 if (this.aiStyle == 14)
                                 {
                                     if (this.type == ProjectileType.N50_GLOWSTICK)
                                     {
                                         if (this.Velocity.X != value2.X)
                                         {
                                             this.Velocity.X = value2.X * -0.2f;
                                         }
                                         if (this.Velocity.Y != value2.Y && (double)value2.Y > 1.5)
                                         {
                                             this.Velocity.Y = value2.Y * -0.2f;
                                         }
                                     }
                                     else
                                     {
                                         if (this.Velocity.X != value2.X)
                                         {
                                             this.Velocity.X = value2.X * -0.5f;
                                         }
                                         if (this.Velocity.Y != value2.Y && value2.Y > 1f)
                                         {
                                             this.Velocity.Y = value2.Y * -0.5f;
                                         }
                                     }
                                 }
                                 else
                                 {
                                     if (this.aiStyle == 16)
                                     {
                                         if (this.Velocity.X != value2.X)
                                         {
                                             this.Velocity.X = value2.X * -0.4f;
                                             if (this.type == ProjectileType.N29_DYNAMITE)
                                             {
                                                 this.Velocity.X = this.Velocity.X * 0.8f;
                                             }
                                         }
                                         if (this.Velocity.Y != value2.Y && (double)value2.Y > 0.7 && this.type != ProjectileType.N102_BOMB)
                                         {
                                             this.Velocity.Y = value2.Y * -0.4f;
                                             if (this.type == ProjectileType.N29_DYNAMITE)
                                             {
                                                 this.Velocity.Y = this.Velocity.Y * 0.8f;
                                             }
                                         }
                                     }
                                     else if (this.aiStyle != 9 || this.Owner == Main.myPlayer)
                                     {
                                         this.Position += this.Velocity;
                                         this.Kill(TileRefs, sandbox);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (this.type == ProjectileType.N7_VILETHORN || this.type == ProjectileType.N8_VILETHORN)
         {
             goto IL_D48;
         }
         if (this.wet)
         {
             this.Position += value;
             goto IL_D48;
         }
         this.Position += this.Velocity;
     IL_D48:
         if ((this.aiStyle != 3 || this.ai[0] != 1f) && (this.aiStyle != 7 || this.ai[0] != 1f) && (this.aiStyle != 13 || this.ai[0] != 1f) && (this.aiStyle != 15 || this.ai[0] != 1f))
         {
             if (this.Velocity.X < 0f)
             {
                 this.direction = -1;
             }
             else
             {
                 this.direction = 1;
             }
         }
         if (!this.Active)
         {
             return;
         }
         this.Damage(TileRefs, sandbox);
         if (this.type == ProjectileType.N99_BOULDER)
         {
             Collision.SwitchTiles(TileRefs, sandbox, this.Position, this.Width, this.Height, this.lastPosition, this.Creator);
         }
         if (this.type == ProjectileType.N94_CRYSTAL_STORM)
         {
             //for (int num12 = this.oldPos.Length - 1; num12 > 0; num12--)
             //{
             //     this.oldPos[num12] = this.oldPos[num12 - 1];
             // }
             //  this.oldPos[0] = this.Position;
         }
         this.timeLeft--;
         if (this.timeLeft <= 0)
         {
             this.Kill(TileRefs, sandbox);
         }
         if (this.penetrate == 0)
         {
             this.Kill(TileRefs, sandbox);
         }
         if (this.Active && this.Owner == Main.myPlayer)
         {
             if (this.netUpdate2)
             {
                 this.netUpdate = true;
             }
             if (!this.Active)
             {
                 this.netSpam = 0;
             }
             if (this.netUpdate)
             {
                 if (this.netSpam < 60)
                 {
                     this.netSpam += 5;
                     NetMessage.SendData(27, -1, -1, "", i);
                     this.netUpdate2 = false;
                 }
                 else
                 {
                     this.netUpdate2 = true;
                 }
             }
             if (this.netSpam > 0)
             {
                 this.netSpam--;
             }
         }
         if (this.Active && this.maxUpdates > 0)
         {
             this.numUpdates--;
             if (this.numUpdates >= 0)
             {
                 this.Update(TileRefs, sandbox, i);
             }
             else
             {
                 this.numUpdates = this.maxUpdates;
             }
         }
         this.netUpdate = false;
     }
 }
Example #48
0
 public MethodExecutor(ISandbox sandbox)
 {
     _sandbox = sandbox;
 }
Example #49
0
 public SandboxHost(ISandbox sandbox)
 {
     _instance = sandbox;
 }
        public static void Check2x2(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, int type)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (destroyObject)
                return;

            bool flag = false;
            int num = i;
            int num2 = 0;
            num = (int)(TileRefs(i, j).FrameX / 18 * -1);
            int num3 = (int)(TileRefs(i, j).FrameY / 18 * -1);
            if (num < -1)
            {
                num += 2;
                num2 = 36;
            }
            num += i;
            num3 += j;
            for (int k = num; k < num + 2; k++)
            {
                for (int l = num3; l < num3 + 2; l++)
                {
                    if (!TileRefs(k, l).Active || (int)TileRefs(k, l).Type != type ||
                        (int)TileRefs(k, l).FrameX != (k - num) * 18 + num2 || (int)TileRefs(k, l).FrameY != (l - num3) * 18)
                    {
                        flag = true;
                    }
                }
                if (type == 95 || type == 126)
                {
                    if (!TileRefs(k, num3 - 1).Active || !Main.tileSolid[(int)TileRefs(k, num3 - 1).Type] || Main.tileSolidTop[(int)TileRefs(k, num3 - 1).Type])
                    {
                        flag = true;
                    }
                }
                else if (type != 138)
                {
                    if (!TileRefs(k, num3 + 2).Active || (!Main.tileSolid[(int)TileRefs(k, num3 + 2).Type] && !Main.tileTable[(int)TileRefs(k, num3 + 2).Type]))
                    {
                        flag = true;
                    }
                }
            }
            if (type == 138 && !SolidTile(TileRefs, num, num3 + 2) && !SolidTile(TileRefs, num + 1, num3 + 2))
            {
                flag = true;
            }
            if (flag)
            {
                destroyObject = true;
                for (int m = num; m < num + 2; m++)
                {
                    for (int n = num3; n < num3 + 2; n++)
                    {
                        if ((int)TileRefs(m, n).Type == type && TileRefs(m, n).Active)
                            KillTile(TileRefs, sandbox, m, n);
                    }
                }
                if (type == 85)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 321);

                if (type == 94)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 352);

                if (type == 95)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 344);

                if (type == 96)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 345);

                if (type == 97)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 346);

                if (type == 98)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 347);

                if (type == 99)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 348);

                if (type == 100)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 349);

                if (type == 125)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 487);

                if (type == 126)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 488);

                if (type == 132)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 513);

                if (type == 142)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 581);

                if (type == 143)
                    StorePlayerItem(sandbox, i * 16, j * 16, 32, 32, 582);

                if (type == 138 && !gen)
                    Projectile.NewProjectile((float)(num * 16) + 15.5f, (float)(num3 * 16 + 16), 0f, 0f, 99, 70, 10f, Main.myPlayer);

                destroyObject = false;
                for (int num4 = num - 1; num4 < num + 3; num4++)
                {
                    for (int num5 = num3 - 1; num5 < num3 + 3; num5++)
                    {
                        TileFrame(TileRefs, sandbox, num4, num5, false, false);
                    }
                }
            }
        }
Example #51
0
 public MethodScanner(GaugeApiConnection apiConnection, ISandbox sandbox)
 {
     _apiConnection = apiConnection;
     _sandbox       = sandbox;
 }
        public static bool PlaceTile(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, int type, bool mute = false, bool forced = false, int plr = -1, int style = 0)
        {
            if (type >= MAX_TILE_SETS)
                return false;

            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            bool result = false;
            if (i >= 0 && j >= 0 && i < Main.maxTilesX && j < Main.maxTilesY)
            {
                if (forced || Collision.EmptyTile(i, j, false) || !Main.tileSolid[type] || (type == 23 && TileRefs(i, j).Type == 0 && TileRefs(i, j).Active) || (type == 2 && TileRefs(i, j).Type == 0 && TileRefs(i, j).Active) || (type == 109 && TileRefs(i, j).Type == 0 && TileRefs(i, j).Active) || (type == 60 && TileRefs(i, j).Type == 59 && TileRefs(i, j).Active) || (type == 70 && TileRefs(i, j).Type == 59 && TileRefs(i, j).Active))
                {
                    var failed =
                        (type == 23 && (TileRefs(i, j).Type != 0 || !TileRefs(i, j).Active))
                        ||
                        (type == 2 && (TileRefs(i, j).Type != 0 || !TileRefs(i, j).Active))
                        ||
                        (type == 109 && (TileRefs(i, j).Type != 0 || !TileRefs(i, j).Active))
                        ||
                        (type == 60 && (TileRefs(i, j).Type != 59 || !TileRefs(i, j).Active));

                    if (failed)
                        return false;

                    if (type == 81)
                    {
                        if (TileRefs(i - 1, j).Active || TileRefs(i + 1, j).Active || TileRefs(i, j - 1).Active)
                            return false;
                        if (!TileRefs(i, j + 1).Active || !Main.tileSolid[(int)TileRefs(i, j + 1).Type])
                            return false;
                    }
                    if (TileRefs(i, j).Liquid > 0)
                    {
                        if (type == 4)
                        {
                            if (style != 8)
                                return false;
                        }
                        else if (type == 3 || type == 4 || type == 20 || type == 24 || type == 27 || type == 32 || type == 51 || type == 69 || type == 72)
                            return false;
                    }
                    TileRefs(i, j).SetFrameY(0);
                    TileRefs(i, j).SetFrameX(0);
                    if (type == 3 || type == 24 || type == 110)
                    {
                        if (j + 1 < Main.maxTilesY && TileRefs(i, j + 1).Active && ((TileRefs(i, j + 1).Type == 2 && type == 3) || (TileRefs(i, j + 1).Type == 23 && type == 24) || (TileRefs(i, j + 1).Type == 78 && type == 3) || (TileRefs(i, j + 1).Type == 109 && type == 110)))
                        {
                            if (type == 24 && genRand.Next(13) == 0)
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType(32);
                                SquareTileFrame(TileRefs, sandbox, i, j);
                            }
                            else if (TileRefs(i, j + 1).Type == 78)
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType((byte)type);
                                TileRefs(i, j).SetFrameX((short)(genRand.Next(2) * 18 + 108));
                            }
                            else if (TileRefs(i, j).Wall == 0 && TileRefs(i, j + 1).Wall == 0)
                            {
                                if (genRand.Next(50) == 0 || (type == 24 && genRand.Next(40) == 0))
                                {
                                    TileRefs(i, j).SetActive(true);
                                    TileRefs(i, j).SetType((byte)type);
                                    TileRefs(i, j).SetFrameX(144);
                                }
                                else if (genRand.Next(35) == 0)
                                {
                                    TileRefs(i, j).SetActive(true);
                                    TileRefs(i, j).SetType((byte)type);
                                    TileRefs(i, j).SetFrameX((short)(genRand.Next(2) * 18 + 108));
                                }
                                else
                                {
                                    TileRefs(i, j).SetActive(true);
                                    TileRefs(i, j).SetType((byte)type);
                                    TileRefs(i, j).SetFrameX((short)(genRand.Next(6) * 18));
                                }
                            }
                        }
                    }
                    else if (type == 61)
                    {
                        if (j + 1 < Main.maxTilesY && TileRefs(i, j + 1).Active && TileRefs(i, j + 1).Type == 60)
                        {
                            if (genRand.Next(16) == 0 && (double)j > Main.worldSurface)
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType(69);
                                SquareTileFrame(TileRefs, sandbox, i, j);
                            }
                            else if (genRand.Next(60) == 0 && (double)j > Main.rockLayer)
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType((byte)type);
                                TileRefs(i, j).SetFrameX(144);
                            }
                            else if (genRand.Next(1000) == 0 && (double)j > Main.rockLayer)
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType((byte)type);
                                TileRefs(i, j).SetFrameX(162);
                            }
                            else if (genRand.Next(15) == 0)
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType((byte)type);
                                TileRefs(i, j).SetFrameX((short)(genRand.Next(2) * 18 + 108));
                            }
                            else
                            {
                                TileRefs(i, j).SetActive(true);
                                TileRefs(i, j).SetType((byte)type);
                                TileRefs(i, j).SetFrameX((short)(genRand.Next(6) * 18));
                            }
                        }
                    }
                    else if (type == 71)
                    {
                        if (j + 1 < Main.maxTilesY && TileRefs(i, j + 1).Active && TileRefs(i, j + 1).Type == 70)
                        {
                            TileRefs(i, j).SetActive(true);
                            TileRefs(i, j).SetType((byte)type);
                            TileRefs(i, j).SetFrameX((short)(genRand.Next(5) * 18));
                        }
                    }
                    else if (type == 129)
                    {
                        if (SolidTile(TileRefs, i - 1, j) || SolidTile(TileRefs, i + 1, j) || SolidTile(TileRefs, i, j - 1) || SolidTile(TileRefs, i, j + 1))
                        {
                            TileRefs(i, j).SetActive(true);
                            TileRefs(i, j).SetType((byte)type);
                            TileRefs(i, j).SetFrameX((short)(genRand.Next(8) * 18));
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                    }
                    else if (type == 132 || type == 138 || type == 142 || type == 143)
                    {
                        Place2x2(TileRefs, i, j, type);
                    }
                    else if (type == 137)
                    {
                        TileRefs(i, j).SetActive(true);
                        TileRefs(i, j).SetType((byte)type);

                        if (style == 1)
                            TileRefs(i, j).SetFrameX(18);
                    }
                    else if (type == 136)
                    {
                        if ((TileRefs(i - 1, j).Active && (Main.tileSolid[(int)TileRefs(i - 1, j).Type] || TileRefs(i - 1, j).Type == 124 || (TileRefs(i - 1, j).Type == 5 && TileRefs(i - 1, j - 1).Type == 5 && TileRefs(i - 1, j + 1).Type == 5))) || (TileRefs(i + 1, j).Active && (Main.tileSolid[(int)TileRefs(i + 1, j).Type] || TileRefs(i + 1, j).Type == 124 || (TileRefs(i + 1, j).Type == 5 && TileRefs(i + 1, j - 1).Type == 5 && TileRefs(i + 1, j + 1).Type == 5))) || (TileRefs(i, j + 1).Active && Main.tileSolid[(int)TileRefs(i, j + 1).Type]))
                        {
                            TileRefs(i, j).SetActive(true);
                            TileRefs(i, j).SetType((byte)type);
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                    }
                    else if (type == 4)
                    {
                        if ((TileRefs(i - 1, j).Active && (Main.tileSolid[(int)TileRefs(i - 1, j).Type] || TileRefs(i - 1, j).Type == 124 || (TileRefs(i - 1, j).Type == 5 && TileRefs(i - 1, j - 1).Type == 5 && TileRefs(i - 1, j + 1).Type == 5))) || (TileRefs(i + 1, j).Active && (Main.tileSolid[(int)TileRefs(i + 1, j).Type] || TileRefs(i + 1, j).Type == 124 || (TileRefs(i + 1, j).Type == 5 && TileRefs(i + 1, j - 1).Type == 5 && TileRefs(i + 1, j + 1).Type == 5))) || (TileRefs(i, j + 1).Active && Main.tileSolid[(int)TileRefs(i, j + 1).Type]))
                        {
                            TileRefs(i, j).SetActive(true);
                            TileRefs(i, j).SetType((byte)type);
                            TileRefs(i, j).SetFrameY((short)(22 * style));
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                    }
                    else if (type == 10)
                    {
                        if (!TileRefs(i, j - 1).Active && !TileRefs(i, j - 2).Active && TileRefs(i, j - 3).Active && Main.tileSolid[(int)TileRefs(i, j - 3).Type])
                        {
                            PlaceDoor(TileRefs, i, j - 1, type);
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                        else
                        {
                            if (TileRefs(i, j + 1).Active || TileRefs(i, j + 2).Active || !TileRefs(i, j + 3).Active || !Main.tileSolid[(int)TileRefs(i, j + 3).Type])
                                return false;

                            PlaceDoor(TileRefs, i, j + 1, type);
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                    }
                    else if (type == 128)
                    {
                        PlaceMan(TileRefs, i, j, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 149)
                    {
                        if (SolidTile(TileRefs, i - 1, j) || SolidTile(TileRefs, i + 1, j) ||
                            SolidTile(TileRefs, i, j - 1) || SolidTile(TileRefs, i, j + 1))
                        {
                            TileRefs(i, j).SetFrameX((short)(18 * style));
                            TileRefs(i, j).SetActive(true);
                            TileRefs(i, j).SetType((byte)type);
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                    }
                    else if (type == 139)
                    {
                        PlaceMB(TileRefs, i, j, type, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 34 || type == 35 || type == 36 || type == 106)
                    {
                        Place3x3(TileRefs, i, j, type);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 13 || type == 33 || type == 49 || type == 50 || type == 78)
                    {
                        PlaceOnTable1x1(TileRefs, i, j, type, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 14 || type == 26 || type == 86 || type == 87 || type == 88 || type == 89 || type == 114)
                    {
                        Place3x2(TileRefs, i, j, type);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 20)
                    {
                        if (TileRefs(i, j + 1).Active && (TileRefs(i, j + 1).Type == 2 || TileRefs(i, j + 1).Type == 109 || TileRefs(i, j + 1).Type == 147))
                        {
                            Place1x2(TileRefs, i, j, type, style);
                            SquareTileFrame(TileRefs, sandbox, i, j);
                        }
                    }
                    else if (type == 15)
                    {
                        Place1x2(TileRefs, i, j, type, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 16 || type == 18 || type == 29 || type == 103 || type == 134)
                    {
                        Place2x1(TileRefs, i, j, type);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 92 || type == 93)
                    {
                        Place1xX(TileRefs, i, j, type, 0);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 104 || type == 105)
                    {
                        Place2xX(TileRefs, i, j, type, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 17 || type == 77 || type == 133)
                    {
                        Place3x2(TileRefs, i, j, type);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 21)
                    {
                        PlaceChest(TileRefs, i, j, type, false, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 91)
                    {
                        PlaceBanner(TileRefs, i, j, type, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 135 || type == 141 || type == 144)
                    {
                        Place1x1(TileRefs, i, j, type, style);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 101 || type == 102)
                    {
                        Place3x4(TileRefs, i, j, type);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 27)
                    {
                        PlaceSunflower(TileRefs, i, j, 27);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 28)
                    {
                        PlacePot(TileRefs, i, j, 28);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 42)
                    {
                        Place1x2Top(TileRefs, i, j, type);
                        SquareTileFrame(TileRefs, sandbox, i, j);
                    }
                    else if (type == 55 || type == 85)
                    {
                        PlaceSign(TileRefs, i, j, type);
                    }
                    else if (Main.tileAlch[type])
                    {
                        PlaceAlch(TileRefs, i, j, style);
                    }
                    else if (type == 94 || type == 95 || type == 96 || type == 97 || type == 98 || type == 99 || type == 100 || type == 125 || type == 126)
                    {
                        Place2x2(TileRefs, i, j, type);
                    }
                    else if (type == 79 || type == 90)
                    {
                        int direction = 1;
                        if (plr > -1)
                            direction = Main.players[plr].direction;

                        Place4x2(TileRefs, i, j, type, direction);
                    }
                    else if (type == 81)
                    {
                        TileRefs(i, j).SetFrameX((short)(26 * genRand.Next(6)));
                        TileRefs(i, j).SetActive(true);
                        TileRefs(i, j).SetType((byte)type);
                    }
                    else
                    {
                        TileRefs(i, j).SetActive(true);
                        TileRefs(i, j).SetType((byte)type);
                    }

                    if (TileRefs(i, j).Active && !mute)
                    {
                        SquareTileFrame(TileRefs, sandbox, i, j);
                        return true;
                    }
                }
            }
            return result;
        }
Example #53
0
 public ScenarioExecutionEndingProcessor(IHookRegistry hookRegistry, IMethodExecutor methodExecutor, ISandbox sandbox)
     : base(hookRegistry, methodExecutor)
 {
     _sandbox = sandbox;
 }
        public static bool placeTrap(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x2, int y2, int type = -1)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            int num = y2;
            while (!SolidTile(TileRefs, x2, num))
            {
                num++;
                if (num >= Main.maxTilesY - 300)
                {
                    return false;
                }
            }
            num--;
            if (TileRefs(x2, num).Liquid > 0 && TileRefs(x2, num).Lava)
            {
                return false;
            }
            if (type == -1 && Main.rand.Next(20) == 0)
            {
                type = 2;
            }
            else
            {
                if (type == -1)
                {
                    type = Main.rand.Next(2);
                }
            }
            if (TileRefs(x2, num).Active || TileRefs(x2 - 1, num).Active || TileRefs(x2 + 1, num).Active || TileRefs(x2, num - 1).Active || TileRefs(x2 - 1, num - 1).Active || TileRefs(x2 + 1, num - 1).Active || TileRefs(x2, num - 2).Active || TileRefs(x2 - 1, num - 2).Active || TileRefs(x2 + 1, num - 2).Active)
            {
                return false;
            }
            if (TileRefs(x2, num + 1).Type == 48)
            {
                return false;
            }
            if (type == 0)
            {
                int num2 = x2;
                int num3 = num;
                num3 -= genRand.Next(3);
                while (!SolidTile(TileRefs, num2, num3))
                {
                    num2--;
                }
                int num4 = num2;
                num2 = x2;
                while (!SolidTile(TileRefs, num2, num3))
                {
                    num2++;
                }
                int num5 = num2;
                int num6 = x2 - num4;
                int num7 = num5 - x2;
                bool flag = false;
                bool flag2 = false;
                if (num6 > 5 && num6 < 50)
                {
                    flag = true;
                }
                if (num7 > 5 && num7 < 50)
                {
                    flag2 = true;
                }
                if (flag && !SolidTile(TileRefs, num4, num3 + 1))
                {
                    flag = false;
                }
                if (flag2 && !SolidTile(TileRefs, num5, num3 + 1))
                {
                    flag2 = false;
                }
                if (flag && (TileRefs(num4, num3).Type == 10 || TileRefs(num4, num3).Type == 48 || TileRefs(num4, num3 + 1).Type == 10 || TileRefs(num4, num3 + 1).Type == 48))
                {
                    flag = false;
                }
                if (flag2 && (TileRefs(num5, num3).Type == 10 || TileRefs(num5, num3).Type == 48 || TileRefs(num5, num3 + 1).Type == 10 || TileRefs(num5, num3 + 1).Type == 48))
                {
                    flag2 = false;
                }
                int style = 0;
                if (flag && flag2)
                {
                    style = 1;
                    num2 = num4;
                    if (genRand.Next(2) == 0)
                    {
                        num2 = num5;
                        style = -1;
                    }
                }
                else
                {
                    if (flag2)
                    {
                        num2 = num5;
                        style = -1;
                    }
                    else
                    {
                        if (!flag)
                        {
                            return false;
                        }
                        num2 = num4;
                        style = 1;
                    }
                }
                if (TileRefs(x2, num).Wall > 0)
                {
                    PlaceTile(TileRefs, sandbox, x2, num, 135, true, true, -1, 2);
                }
                else
                {
                    PlaceTile(TileRefs, sandbox, x2, num, 135, true, true, -1, genRand.Next(2, 4));
                }
                KillTile(TileRefs, sandbox, num2, num3);
                PlaceTile(TileRefs, sandbox, num2, num3, 137, true, true, -1, style);
                int num8 = x2;
                int num9 = num;
                while (num8 != num2 || num9 != num3)
                {
                    TileRefs(num8, num9).SetWire(true);
                    if (num8 > num2)
                    {
                        num8--;
                    }
                    if (num8 < num2)
                    {
                        num8++;
                    }
                    TileRefs(num8, num9).SetWire(true);
                    if (num9 > num3)
                    {
                        num9--;
                    }
                    if (num9 < num3)
                    {
                        num9++;
                    }
                    TileRefs(num8, num9).SetWire(true);
                }
                return true;
            }
            if (type != 1)
            {
                if (type == 2)
                {
                    int num10 = Main.rand.Next(4, 7);
                    int num11 = x2 + Main.rand.Next(-1, 2);
                    int num12 = num;
                    for (int i = 0; i < num10; i++)
                    {
                        num12++;
                        if (!SolidTile(TileRefs, num11, num12))
                        {
                            return false;
                        }
                    }
                    for (int j = num11 - 2; j <= num11 + 2; j++)
                    {
                        for (int k = num12 - 2; k <= num12 + 2; k++)
                        {
                            if (!SolidTile(TileRefs, j, k))
                            {
                                return false;
                            }
                        }
                    }
                    KillTile(TileRefs, sandbox, num11, num12);
                    TileRefs(num11, num12).SetActive(true);
                    TileRefs(num11, num12).SetType(141);
                    TileRefs(num11, num12).SetFrameX(0);
                    TileRefs(num11, num12).SetFrameY((short)(18 * Main.rand.Next(2)));
                    PlaceTile(TileRefs, sandbox, x2, num, 135, true, true, -1, genRand.Next(2, 4));
                    int num13 = x2;
                    int num14 = num;
                    while (num13 != num11 || num14 != num12)
                    {
                        TileRefs(num13, num14).SetWire(true);
                        if (num13 > num11)
                        {
                            num13--;
                        }
                        if (num13 < num11)
                        {
                            num13++;
                        }
                        TileRefs(num13, num14).SetWire(true);
                        if (num14 > num12)
                        {
                            num14--;
                        }
                        if (num14 < num12)
                        {
                            num14++;
                        }
                        TileRefs(num13, num14).SetWire(true);
                    }
                }
                return false;
            }
            int num15 = num - 8;
            int num16 = x2 + genRand.Next(-1, 2);
            bool flag3 = true;
            while (flag3)
            {
                bool flag4 = true;
                int num17 = 0;
                for (int l = num16 - 2; l <= num16 + 3; l++)
                {
                    for (int m = num15; m <= num15 + 3; m++)
                    {
                        if (!SolidTile(TileRefs, l, m))
                        {
                            flag4 = false;
                        }
                        if (TileRefs(l, m).Active && (TileRefs(l, m).Type == 0 || TileRefs(l, m).Type == 1 || TileRefs(l, m).Type == 59))
                        {
                            num17++;
                        }
                    }
                }
                num15--;
                if ((double)num15 < Main.worldSurface)
                {
                    return false;
                }
                if (flag4 && num17 > 2)
                {
                    flag3 = false;
                }
            }
            if (num - num15 <= 5 || num - num15 >= 40)
            {
                return false;
            }
            for (int n = num16; n <= num16 + 1; n++)
            {
                for (int num18 = num15; num18 <= num; num18++)
                {
                    if (SolidTile(TileRefs, n, num18))
                    {
                        KillTile(TileRefs, sandbox, n, num18);
                    }
                }
            }
            for (int num19 = num16 - 2; num19 <= num16 + 3; num19++)
            {
                for (int num20 = num15 - 2; num20 <= num15 + 3; num20++)
                {
                    if (SolidTile(TileRefs, num19, num20))
                    {
                        TileRefs(num19, num20).SetType(1);
                    }
                }
            }
            PlaceTile(TileRefs, sandbox, x2, num, 135, true, true, -1, genRand.Next(2, 4));
            PlaceTile(TileRefs, sandbox, num16, num15 + 2, 130, true, false, -1, 0);
            PlaceTile(TileRefs, sandbox, num16 + 1, num15 + 2, 130, true, false, -1, 0);
            PlaceTile(TileRefs, sandbox, num16 + 1, num15 + 1, 138, true, false, -1, 0);
            num15 += 2;
            TileRefs(num16, num15).SetWire(true);
            TileRefs(num16 + 1, num15).SetWire(true);
            num15++;
            PlaceTile(TileRefs, sandbox, num16, num15, 130, true, false, -1, 0);
            PlaceTile(TileRefs, sandbox, num16 + 1, num15, 130, true, false, -1, 0);
            TileRefs(num16, num15).SetWire(true);
            TileRefs(num16 + 1, num15).SetWire(true);
            PlaceTile(TileRefs, sandbox, num16, num15 + 1, 130, true, false, -1, 0);
            PlaceTile(TileRefs, sandbox, num16 + 1, num15 + 1, 130, true, false, -1, 0);
            TileRefs(num16, num15 + 1).SetWire(true);
            TileRefs(num16 + 1, num15 + 1).SetWire(true);
            int num21 = x2;
            int num22 = num;
            while (num21 != num16 || num22 != num15)
            {
                TileRefs(num21, num22).SetWire(true);
                if (num21 > num16)
                {
                    num21--;
                }
                if (num21 < num16)
                {
                    num21++;
                }
                TileRefs(num21, num22).SetWire(true);
                if (num22 > num15)
                {
                    num22--;
                }
                if (num22 < num15)
                {
                    num22++;
                }
                TileRefs(num21, num22).SetWire(true);
            }
            return true;
        }
Example #55
0
 public void Initialize(SandboxManager manager)
 {
     this._manager = manager;
     this._sandbox = this._manager.DefaultSandbox;
 }
        public static void Check2xX(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, byte type)
        {
            if (destroyObject)
                return;

            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            var frx = (int)TileRefs(x, y).FrameX;
            int num = x, k;
            for (k = frx; k >= 36; k -= 36) { }

            if (k == 18)
                num--;

            int num2 = y - (int)(TileRefs(num, y).FrameY / 18);

            int frameX = (int)TileRefs(num, y).FrameX;
            int num3 = 3;

            if (type == 104)
                num3 = 5;

            bool flag = false;
            for (int l = 0; l < num3; l++)
            {
                if (!TileRefs(num, num2 + l).Active)
                {
                    flag = true;
                }
                else if (TileRefs(num, num2 + l).Type != type)
                {
                    flag = true;
                }
                else if ((int)TileRefs(num, num2 + l).FrameY != l * 18)
                {
                    flag = true;
                }
                else if ((int)TileRefs(num, num2 + l).FrameX != frameX)
                {
                    flag = true;
                }

                if (!TileRefs(num + 1, num2 + l).Active)
                {
                    flag = true;
                }
                else if (TileRefs(num + 1, num2 + l).Type != type)
                {
                    flag = true;
                }
                else if ((int)TileRefs(num + 1, num2 + l).FrameY != l * 18)
                {
                    flag = true;
                }
                else if ((int)TileRefs(num + 1, num2 + l).FrameX != frameX + 18)
                {
                    flag = true;
                }
            }

            if (!TileRefs(num, num2 + num3).Active)
            {
                flag = true;
            }
            if (!Main.tileSolid[(int)TileRefs(num, num2 + num3).Type])
            {
                flag = true;
            }
            if (!TileRefs(num + 1, num2 + num3).Active)
            {
                flag = true;
            }
            if (!Main.tileSolid[(int)TileRefs(num + 1, num2 + num3).Type])
            {
                flag = true;
            }

            if (flag)
            {
                destroyObject = true;
                for (int m = 0; m < num3; m++)
                {
                    if (TileRefs(num, num2 + m).Type == type)
                        KillTile(TileRefs, sandbox, num, num2 + m);

                    if (TileRefs(num + 1, num2 + m).Type == type)
                        KillTile(TileRefs, sandbox, num + 1, num2 + m);
                }

                if (type == 104)
                    StorePlayerItem(sandbox, num * 16, y * 16, 32, 32, 359, 1, false, 0);

                if (type == 105)
                {
                    int num4 = frameX / 36;

                    if (num4 == 0)
                        num4 = 360;
                    else if (num4 == 1)
                        num4 = 52;
                    else
                        num4 = 438 + num4 - 2;

                    StorePlayerItem(sandbox, num * 16, y * 16, 32, 32, num4, 1, false, 0);
                }

                destroyObject = false;
            }
        }
        public static bool OpenDoor(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, int direction, ISender sender)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            if (sender == null)
                sender = new ConsoleSender();

            if (Program.properties.NPCDoorOpenCancel && sender is NPC)
                return false;

            var ctx = new HookContext
            {
                Sender = sender,
            };

            var args = new HookArgs.DoorStateChanged
            {
                X = x,
                Y = y,
                Direction = direction,
                Open = true,
            };

            HookPoints.DoorStateChanged.Invoke(ref ctx, ref args);

            if (ctx.CheckForKick())
                return false;

            if (ctx.Result == HookResult.IGNORE)
                return false;

            if (ctx.Result == HookResult.RECTIFY)
            {
                NetMessage.SendData(19, -1, -1, "", 1, (float)x, (float)y, 0); //Inform the client of the update
                return false;
            }

            int num = 0;
            if (TileRefs(x, y - 1).FrameY == 0 && TileRefs(x, y - 1).Type == TileRefs(x, y).Type)
            {
                num = y - 1;
            }
            else if (TileRefs(x, y - 2).FrameY == 0 && TileRefs(x, y - 2).Type == TileRefs(x, y).Type)
            {
                num = y - 2;
            }
            else if (TileRefs(x, y + 1).FrameY == 0 && TileRefs(x, y + 1).Type == TileRefs(x, y).Type)
            {
                num = y + 1;
            }
            else
            {
                num = y;
            }
            int num2 = x;
            short num3 = 0;
            int num4;
            if (direction == -1)
            {
                num2 = x - 1;
                num3 = 36;
                num4 = x - 1;
            }
            else
            {
                num2 = x;
                num4 = x + 1;
            }
            bool flag = true;
            for (int k = num; k < num + 3; k++)
            {
                if (TileRefs(num4, k).Active)
                {
                    if (!Main.tileCut[(int)TileRefs(num4, k).Type] && TileRefs(num4, k).Type != 3 && TileRefs(num4, k).Type != 24 && TileRefs(num4, k).Type != 52 && TileRefs(num4, k).Type != 61 && TileRefs(num4, k).Type != 62 && TileRefs(num4, k).Type != 69 && TileRefs(num4, k).Type != 71 && TileRefs(num4, k).Type != 73 && TileRefs(num4, k).Type != 74)
                    {
                        flag = false;
                        break;
                    }
                    KillTile(TileRefs, sandbox, num4, k);
                }
            }
            if (flag)
            {
                for (int l = num2; l <= num2 + 1; l++)
                    for (int m = num; m <= num + 2; m++)
                        if (numNoWire < MAX_WIRE - 1)
                        {
                            noWireX[numNoWire] = l;
                            noWireY[numNoWire] = m;
                            numNoWire++;
                        }

                TileRefs(num2, num).SetActive(true);
                TileRefs(num2, num).SetType(11);
                TileRefs(num2, num).SetFrameY(0);
                TileRefs(num2, num).SetFrameX(num3);
                TileRefs(num2 + 1, num).SetActive(true);
                TileRefs(num2 + 1, num).SetType(11);
                TileRefs(num2 + 1, num).SetFrameY(0);
                TileRefs(num2 + 1, num).SetFrameX((short)(num3 + 18));
                TileRefs(num2, num + 1).SetActive(true);
                TileRefs(num2, num + 1).SetType(11);
                TileRefs(num2, num + 1).SetFrameY(18);
                TileRefs(num2, num + 1).SetFrameX(num3);
                TileRefs(num2 + 1, num + 1).SetActive(true);
                TileRefs(num2 + 1, num + 1).SetType(11);
                TileRefs(num2 + 1, num + 1).SetFrameY(18);
                TileRefs(num2 + 1, num + 1).SetFrameX((short)(num3 + 18));
                TileRefs(num2, num + 2).SetActive(true);
                TileRefs(num2, num + 2).SetType(11);
                TileRefs(num2, num + 2).SetFrameY(36);
                TileRefs(num2, num + 2).SetFrameX(num3);
                TileRefs(num2 + 1, num + 2).SetActive(true);
                TileRefs(num2 + 1, num + 2).SetType(11);
                TileRefs(num2 + 1, num + 2).SetFrameY(36);
                TileRefs(num2 + 1, num + 2).SetFrameX((short)(num3 + 18));
                for (int l = num2 - 1; l <= num2 + 2; l++)
                {
                    for (int m = num - 1; m <= num + 2; m++)
                    {
                        TileFrame(TileRefs, sandbox, l, m, false, false);
                    }
                }
            }
            return flag;
        }
        public static void PlantCactus(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            GrowCactus(TileRefs, sandbox, i, j);
            for (int k = 0; k < 150; k++)
            {
                int i2 = genRand.Next(i - 1, i + 2);
                int j2 = genRand.Next(j - 10, j + 2);
                GrowCactus(TileRefs, sandbox, i2, j2);
            }
        }
Example #59
0
 public DataStoreInitProcessor(ISandbox sandbox)
 {
     _sandbox = sandbox;
 }
        public static void OreRunner(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int i, int j, double strength, int steps, int type)
        {
            if (TileRefs == null)
                TileRefs = TileCollection.ITileAt;

            double num = strength;
            float num2 = (float)steps;
            Vector2 value;
            value.X = (float)i;
            value.Y = (float)j;
            Vector2 value2;
            value2.X = (float)genRand.Next(-10, 11) * 0.1f;
            value2.Y = (float)genRand.Next(-10, 11) * 0.1f;
            while (num > 0.0 && num2 > 0f)
            {
                if (value.Y < 0f && num2 > 0f && type == 59)
                {
                    num2 = 0f;
                }
                num = strength * (double)(num2 / (float)steps);
                num2 -= 1f;
                int num3 = (int)((double)value.X - num * 0.5);
                int num4 = (int)((double)value.X + num * 0.5);
                int num5 = (int)((double)value.Y - num * 0.5);
                int num6 = (int)((double)value.Y + num * 0.5);
                if (num3 < 0)
                {
                    num3 = 0;
                }
                if (num4 > Main.maxTilesX)
                {
                    num4 = Main.maxTilesX;
                }
                if (num5 < 0)
                {
                    num5 = 0;
                }
                if (num6 > Main.maxTilesY)
                {
                    num6 = Main.maxTilesY;
                }
                for (int k = num3; k < num4; k++)
                {
                    for (int l = num5; l < num6; l++)
                    {
                        if ((double)(Math.Abs((float)k - value.X) + Math.Abs((float)l - value.Y)) < strength * 0.5 * (1.0 + (double)genRand.Next(-10, 11) * 0.015) &&
                            TileRefs(k, l).Active && (TileRefs(k, l).Type == 0 || TileRefs(k, l).Type == 1 || TileRefs(k, l).Type == 23 || TileRefs(k, l).Type == 25 ||
                                TileRefs(k, l).Type == 40 || TileRefs(k, l).Type == 53 || TileRefs(k, l).Type == 57 || TileRefs(k, l).Type == 59 ||
                                    TileRefs(k, l).Type == 60 || TileRefs(k, l).Type == 70 || TileRefs(k, l).Type == 109 || TileRefs(k, l).Type == 112 ||
                                        TileRefs(k, l).Type == 116 || TileRefs(k, l).Type == 117))
                        {
                            TileRefs(k, l).SetType((byte)type);
                            SquareTileFrame(TileRefs, sandbox, k, l, true);
                            NetMessage.SendTileSquare(-1, k, l, 1);
                        }
                    }
                }
                value += value2;
                value2.X += (float)genRand.Next(-10, 11) * 0.05f;
                if (value2.X > 1f)
                {
                    value2.X = 1f;
                }
                if (value2.X < -1f)
                {
                    value2.X = -1f;
                }
            }
        }