public static void HandleTransportion(int i, int j, int playernum, bool inServer = false) { int statX = i; int addX = 0; int PortalType = ModContent.TileType <UnderworldPortal>(); Vector2 PortalUnderworld = Vector2.Zero; if (j >= Main.maxTilesY - 360) // 如果在地狱附近(传送目标地表) { Player player = Main.player[playernum]; // 搜索可用的在地表附近的地狱门 while (PortalUnderworld == Vector2.Zero) { addX++; for (int y = 10; y < Main.maxTilesY - 360; y++) { if (Main.tile[statX + addX, y] == null) { Main.tile[statX + addX, y] = new Tile(); } if (Main.tile[statX - addX, y] == null) { Main.tile[statX - addX, y] = new Tile(); } if (WorldGen.InWorld(statX + addX, y) && Main.tile[statX + addX, y].type == PortalType) { PortalUnderworld = new Vector2(statX + addX, y); } if (WorldGen.InWorld(statX - addX, y) && Main.tile[statX - addX, y].type == PortalType) { PortalUnderworld = new Vector2(statX - addX, y); } } // 如果左右300格范围内没有,直接传送至出生点 if (addX >= 300) { ModHelper.Return(player); return; } } // 如果搜索到,传送 player.HandleTeleport(PortalUnderworld.ToWorldCoordinates(0, -16)); } else // 在地表 { // 搜索可用的在地狱高度的地狱门 while (PortalUnderworld == Vector2.Zero) { for (int y = Main.maxTilesY - 180; y < Main.maxTilesY - 30; y++) { if (Main.tile[statX + addX, y] == null) { Main.tile[statX + addX, y] = new Tile(); } if (Main.tile[statX - addX, y] == null) { Main.tile[statX - addX, y] = new Tile(); } if (WorldGen.InWorld(statX + addX, y) && Main.tile[statX + addX, y].type == PortalType) { PortalUnderworld = new Vector2(statX + addX, y); } if (WorldGen.InWorld(statX - addX, y) && Main.tile[statX - addX, y].type == PortalType) { PortalUnderworld = new Vector2(statX - addX, y); } } // 如果左右150格范围内没有,停止搜索 if (addX >= 150) { break; } addX++; } // 如果没有找到,转而生成地狱门 if (PortalUnderworld == Vector2.Zero) { PortalUnderworld.X = statX; PortalUnderworld.Y = Main.maxTilesY - Main.rand.Next(160, 210); if (PortalUnderworld.X < 30) { PortalUnderworld.X = 30; } if (PortalUnderworld.X > Main.maxTilesX - 30 - 6) { PortalUnderworld.X = Main.maxTilesX - 30 - 6; } // 创建物块 if (inServer) { MessageHelper.BuildBuilding("Buildings/UnderworldPortal.ebuilding", PortalUnderworld.ToWorldCoordinates()); } else { Buildings.Build("Buildings/UnderworldPortal.ebuilding", PortalUnderworld.ToWorldCoordinates()); } // 定位到左上角的传送门方块 PortalUnderworld.X += 1; PortalUnderworld.Y += 2; } // 2:进行传送 Player player = Main.player[playernum]; player.HandleTeleport(PortalUnderworld.ToWorldCoordinates(8, -16)); } }