Support for multisell enchantmentLevel option.

This commit is contained in:
MobiusDev 2016-06-14 18:46:52 +00:00
parent 68c7c5a385
commit 842ecc6af0
6 changed files with 72 additions and 54 deletions

View File

@ -37,7 +37,9 @@ TAGS:
<list></list> : start and end the list
<item></item> : start and end a single entry within the list
<production id="itemID" count="amount"/> : add a product for the entry
<ingredient id="ItemID" count="amount"/> : add an ingredient for the entry.
<ingredient id="ItemID" count="amount"/> : add an ingredient for the entry
enchantmentLevel : add item enchantment level
Sample:
<list applyTaxes="true">
@ -48,7 +50,7 @@ Sample:
<ingredient id="57" count="200">
</item>
<item>
<production id="123" count="1">
<production id="123" enchantmentLevel="16" count="1">
<ingredient id="57" count="2030">
</item>
</list>

View File

@ -20,6 +20,7 @@
<xs:element name="ingredient" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:integer" use="required" />
<xs:attribute name="enchantmentLevel" type="xs:integer" />
<xs:attribute name="count" type="xs:positiveInteger" use="required" />
<xs:attribute name="maintainIngredient" type="xs:boolean" />
</xs:complexType>
@ -27,6 +28,7 @@
<xs:element name="production" minOccurs="1" maxOccurs="unbounded">
<xs:complexType>
<xs:attribute name="id" type="xs:integer" use="required" />
<xs:attribute name="enchantmentLevel" type="xs:integer" />
<xs:attribute name="count" type="xs:positiveInteger" use="required" />
<xs:attribute name="chance" type="xs:integer" use="optional" />
</xs:complexType>

View File

@ -30,6 +30,7 @@ public class Ingredient
{
private int _itemId;
private long _itemCount;
private final int _enchantmentLevel;
private boolean _isTaxIngredient;
private boolean _maintainIngredient;
private L2Item _template = null;
@ -38,13 +39,14 @@ public class Ingredient
public Ingredient(StatsSet set)
{
this(set.getInt("id"), set.getLong("count"), set.getInt("chance", 0), set.getBoolean("isTaxIngredient", false), set.getBoolean("maintainIngredient", false));
this(set.getInt("id"), set.getLong("count"), set.getInt("enchantmentLevel", 0), set.getInt("chance", 0), set.getBoolean("isTaxIngredient", false), set.getBoolean("maintainIngredient", false));
}
public Ingredient(int itemId, long itemCount, int chance, boolean isTaxIngredient, boolean maintainIngredient)
public Ingredient(int itemId, long itemCount, int enchantmentLevel, int chance, boolean isTaxIngredient, boolean maintainIngredient)
{
_itemId = itemId;
_itemCount = itemCount;
_enchantmentLevel = enchantmentLevel;
_chance = chance;
_isTaxIngredient = isTaxIngredient;
_maintainIngredient = maintainIngredient;
@ -59,7 +61,7 @@ public class Ingredient
*/
public Ingredient getCopy()
{
return new Ingredient(_itemId, _itemCount, _chance, _isTaxIngredient, _maintainIngredient);
return new Ingredient(_itemId, _itemCount, _enchantmentLevel, _chance, _isTaxIngredient, _maintainIngredient);
}
public final L2Item getTemplate()
@ -84,7 +86,7 @@ public class Ingredient
public final int getEnchantLevel()
{
return _itemInfo != null ? _itemInfo.getEnchantLevel() : 0;
return _itemInfo == null ? _enchantmentLevel : _itemInfo.getEnchantLevel();
}
public final void setItemId(int itemId)

View File

@ -61,7 +61,7 @@ public class PreparedEntry extends Entry
// do not yet add this adena amount to the list as non-taxIngredient adena might be entered later (order not guaranteed)
continue;
}
else if (maintainEnchantment && (item != null) && ing.isArmorOrWeapon())
if (maintainEnchantment && (item != null) && ing.isArmorOrWeapon())
{
info = new ItemInfo(item);
final Ingredient newIngredient = ing.getCopy();
@ -70,8 +70,7 @@ public class PreparedEntry extends Entry
}
else
{
final Ingredient newIngredient = ing.getCopy();
_ingredients.add(newIngredient);
_ingredients.add(ing.getCopy());
}
}
@ -79,7 +78,7 @@ public class PreparedEntry extends Entry
adenaAmount += _taxAmount; // do not forget tax
if (adenaAmount > 0)
{
_ingredients.add(new Ingredient(ADENA_ID, adenaAmount, 0, false, false));
_ingredients.add(new Ingredient(ADENA_ID, adenaAmount, 0, 0, false, false));
}
// now copy products

View File

@ -152,8 +152,7 @@ public class MultiSellChoose implements IClientIncomingPacket
}
final ArrayList<Ingredient> ingredientsList = new ArrayList<>(entry.getIngredients().size());
// Generate a list of distinct ingredients and counts in order to check if the correct item-counts
// are possessed by the player
// Generate a list of distinct ingredients and counts in order to check if the correct item-counts are possessed by the player
boolean newIng;
for (Ingredient e : entry.getIngredients())
{
@ -187,7 +186,7 @@ public class MultiSellChoose implements IClientIncomingPacket
}
}
// now check if the player has sufficient items in the inventory to cover the ingredients' expences
// now check if the player has sufficient items in the inventory to cover the ingredient expenses
for (Ingredient e : ingredientsList)
{
if ((e.getItemCount() * _amount) > Integer.MAX_VALUE)
@ -206,13 +205,23 @@ public class MultiSellChoose implements IClientIncomingPacket
{
// if this is not a list that maintains enchantment, check the count of all items that have the given id.
// otherwise, check only the count of items with exactly the needed enchantment level
final long required = ((Config.ALT_BLACKSMITH_USE_RECIPES || !e.getMaintainIngredient()) ? (e.getItemCount() * _amount) : e.getItemCount());
if (inv.getInventoryItemCount(e.getItemId(), list.getMaintainEnchantment() ? e.getEnchantLevel() : -1, false) < required)
final long required = (Config.ALT_BLACKSMITH_USE_RECIPES || !e.getMaintainIngredient()) ? (e.getItemCount() * _amount) : e.getItemCount();
if (inv.getInventoryItemCount(e.getItemId(), (list.getMaintainEnchantment() || (e.getEnchantLevel() > 0)) ? e.getEnchantLevel() : -1, false) < required)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_NEED_S2_S1_S);
sm.addItemName(e.getTemplate());
sm.addLong(required);
player.sendPacket(sm);
if (e.getEnchantLevel() > 0)
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_NEED_S2_S1_S);
sm.addString("+" + e.getEnchantLevel() + " " + e.getTemplate().getName());
sm.addLong(required);
player.sendPacket(sm);
}
else
{
final SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_NEED_S2_S1_S);
sm.addItemName(e.getTemplate());
sm.addLong(required);
player.sendPacket(sm);
}
return;
}
}
@ -253,7 +262,7 @@ public class MultiSellChoose implements IClientIncomingPacket
// if it's a stackable item, just reduce the amount from the first (only) instance that is found in the inventory
if (itemToTake.isStackable())
{
if (!player.destroyItem("Multisell", itemToTake.getObjectId(), (e.getItemCount() * _amount), player.getTarget(), true))
if (!player.destroyItem("Multisell", itemToTake.getObjectId(), e.getItemCount() * _amount, player.getTarget(), true))
{
player.setMultiSell(null);
return;
@ -266,7 +275,7 @@ public class MultiSellChoose implements IClientIncomingPacket
// b) list does not maintain enchantment: get the instances with the LOWEST enchantment level
// a) if enchantment is maintained, then get a list of items that exactly match this enchantment
if (list.getMaintainEnchantment())
if (list.getMaintainEnchantment() || (e.getEnchantLevel() > 0))
{
// loop through this list and remove (one by one) each item until the required amount is taken.
final L2ItemInstance[] inventoryContents = inv.getAllItemsByItemId(e.getItemId(), e.getEnchantLevel(), false).toArray(new L2ItemInstance[0]);
@ -329,7 +338,7 @@ public class MultiSellChoose implements IClientIncomingPacket
{
for (L2ItemInstance item : inventoryContents)
{
if (item.getEnchantLevel() < itemToTake.getEnchantLevel())
if ((item.getEnchantLevel() < itemToTake.getEnchantLevel()) && (item.getEnchantLevel() >= e.getEnchantLevel()))
{
itemToTake = item;
// nothing will have enchantment less than 0. If a zero-enchanted
@ -369,7 +378,7 @@ public class MultiSellChoose implements IClientIncomingPacket
}
// Calculate chance
matched = (itemRandom < (cumulativeChance += e.getChance()));
matched = itemRandom < (cumulativeChance += e.getChance());
if (!matched)
{
continue;
@ -388,47 +397,51 @@ public class MultiSellChoose implements IClientIncomingPacket
}
else
{
L2ItemInstance product = null;
for (int i = 0; i < (e.getItemCount() * _amount); i++)
{
final L2ItemInstance product = inv.addItem("Multisell", e.getItemId(), 1, player, player.getTarget());
if ((product != null) && list.getMaintainEnchantment())
product = inv.addItem("Multisell", e.getItemId(), 1, player, player.getTarget());
if ((product != null) && (list.getMaintainEnchantment() || (e.getEnchantLevel() > 0)))
{
final ItemInfo info = originalInfos.get(i);
if (info.getAugmentId() > 0)
if (info != null)
{
product.setAugmentation(new L2Augmentation(info.getAugmentId()));
}
if (info.getElementals().length > 0)
{
Arrays.stream(info.getElementals()).filter(Objects::nonNull).forEach(product::setAttribute);
}
if (info.getVisualId() > 0)
{
product.setVisualId(info.getVisualId());
if (info.getVisualStoneId() > 0)
if (info.getAugmentId() > 0)
{
product.getVariables().set(ItemVariables.VISUAL_APPEARANCE_STONE_ID, info.getVisualStoneId());
product.setAugmentation(new L2Augmentation(info.getAugmentId()));
}
if (info.getVisualIdLifeTime() > 0)
if (info.getElementals().length > 0)
{
product.getVariables().set(ItemVariables.VISUAL_APPEARANCE_LIFE_TIME, info.getVisualIdLifeTime());
product.scheduleVisualLifeTime();
Arrays.stream(info.getElementals()).filter(Objects::nonNull).forEach(product::setAttribute);
}
}
if (!info.getSpecialAbilities().isEmpty())
{
int position = 0;
for (EnsoulOption option : info.getSpecialAbilities())
if (info.getVisualId() > 0)
{
product.addSpecialAbility(option, position++, 1, true);
product.setVisualId(info.getVisualId());
if (info.getVisualStoneId() > 0)
{
product.getVariables().set(ItemVariables.VISUAL_APPEARANCE_STONE_ID, info.getVisualStoneId());
}
if (info.getVisualIdLifeTime() > 0)
{
product.getVariables().set(ItemVariables.VISUAL_APPEARANCE_LIFE_TIME, info.getVisualIdLifeTime());
product.scheduleVisualLifeTime();
}
}
}
if (!info.getAdditionalSpecialAbilities().isEmpty())
{
int position = 0;
for (EnsoulOption option : info.getAdditionalSpecialAbilities())
if (!info.getSpecialAbilities().isEmpty())
{
product.addSpecialAbility(option, position++, 2, true);
int position = 0;
for (EnsoulOption option : info.getSpecialAbilities())
{
product.addSpecialAbility(option, position++, 1, true);
}
}
if (!info.getAdditionalSpecialAbilities().isEmpty())
{
int position = 0;
for (EnsoulOption option : info.getAdditionalSpecialAbilities())
{
product.addSpecialAbility(option, position++, 2, true);
}
}
}
product.setEnchantLevel(e.getEnchantLevel());

View File

@ -138,7 +138,7 @@ public final class MultiSellList implements IClientOutgoingPacket
}
else
{
packet.writeH(0x00); // enchant level
packet.writeH(ing.getEnchantLevel()); // enchant level
packet.writeD(ing.getChance()); // augment id
packet.writeD(0x00); // mana
packet.writeD(0x00); // time ?
@ -196,7 +196,7 @@ public final class MultiSellList implements IClientOutgoingPacket
}
else
{
packet.writeH(0x00); // enchant level
packet.writeH(ing.getEnchantLevel()); // enchant level
packet.writeD(ing.getChance()); // augment id
packet.writeD(0x00); // mana
packet.writeH(0x00); // attack element