L2Clan.java 76 KB

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