Hello,
The problem I encounter is that when I kill an npc, I only get the item that has a 100% drop rate chance.
Here is my
drop.java
Code:
package com.rs.game.npc;
public class Drop {
public static Drop create(int itemId, double rate, int minAmount,
int maxAmount, boolean rare) {
return new Drop((short) itemId, rate, minAmount, maxAmount, rare);
}
private int itemId, minAmount, maxAmount;
private double rate;
private boolean rare;
public Drop(int itemId, double rate, int minAmount, int maxAmount,
boolean rare) {
this.itemId = itemId;
this.rate = rate;
this.minAmount = minAmount;
this.maxAmount = maxAmount;
this.rare = rare;
}
public int getExtraAmount() {
return maxAmount - minAmount;
}
public int getItemId() {
return itemId;
}
public int getMaxAmount() {
return maxAmount;
}
public int getMinAmount() {
return minAmount;
}
public double getRate() {
return rate;
}
public boolean isFromRareTable() {
return rare;
}
public void setItemId(short itemId) {
this.itemId = itemId;
}
public void setMaxAmount(int amount) {
this.maxAmount = amount;
}
public void setMinAmount(int amount) {
this.minAmount = amount;
}
public void setRate(double rate) {
this.rate = rate;
}
}
npcdrops.java
Code:
package com.rs.utils;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import com.rs.game.npc.Drop;
public class NPCDrops {
private final static String PACKED_PATH = "data/npcs/packedDrops.d";
private static HashMap<Integer, Drop[]> npcDrops;
public static final void init() {
loadPackedNPCDrops();
}
public static Drop[] getDrops(int npcId) {
return npcDrops.get(npcId);
}
private Map<Integer, ArrayList<Drop>> dropMapx = null;
public Map<Integer, ArrayList<Drop>> getDropArray() {
if (dropMapx == null)
dropMapx = new LinkedHashMap<Integer, ArrayList<Drop>>();
// dropMapx = new LinkedHashMap<Integer, ArrayList<Drop>>();
for (int i : npcDrops.keySet()) {
int npcId = i;
ArrayList<Drop> temp = new ArrayList<Drop>();
for (Drop mainDrop : npcDrops.get(npcId)) {
temp.add(mainDrop);
}
dropMapx.put(i, temp);
}
return dropMapx;
}
public void insertDrop(int npcID, Drop d) {
loadPackedNPCDrops();
Drop[] oldDrop = npcDrops.get(npcID);
if (oldDrop == null) {
npcDrops.put(npcID, new Drop[] { d });
} else {
int length = oldDrop.length;
Drop destination[] = new Drop[length + 1];
System.arraycopy(oldDrop, 0, destination, 0, length);
destination[length] = d;
npcDrops.put(npcID, destination);
}
}
private static void loadPackedNPCDrops() {
try {
RandomAccessFile in = new RandomAccessFile(PACKED_PATH, "r");
FileChannel channel = in.getChannel();
ByteBuffer buffer = channel.map(MapMode.READ_ONLY, 0,
channel.size());
int dropSize = buffer.getShort() & 0xffff;
npcDrops = new HashMap<Integer, Drop[]>(dropSize);
for (int i = 0; i < dropSize; i++) {
int npcId = buffer.getShort() & 0xffff;
Drop[] drops = new Drop[buffer.getShort() & 0xffff];
for (int d = 0; d < drops.length; d++) {
if (buffer.get() == 0)
drops[d] = new Drop(buffer.getShort() & 0xffff,
buffer.getDouble(), buffer.getInt(),
buffer.getInt(), false);
else
drops[d] = new Drop(0, 0, 0, 0, true);
}
npcDrops.put(npcId, drops);
}
channel.close();
in.close();
} catch (Throwable e) {
Logger.handle(e);
}
}
public HashMap<Integer, Drop[]> getDropMap() {
return npcDrops;
}
}
in npc.java the public void drop method.
Code:
public void drop() {
try {
Drop[] drops = NPCDrops.getDrops(id);
if (drops == null)
return;
Player killer = getMostDamageReceivedSourcePlayer();
if (killer == null)
return;
if (isCyclops(getDefinitions().name) && Utils.random(500) > 400) {
World.addGroundItem(new Item(whatDefender(), 1), new WorldTile(
this.getLastWorldTile()), killer, true, 180, true);
}
if (isRevenantNPC(getDefinitions().name) && Utils.random(65) == 0) {
World.addGroundItem(
new Item(BRAWLING_REWARDS[Utils
.random(BRAWLING_REWARDS.length - 1)], 1),
new WorldTile(this.getLastWorldTile()), killer, true,
180, true);
}
if (isRevenantNPC(getDefinitions().name)
&& killer.checkTotalLevel(350) < 350
&& Utils.random(3000) >= 2700) {
int pvpItem = PVP_ITEMS[Utils.random(PVP_ITEMS.length - 1)];
World.addGroundItem(
new Item(pvpItem, pvpItem == 13882 ? Utils.random(30)
: pvpItem == 13879 ? Utils.random(30) : 1),
new WorldTile(this.getLastWorldTile()), killer, true,
180, true);
return;
} else if (isRevenantNPC(getDefinitions().name)
&& killer.checkTotalLevel(1500) > 1000
&& Utils.random(1000) >= 900) {
int pvpItem = PVP_ITEMS[Utils.random(PVP_ITEMS.length - 1)];
World.addGroundItem(
new Item(pvpItem, pvpItem == 13882 ? Utils.random(30)
: pvpItem == 13879 ? Utils.random(30) : 1),
new WorldTile(this.getLastWorldTile()), killer, true,
180, true);
return;
} else if (isRevenantNPC(getDefinitions().name)) {
World.addGroundItem(new Item(995, Utils.random(5000)),
new WorldTile(this.getLastWorldTile()), killer, true,
180, true);
return;
}
if (isLucien(getDefinitions().name) && Utils.random(15) == 0) {
World.addGroundItem(
new Item(LUCIEN_REWARDS[Utils
.random(LUCIEN_REWARDS.length - 1)], 1),
new WorldTile(this.getLastWorldTile()), killer, true,
180, true);
}
Drop[] possibleDrops = new Drop[drops.length];
Item ring = killer.getEquipment().getItem(Equipment.SLOT_RING);
int possibleDropsCount = 0;
for (Drop drop : drops) {
if (drop.getRate() == 100) {
sendDrop(killer, drop);
} else {
if (Utils.random(1, 100) <= (drop.getRate() * killer.getDropBoost())) {
possibleDrops[possibleDropsCount++] = drop;
}
}
}
if (onLowPointsTable(getDefinitions().name)) {
killer.setPvmPoints(killer.getPvmPoints() + 10);
killer.getPackets().sendGameMessage(
"You've been awarded 10 PvM points for your effort, you now have "
+ killer.getPvmPoints() + " Points.");
} else if (onMedPointsTable(getDefinitions().name)) {
killer.setPvmPoints(killer.getPvmPoints() + 35);
killer.getPackets().sendGameMessage(
"You've been awarded 35 PvM points for your effort, you now have "
+ killer.getPvmPoints() + " Points.");
} else if (onHighPointsTable(getDefinitions().name)) {
killer.setPvmPoints(killer.getPvmPoints() + 100);
killer.getPackets().sendGameMessage(
"You've been awarded 100 PvM points for your effort, you now have "
+ killer.getPvmPoints() + " Points.");
}
if (possibleDropsCount > 0)
sendDrop(killer,
possibleDrops[Utils.getRandom(possibleDropsCount - 1)]);
if (getCombatLevel() > 100) {
if (Utils.random(3) == 0)
dropCharm(killer,
HIGH_CHARMS_DROP[Utils
.random(HIGH_CHARMS_DROP.length)], id);
return;
} else if (getCombatLevel() > 50) {
if (Utils.random(3) == 0)
dropCharm(killer,
MED_CHARMS_DROP[Utils
.random(MED_CHARMS_DROP.length)], id);
return;
} else if (getCombatLevel() < 50) {
if (Utils.random(3) == 0)
dropCharm(killer,
LOW_CHARMS_DROP[Utils
.random(LOW_CHARMS_DROP.length)], id);
return;
}
} catch (Exception e) {
e.printStackTrace();
} catch (Error e) {
e.printStackTrace();
}
}