L2CommandChannel.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (C) 2004-2013 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.model;
  20. import java.util.List;
  21. import javolution.util.FastList;
  22. import com.l2jserver.Config;
  23. import com.l2jserver.gameserver.model.actor.L2Character;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.model.interfaces.IL2Procedure;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  28. import com.l2jserver.gameserver.network.serverpackets.ExCloseMPCC;
  29. import com.l2jserver.gameserver.network.serverpackets.ExMPCCPartyInfoUpdate;
  30. import com.l2jserver.gameserver.network.serverpackets.ExOpenMPCC;
  31. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  32. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  33. /**
  34. * @author chris_00
  35. */
  36. public class L2CommandChannel extends AbstractPlayerGroup
  37. {
  38. private final List<L2Party> _partys;
  39. private L2PcInstance _commandLeader = null;
  40. private int _channelLvl;
  41. /**
  42. * Creates a New Command Channel and Add the Leaders party to the CC
  43. * @param leader
  44. */
  45. public L2CommandChannel(L2PcInstance leader)
  46. {
  47. _commandLeader = leader;
  48. _partys = new FastList<L2Party>().shared();
  49. _partys.add(leader.getParty());
  50. _channelLvl = leader.getParty().getLevel();
  51. leader.getParty().setCommandChannel(this);
  52. leader.getParty().broadcastMessage(SystemMessageId.COMMAND_CHANNEL_FORMED);
  53. leader.getParty().broadcastPacket(ExOpenMPCC.STATIC_PACKET);
  54. }
  55. /**
  56. * Adds a Party to the Command Channel
  57. * @param party
  58. */
  59. public void addParty(L2Party party)
  60. {
  61. if (party == null)
  62. {
  63. return;
  64. }
  65. // Update the CCinfo for existing players
  66. broadcastPacket(new ExMPCCPartyInfoUpdate(party, 1));
  67. _partys.add(party);
  68. if (party.getLevel() > _channelLvl)
  69. {
  70. _channelLvl = party.getLevel();
  71. }
  72. party.setCommandChannel(this);
  73. party.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.JOINED_COMMAND_CHANNEL));
  74. party.broadcastPacket(ExOpenMPCC.STATIC_PACKET);
  75. }
  76. /**
  77. * Removes a Party from the Command Channel
  78. * @param party
  79. */
  80. public void removeParty(L2Party party)
  81. {
  82. if (party == null)
  83. {
  84. return;
  85. }
  86. _partys.remove(party);
  87. _channelLvl = 0;
  88. for (L2Party pty : _partys)
  89. {
  90. if (pty.getLevel() > _channelLvl)
  91. {
  92. _channelLvl = pty.getLevel();
  93. }
  94. }
  95. party.setCommandChannel(null);
  96. party.broadcastPacket(new ExCloseMPCC());
  97. if (_partys.size() < 2)
  98. {
  99. broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.COMMAND_CHANNEL_DISBANDED));
  100. disbandChannel();
  101. }
  102. else
  103. {
  104. // Update the CCinfo for existing players
  105. broadcastPacket(new ExMPCCPartyInfoUpdate(party, 0));
  106. }
  107. }
  108. /**
  109. * disbands the whole Command Channel
  110. */
  111. public void disbandChannel()
  112. {
  113. if (_partys != null)
  114. {
  115. for (L2Party party : _partys)
  116. {
  117. if (party != null)
  118. {
  119. removeParty(party);
  120. }
  121. }
  122. _partys.clear();
  123. }
  124. }
  125. /**
  126. * @return overall member count of the Command Channel
  127. */
  128. @Override
  129. public int getMemberCount()
  130. {
  131. int count = 0;
  132. for (L2Party party : _partys)
  133. {
  134. if (party != null)
  135. {
  136. count += party.getMemberCount();
  137. }
  138. }
  139. return count;
  140. }
  141. /**
  142. * Broadcast packet to every channel member
  143. * @param gsp
  144. * @deprecated
  145. * @see L2CommandChannel#broadcastPacket(L2GameServerPacket)
  146. */
  147. @Deprecated
  148. public void broadcastToChannelMembers(L2GameServerPacket gsp)
  149. {
  150. broadcastPacket(gsp);
  151. }
  152. @Deprecated
  153. public void broadcastCSToChannelMembers(CreatureSay gsp, L2PcInstance broadcaster)
  154. {
  155. broadcastCreatureSay(gsp, broadcaster);
  156. }
  157. /**
  158. * @return list of Parties in Command Channel
  159. */
  160. public List<L2Party> getPartys()
  161. {
  162. return _partys;
  163. }
  164. /**
  165. * @return list of all Members in Command Channel
  166. */
  167. @Override
  168. public List<L2PcInstance> getMembers()
  169. {
  170. List<L2PcInstance> members = new FastList<L2PcInstance>().shared();
  171. for (L2Party party : getPartys())
  172. {
  173. members.addAll(party.getMembers());
  174. }
  175. return members;
  176. }
  177. /**
  178. * @return Level of CC
  179. */
  180. @Override
  181. public int getLevel()
  182. {
  183. return _channelLvl;
  184. }
  185. /**
  186. * @param leader the leader of the Command Channel
  187. */
  188. public void setChannelLeader(L2PcInstance leader)
  189. {
  190. _commandLeader = leader;
  191. }
  192. /**
  193. * @return the leader of the Command Channel
  194. * @deprecated
  195. * @see L2CommandChannel#getLeader()
  196. */
  197. @Deprecated
  198. public L2PcInstance getChannelLeader()
  199. {
  200. return getLeader();
  201. }
  202. /**
  203. * @param obj
  204. * @return true if proper condition for RaidWar
  205. */
  206. public boolean meetRaidWarCondition(L2Object obj)
  207. {
  208. if (!((obj instanceof L2Character) && ((L2Character) obj).isRaid()))
  209. {
  210. return false;
  211. }
  212. return (getMemberCount() >= Config.LOOT_RAIDS_PRIVILEGE_CC_SIZE);
  213. }
  214. /**
  215. * @return the leader of the Command Channel
  216. */
  217. @Override
  218. public L2PcInstance getLeader()
  219. {
  220. return _commandLeader;
  221. }
  222. @Override
  223. public boolean containsPlayer(L2PcInstance player)
  224. {
  225. if ((_partys != null) && !_partys.isEmpty())
  226. {
  227. for (L2Party party : _partys)
  228. {
  229. if (party.containsPlayer(player))
  230. {
  231. return true;
  232. }
  233. }
  234. }
  235. return false;
  236. }
  237. /**
  238. * Iterates over CC without need to allocate any new list
  239. * @see com.l2jserver.gameserver.model.AbstractPlayerGroup#forEachMember(IL2Procedure)
  240. */
  241. @Override
  242. public boolean forEachMember(IL2Procedure<L2PcInstance> procedure)
  243. {
  244. if ((_partys != null) && !_partys.isEmpty())
  245. {
  246. for (L2Party party : _partys)
  247. {
  248. if (!party.forEachMember(procedure))
  249. {
  250. return false;
  251. }
  252. }
  253. }
  254. return true;
  255. }
  256. }