L2SpawnZone.java 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  24. *
  25. */
  26. public abstract class L2SpawnZone extends L2ZoneType
  27. {
  28. private List<Location> _spawnLocs = null;
  29. private List<Location> _chaoticSpawnLocs = null;
  30. public L2SpawnZone(int id)
  31. {
  32. super(id);
  33. }
  34. public final void addSpawn(int x, int y, int z)
  35. {
  36. if (_spawnLocs == null)
  37. _spawnLocs = new ArrayList<Location>();
  38. _spawnLocs.add(new Location(x, y, z));
  39. }
  40. public final void addChaoticSpawn(int x, int y, int z)
  41. {
  42. if (_chaoticSpawnLocs == null)
  43. _chaoticSpawnLocs = new ArrayList<Location>();
  44. _chaoticSpawnLocs.add(new Location(x, y, z));
  45. }
  46. public final List<Location> getSpawns()
  47. {
  48. return _spawnLocs;
  49. }
  50. public final Location getSpawnLoc()
  51. {
  52. if (Config.RANDOM_RESPAWN_IN_TOWN_ENABLED)
  53. return _spawnLocs.get(Rnd.get(_spawnLocs.size()));
  54. else
  55. return _spawnLocs.get(0);
  56. }
  57. public final Location getChaoticSpawnLoc()
  58. {
  59. if (_chaoticSpawnLocs != null)
  60. return _chaoticSpawnLocs.get(Rnd.get(_chaoticSpawnLocs.size()));
  61. else
  62. return getSpawnLoc();
  63. }
  64. }