l2j_mobius/trunk/dist/game/data/scripts/ai/others/Incarnation.java
2016-06-12 01:34:09 +00:00

80 lines
2.7 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 ai.others;
import com.l2jmobius.gameserver.ai.CtrlIntention;
import com.l2jmobius.gameserver.model.L2Object;
import com.l2jmobius.gameserver.model.actor.L2Character;
import com.l2jmobius.gameserver.model.actor.L2Npc;
import com.l2jmobius.gameserver.model.events.EventType;
import com.l2jmobius.gameserver.model.events.ListenerRegisterType;
import com.l2jmobius.gameserver.model.events.annotations.Id;
import com.l2jmobius.gameserver.model.events.annotations.RegisterEvent;
import com.l2jmobius.gameserver.model.events.annotations.RegisterType;
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureAttack;
import com.l2jmobius.gameserver.model.events.impl.character.OnCreatureSkillFinishCast;
import com.l2jmobius.gameserver.model.events.impl.character.npc.OnNpcSpawn;
import com.l2jmobius.gameserver.model.events.listeners.ConsumerEventListener;
import ai.AbstractNpcAI;
/**
* @author Nik
*/
public final class Incarnation extends AbstractNpcAI
{
public Incarnation()
{
}
@RegisterEvent(EventType.ON_NPC_SPAWN)
@RegisterType(ListenerRegisterType.NPC)
@Id(13302)
@Id(13303)
@Id(13304)
@Id(13305)
@Id(13455)
@Id(13456)
@Id(13457)
public void onNpcSpawn(OnNpcSpawn event)
{
final L2Npc npc = event.getNpc();
if (npc.getSummoner() != null)
{
npc.getSummoner().addListener(new ConsumerEventListener(npc, EventType.ON_CREATURE_ATTACK, (OnCreatureAttack e) -> onOffense(npc, e.getAttacker(), e.getTarget()), this));
npc.getSummoner().addListener(new ConsumerEventListener(npc, EventType.ON_CREATURE_SKILL_FINISH_CAST, (OnCreatureSkillFinishCast e) -> onOffense(npc, e.getCaster(), e.getTarget()), this));
}
}
public void onOffense(L2Npc npc, L2Character attacker, L2Object target)
{
if ((attacker == target) || (npc.getSummoner() == null))
{
return;
}
// Attack target of summoner
npc.setRunning();
npc.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
}
public static void main(String[] args)
{
new Incarnation();
}
}