l2j_mobius/trunk/dist/game/data/scripts/handlers/playeractions/SitStand.java
2016-06-12 01:34:09 +00:00

98 lines
3.2 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.enums.MountType;
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.actor.instance.L2StaticObjectInstance;
import com.l2jmobius.gameserver.model.effects.EffectFlag;
import com.l2jmobius.gameserver.network.serverpackets.ChairSit;
/**
* Sit/Stand player action handler.
* @author UnAfraid
*/
public final class SitStand implements IPlayerActionHandler
{
@Override
public void useAction(L2PcInstance activeChar, ActionDataHolder data, boolean ctrlPressed, boolean shiftPressed)
{
if (activeChar.isSitting() || !activeChar.isMoving() || activeChar.isFakeDeath())
{
useSit(activeChar, activeChar.getTarget());
}
else
{
// Sit when arrive using next action.
// Creating next action class.
final NextAction nextAction = new NextAction(CtrlEvent.EVT_ARRIVED, CtrlIntention.AI_INTENTION_MOVE_TO, () -> useSit(activeChar, activeChar.getTarget()));
// Binding next action to AI.
activeChar.getAI().setNextAction(nextAction);
}
}
/**
* Use the sit action.
* @param activeChar the player trying to sit
* @param target the target to sit, throne, bench or chair
* @return {@code true} if the player can sit, {@code false} otherwise
*/
protected boolean useSit(L2PcInstance activeChar, L2Object target)
{
if (activeChar.getMountType() != MountType.NONE)
{
return false;
}
if (!activeChar.isSitting() && (target instanceof L2StaticObjectInstance) && (((L2StaticObjectInstance) target).getType() == 1) && activeChar.isInsideRadius(target, L2StaticObjectInstance.INTERACTION_DISTANCE, false, false))
{
final ChairSit cs = new ChairSit(activeChar, target.getId());
activeChar.sendPacket(cs);
activeChar.sitDown();
activeChar.broadcastPacket(cs);
return true;
}
if (activeChar.isFakeDeath())
{
activeChar.stopEffects(EffectFlag.FAKE_DEATH);
}
else if (activeChar.isSitting())
{
activeChar.standUp();
}
else
{
activeChar.sitDown();
}
return true;
}
public static void main(String[] args)
{
PlayerActionHandler.getInstance().registerHandler(new SitStand());
}
}