123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- /*
- * Copyright (C) 2004-2014 L2J Server
- *
- * This file is part of L2J Server.
- *
- * L2J Server 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 Server 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 com.l2jserver.gameserver.model.drops;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import com.l2jserver.gameserver.model.actor.L2Character;
- import com.l2jserver.gameserver.model.drops.strategy.IAmountMultiplierStrategy;
- import com.l2jserver.gameserver.model.drops.strategy.IChanceMultiplierStrategy;
- import com.l2jserver.gameserver.model.drops.strategy.IGroupedItemDropCalculationStrategy;
- import com.l2jserver.gameserver.model.drops.strategy.IKillerChanceModifierStrategy;
- import com.l2jserver.gameserver.model.drops.strategy.IPreciseDeterminationStrategy;
- import com.l2jserver.gameserver.model.holders.ItemHolder;
- /**
- * @author Nos
- */
- public final class GroupedGeneralDropItem implements IDropItem
- {
-
- private final double _chance;
- private List<GeneralDropItem> _items;
- protected final IGroupedItemDropCalculationStrategy _dropCalculationStrategy;
- protected final IKillerChanceModifierStrategy _killerChanceModifierStrategy;
- protected final IPreciseDeterminationStrategy _preciseStrategy;
-
- /**
- * @param chance the chance of this drop item.
- */
- public GroupedGeneralDropItem(double chance)
- {
- this(chance, IGroupedItemDropCalculationStrategy.DEFAULT_STRATEGY, IKillerChanceModifierStrategy.DEFAULT_STRATEGY, IPreciseDeterminationStrategy.DEFAULT);
- }
-
- /**
- * @param chance the chance of this drop item.
- * @param dropStrategy to calculate drops.
- * @param killerStrategy
- * @param preciseStrategy
- */
- public GroupedGeneralDropItem(double chance, IGroupedItemDropCalculationStrategy dropStrategy, IKillerChanceModifierStrategy killerStrategy, IPreciseDeterminationStrategy preciseStrategy)
- {
- _chance = chance;
- _dropCalculationStrategy = dropStrategy;
- _killerChanceModifierStrategy = killerStrategy;
- _preciseStrategy = preciseStrategy;
- }
-
- /**
- * Gets the chance of this drop item.
- * @return the chance
- */
- public final double getChance()
- {
- return _chance;
- }
-
- /**
- * Gets the items.
- * @return the items
- */
- public final List<GeneralDropItem> getItems()
- {
- return _items;
- }
-
- /**
- * @return the strategy
- */
- public final IGroupedItemDropCalculationStrategy getDropCalculationStrategy()
- {
- return _dropCalculationStrategy;
- }
-
- /**
- * @return the _killerChanceModifierStrategy
- */
- public IKillerChanceModifierStrategy getKillerChanceModifierStrategy()
- {
- return _killerChanceModifierStrategy;
- }
-
- /**
- * @return the _preciseStrategy
- */
- public final IPreciseDeterminationStrategy getPreciseStrategy()
- {
- return _preciseStrategy;
- }
-
- /**
- * Sets an item list to this drop item.
- * @param items the item list
- */
- public final void setItems(List<GeneralDropItem> items)
- {
- _items = Collections.unmodifiableList(items);
- }
-
- /**
- * Returns a list of items in the group with chance multiplied by chance of the group
- * @return the list of items with modified chances
- */
- public final List<GeneralDropItem> extractMe()
- {
- List<GeneralDropItem> items = new ArrayList<>();
- for (final GeneralDropItem item : getItems())
- {
- // precise and killer strategies of the group
- items.add(new GeneralDropItem(item.getItemId(), item.getMin(), item.getMax(), (item.getChance() * getChance()) / 100, item.getAmountStrategy(), item.getChanceStrategy(), getPreciseStrategy(), getKillerChanceModifierStrategy(), item.getDropCalculationStrategy()));
- }
- return items;
- }
-
- /**
- * statically normalizes a group, useful when need to convert legacy SQL data
- * @return a new group with items, which have a sum of getChance() of 100%
- */
- public final GroupedGeneralDropItem normalizeMe()
- {
- double sumchance = 0;
- for (GeneralDropItem item : getItems())
- {
- sumchance += (item.getChance() * getChance()) / 100;
- }
- final double sumchance1 = sumchance;
- GroupedGeneralDropItem group = new GroupedGeneralDropItem(sumchance1, getDropCalculationStrategy(), IKillerChanceModifierStrategy.NO_RULES, getPreciseStrategy());
- List<GeneralDropItem> items = new ArrayList<>();
- for (final GeneralDropItem item : getItems())
- {
- // modify only the chance, leave all other rules intact
- items.add(new GeneralDropItem(item.getItemId(), item.getMin(), item.getMax(), (item.getChance() * getChance()) / sumchance1, item.getAmountStrategy(), item.getChanceStrategy(), item.getPreciseStrategy(), item.getKillerChanceModifierStrategy(), item.getDropCalculationStrategy()));
- }
- group.setItems(items);
- return group;
- }
-
- /**
- * Creates a normalized group taking into account all drop modifiers, needed when handling a group which has items with different chance rates
- * @param victim
- * @param killer
- * @return a new normalized group with all drop modifiers applied
- */
- public final GroupedGeneralDropItem normalizeMe(L2Character victim, L2Character killer)
- {
- return normalizeMe(victim, killer, true, 1);
- }
-
- /**
- * Creates a normalized group taking into account all drop modifiers, needed when handling a group which has items with different chance rates
- * @param victim
- * @param killer
- * @param chanceModifier an additional chance modifier
- * @return a new normalized group with all drop modifiers applied
- */
- public final GroupedGeneralDropItem normalizeMe(L2Character victim, L2Character killer, double chanceModifier)
- {
- return normalizeMe(victim, killer, true, chanceModifier);
- }
-
- /**
- * Creates a normalized group taking into account all drop modifiers, needed when handling a group which has items with different chance rates
- * @param victim
- * @return a new normalized group with all victim modifiers applied
- */
- public final GroupedGeneralDropItem normalizeMe(L2Character victim)
- {
- return normalizeMe(victim, null, false, 1);
- }
-
- /**
- * Creates a normalized group taking into account all drop modifiers, needed when handling a group which has items with different chance rates
- * @param victim
- * @param chanceModifier an additional chance modifier
- * @return a new normalized group with all victim modifiers applied
- */
- public final GroupedGeneralDropItem normalizeMe(L2Character victim, double chanceModifier)
- {
- return normalizeMe(victim, null, false, chanceModifier);
- }
-
- /**
- * Creates a normalized group taking into account all drop modifiers, needed when handling a group which has items with different chance rates
- * @param victim
- * @param killer
- * @param applyKillerModifier if to modify chance by {@link GroupedGeneralDropItem#getKillerChanceModifier(L2Character, L2Character)}
- * @param chanceModifier an additional chance modifier
- * @return a new normalized group with all drop modifiers applied
- */
- private final GroupedGeneralDropItem normalizeMe(L2Character victim, L2Character killer, boolean applyKillerModifier, double chanceModifier)
- {
- if (applyKillerModifier)
- {
- chanceModifier *= (getKillerChanceModifier(victim, killer));
- }
- double sumchance = 0;
- for (GeneralDropItem item : getItems())
- {
- sumchance += (item.getChance(victim) * getChance() * chanceModifier) / 100;
- }
- GroupedGeneralDropItem group = new GroupedGeneralDropItem(sumchance, getDropCalculationStrategy(), IKillerChanceModifierStrategy.NO_RULES, getPreciseStrategy()); // to discard further deep blue calculations
- List<GeneralDropItem> items = new ArrayList<>();
- for (GeneralDropItem item : getItems())
- {
- // the item is made almost "static"
- items.add(new GeneralDropItem(item.getItemId(), item.getMin(victim), item.getMax(victim), (item.getChance(victim) * getChance() * chanceModifier) / sumchance, IAmountMultiplierStrategy.STATIC, IChanceMultiplierStrategy.STATIC, getPreciseStrategy(), IKillerChanceModifierStrategy.NO_RULES, item.getDropCalculationStrategy()));
- }
- group.setItems(items);
- return group;
-
- }
-
- /*
- * (non-Javadoc)
- * @see com.l2jserver.gameserver.model.drop.IDropItem#calculateDrops(com.l2jserver.gameserver.model.actor.L2Character, com.l2jserver.gameserver.model.actor.L2Character)
- */
- @Override
- public final List<ItemHolder> calculateDrops(L2Character victim, L2Character killer)
- {
- return _dropCalculationStrategy.calculateDrops(this, victim, killer);
- }
-
- /**
- * This handles by default deep blue drop rules. It may also be used to handle another drop chance rules based on killer
- * @param victim the victim who drops the item
- * @param killer who kills the victim
- * @return a number between 0 and 1 (usually)
- */
- public final double getKillerChanceModifier(L2Character victim, L2Character killer)
- {
- return _killerChanceModifierStrategy.getKillerChanceModifier(this, victim, killer);
- }
-
- public boolean isPreciseCalculated()
- {
- return _preciseStrategy.isPreciseCalculated(this);
- }
- }
|