477 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			477 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| /*
 | |
|  * Copyright (C) 2004-2015 L2J DataPack
 | |
|  * 
 | |
|  * This file is part of L2J DataPack.
 | |
|  * 
 | |
|  * L2J DataPack is free software: you can redistribute it and/or modify
 | |
|  * it under the terms of the GNU General Public License as published by
 | |
|  * the Free Software Foundation, either version 3 of the License, or
 | |
|  * (at your option) any later version.
 | |
|  * 
 | |
|  * L2J DataPack is distributed in the hope that it will be useful,
 | |
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | |
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 | |
|  * General Public License for more details.
 | |
|  * 
 | |
|  * You should have received a copy of the GNU General Public License
 | |
|  * along with this program. If not, see <http://www.gnu.org/licenses/>.
 | |
|  */
 | |
| package handlers.voicedcommandhandlers;
 | |
| 
 | |
| import java.sql.Connection;
 | |
| import java.sql.PreparedStatement;
 | |
| import java.sql.ResultSet;
 | |
| import java.util.logging.Level;
 | |
| import java.util.logging.Logger;
 | |
| 
 | |
| import com.l2jserver.Config;
 | |
| import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
 | |
| import com.l2jserver.gameserver.GameTimeController;
 | |
| import com.l2jserver.gameserver.ThreadPoolManager;
 | |
| import com.l2jserver.gameserver.ai.CtrlIntention;
 | |
| import com.l2jserver.gameserver.datatables.SkillData;
 | |
| import com.l2jserver.gameserver.enums.PlayerAction;
 | |
| import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
 | |
| import com.l2jserver.gameserver.instancemanager.CoupleManager;
 | |
| import com.l2jserver.gameserver.instancemanager.GrandBossManager;
 | |
| import com.l2jserver.gameserver.instancemanager.SiegeManager;
 | |
| import com.l2jserver.gameserver.model.L2World;
 | |
| import com.l2jserver.gameserver.model.Location;
 | |
| import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
 | |
| import com.l2jserver.gameserver.model.entity.L2Event;
 | |
| import com.l2jserver.gameserver.model.entity.TvTEvent;
 | |
| import com.l2jserver.gameserver.model.skills.AbnormalVisualEffect;
 | |
| import com.l2jserver.gameserver.model.skills.Skill;
 | |
| import com.l2jserver.gameserver.model.zone.ZoneId;
 | |
| import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
 | |
| import com.l2jserver.gameserver.network.serverpackets.ConfirmDlg;
 | |
| import com.l2jserver.gameserver.network.serverpackets.MagicSkillUse;
 | |
| import com.l2jserver.gameserver.network.serverpackets.SetupGauge;
 | |
| import com.l2jserver.gameserver.util.Broadcast;
 | |
| 
 | |
| /**
 | |
|  * Wedding voiced commands handler.
 | |
|  * @author evill33t
 | |
|  */
 | |
| public class Wedding implements IVoicedCommandHandler
 | |
| {
 | |
| 	static final Logger _log = Logger.getLogger(Wedding.class.getName());
 | |
| 	private static final String[] _voicedCommands =
 | |
| 	{
 | |
| 		"divorce",
 | |
| 		"engage",
 | |
| 		"gotolove"
 | |
| 	};
 | |
| 	
 | |
| 	@Override
 | |
| 	public boolean useVoicedCommand(String command, L2PcInstance activeChar, String params)
 | |
| 	{
 | |
| 		if (activeChar == null)
 | |
| 		{
 | |
| 			return false;
 | |
| 		}
 | |
| 		if (command.startsWith("engage"))
 | |
| 		{
 | |
| 			return engage(activeChar);
 | |
| 		}
 | |
| 		else if (command.startsWith("divorce"))
 | |
| 		{
 | |
| 			return divorce(activeChar);
 | |
| 		}
 | |
| 		else if (command.startsWith("gotolove"))
 | |
| 		{
 | |
| 			return goToLove(activeChar);
 | |
| 		}
 | |
| 		return false;
 | |
| 	}
 | |
| 	
 | |
| 	public boolean divorce(L2PcInstance activeChar)
 | |
| 	{
 | |
| 		if (activeChar.getPartnerId() == 0)
 | |
| 		{
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		int _partnerId = activeChar.getPartnerId();
 | |
| 		int _coupleId = activeChar.getCoupleId();
 | |
| 		long AdenaAmount = 0;
 | |
| 		
 | |
| 		if (activeChar.isMarried())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are now divorced.");
 | |
| 			
 | |
| 			AdenaAmount = (activeChar.getAdena() / 100) * Config.L2JMOD_WEDDING_DIVORCE_COSTS;
 | |
| 			activeChar.getInventory().reduceAdena("Wedding", AdenaAmount, activeChar, null);
 | |
| 			
 | |
| 		}
 | |
| 		else
 | |
| 		{
 | |
| 			activeChar.sendMessage("You have broken up as a couple.");
 | |
| 		}
 | |
| 		
 | |
| 		final L2PcInstance partner = L2World.getInstance().getPlayer(_partnerId);
 | |
| 		if (partner != null)
 | |
| 		{
 | |
| 			partner.setPartnerId(0);
 | |
| 			if (partner.isMarried())
 | |
| 			{
 | |
| 				partner.sendMessage("Your spouse has decided to divorce you.");
 | |
| 			}
 | |
| 			else
 | |
| 			{
 | |
| 				partner.sendMessage("Your fiance has decided to break the engagement with you.");
 | |
| 			}
 | |
| 			
 | |
| 			// give adena
 | |
| 			if (AdenaAmount > 0)
 | |
| 			{
 | |
| 				partner.addAdena("WEDDING", AdenaAmount, null, false);
 | |
| 			}
 | |
| 		}
 | |
| 		CoupleManager.getInstance().deleteCouple(_coupleId);
 | |
| 		return true;
 | |
| 	}
 | |
| 	
 | |
| 	public boolean engage(L2PcInstance activeChar)
 | |
| 	{
 | |
| 		if (activeChar.getTarget() == null)
 | |
| 		{
 | |
| 			activeChar.sendMessage("You have no one targeted.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		else if (!(activeChar.getTarget() instanceof L2PcInstance))
 | |
| 		{
 | |
| 			activeChar.sendMessage("You can only ask another player to engage you.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		else if (activeChar.getPartnerId() != 0)
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are already engaged.");
 | |
| 			if (Config.L2JMOD_WEDDING_PUNISH_INFIDELITY)
 | |
| 			{
 | |
| 				activeChar.startAbnormalVisualEffect(AbnormalVisualEffect.BIG_HEAD); // give player a Big Head
 | |
| 				// lets recycle the sevensigns debuffs
 | |
| 				int skillId;
 | |
| 				
 | |
| 				int skillLevel = 1;
 | |
| 				
 | |
| 				if (activeChar.getLevel() > 40)
 | |
| 				{
 | |
| 					skillLevel = 2;
 | |
| 				}
 | |
| 				
 | |
| 				if (activeChar.isMageClass())
 | |
| 				{
 | |
| 					skillId = 4362;
 | |
| 				}
 | |
| 				else
 | |
| 				{
 | |
| 					skillId = 4361;
 | |
| 				}
 | |
| 				
 | |
| 				final Skill skill = SkillData.getInstance().getSkill(skillId, skillLevel);
 | |
| 				if (!activeChar.isAffectedBySkill(skillId))
 | |
| 				{
 | |
| 					skill.applyEffects(activeChar, activeChar);
 | |
| 				}
 | |
| 			}
 | |
| 			return false;
 | |
| 		}
 | |
| 		final L2PcInstance ptarget = (L2PcInstance) activeChar.getTarget();
 | |
| 		// check if player target himself
 | |
| 		if (ptarget.getObjectId() == activeChar.getObjectId())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Is there something wrong with you, are you trying to go out with youself?");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (ptarget.isMarried())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Player already married.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (ptarget.isEngageRequest())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Player already asked by someone else.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (ptarget.getPartnerId() != 0)
 | |
| 		{
 | |
| 			activeChar.sendMessage("Player already engaged with someone else.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if ((ptarget.getAppearance().getSex() == activeChar.getAppearance().getSex()) && !Config.L2JMOD_WEDDING_SAMESEX)
 | |
| 		{
 | |
| 			activeChar.sendMessage("Gay marriage is not allowed on this server!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		// Check if target has player on friend list
 | |
| 		boolean foundOnFriendList = false;
 | |
| 		try (Connection con = ConnectionFactory.getInstance().getConnection();
 | |
| 			PreparedStatement statement = con.prepareStatement("SELECT friendId FROM character_friends WHERE charId=?"))
 | |
| 		{
 | |
| 			statement.setInt(1, ptarget.getObjectId());
 | |
| 			try (ResultSet rset = statement.executeQuery())
 | |
| 			{
 | |
| 				while (rset.next())
 | |
| 				{
 | |
| 					if (rset.getInt("friendId") == activeChar.getObjectId())
 | |
| 					{
 | |
| 						foundOnFriendList = true;
 | |
| 					}
 | |
| 				}
 | |
| 			}
 | |
| 		}
 | |
| 		catch (Exception e)
 | |
| 		{
 | |
| 			_log.warning("could not read friend data:" + e);
 | |
| 		}
 | |
| 		
 | |
| 		if (!foundOnFriendList)
 | |
| 		{
 | |
| 			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.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		ptarget.setEngageRequest(true, activeChar.getObjectId());
 | |
| 		ptarget.addAction(PlayerAction.USER_ENGAGE);
 | |
| 		
 | |
| 		final ConfirmDlg dlg = new ConfirmDlg(activeChar.getName() + " is asking to engage you. Do you want to start a new relationship?");
 | |
| 		dlg.addTime(15 * 1000);
 | |
| 		ptarget.sendPacket(dlg);
 | |
| 		return true;
 | |
| 	}
 | |
| 	
 | |
| 	public boolean goToLove(L2PcInstance activeChar)
 | |
| 	{
 | |
| 		if (!activeChar.isMarried())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You're not married.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.getPartnerId() == 0)
 | |
| 		{
 | |
| 			activeChar.sendMessage("Couldn't find your fiance in the Database - Inform a Gamemaster.");
 | |
| 			_log.severe("Married but couldn't find parter for " + activeChar.getName());
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (GrandBossManager.getInstance().getZone(activeChar) != null)
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are inside a Boss Zone.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.isCombatFlagEquipped())
 | |
| 		{
 | |
| 			activeChar.sendMessage("While you are holding a Combat Flag or Territory Ward you can't go to your love!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.isCursedWeaponEquipped())
 | |
| 		{
 | |
| 			activeChar.sendMessage("While you are holding a Cursed Weapon you can't go to your love!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (GrandBossManager.getInstance().getZone(activeChar) != null)
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are inside a Boss Zone.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.isJailed())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in Jail!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.isInOlympiadMode())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in the Olympiad now.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (L2Event.isParticipant(activeChar))
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in an event.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.isInDuel())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in a duel!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.inObserverMode())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in the observation.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if ((SiegeManager.getInstance().getSiege(activeChar) != null) && SiegeManager.getInstance().getSiege(activeChar).isInProgress())
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in a siege, you cannot go to your partner.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		// Thanks nbd
 | |
| 		if (!TvTEvent.onEscapeUse(activeChar.getObjectId()))
 | |
| 		{
 | |
| 			activeChar.sendPacket(ActionFailed.STATIC_PACKET);
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
 | |
| 		{
 | |
| 			activeChar.sendMessage("You are in area which blocks summoning.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		final L2PcInstance partner = L2World.getInstance().getPlayer(activeChar.getPartnerId());
 | |
| 		if ((partner == null) || !partner.isOnline())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is not online.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.getInstanceId() != partner.getInstanceId())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in another World!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isJailed())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in Jail.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isCursedWeaponEquipped())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is holding a Cursed Weapon and you can't go to your love!");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (GrandBossManager.getInstance().getZone(partner) != null)
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is inside a Boss Zone.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInOlympiadMode())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in the Olympiad now.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (L2Event.isParticipant(partner))
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in an event.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInDuel())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in a duel.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		if (partner.inObserverMode())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in the observation.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if ((SiegeManager.getInstance().getSiege(partner) != null) && SiegeManager.getInstance().getSiege(partner).isInProgress())
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in a siege, you cannot go to your partner.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (!TvTEvent.onEscapeUse(partner.getObjectId()))
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in an event.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInsideZone(ZoneId.NO_SUMMON_FRIEND))
 | |
| 		{
 | |
| 			activeChar.sendMessage("Your partner is in area which blocks summoning.");
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		final int teleportTimer = Config.L2JMOD_WEDDING_TELEPORT_DURATION * 1000;
 | |
| 		activeChar.sendMessage("After " + (teleportTimer / 60000) + " min. you will be teleported to your partner.");
 | |
| 		activeChar.getInventory().reduceAdena("Wedding", Config.L2JMOD_WEDDING_TELEPORT_PRICE, activeChar, null);
 | |
| 		
 | |
| 		activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_IDLE);
 | |
| 		// SoE Animation section
 | |
| 		activeChar.setTarget(activeChar);
 | |
| 		activeChar.disableAllSkills();
 | |
| 		
 | |
| 		final MagicSkillUse msk = new MagicSkillUse(activeChar, 1050, 1, teleportTimer, 0);
 | |
| 		Broadcast.toSelfAndKnownPlayersInRadius(activeChar, msk, 900);
 | |
| 		final SetupGauge sg = new SetupGauge(0, teleportTimer);
 | |
| 		activeChar.sendPacket(sg);
 | |
| 		// End SoE Animation section
 | |
| 		
 | |
| 		final EscapeFinalizer ef = new EscapeFinalizer(activeChar, partner.getLocation());
 | |
| 		// continue execution later
 | |
| 		activeChar.setSkillCast(ThreadPoolManager.getInstance().scheduleGeneral(ef, teleportTimer));
 | |
| 		activeChar.forceIsCasting(GameTimeController.getInstance().getGameTicks() + (teleportTimer / GameTimeController.MILLIS_IN_TICK));
 | |
| 		
 | |
| 		return true;
 | |
| 	}
 | |
| 	
 | |
| 	static class EscapeFinalizer implements Runnable
 | |
| 	{
 | |
| 		private final L2PcInstance _activeChar;
 | |
| 		private final Location _partnerLoc;
 | |
| 		
 | |
| 		EscapeFinalizer(L2PcInstance activeChar, Location loc)
 | |
| 		{
 | |
| 			_activeChar = activeChar;
 | |
| 			_partnerLoc = loc;
 | |
| 		}
 | |
| 		
 | |
| 		@Override
 | |
| 		public void run()
 | |
| 		{
 | |
| 			if (_activeChar.isDead())
 | |
| 			{
 | |
| 				return;
 | |
| 			}
 | |
| 			
 | |
| 			if ((SiegeManager.getInstance().getSiege(_partnerLoc) != null) && SiegeManager.getInstance().getSiege(_partnerLoc).isInProgress())
 | |
| 			{
 | |
| 				_activeChar.sendMessage("Your partner is in siege, you can't go to your partner.");
 | |
| 				return;
 | |
| 			}
 | |
| 			
 | |
| 			_activeChar.enableAllSkills();
 | |
| 			_activeChar.setIsCastingNow(false);
 | |
| 			
 | |
| 			try
 | |
| 			{
 | |
| 				_activeChar.teleToLocation(_partnerLoc);
 | |
| 			}
 | |
| 			catch (Exception e)
 | |
| 			{
 | |
| 				_log.log(Level.SEVERE, "", e);
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	@Override
 | |
| 	public String[] getVoicedCommandList()
 | |
| 	{
 | |
| 		return _voicedCommands;
 | |
| 	}
 | |
| }
 | 
