TownManager.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright © 2004-2020 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.instancemanager;
  20. import com.l2jserver.gameserver.model.entity.Castle;
  21. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  22. import com.l2jserver.gameserver.model.zone.type.L2TownZone;
  23. public final class TownManager {
  24. public static int getTownCastle(int townId) {
  25. switch (townId) {
  26. case 912:
  27. return 1;
  28. case 916:
  29. return 2;
  30. case 918:
  31. return 3;
  32. case 922:
  33. return 4;
  34. case 924:
  35. return 5;
  36. case 926:
  37. return 6;
  38. case 1538:
  39. return 7;
  40. case 1537:
  41. return 8;
  42. case 1714:
  43. return 9;
  44. default:
  45. return 0;
  46. }
  47. }
  48. public static boolean townHasCastleInSiege(int townId) {
  49. int castleIndex = getTownCastle(townId);
  50. if (castleIndex > 0) {
  51. Castle castle = CastleManager.getInstance().getCastles().get(CastleManager.getInstance().getCastleIndex(castleIndex));
  52. if (castle != null) {
  53. return castle.getSiege().isInProgress();
  54. }
  55. }
  56. return false;
  57. }
  58. public static boolean townHasCastleInSiege(int x, int y) {
  59. return townHasCastleInSiege(MapRegionManager.getInstance().getMapRegionLocId(x, y));
  60. }
  61. public static L2TownZone getTown(int townId) {
  62. for (L2TownZone temp : ZoneManager.getInstance().getAllZones(L2TownZone.class)) {
  63. if (temp.getTownId() == townId) {
  64. return temp;
  65. }
  66. }
  67. return null;
  68. }
  69. /**
  70. * Returns the town at that position (if any)
  71. * @param x
  72. * @param y
  73. * @param z
  74. * @return
  75. */
  76. public static L2TownZone getTown(int x, int y, int z) {
  77. for (L2ZoneType temp : ZoneManager.getInstance().getZones(x, y, z)) {
  78. if (temp instanceof L2TownZone) {
  79. return (L2TownZone) temp;
  80. }
  81. }
  82. return null;
  83. }
  84. }