Drop of VariationWeaponType and support for specific item id in OptionDataCategory.
This commit is contained in:
@@ -36,10 +36,9 @@ import org.l2jmobius.gameserver.model.options.OptionDataGroup;
|
||||
import org.l2jmobius.gameserver.model.options.Options;
|
||||
import org.l2jmobius.gameserver.model.options.Variation;
|
||||
import org.l2jmobius.gameserver.model.options.VariationFee;
|
||||
import org.l2jmobius.gameserver.model.options.VariationWeaponType;
|
||||
|
||||
/**
|
||||
* @author Pere
|
||||
* @author Pere, Mobius
|
||||
*/
|
||||
public class VariationData implements IXmlReader
|
||||
{
|
||||
@@ -79,8 +78,6 @@ public class VariationData implements IXmlReader
|
||||
|
||||
forEach(variationNode, "optionGroup", groupNode ->
|
||||
{
|
||||
final String weaponTypeString = parseString(groupNode.getAttributes(), "weaponType").toUpperCase();
|
||||
final VariationWeaponType weaponType = VariationWeaponType.valueOf(weaponTypeString);
|
||||
final int order = parseInteger(groupNode.getAttributes(), "order");
|
||||
final List<OptionDataCategory> sets = new ArrayList<>();
|
||||
forEach(groupNode, "optionCategory", categoryNode ->
|
||||
@@ -116,10 +113,33 @@ public class VariationData implements IXmlReader
|
||||
}
|
||||
});
|
||||
|
||||
sets.add(new OptionDataCategory(options, chance));
|
||||
// Support for specific item ids.
|
||||
final List<Integer> itemIds = new ArrayList<>();
|
||||
forEach(categoryNode, "item", optionNode ->
|
||||
{
|
||||
final int itemId = parseInteger(optionNode.getAttributes(), "id");
|
||||
if (!itemIds.contains(itemId))
|
||||
{
|
||||
itemIds.add(itemId);
|
||||
}
|
||||
});
|
||||
forEach(categoryNode, "items", optionNode ->
|
||||
{
|
||||
final int fromId = parseInteger(optionNode.getAttributes(), "from");
|
||||
final int toId = parseInteger(optionNode.getAttributes(), "to");
|
||||
for (int id = fromId; id <= toId; id++)
|
||||
{
|
||||
if (!itemIds.contains(id))
|
||||
{
|
||||
itemIds.add(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
sets.add(new OptionDataCategory(options, itemIds, chance));
|
||||
});
|
||||
|
||||
variation.setEffectGroup(weaponType, order, new OptionDataGroup(sets));
|
||||
variation.setEffectGroup(order, new OptionDataGroup(sets));
|
||||
});
|
||||
|
||||
_variations.put(mineralId, variation);
|
||||
@@ -174,8 +194,13 @@ public class VariationData implements IXmlReader
|
||||
|
||||
for (int item : itemGroup)
|
||||
{
|
||||
final Map<Integer, VariationFee> fees = _fees.computeIfAbsent(item, k -> new HashMap<>());
|
||||
Map<Integer, VariationFee> fees = _fees.get(item);
|
||||
if (fees == null)
|
||||
{
|
||||
fees = new HashMap<>();
|
||||
}
|
||||
fees.putAll(feeByMinerals);
|
||||
_fees.put(item, fees);
|
||||
}
|
||||
}));
|
||||
});
|
||||
@@ -199,14 +224,13 @@ public class VariationData implements IXmlReader
|
||||
*/
|
||||
public VariationInstance generateRandomVariation(Variation variation, ItemInstance targetItem)
|
||||
{
|
||||
final VariationWeaponType weaponType = ((targetItem.getWeaponItem() != null) && targetItem.getWeaponItem().isMagicWeapon()) ? VariationWeaponType.MAGE : VariationWeaponType.WARRIOR;
|
||||
return generateRandomVariation(variation, weaponType);
|
||||
return generateRandomVariation(variation, targetItem.getId());
|
||||
}
|
||||
|
||||
private VariationInstance generateRandomVariation(Variation variation, VariationWeaponType weaponType)
|
||||
private VariationInstance generateRandomVariation(Variation variation, int targetItemId)
|
||||
{
|
||||
final Options option1 = variation.getRandomEffect(weaponType, 0);
|
||||
final Options option2 = variation.getRandomEffect(weaponType, 1);
|
||||
final Options option1 = variation.getRandomEffect(0, targetItemId);
|
||||
final Options option2 = variation.getRandomEffect(1, targetItemId);
|
||||
return ((option1 != null) && (option2 != null)) ? new VariationInstance(variation.getMineralId(), option1, option2) : null;
|
||||
}
|
||||
|
||||
|
@@ -16,21 +16,24 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.options;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
|
||||
/**
|
||||
* @author Pere
|
||||
* @author Pere, Mobius
|
||||
*/
|
||||
public class OptionDataCategory
|
||||
{
|
||||
private final Map<Options, Double> _options;
|
||||
private final List<Integer> _itemIds;
|
||||
private final double _chance;
|
||||
|
||||
public OptionDataCategory(Map<Options, Double> options, double chance)
|
||||
public OptionDataCategory(Map<Options, Double> options, List<Integer> itemIds, double chance)
|
||||
{
|
||||
_options = options;
|
||||
_itemIds = itemIds;
|
||||
_chance = chance;
|
||||
}
|
||||
|
||||
@@ -55,6 +58,11 @@ public class OptionDataCategory
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Integer> getItemIds()
|
||||
{
|
||||
return _itemIds;
|
||||
}
|
||||
|
||||
public double getChance()
|
||||
{
|
||||
return _chance;
|
||||
|
@@ -16,12 +16,13 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.options;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.l2jmobius.commons.util.Rnd;
|
||||
|
||||
/**
|
||||
* @author Pere
|
||||
* @author Pere, Mobius
|
||||
*/
|
||||
public class OptionDataGroup
|
||||
{
|
||||
@@ -32,25 +33,33 @@ public class OptionDataGroup
|
||||
_categories = categories;
|
||||
}
|
||||
|
||||
Options getRandomEffect()
|
||||
Options getRandomEffect(int itemId)
|
||||
{
|
||||
final List<OptionDataCategory> exclutions = new ArrayList<>();
|
||||
Options result = null;
|
||||
do
|
||||
{
|
||||
double random = Rnd.nextDouble() * 100.0;
|
||||
for (OptionDataCategory category : _categories)
|
||||
{
|
||||
if (!category.getItemIds().isEmpty() && !category.getItemIds().contains(itemId))
|
||||
{
|
||||
if (!exclutions.contains(category))
|
||||
{
|
||||
exclutions.add(category);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (category.getChance() >= random)
|
||||
{
|
||||
result = category.getRandomOptions();
|
||||
break;
|
||||
}
|
||||
|
||||
random -= category.getChance();
|
||||
}
|
||||
}
|
||||
while (result == null);
|
||||
// Should never get there
|
||||
while ((result == null) && (exclutions.size() < _categories.size()));
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@@ -16,19 +16,17 @@
|
||||
*/
|
||||
package org.l2jmobius.gameserver.model.options;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author Pere
|
||||
* @author Pere, Mobius
|
||||
*/
|
||||
public class Variation
|
||||
{
|
||||
private static final Logger LOGGER = Logger.getLogger(Variation.class.getSimpleName());
|
||||
|
||||
private final int _mineralId;
|
||||
private final Map<VariationWeaponType, OptionDataGroup[]> _effects = new EnumMap<>(VariationWeaponType.class);
|
||||
private final OptionDataGroup[] _effects = new OptionDataGroup[2];
|
||||
|
||||
public Variation(int mineralId)
|
||||
{
|
||||
@@ -40,20 +38,18 @@ public class Variation
|
||||
return _mineralId;
|
||||
}
|
||||
|
||||
public void setEffectGroup(VariationWeaponType type, int order, OptionDataGroup group)
|
||||
public void setEffectGroup(int order, OptionDataGroup group)
|
||||
{
|
||||
final OptionDataGroup[] effects = _effects.computeIfAbsent(type, k -> new OptionDataGroup[2]);
|
||||
effects[order] = group;
|
||||
_effects[order] = group;
|
||||
}
|
||||
|
||||
public Options getRandomEffect(VariationWeaponType type, int order)
|
||||
public Options getRandomEffect(int order, int targetItemId)
|
||||
{
|
||||
final OptionDataGroup[] effects = _effects.get(type);
|
||||
if ((effects == null) || (effects[order] == null))
|
||||
if ((_effects == null) || (_effects[order] == null))
|
||||
{
|
||||
LOGGER.warning("Null effect: " + type + ", " + order);
|
||||
LOGGER.warning("Null effect: for mineral " + _mineralId + ", order " + order);
|
||||
return null;
|
||||
}
|
||||
return effects[order].getRandomEffect();
|
||||
return _effects[order].getRandomEffect(targetItemId);
|
||||
}
|
||||
}
|
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* This program 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.
|
||||
*
|
||||
* This program 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 org.l2jmobius.gameserver.model.options;
|
||||
|
||||
/**
|
||||
* @author Pere
|
||||
*/
|
||||
public enum VariationWeaponType
|
||||
{
|
||||
WARRIOR,
|
||||
MAGE
|
||||
}
|
Reference in New Issue
Block a user