RequestCursedWeaponLocation.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import java.util.ArrayList;
  21. import java.util.List;
  22. import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
  23. import com.l2jserver.gameserver.model.CursedWeapon;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. import com.l2jserver.gameserver.network.serverpackets.ExCursedWeaponLocation;
  27. import com.l2jserver.gameserver.network.serverpackets.ExCursedWeaponLocation.CursedWeaponInfo;
  28. /**
  29. * Format: (ch)
  30. * @author -Wooden-
  31. */
  32. public final class RequestCursedWeaponLocation extends L2GameClientPacket
  33. {
  34. private static final String _C__D0_2B_REQUESTCURSEDWEAPONLOCATION = "[C] D0:2B RequestCursedWeaponLocation";
  35. @Override
  36. protected void readImpl()
  37. {
  38. // nothing to read it's just a trigger
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2Character activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. {
  46. return;
  47. }
  48. List<CursedWeaponInfo> list = new ArrayList<>();
  49. for (CursedWeapon cw : CursedWeaponsManager.getInstance().getCursedWeapons())
  50. {
  51. if (!cw.isActive())
  52. {
  53. continue;
  54. }
  55. Location pos = cw.getWorldPosition();
  56. if (pos != null)
  57. {
  58. list.add(new CursedWeaponInfo(pos, cw.getItemId(), cw.isActivated() ? 1 : 0));
  59. }
  60. }
  61. // send the ExCursedWeaponLocation
  62. if (!list.isEmpty())
  63. {
  64. activeChar.sendPacket(new ExCursedWeaponLocation(list));
  65. }
  66. }
  67. @Override
  68. public String getType()
  69. {
  70. return _C__D0_2B_REQUESTCURSEDWEAPONLOCATION;
  71. }
  72. @Override
  73. protected boolean triggersOnActionRequest()
  74. {
  75. return false;
  76. }
  77. }