阅读:4250回复:7
给《飞飞》添加一键整理背包功能
源文件中_Interface文件夹下WndField.cpp文件
搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ) struct sItem { DWORD dwId; DWORD dwKind2; DWORD dwItemId; BYTE nIndex; sItem(){ dwId = dwKind2 = dwItemId = nIndex = 0; } bool operator < (const sItem p2) { if (dwKind2 == p2.dwKind2) { return dwItemId < p2.dwItemId; }else{ return dwKind2 < p2.dwKind2; } } }; class CInventorySort { public: CInventorySort() { m_dwPos = 0; } ~CInventorySort(){} private: sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息 DWORD m_dwPos; public: void Add(BYTE nIndex) { if (m_dwPos >= MAX_INVENTORY) { return; } m_Item[m_dwPos].nIndex = nIndex; m_Item[m_dwPos].dwId = m_dwPos; m_dwPos++; } BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列 { for (int i=0;i<MAX_INVENTORY;i++) { if (m_Item.dwId == dwId) { return m_Item.nIndex; } } return 255; } void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置 { BYTE nTmp = 0; bool bDest = false,bSrc = false; for (int i=0;i<MAX_INVENTORY;i++) { if (dwSrcId == m_Item.dwId) { //id相等 则 改变对应的dest和src nTmp = m_Item.nIndex; m_Item.nIndex = dest; } } //临时数据保存完毕,交换开始 for (int i=0;i<MAX_INVENTORY;i++) { if (dest == m_Item.nIndex) { //id相等 则 改变对应的dest和src m_Item.nIndex = nTmp; } } } }; ------------------------------------------------------------------------- 依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ) 搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase); 紧靠其上添加: if( pWndBase == &m_wndMenu ) { switch( nID ) { case 2: { //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL); if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)) { break; } for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++) { CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i); if( !pItemElem ) continue; if(pItemElem->GetExtra() > 0) continue; if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) continue; if( g_pPlayer->IsUsing( pItemElem ) ) continue; if( pItemElem->IsUndestructable() == TRUE ) { g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) ); continue; } g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum); } break; } case 1: { //整理背包 ////////////////////////////////////////////////////////////////////////// //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) ); ////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// CInventorySort* pInvSort = new CInventorySort; vector <sItem> vItem; vItem.resize(MAX_INVENTORY);//初始化大小 ////////////////////////////////////////////////////////////////////////// //填充数据 for (int i=0;i<MAX_INVENTORY;i++) { CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i); if (!pItemElem) { vItem.dwKind2 = 0xffffffff; vItem.dwItemId = 0xffffffff; vItem.nIndex = i; }else { ItemProp* pProp = pItemElem->GetProp(); vItem.dwKind2 = pProp->dwItemKind2; vItem.dwItemId = pItemElem->m_dwItemId; vItem.nIndex = i; } //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId); } ////////////////////////////////////////////////////////////////////////// sort(vItem.begin(),vItem.end());//排序 ////////////////////////////////////////////////////////////////////////// //交换 for (size_t i=0;i<vItem.size();i++) { //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId); pInvSort->Add(vItem.nIndex); } BYTE nDestPos = 0; for (int i=0;i<MAX_INVENTORY;i++) { CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos); if (pItemElem) { if (IsUsingItem(pItemElem)) { //这个位置无法放 nDestPos++; } } BYTE nSrc = pInvSort->GetItemSrc(i); pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc); if (pItemElem) { if (IsUsingItem(pItemElem)) { //这个道具无法移动,跳过 continue; } }else{ //空位置 不用动 continue; } ////////////////////////////////////////////////////////////////////////// //开始移动 if (nSrc == nDestPos) { //原地不动 nDestPos++; continue; } pInvSort->MoveItem(i,nDestPos); g_DPlay.SendMoveItem(0,nSrc,nDestPos); Sleep(5); //Error("移动 - %d->%d",nSrc,nDestPos); nDestPos++; } //取第一个元素的信息 /* if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff) { Error("Move - From:%d,To:%d",vItem[0].nIndex,x); g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x); } */ ////////////////////////////////////////////////////////////////////////// break; } } } m_wndMenu.SetVisible(FALSE); -------------------------------------------------------------------------------------------------------- 搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point) { BaseMouseCursor(); } 在其下添加: void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point) { m_wndMenu.DeleteAllMenu(); m_wndMenu.CreateMenu(this); m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包"); if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)) { //P以上级别才可以删除所有道具 m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear"); } m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point ); m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() ); m_wndMenu.SetFocus(); } ------------------------------------------------------------------------------------------------------------ ************************* WndField.h文件 ************************* 搜索:BOOL m_bReport; 其后添加: CWndMenu m_wndMenu; 搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point); 其后添加: virtual void OnRButtonUp(UINT nFlags, CPoint point); |
|
4楼#
发布于:2023-12-16 08:29
为了一个铜币努力176951000
|
|