/* * 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 silentium.gameserver.model.actor.instance; import silentium.commons.utils.Rnd; import silentium.gameserver.ThreadPoolManager; import silentium.gameserver.ai.CtrlIntention; import silentium.gameserver.model.L2CharPosition; import silentium.gameserver.model.actor.L2Npc; import silentium.gameserver.network.serverpackets.ActionFailed; import silentium.gameserver.network.serverpackets.MoveToPawn; import silentium.gameserver.network.serverpackets.MyTargetSelected; import silentium.gameserver.network.serverpackets.ValidateLocation; import silentium.gameserver.templates.chars.L2NpcTemplate; public class L2TownPetInstance extends L2NpcInstance { int randomX, randomY, spawnX, spawnY; public L2TownPetInstance(int objectId, L2NpcTemplate template) { super(objectId, template); setRunning(); ThreadPoolManager.getInstance().scheduleAiAtFixedRate(new RandomWalkTask(), 1000, 10000); } @Override public void onAction(L2PcInstance player) { if (!player.canTarget()) return; if (this != player.getTarget()) { player.setTarget(this); player.sendPacket(new MyTargetSelected(getObjectId(), 0)); player.sendPacket(new ValidateLocation(this)); } else { if (!canInteract(player)) player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this); else { // Rotate the player to face the instance player.sendPacket(new MoveToPawn(player, this, L2Npc.INTERACTION_DISTANCE)); // Send ActionFailed to the player in order to avoid he stucks player.sendPacket(ActionFailed.STATIC_PACKET); } } } @Override public void onSpawn() { super.onSpawn(); spawnX = getX(); spawnY = getY(); } public class RandomWalkTask implements Runnable { @Override public void run() { randomX = spawnX + Rnd.get(150) - 75; randomY = spawnY + Rnd.get(150) - 75; if ((randomX != getX()) && (randomY != getY())) getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(randomX, randomY, getZ(), 0)); } } }