コード例 #1
0
        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;
        }
コード例 #2
0
        public static bool OpenDoor(int x, int y, int direction, ISender sender)
        {
            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 (Main.tile.At(x, y - 1).FrameY == 0 && Main.tile.At(x, y - 1).Type == Main.tile.At(x, y).Type)
            {
                num = y - 1;
            }
            else if (Main.tile.At(x, y - 2).FrameY == 0 && Main.tile.At(x, y - 2).Type == Main.tile.At(x, y).Type)
            {
                num = y - 2;
            }
            else if (Main.tile.At(x, y + 1).FrameY == 0 && Main.tile.At(x, y + 1).Type == Main.tile.At(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 (Main.tile.At(num4, k).Active)
                {
                    if (Main.tile.At(num4, k).Type != 3 && Main.tile.At(num4, k).Type != 24 && Main.tile.At(num4, k).Type != 52 && Main.tile.At(num4, k).Type != 61 && Main.tile.At(num4, k).Type != 62 && Main.tile.At(num4, k).Type != 69 && Main.tile.At(num4, k).Type != 71 && Main.tile.At(num4, k).Type != 73 && Main.tile.At(num4, k).Type != 74)
                    {
                        flag = false;
                        break;
                    }
                    WorldModify.KillTile(num4, k, false, false, false);
                }
            }
            if (flag)
            {
                Main.tile.At(num2, num).SetActive (true);
                Main.tile.At(num2, num).SetType (11);
                Main.tile.At(num2, num).SetFrameY (0);
                Main.tile.At(num2, num).SetFrameX (num3);
                Main.tile.At(num2 + 1, num).SetActive (true);
                Main.tile.At(num2 + 1, num).SetType (11);
                Main.tile.At(num2 + 1, num).SetFrameY (0);
                Main.tile.At(num2 + 1, num).SetFrameX ((short)(num3 + 18));
                Main.tile.At(num2, num + 1).SetActive (true);
                Main.tile.At(num2, num + 1).SetType (11);
                Main.tile.At(num2, num + 1).SetFrameY (18);
                Main.tile.At(num2, num + 1).SetFrameX (num3);
                Main.tile.At(num2 + 1, num + 1).SetActive (true);
                Main.tile.At(num2 + 1, num + 1).SetType (11);
                Main.tile.At(num2 + 1, num + 1).SetFrameY (18);
                Main.tile.At(num2 + 1, num + 1).SetFrameX ((short)(num3 + 18));
                Main.tile.At(num2, num + 2).SetActive (true);
                Main.tile.At(num2, num + 2).SetType (11);
                Main.tile.At(num2, num + 2).SetFrameY (36);
                Main.tile.At(num2, num + 2).SetFrameX (num3);
                Main.tile.At(num2 + 1, num + 2).SetActive (true);
                Main.tile.At(num2 + 1, num + 2).SetType (11);
                Main.tile.At(num2 + 1, num + 2).SetFrameY (36);
                Main.tile.At(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++)
                    {
                        WorldModify.TileFrame(l, m, false, false);
                    }
                }
            }
            return flag;
        }
コード例 #3
0
        public static bool CloseDoor(Func<Int32, Int32, ITile> TileRefs, ISandbox sandbox, int x, int y, bool forced, 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 = 1,
                Open = false,
            };

            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, "", 0, (float)x, (float)y, 0); //Inform the client of the update
                return false;
            }

            int num = 0;
            int num2 = x;
            int num3 = y;

            int frameX = (int)TileRefs(x, y).FrameX;
            int frameY = (int)TileRefs(x, y).FrameY;
            if (frameX == 0)
            {
                num2 = x;
                num = 1;
            }
            else if (frameX == 18)
            {
                num2 = x - 1;
                num = 1;
            }
            else if (frameX == 36)
            {
                num2 = x + 1;
                num = -1;
            }
            else if (frameX == 54)
            {
                num2 = x;
                num = -1;
            }

            if (frameY == 0)
            {
                num3 = y;
            }
            else if (frameY == 18)
            {
                num3 = y - 1;
            }
            else if (frameY == 36)
            {
                num3 = y - 2;
            }

            int num4 = num2;
            if (num == -1)
            {
                num4 = num2 - 1;
            }
            if (!forced)
            {
                for (int k = num3; k < num3 + 3; k++)
                {
                    if (!Collision.EmptyTile(num2, k, true))
                        return false;
                }
            }
            for (int l = num4; l < num4 + 2; l++)
            {
                for (int m = num3; m < num3 + 3; m++)
                {
                    if (l == num2)
                    {
                        TileRefs(l, m).SetType(10);
                        TileRefs(l, m).SetFrameX((short)(genRand.Next(3) * 18));
                    }
                    else
                    {
                        TileRefs(l, m).SetActive(false);
                    }
                }
            }

            /* 1.1 */
            int num5 = num2;
            for (int n = num3; n <= num3 + 2; n++)
            {
                if (numNoWire < MAX_WIRE - 1)
                {
                    noWireX[numNoWire] = num5;
                    noWireY[numNoWire] = n;
                    numNoWire++;
                }
            }

            for (int n = num2 - 1; n <= num2 + 1; n++)
            {
                for (int num6 = num3 - 1; num5 <= num3 + 2; num5++)
                {
                    TileFrame(TileRefs, sandbox, n, num5, false, false);
                }
            }
            return true;
        }
コード例 #4
0
        public static bool CloseDoor(int x, int y, bool forced, ISender sender)
        {
            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 = 1,
                Open = false,
            };

            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, "", 0, (float)x, (float)y, 0); //Inform the client of the update
                return false;
            }

            int num = 0;
            int num2 = x;
            int num3 = y;

            int frameX = (int)Main.tile.At(x, y).FrameX;
            int frameY = (int)Main.tile.At(x, y).FrameY;
            if (frameX == 0)
            {
                num2 = x;
                num = 1;
            }
            else if (frameX == 18)
            {
                num2 = x - 1;
                num = 1;
            }
            else if (frameX == 36)
            {
                num2 = x + 1;
                num = -1;
            }
            else if (frameX == 54)
            {
                num2 = x;
                num = -1;
            }
            if (frameY == 0)
            {
                num3 = y;
            }
            else if (frameY == 18)
            {
                num3 = y - 1;
            }
            else if (frameY == 36)
            {
                num3 = y - 2;
            }
            int num4 = num2;
            if (num == -1)
            {
                num4 = num2 - 1;
            }
            if (!forced)
            {
                for (int k = num3; k < num3 + 3; k++)
                {
                    if (!Collision.EmptyTile(num2, k, true))
                    {
                        return false;
                    }
                }
            }
            for (int l = num4; l < num4 + 2; l++)
            {
                for (int m = num3; m < num3 + 3; m++)
                {
                    if (l == num2)
                    {
                        Main.tile.At(l, m).SetType (10);
                        Main.tile.At(l, m).SetFrameX ((short)(WorldModify.genRand.Next(3) * 18));
                    }
                    else
                    {
                        Main.tile.At(l, m).SetActive (false);
                    }
                }
            }
            for (int n = num2 - 1; n <= num2 + 1; n++)
            {
                for (int num5 = num3 - 1; num5 <= num3 + 2; num5++)
                {
                    WorldModify.TileFrame(n, num5, false, false);
                }
            }
            return true;
        }