Finally got around to modifying what you gave me in a IDE (i'm liking netbeans) and still taking a my java courses so I'm still very much a noob but I'm definitely starting to understand things quite a bit more than when i first made this post.
If the code is indeted weird I noticed toggling 'Line Numbers' corrects this.
Code: Select all
package ai.npc; import java.util.List; import java.util.ArrayList; import java.util.Set; import java.util.HashSet; import java.util.Optional; import com.l2jserver.gameserver.datatables.NpcData; import com.l2jserver.gameserver.model.actor.L2Attackable; import com.l2jserver.gameserver.model.events.impl.character.OnCreatureKill; import com.l2jserver.gameserver.model.holders.ItemHolder; /** * @author jurchiks */ public final class DropExample extends AbstractNpcAI { private static final List<DropDetails> DROP_DATA = new ArrayList<>(); static { DROP_DATA.add(new DropDetails(1, 10, new DropItem(57, 100, 1000, 1000000), new DropItem(1206, 1, 1, 5000, false))); DROP_DATA.add(new DropDetails(11, 20, new DropItem(57, 1000, 2600, 1000000))); // and so on... } private static class DropDetails { public final int minLevel; public final int maxLevel; private final List<DropItem> itemDrops; public DropDetails(int minLevel, int maxLevel, DropItem... drops) { this.minLevel = minLevel; this.maxLevel = maxLevel; for (drop : drops) { if (drop != null) { itemDrops.add(drop); } } } public List<DropItem> getDrops() { return this.itemDrops; } } private static class DropItem { public final int itemId; public final int minCount; public final int maxCount; public final int dropChance; public final boolean isSpoil; public DropItem(int itemId, int minCount, int maxCount, int dropChance) { this.itemId = itemId; this.minCount = minCount; this.maxCount = maxCount; this.dropChance = dropChance; this.isSpoil = false; } public DropItem(int itemId, int minCount, int maxCount, int dropChance, boolean isSpoil) { this.itemId = itemId; this.minCount = minCount; this.maxCount = maxCount; this.dropChance = dropChance; this.isSpoil = isSpoil; } public boolean dropBySpoil(){ return this.isSpoil; } } private DropExample() { super(DropExample.class.getSimpleName(), "ai/npc"); final Set<Integer> npcIds = new HashSet<>(); for (DropDetails details : DROP_DATA) { NpcData.getInstance().findTemplates(t -> (t.getLevel() >= details.minLevel) && (t.getLevel() <= details.maxLevel)) .forEach(t -> npcIds.add(t.getId())); } 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(); // find drop data based on monster's level, can't do it any other way since drop data is stored in a list, not a map final Optional<DropDetails> dd = DROP_DATA.stream().filter(dd -> monster.getLevel() >= dd.minLevel && monster.getLevel() <= dd.maxLevel) .findFirst(); // drop details for NPC's level were found, use them if (dd.isPresent()) { for (DropItem di : dd.get().getDrops()) { // Drops the item normally if drop chance is achieved and not a spoil type drop. if (getRandom(0,1000000) <= di.dropChance &! di.dropBySpoil()) { monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(di.itemId, getRandom(di.minCount, di.maxCount))); } // Changes drop type if the spoil condition is true else if (di.dropBySpoil() && getRandom(0,1000000) <= di.dropChance) monster.dropItem(event.getAttacker().getActingPlayer(), new ItemHolder(di.itemId, getRandom(di.minCount, di.maxCount))); } } } } public static void main(String[] args) { new DropExample(); } }
Only question I got now, Is on my line 118 (I guess its
119 on here since line 1 is blank.) what would I have to modify in that statement to change it to a spoil drop type instead of a regular drop ?