diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_1.0_Ertheia/dist/game/data/xsd/skills.xsd b/L2J_Mobius_1.0_Ertheia/dist/game/data/xsd/skills.xsd index ba8e72fc3f..af32c9fe01 100644 --- a/L2J_Mobius_1.0_Ertheia/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_1.0_Ertheia/dist/game/data/xsd/skills.xsd @@ -1237,6 +1237,8 @@ + + diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_1.0_Ertheia/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +} diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_2.5_Underground/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_2.5_Underground/dist/game/data/xsd/skills.xsd b/L2J_Mobius_2.5_Underground/dist/game/data/xsd/skills.xsd index 71287d5743..cc3594e13d 100644 --- a/L2J_Mobius_2.5_Underground/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_2.5_Underground/dist/game/data/xsd/skills.xsd @@ -1241,6 +1241,8 @@ + + diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_2.5_Underground/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +} diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_3.0_Helios/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_3.0_Helios/dist/game/data/xsd/skills.xsd b/L2J_Mobius_3.0_Helios/dist/game/data/xsd/skills.xsd index 9a59671ca7..4e3c4d8d9d 100644 --- a/L2J_Mobius_3.0_Helios/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_3.0_Helios/dist/game/data/xsd/skills.xsd @@ -1273,6 +1273,8 @@ + + diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_3.0_Helios/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +} diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/xsd/skills.xsd b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/xsd/skills.xsd index 4be3b54e92..0dbdcb8d5b 100644 --- a/L2J_Mobius_4.0_GrandCrusade/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_4.0_GrandCrusade/dist/game/data/xsd/skills.xsd @@ -1292,6 +1292,8 @@ + + diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_4.0_GrandCrusade/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +} diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/xsd/skills.xsd b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/xsd/skills.xsd index be1183aaf8..154fd9e671 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_Classic_2.0_Saviors/dist/game/data/xsd/skills.xsd @@ -1355,7 +1355,9 @@ - + + + diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_Classic_2.0_Saviors/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +} diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/xsd/skills.xsd b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/xsd/skills.xsd index be1183aaf8..154fd9e671 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_Classic_2.1_Zaken/dist/game/data/xsd/skills.xsd @@ -1355,7 +1355,9 @@ - + + + diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_Classic_2.1_Zaken/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +} diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java index 339f3dbc38..b81aa4722e 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java +++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/scripts/handlers/effecthandlers/RestorationRandom.java @@ -17,7 +17,10 @@ package handlers.effecthandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Map.Entry; import com.l2jmobius.Config; import com.l2jmobius.commons.util.Rnd; @@ -27,16 +30,17 @@ import com.l2jmobius.gameserver.model.actor.L2Character; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.effects.AbstractEffect; import com.l2jmobius.gameserver.model.effects.L2EffectType; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; import com.l2jmobius.gameserver.model.items.instance.L2ItemInstance; import com.l2jmobius.gameserver.model.skills.Skill; import com.l2jmobius.gameserver.network.SystemMessageId; +import com.l2jmobius.gameserver.network.serverpackets.SystemMessage; /** * Restoration Random effect implementation.
* This effect is present in item skills that "extract" new items upon usage.
* This effect has been unhardcoded in order to work on targets as well. - * @author Zoey76 + * @author Zoey76, Mobius */ public final class RestorationRandom extends AbstractEffect { @@ -46,10 +50,10 @@ public final class RestorationRandom extends AbstractEffect { for (StatsSet group : params.getList("items", StatsSet.class)) { - final List items = new ArrayList<>(); + final List items = new ArrayList<>(); for (StatsSet item : group.getList(".", StatsSet.class)) { - items.add(new ItemHolder(item.getInt(".id"), item.getInt(".count"))); + items.add(new RestorationItemHolder(item.getInt(".id"), item.getInt(".count"), item.getInt(".minEnchant", 0), item.getInt(".maxEnchant", 0))); } _products.add(new L2ExtractableProductItem(items, group.getFloat(".chance"))); } @@ -67,7 +71,7 @@ public final class RestorationRandom extends AbstractEffect final double rndNum = 100 * Rnd.nextDouble(); double chance = 0; double chanceFrom = 0; - final List creationList = new ArrayList<>(); + final List creationList = new ArrayList<>(); // Explanation for future changes: // You get one chance for the current skill, then you can fall into @@ -96,13 +100,35 @@ public final class RestorationRandom extends AbstractEffect return; } - for (ItemHolder createdItem : creationList) + final Map extractedItems = new HashMap<>(); + for (RestorationItemHolder createdItem : creationList) { if ((createdItem.getId() <= 0) || (createdItem.getCount() <= 0)) { continue; } - player.addItem("Extract", createdItem.getId(), (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE), effector, true); + + long itemCount = (long) (createdItem.getCount() * Config.RATE_EXTRACTABLE); + final L2ItemInstance newItem = player.addItem("Extract", createdItem.getId(), itemCount, effector, false); + + if (createdItem.getMaxEnchant() > 0) + { + newItem.setEnchantLevel(Rnd.get(createdItem.getMinEnchant(), createdItem.getMaxEnchant())); + } + + if (extractedItems.get(newItem) != null) + { + extractedItems.put(newItem, extractedItems.get(newItem) + itemCount); + } + else + { + extractedItems.put(newItem, itemCount); + } + } + + for (Entry entry : extractedItems.entrySet()) + { + sendMessage(player, entry.getKey(), entry.getValue()); } } @@ -111,4 +137,27 @@ public final class RestorationRandom extends AbstractEffect { return L2EffectType.EXTRACT_ITEM; } + + private void sendMessage(L2PcInstance player, L2ItemInstance item, Long count) + { + final SystemMessage sm; + if (count > 1) + { + sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_HAVE_OBTAINED_S2_S1); + sm.addItemName(item); + sm.addLong(count); + } + 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); + } } diff --git a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/xsd/skills.xsd b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/xsd/skills.xsd index be1183aaf8..154fd9e671 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/xsd/skills.xsd +++ b/L2J_Mobius_Classic_2.2_Antharas/dist/game/data/xsd/skills.xsd @@ -1355,7 +1355,9 @@ - + + + diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java index 8507c732d0..3644453c83 100644 --- a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/L2ExtractableProductItem.java @@ -18,17 +18,17 @@ package com.l2jmobius.gameserver.model; import java.util.List; -import com.l2jmobius.gameserver.model.holders.ItemHolder; +import com.l2jmobius.gameserver.model.holders.RestorationItemHolder; /** * @author Zoey76 */ public class L2ExtractableProductItem { - private final List _items; + private final List _items; private final double _chance; - public L2ExtractableProductItem(List items, double chance) + public L2ExtractableProductItem(List items, double chance) { _items = items; _chance = chance; @@ -37,7 +37,7 @@ public class L2ExtractableProductItem /** * @return the the production list. */ - public List getItems() + public List getItems() { return _items; } diff --git a/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java new file mode 100644 index 0000000000..e7c86af9b5 --- /dev/null +++ b/L2J_Mobius_Classic_2.2_Antharas/java/com/l2jmobius/gameserver/model/holders/RestorationItemHolder.java @@ -0,0 +1,56 @@ +/* + * 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 . + */ +package com.l2jmobius.gameserver.model.holders; + +/** + * @author Mobius + */ +public class RestorationItemHolder +{ + private final int _id; + private final long _count; + private final int _minEnchant; + private final int _maxEnchant; + + public RestorationItemHolder(int id, long count, int minEnchant, int maxEnchant) + { + _id = id; + _count = count; + _minEnchant = minEnchant; + _maxEnchant = maxEnchant; + } + + public int getId() + { + return _id; + } + + public long getCount() + { + return _count; + } + + public int getMinEnchant() + { + return _minEnchant; + } + + public int getMaxEnchant() + { + return _maxEnchant; + } +}