Wedding.java 15 KB

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