Support for multisell maintain ingredient.

This commit is contained in:
MobiusDev
2018-05-23 14:52:12 +00:00
parent 4114fee07c
commit 7148655e9a
28 changed files with 175 additions and 14 deletions

View File

@ -99,7 +99,8 @@ public final class MultisellData implements IGameXmlReader
final int id = parseInteger(d.getAttributes(), "id");
final long count = parseLong(d.getAttributes(), "count");
final byte enchantmentLevel = parseByte(d.getAttributes(), "enchantmentLevel", (byte) 0);
final ItemChanceHolder ingredient = new ItemChanceHolder(id, 0, count, enchantmentLevel);
final Boolean maintainIngredient = parseBoolean(d.getAttributes(), "maintainIngredient", false);
final ItemChanceHolder ingredient = new ItemChanceHolder(id, 0, count, enchantmentLevel, maintainIngredient);
if (itemExists(ingredient))
{

View File

@ -29,6 +29,7 @@ public class ItemChanceHolder extends ItemHolder
{
private final double _chance;
private final byte _enchantmentLevel;
private final boolean _maintainIngredient;
public ItemChanceHolder(int id, double chance)
{
@ -40,6 +41,7 @@ public class ItemChanceHolder extends ItemHolder
super(id, count);
_chance = chance;
_enchantmentLevel = 0;
_maintainIngredient = false;
}
public ItemChanceHolder(int id, double chance, long count, byte enchantmentLevel)
@ -47,6 +49,15 @@ public class ItemChanceHolder extends ItemHolder
super(id, count);
_chance = chance;
_enchantmentLevel = enchantmentLevel;
_maintainIngredient = false;
}
public ItemChanceHolder(int id, double chance, long count, byte enchantmentLevel, boolean maintainIngredient)
{
super(id, count);
_chance = chance;
_enchantmentLevel = enchantmentLevel;
_maintainIngredient = maintainIngredient;
}
/**
@ -67,6 +78,11 @@ public class ItemChanceHolder extends ItemHolder
return _enchantmentLevel;
}
public boolean isMaintainIngredient()
{
return _maintainIngredient;
}
/**
* Calculates a cumulative chance of all given holders. If all holders' chance sum up to 100% or above, there is 100% guarantee a holder will be selected.
* @param holders list of holders to calculate chance from.

View File

@ -316,6 +316,11 @@ public class MultiSellChoose implements IClientIncomingPacket
// Take all ingredients
for (ItemChanceHolder ingredient : entry.getIngredients())
{
if (ingredient.isMaintainIngredient())
{
continue;
}
final long totalCount = Math.multiplyExact(list.getIngredientCount(ingredient), _amount);
final SpecialItemType specialItem = SpecialItemType.getByClientId(ingredient.getId());
if (specialItem != null)