Metin2 İtemlerin Yer Değiştirmesi | Gamesfrm.com
Moderatör Alımları
Reklam Alanı   Reklam Alanı
Meyhane2   Reklam Alanı

Metin2 İtemlerin Yer Değiştirmesi

RuLing

İşsiz Moderatör
Yönetici
Haber Editörü
Sosyal Editör
Katılım
28 May 2018
Mesajlar
4,078
Tepki puanı
270
Konum
Diyarbakır
Merhaba arkadaşlar,

Envanterdeki itemlerin yerini kolayca değiştirmek için bu sistemi kullanabilirsiniz. Sistemin mantığı için gife bakabilirsiniz.

oXVJm7.gif



Char_item.cpp açılır ve aratılır

C++:
LPITEM CHARACTER::GetItem(TItemPos Cell) const

Kod bloğu altına eklenir

C++:
LPITEM CHARACTER::GetItem_NEW(const TItemPos &Cell) const
{
    CItem * cellItem = GetItem(Cell);
    if (cellItem)
        return cellItem;

    //There's no item in this cell, but that does not mean there is not an item which currently uses up this cell.
    uint16_t bCell = Cell.cell;
    uint8_t bPage = bCell / (4);

 
    for (int j = -5; j < 0; ++j)
    {
        uint8_t p = bCell + (5 * j);

        if (p / (4) != bPage)
            continue;

        if (p >= INVENTORY_MAX_NUM) // Eeh just for the sake of...
            continue;

        CItem * curCellItem = GetItem(TItemPos(INVENTORY, p));
        if (!curCellItem)
            continue;

        if (p + (curCellItem->GetSize() - 1) * 5 < Cell.cell) //Doesn't reach Cell.cell
            continue;

        return curCellItem;
    }

    return NULL;
}

Aratılır

C++:
            if (!IsEmptyItemGrid(DestCell, item->GetSize(), Cell.cell))
            return false;

Değiştirilir

C++:
        if (!IsEmptyItemGrid(DestCell, item->GetSize(), Cell.cell)) //It's not empty - Let's try swapping.
        {
            if (count != 0 && count != item->GetCount()) //Can't swap if not the item as a whole is being moved
                return false;

            if (!DestCell.IsDefaultInventoryPosition() || !Cell.IsDefaultInventoryPosition()) //Only this kind of swapping on inventory
                return false;

            CItem * targetItem = GetItem_NEW(DestCell);
            if (!targetItem)
                return false;
          
            if (targetItem->GetVID() == item->GetVID()) //Can't swap over my own slots
                return false;
              
            if (targetItem) {
                DestCell = TItemPos(INVENTORY, targetItem->GetCell());
            }

            if (item->IsExchanging() || (targetItem && targetItem->IsExchanging()))
                return false;

            if (targetItem->isLocked() == true)
                return false;
          
            uint8_t basePage = DestCell.cell / (4);
            std::map<uint16_t, CItem *> moveItemMap;
            uint8_t sizeLeft = item->GetSize();

            for (uint16_t i = 0; i < item->GetSize(); ++i)
            {
                uint16_t cellNumber = DestCell.cell + i * 5;

                uint8_t cPage = cellNumber / (4);
                if (basePage != cPage)
                    return false;

                CItem * mvItem = GetItem(TItemPos(INVENTORY, cellNumber));
                if (mvItem) {
                    if (mvItem->GetSize() > item->GetSize())
                        return false;

                    if (mvItem->IsExchanging())
                        return false;

                    moveItemMap.insert({ Cell.cell + i * 5, mvItem });
                    sizeLeft -= mvItem->GetSize();

                    if (mvItem->GetSize() > 1)
                        i += mvItem->GetSize() - 1; //Skip checking the obviously used cells
                }
                else {
                    sizeLeft -= 1; //Empty slot
                }
            }

            if (sizeLeft != 0)
                return false;

            //This map will hold cell positions for syncing the quickslots afterwards
            std::map<uint8_t, uint16_t> syncCells; //Quickslot pos -> Target cell.

            //Let's remove the original item
            syncCells.insert({ GetQuickslotPosition(QUICKSLOT_TYPE_ITEM, item->GetCell()), DestCell.cell });
            item->RemoveFromCharacter();

            for (auto & it : moveItemMap)
            {
                uint16_t toCellNumber = it.first;
                CItem * mvItem = it.second;

                syncCells.insert({ GetQuickslotPosition(QUICKSLOT_TYPE_ITEM, mvItem->GetCell()), toCellNumber });
                mvItem->RemoveFromCharacter();

#ifdef __HIGHLIGHT_SYSTEM__
                SetItem(TItemPos(INVENTORY, toCellNumber), mvItem, false);
#else
                SetItem(TItemPos(INVENTORY, toCellNumber), mvItem);
#endif
            }

#ifdef __HIGHLIGHT_SYSTEM__
            SetItem(DestCell, item, false);
#else
            SetItem(DestCell, item);
#endif

            //Sync quickslots only after all is set
            for (auto & sCell : syncCells)
            {
                TQuickslot qs;
                qs.type = QUICKSLOT_TYPE_ITEM;
                qs.pos = sCell.second;

                SetQuickslot(sCell.first, qs);
            }

            return true;
        }

char.h açılır ve aratılır

C++:
        LPITEM            GetItem(TItemPos Cell) const;

Altına eklenir

C++:
        LPITEM            GetItem_NEW(const TItemPos &Cell) const;
 
Üst