Lineage II Classic Einhovant new project is looking for a skilled Java Developer to join our team!
If you're passionate about game development and eager to contribute to this project, we'd love to hear from you.
For more details, feel free to send us a message. Let’s create something amazing together!
Question
l2jkain
Hello I created this system to drop enchanted items but it drops 2 item even putting the amount 1. What can I do to improve the code ?
Index: java/net/sf/l2j/gameserver/model/actor/Attackable.java
===================================================================
--- java/net/sf/l2j/gameserver/model/actor/Attackable.java (revision 3)
+++ java/net/sf/l2j/gameserver/model/actor/Attackable.java (working copy)
@@ -1184,6 +1184,28 @@
}
}
+ // Drop All Monsters Itens enchantados By Dev Williams
+ if ((Config.ENABLE_DROP_ITEM_ENCHANT) && ((this instanceof Monster)))
+ {
+ for (int i = 1; i < 81; i++)
+ {
+ if (i > 10)
+ {
+ if (player.getLevel() == i && getLevel() < player.getLevel() - 8)
+ return;
+ }
+ }
+ if (Rnd.get(100) < Config.DROP_ITEM_ENCHANT[3])
+ {
+ IntIntHolder item = new IntIntHolder(Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1]);
+ if (Config.AUTO_LOOT)
+ player.doAutoLoot(this, item);
+ else
+ dropItem(player, item);
+ player.getInventory().addEnchantedItem("Reward Enchant: ", Config.DROP_ITEM_ENCHANT[0], Config.DROP_ITEM_ENCHANT[1], Config.DROP_ITEM_ENCHANT[2], player, null);
+ }
+ }
+
Index: java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java
===================================================================
--- java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java (revision 2)
+++ java/net/sf/l2j/gameserver/model/itemcontainer/PcInventory.java (working copy)
@@ -17,9 +17,11 @@
import net.sf.l2j.gameserver.model.itemcontainer.listeners.ItemPassiveSkillsListener;
import net.sf.l2j.gameserver.model.tradelist.TradeItem;
import net.sf.l2j.gameserver.model.tradelist.TradeList;
+import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.InventoryUpdate;
import net.sf.l2j.gameserver.network.serverpackets.ItemList;
import net.sf.l2j.gameserver.network.serverpackets.StatusUpdate;
+import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.taskmanager.ShadowItemTaskManager;
public class PcInventory extends Inventory
@@ -439,6 +441,43 @@
return item;
}
+
+ public ItemInstance addEnchantedItem(String process, int itemId, int itemCount, int enchantLevel, Player actor, WorldObject reference)
+ {
+ ItemInstance item = super.addItem(process, itemId, itemCount, actor, reference);
+
+ if (item == null)
+ return null;
+
+ if (enchantLevel > 0)
+ item.setEnchantLevel(enchantLevel);
+
+ if (itemId == 57)
+ {
+ SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S1_ADENA);
+ smsg.addItemNumber(itemCount);
+ actor.sendPacket(smsg);
+ }
+ else if (itemCount > 1)
+ {
+ SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.EARNED_S2_S1_S);
+ smsg.addItemName(itemId);
+ smsg.addItemNumber(itemCount);
+ actor.sendPacket(smsg);
+ }
+ else
+ {
+ SystemMessage smsg = SystemMessage.getSystemMessage(SystemMessageId.ACQUIRED_S1_S2);
+ smsg.addNumber(enchantLevel);
+ smsg.addItemName(itemId);
+ actor.sendPacket(smsg);
+ }
+ StatusUpdate su = new StatusUpdate(actor);
+ su.addAttribute(14, actor.getCurrentLoad());
+ actor.sendPacket(su);
+
+ return item;
+ }
11 answers to this question
Recommended Posts