Support for extractable items with enchant.
This commit is contained in:
parent
ed29d1e9eb
commit
599f3a0dca
@ -18,6 +18,7 @@
|
||||
*/
|
||||
package handlers.itemhandlers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jserver.Config;
|
||||
@ -28,11 +29,13 @@ import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jserver.gameserver.model.items.L2EtcItem;
|
||||
import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
|
||||
import com.l2jserver.gameserver.network.SystemMessageId;
|
||||
import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
|
||||
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
|
||||
import com.l2jserver.util.Rnd;
|
||||
|
||||
/**
|
||||
* Extractable Items handler.
|
||||
* @author HorridoJoho
|
||||
* @author HorridoJoho, Mobius
|
||||
*/
|
||||
public class ExtractableItems implements IItemHandler
|
||||
{
|
||||
@ -61,6 +64,7 @@ public class ExtractableItems implements IItemHandler
|
||||
}
|
||||
|
||||
boolean created = false;
|
||||
List<L2ItemInstance> enchantedItems = new ArrayList<>();
|
||||
for (L2ExtractableProduct expi : exitem)
|
||||
{
|
||||
if (Rnd.get(100000) <= expi.getChance())
|
||||
@ -76,15 +80,28 @@ public class ExtractableItems implements IItemHandler
|
||||
|
||||
if (item.isStackable() || (createItemAmount == 1))
|
||||
{
|
||||
activeChar.addItem("Extract", expi.getId(), createItemAmount, activeChar, true);
|
||||
final L2ItemInstance newItem = activeChar.addItem("Extract", expi.getId(), createItemAmount, activeChar, false);
|
||||
if (expi.getMaxEnchant() > 0)
|
||||
{
|
||||
newItem.setEnchantLevel(Rnd.get(expi.getMinEnchant(), expi.getMaxEnchant()));
|
||||
enchantedItems.add(newItem);
|
||||
}
|
||||
sendMessage(activeChar, newItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
while (createItemAmount > 0)
|
||||
{
|
||||
activeChar.addItem("Extract", expi.getId(), 1, activeChar, true);
|
||||
final L2ItemInstance newItem = activeChar.addItem("Extract", expi.getId(), 1, activeChar, false);
|
||||
if (expi.getMaxEnchant() > 0)
|
||||
{
|
||||
newItem.setEnchantLevel(Rnd.get(expi.getMinEnchant(), expi.getMaxEnchant()));
|
||||
enchantedItems.add(newItem);
|
||||
}
|
||||
sendMessage(activeChar, newItem);
|
||||
createItemAmount--;
|
||||
}
|
||||
|
||||
}
|
||||
created = true;
|
||||
}
|
||||
@ -94,6 +111,40 @@ public class ExtractableItems implements IItemHandler
|
||||
{
|
||||
activeChar.sendPacket(SystemMessageId.THERE_WAS_NOTHING_FOUND_INSIDE);
|
||||
}
|
||||
if (!enchantedItems.isEmpty())
|
||||
{
|
||||
InventoryUpdate playerIU = new InventoryUpdate();
|
||||
for (L2ItemInstance i : enchantedItems)
|
||||
{
|
||||
playerIU.addModifiedItem(i);
|
||||
}
|
||||
activeChar.sendPacket(playerIU);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sendMessage(L2PcInstance player, L2ItemInstance item)
|
||||
{
|
||||
if (item.getCount() > 1)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1);
|
||||
sm.addItemName(item);
|
||||
sm.addLong(item.getCount());
|
||||
player.sendPacket(sm);
|
||||
}
|
||||
else if (item.getEnchantLevel() > 0)
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_A_S1_S2);
|
||||
sm.addInt(item.getEnchantLevel());
|
||||
sm.addItemName(item);
|
||||
player.sendPacket(sm);
|
||||
}
|
||||
else
|
||||
{
|
||||
SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S1);
|
||||
sm.addItemName(item);
|
||||
player.sendPacket(sm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,20 +27,26 @@ public class L2ExtractableProduct
|
||||
private final int _min;
|
||||
private final int _max;
|
||||
private final int _chance;
|
||||
private final int _minEnchant;
|
||||
private final int _maxEnchant;
|
||||
|
||||
/**
|
||||
* Create Extractable product
|
||||
* @param id crete item id
|
||||
* @param id create item id
|
||||
* @param min item count max
|
||||
* @param max item count min
|
||||
* @param chance chance for creating
|
||||
* @param minEnchant item min enchant
|
||||
* @param maxEnchant item max enchant
|
||||
*/
|
||||
public L2ExtractableProduct(int id, int min, int max, double chance)
|
||||
public L2ExtractableProduct(int id, int min, int max, double chance, int minEnchant, int maxEnchant)
|
||||
{
|
||||
_id = id;
|
||||
_min = min;
|
||||
_max = max;
|
||||
_chance = (int) (chance * 1000);
|
||||
_minEnchant = minEnchant;
|
||||
_maxEnchant = maxEnchant;
|
||||
}
|
||||
|
||||
public int getId()
|
||||
@ -62,4 +68,14 @@ public class L2ExtractableProduct
|
||||
{
|
||||
return _chance;
|
||||
}
|
||||
|
||||
public int getMinEnchant()
|
||||
{
|
||||
return _minEnchant;
|
||||
}
|
||||
|
||||
public int getMaxEnchant()
|
||||
{
|
||||
return _maxEnchant;
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ public final class L2EtcItem extends L2Item
|
||||
continue;
|
||||
}
|
||||
String[] data = part.split(",");
|
||||
if (data.length != 4)
|
||||
if ((data.length != 4) && (data.length != 6))
|
||||
{
|
||||
_log.info(StringUtil.concat("> Couldnt parse ", part, " in capsuled_items! item ", toString()));
|
||||
continue;
|
||||
@ -96,14 +96,25 @@ public final class L2EtcItem extends L2Item
|
||||
int itemId = Integer.parseInt(data[0]);
|
||||
int min = Integer.parseInt(data[1]);
|
||||
int max = Integer.parseInt(data[2]);
|
||||
double chance = Double.parseDouble(data[3]);
|
||||
if (max < min)
|
||||
{
|
||||
_log.info(StringUtil.concat("> Max amount < Min amount in ", part, ", item ", toString()));
|
||||
continue;
|
||||
}
|
||||
L2ExtractableProduct product = new L2ExtractableProduct(itemId, min, max, chance);
|
||||
_extractableItems.add(product);
|
||||
double chance = Double.parseDouble(data[3]);
|
||||
int minEnchant = 0;
|
||||
int maxEnchant = 0;
|
||||
if (data.length == 6)
|
||||
{
|
||||
minEnchant = Integer.parseInt(data[4]);
|
||||
maxEnchant = Integer.parseInt(data[5]);
|
||||
if (maxEnchant < minEnchant)
|
||||
{
|
||||
_log.info(StringUtil.concat("> Max enchant < Min enchant in ", part, ", item ", toString()));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
_extractableItems.add(new L2ExtractableProduct(itemId, min, max, chance, minEnchant, maxEnchant));
|
||||
}
|
||||
((ArrayList<?>) _extractableItems).trimToSize();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user