Terraria.Player.TeleportationPotion C# (CSharp) Method

TeleportationPotion() public method

public TeleportationPotion ( ) : void
return void
        public void TeleportationPotion()
        {
            bool flag1 = false;
            int num1 = 0;
            int num2 = 0;
            int num3 = 0;
            int Width = this.width;
            Vector2 Position = new Vector2((float)num2, (float)num3) * 16f + new Vector2((float)(-Width / 2 + 8), (float)-this.height);
            while (!flag1 && num1 < 1000)
            {
                ++num1;
                int index1 = 100 + Main.rand.Next(Main.maxTilesX - 200);
                int index2 = 100 + Main.rand.Next(Main.maxTilesY - 200);
                Position = new Vector2((float)index1, (float)index2) * 16f + new Vector2((float)(-Width / 2 + 8), (float)-this.height);
                if (!Collision.SolidCollision(Position, Width, this.height))
                {
                    if (Main.tile[index1, index2] == null)
                        Main.tile[index1, index2] = new Tile();
                    if (((int)Main.tile[index1, index2].wall != 87 || (double)index2 <= Main.worldSurface || NPC.downedPlantBoss) && (!Main.wallDungeon[(int)Main.tile[index1, index2].wall] || (double)index2 <= Main.worldSurface || NPC.downedBoss3))
                    {
                        int num4 = 0;
                        while (num4 < 100)
                        {
                            if (Main.tile[index1, index2 + num4] == null)
                                Main.tile[index1, index2 + num4] = new Tile();
                            Tile tile = Main.tile[index1, index2 + num4];
                            Position = new Vector2((float)index1, (float)(index2 + num4)) * 16f + new Vector2((float)(-Width / 2 + 8), (float)-this.height);
                            Vector4 vector4 = Collision.SlopeCollision(Position, this.velocity, Width, this.height, this.gravDir, false);
                            bool flag2 = !Collision.SolidCollision(Position, Width, this.height);
                            if ((double)vector4.Z == (double)this.velocity.X)
                            {
                                double num5 = (double)this.velocity.Y;
                            }
                            if (flag2)
                                ++num4;
                            else if (!tile.active() || tile.inActive() || !Main.tileSolid[(int)tile.type])
                                ++num4;
                            else
                                break;
                        }
                        if (!Collision.LavaCollision(Position, Width, this.height) && (double)Collision.HurtTiles(Position, this.velocity, Width, this.height, false).Y <= 0.0)
                        {
                            Collision.SlopeCollision(Position, this.velocity, Width, this.height, this.gravDir, false);
                            if (Collision.SolidCollision(Position, Width, this.height) && num4 < 99)
                            {
                                Vector2 Velocity1 = Vector2.UnitX * 16f;
                                if (!(Collision.TileCollision(Position - Velocity1, Velocity1, this.width, this.height, false, false, (int)this.gravDir) != Velocity1))
                                {
                                    Vector2 Velocity2 = -Vector2.UnitX * 16f;
                                    if (!(Collision.TileCollision(Position - Velocity2, Velocity2, this.width, this.height, false, false, (int)this.gravDir) != Velocity2))
                                    {
                                        Vector2 Velocity3 = Vector2.UnitY * 16f;
                                        if (!(Collision.TileCollision(Position - Velocity3, Velocity3, this.width, this.height, false, false, (int)this.gravDir) != Velocity3))
                                        {
                                            Vector2 Velocity4 = -Vector2.UnitY * 16f;
                                            if (!(Collision.TileCollision(Position - Velocity4, Velocity4, this.width, this.height, false, false, (int)this.gravDir) != Velocity4))
                                            {
                                                flag1 = true;
                                                int num5 = index2 + num4;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (!flag1)
                return;
            Vector2 newPos = Position;
            this.Teleport(newPos, 2, 0);
            this.velocity = Vector2.Zero;
            if (Main.netMode != 2)
                return;
            RemoteClient.CheckSection(this.whoAmI, this.position, 1);
            NetMessage.SendData(65, -1, -1, "", 0, (float)this.whoAmI, newPos.X, newPos.Y, 3, 0, 0);
        }

Usage Example

Ejemplo n.º 1
0
        public void OnPlayerPreUpdate(Player player)
        {
            if (player.whoAmI != Main.myPlayer) return;

            if (player.inventory[player.selectedItem].type == ItemID.CellPhone)
            {
                if (Main.mouseItem.type == ItemID.CellPhone) return; // don't allow it to be on your cursor

                if (Main.mouseLeft && Main.mouseLeftRelease)
                {
                    if (mode == Mode.Home) return;

                    player.mouseInterface = true;
                    Main.mouseLeftRelease = false;
                    if (mode == Mode.LeftOcean)
                    {
                        // left ocean
                        player.Teleport(new Vector2(200 * 16, (float)(Main.worldSurface / 2f) * 16f), 3);
                        if (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 3].active())
                        {
                            while (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y += 16f;
                            }
                        }
                        else
                        {
                            while (Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y -= 16f;
                            }
                        }
                        player.fallStart = (int)(player.position.Y / 16f);
                        if (Main.netMode == 1) NetMessage.SendTileSquare(player.whoAmI, 200, (int)Main.worldSurface / 2, 10);
                    }
                    else if (mode == Mode.RightOcean)
                    {
                        // right ocean
                        player.Teleport(new Vector2((Main.maxTilesX - 200) * 16, (float)(Main.worldSurface / 2f) * 16f), 3);
                        if (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 3].active())
                        {
                            while (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y += 16f;
                            }
                        }
                        else
                        {
                            while (Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y -= 16f;
                            }
                        }
                        player.fallStart = (int)(player.position.Y / 16f);
                        if (Main.netMode == 1) NetMessage.SendTileSquare(player.whoAmI, Main.maxTilesX - 200, (int)Main.worldSurface / 2, 10);
                    }
                    else if (mode == Mode.Hell)
                    {
                        // hell
                        player.Teleport(new Vector2((Main.maxTilesX / 2) * 16, (float)(Main.maxTilesY - 180) * 16f), 3);
                        if (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 3].active())
                        {
                            while (!Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y += 16f;
                                if ((int)(player.position.Y / 16f) > Main.maxTilesY)
                                {
                                    player.position.Y = (float)(Main.maxTilesY * 16) - 130f;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            while (Main.tile[(int)(player.position.X / 16f), (int)(player.position.Y / 16f) + 4].active())
                            {
                                player.position.Y -= 16f;
                            }
                        }
                        player.fallStart = (int)(player.position.Y / 16f);
                        if (Main.netMode == 1) NetMessage.SendTileSquare(player.whoAmI, Main.maxTilesX / 2, (int)Main.maxTilesY - 180, 10);
                    }
                    else if (mode == Mode.Random)
                    {
                        if (Main.netMode == 0)
                        {
                            player.TeleportationPotion();
                        }
                        else if (Main.netMode == 1 && player.whoAmI == Main.myPlayer)
                        {
                            NetMessage.SendData(73, -1, -1, "", 0, 0f, 0f, 0f, 0);
                        }
                    }
                    for (int num91 = 0; num91 < 70; num91++)
                    {
                        Dust.NewDust(player.position, player.width, player.height, 15, 0f, 0f, 150, default(Color), 1.5f);
                    }
                }
            }
        }
Player