Wedding.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /*
  2. * Copyright (C) 2004-2014 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.L2DatabaseFactory;
  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 friendlist
  193. boolean FoundOnFriendList = false;
  194. int objectId;
  195. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  196. {
  197. final PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=?");
  198. statement.setInt(1, ptarget.getObjectId());
  199. final ResultSet rset = statement.executeQuery();
  200. while (rset.next())
  201. {
  202. objectId = rset.getInt("friendId");
  203. if (objectId == activeChar.getObjectId())
  204. {
  205. FoundOnFriendList = true;
  206. }
  207. }
  208. statement.close();
  209. }
  210. catch (Exception e)
  211. {
  212. _log.warning("could not read friend data:" + e);
  213. }
  214. if (!FoundOnFriendList)
  215. {
  216. 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.");
  217. return false;
  218. }
  219. ptarget.setEngageRequest(true, activeChar.getObjectId());
  220. ptarget.addAction(PlayerAction.USER_ENGAGE);
  221. final ConfirmDlg dlg = new ConfirmDlg(activeChar.getName() + " is asking to engage you. Do you want to start a new relationship?");
  222. dlg.addTime(15 * 1000);
  223. ptarget.sendPacket(dlg);
  224. return true;
  225. }
  226. public boolean goToLove(L2PcInstance activeChar)
  227. {
  228. if (!activeChar.isMarried())
  229. {
  230. activeChar.sendMessage("You're not married.");
  231. return false;
  232. }
  233. if (activeChar.getPartnerId() == 0)
  234. {
  235. activeChar.sendMessage("Couldn't find your fiance in the Database - Inform a Gamemaster.");
  236. _log.severe("Married but couldn't find parter for " + activeChar.getName());
  237. return false;
  238. }
  239. if (GrandBossManager.getInstance().getZone(activeChar) != null)
  240. {
  241. activeChar.sendMessage("You are inside a Boss Zone.");
  242. return false;
  243. }
  244. if (activeChar.isCombatFlagEquipped())
  245. {
  246. activeChar.sendMessage("While you are holding a Combat Flag or Territory Ward you can't go to your love!");
  247. return false;
  248. }
  249. if (activeChar.isCursedWeaponEquipped())
  250. {
  251. activeChar.sendMessage("While you are holding a Cursed Weapon you can't go to your love!");
  252. return false;
  253. }
  254. if (GrandBossManager.getInstance().getZone(activeChar) != null)
  255. {
  256. activeChar.sendMessage("You are inside a Boss Zone.");
  257. return false;
  258. }
  259. if (activeChar.isJailed())
  260. {
  261. activeChar.sendMessage("You are in Jail!");
  262. return false;
  263. }
  264. if (activeChar.isInOlympiadMode())
  265. {
  266. activeChar.sendMessage("You are in the Olympiad now.");
  267. return false;
  268. }
  269. if (L2Event.isParticipant(activeChar))
  270. {
  271. activeChar.sendMessage("You are in an event.");
  272. return false;
  273. }
  274. if (activeChar.isInDuel())
  275. {
  276. activeChar.sendMessage("You are in a duel!");
  277. return false;
  278. }
  279. if (activeChar.inObserverMode())
  280. {
  281. activeChar.sendMessage("You are in the observation.");
  282. return false;
  283. }
  284. if ((SiegeManager.getInstance().getSiege(activeChar) != null) && SiegeManager.getInstance().getSiege(activeChar).isInProgress())
  285. {
  286. activeChar.sendMessage("You are in a siege, you cannot go to your partner.");
  287. return false;
  288. }
  289. if (activeChar.isFestivalParticipant())
  290. {
  291. activeChar.sendMessage("You are in a festival.");
  292. return false;
  293. }
  294. if (activeChar.isInParty() && activeChar.getParty().isInDimensionalRift())
  295. {
  296. activeChar.sendMessage("You are in the dimensional rift.");
  297. return false;
  298. }
  299. // Thanks nbd
  300. if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
  301. {
  302. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  303. return false;
  304. }
  305. if (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
  306. {
  307. activeChar.sendMessage("You are in area which blocks summoning.");
  308. return false;
  309. }
  310. final L2PcInstance partner = L2World.getInstance().getPlayer(activeChar.getPartnerId());
  311. if ((partner == null) || !partner.isOnline())
  312. {
  313. activeChar.sendMessage("Your partner is not online.");
  314. return false;
  315. }
  316. if (activeChar.getInstanceId() != partner.getInstanceId())
  317. {
  318. activeChar.sendMessage("Your partner is in another World!");
  319. return false;
  320. }
  321. if (partner.isJailed())
  322. {
  323. activeChar.sendMessage("Your partner is in Jail.");
  324. return false;
  325. }
  326. if (partner.isCursedWeaponEquipped())
  327. {
  328. activeChar.sendMessage("Your partner is holding a Cursed Weapon and you can't go to your love!");
  329. return false;
  330. }
  331. if (GrandBossManager.getInstance().getZone(partner) != null)
  332. {
  333. activeChar.sendMessage("Your partner is inside a Boss Zone.");
  334. return false;
  335. }
  336. if (partner.isInOlympiadMode())
  337. {
  338. activeChar.sendMessage("Your partner is in the Olympiad now.");
  339. return false;
  340. }
  341. if (L2Event.isParticipant(partner))
  342. {
  343. activeChar.sendMessage("Your partner is in an event.");
  344. return false;
  345. }
  346. if (partner.isInDuel())
  347. {
  348. activeChar.sendMessage("Your partner is in a duel.");
  349. return false;
  350. }
  351. if (partner.isFestivalParticipant())
  352. {
  353. activeChar.sendMessage("Your partner is in a festival.");
  354. return false;
  355. }
  356. if (partner.isInParty() && partner.getParty().isInDimensionalRift())
  357. {
  358. activeChar.sendMessage("Your partner is in dimensional rift.");
  359. return false;
  360. }
  361. if (partner.inObserverMode())
  362. {
  363. activeChar.sendMessage("Your partner is in the observation.");
  364. return false;
  365. }
  366. if ((SiegeManager.getInstance().getSiege(partner) != null) && SiegeManager.getInstance().getSiege(partner).isInProgress())
  367. {
  368. activeChar.sendMessage("Your partner is in a siege, you cannot go to your partner.");
  369. return false;
  370. }
  371. if (partner.isIn7sDungeon() && !activeChar.isIn7sDungeon())
  372. {
  373. final int playerCabal = SevenSigns.getInstance().getPlayerCabal(activeChar.getObjectId());
  374. final boolean isSealValidationPeriod = SevenSigns.getInstance().isSealValidationPeriod();
  375. final int compWinner = SevenSigns.getInstance().getCabalHighestScore();
  376. if (isSealValidationPeriod)
  377. {
  378. if (playerCabal != compWinner)
  379. {
  380. activeChar.sendMessage("Your Partner is in a Seven Signs Dungeon and you are not in the winner Cabal!");
  381. return false;
  382. }
  383. }
  384. else
  385. {
  386. if (playerCabal == SevenSigns.CABAL_NULL)
  387. {
  388. activeChar.sendMessage("Your Partner is in a Seven Signs Dungeon and you are not registered!");
  389. return false;
  390. }
  391. }
  392. }
  393. if (!TvTEvent.onEscapeUse(partner.getObjectId()))
  394. {
  395. activeChar.sendMessage("Your partner is in an event.");
  396. return false;
  397. }
  398. if (partner.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
  399. {
  400. activeChar.sendMessage("Your partner is in area which blocks summoning.");
  401. return false;
  402. }
  403. final int teleportTimer = Config.L2JMOD_WEDDING_TELEPORT_DURATION * 1000;
  404. activeChar.sendMessage("After " + (teleportTimer / 60000) + " min. you will be teleported to your partner.");
  405. activeChar.getInventory().reduceAdena("Wedding", Config.L2JMOD_WEDDING_TELEPORT_PRICE, activeChar, null);
  406. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
  407. // SoE Animation section
  408. activeChar.setTarget(activeChar);
  409. activeChar.disableAllSkills();
  410. final MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, teleportTimer, 0);
  411. Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 900);
  412. final SetupGauge sg = new SetupGauge(0, teleportTimer);
  413. activeChar.sendPacket(sg);
  414. // End SoE Animation section
  415. final EscapeFinalizer ef = new EscapeFinalizer(activeChar, partner.getLocation(), partner.isIn7sDungeon());
  416. // continue execution later
  417. activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, teleportTimer));
  418. activeChar.forceIsCasting(GameTimeController.getInstance().getGameTicks() + (teleportTimer / GameTimeController.MILLIS_IN_TICK));
  419. return true;
  420. }
  421. static class EscapeFinalizer implements Runnable
  422. {
  423. private final L2PcInstance _activeChar;
  424. private final Location _partnerLoc;
  425. private final boolean _to7sDungeon;
  426. EscapeFinalizer(L2PcInstance activeChar, Location loc, boolean to7sDungeon)
  427. {
  428. _activeChar = activeChar;
  429. _partnerLoc = loc;
  430. _to7sDungeon = to7sDungeon;
  431. }
  432. @Override
  433. public void run()
  434. {
  435. if (_activeChar.isDead())
  436. {
  437. return;
  438. }
  439. if ((SiegeManager.getInstance().getSiege(_partnerLoc) != null) && SiegeManager.getInstance().getSiege(_partnerLoc).isInProgress())
  440. {
  441. _activeChar.sendMessage("Your partner is in siege, you can't go to your partner.");
  442. return;
  443. }
  444. _activeChar.setIsIn7sDungeon(_to7sDungeon);
  445. _activeChar.enableAllSkills();
  446. _activeChar.setIsCastingNow(false);
  447. try
  448. {
  449. _activeChar.teleToLocation(_partnerLoc);
  450. }
  451. catch (Exception e)
  452. {
  453. _log.log(Level.SEVERE, "", e);
  454. }
  455. }
  456. }
  457. @Override
  458. public String[] getVoicedCommandList()
  459. {
  460. return _voicedCommands;
  461. }
  462. }