Wedding.java 15 KB

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