Extractable item handler rework.
This commit is contained in:
@@ -16,6 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package handlers.itemhandlers;
|
package handlers.itemhandlers;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.l2jmobius.Config;
|
import com.l2jmobius.Config;
|
||||||
@@ -27,10 +28,12 @@ import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
|||||||
import com.l2jmobius.gameserver.model.items.L2EtcItem;
|
import com.l2jmobius.gameserver.model.items.L2EtcItem;
|
||||||
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance;
|
||||||
import com.l2jmobius.gameserver.network.SystemMessageId;
|
import com.l2jmobius.gameserver.network.SystemMessageId;
|
||||||
|
import com.l2jmobius.gameserver.network.serverpackets.InventoryUpdate;
|
||||||
|
import com.l2jmobius.gameserver.network.serverpackets.SystemMessage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extractable Items handler.
|
* Extractable Items handler.
|
||||||
* @author HorridoJoho
|
* @author HorridoJoho, Mobius
|
||||||
*/
|
*/
|
||||||
public class ExtractableItems implements IItemHandler
|
public class ExtractableItems implements IItemHandler
|
||||||
{
|
{
|
||||||
@@ -45,8 +48,8 @@ public class ExtractableItems implements IItemHandler
|
|||||||
|
|
||||||
final L2PcInstance activeChar = playable.getActingPlayer();
|
final L2PcInstance activeChar = playable.getActingPlayer();
|
||||||
final L2EtcItem etcitem = (L2EtcItem) item.getItem();
|
final L2EtcItem etcitem = (L2EtcItem) item.getItem();
|
||||||
final List<L2ExtractableProduct> exitem = etcitem.getExtractableItems();
|
final List<L2ExtractableProduct> exitems = etcitem.getExtractableItems();
|
||||||
if (exitem == null)
|
if (exitems == null)
|
||||||
{
|
{
|
||||||
_log.info("No extractable data defined for " + etcitem);
|
_log.info("No extractable data defined for " + etcitem);
|
||||||
return false;
|
return false;
|
||||||
@@ -58,40 +61,162 @@ public class ExtractableItems implements IItemHandler
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean created = false;
|
final List<L2ItemInstance> extractedItems = new ArrayList<>();
|
||||||
for (L2ExtractableProduct expi : exitem)
|
final List<L2ItemInstance> enchantedItems = new ArrayList<>();
|
||||||
|
if (etcitem.getExtractableCountMin() > 0)
|
||||||
{
|
{
|
||||||
if (Rnd.get(100000) <= expi.getChance())
|
while (extractedItems.size() < etcitem.getExtractableCountMin())
|
||||||
{
|
{
|
||||||
final int min = (int) (expi.getMin() * Config.RATE_EXTRACTABLE);
|
for (L2ExtractableProduct expi : exitems)
|
||||||
final int max = (int) (expi.getMax() * Config.RATE_EXTRACTABLE);
|
|
||||||
|
|
||||||
int createItemAmount = (max == min) ? min : (Rnd.get((max - min) + 1) + min);
|
|
||||||
if (createItemAmount == 0)
|
|
||||||
{
|
{
|
||||||
continue;
|
if ((etcitem.getExtractableCountMax() > 0) && (extractedItems.size() == etcitem.getExtractableCountMax()))
|
||||||
}
|
|
||||||
|
|
||||||
if (item.isStackable() || (createItemAmount == 1))
|
|
||||||
{
|
|
||||||
activeChar.addItem("Extract", expi.getId(), createItemAmount, activeChar, true);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (createItemAmount > 0)
|
|
||||||
{
|
{
|
||||||
activeChar.addItem("Extract", expi.getId(), 1, activeChar, true);
|
break;
|
||||||
createItemAmount--;
|
}
|
||||||
|
|
||||||
|
if (Rnd.get(100000) <= expi.getChance())
|
||||||
|
{
|
||||||
|
final int min = (int) (expi.getMin() * Config.RATE_EXTRACTABLE);
|
||||||
|
final int max = (int) (expi.getMax() * Config.RATE_EXTRACTABLE);
|
||||||
|
|
||||||
|
int createItemAmount = (max == min) ? min : (Rnd.get((max - min) + 1) + min);
|
||||||
|
if (createItemAmount == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not extract the same item.
|
||||||
|
boolean alreadyExtracted = false;
|
||||||
|
for (L2ItemInstance i : extractedItems)
|
||||||
|
{
|
||||||
|
if (i.getItem().getId() == expi.getId())
|
||||||
|
{
|
||||||
|
alreadyExtracted = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (alreadyExtracted && (exitems.size() >= etcitem.getExtractableCountMax()))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.isStackable() || (createItemAmount == 1))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
extractedItems.add(newItem);
|
||||||
|
sendMessage(activeChar, newItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (createItemAmount > 0)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
extractedItems.add(newItem);
|
||||||
|
sendMessage(activeChar, newItem);
|
||||||
|
createItemAmount--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (L2ExtractableProduct expi : exitems)
|
||||||
|
{
|
||||||
|
if ((etcitem.getExtractableCountMax() > 0) && (extractedItems.size() == etcitem.getExtractableCountMax()))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Rnd.get(100000) <= expi.getChance())
|
||||||
|
{
|
||||||
|
final int min = (int) (expi.getMin() * Config.RATE_EXTRACTABLE);
|
||||||
|
final int max = (int) (expi.getMax() * Config.RATE_EXTRACTABLE);
|
||||||
|
|
||||||
|
int createItemAmount = (max == min) ? min : (Rnd.get((max - min) + 1) + min);
|
||||||
|
if (createItemAmount == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item.isStackable() || (createItemAmount == 1))
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
extractedItems.add(newItem);
|
||||||
|
sendMessage(activeChar, newItem);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (createItemAmount > 0)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
extractedItems.add(newItem);
|
||||||
|
sendMessage(activeChar, newItem);
|
||||||
|
createItemAmount--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
created = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!created)
|
if (extractedItems.size() == 0)
|
||||||
{
|
{
|
||||||
activeChar.sendPacket(SystemMessageId.THERE_WAS_NOTHING_FOUND_INSIDE);
|
activeChar.sendPacket(SystemMessageId.THERE_WAS_NOTHING_FOUND_INSIDE);
|
||||||
}
|
}
|
||||||
|
if (!enchantedItems.isEmpty())
|
||||||
|
{
|
||||||
|
final InventoryUpdate playerIU = new InventoryUpdate();
|
||||||
|
for (L2ItemInstance i : enchantedItems)
|
||||||
|
{
|
||||||
|
playerIU.addModifiedItem(i);
|
||||||
|
}
|
||||||
|
activeChar.sendPacket(playerIU);
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sendMessage(L2PcInstance player, L2ItemInstance item)
|
||||||
|
{
|
||||||
|
final SystemMessage sm;
|
||||||
|
if (item.getCount() > 1)
|
||||||
|
{
|
||||||
|
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1);
|
||||||
|
sm.addItemName(item);
|
||||||
|
sm.addLong(item.getCount());
|
||||||
|
}
|
||||||
|
else if (item.getEnchantLevel() > 0)
|
||||||
|
{
|
||||||
|
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_A_S1_S2);
|
||||||
|
sm.addInt(item.getEnchantLevel());
|
||||||
|
sm.addItemName(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S1);
|
||||||
|
sm.addItemName(item);
|
||||||
|
}
|
||||||
|
player.sendPacket(sm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,7 +25,7 @@ import com.l2jmobius.gameserver.model.quest.State;
|
|||||||
import quests.Q10817_ExaltedOneWhoOvercomesTheLimit.Q10817_ExaltedOneWhoOvercomesTheLimit;
|
import quests.Q10817_ExaltedOneWhoOvercomesTheLimit.Q10817_ExaltedOneWhoOvercomesTheLimit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For Honor (10821)
|
* Helping Others (10821)
|
||||||
* @URL https://l2wiki.com/Helping_Others
|
* @URL https://l2wiki.com/Helping_Others
|
||||||
* @author Mobius
|
* @author Mobius
|
||||||
*/
|
*/
|
||||||
|
10
trunk/dist/game/data/stats/items/search.cmd
vendored
Normal file
10
trunk/dist/game/data/stats/items/search.cmd
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
@echo off
|
||||||
|
title XML Search
|
||||||
|
cls
|
||||||
|
:search
|
||||||
|
set /p text="Enter search text: "
|
||||||
|
echo.
|
||||||
|
echo.search text "%text%" result:
|
||||||
|
findstr /I /N %text% *.xml
|
||||||
|
echo.
|
||||||
|
goto search
|
2
trunk/dist/game/data/xsd/items.xsd
vendored
2
trunk/dist/game/data/xsd/items.xsd
vendored
@@ -80,6 +80,8 @@
|
|||||||
<xs:enumeration value="equip_condition" />
|
<xs:enumeration value="equip_condition" />
|
||||||
<xs:enumeration value="equip_reuse_delay" />
|
<xs:enumeration value="equip_reuse_delay" />
|
||||||
<xs:enumeration value="ex_immediate_effect" />
|
<xs:enumeration value="ex_immediate_effect" />
|
||||||
|
<xs:enumeration value="extractableCountMin" />
|
||||||
|
<xs:enumeration value="extractableCountMax" />
|
||||||
<xs:enumeration value="etcitem_type" />
|
<xs:enumeration value="etcitem_type" />
|
||||||
<xs:enumeration value="for_npc" />
|
<xs:enumeration value="for_npc" />
|
||||||
<xs:enumeration value="handler" />
|
<xs:enumeration value="handler" />
|
||||||
|
@@ -174,7 +174,9 @@ public final class DocumentItem extends DocumentBase implements IGameXmlReader
|
|||||||
final int min = parseInteger(b.getAttributes(), "min");
|
final int min = parseInteger(b.getAttributes(), "min");
|
||||||
final int max = parseInteger(b.getAttributes(), "max");
|
final int max = parseInteger(b.getAttributes(), "max");
|
||||||
final double chance = parseDouble(b.getAttributes(), "chance");
|
final double chance = parseDouble(b.getAttributes(), "chance");
|
||||||
_currentItem.item.addCapsuledItem(new L2ExtractableProduct(id, min, max, chance));
|
final int minEnchant = parseInteger(b.getAttributes(), "minEnchant", 0);
|
||||||
|
final int maxEnchant = parseInteger(b.getAttributes(), "maxEnchant", 0);
|
||||||
|
_currentItem.item.addCapsuledItem(new L2ExtractableProduct(id, min, max, chance, minEnchant, maxEnchant));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -25,20 +25,26 @@ public class L2ExtractableProduct
|
|||||||
private final int _min;
|
private final int _min;
|
||||||
private final int _max;
|
private final int _max;
|
||||||
private final int _chance;
|
private final int _chance;
|
||||||
|
private final int _minEnchant;
|
||||||
|
private final int _maxEnchant;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create Extractable product
|
* Create Extractable product
|
||||||
* @param id crete item id
|
* @param id create item id
|
||||||
* @param min item count max
|
* @param min item count max
|
||||||
* @param max item count min
|
* @param max item count min
|
||||||
* @param chance chance for creating
|
* @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;
|
_id = id;
|
||||||
_min = min;
|
_min = min;
|
||||||
_max = max;
|
_max = max;
|
||||||
_chance = (int) (chance * 1000);
|
_chance = (int) (chance * 1000);
|
||||||
|
_minEnchant = minEnchant;
|
||||||
|
_maxEnchant = maxEnchant;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId()
|
public int getId()
|
||||||
@@ -60,4 +66,14 @@ public class L2ExtractableProduct
|
|||||||
{
|
{
|
||||||
return _chance;
|
return _chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getMinEnchant()
|
||||||
|
{
|
||||||
|
return _minEnchant;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxEnchant()
|
||||||
|
{
|
||||||
|
return _maxEnchant;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -32,6 +32,8 @@ public final class L2EtcItem extends L2Item
|
|||||||
private String _handler;
|
private String _handler;
|
||||||
private EtcItemType _type;
|
private EtcItemType _type;
|
||||||
private List<L2ExtractableProduct> _extractableItems;
|
private List<L2ExtractableProduct> _extractableItems;
|
||||||
|
private int _extractableCountMin;
|
||||||
|
private int _extractableCountMax;
|
||||||
private boolean _isInfinite;
|
private boolean _isInfinite;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,6 +63,14 @@ public final class L2EtcItem extends L2Item
|
|||||||
}
|
}
|
||||||
|
|
||||||
_handler = set.getString("handler", null); // ! null !
|
_handler = set.getString("handler", null); // ! null !
|
||||||
|
|
||||||
|
_extractableCountMin = set.getInt("extractableCountMin", 0);
|
||||||
|
_extractableCountMax = set.getInt("extractableCountMax", 0);
|
||||||
|
if (_extractableCountMin > _extractableCountMax)
|
||||||
|
{
|
||||||
|
LOGGER.warning("Item " + this + " extractableCountMin is bigger than extractableCountMax!");
|
||||||
|
}
|
||||||
|
|
||||||
_isInfinite = set.getBoolean("is_infinite", false);
|
_isInfinite = set.getBoolean("is_infinite", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +108,22 @@ public final class L2EtcItem extends L2Item
|
|||||||
return _extractableItems;
|
return _extractableItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the minimum count of extractable items
|
||||||
|
*/
|
||||||
|
public int getExtractableCountMin()
|
||||||
|
{
|
||||||
|
return _extractableCountMin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the maximum count of extractable items
|
||||||
|
*/
|
||||||
|
public int getExtractableCountMax()
|
||||||
|
{
|
||||||
|
return _extractableCountMax;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if item is infinite
|
* @return true if item is infinite
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user