Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: java/com/l2jserver/gameserver/model/L2DropCategory.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/L2DropCategory.java (revision 4580)
- +++ java/com/l2jserver/gameserver/model/L2DropCategory.java (working copy)
- @@ -14,6 +14,8 @@
- */
- package com.l2jserver.gameserver.model;
- +import java.util.List;
- +
- import javolution.util.FastList;
- import com.l2jserver.Config;
- @@ -21,105 +23,72 @@
- /**
- *
- - * @author Fulminus
- + * @author Nik
- */
- public class L2DropCategory
- {
- - private FastList<L2DropData> _drops;
- - private int _categoryChance; // a sum of chances for calculating if an item will be dropped from this category
- - private int _categoryBalancedChance; // sum for balancing drop selection inside categories in high rate servers
- - private int _categoryType;
- -
- - public L2DropCategory(int categoryType)
- + public enum CategoryType
- {
- - _categoryType = categoryType;
- - _drops = new FastList<L2DropData>(0);
- - _categoryChance = 0;
- - _categoryBalancedChance = 0;
- + NORMAL, SWEEP, HERB, RAID, VITALITY_HERBS, HP_HERBS, MP_HERBS, SPECIAL_HERBS, COMMON_HERBS
- }
- - public void addDropData(L2DropData drop, boolean raid)
- - {
- - boolean found = false;
- -
- - if (drop.isQuestDrop()) {
- - //if (_questDrops == null)
- - // _questDrops = new FastList<L2DropData>(0);
- - //_questDrops.add(drop);
- - }
- - else
- - {
- - if (Config.CUSTOM_DROPLIST_TABLE)
- - {
- - // If the drop exists is replaced
- - for (L2DropData d : _drops)
- - {
- - if (d.getItemId() == drop.getItemId())
- - {
- - d.setMinDrop(drop.getMinDrop());
- - d.setMaxDrop(drop.getMaxDrop());
- - if (d.getChance() != drop.getChance())
- - {
- - // Re-calculate Chance
- - _categoryChance -= d.getChance();
- - _categoryBalancedChance -= Math.min((d.getChance() * Config.RATE_DROP_ITEMS), L2DropData.MAX_CHANCE);
- - d.setChance(drop.getChance());
- - _categoryChance += d.getChance();
- - _categoryBalancedChance += Math.min((d.getChance() * Config.RATE_DROP_ITEMS), L2DropData.MAX_CHANCE);
- - }
- - found = true;
- - break;
- - }
- - }
- - }
- -
- - if (!found)
- - {
- - _drops.add(drop);
- - _categoryChance += drop.getChance();
- - // for drop selection inside a category: max 100 % chance for getting an item, scaling all values to that.
- - _categoryBalancedChance += Math.min((drop.getChance()*(raid?Config.RATE_DROP_ITEMS_BY_RAID : Config.RATE_DROP_ITEMS)),L2DropData.MAX_CHANCE);
- - }
- - }
- - }
- + private final FastList<L2DropData> _drops;
- + private final int _categoryChance; // The chance that items are dropped from this category
- + private final CategoryType _categoryType;
- - public FastList<L2DropData> getAllDrops()
- + public L2DropCategory(CategoryType ct, int categoryChance)
- {
- - return _drops;
- - }
- -
- - public void clearAllDrops()
- - {
- - _drops.clear();
- - }
- -
- - public boolean isSweep()
- - {
- - return (getCategoryType()==-1);
- - }
- -
- - // this returns the chance for the category to be visited in order to check if
- - // drops might come from it. Category -1 (spoil) must always be visited
- - // (but may return 0 or many drops)
- - public int getCategoryChance()
- - {
- - if (getCategoryType() >= 0)
- - return _categoryChance;
- - else
- - return L2DropData.MAX_CHANCE;
- - }
- -
- - public int getCategoryBalancedChance()
- - {
- - if (getCategoryType() >= 0)
- - return _categoryBalancedChance;
- - else
- - return L2DropData.MAX_CHANCE;
- + _drops = new FastList<L2DropData>(0);
- + _categoryChance = categoryChance;
- + _categoryType = ct;
- }
- - public int getCategoryType()
- + /**
- + * Modifies the param's drop chance with the config values of the corresponding category type
- + * then the item is added to the _drops, with a modified chance, which can exceed L2DropData.MAX_CHANCE
- + * @param drop
- + */
- + public void addDrop(L2DropData drop)
- {
- - return _categoryType;
- + int newDropChance = drop.getChance();
- + switch(_categoryType)
- + {
- + case NORMAL:
- + if (Config.RATE_DROP_ITEMS_ID.get(drop.getItemId()) != 0)
- + newDropChance *= Config.RATE_DROP_ITEMS_ID.get(drop.getItemId());
- + else
- + newDropChance *= Config.RATE_DROP_ITEMS;
- + break;
- + case SWEEP:
- + if (Config.RATE_DROP_ITEMS_ID.get(drop.getItemId()) != 0)
- + newDropChance *= Config.RATE_DROP_ITEMS_ID.get(drop.getItemId());
- + else
- + newDropChance *= Config.RATE_DROP_SPOIL;
- + break;
- + case RAID:
- + if (Config.RATE_DROP_ITEMS_ID.get(drop.getItemId()) != 0)
- + newDropChance *= Config.RATE_DROP_ITEMS_ID.get(drop.getItemId());
- + else
- + newDropChance *= Config.RATE_DROP_ITEMS_BY_RAID;
- + break;
- + case VITALITY_HERBS:
- + newDropChance *= Config.RATE_DROP_VITALITY_HERBS;
- + break;
- + case HP_HERBS:
- + newDropChance *= Config.RATE_DROP_HP_HERBS;
- + break;
- + case MP_HERBS:
- + newDropChance *= Config.RATE_DROP_MP_HERBS;
- + break;
- + case SPECIAL_HERBS:
- + newDropChance *= Config.RATE_DROP_SPECIAL_HERBS;
- + break;
- + case COMMON_HERBS:
- + newDropChance *= Config.RATE_DROP_COMMON_HERBS;
- + }
- +
- + drop.setChance(newDropChance);
- + _drops.add(drop);
- }
- /**
- @@ -136,28 +105,26 @@
- public synchronized L2DropData dropSeedAllowedDropsOnly()
- {
- FastList<L2DropData> drops = new FastList<L2DropData>();
- - int subCatChance = 0;
- - for (L2DropData drop : getAllDrops())
- + for (L2DropData drop : _drops)
- {
- - if ((drop.getItemId() == 57) || (drop.getItemId() == 6360)|| (drop.getItemId() == 6361)|| (drop.getItemId() == 6362))
- - {
- + if ((drop.getItemId() == 57) || (drop.getItemId() == 6360) || (drop.getItemId() == 6361) || (drop.getItemId() == 6362))
- drops.add(drop);
- - subCatChance += drop.getChance();
- - }
- }
- - // among the results choose one.
- - int randomIndex = Rnd.get(subCatChance);
- - int sum = 0;
- - for (L2DropData drop : drops)
- + while (!drops.isEmpty())
- {
- - sum += drop.getChance();
- -
- - if (sum > randomIndex) // drop this item and exit the function
- + // Get drop data from a random index
- + L2DropData dd = drops.get(Rnd.get(drops.size()));
- + if (dd.getChance() >= Rnd.get(L2DropData.MAX_CHANCE))
- + {
- + // This is the lucky drop :)
- + return dd;
- + }
- + else
- {
- - drops.clear();
- - drops=null;
- - return drop;
- + // This drop is unlucky :( so it wont drop.
- + // Remove this drop, since it already got checked
- + drops.remove(dd);
- }
- }
- // since it is still within category, only drop one of the acceptable drops from the results.
- @@ -165,43 +132,49 @@
- }
- /**
- - * ONE of the drops in this category is to be dropped now.
- - * to see which one will be dropped, weight all items' chances such that
- - * their sum of chances equals MAX_CHANCE.
- - * since the individual drops have their base chance, we also ought to use the
- - * base category chance for the weight. So weight = MAX_CHANCE/basecategoryDropChance.
- - * Then get a single random number within this range. The first item
- - * (in order of the list) whose contribution to the sum makes the
- - * sum greater than the random number, will be dropped.
- - *
- - * Edited: How _categoryBalancedChance works in high rate servers:
- - * Let's say item1 has a drop chance (when considered alone, without category) of
- - * 1 % * RATE_DROP_ITEMS and item2 has 20 % * RATE_DROP_ITEMS, and the server's
- - * RATE_DROP_ITEMS is for example 50x. Without this balancer, the relative chance inside
- - * the category to select item1 to be dropped would be 1/26 and item2 25/26, no matter
- - * what rates are used. In high rate servers people usually consider the 1 % individual
- - * drop chance should become higher than this relative chance (1/26) inside the category,
- - * since having the both items for example in their own categories would result in having
- - * a drop chance for item1 50 % and item2 1000 %. _categoryBalancedChance limits the
- - * individual chances to 100 % max, making the chance for item1 to be selected from this
- - * category 50/(50+100) = 1/3 and item2 100/150 = 2/3.
- - * This change doesn't affect calculation when drop_chance * RATE_DROP_ITEMS < 100 %,
- - * meaning there are no big changes for low rate servers and no changes at all for 1x
- - * servers.
- - *
- - * @return selected drop from category, or null if nothing is dropped.
- + * Gets a random index from the drop list, checks if the chance of the L2DropData
- + * corresponding to the index if bigger than Rnd.get(L2DropData.MAX_CHANCE)
- + * if so, this L2DropData will be returned, if not, it will go through the same
- + * loop with another L2DropData (not the same, since it gets removed).
- + * If no L2DropData gets chosen, it will return null.
- + * @return Lucky L2DropData or null if there is no lucky hit :)
- */
- - public synchronized L2DropData dropOne(boolean raid)
- + public synchronized L2DropData dropOne()
- {
- - int randomIndex = Rnd.get(getCategoryBalancedChance());
- - int sum = 0;
- - for (L2DropData drop : getAllDrops())
- + List<L2DropData> tmp = new FastList<L2DropData>();
- + tmp.addAll(_drops);
- + while (!tmp.isEmpty())
- {
- - sum += Math.min((drop.getChance()*(raid?Config.RATE_DROP_ITEMS_BY_RAID : Config.RATE_DROP_ITEMS)),L2DropData.MAX_CHANCE);
- -
- - if (sum >= randomIndex) // drop this item and exit the function
- - return drop;
- + // Get drop data from a random index
- + L2DropData dd = tmp.get(Rnd.get(tmp.size()));
- + if (dd.getChance() >= Rnd.get(L2DropData.MAX_CHANCE))
- + {
- + // This is the lucky drop :)
- + return dd;
- + }
- + else
- + {
- + // This drop is unlucky :( so it wont drop.
- + // Remove this drop, since it already got checked
- + tmp.remove(dd);
- + }
- }
- +
- return null;
- }
- +
- + public FastList<L2DropData> getDrops()
- + {
- + return _drops;
- + }
- +
- + public int getCategoryChance()
- + {
- + return _categoryChance;
- + }
- +
- + public CategoryType getCategoryType()
- + {
- + return _categoryType;
- + }
- }
- Index: java/com/l2jserver/gameserver/model/L2Skill.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/L2Skill.java (revision 4580)
- +++ java/com/l2jserver/gameserver/model/L2Skill.java (working copy)
- @@ -464,8 +464,8 @@
- _magicLevel = set.getInteger("magicLvl", SkillTreeTable.getInstance().getMinSkillLevel(_id, _level));
- _levelDepend = set.getInteger("lvlDepend", 0);
- _ignoreResists = set.getBool("ignoreResists", false);
- - _minChance = set.getInteger("minChance", 1);
- - _maxChance = set.getInteger("maxChance", 99);
- + _minChance = set.getInteger("minChance", 10);
- + _maxChance = set.getInteger("maxChance", 90);
- _stat = set.getEnum("stat", Stats.class, null);
- _ignoreShield = set.getBool("ignoreShld", false);
- _skillType = set.getEnum("skillType", L2SkillType.class);
- Index: java/com/l2jserver/gameserver/model/actor/L2Attackable.java
- ===================================================================
- --- java/com/l2jserver/gameserver/model/actor/L2Attackable.java (revision 4580)
- +++ java/com/l2jserver/gameserver/model/actor/L2Attackable.java (working copy)
- @@ -32,7 +32,6 @@
- import com.l2jserver.gameserver.ai.L2SiegeGuardAI;
- import com.l2jserver.gameserver.datatables.EventDroplist;
- import com.l2jserver.gameserver.datatables.EventDroplist.DateDrop;
- -import com.l2jserver.gameserver.datatables.HerbDropTable;
- import com.l2jserver.gameserver.datatables.ItemTable;
- import com.l2jserver.gameserver.datatables.SkillTable;
- import com.l2jserver.gameserver.instancemanager.CursedWeaponsManager;
- @@ -247,7 +246,7 @@
- public int getCount() { return _count;}
- }
- - private FastMap<L2Character, AggroInfo> _aggroList = new FastMap<L2Character, AggroInfo>().shared();
- + private final FastMap<L2Character, AggroInfo> _aggroList = new FastMap<L2Character, AggroInfo>().shared();
- public final FastMap<L2Character, AggroInfo> getAggroList()
- {
- @@ -301,7 +300,7 @@
- private boolean _absorbed;
- - private FastMap<Integer, AbsorberInfo> _absorbersList = new FastMap<Integer, AbsorberInfo>().shared();
- + private final FastMap<Integer, AbsorberInfo> _absorbersList = new FastMap<Integer, AbsorberInfo>().shared();
- private boolean _mustGiveExpSp;
- @@ -555,10 +554,10 @@
- private static class OnKillNotifyTask implements Runnable
- {
- - private L2Attackable _attackable;
- - private Quest _quest;
- - private L2PcInstance _killer;
- - private boolean _isPet;
- + private final L2Attackable _attackable;
- + private final Quest _quest;
- + private final L2PcInstance _killer;
- + private final boolean _isPet;
- public OnKillNotifyTask(L2Attackable attackable, Quest quest, L2PcInstance killer, boolean isPet)
- {
- @@ -1331,38 +1330,13 @@
- // Check if an Item from this category must be dropped
- if (Rnd.get(L2DropData.MAX_CHANCE) < categoryDropChance)
- {
- - L2DropData drop = categoryDrops.dropOne(isRaid() && !isRaidMinion());
- + // Drop's chance (increased by configs) is calculated inside L2DropCategory
- + // this chance can exceed L2DropData.MAX_CHANCE;
- + L2DropData drop = categoryDrops.dropOne();
- if (drop == null)
- return null;
- - // Now decide the quantity to drop based on the rates and penalties. To get this value
- - // simply divide the modified categoryDropChance by the base category chance. This
- - // results in a chance that will dictate the drops amounts: for each amount over 100
- - // that it is, it will give another chance to add to the min/max quantities.
- -
- - // For example, If the final chance is 120%, then the item should drop between
- - // its min and max one time, and then have 20% chance to drop again. If the final
- - // chance is 330%, it will similarly give 3 times the min and max, and have a 30%
- - // chance to give a 4th time.
- - // At least 1 item will be dropped for sure. So the chance will be adjusted to 100%
- - // if smaller.
- -
- - int dropChance = drop.getChance();
- -
- - if (Config.RATE_DROP_ITEMS_ID.get(drop.getItemId()) != 0)
- - dropChance *= Config.RATE_DROP_ITEMS_ID.get(drop.getItemId());
- - else
- - dropChance *= isRaid() && !isRaidMinion() ? Config.RATE_DROP_ITEMS_BY_RAID : Config.RATE_DROP_ITEMS;
- -
- - if (Config.L2JMOD_CHAMPION_ENABLE && isChampion())
- - dropChance *= Config.L2JMOD_CHAMPION_REWARDS;
- -
- - dropChance = Math.round(dropChance);
- -
- - if (dropChance < L2DropData.MAX_CHANCE)
- - dropChance = L2DropData.MAX_CHANCE;
- -
- // Get min and max Item quantity that can be dropped in one time
- int min = drop.getMinDrop();
- int max = drop.getMaxDrop();
- @@ -1371,9 +1345,9 @@
- int itemCount = 0;
- // Count and chance adjustment for high rate servers
- - if (dropChance > L2DropData.MAX_CHANCE && !Config.PRECISE_DROP_CALCULATION)
- + if (drop.getChance() > L2DropData.MAX_CHANCE && !Config.PRECISE_DROP_CALCULATION)
- {
- - int multiplier = dropChance / L2DropData.MAX_CHANCE;
- + int multiplier = drop.getChance() / L2DropData.MAX_CHANCE;
- if (min < max)
- itemCount += Rnd.get(min * multiplier, max * multiplier);
- @@ -1382,12 +1356,12 @@
- else
- itemCount += multiplier;
- - dropChance = dropChance % L2DropData.MAX_CHANCE;
- + drop.setChance(drop.getChance() % L2DropData.MAX_CHANCE);
- }
- // Check if the Item must be dropped
- int random = Rnd.get(L2DropData.MAX_CHANCE);
- - while (random < dropChance)
- + while (random < drop.getChance())
- {
- // Get the item quantity dropped
- if (min < max)
- @@ -1397,8 +1371,8 @@
- else
- itemCount++;
- - // Prepare for next iteration if dropChance > L2DropData.MAX_CHANCE
- - dropChance -= L2DropData.MAX_CHANCE;
- + // Prepare for next iteration if drop.getChance() > L2DropData.MAX_CHANCE
- + drop.setChance(drop.getChance() - L2DropData.MAX_CHANCE);
- }
- if (Config.L2JMOD_CHAMPION_ENABLE)
- // TODO (April 11, 2009): Find a way not to hardcode these values.
- @@ -1443,138 +1417,6 @@
- return 0;
- }
- - private RewardItem calculateCategorizedHerbItem(L2PcInstance lastAttacker, L2DropCategory categoryDrops)
- - {
- - if (categoryDrops == null)
- - return null;
- -
- - // Get default drop chance for the category (that's the sum of chances for all items in the category)
- - // keep track of the base category chance as it'll be used later, if an item is drop from the category.
- - // for everything else, use the total "categoryDropChance"
- - int basecategoryDropChance = categoryDrops.getCategoryChance() ;
- - int categoryDropChance = basecategoryDropChance;
- -
- - // Applies Drop rates
- - switch(categoryDrops.getCategoryType())
- - {
- - case 0:
- - if (Config.ENABLE_DROP_VITALITY_HERBS)
- - categoryDropChance *= Config.RATE_DROP_VITALITY_HERBS;
- - else
- - return null;
- - break;
- - case 1:
- - categoryDropChance *= Config.RATE_DROP_HP_HERBS;
- - break;
- - case 2:
- - categoryDropChance *= Config.RATE_DROP_MP_HERBS;
- - break;
- - case 3:
- - categoryDropChance *= Config.RATE_DROP_SPECIAL_HERBS;
- - break;
- - default:
- - categoryDropChance *= Config.RATE_DROP_COMMON_HERBS;
- - }
- -
- - // Round drop chance
- - categoryDropChance = Math.round(categoryDropChance);
- -
- - // Set our limits for chance of drop
- - if (categoryDropChance < 1)
- - categoryDropChance = 1;
- -
- - // Check if an Item from this category must be dropped
- - if (Rnd.get(L2DropData.MAX_CHANCE) < categoryDropChance)
- - {
- - L2DropData drop = categoryDrops.dropOne(false);
- -
- - if (drop == null)
- - return null;
- -
- - // Now decide the quantity to drop based on the rates and penalties. To get this value
- - // simply divide the modified categoryDropChance by the base category chance. This
- - // results in a chance that will dictate the drops amounts: for each amount over 100
- - // that it is, it will give another chance to add to the min/max quantities.
- -
- - // For example, If the final chance is 120%, then the item should drop between
- - // its min and max one time, and then have 20% chance to drop again. If the final
- - // chance is 330%, it will similarly give 3 times the min and max, and have a 30%
- - // chance to give a 4th time.
- - // At least 1 item will be dropped for sure. So the chance will be adjusted to 100%
- - // if smaller.
- -
- - int dropChance = drop.getChance();
- -
- - switch(categoryDrops.getCategoryType())
- - {
- - case 0:
- - dropChance *= Config.RATE_DROP_VITALITY_HERBS;
- - break;
- - case 1:
- - dropChance *= Config.RATE_DROP_HP_HERBS;
- - break;
- - case 2:
- - dropChance *= Config.RATE_DROP_MP_HERBS;
- - break;
- - case 3:
- - dropChance *= Config.RATE_DROP_SPECIAL_HERBS;
- - break;
- - default:
- - dropChance *= Config.RATE_DROP_COMMON_HERBS;
- - }
- -
- -
- - dropChance = Math.round(dropChance);
- -
- - if (dropChance < L2DropData.MAX_CHANCE)
- - dropChance = L2DropData.MAX_CHANCE;
- -
- - // Get min and max Item quantity that can be dropped in one time
- - int min = drop.getMinDrop();
- - int max = drop.getMaxDrop();
- -
- - // Get the item quantity dropped
- - int itemCount = 0;
- -
- - // Count and chance adjustment for high rate servers
- - if (dropChance > L2DropData.MAX_CHANCE && !Config.PRECISE_DROP_CALCULATION)
- - {
- - int multiplier = dropChance / L2DropData.MAX_CHANCE;
- -
- - if (min < max)
- - itemCount += Rnd.get(min * multiplier, max * multiplier);
- - else if (min == max)
- - itemCount += min * multiplier;
- - else
- - itemCount += multiplier;
- -
- - dropChance = dropChance % L2DropData.MAX_CHANCE;
- - }
- -
- - // Check if the Item must be dropped
- - int random = Rnd.get(L2DropData.MAX_CHANCE);
- - while (random < dropChance)
- - {
- - // Get the item quantity dropped
- - if (min < max)
- - itemCount += Rnd.get(min, max);
- - else if (min == max)
- - itemCount += min;
- - else
- - itemCount++;
- -
- - // Prepare for next iteration if dropChance > L2DropData.MAX_CHANCE
- - dropChance -= L2DropData.MAX_CHANCE;
- - }
- -
- - if (itemCount > 0)
- - return new RewardItem(drop.getItemId(), itemCount);
- - else if (itemCount == 0 && Config.DEBUG)
- - _log.fine("Roll produced no drops.");
- - }
- - return null;
- - }
- -
- public void doItemDrop(L2Character lastAttacker)
- {
- doItemDrop(getTemplate(),lastAttacker);
- @@ -1621,14 +1463,14 @@
- for(L2DropCategory cat:npcTemplate.getDropData())
- {
- RewardItem item = null;
- - if (cat.isSweep())
- + if (cat.getCategoryType() == L2DropCategory.CategoryType.SWEEP)
- {
- // according to sh1ny, seeded mobs CAN be spoiled and swept.
- if ( isSpoil()/* && !isSeeded() */)
- {
- FastList<RewardItem> sweepList = new FastList<RewardItem>();
- - for(L2DropData drop: cat.getAllDrops() )
- + for(L2DropData drop: cat.getDrops() )
- {
- item = calculateRewardItem(player, drop, levelModifier, true);
- if (item == null)
- @@ -1705,30 +1547,6 @@
- dropItem(player, item);
- }
- }
- -
- - //Instant Item Drop :>
- - if (getTemplate().dropherbgroup > 0)
- - {
- - for(L2DropCategory cat : HerbDropTable.getInstance().getHerbDroplist(getTemplate().dropherbgroup))
- - {
- - RewardItem item = calculateCategorizedHerbItem(player, cat);
- - if (item != null)
- - {
- - // more than one herb cant be auto looted!
- - int count = item.getCount();
- - if (count > 1)
- - {
- - item._count = 1;
- - for(int i = 0; i < count; i++)
- - dropItem(player, item);
- - }
- - else if (isFlying() || Config.AUTO_LOOT_HERBS)
- - player.addItem("Loot", item.getItemId(), count, this, true);
- - else
- - dropItem(player, item);
- - }
- - }
- - }
- }
- /**
- @@ -2297,7 +2115,7 @@
- private static class CommandChannelTimer implements Runnable
- {
- - private L2Attackable _monster;
- + private final L2Attackable _monster;
- public CommandChannelTimer(L2Attackable monster)
- {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement