L2Clan.java 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322
  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.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.List;
  19. import java.util.Map;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import javolution.util.FastList;
  23. import javolution.util.FastMap;
  24. import net.sf.l2j.Config;
  25. import net.sf.l2j.L2DatabaseFactory;
  26. import net.sf.l2j.gameserver.communitybbs.BB.Forum;
  27. import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
  28. import net.sf.l2j.gameserver.datatables.ClanTable;
  29. import net.sf.l2j.gameserver.datatables.SkillTable;
  30. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  31. import net.sf.l2j.gameserver.instancemanager.SiegeManager;
  32. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  33. import net.sf.l2j.gameserver.model.itemcontainer.ItemContainer;
  34. import net.sf.l2j.gameserver.network.SystemMessageId;
  35. import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  36. import net.sf.l2j.gameserver.network.serverpackets.ItemList;
  37. import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  38. import net.sf.l2j.gameserver.network.serverpackets.PledgeReceiveSubPledgeCreated;
  39. import net.sf.l2j.gameserver.network.serverpackets.PledgeShowInfoUpdate;
  40. import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListAll;
  41. import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListDeleteAll;
  42. import net.sf.l2j.gameserver.network.serverpackets.PledgeShowMemberListUpdate;
  43. import net.sf.l2j.gameserver.network.serverpackets.PledgeSkillListAdd;
  44. import net.sf.l2j.gameserver.network.serverpackets.SkillCoolTime;
  45. import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
  46. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  47. import net.sf.l2j.gameserver.network.serverpackets.UserInfo;
  48. import net.sf.l2j.gameserver.util.Util;
  49. /**
  50. * This class ...
  51. *
  52. * @version $Revision: 1.7.2.4.2.7 $ $Date: 2005/04/06 16:13:41 $
  53. */
  54. public class L2Clan
  55. {
  56. private static final Logger _log = Logger.getLogger(L2Clan.class.getName());
  57. private String _name;
  58. private int _clanId;
  59. private L2ClanMember _leader;
  60. private Map<Integer, L2ClanMember> _members = new FastMap<Integer, L2ClanMember>();
  61. private String _allyName;
  62. private int _allyId;
  63. private int _level;
  64. private int _hasCastle;
  65. private int _hasFort;
  66. private int _hasHideout;
  67. private boolean _hasCrest;
  68. private int _hiredGuards;
  69. private int _crestId;
  70. private int _crestLargeId;
  71. private int _allyCrestId;
  72. private int _auctionBiddedAt = 0;
  73. private long _allyPenaltyExpiryTime;
  74. private int _allyPenaltyType;
  75. private long _charPenaltyExpiryTime;
  76. private long _dissolvingExpiryTime;
  77. // Ally Penalty Types
  78. /** Clan leaved ally */
  79. public static final int PENALTY_TYPE_CLAN_LEAVED = 1;
  80. /** Clan was dismissed from ally */
  81. public static final int PENALTY_TYPE_CLAN_DISMISSED = 2;
  82. /** Leader clan dismiss clan from ally */
  83. public static final int PENALTY_TYPE_DISMISS_CLAN = 3;
  84. /** Leader clan dissolve ally */
  85. public static final int PENALTY_TYPE_DISSOLVE_ALLY = 4;
  86. private ItemContainer _warehouse = new ClanWarehouse(this);
  87. private List<Integer> _atWarWith = new FastList<Integer>();
  88. private List<Integer> _atWarAttackers = new FastList<Integer>();
  89. private boolean _hasCrestLarge;
  90. private Forum _forum;
  91. private List<L2Skill> _skillList = new FastList<L2Skill>();
  92. // Clan Privileges
  93. /** No privilege to manage any clan activity */
  94. public static final int CP_NOTHING = 0;
  95. /** Privilege to join clan */
  96. public static final int CP_CL_JOIN_CLAN = 2;
  97. /** Privilege to give a title */
  98. public static final int CP_CL_GIVE_TITLE = 4;
  99. /** Privilege to view warehouse content */
  100. public static final int CP_CL_VIEW_WAREHOUSE = 8;
  101. /** Privilege to manage clan ranks */
  102. public static final int CP_CL_MANAGE_RANKS = 16;
  103. public static final int CP_CL_PLEDGE_WAR = 32;
  104. public static final int CP_CL_DISMISS = 64;
  105. /** Privilege to register clan crest */
  106. public static final int CP_CL_REGISTER_CREST = 128;
  107. public static final int CP_CL_MASTER_RIGHTS = 256;
  108. public static final int CP_CL_MANAGE_LEVELS = 512;
  109. /** Privilege to open a door */
  110. public static final int CP_CH_OPEN_DOOR = 1024;
  111. public static final int CP_CH_OTHER_RIGHTS = 2048;
  112. public static final int CP_CH_AUCTION = 4096;
  113. public static final int CP_CH_DISMISS = 8192;
  114. public static final int CP_CH_SET_FUNCTIONS = 16384;
  115. public static final int CP_CS_OPEN_DOOR = 32768;
  116. public static final int CP_CS_MANOR_ADMIN = 65536;
  117. public static final int CP_CS_MANAGE_SIEGE = 131072;
  118. public static final int CP_CS_USE_FUNCTIONS = 262144;
  119. public static final int CP_CS_DISMISS = 524288;
  120. public static final int CP_CS_TAXES =1048576;
  121. public static final int CP_CS_MERCENARIES =2097152;
  122. public static final int CP_CS_SET_FUNCTIONS =4194304;
  123. /** Privilege to manage all clan activity */
  124. public static final int CP_ALL = 8388606;
  125. // Sub-unit types
  126. /** Clan subunit type of Academy */
  127. public static final int SUBUNIT_ACADEMY = -1;
  128. /** Clan subunit type of Royal Guard A */
  129. public static final int SUBUNIT_ROYAL1 = 100;
  130. /** Clan subunit type of Royal Guard B */
  131. public static final int SUBUNIT_ROYAL2 = 200;
  132. /** Clan subunit type of Order of Knights A-1 */
  133. public static final int SUBUNIT_KNIGHT1 = 1001;
  134. /** Clan subunit type of Order of Knights A-2 */
  135. public static final int SUBUNIT_KNIGHT2 = 1002;
  136. /** Clan subunit type of Order of Knights B-1 */
  137. public static final int SUBUNIT_KNIGHT3 = 2001;
  138. /** Clan subunit type of Order of Knights B-2 */
  139. public static final int SUBUNIT_KNIGHT4 = 2002;
  140. /** FastMap(Integer, L2Skill) containing all skills of the L2Clan */
  141. protected final Map<Integer, L2Skill> _skills = new FastMap<Integer, L2Skill>();
  142. protected final Map<Integer, RankPrivs> _privs = new FastMap<Integer, RankPrivs>();
  143. protected final Map<Integer, SubPledge> _subPledges = new FastMap<Integer, SubPledge>();
  144. private int _reputationScore = 0;
  145. private int _rank = 0;
  146. /**
  147. * Called if a clan is referenced only by id.
  148. * In this case all other data needs to be fetched from db
  149. *
  150. * @param clanId A valid clan Id to create and restore
  151. */
  152. public L2Clan(int clanId)
  153. {
  154. _clanId = clanId;
  155. initializePrivs();
  156. restore();
  157. getWarehouse().restore();
  158. }
  159. /**
  160. * Called only if a new clan is created
  161. *
  162. * @param clanId A valid clan Id to create
  163. * @param clanName A valid clan name
  164. */
  165. public L2Clan(int clanId, String clanName)
  166. {
  167. _clanId = clanId;
  168. _name = clanName;
  169. initializePrivs();
  170. }
  171. /**
  172. * @return Returns the clanId.
  173. */
  174. public int getClanId()
  175. {
  176. return _clanId;
  177. }
  178. /**
  179. * @param clanId The clanId to set.
  180. */
  181. public void setClanId(int clanId)
  182. {
  183. _clanId = clanId;
  184. }
  185. /**
  186. * @return Returns the leaderId.
  187. */
  188. public int getLeaderId()
  189. {
  190. return (_leader != null ? _leader.getObjectId() : 0);
  191. }
  192. /**
  193. * @return L2ClanMember of clan leader.
  194. */
  195. public L2ClanMember getLeader()
  196. {
  197. return _leader;
  198. }
  199. /**
  200. * @param leaderId The leaderId to set.
  201. */
  202. public void setLeader(L2ClanMember leader)
  203. {
  204. _leader = leader;
  205. _members.put(leader.getObjectId(), leader);
  206. }
  207. public void setNewLeader(L2ClanMember member)
  208. {
  209. if (!getLeader().isOnline())
  210. {
  211. return;
  212. }
  213. if (member == null)
  214. {
  215. return;
  216. }
  217. if (!member.isOnline())
  218. {
  219. return;
  220. }
  221. L2PcInstance exLeader = getLeader().getPlayerInstance();
  222. SiegeManager.getInstance().removeSiegeSkills(exLeader);
  223. exLeader.setClan(this);
  224. exLeader.setClanPrivileges(L2Clan.CP_NOTHING);
  225. exLeader.broadcastUserInfo();
  226. setLeader(member);
  227. updateClanInDB();
  228. exLeader.setPledgeClass(exLeader.getClan().getClanMember(exLeader.getObjectId()).calculatePledgeClass(exLeader));
  229. exLeader.broadcastUserInfo();
  230. exLeader.checkItemRestriction();
  231. L2PcInstance newLeader = member.getPlayerInstance();
  232. newLeader.setClan(this);
  233. newLeader.setPledgeClass(member.calculatePledgeClass(newLeader));
  234. newLeader.setClanPrivileges(L2Clan.CP_ALL);
  235. if (getLevel() >= SiegeManager.getInstance().getSiegeClanMinLevel())
  236. {
  237. SiegeManager.getInstance().addSiegeSkills(newLeader);
  238. // Transferring siege skills TimeStamps from old leader to new leader to prevent unlimited headquarters
  239. if (!exLeader.getReuseTimeStamp().isEmpty())
  240. {
  241. for (L2Skill sk : SkillTable.getInstance().getSiegeSkills(newLeader.isNoble()))
  242. {
  243. if (exLeader.getReuseTimeStamp().containsKey(sk.getId()))
  244. newLeader.addTimeStamp(exLeader.getReuseTimeStamp().get(sk.getId()));
  245. }
  246. newLeader.sendPacket(new SkillCoolTime(newLeader));
  247. }
  248. }
  249. newLeader.broadcastUserInfo();
  250. broadcastClanStatus();
  251. SystemMessage sm = new SystemMessage(SystemMessageId.CLAN_LEADER_PRIVILEGES_HAVE_BEEN_TRANSFERRED_TO_S1);
  252. sm.addString(newLeader.getName());
  253. broadcastToOnlineMembers(sm);
  254. sm = null;
  255. }
  256. /**
  257. * @return Returns the leaderName.
  258. */
  259. public String getLeaderName()
  260. {
  261. return _members.get(new Integer(_leader.getObjectId())).getName();
  262. }
  263. /**
  264. * @return Returns the name.
  265. */
  266. public String getName()
  267. {
  268. return _name;
  269. }
  270. /**
  271. * @param name The name to set.
  272. */
  273. public void setName(String name)
  274. {
  275. _name = name;
  276. }
  277. private void addClanMember(L2ClanMember member)
  278. {
  279. _members.put(member.getObjectId(), member);
  280. }
  281. public void addClanMember(L2PcInstance player)
  282. {
  283. // Using a different constructor, to make it easier to read
  284. // L2ClanMember(L2Clan, L2PcInstance)
  285. // L2ClanMember member = new L2ClanMember(this,player.getName(), player.getLevel(), player.getClassId().getId(), player.getObjectId(), player.getPledgeType(), player.getPowerGrade(), player.getTitle(), player.getAppearance().getSex(), player.getRace().ordinal());
  286. L2ClanMember member = new L2ClanMember(this, player);
  287. // store in memory
  288. //
  289. addClanMember(member);
  290. member.setPlayerInstance(player);
  291. player.setClan(this);
  292. player.setPledgeClass(member.calculatePledgeClass(player));
  293. player.sendPacket(new PledgeShowMemberListUpdate(player));
  294. player.sendPacket(new UserInfo(player));
  295. }
  296. public void updateClanMember(L2PcInstance player)
  297. {
  298. L2ClanMember member = new L2ClanMember(player);
  299. addClanMember(member);
  300. }
  301. public L2ClanMember getClanMember(String name)
  302. {
  303. for (L2ClanMember temp : _members.values())
  304. {
  305. if (temp.getName().equals(name)) return temp;
  306. }
  307. return null;
  308. }
  309. public L2ClanMember getClanMember(int objectID)
  310. {
  311. return _members.get(objectID);
  312. }
  313. public void removeClanMember(int objectId, long clanJoinExpiryTime)
  314. {
  315. L2ClanMember exMember = _members.remove(objectId);
  316. if(exMember == null)
  317. {
  318. _log.warning("Member Object ID: "+objectId+" not found in clan while trying to remove");
  319. return;
  320. }
  321. int leadssubpledge = getLeaderSubPledge(objectId);
  322. if (leadssubpledge != 0)
  323. {
  324. // Sub-unit leader withdraws, position becomes vacant and leader
  325. // should appoint new via NPC
  326. getSubPledge(leadssubpledge).setLeaderId(0);
  327. updateSubPledgeInDB(leadssubpledge);
  328. }
  329. if(exMember.getApprentice() != 0)
  330. {
  331. L2ClanMember apprentice = getClanMember(exMember.getApprentice());
  332. if(apprentice != null)
  333. {
  334. if (apprentice.getPlayerInstance() != null)
  335. apprentice.getPlayerInstance().setSponsor(0);
  336. else
  337. apprentice.initApprenticeAndSponsor(0, 0);
  338. apprentice.saveApprenticeAndSponsor(0, 0);
  339. }
  340. }
  341. if(exMember.getSponsor() != 0)
  342. {
  343. L2ClanMember sponsor = getClanMember(exMember.getSponsor());
  344. if(sponsor != null)
  345. {
  346. if (sponsor.getPlayerInstance() != null)
  347. sponsor.getPlayerInstance().setApprentice(0);
  348. else
  349. sponsor.initApprenticeAndSponsor(0, 0);
  350. sponsor.saveApprenticeAndSponsor(0, 0);
  351. }
  352. }
  353. exMember.saveApprenticeAndSponsor(0, 0);
  354. if (Config.REMOVE_CASTLE_CIRCLETS)
  355. {
  356. CastleManager.getInstance().removeCirclet(exMember,getHasCastle());
  357. }
  358. if (exMember.isOnline())
  359. {
  360. L2PcInstance player = exMember.getPlayerInstance();
  361. player.setTitle("");
  362. player.setApprentice(0);
  363. player.setSponsor(0);
  364. if (player.isClanLeader())
  365. {
  366. SiegeManager.getInstance().removeSiegeSkills(player);
  367. player.setClanCreateExpiryTime(System.currentTimeMillis() + Config.ALT_CLAN_CREATE_DAYS * 86400000L); //24*60*60*1000 = 86400000
  368. }
  369. // remove Clanskills from Player
  370. for(L2Skill skill: player.getClan().getAllSkills())
  371. player.removeSkill(skill,false);
  372. player.setClan(null);
  373. player.setClanJoinExpiryTime(clanJoinExpiryTime);
  374. player.setPledgeClass(exMember.calculatePledgeClass(player));
  375. player.broadcastUserInfo();
  376. // disable clan tab
  377. player.sendPacket(new PledgeShowMemberListDeleteAll());
  378. }
  379. else
  380. {
  381. removeMemberInDatabase(exMember, clanJoinExpiryTime,
  382. getLeaderId()==objectId ? System.currentTimeMillis() + Config.ALT_CLAN_CREATE_DAYS * 86400000L : 0);
  383. }
  384. }
  385. public L2ClanMember[] getMembers()
  386. {
  387. return _members.values().toArray(new L2ClanMember[_members.size()]);
  388. }
  389. public int getMembersCount()
  390. {
  391. return _members.size();
  392. }
  393. public int getSubPledgeMembersCount(int subpl)
  394. {
  395. int result = 0;
  396. for (L2ClanMember temp : _members.values())
  397. {
  398. if (temp.getPledgeType() == subpl) result++;
  399. }
  400. return result;
  401. }
  402. public int getMaxNrOfMembers(int pledgetype)
  403. {
  404. int limit = 0;
  405. switch (pledgetype)
  406. {
  407. case 0:
  408. switch (getLevel())
  409. {
  410. case 4:
  411. limit = 40;
  412. break;
  413. case 3:
  414. limit = 30;
  415. break;
  416. case 2:
  417. limit = 20;
  418. break;
  419. case 1:
  420. limit = 15;
  421. break;
  422. case 0:
  423. limit = 10;
  424. break;
  425. default:
  426. limit = 40;
  427. break;
  428. }
  429. break;
  430. case -1:
  431. case 100:
  432. case 200:
  433. limit = 20;
  434. break;
  435. case 1001:
  436. case 1002:
  437. case 2001:
  438. case 2002:
  439. switch (getLevel())
  440. {
  441. case 9:
  442. case 10:
  443. limit = 25;
  444. break;
  445. default:
  446. limit = 10;
  447. break;
  448. }
  449. break;
  450. default:
  451. break;
  452. }
  453. return limit;
  454. }
  455. public L2PcInstance[] getOnlineMembers(int exclude)
  456. {
  457. List<L2PcInstance> result = new FastList<L2PcInstance>();
  458. for (L2ClanMember temp : _members.values())
  459. {
  460. try {
  461. if (temp.isOnline() && !(temp.getObjectId()==exclude))
  462. result.add(temp.getPlayerInstance());
  463. } catch (NullPointerException e) {}
  464. }
  465. return result.toArray(new L2PcInstance[result.size()]);
  466. }
  467. /**
  468. * @return
  469. */
  470. public int getAllyId()
  471. {
  472. return _allyId;
  473. }
  474. /**
  475. * @return
  476. */
  477. public String getAllyName()
  478. {
  479. return _allyName;
  480. }
  481. public void setAllyCrestId(int allyCrestId)
  482. {
  483. _allyCrestId = allyCrestId;
  484. }
  485. /**
  486. * @return
  487. */
  488. public int getAllyCrestId()
  489. {
  490. return _allyCrestId;
  491. }
  492. /**
  493. * @return
  494. */
  495. public int getLevel()
  496. {
  497. return _level;
  498. }
  499. /**
  500. * @return
  501. */
  502. public int getHasCastle()
  503. {
  504. return _hasCastle;
  505. }
  506. /**
  507. * @return
  508. */
  509. public int getHasFort()
  510. {
  511. return _hasFort;
  512. }
  513. /**
  514. * @return
  515. */
  516. public int getHasHideout()
  517. {
  518. return _hasHideout;
  519. }
  520. /**
  521. * @param crestId The id of pledge crest.
  522. */
  523. public void setCrestId(int crestId)
  524. {
  525. _crestId = crestId;
  526. }
  527. /**
  528. * @return Returns the clanCrestId.
  529. */
  530. public int getCrestId()
  531. {
  532. return _crestId;
  533. }
  534. /**
  535. * @param crestLargeId The id of pledge LargeCrest.
  536. */
  537. public void setCrestLargeId(int crestLargeId)
  538. {
  539. _crestLargeId = crestLargeId;
  540. }
  541. /**
  542. * @return Returns the clan CrestLargeId
  543. */
  544. public int getCrestLargeId()
  545. {
  546. return _crestLargeId;
  547. }
  548. /**
  549. * @param allyId The allyId to set.
  550. */
  551. public void setAllyId(int allyId)
  552. {
  553. _allyId = allyId;
  554. }
  555. /**
  556. * @param allyName The allyName to set.
  557. */
  558. public void setAllyName(String allyName)
  559. {
  560. _allyName = allyName;
  561. }
  562. /**
  563. * @param hasCastle The hasCastle to set.
  564. */
  565. public void setHasCastle(int hasCastle)
  566. {
  567. _hasCastle = hasCastle;
  568. }
  569. /**
  570. * @param hasFort The hasFort to set.
  571. */
  572. public void setHasFort(int hasFort)
  573. {
  574. _hasFort = hasFort;
  575. }
  576. /**
  577. * @param hasHideout The hasHideout to set.
  578. */
  579. public void setHasHideout(int hasHideout)
  580. {
  581. _hasHideout = hasHideout;
  582. }
  583. /**
  584. * @param level The level to set.
  585. */
  586. public void setLevel(int level)
  587. {
  588. _level = level;
  589. if(_forum == null)
  590. {
  591. if(_level >= 2)
  592. {
  593. _forum = ForumsBBSManager.getInstance().getForumByName("ClanRoot").getChildByName(_name);
  594. if(_forum == null)
  595. {
  596. _forum = ForumsBBSManager.getInstance().createNewForum(_name,ForumsBBSManager.getInstance().getForumByName("ClanRoot"),Forum.CLAN,Forum.CLANMEMBERONLY,getClanId());
  597. }
  598. }
  599. }
  600. }
  601. /**
  602. * @param player name
  603. * @return
  604. */
  605. public boolean isMember(int id)
  606. {
  607. return (id == 0 ? false :_members.containsKey(id));
  608. }
  609. public void updateClanInDB()
  610. {
  611. java.sql.Connection con = null;
  612. try
  613. {
  614. con = L2DatabaseFactory.getInstance().getConnection();
  615. PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET leader_id=?,ally_id=?,ally_name=?,reputation_score=?,ally_penalty_expiry_time=?,ally_penalty_type=?,char_penalty_expiry_time=?,dissolving_expiry_time=? WHERE clan_id=?");
  616. statement.setInt(1, getLeaderId());
  617. statement.setInt(2, getAllyId());
  618. statement.setString(3, getAllyName());
  619. statement.setInt(4, getReputationScore());
  620. statement.setLong(5, getAllyPenaltyExpiryTime());
  621. statement.setInt(6, getAllyPenaltyType());
  622. statement.setLong(7, getCharPenaltyExpiryTime());
  623. statement.setLong(8, getDissolvingExpiryTime());
  624. statement.setInt(9, getClanId());
  625. statement.execute();
  626. statement.close();
  627. if (Config.DEBUG) _log.fine("New clan leader saved in db: "+getClanId());
  628. }
  629. catch (Exception e)
  630. {
  631. _log.log(Level.SEVERE, "Error saving new clan leader.", e);
  632. }
  633. finally
  634. {
  635. try
  636. {
  637. con.close();
  638. }
  639. catch (Exception e)
  640. {
  641. }
  642. }
  643. }
  644. public void store()
  645. {
  646. java.sql.Connection con = null;
  647. try
  648. {
  649. con = L2DatabaseFactory.getInstance().getConnection();
  650. PreparedStatement statement = con.prepareStatement("INSERT INTO clan_data (clan_id,clan_name,clan_level,hasCastle,ally_id,ally_name,leader_id,crest_id,crest_large_id,ally_crest_id) values (?,?,?,?,?,?,?,?,?,?)");
  651. statement.setInt(1, getClanId());
  652. statement.setString(2, getName());
  653. statement.setInt(3, getLevel());
  654. statement.setInt(4, getHasCastle());
  655. statement.setInt(5, getAllyId());
  656. statement.setString(6, getAllyName());
  657. statement.setInt(7, getLeaderId());
  658. statement.setInt(8, getCrestId());
  659. statement.setInt(9,getCrestLargeId());
  660. statement.setInt(10,getAllyCrestId());
  661. statement.execute();
  662. statement.close();
  663. if (Config.DEBUG) _log.fine("New clan saved in db: "+getClanId());
  664. }
  665. catch (Exception e)
  666. {
  667. _log.log(Level.SEVERE, "Error saving new clan.", e);
  668. }
  669. finally
  670. {
  671. try { con.close(); } catch (Exception e) {}
  672. }
  673. }
  674. private void removeMemberInDatabase(L2ClanMember member, long clanJoinExpiryTime, long clanCreateExpiryTime)
  675. {
  676. java.sql.Connection con = null;
  677. try
  678. {
  679. con = L2DatabaseFactory.getInstance().getConnection();
  680. PreparedStatement statement = con.prepareStatement("UPDATE characters SET clanid=0, title=?, clan_join_expiry_time=?, clan_create_expiry_time=?, clan_privs=0, wantspeace=0, subpledge=0, lvl_joined_academy=0, apprentice=0, sponsor=0 WHERE charId=?");
  681. statement.setString(1, "");
  682. statement.setLong(2, clanJoinExpiryTime);
  683. statement.setLong(3, clanCreateExpiryTime);
  684. statement.setInt(4, member.getObjectId());
  685. statement.execute();
  686. statement.close();
  687. if (Config.DEBUG) _log.fine("clan member removed in db: "+getClanId());
  688. statement = con.prepareStatement("UPDATE characters SET apprentice=0 WHERE apprentice=?");
  689. statement.setInt(1, member.getObjectId());
  690. statement.execute();
  691. statement.close();
  692. statement = con.prepareStatement("UPDATE characters SET sponsor=0 WHERE sponsor=?");
  693. statement.setInt(1, member.getObjectId());
  694. statement.execute();
  695. statement.close();
  696. }
  697. catch (Exception e)
  698. {
  699. _log.log(Level.SEVERE, "Error removing clan member.", e);
  700. }
  701. finally
  702. {
  703. try { con.close(); } catch (Exception e) {}
  704. }
  705. }
  706. @SuppressWarnings("unused")
  707. private void updateWarsInDB()
  708. {
  709. java.sql.Connection con = null;
  710. try
  711. {
  712. con = L2DatabaseFactory.getInstance().getConnection();
  713. PreparedStatement statement;
  714. statement = con.prepareStatement("UPDATE clan_wars SET wantspeace1=? WHERE clan1=?");
  715. statement.setInt(1, 0);
  716. statement.setInt(2, 0);
  717. // TODO: deprecated? no execute? :o
  718. statement.close();
  719. }
  720. catch (Exception e)
  721. {
  722. _log.log(Level.SEVERE, "Error updating clan wars data.", e);
  723. }
  724. finally
  725. {
  726. try
  727. {
  728. con.close();
  729. }
  730. catch (Exception e)
  731. {
  732. }
  733. }
  734. }
  735. private void restore()
  736. {
  737. //restorewars();
  738. java.sql.Connection con = null;
  739. try
  740. {
  741. L2ClanMember member;
  742. con = L2DatabaseFactory.getInstance().getConnection();
  743. PreparedStatement statement = con.prepareStatement("SELECT clan_name,clan_level,hasCastle,ally_id,ally_name,leader_id,crest_id,crest_large_id,ally_crest_id,reputation_score,auction_bid_at,ally_penalty_expiry_time,ally_penalty_type,char_penalty_expiry_time,dissolving_expiry_time FROM clan_data where clan_id=?");
  744. statement.setInt(1, getClanId());
  745. ResultSet clanData = statement.executeQuery();
  746. if (clanData.next())
  747. {
  748. setName(clanData.getString("clan_name"));
  749. setLevel(clanData.getInt("clan_level"));
  750. setHasCastle(clanData.getInt("hasCastle"));
  751. setAllyId(clanData.getInt("ally_id"));
  752. setAllyName(clanData.getString("ally_name"));
  753. setAllyPenaltyExpiryTime(clanData.getLong("ally_penalty_expiry_time"), clanData.getInt("ally_penalty_type"));
  754. if (getAllyPenaltyExpiryTime() < System.currentTimeMillis())
  755. {
  756. setAllyPenaltyExpiryTime(0, 0);
  757. }
  758. setCharPenaltyExpiryTime(clanData.getLong("char_penalty_expiry_time"));
  759. if (getCharPenaltyExpiryTime() + Config.ALT_CLAN_JOIN_DAYS * 86400000L < System.currentTimeMillis()) //24*60*60*1000 = 86400000
  760. {
  761. setCharPenaltyExpiryTime(0);
  762. }
  763. setDissolvingExpiryTime(clanData.getLong("dissolving_expiry_time"));
  764. setCrestId(clanData.getInt("crest_id"));
  765. if (getCrestId() != 0)
  766. {
  767. setHasCrest(true);
  768. }
  769. setCrestLargeId(clanData.getInt("crest_large_id"));
  770. if (getCrestLargeId() != 0)
  771. {
  772. setHasCrestLarge(true);
  773. }
  774. setAllyCrestId(clanData.getInt("ally_crest_id"));
  775. setReputationScore(clanData.getInt("reputation_score"), false);
  776. setAuctionBiddedAt(clanData.getInt("auction_bid_at"), false);
  777. int leaderId = (clanData.getInt("leader_id"));
  778. PreparedStatement statement2 = con.prepareStatement("SELECT char_name,level,classid,charId,title,power_grade,subpledge,apprentice,sponsor,sex,race FROM characters WHERE clanid=?");
  779. statement2.setInt(1, getClanId());
  780. ResultSet clanMembers = statement2.executeQuery();
  781. while (clanMembers.next())
  782. {
  783. member = new L2ClanMember(this, clanMembers.getString("char_name"), clanMembers.getInt("level"), clanMembers.getInt("classid"), clanMembers.getInt("charId"),clanMembers.getInt("subpledge"), clanMembers.getInt("power_grade"), clanMembers.getString("title"), (clanMembers.getInt("sex")!=0), clanMembers.getInt("race"));
  784. if (member.getObjectId() == leaderId)
  785. setLeader(member);
  786. else
  787. addClanMember(member);
  788. member.initApprenticeAndSponsor(clanMembers.getInt("apprentice"), clanMembers.getInt("sponsor"));
  789. }
  790. clanMembers.close();
  791. statement2.close();
  792. }
  793. clanData.close();
  794. statement.close();
  795. if (Config.DEBUG && getName() != null)
  796. _log.config("Restored clan data for \"" + getName() + "\" from database.");
  797. restoreSubPledges();
  798. restoreRankPrivs();
  799. restoreSkills();
  800. }
  801. catch (Exception e)
  802. {
  803. _log.log(Level.SEVERE, "Error restoring clan data.", e);
  804. }
  805. finally
  806. {
  807. try { con.close(); } catch (Exception e) {}
  808. }
  809. }
  810. private void restoreSkills()
  811. {
  812. java.sql.Connection con = null;
  813. try
  814. {
  815. // Retrieve all skills of this L2PcInstance from the database
  816. con = L2DatabaseFactory.getInstance().getConnection();
  817. PreparedStatement statement = con.prepareStatement("SELECT skill_id,skill_level FROM clan_skills WHERE clan_id=?");
  818. statement.setInt(1, getClanId());
  819. ResultSet rset = statement.executeQuery();
  820. // Go though the recordset of this SQL query
  821. while (rset.next())
  822. {
  823. int id = rset.getInt("skill_id");
  824. int level = rset.getInt("skill_level");
  825. // Create a L2Skill object for each record
  826. L2Skill skill = SkillTable.getInstance().getInfo(id, level);
  827. // Add the L2Skill object to the L2Clan _skills
  828. _skills.put(skill.getId(), skill);
  829. }
  830. rset.close();
  831. statement.close();
  832. }
  833. catch (Exception e)
  834. {
  835. _log.log(Level.SEVERE, "Error restoring clan skills.", e);
  836. }
  837. finally
  838. {
  839. try { con.close(); } catch (Exception e) {}
  840. }
  841. }
  842. /** used to retrieve all skills */
  843. public final L2Skill[] getAllSkills()
  844. {
  845. if (_skills == null)
  846. return new L2Skill[0];
  847. return _skills.values().toArray(new L2Skill[_skills.values().size()]);
  848. }
  849. /** used to add a skill to skill list of this L2Clan */
  850. public L2Skill addSkill(L2Skill newSkill)
  851. {
  852. L2Skill oldSkill = null;
  853. if (newSkill != null)
  854. {
  855. // Replace oldSkill by newSkill or Add the newSkill
  856. oldSkill = _skills.put(newSkill.getId(), newSkill);
  857. }
  858. return oldSkill;
  859. }
  860. /** used to add a new skill to the list, send a packet to all online clan members, update their stats and store it in db*/
  861. public L2Skill addNewSkill(L2Skill newSkill)
  862. {
  863. L2Skill oldSkill = null;
  864. java.sql.Connection con = null;
  865. if (newSkill != null)
  866. {
  867. // Replace oldSkill by newSkill or Add the newSkill
  868. oldSkill = _skills.put(newSkill.getId(), newSkill);
  869. try
  870. {
  871. con = L2DatabaseFactory.getInstance().getConnection();
  872. PreparedStatement statement;
  873. if (oldSkill != null)
  874. {
  875. statement = con.prepareStatement("UPDATE clan_skills SET skill_level=? WHERE skill_id=? AND clan_id=?");
  876. statement.setInt(1, newSkill.getLevel());
  877. statement.setInt(2, oldSkill.getId());
  878. statement.setInt(3, getClanId());
  879. statement.execute();
  880. statement.close();
  881. }
  882. else
  883. {
  884. statement = con.prepareStatement("INSERT INTO clan_skills (clan_id,skill_id,skill_level,skill_name) VALUES (?,?,?,?)");
  885. statement.setInt(1, getClanId());
  886. statement.setInt(2, newSkill.getId());
  887. statement.setInt(3, newSkill.getLevel());
  888. statement.setString(4, newSkill.getName());
  889. statement.execute();
  890. statement.close();
  891. }
  892. }
  893. catch (Exception e)
  894. {
  895. _log.warning("Error could not store char skills: " + e);
  896. }
  897. finally
  898. {
  899. try { con.close(); } catch (Exception e) {}
  900. }
  901. for (L2ClanMember temp : _members.values())
  902. {
  903. try {
  904. if (temp.isOnline())
  905. {
  906. if (newSkill.getMinPledgeClass() <= temp.getPlayerInstance().getPledgeClass())
  907. {
  908. temp.getPlayerInstance().addSkill(newSkill, false); // Skill is not saved to player DB
  909. temp.getPlayerInstance().sendPacket(new PledgeSkillListAdd(newSkill.getId(), newSkill.getLevel()));
  910. }
  911. }
  912. } catch (NullPointerException e) {}
  913. }
  914. }
  915. return oldSkill;
  916. }
  917. public void addSkillEffects()
  918. {
  919. for(L2Skill skill : _skills.values())
  920. {
  921. for (L2ClanMember temp : _members.values())
  922. {
  923. try{
  924. if (temp.isOnline())
  925. {
  926. if (skill.getMinPledgeClass() <= temp.getPlayerInstance().getPledgeClass())
  927. temp.getPlayerInstance().addSkill(skill, false); // Skill is not saved to player DB
  928. }
  929. } catch (NullPointerException e) {}
  930. }
  931. }
  932. }
  933. public void addSkillEffects(L2PcInstance cm)
  934. {
  935. if (cm == null)
  936. return;
  937. for(L2Skill skill : _skills.values())
  938. {
  939. //TODO add skills according to members class( in ex. don't add Clan Agillity skill's effect to lower class then Baron)
  940. if (skill.getMinPledgeClass() <= cm.getPledgeClass())
  941. cm.addSkill(skill, false); // Skill is not saved to player DB
  942. }
  943. }
  944. /*
  945. public void broadcastToOnlineAllyMembers(L2GameServerPacket packet)
  946. {
  947. if (getAllyId() == 0)
  948. {
  949. return;
  950. }
  951. for (L2Clan clan : _allyList.values())
  952. {
  953. clan.broadcastToOnlineMembers(packet);
  954. }
  955. }
  956. */
  957. public void broadcastToOnlineAllyMembers(L2GameServerPacket packet)
  958. {
  959. if (getAllyId() == 0)
  960. {
  961. return;
  962. }
  963. for (L2Clan clan : ClanTable.getInstance().getClans())
  964. {
  965. if (clan.getAllyId() == getAllyId())
  966. {
  967. clan.broadcastToOnlineMembers(packet);
  968. }
  969. }
  970. }
  971. public void broadcastToOnlineMembers(L2GameServerPacket packet)
  972. {
  973. for (L2ClanMember member : _members.values())
  974. {
  975. try {
  976. if (member.isOnline())
  977. member.getPlayerInstance().sendPacket(packet);
  978. } catch (NullPointerException e) {}
  979. }
  980. }
  981. public void broadcastCSToOnlineMembers(CreatureSay packet, L2PcInstance broadcaster)
  982. {
  983. for (L2ClanMember member : _members.values())
  984. {
  985. try {
  986. if (member.isOnline() && !BlockList.isBlocked(member.getPlayerInstance(), broadcaster))
  987. member.getPlayerInstance().sendPacket(packet);
  988. } catch (NullPointerException e) {}
  989. }
  990. }
  991. public void broadcastToOtherOnlineMembers(L2GameServerPacket packet, L2PcInstance player)
  992. {
  993. for (L2ClanMember member : _members.values())
  994. {
  995. try {
  996. if (member.isOnline() && member.getPlayerInstance() != player)
  997. member.getPlayerInstance().sendPacket(packet);
  998. } catch (NullPointerException e) {}
  999. }
  1000. }
  1001. @Override
  1002. public String toString()
  1003. {
  1004. return getName();
  1005. }
  1006. /**
  1007. * @return
  1008. */
  1009. public boolean hasCrest()
  1010. {
  1011. return _hasCrest;
  1012. }
  1013. public boolean hasCrestLarge()
  1014. {
  1015. return _hasCrestLarge;
  1016. }
  1017. public void setHasCrest(boolean flag)
  1018. {
  1019. _hasCrest = flag;
  1020. }
  1021. public void setHasCrestLarge(boolean flag)
  1022. {
  1023. _hasCrestLarge = flag;
  1024. }
  1025. public ItemContainer getWarehouse()
  1026. {
  1027. return _warehouse;
  1028. }
  1029. public boolean isAtWarWith(Integer id)
  1030. {
  1031. if ((_atWarWith != null)&&(_atWarWith.size() > 0))
  1032. if (_atWarWith.contains(id)) return true;
  1033. return false;
  1034. }
  1035. public boolean isAtWarAttacker(Integer id)
  1036. {
  1037. if ((_atWarAttackers != null)&&(_atWarAttackers.size() > 0))
  1038. if (_atWarAttackers.contains(id)) return true;
  1039. return false;
  1040. }
  1041. public void setEnemyClan(L2Clan clan)
  1042. {
  1043. Integer id = clan.getClanId();
  1044. _atWarWith.add(id);
  1045. }
  1046. public void setEnemyClan(Integer clan)
  1047. {
  1048. _atWarWith.add(clan);
  1049. }
  1050. public void setAttackerClan(L2Clan clan)
  1051. {
  1052. Integer id = clan.getClanId();
  1053. _atWarAttackers.add(id);
  1054. }
  1055. public void setAttackerClan(Integer clan)
  1056. {
  1057. _atWarAttackers.add(clan);
  1058. }
  1059. public void deleteEnemyClan(L2Clan clan)
  1060. {
  1061. Integer id = clan.getClanId();
  1062. _atWarWith.remove(id);
  1063. }
  1064. public void deleteAttackerClan(L2Clan clan)
  1065. {
  1066. Integer id = clan.getClanId();
  1067. _atWarAttackers.remove(id);
  1068. }
  1069. public int getHiredGuards(){ return _hiredGuards; }
  1070. public void incrementHiredGuards(){ _hiredGuards++; }
  1071. public boolean isAtWar()
  1072. {
  1073. if ((_atWarWith != null)&&(_atWarWith.size() > 0))
  1074. return true;
  1075. return false;
  1076. }
  1077. public List<Integer> getWarList()
  1078. {
  1079. return _atWarWith;
  1080. }
  1081. public List<Integer> getAttackerList()
  1082. {
  1083. return _atWarAttackers;
  1084. }
  1085. public void broadcastClanStatus()
  1086. {
  1087. for(L2PcInstance member: getOnlineMembers(0))
  1088. {
  1089. member.sendPacket(new PledgeShowMemberListDeleteAll());
  1090. member.sendPacket(new PledgeShowMemberListAll(this, member));
  1091. }
  1092. }
  1093. public void removeSkill(int id)
  1094. {
  1095. L2Skill deleteSkill = null;
  1096. for(L2Skill sk : _skillList)
  1097. {
  1098. if(sk.getId() == id)
  1099. {
  1100. deleteSkill = sk;
  1101. return;
  1102. }
  1103. }
  1104. _skillList.remove(deleteSkill);
  1105. }
  1106. public void removeSkill(L2Skill deleteSkill)
  1107. {
  1108. _skillList.remove(deleteSkill);
  1109. }
  1110. /**
  1111. * @return
  1112. */
  1113. public List<L2Skill> getSkills()
  1114. {
  1115. return _skillList;
  1116. }
  1117. public class SubPledge
  1118. {
  1119. private int _id;
  1120. private String _subPledgeName;
  1121. private int _leaderId;
  1122. public SubPledge(int id, String name, int leaderId)
  1123. {
  1124. _id = id;
  1125. _subPledgeName = name;
  1126. _leaderId = leaderId;
  1127. }
  1128. public int getId()
  1129. {
  1130. return _id;
  1131. }
  1132. public String getName()
  1133. {
  1134. return _subPledgeName;
  1135. }
  1136. public int getLeaderId()
  1137. {
  1138. return _leaderId;
  1139. }
  1140. public void setLeaderId(int leaderId)
  1141. {
  1142. _leaderId = leaderId;
  1143. }
  1144. }
  1145. public class RankPrivs
  1146. {
  1147. private int _rankId;
  1148. private int _party;// TODO find out what this stuff means and implement it
  1149. private int _rankPrivs;
  1150. public RankPrivs(int rank, int party, int privs)
  1151. {
  1152. _rankId = rank;
  1153. _party = party;
  1154. _rankPrivs = privs;
  1155. }
  1156. public int getRank()
  1157. {
  1158. return _rankId;
  1159. }
  1160. public int getParty()
  1161. {
  1162. return _party;
  1163. }
  1164. public int getPrivs()
  1165. {
  1166. return _rankPrivs;
  1167. }
  1168. public void setPrivs(int privs)
  1169. {
  1170. _rankPrivs = privs;
  1171. }
  1172. }
  1173. private void restoreSubPledges()
  1174. {
  1175. java.sql.Connection con = null;
  1176. try
  1177. {
  1178. // Retrieve all subpledges of this clan from the database
  1179. con = L2DatabaseFactory.getInstance().getConnection();
  1180. PreparedStatement statement = con.prepareStatement("SELECT sub_pledge_id,name,leader_id FROM clan_subpledges WHERE clan_id=?");
  1181. statement.setInt(1, getClanId());
  1182. ResultSet rset = statement.executeQuery();
  1183. while (rset.next())
  1184. {
  1185. int id = rset.getInt("sub_pledge_id");
  1186. String name = rset.getString("name");
  1187. int leaderId = rset.getInt("leader_id");
  1188. // Create a SubPledge object for each record
  1189. SubPledge pledge = new SubPledge(id, name, leaderId);
  1190. _subPledges.put(id, pledge);
  1191. }
  1192. rset.close();
  1193. statement.close();
  1194. }
  1195. catch (Exception e)
  1196. {
  1197. _log.warning("Could not restore clan sub-units: " + e);
  1198. }
  1199. finally
  1200. {
  1201. try { con.close(); } catch (Exception e) {}
  1202. }
  1203. }
  1204. /** used to retrieve subPledge by type */
  1205. public final SubPledge getSubPledge(int pledgeType)
  1206. {
  1207. if (_subPledges == null)
  1208. return null;
  1209. return _subPledges.get(pledgeType);
  1210. }
  1211. /** used to retrieve subPledge by type */
  1212. public final SubPledge getSubPledge(String pledgeName)
  1213. {
  1214. if (_subPledges == null)
  1215. return null;
  1216. for (SubPledge sp : _subPledges.values())
  1217. {
  1218. if (sp.getName().equalsIgnoreCase(pledgeName))
  1219. {
  1220. return sp;
  1221. }
  1222. }
  1223. return null;
  1224. }
  1225. /** used to retrieve all subPledges */
  1226. public final SubPledge[] getAllSubPledges()
  1227. {
  1228. if (_subPledges == null)
  1229. return new SubPledge[0];
  1230. return _subPledges.values().toArray(new SubPledge[_subPledges.values().size()]);
  1231. }
  1232. public SubPledge createSubPledge(L2PcInstance player, int pledgeType, int leaderId, String subPledgeName)
  1233. {
  1234. SubPledge subPledge = null;
  1235. pledgeType = getAvailablePledgeTypes(pledgeType);
  1236. if (pledgeType == 0)
  1237. {
  1238. if (pledgeType == L2Clan.SUBUNIT_ACADEMY)
  1239. player.sendPacket(new SystemMessage(SystemMessageId.CLAN_HAS_ALREADY_ESTABLISHED_A_CLAN_ACADEMY));
  1240. else
  1241. player.sendMessage("You can't create any more sub-units of this type");
  1242. return null;
  1243. }
  1244. if (_leader.getObjectId()==leaderId)
  1245. {
  1246. player.sendMessage("Leader is not correct");
  1247. return null;
  1248. }
  1249. // Royal Guard 5000 points per each
  1250. // Order of Knights 10000 points per each
  1251. if(pledgeType != -1 &&
  1252. ((getReputationScore() < 5000 && pledgeType < L2Clan.SUBUNIT_KNIGHT1) ||
  1253. (getReputationScore() < 10000 && pledgeType > L2Clan.SUBUNIT_ROYAL2)))
  1254. {
  1255. SystemMessage sp = new SystemMessage(SystemMessageId.THE_CLAN_REPUTATION_SCORE_IS_TOO_LOW);
  1256. player.sendPacket(sp);
  1257. return null;
  1258. }
  1259. else
  1260. {
  1261. java.sql.Connection con = null;
  1262. try
  1263. {
  1264. con = L2DatabaseFactory.getInstance().getConnection();
  1265. PreparedStatement statement = con.prepareStatement("INSERT INTO clan_subpledges (clan_id,sub_pledge_id,name,leader_id) values (?,?,?,?)");
  1266. statement.setInt(1, getClanId());
  1267. statement.setInt(2, pledgeType);
  1268. statement.setString(3, subPledgeName);
  1269. if (pledgeType != -1)
  1270. statement.setInt(4, leaderId);
  1271. else
  1272. statement.setInt(4, 0);
  1273. statement.execute();
  1274. statement.close();
  1275. subPledge = new SubPledge(pledgeType, subPledgeName, leaderId);
  1276. _subPledges.put(pledgeType, subPledge);
  1277. if(pledgeType != -1)
  1278. {
  1279. setReputationScore(getReputationScore() - 2500, true);
  1280. }
  1281. if (Config.DEBUG) _log.fine("New sub_clan saved in db: "+getClanId()+"; "+pledgeType);
  1282. }
  1283. catch (Exception e)
  1284. {
  1285. _log.log(Level.SEVERE, "Error saving sub clan data.", e);
  1286. }
  1287. finally
  1288. {
  1289. try { con.close(); } catch (Exception e) {}
  1290. }
  1291. }
  1292. broadcastToOnlineMembers(new PledgeShowInfoUpdate(_leader.getClan()));
  1293. broadcastToOnlineMembers(new PledgeReceiveSubPledgeCreated(subPledge, _leader.getClan()));
  1294. return subPledge;
  1295. }
  1296. public int getAvailablePledgeTypes(int pledgeType)
  1297. {
  1298. if (_subPledges.get(pledgeType) != null)
  1299. {
  1300. //_log.warning("found sub-unit with id: "+pledgeType);
  1301. switch(pledgeType)
  1302. {
  1303. case SUBUNIT_ACADEMY:
  1304. return 0;
  1305. case SUBUNIT_ROYAL1:
  1306. pledgeType = getAvailablePledgeTypes(SUBUNIT_ROYAL2);
  1307. break;
  1308. case SUBUNIT_ROYAL2:
  1309. return 0;
  1310. case SUBUNIT_KNIGHT1:
  1311. pledgeType = getAvailablePledgeTypes(SUBUNIT_KNIGHT2);
  1312. break;
  1313. case SUBUNIT_KNIGHT2:
  1314. pledgeType = getAvailablePledgeTypes(SUBUNIT_KNIGHT3);
  1315. break;
  1316. case SUBUNIT_KNIGHT3:
  1317. pledgeType = getAvailablePledgeTypes(SUBUNIT_KNIGHT4);
  1318. break;
  1319. case SUBUNIT_KNIGHT4:
  1320. return 0;
  1321. }
  1322. }
  1323. return pledgeType;
  1324. }
  1325. public void updateSubPledgeInDB(int pledgeType)
  1326. {
  1327. java.sql.Connection con = null;
  1328. try
  1329. {
  1330. con = L2DatabaseFactory.getInstance().getConnection();
  1331. PreparedStatement statement = con.prepareStatement("UPDATE clan_subpledges SET leader_id=? WHERE clan_id=? AND sub_pledge_id=?");
  1332. statement.setInt(1, getSubPledge(pledgeType).getLeaderId());
  1333. statement.setInt(2, getClanId());
  1334. statement.setInt(3, pledgeType);
  1335. statement.execute();
  1336. statement.close();
  1337. if (Config.DEBUG)
  1338. _log.fine("New subpledge leader saved in db: "+getClanId());
  1339. }
  1340. catch (Exception e)
  1341. {
  1342. _log.log(Level.SEVERE, "Error saving new sub clan leader.", e);
  1343. }
  1344. finally
  1345. {
  1346. try { con.close(); } catch (Exception e) {}
  1347. }
  1348. }
  1349. private void restoreRankPrivs()
  1350. {
  1351. java.sql.Connection con = null;
  1352. try
  1353. {
  1354. // Retrieve all skills of this L2PcInstance from the database
  1355. con = L2DatabaseFactory.getInstance().getConnection();
  1356. PreparedStatement statement = con.prepareStatement("SELECT privs,rank,party FROM clan_privs WHERE clan_id=?");
  1357. statement.setInt(1, getClanId());
  1358. //_log.warning("clanPrivs restore for ClanId : "+getClanId());
  1359. ResultSet rset = statement.executeQuery();
  1360. // Go though the recordset of this SQL query
  1361. while (rset.next())
  1362. {
  1363. int rank = rset.getInt("rank");
  1364. //int party = rset.getInt("party");
  1365. int privileges = rset.getInt("privs");
  1366. // Create a SubPledge object for each record
  1367. if (rank == -1)
  1368. continue;
  1369. _privs.get(rank).setPrivs(privileges);
  1370. }
  1371. rset.close();
  1372. statement.close();
  1373. }
  1374. catch (Exception e)
  1375. {
  1376. _log.log(Level.SEVERE, "Error restoring clan privs by rank.", e);
  1377. }
  1378. finally
  1379. {
  1380. try { con.close(); } catch (Exception e) {}
  1381. }
  1382. }
  1383. public void initializePrivs()
  1384. {
  1385. RankPrivs privs;
  1386. for (int i=1; i < 10; i++)
  1387. {
  1388. privs = new RankPrivs(i, 0, CP_NOTHING);
  1389. _privs.put(i, privs);
  1390. }
  1391. }
  1392. public int getRankPrivs(int rank)
  1393. {
  1394. if (_privs.get(rank) != null)
  1395. return _privs.get(rank).getPrivs();
  1396. else
  1397. return CP_NOTHING;
  1398. }
  1399. public void setRankPrivs(int rank, int privs)
  1400. {
  1401. if (_privs.get(rank)!= null)
  1402. {
  1403. _privs.get(rank).setPrivs(privs);
  1404. java.sql.Connection con = null;
  1405. try
  1406. {
  1407. //_log.warning("requested store clan privs in db for rank: "+rank+", privs: "+privs);
  1408. // Retrieve all skills of this L2PcInstance from the database
  1409. con = L2DatabaseFactory.getInstance().getConnection();
  1410. PreparedStatement statement = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE privs = ?");
  1411. statement.setInt(1, getClanId());
  1412. statement.setInt(2, rank);
  1413. statement.setInt(3, 0);
  1414. statement.setInt(4, privs);
  1415. statement.setInt(5, privs);
  1416. statement.execute();
  1417. statement.close();
  1418. }
  1419. catch (Exception e)
  1420. {
  1421. _log.warning("Could not store clan privs for rank: " + e);
  1422. }
  1423. finally
  1424. {
  1425. try { con.close(); } catch (Exception e) {}
  1426. }
  1427. for (L2ClanMember cm : getMembers())
  1428. {
  1429. if (cm.isOnline())
  1430. if (cm.getPowerGrade() == rank)
  1431. if (cm.getPlayerInstance() != null)
  1432. {
  1433. cm.getPlayerInstance().setClanPrivileges(privs);
  1434. cm.getPlayerInstance().sendPacket(new UserInfo(cm.getPlayerInstance()));
  1435. }
  1436. }
  1437. broadcastClanStatus();
  1438. }
  1439. else
  1440. {
  1441. _privs.put(rank, new RankPrivs(rank, 0, privs));
  1442. java.sql.Connection con = null;
  1443. try
  1444. {
  1445. //_log.warning("requested store clan new privs in db for rank: "+rank);
  1446. // Retrieve all skills of this L2PcInstance from the database
  1447. con = L2DatabaseFactory.getInstance().getConnection();
  1448. PreparedStatement statement = con.prepareStatement("INSERT INTO clan_privs (clan_id,rank,party,privs) VALUES (?,?,?,?)");
  1449. statement.setInt(1, getClanId());
  1450. statement.setInt(2, rank);
  1451. statement.setInt(3, 0);
  1452. statement.setInt(4, privs);
  1453. statement.execute();
  1454. statement.close();
  1455. }
  1456. catch (Exception e)
  1457. {
  1458. _log.warning("Could not create new rank and store clan privs for rank: " + e);
  1459. }
  1460. finally
  1461. {
  1462. try { con.close(); } catch (Exception e) {}
  1463. }
  1464. }
  1465. }
  1466. /** used to retrieve all RankPrivs */
  1467. public final RankPrivs[] getAllRankPrivs()
  1468. {
  1469. if (_privs == null)
  1470. return new RankPrivs[0];
  1471. return _privs.values().toArray(new RankPrivs[_privs.values().size()]);
  1472. }
  1473. public int getLeaderSubPledge(int leaderId)
  1474. {
  1475. int id = 0;
  1476. for (SubPledge sp : _subPledges.values())
  1477. {
  1478. if (sp.getLeaderId() == 0) continue;
  1479. if (sp.getLeaderId() == leaderId)
  1480. id = sp.getId();
  1481. }
  1482. return id;
  1483. }
  1484. public void setReputationScore(int value, boolean save)
  1485. {
  1486. if(_reputationScore >= 0 && value < 0)
  1487. {
  1488. broadcastToOnlineMembers(new SystemMessage(SystemMessageId.REPUTATION_POINTS_0_OR_LOWER_CLAN_SKILLS_DEACTIVATED));
  1489. L2Skill[] skills = getAllSkills();
  1490. for (L2ClanMember member : _members.values())
  1491. {
  1492. if (member.isOnline() && member.getPlayerInstance() != null)
  1493. {
  1494. for (L2Skill sk : skills)
  1495. member.getPlayerInstance().removeSkill(sk, false);
  1496. }
  1497. }
  1498. }
  1499. else if(_reputationScore < 0 && value >= 0)
  1500. {
  1501. broadcastToOnlineMembers(new SystemMessage(SystemMessageId.CLAN_SKILLS_WILL_BE_ACTIVATED_SINCE_REPUTATION_IS_0_OR_HIGHER));
  1502. L2Skill[] skills = getAllSkills();
  1503. for (L2ClanMember member : _members.values())
  1504. {
  1505. if (member.isOnline() && member.getPlayerInstance() != null)
  1506. {
  1507. for (L2Skill sk : skills)
  1508. {
  1509. if(sk.getMinPledgeClass() <= member.getPlayerInstance().getPledgeClass())
  1510. member.getPlayerInstance().addSkill(sk, false);
  1511. }
  1512. }
  1513. }
  1514. }
  1515. _reputationScore = value;
  1516. if(_reputationScore > 100000000) _reputationScore = 100000000;
  1517. if(_reputationScore < -100000000) _reputationScore = -100000000;
  1518. if (save) updateClanInDB();
  1519. }
  1520. public int getReputationScore()
  1521. {
  1522. return _reputationScore;
  1523. }
  1524. public void setRank(int rank)
  1525. {
  1526. _rank = rank;
  1527. }
  1528. public int getRank()
  1529. {
  1530. return _rank;
  1531. }
  1532. public int getAuctionBiddedAt()
  1533. {
  1534. return _auctionBiddedAt;
  1535. }
  1536. public void setAuctionBiddedAt(int id, boolean storeInDb)
  1537. {
  1538. _auctionBiddedAt = id;
  1539. if(storeInDb)
  1540. {
  1541. java.sql.Connection con = null;
  1542. try
  1543. {
  1544. con = L2DatabaseFactory.getInstance().getConnection();
  1545. PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET auction_bid_at=? WHERE clan_id=?");
  1546. statement.setInt(1, id);
  1547. statement.setInt(2, getClanId());
  1548. statement.execute();
  1549. statement.close();
  1550. }
  1551. catch (Exception e)
  1552. {
  1553. _log.warning("Could not store auction for clan: " + e);
  1554. }
  1555. finally
  1556. {
  1557. try { con.close(); } catch (Exception e) {}
  1558. }
  1559. }
  1560. }
  1561. /**
  1562. * Checks if activeChar and target meet various conditions to join a clan
  1563. *
  1564. * @param activeChar
  1565. * @param target
  1566. * @param pledgeType
  1567. * @return
  1568. */
  1569. public boolean checkClanJoinCondition(L2PcInstance activeChar, L2PcInstance target, int pledgeType)
  1570. {
  1571. if (activeChar == null)
  1572. {
  1573. return false;
  1574. }
  1575. if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_JOIN_CLAN) != L2Clan.CP_CL_JOIN_CLAN)
  1576. {
  1577. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
  1578. return false;
  1579. }
  1580. if (target == null)
  1581. {
  1582. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_INVITED_THE_WRONG_TARGET));
  1583. return false;
  1584. }
  1585. if (activeChar.getObjectId() == target.getObjectId())
  1586. {
  1587. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_INVITE_YOURSELF));
  1588. return false;
  1589. }
  1590. if (getCharPenaltyExpiryTime() > System.currentTimeMillis())
  1591. {
  1592. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_MUST_WAIT_BEFORE_ACCEPTING_A_NEW_MEMBER);
  1593. sm.addString(target.getName());
  1594. activeChar.sendPacket(sm);
  1595. sm = null;
  1596. return false;
  1597. }
  1598. if (target.getClanId() != 0)
  1599. {
  1600. SystemMessage sm = new SystemMessage(SystemMessageId.S1_WORKING_WITH_ANOTHER_CLAN);
  1601. sm.addString(target.getName());
  1602. activeChar.sendPacket(sm);
  1603. sm = null;
  1604. return false;
  1605. }
  1606. if (target.getClanJoinExpiryTime() > System.currentTimeMillis())
  1607. {
  1608. SystemMessage sm = new SystemMessage(SystemMessageId.S1_MUST_WAIT_BEFORE_JOINING_ANOTHER_CLAN);
  1609. sm.addString(target.getName());
  1610. activeChar.sendPacket(sm);
  1611. sm = null;
  1612. return false;
  1613. }
  1614. if ((target.getLevel() > 40 || target.getClassId().level() >= 2) && pledgeType == -1)
  1615. {
  1616. SystemMessage sm = new SystemMessage(SystemMessageId.S1_DOESNOT_MEET_REQUIREMENTS_TO_JOIN_ACADEMY);
  1617. sm.addString(target.getName());
  1618. activeChar.sendPacket(sm);
  1619. sm = null;
  1620. activeChar.sendPacket(new SystemMessage(SystemMessageId.ACADEMY_REQUIREMENTS));
  1621. return false;
  1622. }
  1623. if (getSubPledgeMembersCount(pledgeType) >= getMaxNrOfMembers(pledgeType))
  1624. {
  1625. if (pledgeType == 0)
  1626. {
  1627. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CLAN_IS_FULL);
  1628. sm.addString(getName());
  1629. activeChar.sendPacket(sm);
  1630. sm = null;
  1631. }
  1632. else
  1633. {
  1634. activeChar.sendPacket(new SystemMessage(SystemMessageId.SUBCLAN_IS_FULL));
  1635. }
  1636. return false;
  1637. }
  1638. return true;
  1639. }
  1640. /**
  1641. * Checks if activeChar and target meet various conditions to join a clan
  1642. *
  1643. * @param activeChar
  1644. * @param target
  1645. * @return
  1646. */
  1647. public boolean checkAllyJoinCondition(L2PcInstance activeChar, L2PcInstance target)
  1648. {
  1649. if (activeChar == null)
  1650. {
  1651. return false;
  1652. }
  1653. if (activeChar.getAllyId() == 0 || !activeChar.isClanLeader() || activeChar.getClanId() != activeChar.getAllyId())
  1654. {
  1655. activeChar.sendPacket(new SystemMessage(SystemMessageId.FEATURE_ONLY_FOR_ALLIANCE_LEADER));
  1656. return false;
  1657. }
  1658. L2Clan leaderClan = activeChar.getClan();
  1659. if (leaderClan.getAllyPenaltyExpiryTime() > System.currentTimeMillis())
  1660. {
  1661. if (leaderClan.getAllyPenaltyType() == PENALTY_TYPE_DISMISS_CLAN)
  1662. {
  1663. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_INVITE_CLAN_WITHIN_1_DAY));
  1664. return false;
  1665. }
  1666. }
  1667. if (target == null)
  1668. {
  1669. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_INVITED_THE_WRONG_TARGET));
  1670. return false;
  1671. }
  1672. if (activeChar.getObjectId() == target.getObjectId())
  1673. {
  1674. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANNOT_INVITE_YOURSELF));
  1675. return false;
  1676. }
  1677. if (target.getClan() == null)
  1678. {
  1679. activeChar.sendPacket(new SystemMessage(SystemMessageId.TARGET_MUST_BE_IN_CLAN));
  1680. return false;
  1681. }
  1682. if (!target.isClanLeader())
  1683. {
  1684. SystemMessage sm = new SystemMessage(SystemMessageId.S1_IS_NOT_A_CLAN_LEADER);
  1685. sm.addString(target.getName());
  1686. activeChar.sendPacket(sm);
  1687. sm = null;
  1688. return false;
  1689. }
  1690. L2Clan targetClan = target.getClan();
  1691. if (target.getAllyId() != 0)
  1692. {
  1693. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CLAN_ALREADY_MEMBER_OF_S2_ALLIANCE);
  1694. sm.addString(targetClan.getName());
  1695. sm.addString(targetClan.getAllyName());
  1696. activeChar.sendPacket(sm);
  1697. sm = null;
  1698. return false;
  1699. }
  1700. if (targetClan.getAllyPenaltyExpiryTime() > System.currentTimeMillis())
  1701. {
  1702. if (targetClan.getAllyPenaltyType() == PENALTY_TYPE_CLAN_LEAVED)
  1703. {
  1704. SystemMessage sm = new SystemMessage(SystemMessageId.S1_CANT_ENTER_ALLIANCE_WITHIN_1_DAY);
  1705. sm.addString(target.getClan().getName());
  1706. sm.addString(target.getClan().getAllyName());
  1707. activeChar.sendPacket(sm);
  1708. sm = null;
  1709. return false;
  1710. }
  1711. if (targetClan.getAllyPenaltyType() == PENALTY_TYPE_CLAN_DISMISSED)
  1712. {
  1713. activeChar.sendPacket(new SystemMessage(SystemMessageId.CANT_ENTER_ALLIANCE_WITHIN_1_DAY));
  1714. return false;
  1715. }
  1716. }
  1717. if (activeChar.isInsideZone(L2Character.ZONE_SIEGE) && target.isInsideZone(L2Character.ZONE_SIEGE))
  1718. {
  1719. activeChar.sendPacket(new SystemMessage(SystemMessageId.OPPOSING_CLAN_IS_PARTICIPATING_IN_SIEGE));
  1720. return false;
  1721. }
  1722. if (leaderClan.isAtWarWith(targetClan.getClanId()))
  1723. {
  1724. activeChar.sendPacket(new SystemMessage(SystemMessageId.MAY_NOT_ALLY_CLAN_BATTLE));
  1725. return false;
  1726. }
  1727. int numOfClansInAlly = 0;
  1728. for (L2Clan clan : ClanTable.getInstance().getClans())
  1729. {
  1730. if (clan.getAllyId() == activeChar.getAllyId())
  1731. {
  1732. ++numOfClansInAlly;
  1733. }
  1734. }
  1735. if (numOfClansInAlly >= Config.ALT_MAX_NUM_OF_CLANS_IN_ALLY)
  1736. {
  1737. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EXCEEDED_THE_LIMIT));
  1738. return false;
  1739. }
  1740. return true;
  1741. }
  1742. public long getAllyPenaltyExpiryTime()
  1743. {
  1744. return _allyPenaltyExpiryTime;
  1745. }
  1746. public int getAllyPenaltyType()
  1747. {
  1748. return _allyPenaltyType;
  1749. }
  1750. public void setAllyPenaltyExpiryTime(long expiryTime, int penaltyType)
  1751. {
  1752. _allyPenaltyExpiryTime = expiryTime;
  1753. _allyPenaltyType = penaltyType;
  1754. }
  1755. public long getCharPenaltyExpiryTime()
  1756. {
  1757. return _charPenaltyExpiryTime;
  1758. }
  1759. public void setCharPenaltyExpiryTime(long time)
  1760. {
  1761. _charPenaltyExpiryTime = time;
  1762. }
  1763. public long getDissolvingExpiryTime()
  1764. {
  1765. return _dissolvingExpiryTime;
  1766. }
  1767. public void setDissolvingExpiryTime(long time)
  1768. {
  1769. _dissolvingExpiryTime = time;
  1770. }
  1771. public void createAlly(L2PcInstance player, String allyName)
  1772. {
  1773. if (null == player)
  1774. return;
  1775. if (Config.DEBUG)
  1776. _log.fine(player.getObjectId() + "(" + player.getName() + ") requested ally creation from ");
  1777. if (!player.isClanLeader())
  1778. {
  1779. player.sendPacket(new SystemMessage(SystemMessageId.ONLY_CLAN_LEADER_CREATE_ALLIANCE));
  1780. return;
  1781. }
  1782. if (getAllyId() != 0)
  1783. {
  1784. player.sendPacket(new SystemMessage(SystemMessageId.ALREADY_JOINED_ALLIANCE));
  1785. return;
  1786. }
  1787. if (getLevel() < 5)
  1788. {
  1789. player.sendPacket(new SystemMessage(SystemMessageId.TO_CREATE_AN_ALLY_YOU_CLAN_MUST_BE_LEVEL_5_OR_HIGHER));
  1790. return;
  1791. }
  1792. if (getAllyPenaltyExpiryTime() > System.currentTimeMillis())
  1793. {
  1794. if (getAllyPenaltyType() == L2Clan.PENALTY_TYPE_DISSOLVE_ALLY)
  1795. {
  1796. player.sendPacket(new SystemMessage(SystemMessageId.CANT_CREATE_ALLIANCE_10_DAYS_DISOLUTION));
  1797. return;
  1798. }
  1799. }
  1800. if (getDissolvingExpiryTime() > System.currentTimeMillis())
  1801. {
  1802. player.sendPacket(new SystemMessage(SystemMessageId.YOU_MAY_NOT_CREATE_ALLY_WHILE_DISSOLVING));
  1803. return;
  1804. }
  1805. if (!Util.isAlphaNumeric(allyName))
  1806. {
  1807. player.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_ALLIANCE_NAME));
  1808. return;
  1809. }
  1810. if (allyName.length() > 16 || allyName.length() < 2)
  1811. {
  1812. player.sendPacket(new SystemMessage(SystemMessageId.INCORRECT_ALLIANCE_NAME_LENGTH));
  1813. return;
  1814. }
  1815. if (ClanTable.getInstance().isAllyExists(allyName))
  1816. {
  1817. player.sendPacket(new SystemMessage(SystemMessageId.ALLIANCE_ALREADY_EXISTS));
  1818. return;
  1819. }
  1820. setAllyId(getClanId());
  1821. setAllyName(allyName.trim());
  1822. setAllyPenaltyExpiryTime(0, 0);
  1823. updateClanInDB();
  1824. player.sendPacket(new UserInfo(player));
  1825. //TODO: Need correct message id
  1826. player.sendMessage("Alliance " + allyName + " has been created.");
  1827. }
  1828. public void dissolveAlly(L2PcInstance player)
  1829. {
  1830. if (getAllyId() == 0)
  1831. {
  1832. player.sendPacket(new SystemMessage(SystemMessageId.NO_CURRENT_ALLIANCES));
  1833. return;
  1834. }
  1835. if (!player.isClanLeader() || getClanId() != getAllyId())
  1836. {
  1837. player.sendPacket(new SystemMessage(SystemMessageId.FEATURE_ONLY_FOR_ALLIANCE_LEADER));
  1838. return;
  1839. }
  1840. if (player.isInsideZone(L2Character.ZONE_SIEGE))
  1841. {
  1842. player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_DISSOLVE_ALLY_WHILE_IN_SIEGE));
  1843. return;
  1844. }
  1845. broadcastToOnlineAllyMembers(new SystemMessage(SystemMessageId.ALLIANCE_DISOLVED));
  1846. long currentTime = System.currentTimeMillis();
  1847. for (L2Clan clan : ClanTable.getInstance().getClans())
  1848. {
  1849. if (clan.getAllyId() == getAllyId() && clan.getClanId() != getClanId())
  1850. {
  1851. clan.setAllyId(0);
  1852. clan.setAllyName(null);
  1853. clan.setAllyPenaltyExpiryTime(0, 0);
  1854. clan.updateClanInDB();
  1855. }
  1856. }
  1857. setAllyId(0);
  1858. setAllyName(null);
  1859. setAllyPenaltyExpiryTime(
  1860. currentTime + Config.ALT_CREATE_ALLY_DAYS_WHEN_DISSOLVED * 86400000L,
  1861. L2Clan.PENALTY_TYPE_DISSOLVE_ALLY); //24*60*60*1000 = 86400000
  1862. updateClanInDB();
  1863. // The clan leader should take the XP penalty of a full death.
  1864. player.deathPenalty(false, false);
  1865. }
  1866. public void levelUpClan(L2PcInstance player)
  1867. {
  1868. if (!player.isClanLeader())
  1869. {
  1870. player.sendPacket(new SystemMessage(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT));
  1871. return;
  1872. }
  1873. if (System.currentTimeMillis() < getDissolvingExpiryTime())
  1874. {
  1875. player.sendPacket(new SystemMessage(SystemMessageId.CANNOT_RISE_LEVEL_WHILE_DISSOLUTION_IN_PROGRESS));
  1876. return;
  1877. }
  1878. boolean increaseClanLevel = false;
  1879. switch (getLevel())
  1880. {
  1881. case 0:
  1882. {
  1883. // Upgrade to 1
  1884. if (player.getSp() >= 20000 && player.getAdena() >= 650000)
  1885. {
  1886. if (player.reduceAdena("ClanLvl", 650000, player.getTarget(), true))
  1887. {
  1888. player.setSp(player.getSp() - 20000);
  1889. SystemMessage sp = new SystemMessage(SystemMessageId.SP_DECREASED_S1);
  1890. sp.addNumber(30000);
  1891. player.sendPacket(sp);
  1892. sp = null;
  1893. increaseClanLevel = true;
  1894. }
  1895. }
  1896. break;
  1897. }
  1898. case 1:
  1899. {
  1900. // Upgrade to 2
  1901. if (player.getSp() >= 100000 && player.getAdena() >= 2500000)
  1902. {
  1903. if (player.reduceAdena("ClanLvl", 2500000, player.getTarget(), true))
  1904. {
  1905. player.setSp(player.getSp() - 100000);
  1906. SystemMessage sp = new SystemMessage(SystemMessageId.SP_DECREASED_S1);
  1907. sp.addNumber(150000);
  1908. player.sendPacket(sp);
  1909. sp = null;
  1910. increaseClanLevel = true;
  1911. }
  1912. }
  1913. break;
  1914. }
  1915. case 2:
  1916. {
  1917. // Upgrade to 3
  1918. if (player.getSp() >= 350000 && player.getInventory().getItemByItemId(1419) != null)
  1919. {
  1920. // itemId 1419 == Blood Mark
  1921. if (player.destroyItemByItemId("ClanLvl", 1419, 1, player.getTarget(), false))
  1922. {
  1923. player.setSp(player.getSp() - 350000);
  1924. SystemMessage sp = new SystemMessage(SystemMessageId.SP_DECREASED_S1);
  1925. sp.addNumber(500000);
  1926. player.sendPacket(sp);
  1927. sp = null;
  1928. SystemMessage sm = new SystemMessage(SystemMessageId.S2_S1_DISAPPEARED);
  1929. sm.addItemName(1419);
  1930. sm.addNumber(1);
  1931. player.sendPacket(sm);
  1932. sm = null;
  1933. increaseClanLevel = true;
  1934. }
  1935. }
  1936. break;
  1937. }
  1938. case 3:
  1939. {
  1940. // Upgrade to 4
  1941. if (player.getSp() >= 1000000 && player.getInventory().getItemByItemId(3874) != null)
  1942. {
  1943. // itemId 3874 == Alliance Manifesto
  1944. if (player.destroyItemByItemId("ClanLvl", 3874, 1, player.getTarget(), false))
  1945. {
  1946. player.setSp(player.getSp() - 1000000);
  1947. SystemMessage sp = new SystemMessage(SystemMessageId.SP_DECREASED_S1);
  1948. sp.addNumber(1400000);
  1949. player.sendPacket(sp);
  1950. sp = null;
  1951. SystemMessage sm = new SystemMessage(SystemMessageId.S2_S1_DISAPPEARED);
  1952. sm.addItemName(3874);
  1953. sm.addNumber(1);
  1954. player.sendPacket(sm);
  1955. sm = null;
  1956. increaseClanLevel = true;
  1957. }
  1958. }
  1959. break;
  1960. }
  1961. case 4:
  1962. {
  1963. // Upgrade to 5
  1964. if (player.getSp() >= 2500000 && player.getInventory().getItemByItemId(3870) != null)
  1965. {
  1966. // itemId 3870 == Seal of Aspiration
  1967. if (player.destroyItemByItemId("ClanLvl", 3870, 1, player.getTarget(), false))
  1968. {
  1969. player.setSp(player.getSp() - 2500000);
  1970. SystemMessage sp = new SystemMessage(SystemMessageId.SP_DECREASED_S1);
  1971. sp.addNumber(3500000);
  1972. player.sendPacket(sp);
  1973. sp = null;
  1974. SystemMessage sm = new SystemMessage(SystemMessageId.S2_S1_DISAPPEARED);
  1975. sm.addItemName(3870);
  1976. sm.addNumber(1);
  1977. player.sendPacket(sm);
  1978. sm = null;
  1979. increaseClanLevel = true;
  1980. }
  1981. }
  1982. break;
  1983. }
  1984. case 5:
  1985. // Upgrade to 6
  1986. if(getReputationScore() >= 10000 && getMembersCount() >= 30)
  1987. {
  1988. setReputationScore(getReputationScore() - 10000, true);
  1989. SystemMessage cr = new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP);
  1990. cr.addNumber(10000);
  1991. player.sendPacket(cr);
  1992. cr = null;
  1993. increaseClanLevel = true;
  1994. }
  1995. break;
  1996. case 6:
  1997. // Upgrade to 7
  1998. if(getReputationScore() >= 20000 && getMembersCount() >= 80)
  1999. {
  2000. setReputationScore(getReputationScore() - 20000, true);
  2001. SystemMessage cr = new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP);
  2002. cr.addNumber(20000);
  2003. player.sendPacket(cr);
  2004. cr = null;
  2005. increaseClanLevel = true;
  2006. }
  2007. break;
  2008. case 7:
  2009. // Upgrade to 8
  2010. if(getReputationScore() >= 40000 && getMembersCount() >= 120)
  2011. {
  2012. setReputationScore(getReputationScore() - 40000, true);
  2013. SystemMessage cr = new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP);
  2014. cr.addNumber(40000);
  2015. player.sendPacket(cr);
  2016. cr = null;
  2017. increaseClanLevel = true;
  2018. }
  2019. break;
  2020. case 8:
  2021. // Upgrade to 9
  2022. if(getReputationScore() >= 40000 && player.getInventory().getItemByItemId(9910) != null && getMembersCount() >= 120)
  2023. {
  2024. // itemId 9910 == Blood Oath
  2025. if (player.destroyItemByItemId("ClanLvl", 9910, 150, player.getTarget(), false))
  2026. {
  2027. setReputationScore(getReputationScore() - 40000, true);
  2028. SystemMessage cr = new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP);
  2029. cr.addNumber(40000);
  2030. player.sendPacket(cr);
  2031. cr = null;
  2032. SystemMessage sm = new SystemMessage(SystemMessageId.S2_S1_DISAPPEARED);
  2033. sm.addItemName(9910);
  2034. sm.addNumber(150);
  2035. player.sendPacket(sm);
  2036. increaseClanLevel = true;
  2037. }
  2038. }
  2039. break;
  2040. case 9:
  2041. // Upgrade to 10
  2042. if(getReputationScore() >= 40000 && player.getInventory().getItemByItemId(9911) != null && getMembersCount() >= 140)
  2043. {
  2044. // itemId 9911 == Blood Alliance
  2045. if (player.destroyItemByItemId("ClanLvl", 9911, 5, player.getTarget(), false))
  2046. {
  2047. setReputationScore(getReputationScore() - 40000, true);
  2048. SystemMessage cr = new SystemMessage(SystemMessageId.S1_DEDUCTED_FROM_CLAN_REP);
  2049. cr.addNumber(40000);
  2050. player.sendPacket(cr);
  2051. cr = null;
  2052. SystemMessage sm = new SystemMessage(SystemMessageId.S2_S1_DISAPPEARED);
  2053. sm.addItemName(9911);
  2054. sm.addNumber(5);
  2055. player.sendPacket(sm);
  2056. increaseClanLevel = true;
  2057. }
  2058. }
  2059. break;
  2060. default:
  2061. return;
  2062. }
  2063. if (!increaseClanLevel)
  2064. {
  2065. SystemMessage sm = new SystemMessage(SystemMessageId.FAILED_TO_INCREASE_CLAN_LEVEL);
  2066. player.sendPacket(sm);
  2067. return;
  2068. }
  2069. // the player should know that he has less sp now :p
  2070. StatusUpdate su = new StatusUpdate(player.getObjectId());
  2071. su.addAttribute(StatusUpdate.SP, player.getSp());
  2072. player.sendPacket(su);
  2073. ItemList il = new ItemList(player, false);
  2074. player.sendPacket(il);
  2075. changeLevel(getLevel() + 1);
  2076. }
  2077. public void changeLevel(int level)
  2078. {
  2079. java.sql.Connection con = null;
  2080. try
  2081. {
  2082. con = L2DatabaseFactory.getInstance().getConnection();
  2083. PreparedStatement statement = con.prepareStatement("UPDATE clan_data SET clan_level = ? WHERE clan_id = ?");
  2084. statement.setInt(1, level);
  2085. statement.setInt(2, getClanId());
  2086. statement.execute();
  2087. statement.close();
  2088. con.close();
  2089. }
  2090. catch (Exception e)
  2091. {
  2092. _log.warning("could not increase clan level:" + e);
  2093. }
  2094. finally
  2095. {
  2096. try { con.close(); } catch (Exception e) {}
  2097. }
  2098. setLevel(level);
  2099. if (getLeader().isOnline())
  2100. {
  2101. L2PcInstance leader = getLeader().getPlayerInstance();
  2102. if (4 < level)
  2103. {
  2104. SiegeManager.getInstance().addSiegeSkills(leader);
  2105. }
  2106. else if (5 > level)
  2107. {
  2108. SiegeManager.getInstance().removeSiegeSkills(leader);
  2109. }
  2110. if (4 < level)
  2111. {
  2112. leader.sendPacket(new SystemMessage(SystemMessageId.CLAN_CAN_ACCUMULATE_CLAN_REPUTATION_POINTS));
  2113. }
  2114. }
  2115. // notify all the members about it
  2116. broadcastToOnlineMembers(new SystemMessage(SystemMessageId.CLAN_LEVEL_INCREASED));
  2117. broadcastToOnlineMembers(new PledgeShowInfoUpdate(this));
  2118. /*
  2119. * Micht :
  2120. * - use PledgeShowInfoUpdate instead of PledgeStatusChanged
  2121. * to update clan level ingame
  2122. * - remove broadcastClanStatus() to avoid members duplication
  2123. */
  2124. //clan.broadcastToOnlineMembers(new PledgeStatusChanged(clan));
  2125. //clan.broadcastClanStatus();
  2126. }
  2127. }