L2ZoneRespawn.java 3.6 KB

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