AllianceInfo.java 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.Collection;
  21. import com.l2jserver.gameserver.data.sql.impl.ClanTable;
  22. import com.l2jserver.gameserver.model.ClanInfo;
  23. import com.l2jserver.gameserver.model.L2Clan;
  24. import com.l2jserver.gameserver.network.clientpackets.RequestAllyInfo;
  25. /**
  26. * Sent in response to {@link RequestAllyInfo}, if applicable.<BR>
  27. * @author afk5min
  28. */
  29. public class AllianceInfo extends L2GameServerPacket
  30. {
  31. private final String _name;
  32. private final int _total;
  33. private final int _online;
  34. private final String _leaderC;
  35. private final String _leaderP;
  36. private final ClanInfo[] _allies;
  37. public AllianceInfo(int allianceId)
  38. {
  39. final L2Clan leader = ClanTable.getInstance().getClan(allianceId);
  40. _name = leader.getAllyName();
  41. _leaderC = leader.getName();
  42. _leaderP = leader.getLeaderName();
  43. final Collection<L2Clan> allies = ClanTable.getInstance().getClanAllies(allianceId);
  44. _allies = new ClanInfo[allies.size()];
  45. int idx = 0, total = 0, online = 0;
  46. for (final L2Clan clan : allies)
  47. {
  48. final ClanInfo ci = new ClanInfo(clan);
  49. _allies[idx++] = ci;
  50. total += ci.getTotal();
  51. online += ci.getOnline();
  52. }
  53. _total = total;
  54. _online = online;
  55. }
  56. @Override
  57. protected void writeImpl()
  58. {
  59. writeC(0xB5);
  60. writeS(_name);
  61. writeD(_total);
  62. writeD(_online);
  63. writeS(_leaderC);
  64. writeS(_leaderP);
  65. writeD(_allies.length);
  66. for (final ClanInfo aci : _allies)
  67. {
  68. writeS(aci.getClan().getName());
  69. writeD(0x00);
  70. writeD(aci.getClan().getLevel());
  71. writeS(aci.getClan().getLeaderName());
  72. writeD(aci.getTotal());
  73. writeD(aci.getOnline());
  74. }
  75. }
  76. public String getName()
  77. {
  78. return _name;
  79. }
  80. public int getTotal()
  81. {
  82. return _total;
  83. }
  84. public int getOnline()
  85. {
  86. return _online;
  87. }
  88. public String getLeaderC()
  89. {
  90. return _leaderC;
  91. }
  92. public String getLeaderP()
  93. {
  94. return _leaderP;
  95. }
  96. public ClanInfo[] getAllies()
  97. {
  98. return _allies;
  99. }
  100. }