Jump to content

[Patch][7228] Bag Swap


Recommended Posts

Posted

In present, Bag(contains items) and bag(in inventory) cannot be swaped.

So, I made codes which bag swap.

void Player::SwapItem( uint16 src, uint16 dst )
{
   uint8 srcbag = src >> 8;
   uint8 srcslot = src & 255;

   uint8 dstbag = dst >> 8;
   uint8 dstslot = dst & 255;

   Item *pSrcItem = GetItemByPos( srcbag, srcslot );
   Item *pDstItem = GetItemByPos( dstbag, dstslot );

   if( !pSrcItem )
       return;

   sLog.outDebug( "STORAGE: SwapItem bag = %u, slot = %u, item = %u", dstbag, dstslot, pSrcItem->GetEntry());

   if(!isAlive() )
   {
       SendEquipError( EQUIP_ERR_YOU_ARE_DEAD, pSrcItem, pDstItem );
       return;
   }

   if(pSrcItem->m_lootGenerated)                           // prevent swap looting item
   {
       //best error message found for attempting to swap while looting
       SendEquipError( EQUIP_ERR_CANT_DO_RIGHT_NOW, pSrcItem, NULL );
       return;
   }

   // ******************** ADDED CODE **********************
   bool bagswapfailed = false;
   if (pDstItem)
   {
       const ItemPrototype *srcProto = pSrcItem->GetProto(), *dstProto = pDstItem->GetProto();
       if ( !IsBagPos(src) && IsBagPos(dst) && pSrcItem->IsBag() && pDstItem->IsBag() && ((Bag *)pSrcItem)->IsEmpty() && srcProto && dstProto )
       {
           Bag *sBag = (Bag *)pSrcItem;
           Bag *dBag = (Bag *)pDstItem;
           uint32 dstbagsize, count = 0;

           dstbagsize = dBag->GetBagSize();
           for(int i=0; i<dstbagsize; ++i)
           {
               Item *dstbagitem = dBag->GetItemByPos(i);

               if (!dstbagitem)
                   continue;

               const ItemPrototype *dstitemproto = dstbagitem->GetProto();
               if (!dstitemproto)
               {
                   bagswapfailed = true;
                   break;
               }

               if ( !ItemCanGoIntoBag(dstitemproto, srcProto) )
               {
                   bagswapfailed = true;
                   break;
               }

               ++count;
           }

           if (count > sBag->GetBagSize())
               bagswapfailed = true;

           if (!bagswapfailed)
           {
               // Items swap
               count = 0;
               for(int i=0; i<dstbagsize; ++i)
               {
                   Item *dstbagitem = dBag->GetItemByPos(i);

                   if (!dstbagitem)
                       continue;

                   dBag->RemoveItem(i, true);
                   sBag->StoreItem(count, dstbagitem, true);
                   dstbagitem->SetState(ITEM_CHANGED, this);

                   ++count;
               }

               // Bag swap

               // now do moves, remove...
               RemoveItem(dstbag, dstslot, false);
               RemoveItem(srcbag, srcslot, false);

               // add to dest
               _StoreItem(dst, pSrcItem, pSrcItem->GetCount(), false, true);
               _StoreItem(src, pDstItem, pDstItem->GetCount(), false, true);
               pSrcItem->SetState(ITEM_CHANGED, this);
               pDstItem->SetState(ITEM_CHANGED, this);

               return;
           }
       }
   }
   // ****************************** ADD END ******************************

   // check unequip potability for equipped items and bank bags
   if(IsEquipmentPos ( src ) || IsBagPos ( src ))



Please verify my code.

  • 2 weeks later...
Posted

In suggested version you not correctly swap bags in case bank bags, also not do many expected checks.

Also patch not supported swap (with item exchange) at drop non-empty equipped bag at empty non equipped bag.

Not sure is last case need support but for swap, why not ...

I currently change suggested code to resolve this problems or limitations.

[added]Patch with some req.changes in [7228] and in mangos-0.12.

Thank you :)

Please post patches to under review section instead this if you expect its review and adding to mangos sources.

Posted
what about a pouch or a quiver ? can those be swapt between them? or with a normal bag?
Added patch allow this (in case item move to specialized bag (quiver) its must be allowed to place to it.
Those are about to be removed in 3.1.0 ;)

bag swap with item move?

×
×
  • Create New...

Important Information

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. Privacy Policy Terms of Use