Package com.l2jfrozen.gameserver.model.actor.instance

Source Code of com.l2jfrozen.gameserver.model.actor.instance.L2DungeonInstance

/*
* 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 com.l2jfrozen.gameserver.model.actor.instance;

import com.l2jfrozen.gameserver.ai.CtrlIntention;
import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
import com.l2jfrozen.gameserver.templates.L2NpcTemplate;



public class L2DungeonInstance extends L2NpcInstance
  private static final String PARENT_DIR = "data/html/default/";
 
  public L2DungeonInstance(int objectID, L2NpcTemplate template)
  {
    super(objectID, template);
  }
 
  @Override
  public void onAction(L2PcInstance player)
  {
    if(!canTarget(player))
      return;

    // Check if the L2PcInstance already target the L2NpcInstance
    if(this != player.getTarget())
    {
      // Set the target of the L2PcInstance player
      player.setTarget(this);

      // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
      MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
      player.sendPacket(my);
      my = null;

      player.sendPacket(new ValidateLocation(this));
    }
    else
    {
      // Calculate the distance between the L2PcInstance and the L2NpcInstance
      if(!canInteract(player))
      {
        // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
        player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
      }
      else
      {
        NpcHtmlMessage html = new NpcHtmlMessage(1);
        html.setFile(PARENT_DIR+"7090.htm");
        sendHtmlMessage(player, html);
      }
    }
    // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
    player.sendPacket(ActionFailed.STATIC_PACKET);
  }
 
  private void sendHtmlMessage(L2PcInstance player, NpcHtmlMessage html)
    {
        html.replace("%objectId%", String.valueOf(getObjectId()));
        html.replace("%npcId%", String.valueOf(getNpcId()));
        player.sendPacket(html);
    }
}
TOP

Related Classes of com.l2jfrozen.gameserver.model.actor.instance.L2DungeonInstance

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.