Wedding.java 15 KB

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