Updated collection packets.

Contributed by Index.
This commit is contained in:
MobiusDevelopment
2022-10-08 23:27:49 +00:00
parent 4f631eab7c
commit b108ba37c3
8 changed files with 74 additions and 34 deletions

View File

@@ -26,7 +26,10 @@ import org.l2jmobius.gameserver.model.holders.PlayerCollectionData;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.options.Options;
import org.l2jmobius.gameserver.network.GameClient;
import org.l2jmobius.gameserver.network.SystemMessageId;
import org.l2jmobius.gameserver.network.clientpackets.IClientIncomingPacket;
import org.l2jmobius.gameserver.network.serverpackets.ConfirmDlg;
import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
import org.l2jmobius.gameserver.network.serverpackets.collection.ExCollectionComplete;
import org.l2jmobius.gameserver.network.serverpackets.collection.ExCollectionRegister;
@@ -86,9 +89,18 @@ public class RequestCollectionRegister implements IClientIncomingPacket
return;
}
PlayerCollectionData currentColl = player.getCollections().stream().filter(it -> it.getCollectionId() == _collectionId).findAny().orElse(null);
if ((currentColl != null) && (currentColl.getIndex() == _index))
{
player.sendPacket(new ExCollectionRegister(false, _collectionId, _index, new ItemEnchantHolder(item.getId(), count, item.getEnchantLevel())));
player.sendPacket(SystemMessageId.THIS_ITEM_CANNOT_BE_ADDED_TO_YOUR_COLLECTION);
player.sendPacket(new ConfirmDlg("Collection already registered;"));
return;
}
player.destroyItem("Collection", item, count, player, true);
player.sendPacket(new ExCollectionRegister(_collectionId, _index, item));
player.sendPacket(new ExCollectionRegister(true, _collectionId, _index, new ItemEnchantHolder(item.getId(), count, item.getEnchantLevel())));
player.getCollections().add(new PlayerCollectionData(_collectionId, item.getId(), _index));
@@ -96,6 +108,9 @@ public class RequestCollectionRegister implements IClientIncomingPacket
{
player.sendPacket(new ExCollectionComplete(_collectionId));
// TODO: CollectionData.getInstance().getCollection(_collectionId).getName()
player.sendPacket(new SystemMessage(SystemMessageId.S1_COLLECTION_IS_COMPLETED).addString(""));
// Apply collection option if all requirements are met.
final Options options = OptionData.getInstance().getOptions(collection.getOptionId());
if (options != null)

View File

@@ -21,7 +21,7 @@ import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 13.04.2021
* @author Berezkin Nikolay
*/
public class ExCollectionComplete implements IClientOutgoingPacket
{
@@ -37,6 +37,7 @@ public class ExCollectionComplete implements IClientOutgoingPacket
{
OutgoingPackets.EX_COLLECTION_COMPLETE.writeId(packet);
packet.writeH(_collectionId);
packet.writeD(0);
return true;
}
}

View File

@@ -28,7 +28,7 @@ import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 12.04.2021
* @author Berezkin Nikolay
*/
public class ExCollectionInfo implements IClientOutgoingPacket
{
@@ -60,7 +60,8 @@ public class ExCollectionInfo implements IClientOutgoingPacket
{
packet.writeC(current.getIndex());
packet.writeD(current.getItemId());
packet.writeH(CollectionData.getInstance().getCollection(collection).getItems().get(current.getIndex()).getEnchantLevel()); // enchant level
packet.writeC(CollectionData.getInstance().getCollection(collection).getItems().get(current.getIndex()).getEnchantLevel()); // enchant level
packet.writeC(0); // unk flag for item
packet.writeC(0); // unk flag for item
packet.writeD(1); // count
}

View File

@@ -17,24 +17,26 @@
package org.l2jmobius.gameserver.network.serverpackets.collection;
import org.l2jmobius.commons.network.PacketWriter;
import org.l2jmobius.gameserver.model.item.instance.Item;
import org.l2jmobius.gameserver.model.holders.ItemEnchantHolder;
import org.l2jmobius.gameserver.network.OutgoingPackets;
import org.l2jmobius.gameserver.network.serverpackets.IClientOutgoingPacket;
/**
* Written by Berezkin Nikolay, on 12.04.2021
* @author Berezkin Nikolay, Index
*/
public class ExCollectionRegister implements IClientOutgoingPacket
{
private final int _success;
private final int _collectionId;
private final int _index;
private final Item _item;
private final ItemEnchantHolder _collectionInfo;
public ExCollectionRegister(int collectionId, int index, Item item)
public ExCollectionRegister(boolean success, int collectionId, int index, ItemEnchantHolder collectionInfo)
{
_success = success ? 1 : 0;
_collectionId = collectionId;
_index = index;
_item = item;
_collectionInfo = collectionInfo;
}
@Override
@@ -42,14 +44,15 @@ public class ExCollectionRegister implements IClientOutgoingPacket
{
OutgoingPackets.EX_COLLECTION_REGISTER.writeId(packet);
packet.writeH(_collectionId);
packet.writeC(1);
packet.writeC(0x0E);
packet.writeC(0);
packet.writeC(_index);
packet.writeD(_item.getId());
packet.writeH(0);
packet.writeC(0);
packet.writeD(0);
packet.writeC(_success); // success
packet.writeC(0); // recursive reward
packet.writeH(packet.getWritableBytes()); // size
packet.writeC(_index); // slot index
packet.writeD(_collectionInfo.getId()); // item classId
packet.writeH(_collectionInfo.getEnchantLevel()); // enchant level
packet.writeC(0); // is blessed
packet.writeC(0); // blessed conditions
packet.writeD((int) _collectionInfo.getCount()); // amount
return true;
}
}