Wedding.java 16 KB

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