Enchant support for CustomMailManager.

This commit is contained in:
MobiusDevelopment
2024-01-30 03:12:22 +02:00
parent 7b933621f0
commit 64b5d6251a
74 changed files with 2374 additions and 271 deletions

View File

@@ -33,7 +33,8 @@ import org.l2jmobius.gameserver.enums.MailType;
import org.l2jmobius.gameserver.model.Message;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.Player;
import org.l2jmobius.gameserver.model.holders.ItemHolder;
import org.l2jmobius.gameserver.model.holders.ItemEnchantHolder;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.itemcontainer.Mail;
import org.l2jmobius.gameserver.util.Util;
@@ -65,29 +66,35 @@ public class CustomMailManager
// Create message.
final String items = rs.getString("items");
final Message msg = new Message(playerId, rs.getString("subject"), rs.getString("message"), items.length() > 0 ? MailType.PRIME_SHOP_GIFT : MailType.REGULAR);
final List<ItemHolder> itemHolders = new ArrayList<>();
final List<ItemEnchantHolder> itemHolders = new ArrayList<>();
for (String str : items.split(";"))
{
if (str.contains(" "))
{
final String itemId = str.split(" ")[0];
final String itemCount = str.split(" ")[1];
final String[] split = str.split(" ");
final String itemId = split[0];
final String itemCount = split[1];
final String enchant = split.length > 2 ? split[2] : "0";
if (Util.isDigit(itemId) && Util.isDigit(itemCount))
{
itemHolders.add(new ItemHolder(Integer.parseInt(itemId), Long.parseLong(itemCount)));
itemHolders.add(new ItemEnchantHolder(Integer.parseInt(itemId), Long.parseLong(itemCount), Integer.parseInt(enchant)));
}
}
else if (Util.isDigit(str))
{
itemHolders.add(new ItemHolder(Integer.parseInt(str), 1));
itemHolders.add(new ItemEnchantHolder(Integer.parseInt(str), 1));
}
}
if (!itemHolders.isEmpty())
{
final Mail attachments = msg.createAttachments();
for (ItemHolder itemHolder : itemHolders)
for (ItemEnchantHolder itemHolder : itemHolders)
{
attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
final Item item = attachments.addItem("Custom-Mail", itemHolder.getId(), itemHolder.getCount(), null, null);
if (itemHolder.getEnchantLevel() > 0)
{
item.setEnchantLevel(itemHolder.getEnchantLevel());
}
}
}

View File

@@ -3370,6 +3370,21 @@ public class Player extends Playable
* @return
*/
public Item addItem(String process, int itemId, long count, WorldObject reference, boolean sendMessage)
{
return addItem(process, itemId, count, -1, reference, sendMessage);
}
/**
* Adds item to Inventory and send a Server->Client InventoryUpdate packet to the Player.
* @param process : String Identifier of process triggering this action
* @param itemId : int Item Identifier of the item to be added
* @param count : long Quantity of items to be added
* @param enchantLevel : int EnchantLevel of the item to be added
* @param reference : WorldObject Object referencing current action like NPC selling item or previous item in transformation
* @param sendMessage : boolean Specifies whether to send message to Client about this action
* @return
*/
public Item addItem(String process, int itemId, long count, int enchantLevel, WorldObject reference, boolean sendMessage)
{
if (count > 0)
{
@@ -3426,6 +3441,10 @@ public class Player extends Playable
{
// Add the item to inventory
final Item createdItem = _inventory.addItem(process, itemId, count, this, reference);
if (enchantLevel > -1)
{
createdItem.setEnchantLevel(enchantLevel);
}
// If over capacity, drop the item
if (!canOverrideCond(PlayerCondOverride.ITEM_CONDITIONS) && !_inventory.validateCapacity(0, item.isQuestItem()) && createdItem.isDropable() && (!createdItem.isStackable() || (createdItem.getLastChange() != Item.MODIFIED)))

View File

@@ -0,0 +1,73 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package org.l2jmobius.gameserver.model.holders;
import org.l2jmobius.gameserver.model.StatSet;
/**
* @author Index, Mobius
*/
public class ItemEnchantHolder extends ItemHolder
{
private final int _enchantLevel;
public ItemEnchantHolder(StatSet set)
{
super(set);
_enchantLevel = 0;
}
public ItemEnchantHolder(int id, long count)
{
super(id, count);
_enchantLevel = 0;
}
public ItemEnchantHolder(int id, long count, int enchantLevel)
{
super(id, count);
_enchantLevel = enchantLevel;
}
/**
* @return enchant level of items contained in this object
*/
public int getEnchantLevel()
{
return _enchantLevel;
}
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof ItemEnchantHolder objInstance))
{
return false;
}
else if (obj == this)
{
return true;
}
return (getId() == objInstance.getId()) && ((getCount() == objInstance.getCount()) && (_enchantLevel == objInstance.getEnchantLevel()));
}
@Override
public String toString()
{
return "[" + getClass().getSimpleName() + "] ID: " + getId() + ", count: " + getCount() + ", enchant level: " + _enchantLevel;
}
}