2
0

L2CommandChannel.java 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 net.sf.l2j.gameserver.model;
  16. import java.util.List;
  17. import javolution.util.FastList;
  18. import net.sf.l2j.gameserver.model.actor.instance.L2GrandBossInstance;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2RaidBossInstance;
  21. import net.sf.l2j.gameserver.network.serverpackets.ExCloseMPCC;
  22. import net.sf.l2j.gameserver.network.serverpackets.ExMPCCPartyInfoUpdate;
  23. import net.sf.l2j.gameserver.network.serverpackets.ExOpenMPCC;
  24. import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  25. /**
  26. *
  27. * @author chris_00
  28. */
  29. public class L2CommandChannel
  30. {
  31. private List<L2Party> _partys = null;
  32. private L2PcInstance _commandLeader = null;
  33. private int _channelLvl;
  34. /**
  35. * Creates a New Command Channel and Add the Leaders party to the CC
  36. *
  37. * @param CommandChannelLeader
  38. *
  39. */
  40. public L2CommandChannel(L2PcInstance leader)
  41. {
  42. _commandLeader = leader;
  43. _partys = new FastList<L2Party>();
  44. _partys.add(leader.getParty());
  45. _channelLvl = leader.getParty().getLevel();
  46. leader.getParty().setCommandChannel(this);
  47. leader.getParty().broadcastToPartyMembers(new ExOpenMPCC());
  48. }
  49. /**
  50. * Adds a Party to the Command Channel
  51. * @param Party
  52. */
  53. public void addParty(L2Party party)
  54. {
  55. // Update the CCinfo for existing players
  56. this.broadcastToChannelMembers(new ExMPCCPartyInfoUpdate(party, 1));
  57. _partys.add(party);
  58. if (party.getLevel() > _channelLvl)
  59. _channelLvl = party.getLevel();
  60. party.setCommandChannel(this);
  61. party.broadcastToPartyMembers(new ExOpenMPCC());
  62. }
  63. /**
  64. * Removes a Party from the Command Channel
  65. * @param Party
  66. */
  67. public void removeParty(L2Party party)
  68. {
  69. _partys.remove(party);
  70. _channelLvl = 0;
  71. for (L2Party pty : _partys)
  72. {
  73. if (pty.getLevel() > _channelLvl)
  74. _channelLvl = pty.getLevel();
  75. }
  76. party.setCommandChannel(null);
  77. party.broadcastToPartyMembers(new ExCloseMPCC());
  78. if(_partys.size() < 2)
  79. {
  80. disbandChannel();
  81. }
  82. else
  83. {
  84. // Update the CCinfo for existing players
  85. this.broadcastToChannelMembers(new ExMPCCPartyInfoUpdate(party, 0));
  86. }
  87. }
  88. /**
  89. * disbands the whole Command Channel
  90. */
  91. public void disbandChannel()
  92. {
  93. for (L2Party party : _partys)
  94. {
  95. if(party != null)
  96. removeParty(party);
  97. }
  98. _partys = null;
  99. }
  100. /**
  101. * @return overall membercount of the Command Channel
  102. */
  103. public int getMemberCount()
  104. {
  105. int count = 0;
  106. for (L2Party party : _partys)
  107. {
  108. if(party != null)
  109. count += party.getMemberCount();
  110. }
  111. return count;
  112. }
  113. /**
  114. * Broadcast packet to every channelmember
  115. * @param L2GameServerPacket
  116. */
  117. public void broadcastToChannelMembers(L2GameServerPacket gsp)
  118. {
  119. if (_partys != null && !_partys.isEmpty())
  120. {
  121. for (L2Party party : _partys)
  122. {
  123. if(party != null)
  124. party.broadcastToPartyMembers(gsp);
  125. }
  126. }
  127. }
  128. /**
  129. * @return list of Parties in Command Channel
  130. */
  131. public List<L2Party> getPartys()
  132. {
  133. return _partys;
  134. }
  135. /**
  136. * @return list of all Members in Command Channel
  137. */
  138. public List<L2PcInstance> getMembers()
  139. {
  140. List<L2PcInstance> members = new FastList<L2PcInstance>();
  141. for (L2Party party : getPartys())
  142. {
  143. members.addAll(party.getPartyMembers());
  144. }
  145. return members;
  146. }
  147. /**
  148. *
  149. * @return Level of CC
  150. */
  151. public int getLevel() { return _channelLvl; }
  152. /**
  153. * @param sets the leader of the Command Channel
  154. */
  155. public void setChannelLeader(L2PcInstance leader)
  156. {
  157. _commandLeader = leader;
  158. }
  159. /**
  160. * @return the leader of the Command Channel
  161. */
  162. public L2PcInstance getChannelLeader()
  163. {
  164. return _commandLeader;
  165. }
  166. /**
  167. * Queen Ant, Core, Orfen, Zaken: MemberCount > 36<br>
  168. * Baium: MemberCount > 56<br>
  169. * Antharas: MemberCount > 225<br>
  170. * Valakas: MemberCount > 99<br>
  171. * normal RaidBoss: MemberCount > 18
  172. *
  173. * @param obj
  174. * @return true if proper condition for RaidWar
  175. */
  176. public boolean meetRaidWarCondition(L2Object obj)
  177. {
  178. if (!(obj instanceof L2RaidBossInstance) || !(obj instanceof L2GrandBossInstance))
  179. return false;
  180. int npcId = ((L2Attackable)obj).getNpcId();
  181. switch(npcId)
  182. {
  183. case 29001: // Queen Ant
  184. case 29006: // Core
  185. case 29014: // Orfen
  186. case 29022: // Zaken
  187. return (getMemberCount() > 36);
  188. case 29020: // Baium
  189. return (getMemberCount() > 56);
  190. case 29019: // Antharas
  191. return (getMemberCount() > 225);
  192. case 29028: // Valakas
  193. return (getMemberCount() > 99);
  194. default: // normal Raidboss
  195. return (getMemberCount() > 18);
  196. }
  197. }
  198. }