Wedding.java 15 KB

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