Wedding.java 15 KB

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