[Ядро] Вещи в ВХ

BaldIriskin

Выдающийся
VIP
Сообщения
65
Розыгрыши
0
Репутация
35
Реакции
26
Баллы
1 318
Добрый вечер, появилась проблема Сборка EmuRT, с не правильным отображением количества итемов при попытке их положить в ВХ,КВХ, в инвентаре всё отображается правильно, кто подскажет как исправить?

Скрины
Shot00013.jpg Shot00014.jpg
 
Последнее редактирование модератором:
в пакет лезет какая-то дичь, смотреть пакетку
 
логично, что никаких ошибок он не выдаёт, но в пакет лезет какое-то дерьмо.

вопрос 100% в пакетке || в том что в пакет передаётся.
 
Сами пакеты, кто подскажет?
Код:
package l2p.gameserver.clientpackets;

import l2p.commons.lang.ArrayUtils;
import l2p.commons.math.SafeMath;
import l2p.gameserver.Config;
import l2p.gameserver.model.Creature;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.instances.NpcInstance;
import l2p.gameserver.model.items.ItemInstance;
import l2p.gameserver.model.items.PcInventory;
import l2p.gameserver.model.items.Warehouse;
import l2p.gameserver.model.items.Warehouse.WarehouseType;
import l2p.gameserver.model.pledge.Clan;
import l2p.gameserver.serverpackets.components.SystemMsg;
import l2p.gameserver.utils.Log;
import l2p.gameserver.utils.Log.ItemLog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SendWareHouseWithDrawList extends L2GameClientPacket {

    private static final Logger _log = LoggerFactory.getLogger(SendWareHouseWithDrawList.class);
    private int _count;
    private int[] _items;
    private long[] _itemQ;

    @Override
    protected void readImpl() {
        _count = readD();
        if (_count * 12 > _buf.remaining() || _count > Short.MAX_VALUE || _count < 1) {
            _count = 0;
            return;
        }
        _items = new int[_count];
        _itemQ = new long[_count];
        for (int i = 0; i < _count; i++) {
            _items[i] = readD(); // item object id
            _itemQ[i] = readQ(); // count
            if (_itemQ[i] < 1 || ArrayUtils.indexOf(_items, _items[i]) < i) {
                _count = 0;
                break;
            }
        }
    }

    @Override
    protected void runImpl() {
        final Player activeChar = getClient().getActiveChar();
        if (activeChar == null || _count == 0) {
            return;
        }

        if (!activeChar.getPlayerAccess().isUseWarehouse()) {
            activeChar.sendActionFailed();
            return;
        }

        if (activeChar.isActionsDisabled()) {
            activeChar.sendActionFailed();
            return;
        }

        if (activeChar.isInStoreMode()) {
            activeChar.sendPacket(SystemMsg.WHILE_OPERATING_A_PRIVATE_STORE_OR_WORKSHOP_YOU_CANNOT_DISCARD_DESTROY_OR_TRADE_AN_ITEM);
            return;
        }

        if (activeChar.isInTrade()) {
            activeChar.sendActionFailed();
            return;
        }

        final NpcInstance whkeeper = activeChar.getLastNpc();
        if (!Config.COMMUNITY_WAREHOUSE_ALLOW && (whkeeper == null || !activeChar.isInRange(whkeeper, Creature.INTERACTION_DISTANCE))) {
            activeChar.sendPacket(SystemMsg.WAREHOUSE_IS_TOO_FAR);
            return;
        }

        final Warehouse warehouse;
        final ItemLog logType;

        if (activeChar.getUsingWarehouseType() == WarehouseType.PRIVATE) {
            warehouse = activeChar.getWarehouse();
            logType = ItemLog.WarehouseWithdraw;
        } else if (activeChar.getUsingWarehouseType() == WarehouseType.CLAN) {
            logType = ItemLog.ClanWarehouseWithdraw;
            boolean canWithdrawCWH = false;
            if (activeChar.getClan() != null) {
                if ((activeChar.getClanPrivileges() & Clan.CP_CL_WAREHOUSE_SEARCH) == Clan.CP_CL_WAREHOUSE_SEARCH && (Config.ALT_ALLOW_OTHERS_WITHDRAW_FROM_CLAN_WAREHOUSE || activeChar.isClanLeader() || activeChar.getVarB("canWhWithdraw"))) {
                    canWithdrawCWH = true;
                }
            }
            if (!canWithdrawCWH) {
                return;
            }

            warehouse = activeChar.getClan().getWarehouse();
        } else if (activeChar.getUsingWarehouseType() == WarehouseType.FREIGHT) {
            warehouse = activeChar.getFreight();
            logType = ItemLog.FreightWithdraw;
        } else {
            _log.warn("Error retrieving a warehouse object for char " + activeChar.getName() + " - using warehouse type: " + activeChar.getUsingWarehouseType());
            return;
        }

        final PcInventory inventory = activeChar.getInventory();

        inventory.writeLock();
        warehouse.writeLock();
        try {
            long weight = 0;
            int slots = 0;

            for (int i = 0; i < _count; i++) {
                final ItemInstance item = warehouse.getItemByObjectId(_items[i]);
                if (item == null || item.getCount() < _itemQ[i]) {
                    activeChar.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
                    return;
                }

                weight = SafeMath.addAndCheck(weight, SafeMath.mulAndCheck(item.getTemplate().getWeight(), _itemQ[i]));
                if (!item.isStackable() || inventory.getItemByItemId(item.getItemId()) == null) // вещь
                // требует
                // слота
                {
                    slots++;
                }
            }

            if (!activeChar.getInventory().validateCapacity(slots)) {
                activeChar.sendPacket(SystemMsg.YOUR_INVENTORY_IS_FULL);
                return;
            }

            if (!activeChar.getInventory().validateWeight(weight)) {
                activeChar.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_WEIGHT_LIMIT);
                return;
            }

            for (int i = 0; i < _count; i++) {
                final ItemInstance item = warehouse.removeItemByObjectId(_items[i], _itemQ[i]);
                Log.LogItem(activeChar, logType, item);
                activeChar.getInventory().addItem(item);
            }
        } catch (final ArithmeticException ae) {
            // TODO audit
            activeChar.sendPacket(SystemMsg.YOU_HAVE_EXCEEDED_THE_QUANTITY_THAT_CAN_BE_INPUTTED);
            return;
        } finally {
            warehouse.writeUnlock();
            inventory.writeUnlock();
        }

        activeChar.sendChanges();
        activeChar.sendPacket(SystemMsg.THE_TRANSACTION_IS_COMPLETE);
    }
}
Код:
package l2p.gameserver.serverpackets;

import l2p.commons.lang.ArrayUtils;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.items.ItemInstance;
import l2p.gameserver.model.items.Warehouse.ItemClassComparator;
import l2p.gameserver.model.items.Warehouse.WarehouseType;
import l2p.gameserver.templates.item.ItemTemplate.ItemClass;


public class WareHouseWithdrawList extends L2GameServerPacket {
    private final long _adena;
    private final ItemInstance[] _itemList;
    private final int _type;

    public WareHouseWithdrawList(final Player player, final WarehouseType type, final ItemClass clss) {
        _adena = player.getAdena();
        _type = type.ordinal();

        switch (type) {
            case PRIVATE:
                _itemList = player.getWarehouse().getItems(clss);
                break;
            case FREIGHT:
                _itemList = player.getFreight().getItems(clss);
                break;
            case CLAN:
            case CASTLE:
                _itemList = player.getClan().getWarehouse().getItems(clss);
                break;
            default:
                _itemList = new ItemInstance[0];
                ;
                return;
        }

        ArrayUtils.eqSort(_itemList, ItemClassComparator.getInstance());
    }

    @Override
    protected final void writeImpl() {
        writeC(0x42);
        writeH(_type);
        writeQ(_adena);
        writeH(_itemList.length);
        for (final ItemInstance item : _itemList) {
            writeItemInfo(item);
            writeD(item.getObjectId());
        }
    }
}
 
Код:
package l2p.gameserver.serverpackets;

import l2p.commons.net.nio.impl.SendablePacket;
import l2p.gameserver.GameServer;
import l2p.gameserver.data.xml.holder.ItemHolder;
import l2p.gameserver.model.Player;
import l2p.gameserver.model.base.Element;
import l2p.gameserver.model.base.MultiSellIngredient;
import l2p.gameserver.model.items.ItemInfo;
import l2p.gameserver.model.items.ItemInstance;
import l2p.gameserver.network.GameClient;
import l2p.gameserver.serverpackets.components.IStaticPacket;
import l2p.gameserver.templates.item.ItemTemplate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Set;

public abstract class L2GameServerPacket extends SendablePacket<GameClient> implements IStaticPacket {

    private static final Logger _log = LoggerFactory.getLogger(L2GameServerPacket.class);

    @Override
    public final boolean write() {
        try {
            writeImpl();
            return true;
        } catch (final Exception e) {
            _log.error("Client: " + getClient() + " - Failed writing: " + getType() + " - Server Version: " + GameServer.getInstance().getVersion().getRevisionNumber(), e);
        }
        return false;
    }

    protected abstract void writeImpl();

    protected void writeEx(final int value) {
        writeC(0xFE);
        writeH(value);
    }

    protected void writeD(final boolean b) {
        writeD(b ? 1 : 0);
    }

    /**
     * Отсылает число позиций + массив
     */
    protected void writeDD(final int[] values, final boolean sendCount) {
        if (sendCount) {
            getByteBuffer().putInt(values.length);
        }
        for (final int value : values) {
            getByteBuffer().putInt(value);
        }
    }

    protected void writeDD(final Set<Integer> values, final boolean sendCount) {
        if (sendCount) {
            getByteBuffer().putInt(values.size());
        }
        for (final int value : values) {
            getByteBuffer().putInt(value);
        }
    }

    protected void writeDD(final int[] values) {
        writeDD(values, false);
    }

    protected void writeItemElements(final ItemInfo item) {
        writeH(item.getAttackElement());
        writeH(item.getAttackElementValue());
        writeH(item.getDefenceFire());
        writeH(item.getDefenceWater());
        writeH(item.getDefenceWind());
        writeH(item.getDefenceEarth());
        writeH(item.getDefenceHoly());
        writeH(item.getDefenceUnholy());
    }

    protected void writeItemElements(final ItemInstance item) {
        writeH(item.getAttackElement().getId());
        writeH(item.getAttackElementValue());
        writeH(item.getDefenceFire());
        writeH(item.getDefenceWater());
        writeH(item.getDefenceWind());
        writeH(item.getDefenceEarth());
        writeH(item.getDefenceHoly());
        writeH(item.getDefenceUnholy());
    }

    protected void writeItemElements(final MultiSellIngredient item) {
        if (item.getItemId() <= 0) {
            writeItemElements();
            return;
        }
        final ItemTemplate i = ItemHolder.getInstance().getTemplate(item.getItemId());
        if (item.getItemAttributes().getValue() > 0) {
            if (i != null && i.isWeapon()) {
                final Element e = item.getItemAttributes().getElement();
                writeH(e.getId()); // attack element (-1 - none)
                writeH(item.getItemAttributes().getValue(e) + i.getBaseAttributeValue(e)); // attack element value
                writeH(0); // водная стихия (fire pdef)
                writeH(0); // огненная стихия (water pdef)
                writeH(0); // земляная стихия (wind pdef)
                writeH(0); // воздушная стихия (earth pdef)
                writeH(0); // темная стихия (holy pdef)
                writeH(0); // светлая стихия (dark pdef)
            } else if (i != null && i.isArmor()) {
                writeH(-1); // attack element (-1 - none)
                writeH(0); // attack element value
                for (final Element e : Element.VALUES) {
                    writeH(item.getItemAttributes().getValue(e) + i.getBaseAttributeValue(e));
                }
            } else {
                writeItemElements();
            }
        } else {
            writeItemElements();
        }
    }

    protected void writeItemElements() {
        writeH(-1); // attack element (-1 - none)
        writeH(0x00); // attack element value
        writeH(0x00); // водная стихия (fire pdef)
        writeH(0x00); // огненная стихия (water pdef)
        writeH(0x00); // земляная стихия (wind pdef)
        writeH(0x00); // воздушная стихия (earth pdef)
        writeH(0x00); // темная стихия (holy pdef)
        writeH(0x00); // светлая стихия (dark pdef)
    }

    protected void writeItemEnchantOptions(final ItemInfo item) {
        writeH(item.getEnchantOptions()[0]); // может они тут не нужны и нужно просто слать пустышку?
        writeH(item.getEnchantOptions()[1]);
        writeH(item.getEnchantOptions()[2]);
    }

    protected void writeItemEnchantOptions(final ItemInstance item) {
        writeH(item.getEnchantOptions()[0]); // может они тут не нужны и нужно просто слать пустышку?
        writeH(item.getEnchantOptions()[1]);
        writeH(item.getEnchantOptions()[2]);
    }

    protected void writeItemInfo(final ItemInstance item) {
        writeItemInfo(item, item.getCount());
    }

    protected void writeItemInfo(final ItemInstance item, final long count) {
        writeH(item.getTemplate().getType1()); // item type1
        writeD(item.getObjectId());
        writeD(item.getItemId());
        writeD(item.getEquipSlot()); // order
        writeQ(count);
        writeH(item.getTemplate().getType2ForPackets()); // item type2
        writeH(item.getCustomType1()); // item type3
        writeH(item.isEquipped() ? 1 : 0);
        writeD(item.getBodyPart()); // rev 415 slot 0006-lr.ear 0008-neck 0030-lr.finger 0040-head 0080-?? 0100-l.hand 0200-gloves 0400-chest 0800-pants 1000-feet 2000-?? 4000-r.hand 8000-r.hand
        writeH(item.getEnchantLevel()); // enchant level
        writeH(item.getCustomType2()); // item type3
        writeH(item.getAugmentations()[0]);
        writeH(item.getAugmentations()[1]);
        writeD(item.isShadowItem() ? item.getShadowLifeTime() : -1);
        writeItemElements(item);
        writeD(item.isTemporalItem() ? item.getTemporalLifeTime() : 0x00); // limited time item life remaining
        writeItemEnchantOptions(item);
    }

    protected void writeItemInfo(final ItemInfo item) {
        writeItemInfo(item, item.getCount());
    }

    protected void writeItemInfo(final ItemInfo item, final long count) {
        writeH(item.getType1()); // item type1
        writeD(item.getObjectId());
        writeD(item.getItemId());
        writeD(item.getEquipSlot()); // order
        writeQ(count);
        writeH(item.getItem().getType2ForPackets()); // item type2
        writeH(item.getCustomType1()); // item type3
        writeH(item.isEquipped() ? 1 : 0);
        writeD(item.getBodyPart()); // rev 415 slot 0006-lr.ear 0008-neck 0030-lr.finger 0040-head 0080-?? 0100-l.hand 0200-gloves 0400-chest 0800-pants 1000-feet 2000-?? 4000-r.hand 8000-r.hand
        writeH(item.getEnchantLevel()); // enchant level
        writeH(item.getCustomType2()); // item type3
        writeH(item.getAugmentations()[0]);
        writeH(item.getAugmentations()[1]);
        writeD(item.getItem().isShadowItem() ? item.getShadowLifeTime() : -1);
        writeItemElements(item);
        writeD(item.getItem().isTemporal() ? item.getTemporalLifeTime() : 0x00); // limited time item life remaining
        writeItemEnchantOptions(item);
    }

    public String getType() {
        return "[S] " + getClass().getSimpleName();
    }

    @Override
    public L2GameServerPacket packet(final Player player) {
        return this;
    }
}
 
Это тот упоротый эпилог? :eek:_O:
Ты еще всех фокусов не видел... :lel::lel::lel:
 
Прикольно а пакеты с хф :)
 
Назад
Сверху Снизу