U3Games

Games | Desarrollo & Soporte => L2 | Sección de Servidores => Lineage => L2 | Implementaciones => Mensaje iniciado por: Swarlog en Jul 26, 2025, 10:59 PM

Título: Drop kill npc example
Publicado por: Swarlog en Jul 26, 2025, 10:59 PM
/*
 * Copyright (C) 2004-2014 L2J DataPack
 *
 * This file is part of L2J DataPack.
 *
 * L2J DataPack 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.
 *
 * L2J DataPack 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.npc;

import java.util.HashSet;
import java.util.Set;

import com.l2jserver.gameserver.datatables.NpcData;
import com.l2jserver.gameserver.model.actor.L2Attackable;
import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate;
import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill;
import com.l2jserver.gameserver.model.holders.ItemHolder;
import com.l2jserver.util.Rnd;

/**
 * @author UnAfraid
 */
public final class DropExample extends AbstractNpcAI
{

private int MinLvl = 1;
private int MaxLvl = 2;
private int ItemId = null;
private int MinItem = 1;
private int MaxItem = 1;

private SetMobLvl(int min, int max)
{
MinLvl = min;
MaxLvl = max;
}

private SetItem(int item, int min, int max)
{
ItemId = item;
MinItem = min;
MaxItem = max;
}

private CreateDrop()
{
SetMobLvl(1,10);
SetItem(57,100,1000);
DropExample();
SetItem(1206,1,1);
DropExample();

SetMobLvl(11,20);
SetItem(57,1000,2600);
DropExample();
}

private DropExample()
{
super(DropExample.class.getSimpleName(), "ai");

// Temporary npc id holder
final Set<Integer> npcIds = new HashSet<>();

// Get templates of npc between level 1 and level 10
for (int i = MinLvl; i < MaxLvl; i++)
{
// Transform templates into npc ids and add them into npcIds Set
NpcData.getInstance().getAllMonstersOfLevel(i).stream().map(L2NpcTemplate::getId).forEach(id -> npcIds.add(id));
}

// Register templates for event notification.
setCreatureKillId(this::OnCreatureKill, npcIds);
}

public void OnCreatureKill(OnCreatureKill event)
{
// 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(ItemId, Rnd.get(MinItem, MaxItem)));
}
}

public static void main(String[] args)
{
new CreateDrop();
}
}