Wedding.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.voicedcommandhandlers;
  20. import java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import java.util.logging.Level;
  24. import java.util.logging.Logger;
  25. import com.l2jserver.Config;
  26. import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
  27. import com.l2jserver.gameserver.GameTimeController;
  28. import com.l2jserver.gameserver.SevenSigns;
  29. import com.l2jserver.gameserver.ThreadPoolManager;
  30. import com.l2jserver.gameserver.ai.CtrlIntention;
  31. import com.l2jserver.gameserver.datatables.SkillData;
  32. import com.l2jserver.gameserver.enums.PlayerAction;
  33. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  34. import com.l2jserver.gameserver.instancemanager.CoupleManager;
  35. import com.l2jserver.gameserver.instancemanager.GrandBossManager;
  36. import com.l2jserver.gameserver.instancemanager.SiegeManager;
  37. import com.l2jserver.gameserver.model.L2World;
  38. import com.l2jserver.gameserver.model.Location;
  39. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  40. import com.l2jserver.gameserver.model.entity.L2Event;
  41. import com.l2jserver.gameserver.model.entity.TvTEvent;
  42. import com.l2jserver.gameserver.model.skills.AbnormalVisualEffect;
  43. import com.l2jserver.gameserver.model.skills.Skill;
  44. import com.l2jserver.gameserver.model.zone.ZoneId;
  45. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  46. import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
  47. import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
  48. import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
  49. import com.l2jserver.gameserver.util.Broadcast;
  50. /**
  51. * Wedding voiced commands handler.
  52. * @author evill33t
  53. */
  54. public class Wedding implements IVoicedCommandHandler
  55. {
  56. static final Logger _log = Logger.getLogger(Wedding.class.getName());
  57. private static final String[] _voicedCommands =
  58. {
  59. "divorce",
  60. "engage",
  61. "gotolove"
  62. };
  63. @Override
  64. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
  65. {
  66. if (activeChar == null)
  67. {
  68. return false;
  69. }
  70. if (command.startsWith("engage"))
  71. {
  72. return engage(activeChar);
  73. }
  74. else if (command.startsWith("divorce"))
  75. {
  76. return divorce(activeChar);
  77. }
  78. else if (command.startsWith("gotolove"))
  79. {
  80. return goToLove(activeChar);
  81. }
  82. return false;
  83. }
  84. public boolean divorce(L2PcInstance activeChar)
  85. {
  86. if (activeChar.getPartnerId() == 0)
  87. {
  88. return false;
  89. }
  90. int _partnerId = activeChar.getPartnerId();
  91. int _coupleId = activeChar.getCoupleId();
  92. long AdenaAmount = 0;
  93. if (activeChar.isMarried())
  94. {
  95. activeChar.sendMessage("You are now divorced.");
  96. AdenaAmount = (activeChar.getAdena() / 100) * Config.L2JMOD_WEDDING_DIVORCE_COSTS;
  97. activeChar.getInventory().reduceAdena("Wedding", AdenaAmount, activeChar, null);
  98. }
  99. else
  100. {
  101. activeChar.sendMessage("You have broken up as a couple.");
  102. }
  103. final L2PcInstance partner = L2World.getInstance().getPlayer(_partnerId);
  104. if (partner != null)
  105. {
  106. partner.setPartnerId(0);
  107. if (partner.isMarried())
  108. {
  109. partner.sendMessage("Your spouse has decided to divorce you.");
  110. }
  111. else
  112. {
  113. partner.sendMessage("Your fiance has decided to break the engagement with you.");
  114. }
  115. // give adena
  116. if (AdenaAmount > 0)
  117. {
  118. partner.addAdena("WEDDING", AdenaAmount, null, false);
  119. }
  120. }
  121. CoupleManager.getInstance().deleteCouple(_coupleId);
  122. return true;
  123. }
  124. public boolean engage(L2PcInstance activeChar)
  125. {
  126. if (activeChar.getTarget() == null)
  127. {
  128. activeChar.sendMessage("You have no one targeted.");
  129. return false;
  130. }
  131. else if (!(activeChar.getTarget() instanceof L2PcInstance))
  132. {
  133. activeChar.sendMessage("You can only ask another player to engage you.");
  134. return false;
  135. }
  136. else if (activeChar.getPartnerId() != 0)
  137. {
  138. activeChar.sendMessage("You are already engaged.");
  139. if (Config.L2JMOD_WEDDING_PUNISH_INFIDELITY)
  140. {
  141. activeChar.startAbnormalVisualEffect(true, AbnormalVisualEffect.BIG_HEAD); // give player a Big Head
  142. // lets recycle the sevensigns debuffs
  143. int skillId;
  144. int skillLevel = 1;
  145. if (activeChar.getLevel() > 40)
  146. {
  147. skillLevel = 2;
  148. }
  149. if (activeChar.isMageClass())
  150. {
  151. skillId = 4362;
  152. }
  153. else
  154. {
  155. skillId = 4361;
  156. }
  157. final Skill skill = SkillData.getInstance().getSkill(skillId, skillLevel);
  158. if (!activeChar.isAffectedBySkill(skillId))
  159. {
  160. skill.applyEffects(activeChar, activeChar);
  161. }
  162. }
  163. return false;
  164. }
  165. final L2PcInstance ptarget = (L2PcInstance) activeChar.getTarget();
  166. // check if player target himself
  167. if (ptarget.getObjectId() == activeChar.getObjectId())
  168. {
  169. activeChar.sendMessage("Is there something wrong with you, are you trying to go out with youself?");
  170. return false;
  171. }
  172. if (ptarget.isMarried())
  173. {
  174. activeChar.sendMessage("Player already married.");
  175. return false;
  176. }
  177. if (ptarget.isEngageRequest())
  178. {
  179. activeChar.sendMessage("Player already asked by someone else.");
  180. return false;
  181. }
  182. if (ptarget.getPartnerId() != 0)
  183. {
  184. activeChar.sendMessage("Player already engaged with someone else.");
  185. return false;
  186. }
  187. if ((ptarget.getAppearance().getSex() == activeChar.getAppearance().getSex()) && !Config.L2JMOD_WEDDING_SAMESEX)
  188. {
  189. activeChar.sendMessage("Gay marriage is not allowed on this server!");
  190. return false;
  191. }
  192. // Check if target has player on friend list
  193. boolean foundOnFriendList = false;
  194. try (Connection con = ConnectionFactory.getInstance().getConnection();
  195. PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=?"))
  196. {
  197. statement.setInt(1, ptarget.getObjectId());
  198. try (ResultSet rset = statement.executeQuery())
  199. {
  200. while (rset.next())
  201. {
  202. if (rset.getInt("friendId") == activeChar.getObjectId())
  203. {
  204. foundOnFriendList = true;
  205. }
  206. }
  207. }
  208. }
  209. catch (Exception e)
  210. {
  211. _log.warning("could not read friend data:" + e);
  212. }
  213. if (!foundOnFriendList)
  214. {
  215. 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.");
  216. return false;
  217. }
  218. ptarget.setEngageRequest(true, activeChar.getObjectId());
  219. ptarget.addAction(PlayerAction.USER_ENGAGE);
  220. final ConfirmDlg dlg = new ConfirmDlg(activeChar.getName() + " is asking to engage you. Do you want to start a new relationship?");
  221. dlg.addTime(15 * 1000);
  222. ptarget.sendPacket(dlg);
  223. return true;
  224. }
  225. public boolean goToLove(L2PcInstance activeChar)
  226. {
  227. if (!activeChar.isMarried())
  228. {
  229. activeChar.sendMessage("You're not married.");
  230. return false;
  231. }
  232. if (activeChar.getPartnerId() == 0)
  233. {
  234. activeChar.sendMessage("Couldn't find your fiance in the Database - Inform a Gamemaster.");
  235. _log.severe("Married but couldn't find parter for " + activeChar.getName());
  236. return false;
  237. }
  238. if (GrandBossManager.getInstance().getZone(activeChar) != null)
  239. {
  240. activeChar.sendMessage("You are inside a Boss Zone.");
  241. return false;
  242. }
  243. if (activeChar.isCombatFlagEquipped())
  244. {
  245. activeChar.sendMessage("While you are holding a Combat Flag or Territory Ward you can't go to your love!");
  246. return false;
  247. }
  248. if (activeChar.isCursedWeaponEquipped())
  249. {
  250. activeChar.sendMessage("While you are holding a Cursed Weapon you can't go to your love!");
  251. return false;
  252. }
  253. if (GrandBossManager.getInstance().getZone(activeChar) != null)
  254. {
  255. activeChar.sendMessage("You are inside a Boss Zone.");
  256. return false;
  257. }
  258. if (activeChar.isJailed())
  259. {
  260. activeChar.sendMessage("You are in Jail!");
  261. return false;
  262. }
  263. if (activeChar.isInOlympiadMode())
  264. {
  265. activeChar.sendMessage("You are in the Olympiad now.");
  266. return false;
  267. }
  268. if (L2Event.isParticipant(activeChar))
  269. {
  270. activeChar.sendMessage("You are in an event.");
  271. return false;
  272. }
  273. if (activeChar.isInDuel())
  274. {
  275. activeChar.sendMessage("You are in a duel!");
  276. return false;
  277. }
  278. if (activeChar.inObserverMode())
  279. {
  280. activeChar.sendMessage("You are in the observation.");
  281. return false;
  282. }
  283. if ((SiegeManager.getInstance().getSiege(activeChar) != null) && SiegeManager.getInstance().getSiege(activeChar).isInProgress())
  284. {
  285. activeChar.sendMessage("You are in a siege, you cannot go to your partner.");
  286. return false;
  287. }
  288. if (activeChar.isFestivalParticipant())
  289. {
  290. activeChar.sendMessage("You are in a festival.");
  291. return false;
  292. }
  293. if (activeChar.isInParty() && activeChar.getParty().isInDimensionalRift())
  294. {
  295. activeChar.sendMessage("You are in the dimensional rift.");
  296. return false;
  297. }
  298. // Thanks nbd
  299. if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  300. {
  301. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  302. return false;
  303. }
  304. if (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
  305. {
  306. activeChar.sendMessage("You are in area which blocks summoning.");
  307. return false;
  308. }
  309. final L2PcInstance partner = L2World.getInstance().getPlayer(activeChar.getPartnerId());
  310. if ((partner == null) || !partner.isOnline())
  311. {
  312. activeChar.sendMessage("Your partner is not online.");
  313. return false;
  314. }
  315. if (activeChar.getInstanceId() != partner.getInstanceId())
  316. {
  317. activeChar.sendMessage("Your partner is in another World!");
  318. return false;
  319. }
  320. if (partner.isJailed())
  321. {
  322. activeChar.sendMessage("Your partner is in Jail.");
  323. return false;
  324. }
  325. if (partner.isCursedWeaponEquipped())
  326. {
  327. activeChar.sendMessage("Your partner is holding a Cursed Weapon and you can't go to your love!");
  328. return false;
  329. }
  330. if (GrandBossManager.getInstance().getZone(partner) != null)
  331. {
  332. activeChar.sendMessage("Your partner is inside a Boss Zone.");
  333. return false;
  334. }
  335. if (partner.isInOlympiadMode())
  336. {
  337. activeChar.sendMessage("Your partner is in the Olympiad now.");
  338. return false;
  339. }
  340. if (L2Event.isParticipant(partner))
  341. {
  342. activeChar.sendMessage("Your partner is in an event.");
  343. return false;
  344. }
  345. if (partner.isInDuel())
  346. {
  347. activeChar.sendMessage("Your partner is in a duel.");
  348. return false;
  349. }
  350. if (partner.isFestivalParticipant())
  351. {
  352. activeChar.sendMessage("Your partner is in a festival.");
  353. return false;
  354. }
  355. if (partner.isInParty() && partner.getParty().isInDimensionalRift())
  356. {
  357. activeChar.sendMessage("Your partner is in dimensional rift.");
  358. return false;
  359. }
  360. if (partner.inObserverMode())
  361. {
  362. activeChar.sendMessage("Your partner is in the observation.");
  363. return false;
  364. }
  365. if ((SiegeManager.getInstance().getSiege(partner) != null) && SiegeManager.getInstance().getSiege(partner).isInProgress())
  366. {
  367. activeChar.sendMessage("Your partner is in a siege, you cannot go to your partner.");
  368. return false;
  369. }
  370. if (partner.isIn7sDungeon() && !activeChar.isIn7sDungeon())
  371. {
  372. final int playerCabal = SevenSigns.getInstance().getPlayerCabal(activeChar.getObjectId());
  373. final boolean isSealValidationPeriod = SevenSigns.getInstance().isSealValidationPeriod();
  374. final int compWinner = SevenSigns.getInstance().getCabalHighestScore();
  375. if (isSealValidationPeriod)
  376. {
  377. if (playerCabal != compWinner)
  378. {
  379. activeChar.sendMessage("Your Partner is in a Seven Signs Dungeon and you are not in the winner Cabal!");
  380. return false;
  381. }
  382. }
  383. else
  384. {
  385. if (playerCabal == SevenSigns.CABAL_NULL)
  386. {
  387. activeChar.sendMessage("Your Partner is in a Seven Signs Dungeon and you are not registered!");
  388. return false;
  389. }
  390. }
  391. }
  392. if (!TvTEvent.onEscapeUse(partner.getObjectId()))
  393. {
  394. activeChar.sendMessage("Your partner is in an event.");
  395. return false;
  396. }
  397. if (partner.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
  398. {
  399. activeChar.sendMessage("Your partner is in area which blocks summoning.");
  400. return false;
  401. }
  402. final int teleportTimer = Config.L2JMOD_WEDDING_TELEPORT_DURATION * 1000;
  403. activeChar.sendMessage("After " + (teleportTimer / 60000) + " min. you will be teleported to your partner.");
  404. activeChar.getInventory().reduceAdena("Wedding", Config.L2JMOD_WEDDING_TELEPORT_PRICE, activeChar, null);
  405. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  406. // SoE Animation section
  407. activeChar.setTarget(activeChar);
  408. activeChar.disableAllSkills();
  409. final MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, teleportTimer, 0);
  410. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 900);
  411. final SetupGauge sg = new SetupGauge(0, teleportTimer);
  412. activeChar.sendPacket(sg);
  413. // End SoE Animation section
  414. final EscapeFinalizer ef = new EscapeFinalizer(activeChar, partner.getLocation(), partner.isIn7sDungeon());
  415. // continue execution later
  416. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, teleportTimer));
  417. activeChar.forceIsCasting(GameTimeController.getInstance().getGameTicks() + (teleportTimer / GameTimeController.MILLIS_IN_TICK));
  418. return true;
  419. }
  420. static class EscapeFinalizer implements Runnable
  421. {
  422. private final L2PcInstance _activeChar;
  423. private final Location _partnerLoc;
  424. private final boolean _to7sDungeon;
  425. EscapeFinalizer(L2PcInstance activeChar, Location loc, boolean to7sDungeon)
  426. {
  427. _activeChar = activeChar;
  428. _partnerLoc = loc;
  429. _to7sDungeon = to7sDungeon;
  430. }
  431. @Override
  432. public void run()
  433. {
  434. if (_activeChar.isDead())
  435. {
  436. return;
  437. }
  438. if ((SiegeManager.getInstance().getSiege(_partnerLoc) != null) && SiegeManager.getInstance().getSiege(_partnerLoc).isInProgress())
  439. {
  440. _activeChar.sendMessage("Your partner is in siege, you can't go to your partner.");
  441. return;
  442. }
  443. _activeChar.setIsIn7sDungeon(_to7sDungeon);
  444. _activeChar.enableAllSkills();
  445. _activeChar.setIsCastingNow(false);
  446. try
  447. {
  448. _activeChar.teleToLocation(_partnerLoc);
  449. }
  450. catch (Exception e)
  451. {
  452. _log.log(Level.SEVERE, "", e);
  453. }
  454. }
  455. }
  456. @Override
  457. public String[] getVoicedCommandList()
  458. {
  459. return _voicedCommands;
  460. }
  461. }