TownManager.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.instancemanager;
  16. import com.l2jserver.gameserver.model.entity.Castle;
  17. import com.l2jserver.gameserver.model.zone.L2ZoneType;
  18. import com.l2jserver.gameserver.model.zone.type.L2TownZone;
  19. public class TownManager
  20. {
  21. // private static final Logger _log = Logger.getLogger(TownManager.class.getName());
  22. public final static int getTownCastle(int townId)
  23. {
  24. switch (townId)
  25. {
  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 final static boolean townHasCastleInSiege(int townId)
  49. {
  50. int castleIndex = getTownCastle(townId);
  51. if (castleIndex > 0)
  52. {
  53. Castle castle = CastleManager.getInstance().getCastles().get(CastleManager.getInstance().getCastleIndex(castleIndex));
  54. if (castle != null)
  55. {
  56. return castle.getSiege().getIsInProgress();
  57. }
  58. }
  59. return false;
  60. }
  61. public final static boolean townHasCastleInSiege(int x, int y)
  62. {
  63. return townHasCastleInSiege(MapRegionManager.getInstance().getMapRegionLocId(x, y));
  64. }
  65. public final static L2TownZone getTown(int townId)
  66. {
  67. for (L2TownZone temp : ZoneManager.getInstance().getAllZones(L2TownZone.class))
  68. {
  69. if (temp.getTownId() == townId)
  70. {
  71. return temp;
  72. }
  73. }
  74. return null;
  75. }
  76. /**
  77. * Returns the town at that position (if any)
  78. * @param x
  79. * @param y
  80. * @param z
  81. * @return
  82. */
  83. public final static L2TownZone getTown(int x, int y, int z)
  84. {
  85. for (L2ZoneType temp : ZoneManager.getInstance().getZones(x, y, z))
  86. {
  87. if (temp instanceof L2TownZone)
  88. {
  89. return (L2TownZone) temp;
  90. }
  91. }
  92. return null;
  93. }
  94. }