Wedding.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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.handler.voicedcommandhandlers;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.logging.Logger;
  19. import net.sf.l2j.Config;
  20. import net.sf.l2j.L2DatabaseFactory;
  21. import net.sf.l2j.gameserver.GameTimeController;
  22. import net.sf.l2j.gameserver.SevenSigns;
  23. import net.sf.l2j.gameserver.ThreadPoolManager;
  24. import net.sf.l2j.gameserver.ai.CtrlIntention;
  25. import net.sf.l2j.gameserver.datatables.SkillTable;
  26. import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  27. import net.sf.l2j.gameserver.instancemanager.CastleManager;
  28. import net.sf.l2j.gameserver.instancemanager.CoupleManager;
  29. import net.sf.l2j.gameserver.instancemanager.GrandBossManager;
  30. import net.sf.l2j.gameserver.model.L2Skill;
  31. import net.sf.l2j.gameserver.model.L2World;
  32. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  33. import net.sf.l2j.gameserver.model.entity.TvTEvent;
  34. import net.sf.l2j.gameserver.network.SystemMessageId;
  35. import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  36. import net.sf.l2j.gameserver.network.serverpackets.ConfirmDlg;
  37. import net.sf.l2j.gameserver.network.serverpackets.MagicSkillUse;
  38. import net.sf.l2j.gameserver.network.serverpackets.SetupGauge;
  39. import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
  40. import net.sf.l2j.gameserver.util.Broadcast;
  41. /**
  42. * @author evill33t
  43. *
  44. */
  45. public class Wedding implements IVoicedCommandHandler
  46. {
  47. static final Logger _log = Logger.getLogger(Wedding.class.getName());
  48. private static String[] _voicedCommands =
  49. {
  50. "divorce",
  51. "engage",
  52. "gotolove"
  53. };
  54. /**
  55. *
  56. * @see net.sf.l2j.gameserver.handler.IVoicedCommandHandler#useVoicedCommand(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance, java.lang.String)
  57. */
  58. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  59. {
  60. if (command.startsWith("engage"))
  61. return engage(activeChar);
  62. else if (command.startsWith("divorce"))
  63. return divorce(activeChar);
  64. else if (command.startsWith("gotolove"))
  65. return goToLove(activeChar);
  66. return false;
  67. }
  68. public boolean divorce(L2PcInstance activeChar)
  69. {
  70. if (activeChar.getPartnerId() == 0)
  71. return false;
  72. int _partnerId = activeChar.getPartnerId();
  73. int _coupleId = activeChar.getCoupleId();
  74. int AdenaAmount = 0;
  75. if (activeChar.isMarried())
  76. {
  77. activeChar.sendMessage("You are now divorced.");
  78. AdenaAmount = (activeChar.getAdena() / 100) * Config.L2JMOD_WEDDING_DIVORCE_COSTS;
  79. activeChar.getInventory().reduceAdena("Wedding", AdenaAmount, activeChar, null);
  80. }
  81. else
  82. activeChar.sendMessage("You have broken up as a couple.");
  83. L2PcInstance partner;
  84. partner = (L2PcInstance) L2World.getInstance().findObject(_partnerId);
  85. if (partner != null)
  86. {
  87. partner.setPartnerId(0);
  88. if (partner.isMarried())
  89. partner.sendMessage("Your spouse has decided to divorce you.");
  90. else
  91. partner.sendMessage("Your fiance has decided to break the engagement with you.");
  92. // give adena
  93. if (AdenaAmount > 0)
  94. partner.addAdena("WEDDING", AdenaAmount, null, false);
  95. }
  96. CoupleManager.getInstance().deleteCouple(_coupleId);
  97. return true;
  98. }
  99. public boolean engage(L2PcInstance activeChar)
  100. {
  101. // check target
  102. if (activeChar.getTarget() == null)
  103. {
  104. activeChar.sendMessage("You have no one targeted.");
  105. return false;
  106. }
  107. // check if target is a l2pcinstance
  108. if (!(activeChar.getTarget() instanceof L2PcInstance))
  109. {
  110. activeChar.sendMessage("You can only ask another player to engage you.");
  111. return false;
  112. }
  113. // check if player is already engaged
  114. if (activeChar.getPartnerId() != 0)
  115. {
  116. activeChar.sendMessage("You are already engaged.");
  117. if (Config.L2JMOD_WEDDING_PUNISH_INFIDELITY)
  118. {
  119. activeChar.startAbnormalEffect((short) 0x2000); // give player a Big Head
  120. // lets recycle the sevensigns debuffs
  121. int skillId;
  122. int skillLevel = 1;
  123. if (activeChar.getLevel() > 40)
  124. skillLevel = 2;
  125. if (activeChar.isMageClass())
  126. skillId = 4361;
  127. else
  128. skillId = 4362;
  129. L2Skill skill = SkillTable.getInstance().getInfo(skillId, skillLevel);
  130. if (activeChar.getFirstEffect(skill) == null)
  131. {
  132. skill.getEffects(activeChar, activeChar);
  133. SystemMessage sm = new SystemMessage(SystemMessageId.YOU_FEEL_S1_EFFECT);
  134. sm.addSkillName(skill);
  135. activeChar.sendPacket(sm);
  136. }
  137. }
  138. return false;
  139. }
  140. L2PcInstance ptarget = (L2PcInstance) activeChar.getTarget();
  141. // check if player target himself
  142. if (ptarget.getObjectId() == activeChar.getObjectId())
  143. {
  144. activeChar.sendMessage("Is there something wrong with you, are you trying to go out with youself?");
  145. return false;
  146. }
  147. if (ptarget.isMarried())
  148. {
  149. activeChar.sendMessage("Player already married.");
  150. return false;
  151. }
  152. if (ptarget.isEngageRequest())
  153. {
  154. activeChar.sendMessage("Player already asked by someone else.");
  155. return false;
  156. }
  157. if (ptarget.getPartnerId() != 0)
  158. {
  159. activeChar.sendMessage("Player already engaged with someone else.");
  160. return false;
  161. }
  162. if (ptarget.getAppearance().getSex() == activeChar.getAppearance().getSex() && !Config.L2JMOD_WEDDING_SAMESEX)
  163. {
  164. activeChar.sendMessage("Gay marriage is not allowed on this server!");
  165. return false;
  166. }
  167. // check if target has player on friendlist
  168. boolean FoundOnFriendList = false;
  169. int objectId;
  170. java.sql.Connection con = null;
  171. try
  172. {
  173. con = L2DatabaseFactory.getInstance().getConnection();
  174. PreparedStatement statement;
  175. statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=?");
  176. statement.setInt(1, ptarget.getObjectId());
  177. ResultSet rset = statement.executeQuery();
  178. while (rset.next())
  179. {
  180. objectId = rset.getInt("friendId");
  181. if (objectId == activeChar.getObjectId())
  182. FoundOnFriendList = true;
  183. }
  184. statement.close();
  185. }
  186. catch (Exception e)
  187. {
  188. _log.warning("could not read friend data:" + e);
  189. }
  190. finally
  191. {
  192. try
  193. {
  194. con.close();
  195. }
  196. catch (Exception e)
  197. {
  198. }
  199. }
  200. if (!FoundOnFriendList)
  201. {
  202. activeChar.sendMessage("The player you want to ask is not on your friends list, you must first be on each others friends list before you choose to engage.");
  203. return false;
  204. }
  205. ptarget.setEngageRequest(true, activeChar.getObjectId());
  206. // $s1
  207. ConfirmDlg dlg = new ConfirmDlg(SystemMessageId.S1.getId()).addString(activeChar.getName() + " is asking to engage you. Do you want to start a new relationship?");
  208. ptarget.sendPacket(dlg);
  209. return true;
  210. }
  211. public boolean goToLove(L2PcInstance activeChar)
  212. {
  213. if (!activeChar.isMarried())
  214. {
  215. activeChar.sendMessage("You're not married.");
  216. return false;
  217. }
  218. if (activeChar.getPartnerId() == 0)
  219. {
  220. activeChar.sendMessage("Couldn't find your fiance in the Database - Inform a Gamemaster.");
  221. _log.severe("Married but couldn't find parter for " + activeChar.getName());
  222. return false;
  223. }
  224. if (GrandBossManager.getInstance().getZone(activeChar) != null)
  225. {
  226. activeChar.sendMessage("You are inside a Boss Zone.");
  227. return false;
  228. }
  229. L2PcInstance partner;
  230. partner = (L2PcInstance) L2World.getInstance().findObject(activeChar.getPartnerId());
  231. if (partner == null)
  232. {
  233. activeChar.sendMessage("Your partner is not online.");
  234. return false;
  235. }
  236. else if (partner.isInJail())
  237. {
  238. activeChar.sendMessage("Your partner is in Jail.");
  239. return false;
  240. }
  241. else if (GrandBossManager.getInstance().getZone(partner) != null)
  242. {
  243. activeChar.sendMessage("Your partner is inside a Boss Zone.");
  244. return false;
  245. }
  246. else if (partner.isInOlympiadMode())
  247. {
  248. activeChar.sendMessage("Your partner is in the Olympiad now.");
  249. return false;
  250. }
  251. else if (partner.atEvent)
  252. {
  253. activeChar.sendMessage("Your partner is in an event.");
  254. return false;
  255. }
  256. else if (partner.isInDuel())
  257. {
  258. activeChar.sendMessage("Your partner is in a duel.");
  259. return false;
  260. }
  261. else if (partner.isFestivalParticipant())
  262. {
  263. activeChar.sendMessage("Your partner is in a festival.");
  264. return false;
  265. }
  266. else if (partner.isInParty() && partner.getParty().isInDimensionalRift())
  267. {
  268. activeChar.sendMessage("Your partner is in dimensional rift.");
  269. return false;
  270. }
  271. else if (partner.inObserverMode())
  272. {
  273. activeChar.sendMessage("Your partner is in the observation.");
  274. return false;
  275. }
  276. else if (partner.getClan() != null && CastleManager.getInstance().getCastleByOwner(partner.getClan()) != null && CastleManager.getInstance().getCastleByOwner(partner.getClan()).getSiege().getIsInProgress())
  277. {
  278. activeChar.sendMessage("Your partner is in siege, you can't go to your partner.");
  279. return false;
  280. }
  281. else if (partner.isIn7sDungeon() && !activeChar.isIn7sDungeon())
  282. {
  283. int playerCabal = SevenSigns.getInstance().getPlayerCabal(activeChar);
  284. boolean isSealValidationPeriod = SevenSigns.getInstance().isSealValidationPeriod();
  285. int compWinner = SevenSigns.getInstance().getCabalHighestScore();
  286. if (isSealValidationPeriod)
  287. {
  288. if (playerCabal != compWinner)
  289. {
  290. activeChar.sendMessage("Your Partner is in a Seven Signs Dungeon and you are not in the winner Cabal!");
  291. return false;
  292. }
  293. }
  294. else
  295. {
  296. if (playerCabal == SevenSigns.CABAL_NULL)
  297. {
  298. activeChar.sendMessage("Your Partner is in a Seven Signs Dungeon and you are not registered!");
  299. return false;
  300. }
  301. }
  302. }
  303. else if (!TvTEvent.onEscapeUse(partner.getObjectId()))
  304. {
  305. activeChar.sendMessage("Your partner is in an event.");
  306. return false;
  307. }
  308. else if (activeChar.isInJail())
  309. {
  310. activeChar.sendMessage("You are in Jail!");
  311. return false;
  312. }
  313. else if (activeChar.isInOlympiadMode())
  314. {
  315. activeChar.sendMessage("You are in the Olympiad now.");
  316. return false;
  317. }
  318. else if (activeChar.atEvent)
  319. {
  320. activeChar.sendMessage("You are in an event.");
  321. return false;
  322. }
  323. else if (activeChar.isInDuel())
  324. {
  325. activeChar.sendMessage("You are in a duel!");
  326. return false;
  327. }
  328. else if (activeChar.inObserverMode())
  329. {
  330. activeChar.sendMessage("You are in the observation.");
  331. return false;
  332. }
  333. else if (activeChar.getClan() != null && CastleManager.getInstance().getCastleByOwner(activeChar.getClan()) != null && CastleManager.getInstance().getCastleByOwner(activeChar.getClan()).getSiege().getIsInProgress())
  334. {
  335. activeChar.sendMessage("You are in siege, you can't go to your partner.");
  336. return false;
  337. }
  338. else if (activeChar.isFestivalParticipant())
  339. {
  340. activeChar.sendMessage("You are in a festival.");
  341. return false;
  342. }
  343. else if (activeChar.isInParty() && activeChar.getParty().isInDimensionalRift())
  344. {
  345. activeChar.sendMessage("You are in the dimensional rift.");
  346. return false;
  347. }
  348. // Thanks nbd
  349. else if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  350. {
  351. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  352. return false;
  353. }
  354. int teleportTimer = Config.L2JMOD_WEDDING_TELEPORT_DURATION * 1000;
  355. activeChar.sendMessage("After " + teleportTimer / 60000 + " min. you will be teleported to your fiance.");
  356. activeChar.getInventory().reduceAdena("Wedding", Config.L2JMOD_WEDDING_TELEPORT_PRICE, activeChar, null);
  357. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  358. //SoE Animation section
  359. activeChar.setTarget(activeChar);
  360. activeChar.disableAllSkills();
  361. MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, teleportTimer, 0);
  362. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 810000/*900*/);
  363. SetupGauge sg = new SetupGauge(0, teleportTimer);
  364. activeChar.sendPacket(sg);
  365. //End SoE Animation section
  366. EscapeFinalizer ef = new EscapeFinalizer(activeChar, partner.getX(), partner.getY(), partner.getZ(), partner.isIn7sDungeon());
  367. // continue execution later
  368. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, teleportTimer));
  369. activeChar.setSkillCastEndTime(10 + GameTimeController.getGameTicks() + teleportTimer / GameTimeController.MILLIS_IN_TICK);
  370. return true;
  371. }
  372. static class EscapeFinalizer implements Runnable
  373. {
  374. private L2PcInstance _activeChar;
  375. private int _partnerx;
  376. private int _partnery;
  377. private int _partnerz;
  378. private boolean _to7sDungeon;
  379. EscapeFinalizer(L2PcInstance activeChar, int x, int y, int z, boolean to7sDungeon)
  380. {
  381. _activeChar = activeChar;
  382. _partnerx = x;
  383. _partnery = y;
  384. _partnerz = z;
  385. _to7sDungeon = to7sDungeon;
  386. }
  387. public void run()
  388. {
  389. if (_activeChar.isDead())
  390. return;
  391. _activeChar.setIsIn7sDungeon(_to7sDungeon);
  392. _activeChar.enableAllSkills();
  393. try
  394. {
  395. _activeChar.teleToLocation(_partnerx, _partnery, _partnerz);
  396. }
  397. catch (Throwable e)
  398. {
  399. _log.severe(e.toString());
  400. }
  401. }
  402. }
  403. /**
  404. *
  405. * @see net.sf.l2j.gameserver.handler.IVoicedCommandHandler#getVoicedCommandList()
  406. */
  407. public String[] getVoicedCommandList()
  408. {
  409. return _voicedCommands;
  410. }
  411. }