OlympiadAnnouncer.java 3.0 KB

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