public override bool?CanHitNPCWithProj(Projectile proj, NPC target)
 {
     if (critterCatch && target.catchItem > 0 && proj.Colliding(proj.getRect(), target.getRect()))
     {
         GadgetMethods.CatchNPC(target.whoAmI, player.whoAmI, false);
         return(false);
     }
     return(null);
 }
        public override void MeleeEffects(Item item, Rectangle hitbox)
        {
            if (!critterCatch || Main.myPlayer != player.whoAmI || item.type == ItemID.BugNet || item.type == ItemID.GoldenBugNet)
            {
                return;
            }

            for (byte i = 0; i < Main.maxNPCs; i++)
            {
                NPC npc = Main.npc[i];
                if (!npc.active || npc.catchItem <= 0)
                {
                    continue;
                }

                if (hitbox.Intersects(npc.getRect()) && (npc.noTileCollide || player.CanHit(npc)))
                {
                    GadgetMethods.CatchNPC(i, player.whoAmI);
                }
            }
        }
Exemple #3
0
        public override void HandlePacket(BinaryReader reader, int whoAmI)
        {
            MessageType message = (MessageType)reader.ReadByte();

            switch (message)
            {
            case MessageType.CatchNPC:
                GadgetMethods.CatchNPC(reader.ReadByte(), whoAmI, reader.ReadBoolean());                         // fixes catching of npcs with projectiles
                break;

            case MessageType.ExtractorMessage:
                this.GetTileEntity <ChlorophyteExtractorTE>(reader.ReadInt32())?.ReceiveExtractorMessage(reader, whoAmI);
                break;

            case MessageType.TripWire:
                int tileX = reader.ReadInt32();
                int tileY = reader.ReadInt32();
                if (WorldGen.InWorld(tileX, tileY) && Main.tile[tileX, tileY] != null)
                {
                    Items.Tools.ActivationRod.TriggerMech(tileX, tileY);
                }
                break;
            }
        }
Exemple #4
0
        public bool GenerateBoulderTrap(int x, int y, bool floorTrap)
        {
            int plateY = y;

            while (!WorldGen.SolidTile3(x, plateY))
            {
                plateY++;
                if (plateY > WorldGen.tBottom)
                {
                    return(false);
                }
            }

            if (Main.tile[x, plateY].type == TileID.WoodenSpikes)
            {
                return(false);
            }

            plateY--;

            if (Main.tile[x, plateY].type == TileID.LihzahrdAltar)
            {
                return(false);
            }

            int  trapY = y, trapX = WorldGen.genRand.Next(2), plateX = WorldGen.genRand.Next(2);
            bool placePlate = true;
            byte wireColor  = 4;

            if (floorTrap)
            {
                trapY = plateY + 1;

                if ((Main.tile[x - 1 + ((trapX ^ 1) * 2), plateY].type != TileID.LihzahrdBrick &&
                     Main.tile[x - 1 + ((trapX ^ 1) * 2), plateY].type != TileID.WoodenSpikes &&
                     Main.tile[x - 1 + ((trapX ^ 1) * 2), plateY].type != TileID.LihzahrdAltar) &&
                    GadgetMethods.TileAreaCheck(x - trapX, trapY, 2, 2, true, TileID.LihzahrdBrick, true, WallID.LihzahrdBrickUnsafe))
                {
                    trapX = x - trapX;
                }
                else if ((Main.tile[x - 1 + (trapX * 2), plateY].type != TileID.LihzahrdBrick &&
                          Main.tile[x - 1 + (trapX * 2), plateY].type != TileID.WoodenSpikes &&
                          Main.tile[x - 1 + (trapX * 2), plateY].type != TileID.LihzahrdAltar) &&
                         GadgetMethods.TileAreaCheck(x - (trapX ^ 1), trapY, 2, 2, true, TileID.LihzahrdBrick, true, WallID.LihzahrdBrickUnsafe))
                {
                    trapX = x - (trapX ^ 1);
                }
                else
                {
                    return(false);
                }

                placePlate = !(GadgetMethods.HasWire(trapX, plateY) || GadgetMethods.HasWire(trapX + 1, plateY));

                if (placePlate)
                {
                    if (WorldGen.TileEmpty(trapX + plateX, plateY))
                    {
                        plateX = trapX + plateX;
                    }
                    else if (WorldGen.TileEmpty(trapX + (plateX ^ 1), plateY))
                    {
                        plateX = trapX + (plateX ^ 1);
                    }
                    else
                    {
                        return(false);
                    }

                    if (Main.tile[trapX + (trapX == plateX ? 1 : 0), trapY].slope() != 0)
                    {
                        Main.tile[trapX + (trapX == plateX ? 1 : 0), trapY].slope(0);
                    }

                    if (Main.tile[trapX + (trapX == plateX ? 1 : 0), trapY].halfBrick())
                    {
                        Main.tile[trapX + (trapX == plateX ? 1 : 0), trapY].halfBrick(false);
                    }
                }
                else
                {
                    wireColor = GadgetMethods.GetRandomWireColor(trapX + plateX, plateY, 0);
                    if (wireColor == 0)
                    {
                        wireColor = GadgetMethods.GetRandomWireColor(trapX + (plateX ^ 1), plateY, 4);
                    }

                    if (Main.tile[trapX, trapY].slope() != 0)
                    {
                        Main.tile[trapX, trapY].slope(0);
                    }

                    if (Main.tile[trapX, trapY].halfBrick())
                    {
                        Main.tile[trapX, trapY].halfBrick(false);
                    }

                    if (Main.tile[trapX + 1, trapY].slope() != 0)
                    {
                        Main.tile[trapX + 1, trapY].slope(0);
                    }

                    if (Main.tile[trapX + 1, trapY].halfBrick())
                    {
                        Main.tile[trapX + 1, trapY].halfBrick(false);
                    }
                }
            }
            else
            {
                if (!GadgetMethods.HasWire(x, plateY) && Main.tile[x, plateY].active())
                {
                    return(false);
                }

                while (plateY - trapY < 7)
                {
                    trapY--;
                    if (trapY < WorldGen.tTop || WorldGen.SolidTile3(x, trapY))
                    {
                        return(false);
                    }
                }

                bool unoccupiedt = GadgetMethods.TileAreaCheck(x, trapY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe) &&
                                   (GadgetMethods.TileAreaCheck(x + 1, trapY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe) ||
                                    GadgetMethods.TileAreaCheck(x - 1, trapY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe));

                if (!unoccupiedt)
                {
                    return(false);
                }

                bool unoccupiedb = unoccupiedt;

                int maxY = trapY;

                while (unoccupiedb && (plateY - trapY) > 7)
                {
                    trapY++;
                    unoccupiedb = GadgetMethods.TileAreaCheck(x, trapY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe) &&
                                  (GadgetMethods.TileAreaCheck(x + 1, trapY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe) ||
                                   GadgetMethods.TileAreaCheck(x - 1, trapY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe));

                    if (!unoccupiedb)
                    {
                        trapY -= 3;
                        break;
                    }
                }

                while (unoccupiedt)
                {
                    maxY--;
                    unoccupiedt = GadgetMethods.TileAreaCheck(x, maxY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe) &&
                                  (GadgetMethods.TileAreaCheck(x + 1, maxY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe) ||
                                   GadgetMethods.TileAreaCheck(x - 1, maxY, 1, 2, false, 0, true, WallID.LihzahrdBrickUnsafe));

                    if (!unoccupiedt)
                    {
                        maxY += 3;
                        if (trapY < maxY)
                        {
                            return(false);
                        }

                        break;
                    }
                }

                trapY = trapY == maxY ? trapY : WorldGen.genRand.Next(maxY, trapY + 1);

                if (GadgetMethods.TileAreaCheck(x - trapX, trapY, 2, 2, false, 0, true, WallID.LihzahrdBrickUnsafe))
                {
                    trapX = x - trapX;
                }
                else if (GadgetMethods.TileAreaCheck(x - (trapX ^ 1), trapY, 2, 2, false, 0, true, WallID.LihzahrdBrickUnsafe))
                {
                    trapX = x - (trapX ^ 1);
                }
                else
                {
                    return(false);
                }

                for (int i = trapX - 1; i < trapX + 3; i++)
                {
                    for (int j = trapY - 1; j < trapY + 3; j++)
                    {
                        if ((i == trapX - 1 || i == trapX + 2) && (j == trapY - 1 || j == trapY + 2) || !GadgetMethods.HasWire(i, j))
                        {
                            continue;
                        }

                        placePlate = false;
                        plateY     = trapY;
                        wireColor  = GadgetMethods.GetRandomWireColor(i, j, 4);
                        break;
                    }
                }

                if (placePlate)
                {
                    for (int j = trapY + 2; j <= plateY; j++)
                    {
                        if (!GadgetMethods.HasWire(x, j))
                        {
                            continue;
                        }

                        placePlate = false;
                        plateY     = j;
                        wireColor  = GadgetMethods.GetRandomWireColor(x, j, 4);
                        break;
                    }
                }

                for (int j = trapY + 2; j < plateY; j++)
                {
                    GadgetMethods.PlaceWire(x, j, wireColor);
                }

                plateX = x;
            }

            ushort boulderTrap = (ushort)TileType <Tiles.BoulderTrapTile>();
            int    style       = floorTrap ? 3 : 0;

            Main.tile[trapX, trapY].active(true);
            Main.tile[trapX, trapY].frameY = 0;
            Main.tile[trapX, trapY].frameX = (short)(36 * style);
            Main.tile[trapX, trapY].type   = boulderTrap;
            GadgetMethods.PlaceWire(trapX, trapY, wireColor);
            Main.tile[trapX + 1, trapY].active(true);
            Main.tile[trapX + 1, trapY].frameY = 0;
            Main.tile[trapX + 1, trapY].frameX = (short)(36 * style + 18);
            Main.tile[trapX + 1, trapY].type   = boulderTrap;
            GadgetMethods.PlaceWire(trapX + 1, trapY, wireColor);
            Main.tile[trapX, trapY + 1].active(true);
            Main.tile[trapX, trapY + 1].frameY = 18;
            Main.tile[trapX, trapY + 1].frameX = (short)(36 * style);
            Main.tile[trapX, trapY + 1].type   = boulderTrap;
            GadgetMethods.PlaceWire(trapX, trapY + 1, wireColor);
            Main.tile[trapX + 1, trapY + 1].active(true);
            Main.tile[trapX + 1, trapY + 1].frameY = 18;
            Main.tile[trapX + 1, trapY + 1].frameX = (short)(36 * style + 18);
            Main.tile[trapX + 1, trapY + 1].type   = boulderTrap;
            GadgetMethods.PlaceWire(trapX + 1, trapY + 1, wireColor);

            if (!floorTrap)
            {
                Main.tile[trapX, trapY].inActive(true);
                Main.tile[trapX + 1, trapY].inActive(true);
                Main.tile[trapX, trapY + 1].inActive(true);
                Main.tile[trapX + 1, trapY + 1].inActive(true);
            }

            if (placePlate)
            {
                if (Main.tile[plateX, plateY + 1].slope() != 0)
                {
                    Main.tile[plateX, plateY + 1].slope(0);
                }

                if (Main.tile[plateX, plateY + 1].halfBrick())
                {
                    Main.tile[plateX, plateY + 1].halfBrick(false);
                }

                WorldGen.PlaceTile(plateX, plateY, TileID.PressurePlates, true, true, -1, 6);
                GadgetMethods.PlaceWire(plateX, plateY, wireColor);
            }
            return(true);
        }