OlympiadAnnouncer.java 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.NpcStringId;
  22. import com.l2jserver.gameserver.network.clientpackets.Say2;
  23. import com.l2jserver.gameserver.network.serverpackets.NpcSay;
  24. /**
  25. *
  26. * @author DS
  27. *
  28. */
  29. public final class OlympiadAnnouncer implements Runnable
  30. {
  31. private static final int OLY_MANAGER = 31688;
  32. private List<L2Spawn> _managers = new FastList<L2Spawn>();
  33. private int _currentStadium = 0;
  34. public OlympiadAnnouncer()
  35. {
  36. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  37. {
  38. if (spawn != null && spawn.getNpcid() == OLY_MANAGER)
  39. _managers.add(spawn);
  40. }
  41. }
  42. @Override
  43. public void run()
  44. {
  45. OlympiadGameTask task;
  46. for (int i = OlympiadGameManager.getInstance().getNumberOfStadiums(); --i >= 0; _currentStadium++)
  47. {
  48. if (_currentStadium >= OlympiadGameManager.getInstance().getNumberOfStadiums())
  49. _currentStadium = 0;
  50. task = OlympiadGameManager.getInstance().getOlympiadTask(_currentStadium);
  51. if (task != null && task.getGame() != null && task.needAnnounce())
  52. {
  53. NpcStringId npcString;
  54. final String arenaId = String.valueOf(task.getGame().getStadiumId() + 1);
  55. switch (task.getGame().getType())
  56. {
  57. case NON_CLASSED:
  58. npcString = NpcStringId.OLYMPIAD_CLASS_FREE_INDIVIDUAL_MATCH_IS_GOING_TO_BEGIN_IN_ARENA_S1_IN_A_MOMENT;
  59. break;
  60. case CLASSED:
  61. npcString = NpcStringId.OLYMPIAD_CLASS_INDIVIDUAL_MATCH_IS_GOING_TO_BEGIN_IN_ARENA_S1_IN_A_MOMENT;
  62. break;
  63. case TEAMS:
  64. npcString = NpcStringId.OLYMPIAD_CLASS_FREE_TEAM_MATCH_IS_GOING_TO_BEGIN_IN_ARENA_S1_IN_A_MOMENT;
  65. break;
  66. default:
  67. continue;
  68. }
  69. L2Npc manager;
  70. NpcSay packet;
  71. for (L2Spawn spawn : _managers)
  72. {
  73. manager = spawn.getLastSpawn();
  74. if (manager != null)
  75. {
  76. packet = new NpcSay(manager.getObjectId(), Say2.SHOUT, manager.getNpcId(), npcString);
  77. packet.addStringParameter(arenaId);
  78. manager.broadcastPacket(packet);
  79. }
  80. }
  81. break;
  82. }
  83. }
  84. }
  85. }