Not being able to swap between 1 hand to a 2 hand weapon unless you have a free slot down #3

Open
opened 2025-11-28 14:29:10 +00:00 by shadow · 0 comments

The fix will make you be able to swap if you have a free slot down or one up , not only one down

in char_item.cpp compare:

bool CHARACTER::SwapItem(BYTE bCell, BYTE bDestCell)
{
    if (!CanHandleItem())
        return false;

    TItemPos srcCell(INVENTORY, bCell), destCell(INVENTORY, bDestCell);

    if (srcCell.IsDragonSoulEquipPosition() || destCell.IsDragonSoulEquipPosition())
        return false;

    if (bCell == bDestCell)
        return false;

    if (srcCell.IsEquipPosition() && destCell.IsEquipPosition())
        return false;

    LPITEM item1, item2;

    if (srcCell.IsEquipPosition())
    {
        item1 = GetInventoryItem(bDestCell);
        item2 = GetInventoryItem(bCell);
    }
    else
    {
        item1 = GetInventoryItem(bCell);
        item2 = GetInventoryItem(bDestCell);
    }

    if (!item1 || !item2)
        return false;
    
    if (item1 == item2)
    {
        SPDLOG_WARN("[WARNING][WARNING][HACK USER!] : {} {} {}", m_stName.c_str(), bCell, bDestCell);
        return false;
    }

    if (TItemPos(EQUIPMENT, item2->GetCell()).IsEquipPosition())
    {
        BYTE bEquipCell = item2->GetCell() - INVENTORY_MAX_NUM;
        BYTE bInvenCell = item1->GetCell();

        if (false == CanUnequipNow(item2) || false == CanEquipNow(item1))
            return false;

        if (bEquipCell != item1->FindEquipCell(this))
            return false;

        // NEW: Find ANY available space for item2 after removing item1
        item1->RemoveFromCharacter();
        
        // Search for empty space in inventory for item2
        int iEmptyCell = GetEmptyInventory(item2->GetSize());
        
        if (iEmptyCell < 0)
        {
            // No space available, restore item1
#ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__
            item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell), false);
#else
            item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell));
#endif
            return false;
        }

        // Space found, remove item2 from equipment
        item2->RemoveFromCharacter();

        // Try to equip item1
        if (item1->EquipTo(this, bEquipCell))
        {
            // Success, add item2 to the found empty space
#ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__
            item2->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell), false);
#else
            item2->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell));
#endif
        }
        else
        {
            // Failed to equip item1, restore both items
            SPDLOG_ERROR("SwapItem cannot equip {}! item1 {}", item2->GetName(), item1->GetName());
#ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__
            item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell), false);
#else
            item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell));
#endif
            item2->AddToCharacter(this, TItemPos(EQUIPMENT, bEquipCell));
            return false;
        }
    }
    else
    {
        // Regular inventory swap
        if (!IsEmptyItemGrid(TItemPos(INVENTORY, item1->GetCell()), item2->GetSize(), item1->GetCell()))
            return false;

        BYTE bCell1 = item1->GetCell();
        BYTE bCell2 = item2->GetCell();
        
        item1->RemoveFromCharacter();
        item2->RemoveFromCharacter();
#ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__
        item1->AddToCharacter(this, TItemPos(INVENTORY, bCell2), false);
        item2->AddToCharacter(this, TItemPos(INVENTORY, bCell1), false);
#else
        item1->AddToCharacter(this, TItemPos(INVENTORY, bCell2));
        item2->AddToCharacter(this, TItemPos(INVENTORY, bCell1));
#endif
    }

    return true;
}
The fix will make you be able to swap if you have a free slot down or one up , not only one down in char_item.cpp compare: ``` bool CHARACTER::SwapItem(BYTE bCell, BYTE bDestCell) { if (!CanHandleItem()) return false; TItemPos srcCell(INVENTORY, bCell), destCell(INVENTORY, bDestCell); if (srcCell.IsDragonSoulEquipPosition() || destCell.IsDragonSoulEquipPosition()) return false; if (bCell == bDestCell) return false; if (srcCell.IsEquipPosition() && destCell.IsEquipPosition()) return false; LPITEM item1, item2; if (srcCell.IsEquipPosition()) { item1 = GetInventoryItem(bDestCell); item2 = GetInventoryItem(bCell); } else { item1 = GetInventoryItem(bCell); item2 = GetInventoryItem(bDestCell); } if (!item1 || !item2) return false; if (item1 == item2) { SPDLOG_WARN("[WARNING][WARNING][HACK USER!] : {} {} {}", m_stName.c_str(), bCell, bDestCell); return false; } if (TItemPos(EQUIPMENT, item2->GetCell()).IsEquipPosition()) { BYTE bEquipCell = item2->GetCell() - INVENTORY_MAX_NUM; BYTE bInvenCell = item1->GetCell(); if (false == CanUnequipNow(item2) || false == CanEquipNow(item1)) return false; if (bEquipCell != item1->FindEquipCell(this)) return false; // NEW: Find ANY available space for item2 after removing item1 item1->RemoveFromCharacter(); // Search for empty space in inventory for item2 int iEmptyCell = GetEmptyInventory(item2->GetSize()); if (iEmptyCell < 0) { // No space available, restore item1 #ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__ item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell), false); #else item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell)); #endif return false; } // Space found, remove item2 from equipment item2->RemoveFromCharacter(); // Try to equip item1 if (item1->EquipTo(this, bEquipCell)) { // Success, add item2 to the found empty space #ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__ item2->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell), false); #else item2->AddToCharacter(this, TItemPos(INVENTORY, iEmptyCell)); #endif } else { // Failed to equip item1, restore both items SPDLOG_ERROR("SwapItem cannot equip {}! item1 {}", item2->GetName(), item1->GetName()); #ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__ item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell), false); #else item1->AddToCharacter(this, TItemPos(INVENTORY, bInvenCell)); #endif item2->AddToCharacter(this, TItemPos(EQUIPMENT, bEquipCell)); return false; } } else { // Regular inventory swap if (!IsEmptyItemGrid(TItemPos(INVENTORY, item1->GetCell()), item2->GetSize(), item1->GetCell())) return false; BYTE bCell1 = item1->GetCell(); BYTE bCell2 = item2->GetCell(); item1->RemoveFromCharacter(); item2->RemoveFromCharacter(); #ifdef __BL_ENABLE_PICKUP_ITEM_EFFECT__ item1->AddToCharacter(this, TItemPos(INVENTORY, bCell2), false); item2->AddToCharacter(this, TItemPos(INVENTORY, bCell1), false); #else item1->AddToCharacter(this, TItemPos(INVENTORY, bCell2)); item2->AddToCharacter(this, TItemPos(INVENTORY, bCell1)); #endif } return true; } ```
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: Metin2/bug-tracker#3
There is no content yet.