主题:【源码编辑】给游戏添加整理背包功能 作者:烛天丶 时间:2013-08-21 22:23 |
源文件中_Interface文件夹下WndField.cpp文件% d) ^. @! i, U& s6 l 搜索:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase )% H5 @6 { r3 W7 `$ y) Y , Y. O5 P2 w. n8 Z struct sItem2 O) h) n1 O9 U {% n7 N# M6 k4 D2 | DWORD dwId;9 E3 o# b. n/ W5 H- ~, F DWORD dwKind2;2 J) q9 B7 u6 x! ?/ r/ y3 N! ] DWORD dwItemId;0 U9 t. w" K! ^2 e w BYTE nIndex;: x) O' k( p( U sItem(){. C% r! S+ S) Z4 B: n5 G3 D+ J z4 s dwId = dwKind2 = dwItemId = nIndex = 0;" A. F2 H, j$ ~ }6 g( a) i- J! ]& F j. b bool operator < (const sItem p2) {2 Q$ a7 _6 j* W& L5 h! q1 } if (dwKind2 == p2.dwKind2)% E0 ]: U6 f/ G2 a( M { return dwItemId < p2.dwItemId; f9 v& O* t8 D( 6 I0 X& e' M }else{ return dwKind2 < p2.dwKind2; } } }; class CInventorySort. e5 ]9 p5 ]) v8 y0 I4 g { public:8 F0 V2 m9 @/ Z! T* y' X CInventorySort() {' A' r- V. k; r: m4 E m_dwPos = 0;) " s Q3 Y1 l% c* r9 |1 r2 Q } ~CInventorySort(){} private: sItem m_Item[MAX_INVENTORY];//存放排序好的道具信息 DWORD m_dwPos;/ Z! I) n ~, X8 s public:* o/ O$ a; r9 R1 _ T; J void Add(BYTE nIndex)' G# W% W, v# U+ [- @ {- N+ k3 M/ j; u9 j& s, a4 F0 A if (m_dwPos >= MAX_INVENTORY) { return; }. }9 [) E4 t$ V4 c, a& U m_Item[m_dwPos].nIndex = nIndex; m_Item[m_dwPos].dwId = m_dwPos;) X+ ]& o- M7 % R5 Y7 J/ b m_dwPos++; }. D: h8 _" ~! A+ S4 2 j" h1 O$ H1 @ BYTE GetItemSrc(DWORD dwId)//Id从0到最大值排列# U' a7 }" f' O1 X1 S' [- M {) F* B( B# v4 w* W for (int i=0;i<MAX_INVENTORY;i++); a' & T8 N {' I* Y { if (m_Item.dwId == dwId) { return m_Item.nIndex; }5 F. Y0 I2 f; S. i7 I } return 255;% b4 ~8 c5 w* Z9 x: + A+ r }# a3 K7 Q% `5 s. Z* S" j6 c void MoveItem(DWORD dwSrcId,BYTE dest)//移动道具位置 {1 T* E4 V3 ~& ~% x4 j; F" f$ v7 F BYTE nTmp = 0;) M! c: g- M3 q4 y& } bool bDest = false,bSrc = false; for (int i=0;i<MAX_INVENTORY;i++) { if (dwSrcId == m_Item.dwId): y% r# I& `7 H { //id相等 则 改变对应的dest和src nTmp = m_Item.nIndex;2 k% l# g- P# [ m_Item.nIndex = dest;1 L3 R& n6 @* h7 {( C. P }% D" C2 U& ~1 A, d$ z6 [" G } //临时数据保存完毕,交换开始 for (int i=0;i<MAX_INVENTORY;i++) {' A/ l; L9 g" s, w+ G8 O if (dest == m_Item.nIndex)& b2 @4 e4 ]2 T a8 H {9 y4 k8 m6 @- N4 I2 t8 V) t //id相等 则 改变对应的dest和src m_Item.nIndex = nTmp;( I4 |7 T# [: a& [2 t }2 Q e( n/ n* f8 `* ], e) h& a8 r } } };+ b1 y6 }0 B o3 B4 V6 u# } 8 a% v' T0 F) v: M3 S ------------------------------------------------------------------------- 依然在函数体:BOOL CWndInventory::OnCommand( UINT nID, DWORD dwMessage, CWndBase* pWndBase ) 搜索:return CWndNeuz::OnCommand(nID,dwMessage,pWndBase);: }7 K( g4 K6 j : r6 N, K4 n. B6 c9 b; @ 紧靠其上添加:$ V* g7 K' 3 L2 H if( pWndBase == &m_wndMenu ) { switch( nID ) { case 2:! |$ ]: N8 R, c8 n0 { //g_WndMng.OpenMessageBox("确定清空整个背包吗?",MB_OKCANCEL); if(!g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)) { break; } for (int i=0;i<g_pPlayer->m_Inventory.GetSize();i++) {/ R# A( i2 ( I6 n# A CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);, I" A/ j3 E5 Y" U0 S9 c if( !pItemElem )3 g4 J2 E2 Y6 @7 V7 W/ | continue; if(pItemElem->GetExtra() > 0) continue; if( g_pPlayer->m_Inventory.IsEquip( pItemElem->m_dwObjId ) ) ; i/ u6 A& & X/ w continue; if( g_pPlayer->IsUsing( pItemElem ) ) continue;4 y% y3 f" W ?! u/ p6 a if( pItemElem->IsUndestructable() == TRUE )) ?3 b: B6 d$ q% V- t0 z; X { g_WndMng.PutString( prj.GetText( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ), NULL, prj.GetTextColor( TID_GAME_ERROR_UNDESTRUCTABLE_ITEM ) ); continue; }/ c" E5 ^, r8 U" v0 K2 I ) o* Q8 Z" G$ c# ?- A: Y; o g_DPlay.SendRemoveItem( pItemElem, pItemElem->m_nItemNum); } break; }" @# z+ x' m% N4 E case 1: {& m* G+ ^5 ^7 ^7 X' _! c6 y' E //整理背包 //////////////////////////////////////////////////////////////////////////8 x1 F- O( P) `) R //g_DPlay.SendMoveItem( 0, (BYTE)( pShortcut->m_dwIndex ), (BYTE)( (DWORD)nDstIndex ) ); ////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////0 S7 J. }1 U5 ]+ T' o CInventorySort* pInvSort = new CInventorySort;0 w2 B7 @/ ~+ Y8 e3 G# t vector <sItem> vItem;% Y8 Z: _( `, e) P( B. ~# P4 G; s vItem.resize(MAX_INVENTORY);//初始化大小" V8 _: T: Q0 M% 4 ^ //////////////////////////////////////////////////////////////////////////- v" Z7 K( u4 _' T3 B/ U* A5 F //填充数据 for (int i=0;i<MAX_INVENTORY;i++)8 ~, N0 r+ B/ K4 a' g: J; f { CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(i);$ j0 V8 M8 t; ?; L8 _+ ~ n if (!pItemElem)$ [* C A* . E3 q0 X2 d {/ n" |% }) [! f; D- t+ F6 | vItem.dwKind2 = 0xffffffff; vItem.dwItemId = 0xffffffff;& O$ ^3 |8 K$ | q( M8 W5 K vItem.nIndex = i; }else {# Q8 Q1 a9 b [) U ItemProp* pProp = pItemElem->GetProp(); vItem.dwKind2 = pProp->dwItemKind2; vItem.dwItemId = pItemElem->m_dwItemId;2 t" D, m, Z5 ~; p+ | vItem.nIndex = i;* g' u8 u( T1 b) r/ {0 v } //Error("排序前 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);3 A' b$ H* w! U$ K4 z/ x! ?9 H. o }6 u; x* N# N, f! F ////////////////////////////////////////////////////////////////////////// sort(vItem.begin(),vItem.end());//排序 ////////////////////////////////////////////////////////////////////////// //交换 for (size_t i=0;i<vItem.size();i++) {4 _- q1 |; G: c) P2 d- Q/ G, j, i% ` //Error("排序后 - nIndex:%d,Kind2:%d,ItemId:%d",vItem.nIndex,vItem.dwKind2,vItem.dwItemId);" n) A( W4 I. A% m3 l* T pInvSort->Add(vItem.nIndex); } BYTE nDestPos = 0; for (int i=0;i<MAX_INVENTORY;i++) {) H3 c" s$ F, _5 l: Y1 j, `: I CItemElem* pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nDestPos);0 k) A$ {& p5 s( Q2 ], w9 m if (pItemElem)+ n _ ?5 r, m+ U# p {1 N; U; x/ O! I8 ?+ m# | if (IsUsingItem(pItemElem)) { //这个位置无法放 nDestPos++; }( a' J/ s% |" C" p- T% M6 B }* d; e' o1 j! h BYTE nSrc = pInvSort->GetItemSrc(i);# _$ c% Q( e. D6 |3 b8 d: J U9 W4 X pItemElem = (CItemElem*)g_pPlayer->m_Inventory.GetAt(nSrc); if (pItemElem) { if (IsUsingItem(pItemElem)) { //这个道具无法移动,跳过0 E5 n) e1 c4 I! _- { continue; } }else{. y0 z0 A7 [/ K9 H" w# r //空位置 不用动 continue; }6 A$ }8 ?+ Q* G5 N //////////////////////////////////////////////////////////////////////////, r5 e3 d5 u" I2 P. ^ //开始移动2 ]$ [2 x9 z: H, j% m6 y if (nSrc == nDestPos)* P$ F+ B O1 b# }* d$ l8 i* s& D: a# U { //原地不动 nDestPos++; continue;* G, x: Z6 O1 j' T2 c4 C& p# r4 w } pInvSort->MoveItem(i,nDestPos);- ^) @! d. y( E4 K5 f- [# a4 L g_DPlay.SendMoveItem(0,nSrc,nDestPos); Sleep(5);- s7 i/ u: x( Z7 K! h) F. w //Error("移动 - %d->%d",nSrc,nDestPos); nDestPos++; d3 b- v$ f I1 m) J }2 C7 ?$ N& H8 R" u# ^7 t //取第一个元素的信息# t7 Z) v& p4 `1 R+ v /*, S$ e" ~0 ^; I! S# B6 x if (vItem[0].dwItemId > 0 && vItem[0].dwItemId < 0xffffffff)7 G( H2 D) H0 h4 _* C9 s0 { {% y( f( a! X' x, ] Error("Move - From:%d,To:%d",vItem[0].nIndex,x);% o( H$ o( E- f4 Z4 w5 H g_DPlay.SendMoveItem(0,(BYTE)vItem[0].nIndex,(BYTE)x); h0 `: U! o2 W( X }9 d- t% P1 y+ [/ r6 L$ a, q7 f" x */6 U% i; f2 Y3 r/ |: e- y ////////////////////////////////////////////////////////////////////////// break; }( C" r3 l6 ?: ^ } % l5 N, H, @8 s. s3 C: D: h } m_wndMenu.SetVisible(FALSE); & w* S( C4 K" D4 ]+ } 2 T2 J; A ?; q1 F F5 E9 K3 x8 j -------------------------------------------------------------------------------------------------------- 搜索:void CWndInventory::OnRButtonDown(UINT nFlags, CPoint point): l6 t. D8 S/ o$ M8 h6 | {. f9 a& ^; d! U BaseMouseCursor();( i0 D7 v6 G9 W1 x# O+ w } 4 @4 R* i5 a& r# ]" k 在其下添加:" B6 B6 U b: _- f/ D. s- T, ^ ) K4 G- B0 Q, c void CWndInventory::OnRButtonUp(UINT nFlags, CPoint point)! L& T, F, J; Y3 l {! w; W+ o& ~0 G3 _1 I3 ^& H+ i2 Y' O) ~! { m_wndMenu.DeleteAllMenu();7 N8 U) ; D) N* H. z m_wndMenu.CreateMenu(this); m_wndMenu.AppendMenu(0,1,(LPCTSTR)"整理背包"); if (g_pPlayer->IsAuthHigher(AUTH_ADMINISTRATOR)) { //P以上级别才可以删除所有道具. r2 k8 {! K% D& }2 K8 v6 @! O/ T5 ~ m_wndMenu.AppendMenu( 0, 2,(LPCTSTR)"Clear");4 T# v+ g+ f# j, c }. ]" o9 E# l: v* _( c$ |% Z m_wndMenu.Move(CPoint( m_rectCurrentWindow.left, m_rectCurrentWindow.top ) + point ); m_wndMenu.SetVisible( TRUE );//!m_wndMenuMover.IsVisible() ); m_wndMenu.SetFocus(); }; s4 _( B) O4 ]& s 7 D( ^' k! r1 U ------------------------------------------------------------------------------------------------------------ *************************5 N4 m& k- M) f) Y" C 9 }+ G0 W6 w. Y' u- ] D' @) w WndField.h文件6 F9 b. O! C* T1 c# d. {: `4 M6 E . @4 {- F6 g1 ]8 g *************************! I; n' P; _- U$ @& @ . u W( a2 I. x 搜索:BOOL m_bReport; ! R3 I( g* Q$ Q 其后添加:4 N. l/ S% {9 Z/ ^ $ S9 ]) ]& b6 C1 C2 t CWndMenu m_wndMenu; $ E% W: D$ B1 F) R- y6 i" l 搜索:virtual void OnRButtonDown(UINT nFlags, CPoint point);' b, [ c }" R( d% x' Z% X) T4 w % b; v$ T8 w' Z& @ 其后添加: 2 }4 _" l* ?# u virtual void OnRButtonUp(UINT nFlags, CPoint point); -------------------------------------------------------------------------------------------------------- |
1楼:※冰※(2013-08-22 08:16) |
留底保存,慢慢消化 |
2楼:孤独灬寂寞(2013-08-22 11:14) |
我崩溃了··· |
3楼:lansky、(2013-08-22 15:48) |
真希望来一个今日发帖冠军。 |