OlympiadAnnouncer.java 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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.olympiad;
  16. import java.util.List;
  17. import javolution.util.FastList;
  18. import com.l2jserver.gameserver.datatables.SpawnTable;
  19. import com.l2jserver.gameserver.model.L2Spawn;
  20. import com.l2jserver.gameserver.model.actor.L2Npc;
  21. import com.l2jserver.gameserver.network.clientpackets.Say2;
  22. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  23. /**
  24. *
  25. * @author DS
  26. *
  27. */
  28. public final class OlympiadAnnouncer implements Runnable
  29. {
  30. private static final int OLY_MANAGER = 31688;
  31. private List<L2Spawn> _managers = new FastList<L2Spawn>();
  32. private int _currentStadium = 0;
  33. public OlympiadAnnouncer()
  34. {
  35. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  36. {
  37. if (spawn != null && spawn.getNpcid() == OLY_MANAGER)
  38. _managers.add(spawn);
  39. }
  40. }
  41. public void run()
  42. {
  43. OlympiadGameTask task;
  44. for (int i = OlympiadGameManager.getInstance().getNumberOfStadiums(); --i >= 0; _currentStadium++)
  45. {
  46. if (_currentStadium >= OlympiadGameManager.getInstance().getNumberOfStadiums())
  47. _currentStadium = 0;
  48. task = OlympiadGameManager.getInstance().getOlympiadTask(_currentStadium);
  49. if (task != null && task.getGame() != null && task.needAnnounce())
  50. {
  51. int npcString;
  52. final String arenaId = String.valueOf(task.getGame().getStadiumId() + 1);
  53. switch (task.getGame().getType())
  54. {
  55. case NON_CLASSED:
  56. npcString = 1300166; // "Olympiad class-free individual match is going to begin in Arena " + arenaId + " in a moment.";
  57. break;
  58. case CLASSED:
  59. npcString = 1300167; // "Olympiad class-specific individual match is going to begin in Arena " + arenaId + " in a moment.";
  60. break;
  61. case TEAMS:
  62. npcString = 1300132; // "Olympiad class-free team match is going to begin in Arena " + arenaId + " in a moment.";
  63. break;
  64. default:
  65. continue;
  66. }
  67. L2Npc manager;
  68. NpcSay packet;
  69. for (L2Spawn spawn : _managers)
  70. {
  71. manager = spawn.getLastSpawn();
  72. if (manager != null)
  73. {
  74. packet = new NpcSay(manager.getObjectId(), Say2.SHOUT, manager.getNpcId(), npcString);
  75. packet.addStringParameter(arenaId);
  76. manager.broadcastPacket(packet);
  77. }
  78. }
  79. break;
  80. }
  81. }
  82. }
  83. }