325 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
			
		
		
	
	
			325 lines
		
	
	
		
			10 KiB
		
	
	
	
		
			Java
		
	
	
	
	
	
| /*
 | |
|  * This file is part of the L2J Mobius project.
 | |
|  * 
 | |
|  * This program 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.
 | |
|  * 
 | |
|  * This program 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.playeractions;
 | |
| 
 | |
| import com.l2jmobius.gameserver.ai.CtrlEvent;
 | |
| import com.l2jmobius.gameserver.ai.CtrlIntention;
 | |
| import com.l2jmobius.gameserver.ai.NextAction;
 | |
| import com.l2jmobius.gameserver.handler.IPlayerActionHandler;
 | |
| import com.l2jmobius.gameserver.handler.PlayerActionHandler;
 | |
| import com.l2jmobius.gameserver.model.ActionDataHolder;
 | |
| import com.l2jmobius.gameserver.model.L2Object;
 | |
| import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
 | |
| import com.l2jmobius.gameserver.model.events.EventDispatcher;
 | |
| import com.l2jmobius.gameserver.model.events.impl.character.player.OnPlayerSocialAction;
 | |
| import com.l2jmobius.gameserver.network.SystemMessageId;
 | |
| import com.l2jmobius.gameserver.network.serverpackets.ExAskCoupleAction;
 | |
| import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
 | |
| import com.l2jmobius.gameserver.taskmanager.AttackStanceTaskManager;
 | |
| 
 | |
| /**
 | |
|  * Social Action player action handler.
 | |
|  * @author Nik
 | |
|  */
 | |
| public final class SocialAction implements IPlayerActionHandler
 | |
| {
 | |
| 	@Override
 | |
| 	public void useAction(L2PcInstance activeChar, ActionDataHolder data, boolean ctrlPressed, boolean shiftPressed)
 | |
| 	{
 | |
| 		switch (data.getOptionId())
 | |
| 		{
 | |
| 			case 2: // Greeting
 | |
| 			case 3: // Victory
 | |
| 			case 4: // Advance
 | |
| 			case 5: // No
 | |
| 			case 6: // Yes
 | |
| 			case 7: // Bow
 | |
| 			case 8: // Unaware
 | |
| 			case 9: // Social Waiting
 | |
| 			case 10: // Laugh
 | |
| 			case 11: // Applaud
 | |
| 			case 12: // Dance
 | |
| 			case 13: // Sorrow
 | |
| 			case 14: // Charm
 | |
| 			case 15: // Shyness
 | |
| 			case 28: // Propose
 | |
| 			case 29: // Provoke
 | |
| 				useSocial(activeChar, data.getOptionId());
 | |
| 				break;
 | |
| 			case 30: // Beauty Shop
 | |
| 				if (useSocial(activeChar, data.getOptionId()))
 | |
| 				{
 | |
| 					activeChar.broadcastInfo();
 | |
| 				}
 | |
| 				break;
 | |
| 			case 16: // Exchange Bows
 | |
| 			case 17: // High Five
 | |
| 			case 18: // Couple Dance
 | |
| 				useCoupleSocial(activeChar, data.getOptionId());
 | |
| 		}
 | |
| 	}
 | |
| 	
 | |
| 	private boolean useSocial(L2PcInstance activeChar, int id)
 | |
| 	{
 | |
| 		if (activeChar.isFishing())
 | |
| 		{
 | |
| 			activeChar.sendPacket(SystemMessageId.YOU_CANNOT_DO_THAT_WHILE_FISHING3);
 | |
| 			return false;
 | |
| 		}
 | |
| 		
 | |
| 		if (activeChar.canMakeSocialAction())
 | |
| 		{
 | |
| 			activeChar.broadcastPacket(new com.l2jmobius.gameserver.network.serverpackets.SocialAction(activeChar.getObjectId(), id));
 | |
| 			
 | |
| 			// Notify to scripts
 | |
| 			EventDispatcher.getInstance().notifyEventAsync(new OnPlayerSocialAction(activeChar, id), activeChar);
 | |
| 		}
 | |
| 		
 | |
| 		return true;
 | |
| 	}
 | |
| 	
 | |
| 	private void useCoupleSocial(L2PcInstance player, int id)
 | |
| 	{
 | |
| 		if (player == null)
 | |
| 		{
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		final L2Object target = player.getTarget();
 | |
| 		if ((target == null) || !target.isPlayer())
 | |
| 		{
 | |
| 			player.sendPacket(SystemMessageId.INVALID_TARGET);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		final int distance = (int) player.calculateDistance(target, false, false);
 | |
| 		if ((distance > 125) || (distance < 15) || (player.getObjectId() == target.getObjectId()))
 | |
| 		{
 | |
| 			player.sendPacket(SystemMessageId.THE_REQUEST_CANNOT_BE_COMPLETED_BECAUSE_THE_TARGET_DOES_NOT_MEET_LOCATION_REQUIREMENTS);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		SystemMessage sm;
 | |
| 		if (player.isInStoreMode() || player.isInCraftMode())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_PRIVATE_STORE_MODE_OR_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isInCombat() || player.isInDuel() || AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isFishing())
 | |
| 		{
 | |
| 			player.sendPacket(SystemMessageId.YOU_CANNOT_DO_THAT_WHILE_FISHING3);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.getReputation() < 0)
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_CHAOTIC_STATE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isInOlympiadMode())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_PARTICIPATING_IN_THE_OLYMPIAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isInSiege())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_CASTLE_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isInHideoutSiege())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_PARTICIPATING_IN_A_CLAN_HALL_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isMounted() || player.isFlyingMounted() || player.isInBoat() || player.isInAirShip())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_RIDING_A_SHIP_STEED_OR_STRIDER_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isTransformed())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_CURRENTLY_TRANSFORMING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isAlikeDead())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_CURRENTLY_DEAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(player);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		// Checks for partner.
 | |
| 		final L2PcInstance partner = target.getActingPlayer();
 | |
| 		if (partner.isInStoreMode() || partner.isInCraftMode())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_PRIVATE_STORE_MODE_OR_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInCombat() || partner.isInDuel() || AttackStanceTaskManager.getInstance().hasAttackStanceTask(partner))
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_BATTLE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.getMultiSociaAction() > 0)
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_ALREADY_PARTICIPATING_IN_A_COUPLE_ACTION_AND_CANNOT_BE_REQUESTED_FOR_ANOTHER_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isFishing())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_FISHING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.getReputation() < 0)
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_CHAOTIC_STATE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInOlympiadMode())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_PARTICIPATING_IN_THE_OLYMPIAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInHideoutSiege())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_PARTICIPATING_IN_A_CLAN_HALL_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isInSiege())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_IN_A_CASTLE_SIEGE_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isMounted() || partner.isFlyingMounted() || partner.isInBoat() || partner.isInAirShip())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_RIDING_A_SHIP_STEED_OR_STRIDER_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isTeleporting())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_CURRENTLY_TELEPORTING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isTransformed())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_CURRENTLY_TRANSFORMING_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (partner.isAlikeDead())
 | |
| 		{
 | |
| 			sm = SystemMessage.getSystemMessage(SystemMessageId.C1_IS_CURRENTLY_DEAD_AND_CANNOT_BE_REQUESTED_FOR_A_COUPLE_ACTION);
 | |
| 			sm.addPcName(partner);
 | |
| 			player.sendPacket(sm);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isAllSkillsDisabled() || partner.isAllSkillsDisabled())
 | |
| 		{
 | |
| 			player.sendPacket(SystemMessageId.THE_COUPLE_ACTION_WAS_CANCELLED);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		player.setMultiSocialAction(id, partner.getObjectId());
 | |
| 		sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_REQUESTED_A_COUPLE_ACTION_WITH_C1);
 | |
| 		sm.addPcName(partner);
 | |
| 		player.sendPacket(sm);
 | |
| 		
 | |
| 		if ((player.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE) || (partner.getAI().getIntention() != CtrlIntention.AI_INTENTION_IDLE))
 | |
| 		{
 | |
| 			final NextAction nextAction = new NextAction(CtrlEvent.EVT_ARRIVED, CtrlIntention.AI_INTENTION_MOVE_TO, () -> partner.sendPacket(new ExAskCoupleAction(player.getObjectId(), id)));
 | |
| 			player.getAI().setNextAction(nextAction);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		if (player.isCastingNow())
 | |
| 		{
 | |
| 			final NextAction nextAction = new NextAction(CtrlEvent.EVT_FINISH_CASTING, CtrlIntention.AI_INTENTION_CAST, () -> partner.sendPacket(new ExAskCoupleAction(player.getObjectId(), id)));
 | |
| 			player.getAI().setNextAction(nextAction);
 | |
| 			return;
 | |
| 		}
 | |
| 		
 | |
| 		partner.sendPacket(new ExAskCoupleAction(player.getObjectId(), id));
 | |
| 	}
 | |
| 	
 | |
| 	public static void main(String[] args)
 | |
| 	{
 | |
| 		PlayerActionHandler.getInstance().registerHandler(new SocialAction());
 | |
| 	}
 | |
| }
 | 
