L2CommandChannel.java 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. *
  30. * @author chris_00
  31. */
  32. public class L2CommandChannel
  33. {
  34. private final List<L2Party> _partys;
  35. private L2PcInstance _commandLeader = null;
  36. private int _channelLvl;
  37. /**
  38. * Creates a New Command Channel and Add the Leaders party to the CC
  39. *
  40. * @param CommandChannelLeader
  41. *
  42. */
  43. public L2CommandChannel(L2PcInstance leader)
  44. {
  45. _commandLeader = leader;
  46. _partys = new FastList<L2Party>();
  47. _partys.add(leader.getParty());
  48. _channelLvl = leader.getParty().getLevel();
  49. leader.getParty().setCommandChannel(this);
  50. leader.getParty().broadcastToPartyMembers(new SystemMessage(SystemMessageId.COMMAND_CHANNEL_FORMED));
  51. leader.getParty().broadcastToPartyMembers(new ExOpenMPCC());
  52. }
  53. /**
  54. * Adds a Party to the Command Channel
  55. * @param Party
  56. */
  57. public void addParty(L2Party party)
  58. {
  59. if (party == null)
  60. return;
  61. // Update the CCinfo for existing players
  62. this.broadcastToChannelMembers(new ExMPCCPartyInfoUpdate(party, 1));
  63. _partys.add(party);
  64. if (party.getLevel() > _channelLvl)
  65. _channelLvl = party.getLevel();
  66. party.setCommandChannel(this);
  67. party.broadcastToPartyMembers(new SystemMessage(SystemMessageId.JOINED_COMMAND_CHANNEL));
  68. party.broadcastToPartyMembers(new ExOpenMPCC());
  69. }
  70. /**
  71. * Removes a Party from the Command Channel
  72. * @param Party
  73. */
  74. public void removeParty(L2Party party)
  75. {
  76. if (party == null)
  77. return;
  78. _partys.remove(party);
  79. _channelLvl = 0;
  80. for (L2Party pty : _partys)
  81. {
  82. if (pty.getLevel() > _channelLvl)
  83. _channelLvl = pty.getLevel();
  84. }
  85. party.setCommandChannel(null);
  86. party.broadcastToPartyMembers(new ExCloseMPCC());
  87. if(_partys.size() < 2)
  88. {
  89. broadcastToChannelMembers(new SystemMessage(SystemMessageId.COMMAND_CHANNEL_DISBANDED));
  90. disbandChannel();
  91. }
  92. else
  93. {
  94. // Update the CCinfo for existing players
  95. this.broadcastToChannelMembers(new ExMPCCPartyInfoUpdate(party, 0));
  96. }
  97. }
  98. /**
  99. * disbands the whole Command Channel
  100. */
  101. public void disbandChannel()
  102. {
  103. if (_partys != null)
  104. {
  105. for (L2Party party : _partys)
  106. {
  107. if(party != null)
  108. removeParty(party);
  109. }
  110. }
  111. _partys.clear();
  112. }
  113. /**
  114. * @return overall membercount of the Command Channel
  115. */
  116. public int getMemberCount()
  117. {
  118. int count = 0;
  119. for (L2Party party : _partys)
  120. {
  121. if(party != null)
  122. count += party.getMemberCount();
  123. }
  124. return count;
  125. }
  126. /**
  127. * Broadcast packet to every channelmember
  128. * @param L2GameServerPacket
  129. */
  130. public void broadcastToChannelMembers(L2GameServerPacket gsp)
  131. {
  132. if (_partys != null && !_partys.isEmpty())
  133. {
  134. for (L2Party party : _partys)
  135. {
  136. if(party != null)
  137. party.broadcastToPartyMembers(gsp);
  138. }
  139. }
  140. }
  141. public void broadcastCSToChannelMembers(CreatureSay gsp, L2PcInstance broadcaster)
  142. {
  143. if (_partys != null && !_partys.isEmpty())
  144. {
  145. for (L2Party party : _partys)
  146. {
  147. if(party != null)
  148. party.broadcastCSToPartyMembers(gsp, broadcaster);
  149. }
  150. }
  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. public List<L2PcInstance> getMembers()
  163. {
  164. List<L2PcInstance> members = new FastList<L2PcInstance>();
  165. for (L2Party party : getPartys())
  166. {
  167. members.addAll(party.getPartyMembers());
  168. }
  169. return members;
  170. }
  171. /**
  172. *
  173. * @return Level of CC
  174. */
  175. public int getLevel() { return _channelLvl; }
  176. /**
  177. * @param sets the leader of the Command Channel
  178. */
  179. public void setChannelLeader(L2PcInstance leader)
  180. {
  181. _commandLeader = leader;
  182. }
  183. /**
  184. * @return the leader of the Command Channel
  185. */
  186. public L2PcInstance getChannelLeader()
  187. {
  188. return _commandLeader;
  189. }
  190. /**
  191. *
  192. *
  193. * @param obj
  194. * @return true if proper condition for RaidWar
  195. */
  196. public boolean meetRaidWarCondition(L2Object obj)
  197. {
  198. if (!(obj instanceof L2Character && ((L2Character)obj).isRaid()))
  199. return false;
  200. return (getMemberCount() >= Config.LOOT_RAIDS_PRIVILEGE_CC_SIZE);
  201. }
  202. }