SiegeInfo.java 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 java.util.Calendar;
  21. import com.l2jserver.Config;
  22. import com.l2jserver.gameserver.data.sql.impl.ClanTable;
  23. import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
  24. import com.l2jserver.gameserver.model.L2Clan;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.Castle;
  27. import com.l2jserver.gameserver.model.entity.ClanHall;
  28. /**
  29. * Shows the Siege Info<BR>
  30. * <BR>
  31. * c = c9<BR>
  32. * d = CastleID<BR>
  33. * d = Show Owner Controls (0x00 default || >=0x02(mask?) owner)<BR>
  34. * d = Owner ClanID<BR>
  35. * S = Owner ClanName<BR>
  36. * S = Owner Clan LeaderName<BR>
  37. * d = Owner AllyID<BR>
  38. * S = Owner AllyName<BR>
  39. * d = current time (seconds)<BR>
  40. * d = Siege time (seconds) (0 for selectable)<BR>
  41. * d = (UNKNOW) Siege Time Select Related?
  42. * @author KenM
  43. */
  44. public class SiegeInfo extends L2GameServerPacket
  45. {
  46. private Castle _castle;
  47. private ClanHall _hall;
  48. public SiegeInfo(Castle castle)
  49. {
  50. _castle = castle;
  51. }
  52. public SiegeInfo(ClanHall hall)
  53. {
  54. _hall = hall;
  55. }
  56. @Override
  57. protected final void writeImpl()
  58. {
  59. L2PcInstance activeChar = getClient().getActiveChar();
  60. if (activeChar == null)
  61. {
  62. return;
  63. }
  64. writeC(0xc9);
  65. if (_castle != null)
  66. {
  67. writeD(_castle.getResidenceId());
  68. final int ownerId = _castle.getOwnerId();
  69. writeD(((ownerId == activeChar.getClanId()) && (activeChar.isClanLeader())) ? 0x01 : 0x00);
  70. writeD(ownerId);
  71. if (ownerId > 0)
  72. {
  73. L2Clan owner = ClanTable.getInstance().getClan(ownerId);
  74. if (owner != null)
  75. {
  76. writeS(owner.getName()); // Clan Name
  77. writeS(owner.getLeaderName()); // Clan Leader Name
  78. writeD(owner.getAllyId()); // Ally ID
  79. writeS(owner.getAllyName()); // Ally Name
  80. }
  81. else
  82. {
  83. _log.warning("Null owner for castle: " + _castle.getName());
  84. }
  85. }
  86. else
  87. {
  88. writeS(""); // Clan Name
  89. writeS(""); // Clan Leader Name
  90. writeD(0); // Ally ID
  91. writeS(""); // Ally Name
  92. }
  93. writeD((int) (System.currentTimeMillis() / 1000));
  94. if (!_castle.getIsTimeRegistrationOver() && activeChar.isClanLeader() && (activeChar.getClanId() == _castle.getOwnerId()))
  95. {
  96. Calendar cal = Calendar.getInstance();
  97. cal.setTimeInMillis(_castle.getSiegeDate().getTimeInMillis());
  98. cal.set(Calendar.MINUTE, 0);
  99. cal.set(Calendar.SECOND, 0);
  100. writeD(0x00);
  101. writeD(Config.SIEGE_HOUR_LIST.size());
  102. for (int hour : Config.SIEGE_HOUR_LIST)
  103. {
  104. cal.set(Calendar.HOUR_OF_DAY, hour);
  105. writeD((int) (cal.getTimeInMillis() / 1000));
  106. }
  107. }
  108. else
  109. {
  110. writeD((int) (_castle.getSiegeDate().getTimeInMillis() / 1000));
  111. writeD(0x00);
  112. }
  113. }
  114. else
  115. {
  116. writeD(_hall.getId());
  117. final int ownerId = _hall.getOwnerId();
  118. writeD(((ownerId == activeChar.getClanId()) && (activeChar.isClanLeader())) ? 0x01 : 0x00);
  119. writeD(ownerId);
  120. if (ownerId > 0)
  121. {
  122. L2Clan owner = ClanTable.getInstance().getClan(ownerId);
  123. if (owner != null)
  124. {
  125. writeS(owner.getName()); // Clan Name
  126. writeS(owner.getLeaderName()); // Clan Leader Name
  127. writeD(owner.getAllyId()); // Ally ID
  128. writeS(owner.getAllyName()); // Ally Name
  129. }
  130. else
  131. {
  132. _log.warning("Null owner for siegable hall: " + _hall.getName());
  133. }
  134. }
  135. else
  136. {
  137. writeS(""); // Clan Name
  138. writeS(""); // Clan Leader Name
  139. writeD(0); // Ally ID
  140. writeS(""); // Ally Name
  141. }
  142. writeD((int) (Calendar.getInstance().getTimeInMillis() / 1000));
  143. writeD((int) ((CHSiegeManager.getInstance().getSiegableHall(_hall.getId()).getNextSiegeTime()) / 1000));
  144. writeD(0x00); // number of choices?
  145. }
  146. }
  147. }