diff --git a/L2J_DataPack_BETA/dist/game/data/scripts/ai/npc/ListenerTest.java b/L2J_DataPack_BETA/dist/game/data/scripts/ai/npc/ListenerTest.java index 17263d560acb9b249d75eb1e006d8134cb43a24f..f78569f95954fa108fe570be3103e734b472e4c4 100644 --- a/L2J_DataPack_BETA/dist/game/data/scripts/ai/npc/ListenerTest.java +++ b/L2J_DataPack_BETA/dist/game/data/scripts/ai/npc/ListenerTest.java @@ -20,17 +20,20 @@ package ai.npc; import java.util.logging.Level; +import com.l2jserver.gameserver.model.actor.L2Attackable; import com.l2jserver.gameserver.model.events.EventType; import com.l2jserver.gameserver.model.events.ListenerRegisterType; -import com.l2jserver.gameserver.model.events.annotations.Item; -import com.l2jserver.gameserver.model.events.annotations.Npc; +import com.l2jserver.gameserver.model.events.annotations.Id; +import com.l2jserver.gameserver.model.events.annotations.NpcLevelRange; +import com.l2jserver.gameserver.model.events.annotations.Range; import com.l2jserver.gameserver.model.events.annotations.RegisterEvent; import com.l2jserver.gameserver.model.events.annotations.RegisterType; -import com.l2jserver.gameserver.model.events.annotations.Residence; import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill; import com.l2jserver.gameserver.model.events.impl.character.npc.attackable.OnAttackableAttack; import com.l2jserver.gameserver.model.events.impl.item.OnItemCreate; import com.l2jserver.gameserver.model.events.impl.sieges.castle.OnCastleSiegeStart; +import com.l2jserver.gameserver.model.holders.ItemHolder; +import com.l2jserver.util.Rnd; /** * An example usage of Listeners. @@ -50,13 +53,6 @@ public class ListenerTest extends AbstractNpcAI // An set function which is a Consumer it has one parameter and doesn't returns anything! setAttackableAttackId(this::onAttackableAttack, ELPIES); - - // An Add function which is Function it has one parameter and returns either null or a class that extends {@link com.l2jserver.gameserver.model.events.returns.AbstractEventReturn} - addCreatureKillId(event -> - { - System.out.println("on " + event.getClass().getSimpleName() + " executed"); - return null; - }, ELPIES); } /** @@ -68,30 +64,28 @@ public class ListenerTest extends AbstractNpcAI _log.log(Level.INFO, getClass().getSimpleName() + ": " + event.getClass().getSimpleName() + " invoked attacker: " + event.getAttacker() + " target: " + event.getTarget() + " damage: " + event.getDamage() + " skill: " + event.getSkill()); } - @RegisterEvent(EventType.ON_CREATURE_KILL) - @RegisterType(ListenerRegisterType.NPC) - @Npc(20432) - @Npc(22228) /** * This method will be invoked as soon as L2Attackable (Rabbits 20432 and 22228) are being killed by L2PcInstance (a player) * @param event */ + @RegisterEvent(EventType.ON_CREATURE_KILL) + @RegisterType(ListenerRegisterType.NPC) + @Id(20432) + @Id(22228) public void onCreatureKill(OnCreatureKill event) { _log.log(Level.INFO, getClass().getSimpleName() + ": " + event.getClass().getSimpleName() + " invoked attacker: " + event.getAttacker() + " target: " + event.getTarget()); } - //@formatter:off - @RegisterEvent(EventType.ON_CASTLE_SIEGE_START) - @RegisterType(ListenerRegisterType.CASTLE) - @Residence({1, 2, 3}) - @Residence({4, 5, 6}) - @Residence({7, 8, 9}) - //@formatter:on /** * This method will be invoked as soon as Siege of castle ids 1-9 starts * @param event */ + //@formatter:off + @RegisterEvent(EventType.ON_CASTLE_SIEGE_START) + @RegisterType(ListenerRegisterType.CASTLE) + @Range(from = 1, to = 9) + //@formatter:on public void onSiegeStart(OnCastleSiegeStart event) { _log.log(Level.INFO, getClass().getSimpleName() + ": The siege of " + event.getSiege().getCastle().getName() + " (" + event.getSiege().getCastle().getResidenceId() + ") has started!"); @@ -99,12 +93,31 @@ public class ListenerTest extends AbstractNpcAI @RegisterEvent(EventType.ON_ITEM_CREATE) @RegisterType(ListenerRegisterType.ITEM) - @Item(5575) + @Id(5575) public void onItemCreate(OnItemCreate event) { _log.log(Level.INFO, getClass().getSimpleName() + ": Item [" + event.getItem() + "] has been created actor: " + event.getActiveChar() + " process: " + event.getProcess() + " reference: " + event.getReference()); } + @RegisterEvent(EventType.ON_CREATURE_KILL) + @RegisterType(ListenerRegisterType.NPC) + @NpcLevelRange(from = 1, to = 10) + public void OnCreatureKill(OnCreatureKill event) + { + // 70% chance to drop + if (Rnd.get(100) >= 70) + { + return; + } + + // Make sure a player killed this monster. + if ((event.getAttacker() != null) && event.getAttacker().isPlayable() && event.getTarget().isAttackable()) + { + final L2Attackable monster = (L2Attackable) event.getTarget(); + monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(57, Rnd.get(100, 1000))); + } + } + public static void main(String[] args) { new ListenerTest();