Shouldn't be using that lolCode:while (true) {
|
In sendDrop method
Code:Charms charm = calculateCharm(killer, this); if (charm != null) { int charmCount = getCharmsAmount(this, charm); Drop charmDrop = Drop.create(charm.getItemId(), 100, charmCount, charmCount, false); if (killer.getInventory().containsItem(9952, 1)) {// charming // imp if (killer.getInventory().containsItem(charm.getItemId(), 1) || killer.getInventory().hasFreeSlots()) killer.getInventory().addItem(new Item(charmDrop.getItemId(), charmCount)); else drops.add(charmDrop); } else drops.add(charmDrop); }
Add methods
Code:private enum Charms { GOLD_CHARM(12158, 45.0), GREEN_CHARM(12159, 27.0), CRIMSON_CHARM(12160, 11.0), BLUE_CHARM(12163, 5.0); private int itemId; private double chance; private Charms(int itemId, double chance) { this.itemId = itemId; this.chance = chance; } public int getItemId() { return itemId; } public double getChance() { return chance; } }Code:private double NO_CHARMS_CHANCE = 50;Code:private Charms calculateCharm(Player player, NPC npc) { if (npc.getCombatLevel() < 10) return null; if ((npc.getId() != 7134) && Utils.getRandomDouble(100) < NO_CHARMS_CHANCE) return null; while (true) { double chance = Utils.getRandomDouble(100); Charms charm = Charms.values()[Utils.getRandom(Charms.values().length - 1)]; if ((charm.getChance()) > chance) { return charm; } else continue; } }Code:private int getCharmsAmount(NPC npc, Charms charm) { if (npc.getId() == 7134) return Utils.random(10, 38); int charmAmount = (int) (Utils.random(npc.getCombatLevel()) * 0.1); switch (charm) { case BLUE_CHARM: return charmAmount; case CRIMSON_CHARM: return charmAmount; case GOLD_CHARM: return charmAmount; case GREEN_CHARM: return charmAmount; } return -1; }
Shouldn't be using that lolCode:while (true) {
As Oak said, shouldn't use an endless loop. Even though it will continually just "continue" it'll still use up resource. Plus I don't think you even need it to loop it? You just need it once.
Could also modify the getCharmsAmount method into this:
It's pretty nice overall, no major mistakes whatsoever. Clean code, good job.Code:private int getCharmsAmount(NPC npc, Charms charm) { if (npc.getId() == 7134) return Utils.random(10, 38); int charmAmount = (int) (Utils.random(npc.getCombatLevel()) * 0.1); switch (charm) { case BLUE_CHARM: case CRIMSON_CHARM: case GOLD_CHARM: case GREEN_CHARM: return charmAmount; default: return -1; } }
However, if you were really into the detail, you could essentially dump charm drop rates from RSWikia I believe. Most NPCs have the charm drop rates in percentages on their wiki pages. Surprised no one has dumped that data yet tbh.
EDIT: Decided to dump all combat NPC info from RSWikia (At least for the NPCs that exist in 562), including the charm percentages. A lot of the charms had a drop rate ranging from double to another double, so I decided to just add the two up and divide by two (Getting the middle value for them). Anyways, if anyone wants to use this data, feel free to. NOTE: It only contains 171 NPCs data (Went through 9300 NPCs in reality, but a lot of them were still missing some charm percentages on RSWikia and majority of the NPCs weren't even combat related NPCs - only 803 were - does not include any duplicates, goes by NPC name).
EDIT V2:
Refer to this link: https://www.rune-server.ee/showthrea...65#post5323565
Dumped data for up to revision 876 along with the amounts which weren't included before.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |