Jump to content

Item Swap System


Recommended Posts

  • Premium

M2 Download Center

This is the hidden content, please
( Internal )

So someone published item swap on epvp...

Here is better version from me with background color
It's possible i forget about something so give me a call :P

 

You can change background color in OnRenderPickingSlot() function (PythonGridSlotWindow.cpp)

 

Spoiler

225138CPtLSzz.gif.9d27ab0b4c2fa77200767f


SERVER SIDE:

open char_item.cpp
in function bool CHARACTER::MoveItem  replace

Spoiler

if (!IsEmptyItemGrid(DestCell, item->GetSize(), Cell.cell)){
}

with this
 

Spoiler

if (!IsEmptyItemGrid(DestCell, item->GetSize(), Cell.cell)){
            
    if (INVENTORY == Cell.window_type && INVENTORY == DestCell.window_type && !Cell.IsEquipPosition()){
            
        LPITEM item3 = NULL;
        item3 = GetItem(DestCell);
        
        if (!GetItem(DestCell))
            return false;

        if (item3->IsExchanging())
            return false;
                
        if (true == item3->isLocked())
            return false;
        
        // if equal size
        if (item->GetSize() == item3->GetSize()){
                    
            item->RemoveFromCharacter();
            item3->RemoveFromCharacter();
                        
            SetItem(DestCell, item);
            SetItem(Cell, item3);
                        
            return true;
        }
                
        //replace with yours inventory page count
        int page_count = 4;
                
        //when swaping items have diferent size
        if(item->GetSize() > 1 ){
                    
            int j = 0;
                    
            int destination_size = 0;
            LPITEM check_item = NULL;
                    
            do
            {
                BYTE slot = DestCell.cell + (5 * j);
                        
                //if slot is empty
                if (!(check_item = GetItem(TItemPos(INVENTORY, slot)))){
                    if((item->GetSize() -1) == j){
                        if((DestCell.cell / (INVENTORY_MAX_NUM / page_count)) != ((DestCell.cell + (5 * j)) / (INVENTORY_MAX_NUM / page_count)))    
                            return false;
                    }
                }
                else{
                    check_item = GetItem(TItemPos(INVENTORY, slot));
                    destination_size += check_item->GetSize();
                            
                    if((item->GetSize() -1) == j){
                        //last item must have size 1 to swap
                        if(check_item->GetSize() > 1)
                            return false;
                                
                        if((DestCell.cell / (INVENTORY_MAX_NUM / page_count)) != ((DestCell.cell + (5 * j)) / (INVENTORY_MAX_NUM / page_count)))    
                            return false;
                    }                            
                }                
            }
            while (++j < item->GetSize());
                    
                    
            if((Cell.cell + 5) == DestCell.cell)
                return false;
                    
            if(item->GetSize() < destination_size)
                return false;
                        
            item->RemoveFromCharacter();    
                    
            int k = 0;
            check_item = NULL;
                    
            do
            {
                BYTE slot = DestCell.cell + (5 * k);
                BYTE slot2 = Cell.cell + (5 * k);
                        
                if (!(check_item = GetItem(TItemPos(INVENTORY, slot))))
                    continue;
                else{
                    check_item->RemoveFromCharacter();
                    SetItem(TItemPos(INVENTORY, slot2), check_item);
                }    
                        
            }
            while (++k < item->GetSize());
                    
                    SetItem(DestCell, item);
        }
        else
                    return false;
    }
    else
        return false;
}



CLIENT SIDE:

open PythonGridSlotWindow.cpp
replace CGridSlotWindow::OnRenderPickingSlot() function with this
 

Spoiler

void CGridSlotWindow::OnRenderPickingSlot()
{
    if (!UI::CWindowManager::Instance().IsAttaching())
        return;

    BYTE byWidth, byHeight;
    UI::CWindowManager::Instance().GetAttachingIconSize(&byWidth, &byHeight);

    std::list<TSlot*> SlotList;
    if (GetPickedSlotList(byWidth, byHeight, &SlotList))
    {
        DWORD dwSlotNumber = UI::CWindowManager::Instance().GetAttachingSlotNumber();
        DWORD dwItemIndex = UI::CWindowManager::Instance().GetAttachingIndex();

        // UseMode ŔĚ°í..
        if (m_isUseMode)
        {
            // Pick µČ ľĆŔĚĹŰŔĚ ŔÖŔ¸¸é..
            TSlot * pSlot = *SlotList.begin();
            TSlot * pCenterSlot;
            if (GetSlotPointer(pSlot->dwCenterSlotNumber, &pCenterSlot))
            if (pCenterSlot->isItem)
            {
                if (m_isUsableItem)
                    CPythonGraphic::Instance().SetDiffuseColor(1.0f, 1.0f, 0.0f, 0.5f);
                else
                    CPythonGraphic::Instance().SetDiffuseColor(1.0f, 0.0f, 0.0f, 0.5f);

                CPythonGraphic::Instance().RenderBar2d(    m_rect.left + pCenterSlot->ixPosition,
                                                        m_rect.top + pCenterSlot->iyPosition,
                                                        m_rect.left + pCenterSlot->ixPosition + pCenterSlot->byxPlacedItemSize * ITEM_WIDTH,
                                                        m_rect.top + pCenterSlot->iyPosition + pCenterSlot->byyPlacedItemSize * ITEM_HEIGHT);
                return;
            }
        }

        // ľĆ´Ď¸é ±×łÉ żĹ±â±â
        if (!CheckMoving(dwSlotNumber, dwItemIndex, SlotList)){
            if(m_isUsableItem2)
                CPythonGraphic::Instance().SetDiffuseColor(0.0f, 0.55f, 0.55f, 0.5f);//here you can change swapable item color
            else
                CPythonGraphic::Instance().SetDiffuseColor(1.0f, 0.0f, 0.0f, 0.5f);
        }
        else
            CPythonGraphic::Instance().SetDiffuseColor(1.0f, 1.0f, 1.0f, 0.5f);

        RECT Rect;
        Rect.left = m_rect.right;
        Rect.top = m_rect.bottom;
        Rect.right = 0;
        Rect.bottom = 0;

        for (std::list<TSlot*>::iterator itor = SlotList.begin(); itor != SlotList.end(); ++itor)
        {
            TSlot * pSlot = *itor;
            Rect.left = min(Rect.left, m_rect.left + pSlot->ixPosition);
            Rect.top = min(Rect.top, m_rect.top + pSlot->iyPosition);
            Rect.right = max(Rect.right, m_rect.left + pSlot->ixPosition + pSlot->byxPlacedItemSize*ITEM_WIDTH);
            Rect.bottom = max(Rect.bottom, m_rect.top + pSlot->iyPosition + pSlot->byxPlacedItemSize*ITEM_HEIGHT);
        }

        CPythonGraphic::Instance().RenderBar2d(Rect.left, Rect.top, Rect.right, Rect.bottom);
    }
}

 

Open PythonSlotWindow.cpp
add under void CSlotWindow::SetUsableItem(BOOL bFlag) this function
 

Spoiler

void CSlotWindow::SetUsableItem2(BOOL bFlag)
{
    m_isUsableItem2 = bFlag;
}

next add int  void CSlotWindow::__Initialize()

Spoiler

m_isUsableItem2 = FALSE;

in namespace UI add under BOOL m_isUsableItem

Spoiler

BOOL m_isUsableItem2;

 

open PythonSlotWindow.h
add this under void SetUsableItem(BOOL bFlag);
 

Spoiler

void SetUsableItem2(BOOL bFlag);

 

open PythonWindowManagerModule.cpp
add this under PyObject * wndMgrSetUsableItem(PyObject * poSelf, PyObject * poArgs)
 

Spoiler

PyObject * wndMgrSetUsableItem2(PyObject * poSelf, PyObject * poArgs)
{
    UI::CWindow * pWin;
    if (!PyTuple_GetWindow(poArgs, 0, &pWin))
        return Py_BuildException();
    int iFlag;
    if (!PyTuple_GetInteger(poArgs, 1, &iFlag))
        return Py_BuildException();

    if (!pWin->IsType(UI::CSlotWindow::Type()))
        return Py_BuildException();

    UI::CSlotWindow * pSlotWin = (UI::CSlotWindow *)pWin;
    pSlotWin->SetUsableItem2(iFlag);

    return Py_BuildNone();
}

 

add this under { "SetUsableItem",                wndMgrSetUsableItem,                METH_VARARGS },
 

Spoiler

{ "SetUsableItem2",                wndMgrSetUsableItem2,                METH_VARARGS },



PYTHON:
open ui.py and add this function

Spoiler

def SetUsableItem2(self, flag): 
    wndMgr.SetUsableItem2(self.hWnd, flag)    


open uiinventory.py
in function def OverOutItem(self): add

Spoiler

self.wndItem.SetUsableItem2(FALSE)

 

replace OverInItem function with this

Spoiler

def OverInItem(self, overSlotPos):
        overSlotPos = self.__InventoryLocalSlotPosToGlobalSlotPos(overSlotPos)
        self.wndItem.SetUsableItem(FALSE)
        self.wndItem.SetUsableItem2(FALSE)

        if mouseModule.mouseController.isAttached():
            attachedItemType = mouseModule.mouseController.GetAttachedType()
            if player.SLOT_TYPE_INVENTORY == attachedItemType:

                attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
                attachedItemVNum = mouseModule.mouseController.GetAttachedItemIndex()
                
                if self.__CanUseSrcItemToDstItem(attachedItemVNum, attachedSlotPos, overSlotPos):
                    self.wndItem.SetUsableItem(TRUE)
                    self.ShowToolTip(overSlotPos)
                    return
                else:
                    srcItem = player.GetItemIndex(attachedSlotPos)
                    item.SelectItem(srcItem)
                    item1_size = str(item.GetItemSize())
                    
                    dstItem = player.GetItemIndex(overSlotPos)
                    item.SelectItem(dstItem)
                    item2_size = str(item.GetItemSize())
                    
                    if item2_size == item1_size:
                        if attachedSlotPos != overSlotPos:
                            self.wndItem.SetUsableItem2(TRUE)
                            self.ShowToolTip(overSlotPos)
                            return
                    
                    if item1_size == "(1, 2)":
                        if attachedSlotPos != overSlotPos:
                            if item2_size == "(1, 1)":
                                second_item = player.GetItemIndex(overSlotPos+5)
                                item.SelectItem(second_item)
                                second_item_size = str(item.GetItemSize())
                                if second_item_size != "(1, 2)" and second_item_size != "(1, 3)":
                                    self.wndItem.SetUsableItem2(TRUE)
                                    self.ShowToolTip(overSlotPos)
                                    return
                                    
                    if item1_size == "(1, 3)":
                        if attachedSlotPos != overSlotPos:
                            if item2_size == "(1, 1)":
                                second_item = player.GetItemIndex(overSlotPos+5)
                                item.SelectItem(second_item)
                                second_item_size = str(item.GetItemSize())
                                
                                if second_item_size != "(1, 3)":
                                    third_item = player.GetItemIndex(overSlotPos+10)
                                    item.SelectItem(third_item)
                                    third_item_size = str(item.GetItemSize())
                                    
                                    if third_item_size != "(1, 2)" and third_item_size != "(1, 3)":
                                        self.wndItem.SetUsableItem2(TRUE)
                                        self.ShowToolTip(overSlotPos)
                                        return
                            elif item2_size == "(1, 2)":
                                second_item = player.GetItemIndex(overSlotPos+10)
                                item.SelectItem(second_item)
                                second_item_size = str(item.GetItemSize())
                                
                                if second_item_size != "(1, 2)" and second_item_size != "(1, 3)":
                                    self.wndItem.SetUsableItem2(TRUE)
                                    self.ShowToolTip(overSlotPos)
                                    return
                            
                    
        self.ShowToolTip(overSlotPos)

maybe someone will do better python part ^.^

#######################################################################################################
I don't remember now but this was not working perfect because of overin so i created additional function, let me know is it necessary

ADDITIONAL PART:
in PythonGridSlotWindow.cpp
add function
 

Spoiler

BOOL CGridSlotWindow::GetPickedSlotPointer2(TSlot ** ppSlot)
{
    if (!UI::CWindowManager::Instance().IsAttaching())
        return CSlotWindow::GetPickedSlotPointer(ppSlot);

    BYTE byWidth, byHeight;
    UI::CWindowManager::Instance().GetAttachingIconSize(&byWidth, &byHeight);

    std::list<TSlot*> SlotList;
    if (!GetPickedSlotList(byWidth, byHeight, &SlotList))
        return FALSE;    
        
    TSlot * pMinSlot = NULL;
    //DWORD dwSlotNumber = UI::CWindowManager::Instance().GetAttachingSlotNumber();
    //DWORD dwAttachingItemIndex = UI::CWindowManager::Instance().GetAttachingIndex();

    for (std::list<TSlot*>::iterator itor = SlotList.begin(); itor != SlotList.end(); ++itor)
    {
        TSlot * pSlot = *itor;

        // NOTE : ÇŃ ˝˝·Ô ŔĚ»ó »çŔĚÁîŔÇ ľĆŔĚĹŰŔÇ °ćżě °ˇŔĺ żŢÂĘ Ŕ§ŔÇ ˝˝·Ô Ć÷ŔÎĹ͸¦ ¸®ĹĎÇŃ´Ů.
        //        ¸í˝ĂŔűŔĚÁö ¸řÇŃ ÄÚµĺ.. ´ő ÁÁŔş ąćąýŔş ľř´Â°ˇ? - [levites]
        if (!pMinSlot)
        {
            pMinSlot = pSlot;
        }
        else
        {
            if (pSlot->dwSlotNumber < pMinSlot->dwSlotNumber)
            {
                pMinSlot = pSlot;
            }
            else
            {
                if (!pMinSlot->isItem && pSlot->isItem)
                {
                    //pMinSlot = pSlot;
                }
            }
        }
    }

    if (!pMinSlot)
    {
        return FALSE;
    }
    else
    {
        TSlot * pCenterSlot;
        if (!GetSlotPointer(pMinSlot->dwCenterSlotNumber, &pCenterSlot))
            return FALSE;

        *ppSlot = pCenterSlot;

        // ÇöŔç ľĆŔĚĹŰŔ» µé°í ŔÖ´Â ÁßŔĚ°í..
        if (UI::CWindowManager::Instance().IsAttaching())
        {
            DWORD dwSlotNumber = UI::CWindowManager::Instance().GetAttachingSlotNumber();

            if (dwSlotNumber == pCenterSlot->dwSlotNumber)
            {
                *ppSlot = pMinSlot;
            }
        }
    }

    return TRUE;
}

 

in PythonGridSlotWindow.h
add under BOOL GetPickedSlotPointer(TSlot ** ppSlot);
 

Spoiler

BOOL GetPickedSlotPointer2(TSlot ** ppSlot);

 

in PythonSlotWindow.cpp
replace function OnMouseLeftButtonDown() with this

Spoiler

BOOL CSlotWindow::OnMouseLeftButtonDown()
{
    TSlot * pSlot;
    if (!GetPickedSlotPointer2(&pSlot))
    {
        UI::CWindowManager::Instance().DeattachIcon();
        return TRUE;
    }

    if (pSlot->isItem && !(pSlot->dwState & SLOT_STATE_LOCK))
    {
        OnSelectItemSlot(pSlot->dwSlotNumber);
    }
    else
    {
        OnSelectEmptySlot(pSlot->dwSlotNumber);
    }

    return TRUE;
}


under frunction GetPickedSlotPointer(TSlot ** ppSlot)
add this

Spoiler

BOOL CSlotWindow::GetPickedSlotPointer2(TSlot ** ppSlot)
{
    long lx, ly;
    CWindowManager::Instance().GetMousePosition(lx, ly);

    int ixLocal = lx - m_rect.left;
    int iyLocal = ly - m_rect.top;

    // NOTE : żŢÂĘ ¸ÇŔ§ »ó´Ü ÇŃ°÷ŔĚ ±âÁŘ Ŕ̶ó´Â ÁˇŔ» ŔĚżëÇŘ żŢÂĘ Ŕ§żˇĽ­şÎĹÍ żŔ¸ĄÂĘ ľĆ·ˇ·Î
    //        Â÷·Ę·Î °Ë»öÇŘ °¨Ŕ¸·Î˝á µ¤Çô ŔÖ´Â SlotŔş ŔÚµż ą«˝Ă µČ´Ů´Â ĆŻĽşŔ» ŔĚżëÇŃ´Ů. - [levites]
    for (TSlotListIterator itor = m_SlotList.begin(); itor != m_SlotList.end(); ++itor)
    {
        TSlot & rSlot = *itor;

        int ixCellSize = rSlot.ixCellSize;
        int iyCellSize = rSlot.iyCellSize;

        // NOTE : ItemŔĚ Hide µÇľîŔÖŔ» °ćżě¸¦ Ŕ§ÇŃ..
        if (rSlot.isItem)
        {
            ixCellSize = max(rSlot.ixCellSize, int(rSlot.byxPlacedItemSize * ITEM_WIDTH));
            iyCellSize = max(rSlot.iyCellSize, int(rSlot.byyPlacedItemSize * ITEM_HEIGHT));
        }

        if (ixLocal >= rSlot.ixPosition)
        if (iyLocal >= rSlot.iyPosition)
        if (ixLocal <= rSlot.ixPosition + ixCellSize)
        if (iyLocal <= rSlot.iyPosition + iyCellSize)
        {
            *ppSlot = &rSlot;
            return TRUE;
        }
    }

    return FALSE;
}

 

in PythonSlotWindow.h
add under GetPickedSlotPointer(TSlot ** ppSlot); this

Spoiler

virtual BOOL GetPickedSlotPointer2(TSlot ** ppSlot);

 

DONE

  • Metin2 Dev 12
  • Not Good 1
  • Good 2
  • Love 1
  • Love 10
Link to comment
Share on other sites

  • 2 weeks later...
  • 3 weeks later...
  • 1 month later...
  • 1 month later...

Announcements



×
×
  • Create New...

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.