farkmt2official 1
farkmt2official
Bvural41 1
Bvural41
Fethi Polat 1
Fethi Polat
Mt2Hizmet 1
Mt2Hizmet
Scarlet 1
Scarlet
Hikaye Ekle

[C++] Öğelerin yer değiştirmesi

  • Konuyu başlatan Konuyu başlatan [DEV]AB
  • Başlangıç tarihi Başlangıç tarihi
  • Cevaplar Cevaplar 51
  • Görüntüleme Görüntüleme 9K

Ayyıldız2 | 2008 TR Yapısı • 1-99 Orta Emek Destan • Oto Avsız • 10 Temmuz 21:00 HEMEN TIKLA!

ata.gif


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

Kod:
LPITEM CHARACTER::GetItem(TItemPos Cell) const

Kod bloğu altına eklenir​

Kod:
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​

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

Değiştirilir​

Kod:
        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​

Kod:
        LPITEM            GetItem(TItemPos Cell) const;

Altına eklenir​

Kod:
        LPITEM            GetItem_NEW(const TItemPos &Cell) const;

Aratılır​

Kod:
        void            SyncQuickslot(BYTE bType, BYTE bOldPos, BYTE bNewPos);

altına eklenir​

Kod:
        int32_t            GetQuickslotPosition(uint8_t bType, uint16_t bInventoryPos) const;

char_quickslot.cpp açılır ve aratılır​

Kod:
bool CHARACTER::GetQuickslot(BYTE pos, TQuickslot ** ppSlot)

üstüne eklenir​
Kod:
int32_t CHARACTER::GetQuickslotPosition(uint8_t bType, uint16_t bInventoryPos) const
{
    for (int i = 0; i < QUICKSLOT_MAX_NUM; ++i)
    {
        if (m_quickslot[i].type == bType && m_quickslot[i].pos == bInventoryPos)
            return i;
    }

    return -1;
}
 
Son düzenleme:

Şu an konuyu görüntüleyenler (Toplam : 0, Üye: 0, Misafir: 0)

Geri
Üst