TownManager.java 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 1537:
  39. return 7;
  40. case 1538:
  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. return castle.getSiege().getIsInProgress();
  56. }
  57. return false;
  58. }
  59. public final static boolean townHasCastleInSiege(int x, int y)
  60. {
  61. int curtown = MapRegionManager.getInstance().getMapRegion(x, y).getLocId();
  62. return townHasCastleInSiege(curtown);
  63. }
  64. public final static L2TownZone getTown(int townId)
  65. {
  66. for (L2TownZone temp : ZoneManager.getInstance().getAllZones(L2TownZone.class))
  67. {
  68. if (temp.getTownId() == townId)
  69. return temp;
  70. }
  71. return null;
  72. }
  73. /**
  74. * Returns the town at that position (if any)
  75. * @param x
  76. * @param y
  77. * @param z
  78. * @return
  79. */
  80. public final static L2TownZone getTown(int x, int y, int z)
  81. {
  82. for (L2ZoneType temp : ZoneManager.getInstance().getZones(x, y, z))
  83. {
  84. if (temp instanceof L2TownZone)
  85. return (L2TownZone) temp;
  86. }
  87. return null;
  88. }
  89. }