/*
* 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 .
*/
package ai;
import java.util.logging.Logger;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.model.actor.instance.L2MonsterInstance;
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
import com.l2jmobius.gameserver.model.holders.MinionHolder;
import com.l2jmobius.gameserver.model.quest.Quest;
import com.l2jmobius.gameserver.network.serverpackets.SocialAction;
import com.l2jmobius.gameserver.util.Broadcast;
/**
* Abstract NPC AI class for datapack based AIs.
* @author UnAfraid, Zoey76
*/
public abstract class AbstractNpcAI extends Quest
{
protected final Logger _log = Logger.getLogger(getClass().getName());
public AbstractNpcAI()
{
super(-1);
}
/**
* Simple on first talk event handler.
*/
@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
return npc.getId() + ".html";
}
/**
* Registers the following events to the current script:
*
* - ON_ATTACK
* - ON_KILL
* - ON_SPAWN
* - ON_SPELL_FINISHED
* - ON_SKILL_SEE
* - ON_FACTION_CALL
* - ON_AGGR_RANGE_ENTER
*
* @param mobs
*/
public void registerMobs(int... mobs)
{
addAttackId(mobs);
addKillId(mobs);
addSpawnId(mobs);
addSpellFinishedId(mobs);
addSkillSeeId(mobs);
addAggroRangeEnterId(mobs);
addFactionCallId(mobs);
}
/**
* Broadcasts SocialAction packet to self and known players.
* @param character
* @param actionId
*/
protected void broadcastSocialAction(L2Character character, int actionId)
{
Broadcast.toSelfAndKnownPlayers(character, new SocialAction(character.getObjectId(), actionId));
}
/**
* Broadcasts SocialAction packet to self and known players in specific radius.
* @param character
* @param actionId
* @param radius
*/
protected void broadcastSocialAction(L2Character character, int actionId, int radius)
{
Broadcast.toSelfAndKnownPlayersInRadius(character, new SocialAction(character.getObjectId(), actionId), radius);
}
public void spawnMinions(L2Npc npc, String spawnName)
{
for (MinionHolder is : npc.getParameters().getMinionList(spawnName))
{
addMinion((L2MonsterInstance) npc, is.getId());
}
}
}