L2CommandChannel.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model;
  16. import java.util.List;
  17. import javolution.util.FastList;
  18. import com.l2jserver.Config;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.SystemMessageId;
  22. import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
  23. import com.l2jserver.gameserver.network.serverpackets.ExCloseMPCC;
  24. import com.l2jserver.gameserver.network.serverpackets.ExMPCCPartyInfoUpdate;
  25. import com.l2jserver.gameserver.network.serverpackets.ExOpenMPCC;
  26. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  27. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  28. /**
  29. * @author chris_00
  30. */
  31. public class L2CommandChannel extends AbstractPlayerGroup
  32. {
  33. private final List<L2Party> _partys;
  34. private L2PcInstance _commandLeader = null;
  35. private int _channelLvl;
  36. /**
  37. * Creates a New Command Channel and Add the Leaders party to the CC
  38. * @param leader
  39. */
  40. public L2CommandChannel(L2PcInstance leader)
  41. {
  42. _commandLeader = leader;
  43. _partys = new FastList<L2Party>().shared();
  44. _partys.add(leader.getParty());
  45. _channelLvl = leader.getParty().getLevel();
  46. leader.getParty().setCommandChannel(this);
  47. leader.getParty().broadcastMessage(SystemMessageId.COMMAND_CHANNEL_FORMED);
  48. leader.getParty().broadcastPacket(new ExOpenMPCC());
  49. }
  50. /**
  51. * Adds a Party to the Command Channel
  52. * @param party
  53. */
  54. public void addParty(L2Party party)
  55. {
  56. if (party == null)
  57. {
  58. return;
  59. }
  60. // Update the CCinfo for existing players
  61. broadcastPacket(new ExMPCCPartyInfoUpdate(party, 1));
  62. _partys.add(party);
  63. if (party.getLevel() > _channelLvl)
  64. {
  65. _channelLvl = party.getLevel();
  66. }
  67. party.setCommandChannel(this);
  68. party.broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.JOINED_COMMAND_CHANNEL));
  69. party.broadcastPacket(new ExOpenMPCC());
  70. }
  71. /**
  72. * Removes a Party from the Command Channel
  73. * @param party
  74. */
  75. public void removeParty(L2Party party)
  76. {
  77. if (party == null)
  78. {
  79. return;
  80. }
  81. _partys.remove(party);
  82. _channelLvl = 0;
  83. for (L2Party pty : _partys)
  84. {
  85. if (pty.getLevel() > _channelLvl)
  86. {
  87. _channelLvl = pty.getLevel();
  88. }
  89. }
  90. party.setCommandChannel(null);
  91. party.broadcastPacket(new ExCloseMPCC());
  92. if (_partys.size() < 2)
  93. {
  94. broadcastPacket(SystemMessage.getSystemMessage(SystemMessageId.COMMAND_CHANNEL_DISBANDED));
  95. disbandChannel();
  96. }
  97. else
  98. {
  99. // Update the CCinfo for existing players
  100. broadcastPacket(new ExMPCCPartyInfoUpdate(party, 0));
  101. }
  102. }
  103. /**
  104. * disbands the whole Command Channel
  105. */
  106. public void disbandChannel()
  107. {
  108. if (_partys != null)
  109. {
  110. for (L2Party party : _partys)
  111. {
  112. if (party != null)
  113. {
  114. removeParty(party);
  115. }
  116. }
  117. _partys.clear();
  118. }
  119. }
  120. /**
  121. * @return overall member count of the Command Channel
  122. */
  123. @Override
  124. public int getMemberCount()
  125. {
  126. int count = 0;
  127. for (L2Party party : _partys)
  128. {
  129. if (party != null)
  130. {
  131. count += party.getMemberCount();
  132. }
  133. }
  134. return count;
  135. }
  136. /**
  137. * Broadcast packet to every channel member
  138. * @param gsp
  139. * @deprecated
  140. * @see L2CommandChannel#broadcastPacket(L2GameServerPacket)
  141. */
  142. @Deprecated
  143. public void broadcastToChannelMembers(L2GameServerPacket gsp)
  144. {
  145. broadcastPacket(gsp);
  146. }
  147. @Deprecated
  148. public void broadcastCSToChannelMembers(CreatureSay gsp, L2PcInstance broadcaster)
  149. {
  150. broadcastCreatureSay(gsp, broadcaster);
  151. }
  152. /**
  153. * @return list of Parties in Command Channel
  154. */
  155. public List<L2Party> getPartys()
  156. {
  157. return _partys;
  158. }
  159. /**
  160. * @return list of all Members in Command Channel
  161. */
  162. @Override
  163. public List<L2PcInstance> getMembers()
  164. {
  165. List<L2PcInstance> members = new FastList<L2PcInstance>().shared();
  166. for (L2Party party : getPartys())
  167. {
  168. members.addAll(party.getMembers());
  169. }
  170. return members;
  171. }
  172. /**
  173. * @return Level of CC
  174. */
  175. @Override
  176. public int getLevel()
  177. {
  178. return _channelLvl;
  179. }
  180. /**
  181. * @param leader the leader of the Command Channel
  182. */
  183. public void setChannelLeader(L2PcInstance leader)
  184. {
  185. _commandLeader = leader;
  186. }
  187. /**
  188. * @return the leader of the Command Channel
  189. * @deprecated
  190. * @see L2CommandChannel#getLeader()
  191. */
  192. @Deprecated
  193. public L2PcInstance getChannelLeader()
  194. {
  195. return getLeader();
  196. }
  197. /**
  198. * @param obj
  199. * @return true if proper condition for RaidWar
  200. */
  201. public boolean meetRaidWarCondition(L2Object obj)
  202. {
  203. if (!((obj instanceof L2Character) && ((L2Character) obj).isRaid()))
  204. {
  205. return false;
  206. }
  207. return (getMemberCount() >= Config.LOOT_RAIDS_PRIVILEGE_CC_SIZE);
  208. }
  209. /**
  210. * @return the leader of the Command Channel
  211. */
  212. @Override
  213. public L2PcInstance getLeader()
  214. {
  215. return _commandLeader;
  216. }
  217. @Override
  218. public boolean containsPlayer(L2PcInstance player)
  219. {
  220. if ((_partys != null) && !_partys.isEmpty())
  221. {
  222. for (L2Party party : _partys)
  223. {
  224. if (party.containsPlayer(player))
  225. {
  226. return true;
  227. }
  228. }
  229. }
  230. return false;
  231. }
  232. /**
  233. * Iterates over CC without need to allocate any new list
  234. * @see com.l2jserver.gameserver.model.AbstractPlayerGroup#forEachMember(IL2Procedure)
  235. */
  236. @Override
  237. public boolean forEachMember(IL2Procedure<L2PcInstance> procedure)
  238. {
  239. if ((_partys != null) && !_partys.isEmpty())
  240. {
  241. for (L2Party party : _partys)
  242. {
  243. if (!party.forEachMember(procedure))
  244. {
  245. return false;
  246. }
  247. }
  248. }
  249. return true;
  250. }
  251. }