Jump to content
×
×
  • Create New...
  • 0

[HELP]Exchange.cpp Bug Source


nichtwork

Question

The bug inventory  FULL ;(

 

how to fix:

 

Have 5 inventory

Sysuser: Done: Exchange::Done : Cannot find blank position in inventory

 

Code:

bool CExchange::CheckSpace()
{
    static CGrid s_grid1(5, INVENTORY_MAX_NUM/5 / 5); // inven page 1
    static CGrid s_grid2(5, INVENTORY_MAX_NUM/5 / 5); // inven page 2
    static CGrid s_grid3(5, INVENTORY_MAX_NUM/5 / 5); // inven page 3
    static CGrid s_grid4(5, INVENTORY_MAX_NUM/5 / 5); // inven page 4
    static CGrid s_grid5(5, INVENTORY_MAX_NUM/5 / 5); // inven page 5

    s_grid1.Clear();
    s_grid2.Clear();
    s_grid3.Clear();
    s_grid4.Clear();
    s_grid5.Clear();

    LPCHARACTER    victim = GetCompany()->GetOwner();
    LPITEM item;

    int i;

    for (i = 0; i < INVENTORY_MAX_NUM / 5; ++i)
    {
    if (!(item = victim->GetInventoryItem(i)))
        continue;

    s_grid1.Put(i, 1, item->GetSize());
    }
    for (i = INVENTORY_MAX_NUM / 5; i < INVENTORY_MAX_NUM; ++i)
    {
    if (!(item = victim->GetInventoryItem(i)))
        continue;

    s_grid2.Put(i - INVENTORY_MAX_NUM / 5, 1, item->GetSize());
    }
    for (i = INVENTORY_MAX_NUM / 5; i < INVENTORY_MAX_NUM; ++i)
    {
    if (!(item = victim->GetInventoryItem(i)))
        continue;

    s_grid3.Put(i - INVENTORY_MAX_NUM / 5, 1, item->GetSize());
    }
    for (i = INVENTORY_MAX_NUM / 5; i < INVENTORY_MAX_NUM; ++i)
    {
    if (!(item = victim->GetInventoryItem(i)))
        continue;

    s_grid4.Put(i - INVENTORY_MAX_NUM / 5, 1, item->GetSize());
    }
    for (i = INVENTORY_MAX_NUM / 5; i < INVENTORY_MAX_NUM; ++i)
    {
    if (!(item = victim->GetInventoryItem(i)))
        continue;

    s_grid5.Put(i - INVENTORY_MAX_NUM / 5, 1, item->GetSize());
    }

    // ??... ??°ˇ °ł?´˝? °°Ao¸¸... ?e???® ?I???≫ łe¸O ?I?? ?¸°i μ?¶o ¸¸μc ł≫ ?߸???´? ¤đ¤đ
    static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);
    
    // ??´U ?e???®?≫ ±ł??C?Ao ???≫ °ˇ´E???? ?ⓒ?C·I, ?e???® ?I?? ??≫c´A ?e???®?? ?O?≫ ¶§ C?μμ·? C?´?.
    bool bDSInitialized = false;
    
    for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
    {
        if (!(item = m_apItems))
            continue;

        if (item->IsDragonSoul())
        {
            if (!victim->DragonSoul_IsQualified())
            {
                return false;
            }

            if (!bDSInitialized)
            {
                bDSInitialized = true;
                victim->CopyDragonSoulItemGrid(s_vDSGrid);
            }

            bool bExistEmptySpace = false;
            WORD wBasePos = DSManager::instance().GetBasePosition(item);
            if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
                return false;
            
            for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
            {
                WORD wPos = wBasePos + i;
                if (0 == s_vDSGrid[wBasePos])
                {
                    bool bEmpty = true;
                    for (int j = 1; j < item->GetSize(); j++)
                    {
                        if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
                        {
                            bEmpty = false;
                            break;
                        }
                    }
                    if (bEmpty)
                    {
                        for (int j = 0; j < item->GetSize(); j++)
                        {
                            s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] = wPos + 1;
                        }
                        bExistEmptySpace = true;
                        break;
                    }
                }
                if (bExistEmptySpace)
                    break;
            }
            if (!bExistEmptySpace)
                return false;
        }
        else
        {
            int iPos = s_grid1.FindBlank(1, item->GetSize());

            if (iPos >= 0)
            {
                s_grid1.Put(iPos, 1, item->GetSize());
            }
            else
            {
                iPos = s_grid2.FindBlank(1, item->GetSize());

                if (iPos >= 0)
                {
                    s_grid2.Put(iPos, 1, item->GetSize());
                }
                else
                {
                    iPos = s_grid3.FindBlank(1, item->GetSize());

                    if (iPos >= 0)
                    {
                        s_grid3.Put(iPos, 1, item->GetSize());
                    }
                    else
                    {
                        iPos = s_grid4.FindBlank(1, item->GetSize());

                        if (iPos >= 0)
                        {
                            s_grid4.Put(iPos, 1, item->GetSize());
                        }
                        else
                        {
                            iPos = s_grid5.FindBlank(1, item->GetSize());

                            if (iPos >= 0)
                            {
                                s_grid5.Put(iPos, 1, item->GetSize());
                            }
                            else
                            {
                                return false;
                            }
                        }
                    }
                }
            }
        }
    }

    return true;
 

 

Link to comment
Share on other sites

  • Answers 2
  • Created
  • Last Reply

Top Posters For This Question

Popular Days

2 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.