TownManager.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2004-2015 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. {
  25. public static final int getTownCastle(int townId)
  26. {
  27. switch (townId)
  28. {
  29. case 912:
  30. return 1;
  31. case 916:
  32. return 2;
  33. case 918:
  34. return 3;
  35. case 922:
  36. return 4;
  37. case 924:
  38. return 5;
  39. case 926:
  40. return 6;
  41. case 1538:
  42. return 7;
  43. case 1537:
  44. return 8;
  45. case 1714:
  46. return 9;
  47. default:
  48. return 0;
  49. }
  50. }
  51. public static final boolean townHasCastleInSiege(int townId)
  52. {
  53. int castleIndex = getTownCastle(townId);
  54. if (castleIndex > 0)
  55. {
  56. Castle castle = CastleManager.getInstance().getCastles().get(CastleManager.getInstance().getCastleIndex(castleIndex));
  57. if (castle != null)
  58. {
  59. return castle.getSiege().isInProgress();
  60. }
  61. }
  62. return false;
  63. }
  64. public static final boolean townHasCastleInSiege(int x, int y)
  65. {
  66. return townHasCastleInSiege(MapRegionManager.getInstance().getMapRegionLocId(x, y));
  67. }
  68. public static final L2TownZone getTown(int townId)
  69. {
  70. for (L2TownZone temp : ZoneManager.getInstance().getAllZones(L2TownZone.class))
  71. {
  72. if (temp.getTownId() == townId)
  73. {
  74. return temp;
  75. }
  76. }
  77. return null;
  78. }
  79. /**
  80. * Returns the town at that position (if any)
  81. * @param x
  82. * @param y
  83. * @param z
  84. * @return
  85. */
  86. public static final L2TownZone getTown(int x, int y, int z)
  87. {
  88. for (L2ZoneType temp : ZoneManager.getInstance().getZones(x, y, z))
  89. {
  90. if (temp instanceof L2TownZone)
  91. {
  92. return (L2TownZone) temp;
  93. }
  94. }
  95. return null;
  96. }
  97. }