Drop of VariationWeaponType and support for specific item id in OptionDataCategory.

This commit is contained in:
MobiusDevelopment 2021-01-04 11:27:40 +00:00
parent 01b70a0f28
commit 72de17e934
14 changed files with 10516 additions and 17952 deletions

File diff suppressed because it is too large Load Diff

View File

@ -27,12 +27,22 @@
<xs:attribute type="xs:double" name="chance" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:attribute type="xs:int" name="id" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="items">
<xs:complexType>
<xs:attribute type="xs:int" name="from" use="optional"/>
<xs:attribute type="xs:int" name="to" use="optional"/>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute type="xs:float" name="chance" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="weaponType" use="optional"/>
<xs:attribute type="xs:byte" name="order" use="optional"/>
</xs:complexType>
</xs:element>

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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
}

View File

@ -3,106 +3,57 @@
<variations>
<!-- Common Life Stone -->
<variation mineralId="90012">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="40000" to="40072" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="15095" to="15111" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="15112" to="15218" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="15219" to="15272" chance="10.0" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="40000" to="40072" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="15095" to="15111" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="15112" to="15218" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="15219" to="15272" chance="10.0" />
<optionCategory chance="10">
<optionRange from="15219" to="15272" chance="10" />
</optionCategory>
</optionGroup>
</variation>
<!-- Mid-grade Life Stone -->
<variation mineralId="90013">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="40073" to="40145" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="15807" to="15823" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="15824" to="15930" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="15931" to="15984" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="40073" to="40145" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="15807" to="15823" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="15824" to="15930" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="15931" to="15984" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- High-grade Life Stone -->
<variation mineralId="90014">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="40146" to="40218" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="16163" to="16179" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="16180" to="16286" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="16287" to="16340" chance="1.73" />
<optionRange from="16377" to="16380" chance="1.72" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="40146" to="40218" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="16163" to="16179" chance="5.88" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="16180" to="16286" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="16287" to="16340" chance="1.73" />
<optionRange from="16377" to="16380" chance="1.72" />
</optionCategory>
@ -110,36 +61,19 @@
</variation>
<!-- Top-grade Life Stone -->
<variation mineralId="90015">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="40146" to="40218" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="16163" to="16179" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="16180" to="16286" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="16287" to="16340" chance="1.73" />
<optionRange from="16377" to="16380" chance="1.72" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="40146" to="40218" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="16163" to="16179" chance="5.88" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="16180" to="16286" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="16287" to="16340" chance="1.73" />
<optionRange from="16377" to="16380" chance="1.72" />
</optionCategory>
@ -147,176 +81,95 @@
</variation>
<!-- Life Stone Lv.1 - Weapons-->
<variation mineralId="94185">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="33929" to="33948" chance="1.37" />
<optionRange from="33969" to="33988" chance="1.37" />
<optionRange from="34009" to="34048" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34089" to="34108" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34129" to="34144" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34169" to="34188" chance="1.73" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="33929" to="33948" chance="1.37" />
<optionRange from="33969" to="33988" chance="1.37" />
<optionRange from="34009" to="34048" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34089" to="34108" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34129" to="34144" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34169" to="34188" chance="1.73" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.2 - Weapons-->
<variation mineralId="94186">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="33949" to="33968" chance="1.37" />
<optionRange from="33989" to="34008" chance="1.37" />
<optionRange from="34009" to="34088" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34109" to="34128" chance="5.89" />
<optionRange from="34149" to="34168" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34189" to="34208" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34209" to="34228" chance="1.73" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="33949" to="33968" chance="1.37" />
<optionRange from="33989" to="34008" chance="1.37" />
<optionRange from="34009" to="34088" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34109" to="34128" chance="5.89" />
<optionRange from="34149" to="34168" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34189" to="34208" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34209" to="34228" chance="1.73" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv. 1 - Hair Accessory -->
<variation mineralId="90856">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="33959" to="34088" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34089" to="34168" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34169" to="34179" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34180" to="34188" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="33959" to="34088" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34089" to="34168" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34169" to="34179" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34180" to="34188" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv. 2 - Hair Accessory -->
<variation mineralId="90857">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="50102" to="50154" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="50188" to="50190" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="50191" to="50193" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="50194" to="50196" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="50102" to="50154" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="50188" to="50190" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="50191" to="50193" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="50194" to="50196" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.1 - Armor-->
<variation mineralId="94187">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="100.0">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="100.0">
<optionGroup order="1">
<optionCategory chance="100">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
@ -324,65 +177,35 @@
</variation>
<!-- Life Stone Lv. 2 - Armor -->
<variation mineralId="94188">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34329" to="34348" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34489" to="34508" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34329" to="34348" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34489" to="34508" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.1 - Boots -->
<variation mineralId="94187">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="100.0">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="100.0">
<optionGroup order="1">
<optionCategory chance="100">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
@ -390,65 +213,35 @@
</variation>
<!-- Life Stone Lv. 2 - Boots -->
<variation mineralId="94188">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34369" to="34388" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34529" to="34548" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34369" to="34388" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34529" to="34548" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.1 - Gloves -->
<variation mineralId="94187">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="100.0">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="100.0">
<optionGroup order="1">
<optionCategory chance="100">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
@ -456,65 +249,35 @@
</variation>
<!-- Life Stone Lv. 2 - Boots -->
<variation mineralId="94188">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34349" to="34368" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34509" to="34528" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34349" to="34368" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34509" to="34528" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.1 - Helmet -->
<variation mineralId="94187">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="100.0">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="100.0">
<optionGroup order="1">
<optionCategory chance="100">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
@ -522,65 +285,35 @@
</variation>
<!-- Life Stone Lv. 2 - Helmet -->
<variation mineralId="94188">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34309" to="34328" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="34469" to="34488" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
<optionRange from="34309" to="34328" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="34469" to="34488" chance="1.85" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.1 - Legs -->
<variation mineralId="94187">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="100.0">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34229" to="34248" chance="1.37" />
<optionRange from="34269" to="34288" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="100.0">
<optionGroup order="1">
<optionCategory chance="100">
<optionRange from="34389" to="34408" chance="5.89" />
<optionRange from="34429" to="34448" chance="5.89" />
</optionCategory>
@ -588,126 +321,69 @@
</variation>
<!-- Life Stone Lv. 2 - Legs -->
<variation mineralId="94188">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="45.0">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="34249" to="34268" chance="1.37" />
<optionRange from="34289" to="34308" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="34409" to="34428" chance="5.89" />
</optionCategory>
<optionCategory chance="45.0">
<optionCategory chance="45">
<optionRange from="34449" to="34468" chance="0.94" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.1 - Sigil/Shield -->
<variation mineralId="93121">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="100.0">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="100.0">
<optionGroup order="1">
<optionCategory chance="100">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone Lv.2 - Sigil/Shield -->
<variation mineralId="93122">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="50161" to="50166" chance="1.37" />
<optionRange from="50174" to="50179" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="33547" to="33609" chance="1.37" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="50161" to="50166" chance="1.37" />
<optionRange from="50174" to="50179" chance="1.37" />
</optionCategory>
</optionGroup>
</variation>
<!-- Life Stone - Circlets -->
<variation mineralId="94303">
<optionGroup weaponType="warrior" order="0">
<optionCategory chance="100.0">
<optionGroup order="0">
<optionCategory chance="100">
<optionRange from="50102" to="50154" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="warrior" order="1">
<optionCategory chance="55.0">
<optionGroup order="1">
<optionCategory chance="55">
<optionRange from="50188" to="50190" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionCategory chance="35">
<optionRange from="50191" to="50193" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionRange from="50194" to="50196" chance="1.85" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="0">
<optionCategory chance="100.0">
<optionRange from="50102" to="50154" chance="1.37" />
</optionCategory>
</optionGroup>
<optionGroup weaponType="mage" order="1">
<optionCategory chance="55.0">
<optionRange from="50188" to="50190" chance="5.89" />
</optionCategory>
<optionCategory chance="35.0">
<optionRange from="50191" to="50193" chance="0.94" />
</optionCategory>
<optionCategory chance="10.0">
<optionCategory chance="10">
<optionRange from="50194" to="50196" chance="1.85" />
</optionCategory>
</optionGroup>

View File

@ -27,12 +27,22 @@
<xs:attribute type="xs:double" name="chance" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="item">
<xs:complexType>
<xs:attribute type="xs:int" name="id" use="optional"/>
</xs:complexType>
</xs:element>
<xs:element name="items">
<xs:complexType>
<xs:attribute type="xs:int" name="from" use="optional"/>
<xs:attribute type="xs:int" name="to" use="optional"/>
</xs:complexType>
</xs:element>
</xs:choice>
<xs:attribute type="xs:float" name="chance" use="optional"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute type="xs:string" name="weaponType" use="optional"/>
<xs:attribute type="xs:byte" name="order" use="optional"/>
</xs:complexType>
</xs:element>

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}
}

View File

@ -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);
}
}

View File

@ -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
}