ExItemAuctionInfoPacket.java 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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.serverpackets;
  20. import com.l2jserver.gameserver.model.itemauction.ItemAuction;
  21. import com.l2jserver.gameserver.model.itemauction.ItemAuctionBid;
  22. import com.l2jserver.gameserver.model.itemauction.ItemAuctionState;
  23. /**
  24. * @author Forsaiken
  25. */
  26. public final class ExItemAuctionInfoPacket extends AbstractItemPacket
  27. {
  28. private final boolean _refresh;
  29. private final int _timeRemaining;
  30. private final ItemAuction _currentAuction;
  31. private final ItemAuction _nextAuction;
  32. public ExItemAuctionInfoPacket(final boolean refresh, final ItemAuction currentAuction, final ItemAuction nextAuction)
  33. {
  34. if (currentAuction == null)
  35. {
  36. throw new NullPointerException();
  37. }
  38. if (currentAuction.getAuctionState() != ItemAuctionState.STARTED)
  39. {
  40. _timeRemaining = 0;
  41. }
  42. else
  43. {
  44. _timeRemaining = (int) (currentAuction.getFinishingTimeRemaining() / 1000); // in seconds
  45. }
  46. _refresh = refresh;
  47. _currentAuction = currentAuction;
  48. _nextAuction = nextAuction;
  49. }
  50. @Override
  51. protected void writeImpl()
  52. {
  53. writeC(0xFE);
  54. writeH(0x68);
  55. writeC(_refresh ? 0x00 : 0x01);
  56. writeD(_currentAuction.getInstanceId());
  57. final ItemAuctionBid highestBid = _currentAuction.getHighestBid();
  58. writeQ(highestBid != null ? highestBid.getLastBid() : _currentAuction.getAuctionInitBid());
  59. writeD(_timeRemaining);
  60. writeItem(_currentAuction.getItemInfo());
  61. if (_nextAuction != null)
  62. {
  63. writeQ(_nextAuction.getAuctionInitBid());
  64. writeD((int) (_nextAuction.getStartingTime() / 1000)); // unix time in seconds
  65. writeItem(_nextAuction.getItemInfo());
  66. }
  67. }
  68. }