L2ZoneRespawn.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2004-2014 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.model.zone;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.util.Rnd;
  25. /**
  26. * Abstract zone with spawn locations
  27. * @author DS, Nyaran (rework 10/07/2011)
  28. */
  29. public abstract class L2ZoneRespawn extends L2ZoneType
  30. {
  31. private List<Location> _spawnLocs = null;
  32. private List<Location> _otherSpawnLocs = null;
  33. private List<Location> _chaoticSpawnLocs = null;
  34. private List<Location> _banishSpawnLocs = null;
  35. protected L2ZoneRespawn(int id)
  36. {
  37. super(id);
  38. }
  39. public void parseLoc(int x, int y, int z, String type)
  40. {
  41. if ((type == null) || type.isEmpty())
  42. {
  43. addSpawn(x, y, z);
  44. }
  45. else
  46. {
  47. switch (type)
  48. {
  49. case "other":
  50. addOtherSpawn(x, y, z);
  51. break;
  52. case "chaotic":
  53. addChaoticSpawn(x, y, z);
  54. break;
  55. case "banish":
  56. addBanishSpawn(x, y, z);
  57. break;
  58. default:
  59. _log.warning(getClass().getSimpleName() + ": Unknown location type: " + type);
  60. }
  61. }
  62. }
  63. public final void addSpawn(int x, int y, int z)
  64. {
  65. if (_spawnLocs == null)
  66. {
  67. _spawnLocs = new ArrayList<>();
  68. }
  69. _spawnLocs.add(new Location(x, y, z));
  70. }
  71. public final void addOtherSpawn(int x, int y, int z)
  72. {
  73. if (_otherSpawnLocs == null)
  74. {
  75. _otherSpawnLocs = new ArrayList<>();
  76. }
  77. _otherSpawnLocs.add(new Location(x, y, z));
  78. }
  79. public final void addChaoticSpawn(int x, int y, int z)
  80. {
  81. if (_chaoticSpawnLocs == null)
  82. {
  83. _chaoticSpawnLocs = new ArrayList<>();
  84. }
  85. _chaoticSpawnLocs.add(new Location(x, y, z));
  86. }
  87. public final void addBanishSpawn(int x, int y, int z)
  88. {
  89. if (_banishSpawnLocs == null)
  90. {
  91. _banishSpawnLocs = new ArrayList<>();
  92. }
  93. _banishSpawnLocs.add(new Location(x, y, z));
  94. }
  95. public final List<Location> getSpawns()
  96. {
  97. return _spawnLocs;
  98. }
  99. public final Location getSpawnLoc()
  100. {
  101. if (Config.RANDOM_RESPAWN_IN_TOWN_ENABLED)
  102. {
  103. return _spawnLocs.get(Rnd.get(_spawnLocs.size()));
  104. }
  105. return _spawnLocs.get(0);
  106. }
  107. public final Location getOtherSpawnLoc()
  108. {
  109. if (_otherSpawnLocs != null)
  110. {
  111. if (Config.RANDOM_RESPAWN_IN_TOWN_ENABLED)
  112. {
  113. return _otherSpawnLocs.get(Rnd.get(_otherSpawnLocs.size()));
  114. }
  115. return _otherSpawnLocs.get(0);
  116. }
  117. return getSpawnLoc();
  118. }
  119. public final Location getChaoticSpawnLoc()
  120. {
  121. if (_chaoticSpawnLocs != null)
  122. {
  123. if (Config.RANDOM_RESPAWN_IN_TOWN_ENABLED)
  124. {
  125. return _chaoticSpawnLocs.get(Rnd.get(_chaoticSpawnLocs.size()));
  126. }
  127. return _chaoticSpawnLocs.get(0);
  128. }
  129. return getSpawnLoc();
  130. }
  131. public final Location getBanishSpawnLoc()
  132. {
  133. if (_banishSpawnLocs != null)
  134. {
  135. if (Config.RANDOM_RESPAWN_IN_TOWN_ENABLED)
  136. {
  137. return _banishSpawnLocs.get(Rnd.get(_banishSpawnLocs.size()));
  138. }
  139. return _banishSpawnLocs.get(0);
  140. }
  141. return getSpawnLoc();
  142. }
  143. }