KItemList.cpp
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:67k
源码类别:

模拟服务器

开发平台:

C/C++

  1. #include "KCore.h"
  2. #include "MyAssert.H"
  3. #include "KItem.h"
  4. #include "KItemSet.h"
  5. #include "KNpc.h"
  6. #include "KMath.h"
  7. #include "KPlayer.h"
  8. #include "KItemList.h"
  9. #include "KItemChangeRes.h"
  10. #ifdef _SERVER
  11. //#include "../../Headers/IServer.h"
  12. #include "KObjSet.h"
  13. #endif
  14. #ifndef _SERVER
  15. #include "CoreShell.h"
  16. #include "../../Headers/IClient.h"
  17. #endif
  18. // PK死亡惩罚掉穿的装备,各装备掉落的权值
  19. #define defEQUIP_POWER
  20. #ifdef defEQUIP_POWER
  21. int g_nEquipPower[itempart_num] =
  22. {2, 4, 2, 4, 1, 1, 1, 1, 1, 1, 0};
  23. #endif
  24. int KItemList::ms_ActiveEquip[itempart_num][MAX_ITEM_ACTIVE] = 
  25. {
  26. { itempart_foot, itempart_ring1 }, // itempart_head = 0,
  27. { itempart_weapon, itempart_head }, // itempart_body,
  28. { itempart_body, itempart_amulet }, // itempart_belt,
  29. { itempart_ring1, itempart_foot }, // itempart_weapon,
  30. { itempart_cuff, itempart_pendant },// itempart_foot,
  31. { itempart_belt, itempart_ring2 }, // itempart_cuff,
  32. { itempart_head, itempart_weapon }, // itempart_amulet,
  33. { itempart_cuff, itempart_pendant },// itempart_ring1,
  34. { itempart_amulet, itempart_body }, // itempart_ring2,
  35. { itempart_belt, itempart_ring2 }, // itempart_pendant,
  36. { itempart_horse, itempart_horse }, // itempart_horse,
  37. };
  38. int KItemList::ms_ActivedEquip[itempart_num][MAX_ITEM_ACTIVE] =
  39. {
  40. { itempart_body, itempart_amulet }, // itempart_head = 0,
  41. { itempart_ring2, itempart_belt }, // itempart_body,
  42. { itempart_pendant, itempart_cuff },// itempart_belt,
  43. { itempart_amulet, itempart_body }, // itempart_weapon,
  44. { itempart_weapon, itempart_head }, // itempart_foot,
  45. { itempart_foot, itempart_ring1 }, // itempart_cuff,
  46. { itempart_belt, itempart_ring2 }, // itempart_amulet,
  47. { itempart_weapon, itempart_head }, // itempart_ring1,
  48. { itempart_cuff, itempart_pendant },// itempart_ring2,
  49. { itempart_foot, itempart_ring1 }, // itempart_pendant,
  50. { itempart_horse, itempart_horse }, // itempart_horse,
  51. };
  52. KItemList::KItemList()
  53. {
  54. m_PlayerIdx = 0;
  55. m_nListCurIdx = 0;
  56. }
  57. KItemList::~KItemList()
  58. {
  59. }
  60. /*!*****************************************************************************
  61. // Function : KItemList::GetWeaponType
  62. // Purpose : 取得玩家装备的武器类型
  63. // Return : int 
  64. // Comments :
  65. // Author : Spe
  66. *****************************************************************************/
  67. int KItemList::GetWeaponType()
  68. {
  69. if (m_EquipItem[itempart_weapon])
  70. return Item[m_EquipItem[itempart_weapon]].GetDetailType();
  71. else
  72. return -1;
  73. }
  74. void KItemList::GetWeaponDamage(int* nMin, int* nMax)
  75. {
  76. int nWeaponIdx = m_EquipItem[itempart_weapon];
  77. if (nWeaponIdx)
  78. {
  79. _ASSERT(Item[nWeaponIdx].m_CommonAttrib.nItemGenre == item_equip 
  80. && (Item[nWeaponIdx].m_CommonAttrib.nDetailType == equip_meleeweapon
  81. || Item[nWeaponIdx].m_CommonAttrib.nDetailType == equip_rangeweapon));
  82. int nMinDamage, nMaxDamage, nEnhance;
  83. int nDamageMinBase = Item[nWeaponIdx].m_aryBaseAttrib[0].nValue[0];
  84. int nDamageMaxBase = Item[nWeaponIdx].m_aryBaseAttrib[1].nValue[0];
  85. nMinDamage = 0;
  86. nMaxDamage = 0;
  87. nEnhance = 0;
  88. for (int i = 0; i < 6; i++)
  89. {
  90. switch(Item[nWeaponIdx].m_aryMagicAttrib[i].nAttribType)
  91. {
  92. case magic_weapondamagemin_v:
  93. nMinDamage += Item[nWeaponIdx].m_aryMagicAttrib[i].nValue[0];
  94. break;
  95. case magic_weapondamagemax_v:
  96. nMaxDamage += Item[nWeaponIdx].m_aryMagicAttrib[i].nValue[0];
  97. break;
  98. case magic_weapondamageenhance_p:
  99. nEnhance += Item[nWeaponIdx].m_aryMagicAttrib[i].nValue[0];
  100. break;
  101. default:
  102. break;
  103. }
  104. }
  105. *nMin = (nDamageMinBase + nMinDamage) * (100 + nEnhance) / 100;
  106. *nMax = (nDamageMaxBase + nMaxDamage) * (100 + nEnhance) / 100;
  107. }
  108. else // 空手
  109. {
  110. /*
  111. int nDamageBase = Player[m_PlayerIdx].m_nCurStrength * Player[m_PlayerIdx].m_nCurDexterity;
  112. *nMin = nDamageBase >> 9;
  113. *nMax = nDamageBase >> 8;
  114. */
  115. // 数值计算方法修改(孙英要求) by Spe 03/06/11
  116. _ASSERT(STRENGTH_SET_DAMAGE_VALUE > 0);
  117. *nMin = Player[m_PlayerIdx].m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE + 1;
  118. *nMax = Player[m_PlayerIdx].m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE + 1;
  119. }
  120. }
  121. /*!*****************************************************************************
  122. // Function : KItemList::Add
  123. // Purpose : 玩家得到一个装备
  124. // Return : int 
  125. // Argumant : int nIdx Item数组的idx
  126. // Argumant : int nPlace
  127. // Argumant : int nX
  128. // Argumant : int nY
  129. // Comments :
  130. // Author : Spe
  131. *****************************************************************************/
  132. int KItemList::Add(int nIdx, int nPlace, int nX, int nY)
  133. {
  134. if (nIdx <= 0)
  135. return 0;
  136. if (Item[nIdx].GetID() == 0)
  137. return 0;
  138. int i = FindFree();
  139. if (!i)
  140. return 0;
  141. switch(nPlace)
  142. {
  143. case pos_hand:
  144. if (m_Hand)
  145. return 0;
  146. m_Items[i].nPlace = pos_hand;
  147. m_Items[i].nX = 0;
  148. m_Items[i].nY = 0;
  149. m_Hand = nIdx;
  150. break;
  151. case pos_equip:
  152. if (nX < 0 || nX >= itempart_num)
  153. return 0;
  154. if (m_EquipItem[nX])
  155. return 0;
  156. // 有可能是条件不够,被其他装备凑上的。是否能装备应该放到Equip时检查
  157. // if (!CanEquip(nIdx, nX))
  158. // return 0;
  159. m_Items[i].nPlace = pos_equip;
  160. m_Items[i].nX = nX;
  161. m_Items[i].nY = 0;
  162. break;
  163. case pos_equiproom:
  164. if (!m_Room[room_equipment].PlaceItem(nX, nY, nIdx, Item[nIdx].GetWidth(), Item[nIdx].GetHeight()))
  165. return 0;
  166. m_Items[i].nPlace = pos_equiproom;
  167. m_Items[i].nX = nX;
  168. m_Items[i].nY = nY;
  169. break;
  170. #ifndef _SERVER
  171. case pos_trade1:
  172. if ( !Player[CLIENT_PLAYER_INDEX].CheckTrading() )
  173. return 0;
  174. if (!m_Room[room_trade1].PlaceItem(nX, nY, nIdx, Item[nIdx].GetWidth(), Item[nIdx].GetHeight()))
  175. return 0;
  176. m_Items[i].nPlace = pos_trade1;
  177. m_Items[i].nX = nX;
  178. m_Items[i].nY = nY;
  179. break;
  180. #endif
  181. case pos_repositoryroom:
  182. if (!m_Room[room_repository].PlaceItem(nX, nY, nIdx, Item[nIdx].GetWidth(), Item[nIdx].GetHeight()))
  183. return 0;
  184. m_Items[i].nPlace = pos_repositoryroom;
  185. m_Items[i].nX = nX;
  186. m_Items[i].nY = nY;
  187. break;
  188. case pos_immediacy:
  189. if (!m_Room[room_immediacy].PlaceItem(nX, nY, nIdx, Item[nIdx].GetWidth(), Item[nIdx].GetHeight()))
  190. return 0;
  191. m_Items[i].nPlace = pos_immediacy;
  192. m_Items[i].nX = nX;
  193. m_Items[i].nY = nY;
  194. break;
  195. default:
  196. return 0;
  197. }
  198. m_Items[i].nIdx = nIdx;
  199. m_FreeIdx.Remove(i);
  200. m_UseIdx.Insert(i);
  201. if (m_Items[i].nPlace == pos_equip)
  202. {
  203. Equip(m_Items[i].nIdx, nX);
  204. }
  205. #ifdef _SERVER
  206. ITEM_SYNC sItem;
  207. sItem.ProtocolType = s2c_syncitem;
  208. sItem.m_ID = Item[nIdx].GetID();
  209. sItem.m_Genre = Item[nIdx].GetGenre();
  210. sItem.m_Detail = Item[nIdx].GetDetailType();
  211. sItem.m_Particur = Item[nIdx].GetParticular();
  212. sItem.m_Series = Item[nIdx].GetSeries();
  213. sItem.m_Level = Item[nIdx].GetLevel();
  214. sItem.m_Luck = Item[nIdx].m_GeneratorParam.nLuck;
  215. sItem.m_btPlace = m_Items[i].nPlace;
  216. sItem.m_btX = m_Items[i].nX;
  217. sItem.m_btY = m_Items[i].nY;
  218. for (int j = 0; j < 6; j++)
  219. sItem.m_MagicLevel[j] = (BYTE)Item[nIdx].m_GeneratorParam.nGeneratorLevel[j];
  220. sItem.m_RandomSeed = Item[nIdx].m_GeneratorParam.uRandomSeed;
  221. sItem.m_Version = Item[nIdx].m_GeneratorParam.nVersion;
  222. sItem.m_Durability = Item[nIdx].GetDurability();
  223. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sItem, sizeof(ITEM_SYNC));
  224. #endif
  225. #ifndef _SERVER
  226. KUiObjAtContRegion pInfo;
  227. int PartConvert[itempart_num] = 
  228. {
  229. UIEP_HEAD,
  230. UIEP_BODY,
  231. UIEP_WAIST,
  232. UIEP_HAND,
  233. UIEP_FOOT,
  234. UIEP_FINESSE,
  235. UIEP_NECK,
  236. UIEP_FINGER1,
  237. UIEP_FINGER2,
  238. UIEP_WAIST_DECOR,
  239. UIEP_HORSE,
  240. };
  241. pInfo.Obj.uGenre = CGOG_ITEM; //源装备
  242. pInfo.Obj.uId = nIdx;
  243. pInfo.Region.Width = Item[nIdx].GetWidth();
  244. pInfo.Region.Height = Item[nIdx].GetHeight();
  245. switch(nPlace)
  246. {
  247. case pos_immediacy:
  248. pInfo.Region.h = nX;
  249. pInfo.Region.v = nY;
  250. pInfo.eContainer = UOC_IMMEDIA_ITEM;
  251. break;
  252. case pos_hand:
  253. pInfo.eContainer = UOC_IN_HAND;
  254. break;
  255. case pos_equip:
  256. pInfo.Region.h = 0;
  257. pInfo.Region.v = PartConvert[nX];
  258. pInfo.eContainer = UOC_EQUIPTMENT;
  259. break;
  260. case pos_equiproom:
  261. pInfo.Region.h = nX;
  262. pInfo.Region.v = nY;
  263. pInfo.eContainer = UOC_ITEM_TAKE_WITH;
  264. break;
  265. case pos_repositoryroom:
  266. pInfo.Region.h = nX;
  267. pInfo.Region.v = nY;
  268. pInfo.eContainer = UOC_STORE_BOX;
  269. break;
  270. case pos_trade1:
  271. pInfo.Region.h = nX;
  272. pInfo.Region.v = nY;
  273. break;
  274. }
  275. if (nPlace != pos_trade1)
  276. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&pInfo, 1);
  277. else
  278. {
  279. CoreDataChanged(GDCNI_TRADE_DESIRE_ITEM, (DWORD)&pInfo, 1);
  280. }
  281. #ifdef _DEBUG
  282. int nLoopIdx = 0;
  283. nLoopIdx = m_UseIdx.GetNext(nLoopIdx);
  284. g_DebugLog("[ITEM]Item Begin");
  285. while(nLoopIdx)
  286. {
  287. g_DebugLog("[ITEM]ItemListIdx:%d, Item:%d, ItemId:%d", nLoopIdx, m_Items[nLoopIdx].nIdx, Item[m_Items[nLoopIdx].nIdx].GetID());
  288. nLoopIdx = m_UseIdx.GetNext(nLoopIdx);
  289. }
  290. #endif
  291. #endif
  292. return i;
  293. }
  294. /*!*****************************************************************************
  295. // Function : KItemList::Remove
  296. // Purpose : 玩家失去一个装备
  297. // Return : int 
  298. // Argumant : int nGameIdx为游戏世界中道具数组的编号
  299. // Comments :
  300. // Author : Spe
  301. *****************************************************************************/
  302. BOOL KItemList::Remove(int nGameIdx)
  303. {
  304. if (!nGameIdx)
  305. return FALSE;
  306. int nIdx = FindSame(nGameIdx);
  307. if (!nIdx)
  308. return FALSE;
  309. #ifdef _SERVER
  310. ITEM_REMOVE_SYNC sRemove;
  311. sRemove.ProtocolType = s2c_removeitem;
  312. sRemove.m_ID = Item[nGameIdx].m_dwID;
  313. #endif
  314. switch(m_Items[nIdx].nPlace)
  315. {
  316. case pos_hand:
  317. m_Hand = 0;
  318. break;
  319. case pos_equip:
  320. UnEquip(m_Items[nIdx].nIdx);
  321. break;
  322. case pos_immediacy:
  323. m_Room[room_immediacy].PickUpItem(
  324. nGameIdx,
  325. m_Items[nIdx].nX,
  326. m_Items[nIdx].nY,
  327. Item[m_Items[nIdx].nIdx].GetWidth(),
  328. Item[m_Items[nIdx].nIdx].GetHeight());
  329. break;
  330. case pos_equiproom:
  331. m_Room[room_equipment].PickUpItem(
  332. nGameIdx,
  333. m_Items[nIdx].nX,
  334. m_Items[nIdx].nY,
  335. Item[m_Items[nIdx].nIdx].GetWidth(),
  336. Item[m_Items[nIdx].nIdx].GetHeight());
  337. break;
  338. case pos_repositoryroom:
  339. m_Room[room_repository].PickUpItem(
  340. nGameIdx,
  341. m_Items[nIdx].nX,
  342. m_Items[nIdx].nY,
  343. Item[m_Items[nIdx].nIdx].GetWidth(),
  344. Item[m_Items[nIdx].nIdx].GetHeight());
  345. break;
  346. case pos_traderoom:
  347. m_Room[room_trade].PickUpItem(
  348. nGameIdx,
  349. m_Items[nIdx].nX,
  350. m_Items[nIdx].nY,
  351. Item[m_Items[nIdx].nIdx].GetWidth(),
  352. Item[m_Items[nIdx].nIdx].GetHeight());
  353. break;
  354. #ifndef _SERVER
  355. case pos_trade1:
  356. if ( !Player[CLIENT_PLAYER_INDEX].CheckTrading() )
  357. {
  358. _ASSERT(0);
  359. }
  360. m_Room[room_trade1].PickUpItem(
  361. nGameIdx,
  362. m_Items[nIdx].nX,
  363. m_Items[nIdx].nY,
  364. Item[m_Items[nIdx].nIdx].GetWidth(),
  365. Item[m_Items[nIdx].nIdx].GetHeight());
  366. break;
  367. #endif
  368. default:
  369. return FALSE;
  370. }
  371. #ifndef _SERVER
  372. // 客户端从玩家身上去除装备就应该从装备表中去除掉。
  373. ItemSet.Remove(m_Items[nIdx].nIdx);
  374. // 界面处理
  375. KUiObjAtContRegion pInfo;
  376. int PartConvert[itempart_num] = 
  377. {
  378. UIEP_HEAD,
  379. UIEP_BODY,
  380. UIEP_WAIST,
  381. UIEP_HAND,
  382. UIEP_FOOT,
  383. UIEP_FINESSE,
  384. UIEP_NECK,
  385. UIEP_FINGER1,
  386. UIEP_FINGER2,
  387. UIEP_WAIST_DECOR,
  388. UIEP_HORSE,
  389. };
  390. pInfo.Obj.uGenre = CGOG_ITEM;
  391. pInfo.Obj.uId = m_Items[nIdx].nIdx;
  392. pInfo.Region.Width = Item[m_Items[nIdx].nIdx].GetWidth();
  393. pInfo.Region.Height = Item[m_Items[nIdx].nIdx].GetHeight();
  394. switch(m_Items[nIdx].nPlace)
  395. {
  396. case pos_hand:
  397. pInfo.Obj.uGenre = CGOG_NOTHING;
  398. pInfo.Region.h = 0;
  399. pInfo.Region.v = 0;
  400. pInfo.eContainer = UOC_IN_HAND;
  401. break;
  402. case pos_equiproom:
  403. pInfo.Region.h = m_Items[nIdx].nX;
  404. pInfo.Region.v = m_Items[nIdx].nY;
  405. pInfo.eContainer = UOC_ITEM_TAKE_WITH;
  406. break;
  407. case pos_repositoryroom:
  408. pInfo.Region.h = m_Items[nIdx].nX;
  409. pInfo.Region.v = m_Items[nIdx].nY;
  410. pInfo.eContainer = UOC_STORE_BOX;
  411. break;
  412. case pos_immediacy:
  413. pInfo.Region.h = m_Items[nIdx].nX;
  414. pInfo.Region.v = m_Items[nIdx].nY;
  415. pInfo.eContainer = UOC_IMMEDIA_ITEM;
  416. break;
  417. case pos_equip:
  418. pInfo.Region.h = 0;
  419. pInfo.Region.v = PartConvert[m_Items[nIdx].nX];
  420. pInfo.eContainer = UOC_EQUIPTMENT;
  421. break;
  422. case pos_trade1:
  423. pInfo.Region.h = m_Items[nIdx].nX;
  424. pInfo.Region.v = m_Items[nIdx].nY;
  425. break;
  426. }
  427. if (m_Items[nIdx].nPlace != pos_trade1)
  428. {
  429. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&pInfo, 0);
  430. }
  431. else
  432. {
  433. CoreDataChanged(GDCNI_TRADE_DESIRE_ITEM, (DWORD)&pInfo, 0);
  434. }
  435. #endif
  436. m_Items[nIdx].nIdx = 0;
  437. m_Items[nIdx].nPlace = 0;
  438. m_Items[nIdx].nX = 0;
  439. m_Items[nIdx].nY = 0;
  440. m_FreeIdx.Insert(nIdx);
  441. m_UseIdx.Remove(nIdx);
  442. #ifdef _SERVER
  443. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sRemove, sizeof(ITEM_REMOVE_SYNC));
  444. #endif
  445. return TRUE;
  446. }
  447. /*!*****************************************************************************
  448. // Function : KItemList::FindFree
  449. // Purpose : 查找可用空索引
  450. // Return : int 
  451. // Comments :
  452. // Author : Spe
  453. *****************************************************************************/
  454. int KItemList::FindFree()
  455. {
  456. return m_FreeIdx.GetNext(0);
  457. }
  458. /*!*****************************************************************************
  459. // Function : KItemList::FindSame
  460. // Purpose : 
  461. // Return : int 
  462. // Argumant : int nGameIdx
  463. // Comments :
  464. // Author : Spe
  465. *****************************************************************************/
  466. int KItemList::FindSame(int nGameIdx)
  467. {
  468. int nIdx = 0;
  469. while(1)
  470. {
  471. nIdx = m_UseIdx.GetNext(nIdx);
  472. if (!nIdx)
  473. break;
  474. if (m_Items[nIdx].nIdx == nGameIdx)
  475. return nIdx;
  476. }
  477. return 0;
  478. }
  479. /*!*****************************************************************************
  480. // Function : KItemList::Init
  481. // Purpose : 初始化玩家装备列表
  482. // Return : BOOL
  483. // Comments :
  484. // Author : Spe
  485. *****************************************************************************/
  486. BOOL KItemList::Init(int nPlayerIdx)
  487. {
  488. m_PlayerIdx = nPlayerIdx;
  489. m_Hand = 0;
  490. m_nBackHand = 0;
  491. // TODO: Maybe we can read size from ini file.
  492. // int nWidth = 6;
  493. // int nHeight = 10;
  494. // m_Room[room_equipment].Init(nWidth, nHeight);
  495. // m_Room[room_repository].Init(nWidth, nHeight);
  496. // m_Room[room_trade].Init(nWidth, nHeight);
  497. // m_Room[room_tradeback].Init(nWidth, nHeight);
  498. m_Room[room_equipment].Init(EQUIPMENT_ROOM_WIDTH, EQUIPMENT_ROOM_HEIGHT);
  499. m_Room[room_repository].Init(REPOSITORY_ROOM_WIDTH, REPOSITORY_ROOM_HEIGHT);
  500. m_Room[room_trade].Init(TRADE_ROOM_WIDTH, TRADE_ROOM_HEIGHT);
  501. m_Room[room_tradeback].Init(EQUIPMENT_ROOM_WIDTH, EQUIPMENT_ROOM_HEIGHT);
  502. m_Room[room_immediacy].Init(IMMEDIACY_ROOM_WIDTH, IMMEDIACY_ROOM_HEIGHT);
  503. #ifndef _SERVER
  504. m_Room[room_trade1].Init(TRADE_ROOM_WIDTH, TRADE_ROOM_HEIGHT); // 这个的大小必须与 room_trade 的大小一样
  505. #endif
  506. ZeroMemory(m_EquipItem, sizeof(m_EquipItem)); // 玩家装备的道具(对应游戏世界中道具数组的索引)
  507. ZeroMemory(m_Items, sizeof(m_Items)); // 玩家拥有的所有道具(包括装备着的和箱子里放的,对应游戏世界中道具数组的索引)
  508. m_nListCurIdx = 0; // 用于 GetFirstItem 和 GetNextItem
  509. m_FreeIdx.Init(MAX_PLAYER_ITEM);
  510. m_UseIdx.Init(MAX_PLAYER_ITEM);
  511. for (int i = MAX_PLAYER_ITEM - 1; i > 0 ; i--)
  512. {
  513. m_FreeIdx.Insert(i);
  514. }
  515. return TRUE;
  516. }
  517. /*!*****************************************************************************
  518. // Function : KItemList::CanEquip
  519. // Purpose : 
  520. // Return : BOOL 
  521. // Argumant : int nIdx
  522. // Argumant : int nPlace
  523. // Comments :
  524. // Author : Spe
  525. *****************************************************************************/
  526. BOOL KItemList::CanEquip(int nIdx, int nPlace)
  527. {
  528. if (m_PlayerIdx <= 0 || nIdx <= 0 || nIdx >= MAX_ITEM || Item[nIdx].GetGenre() != item_equip)
  529. return FALSE;
  530. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  531. KMagicAttrib* pData = NULL;
  532. if (nPlace != -1 && !Fit(nIdx, nPlace))
  533. {
  534. return FALSE;
  535. }
  536. int nCount = 0;
  537. do
  538. {
  539. pData = (KMagicAttrib*)Item[nIdx].GetRequirement(nCount);
  540. if (pData && !EnoughAttrib(pData))
  541. return FALSE;
  542. nCount++;
  543. } while (pData != NULL);
  544. return TRUE;
  545. }
  546. BOOL KItemList::CanEquip(KItem* pItem, int nPlace /* = -1 */)
  547. {
  548. if (m_PlayerIdx <= 0 || !pItem)
  549. return FALSE;
  550. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  551. KMagicAttrib* pData = NULL;
  552. if (nPlace != -1 && !Fit(pItem, nPlace))
  553. {
  554. return FALSE;
  555. }
  556. int nCount = 0;
  557. do
  558. {
  559. pData = (KMagicAttrib*)pItem->GetRequirement(nCount);
  560. if (pData && !EnoughAttrib(pData))
  561. return FALSE;
  562. nCount++;
  563. } while (pData != NULL);
  564. return TRUE;
  565. }
  566. BOOL KItemList::EnoughAttrib(void* pAttrib)
  567. {
  568. KMagicAttrib* pData = (KMagicAttrib *)pAttrib;
  569. _ASSERT(pData);
  570. switch(pData->nAttribType)
  571. {
  572. case magic_requirestr:
  573. if (Player[m_PlayerIdx].m_nCurStrength < pData->nValue[0])
  574. {
  575. return FALSE;
  576. }
  577. break;
  578. case magic_requiredex:
  579. if (Player[m_PlayerIdx].m_nCurDexterity < pData->nValue[0])
  580. {
  581. return FALSE;
  582. }
  583. break;
  584. case magic_requirevit:
  585. if (Player[m_PlayerIdx].m_nCurVitality < pData->nValue[0])
  586. {
  587. return FALSE;
  588. }
  589. break;
  590. case magic_requireeng:
  591. if (Player[m_PlayerIdx].m_nCurEngergy < pData->nValue[0])
  592. {
  593. return FALSE;
  594. }
  595. break;
  596. case magic_requirelevel:
  597. if (Npc[Player[m_PlayerIdx].m_nIndex].m_Level < pData->nValue[0])
  598. {
  599. return FALSE;
  600. }
  601. break;
  602. case magic_requiremenpai:
  603. if (Player[m_PlayerIdx].m_cFaction.m_nCurFaction != pData->nValue[0])
  604. {
  605. return FALSE;
  606. }
  607. break;
  608. case magic_requireseries:
  609. if (Npc[Player[m_PlayerIdx].m_nIndex].m_Series != pData->nValue[0])
  610. {
  611. return FALSE;
  612. }
  613. break;
  614. case magic_requiresex:
  615. if (Npc[Player[m_PlayerIdx].m_nIndex].m_nSex != pData->nValue[0])
  616. {
  617. return FALSE;
  618. }
  619. break;
  620. default:
  621. break;
  622. }
  623. return TRUE;
  624. }
  625. /*!*****************************************************************************
  626. // Function : KItemList::Equip
  627. // Purpose : 
  628. // Return : BOOL
  629. // Argumant : int nIdx,游戏世界中的道具数组编号,要求一定是装备类道具
  630. // Argumant : int nPlace,身上装备的位置,-1自动找位置
  631. // Comments :
  632. // Author : Spe
  633. *****************************************************************************/
  634. BOOL KItemList::Equip(int nIdx, int nPlace /* = -1 */)
  635. {
  636. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  637. if (m_PlayerIdx <= 0 || nIdx <= 0 || nNpcIdx <= 0 || item_equip != Item[nIdx].GetGenre())
  638. return FALSE;
  639. int nItemListIdx = FindSame(nIdx);
  640. if (!nItemListIdx)
  641. {
  642. _ASSERT(0);
  643. return FALSE;
  644. }
  645. int nEquipPlace = nPlace;
  646. if (-1 == nEquipPlace)
  647. {
  648. nEquipPlace = GetEquipPlace(Item[nIdx].GetDetailType());
  649. }
  650. else if (!Fit(nIdx, nEquipPlace))
  651. {
  652. return FALSE;
  653. }
  654. // 换装
  655. switch(nEquipPlace)
  656. {
  657. case itempart_head:
  658. Npc[nNpcIdx].m_HelmType = g_ItemChangeRes.GetHelmRes(Item[nIdx].GetParticular(), Item[nIdx].GetLevel());
  659. break;
  660. case itempart_body:
  661. Npc[nNpcIdx].m_ArmorType = g_ItemChangeRes.GetArmorRes(Item[nIdx].GetParticular(), Item[nIdx].GetLevel());
  662. break;
  663. case itempart_weapon:
  664. Npc[nNpcIdx].m_WeaponType = g_ItemChangeRes.GetWeaponRes(Item[nIdx].GetDetailType(), Item[nIdx].GetParticular(), Item[nIdx].GetLevel());
  665. break;
  666. case itempart_horse:
  667. Npc[nNpcIdx].m_HorseType = g_ItemChangeRes.GetHorseRes(Item[nIdx].GetParticular(), Item[nIdx].GetLevel());
  668. if (Npc[nNpcIdx].m_HorseType >= 0)
  669. {
  670. Npc[nNpcIdx].m_bRideHorse = TRUE;
  671. }
  672. else
  673. {
  674. Npc[nNpcIdx].m_bRideHorse = FALSE;
  675. }
  676. break;
  677. default:
  678. break;
  679. }
  680. // 更新装备自身坐标
  681. m_EquipItem[nEquipPlace] = nIdx;
  682. m_Items[nItemListIdx].nPlace = pos_equip;
  683. m_Items[nItemListIdx].nX = nEquipPlace;
  684. m_Items[nItemListIdx].nY = 0;
  685. //#ifdef _SERVER because client need to show to menu
  686. int nActive = GetEquipEnhance(nEquipPlace);
  687. Item[nIdx].ApplyMagicAttribToNPC(&Npc[nNpcIdx], nActive);
  688. InfectionNextEquip(nEquipPlace, TRUE);
  689. if (itempart_weapon == nEquipPlace)
  690. {
  691. #ifndef _SERVER
  692. Player[CLIENT_PLAYER_INDEX].UpdateWeaponSkill();
  693. #endif
  694. Player[m_PlayerIdx].SetNpcDamageAttrib();
  695. }
  696. //#endif
  697. return TRUE;
  698. }
  699. /*!*****************************************************************************
  700. // Function : KItemList::InfectionNextEquip
  701. // Purpose : 装备影响其他装备
  702. // Return : void 
  703. // Argumant : int nEquipPlace
  704. // Argumant : BOOL bEquipUp 是装上(TRUE)还是卸下(FALSE)
  705. // Comments :
  706. // Author : Spe
  707. *****************************************************************************/
  708. void KItemList::InfectionNextEquip(int nEquipPlace, BOOL bEquip/* = FALSE */)
  709. {
  710. if (m_PlayerIdx <= 0)
  711. return;
  712. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  713. for (int i = 0; i < MAX_ITEM_ACTIVE; i++)
  714. {
  715. int nInfectionEquip = ms_ActiveEquip[nEquipPlace][i];
  716. if (!m_EquipItem[nInfectionEquip])
  717. continue;
  718. if (g_IsAccrue(Item[m_EquipItem[nEquipPlace]].GetSeries(),
  719. Item[m_EquipItem[nInfectionEquip]].GetSeries()))
  720. {
  721. int nActive = GetEquipEnhance(nInfectionEquip);
  722. _ASSERT(nActive > 0);
  723. if (bEquip)
  724. Item[m_EquipItem[nInfectionEquip]].ApplyHiddenMagicAttribToNPC(&Npc[nNpcIdx], nActive);
  725. else
  726. Item[m_EquipItem[nInfectionEquip]].RemoveHiddenMagicAttribFromNPC(&Npc[nNpcIdx], nActive);
  727. }
  728. }
  729. }
  730. /*!*****************************************************************************
  731. // Function : KItemList::UnEquip
  732. // Purpose : 移除装备
  733. // Return : BOOL 
  734. // Argumant : int nIdx 游戏世界中的道具数组索引
  735. // Comments : 
  736. // Author : Spe
  737. *****************************************************************************/
  738. BOOL KItemList::UnEquip(int nIdx, int nPos/* = -1*/)
  739. {
  740. int i = 0;
  741. if (m_PlayerIdx <= 0)
  742. return FALSE;
  743. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  744. if (nIdx <= 0)
  745. return FALSE;
  746. if (nPos <= 0)
  747. {
  748. for (i = 0; i < itempart_num; i++)
  749. {
  750. if (m_EquipItem[i] == nIdx)
  751. {
  752. break;
  753. }
  754. }
  755. // 没有发现身上有这个装备
  756. if (i == itempart_num)
  757. return FALSE;
  758. }
  759. else
  760. {
  761. if (m_EquipItem[nPos] != nIdx) // 东西不对
  762. return FALSE;
  763. i = nPos;
  764. }
  765. // 移除该装备对NPC的属性调整
  766. int nActive = GetEquipEnhance(i);
  767. Item[nIdx].RemoveMagicAttribFromNPC(&Npc[nNpcIdx], nActive);
  768. // 移除该装备可能对它激活的装备的影响。
  769. InfectionNextEquip(i, FALSE);
  770. // 这句话一定要放在上一句后,保证计算该装备激活的装备激活属性个数计算的正确性
  771. m_EquipItem[i] = 0;
  772. // 换装
  773. switch(i)
  774. {
  775. case itempart_head:
  776. Npc[nNpcIdx].m_HelmType = g_ItemChangeRes.GetHelmRes(0, 0);
  777. break;
  778. case itempart_body:
  779. Npc[nNpcIdx].m_ArmorType = g_ItemChangeRes.GetArmorRes(0, 0);
  780. break;
  781. case itempart_weapon:
  782. Npc[nNpcIdx].m_WeaponType = g_ItemChangeRes.GetWeaponRes(0, 0, 0);
  783. break;
  784. case itempart_horse:
  785. Npc[nNpcIdx].m_HorseType = -1;
  786. Npc[nNpcIdx].m_bRideHorse = FALSE;
  787. break;
  788. default:
  789. break;
  790. }
  791. if (itempart_weapon == i)
  792. {
  793. #ifndef _SERVER
  794. Player[CLIENT_PLAYER_INDEX].UpdateWeaponSkill();
  795. #endif
  796. Player[m_PlayerIdx].SetNpcDamageAttrib();
  797. }
  798. return TRUE;
  799. }
  800. int KItemList::GetEquipPlace(int nType)
  801. {
  802. int nRet = -1;
  803. switch(nType)
  804. {
  805. case equip_meleeweapon:
  806. case equip_rangeweapon:
  807. nRet = itempart_weapon;
  808. break;
  809. case equip_armor:
  810. nRet = itempart_body;
  811. break;
  812. case equip_helm:
  813. nRet = itempart_head;
  814. break;
  815. case equip_boots:
  816. nRet = itempart_foot;
  817. break;
  818. case equip_ring:
  819. nRet = itempart_ring1;
  820. break;
  821. case equip_amulet:
  822. nRet = itempart_amulet;
  823. break;
  824. case equip_belt:
  825. nRet = itempart_belt;
  826. break;
  827. case equip_cuff:
  828. nRet = itempart_cuff;
  829. break;
  830. case equip_pendant:
  831. nRet = itempart_pendant;
  832. break;
  833. case equip_horse:
  834. nRet = itempart_horse;
  835. break;
  836. default:
  837. break;
  838. }
  839. return nRet;
  840. }
  841. /*!*****************************************************************************
  842. // Function : KItemList::Fit
  843. // Purpose : 
  844. // Return : BOOL 
  845. // Argumant : int nIdx
  846. // Argumant : int nPlace
  847. // Comments :
  848. // Author : Spe
  849. *****************************************************************************/
  850. BOOL KItemList::Fit(int nIdx, int nPlace)
  851. {
  852. BOOL bRet = FALSE;
  853. _ASSERT(Item[nIdx].GetGenre() == item_equip);
  854. switch(Item[nIdx].GetDetailType())
  855. {
  856. case equip_meleeweapon:
  857. case equip_rangeweapon:
  858. if (nPlace == itempart_weapon)
  859. bRet = TRUE;
  860. break;
  861. case equip_armor:
  862. if (nPlace == itempart_body)
  863. bRet = TRUE;
  864. break;
  865. case equip_belt:
  866. if (nPlace == itempart_belt)
  867. bRet = TRUE;
  868. break;
  869. case equip_boots:
  870. if (nPlace == itempart_foot)
  871. bRet = TRUE;
  872. break;
  873. case equip_cuff:
  874. if (nPlace == itempart_cuff)
  875. bRet = TRUE;
  876. break;
  877. case equip_ring:
  878. if (nPlace == itempart_ring1 || nPlace == itempart_ring2)
  879. bRet = TRUE;
  880. break;
  881. case equip_amulet:
  882. if (nPlace == itempart_amulet)
  883. bRet = TRUE;
  884. break;
  885. case equip_pendant:
  886. if (nPlace == itempart_pendant)
  887. bRet = TRUE;
  888. break;
  889. case equip_helm:
  890. if (nPlace == itempart_head)
  891. bRet = TRUE;
  892. break;
  893. case equip_horse:
  894. if (nPlace == itempart_horse)
  895. bRet = TRUE;
  896. break;
  897. }
  898. return bRet;
  899. }
  900. BOOL KItemList::Fit(KItem* pItem, int nPlace)
  901. {
  902. BOOL bRet = FALSE;
  903. _ASSERT(pItem->GetGenre() == item_equip);
  904. switch(pItem->GetDetailType())
  905. {
  906. case equip_meleeweapon:
  907. case equip_rangeweapon:
  908. if (nPlace == itempart_weapon)
  909. bRet = TRUE;
  910. break;
  911. case equip_armor:
  912. if (nPlace == itempart_body)
  913. bRet = TRUE;
  914. break;
  915. case equip_belt:
  916. if (nPlace == itempart_belt)
  917. bRet = TRUE;
  918. break;
  919. case equip_boots:
  920. if (nPlace == itempart_foot)
  921. bRet = TRUE;
  922. break;
  923. case equip_cuff:
  924. if (nPlace == itempart_cuff)
  925. bRet = TRUE;
  926. break;
  927. case equip_ring:
  928. if (nPlace == itempart_ring1 || nPlace == itempart_ring2)
  929. bRet = TRUE;
  930. break;
  931. case equip_amulet:
  932. if (nPlace == itempart_amulet)
  933. bRet = TRUE;
  934. break;
  935. case equip_pendant:
  936. if (nPlace == itempart_pendant)
  937. bRet = TRUE;
  938. break;
  939. case equip_helm:
  940. if (nPlace == itempart_head)
  941. bRet = TRUE;
  942. break;
  943. case equip_horse:
  944. if (nPlace == itempart_horse)
  945. bRet = TRUE;
  946. break;
  947. }
  948. return bRet;
  949. }
  950. int KItemList::GetEquipEnhance(int nPlace)
  951. {
  952. if (m_PlayerIdx <= 0)
  953. return FALSE;
  954. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  955. if (nPlace < 0 || nPlace >= itempart_num)
  956. {
  957. _ASSERT(0);
  958. return 0;
  959. }
  960. int nRet = 0;
  961. int nSeries = Item[m_EquipItem[nPlace]].GetSeries();
  962. if (g_IsAccrue(Npc[nNpcIdx].m_Series, nSeries))
  963. nRet ++;
  964. for (int i = 0; i < MAX_ITEM_ACTIVE; i++)
  965. {
  966. // 看看激活这个装备的装备中是否相生这个装备
  967. int nActivedEquip = m_EquipItem[ms_ActivedEquip[nPlace][i]];
  968. if (nActivedEquip)
  969. {
  970. if (g_IsAccrue(Item[nActivedEquip].GetSeries(), nSeries))
  971. nRet++;
  972. }
  973. }
  974. return nRet;
  975. }
  976. BOOL KItemList::EatMecidine(int nIdx)
  977. {
  978. if (m_PlayerIdx <= 0)
  979. return FALSE;
  980. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  981. int nGenre = Item[nIdx].GetGenre();
  982. _ASSERT(nGenre == item_medicine || nGenre == item_townportal);
  983. if (nGenre == item_medicine)
  984. Item[nIdx].ApplyMagicAttribToNPC(&Npc[nNpcIdx], 3);
  985. if (nGenre == item_townportal)
  986. {
  987. if (!Npc[Player[m_PlayerIdx].m_nIndex].m_FightMode)
  988. {
  989. #ifndef _SERVER // 客户端先看看是不是非战斗区,如果是的话就别发给Server了。
  990. // 系统消息
  991. KSystemMessage Msg;
  992. Msg.byConfirmType = SMCT_CLICK;
  993. Msg.byParamSize = 0;
  994. Msg.byPriority = 1;
  995. Msg.eType = SMT_PLAYER;
  996. strcpy(Msg.szMessage, "无法在这里使用土地符!");
  997. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&Msg, NULL);
  998. #endif
  999. return FALSE;
  1000. }
  1001. #ifdef _SERVER
  1002. Player[m_PlayerIdx].UseTownPortal();
  1003. #endif
  1004. }
  1005. #ifdef _SERVER
  1006. Remove(nIdx);
  1007. ItemSet.Remove(nIdx);
  1008. #endif
  1009. if (Npc[Player[m_PlayerIdx].m_nIndex].m_Doing == do_sit)
  1010. {
  1011. Npc[Player[m_PlayerIdx].m_nIndex].SendCommand(do_stand);
  1012. }
  1013. return TRUE;
  1014. }
  1015. #ifndef _SERVER
  1016. int KItemList::UseItem(int nIdx)
  1017. {
  1018. if (m_PlayerIdx <= 0)
  1019. return FALSE;
  1020. int nNpcIdx = Player[m_PlayerIdx].m_nIndex;
  1021. if (0 == FindSame(nIdx))
  1022. {
  1023. return 0;
  1024. }
  1025. int nRet = 0;
  1026. switch(Item[nIdx].GetGenre())
  1027. {
  1028. case item_equip:
  1029. break;
  1030. /* if (Equip(nNpcIdx, nIdx))
  1031. nRet = REQUEST_EQUIP_ITEM;*/
  1032. break;
  1033. case item_townportal:
  1034. case item_medicine:
  1035. if (EatMecidine(nIdx))
  1036. nRet = REQUEST_EAT_MEDICINE;
  1037. break;
  1038. default:
  1039. break;
  1040. }
  1041. return nRet;
  1042. }
  1043. #endif
  1044. #ifndef _SERVER
  1045. BOOL KItemList::SearchPosition(int nWidth, int nHeight, ItemPos* pPos)
  1046. {
  1047. if (nWidth <= 0 || nHeight <= 0 || NULL == pPos)
  1048. {
  1049. return FALSE;
  1050. }
  1051. POINT pPt;
  1052. if (!m_Room[room_equipment].FindRoom(nWidth, nHeight, &pPt))
  1053. {
  1054. if (0 != m_Hand)
  1055. {
  1056. return FALSE;
  1057. }
  1058. pPos->nPlace = pos_hand;
  1059. pPos->nX = 0;
  1060. pPos->nY = 0;
  1061. }
  1062. else
  1063. {
  1064. pPos->nPlace = pos_equiproom;
  1065. pPos->nX = pPt.x;
  1066. pPos->nY = pPt.y;
  1067. }
  1068. return TRUE;
  1069. }
  1070. #endif
  1071. int KItemList::SearchID(int nID)
  1072. {
  1073. if (m_PlayerIdx <= 0)
  1074. return 0;
  1075. int nIdx = 0;
  1076. while(1)
  1077. {
  1078. nIdx = m_UseIdx.GetNext(nIdx);
  1079. if (!nIdx)
  1080. break;
  1081. if (Item[m_Items[nIdx].nIdx].GetID() == (DWORD)nID)
  1082. return m_Items[nIdx].nIdx;
  1083. }
  1084. return 0;
  1085. }
  1086. void KItemList::ExchangeMoney(int pos1, int pos2, int nMoney)
  1087. {
  1088. if (pos1 < 0 || pos2 < 0 || pos1 > room_trade || pos2 > room_trade)
  1089. return;
  1090. if (m_Room[pos1].AddMoney(-nMoney)) // 源位置能拿出这么多钱来
  1091. {
  1092. if (!m_Room[pos2].AddMoney(nMoney)) // 目的地能放不下去
  1093. {
  1094. m_Room[pos1].AddMoney(nMoney); // 还原源位置的钱
  1095. }
  1096. }
  1097. else
  1098. {
  1099. return;
  1100. }
  1101. #ifndef _SERVER
  1102. if (pos1 == room_equipment && pos2 == room_repository)
  1103. SendClientCmdStoreMoney(0, nMoney);
  1104. else if (pos1 == room_repository && pos2 == room_equipment)
  1105. SendClientCmdStoreMoney(1, nMoney);
  1106. #endif
  1107. #ifdef _SERVER
  1108. SendMoneySync();
  1109. #endif
  1110. }
  1111. //----------------------------------------------------------------------
  1112. // 功能:得到物品栏和储物箱的总钱数
  1113. //----------------------------------------------------------------------
  1114. int KItemList::GetMoneyAmount()
  1115. {
  1116. return (m_Room[room_equipment].GetMoney() + m_Room[room_repository].GetMoney());
  1117. }
  1118. //----------------------------------------------------------------------
  1119. // 功能:得到物品栏和储物箱的钱数
  1120. //----------------------------------------------------------------------
  1121. int KItemList::GetEquipmentMoney()
  1122. {
  1123. return m_Room[room_equipment].GetMoney();
  1124. }
  1125. BOOL KItemList::AddMoney(int nRoom, int nMoney)
  1126. {
  1127. if (nRoom < 0 || nRoom >= room_num)
  1128. return FALSE;
  1129. if ( !m_Room[nRoom].AddMoney(nMoney) )
  1130. return FALSE;
  1131. #ifdef _SERVER
  1132. SendMoneySync();
  1133. #endif
  1134. return TRUE;
  1135. }
  1136. BOOL KItemList::CostMoney(int nMoney)
  1137. {
  1138. if (nMoney > GetEquipmentMoney())
  1139. return FALSE;
  1140. if ( !m_Room[room_equipment].AddMoney(-nMoney) )
  1141. return FALSE;
  1142. #ifdef _SERVER
  1143. SendMoneySync();
  1144. #endif
  1145. return TRUE;
  1146. }
  1147. BOOL KItemList::DecMoney(int nMoney)
  1148. {
  1149. if (nMoney < 0)
  1150. return FALSE;
  1151. if (nMoney > m_Room[room_equipment].GetMoney())
  1152. {
  1153. nMoney -= m_Room[room_equipment].GetMoney();
  1154. SetRoomMoney(room_equipment, 0);
  1155. if (nMoney > m_Room[room_repository].GetMoney())
  1156. SetRoomMoney(room_repository, 0);
  1157. else
  1158. AddMoney(room_repository, -nMoney);
  1159. }
  1160. else
  1161. {
  1162. AddMoney(room_equipment, -nMoney);
  1163. }
  1164. #ifdef _SERVER
  1165. SendMoneySync();
  1166. #endif
  1167. return TRUE;
  1168. }
  1169. #ifdef _SERVER
  1170. //----------------------------------------------------------------------------------
  1171. // 功能:调用此接口必须保证传入的nMoney是一个有效数(正数且不超过所有钱数)
  1172. //----------------------------------------------------------------------------------
  1173. void KItemList::TradeMoveMoney(int nMoney)
  1174. {
  1175. // 自己钱的处理
  1176. m_Room[room_trade].SetMoney(nMoney);
  1177. SendMoneySync();
  1178. // 给对方发消息
  1179. TRADE_MONEY_SYNC sMoney;
  1180. sMoney.ProtocolType = s2c_trademoneysync;
  1181. sMoney.m_nMoney = nMoney;
  1182. g_pServer->PackDataToClient(Player[Player[m_PlayerIdx].m_cTrade.m_nTradeDest].m_nNetConnectIdx, (BYTE*)&sMoney, sizeof(TRADE_MONEY_SYNC));
  1183. }
  1184. #endif
  1185. #ifdef _SERVER
  1186. //----------------------------------------------------------------------------------
  1187. // 功能:服务器发money同步信息给客户端
  1188. //----------------------------------------------------------------------------------
  1189. void KItemList::SendMoneySync()
  1190. {
  1191. PLAYER_MONEY_SYNC sMoney;
  1192. sMoney.ProtocolType = s2c_syncmoney;
  1193. sMoney.m_nMoney1 = m_Room[room_equipment].GetMoney();
  1194. sMoney.m_nMoney2 = m_Room[room_repository].GetMoney();
  1195. sMoney.m_nMoney3 = m_Room[room_trade].GetMoney();
  1196. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMoney, sizeof(PLAYER_MONEY_SYNC));
  1197. }
  1198. #endif
  1199. void KItemList::SetMoney(int nMoney1, int nMoney2, int nMoney3)
  1200. {
  1201. m_Room[room_equipment].SetMoney(nMoney1);
  1202. m_Room[room_repository].SetMoney(nMoney2);
  1203. m_Room[room_trade].SetMoney(nMoney3);
  1204. #ifndef _SERVER
  1205. KUiObjAtContRegion sMoney;
  1206. sMoney.Obj.uGenre = CGOG_MONEY;
  1207. sMoney.Obj.uId = nMoney2;
  1208. sMoney.eContainer = UOC_STORE_BOX;
  1209. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&sMoney, 1);
  1210. #endif
  1211. }
  1212. void KItemList::SetRoomMoney(int nRoom, int nMoney)
  1213. {
  1214. if (nRoom >= 0 && nRoom < room_num)
  1215. m_Room[nRoom].SetMoney(nMoney);
  1216. }
  1217. void KItemList::ExchangeItem(ItemPos* SrcPos, ItemPos* DesPos)
  1218. {
  1219. if (SrcPos->nPlace != DesPos->nPlace)
  1220. return;
  1221. int nTempHand = m_Hand;
  1222. int nEquipIdx1 = 0;
  1223. #ifdef _SERVER
  1224. PLAYER_MOVE_ITEM_SYNC sMove;
  1225. sMove.ProtocolType = s2c_playermoveitem;
  1226. sMove.m_btDownPos = SrcPos->nPlace;
  1227. sMove.m_btDownX = SrcPos->nX;
  1228. sMove.m_btDownY = SrcPos->nY;
  1229. sMove.m_btUpPos = DesPos->nPlace;
  1230. sMove.m_btUpX = DesPos->nX;
  1231. sMove.m_btUpY = DesPos->nY;
  1232. #endif
  1233. // 源装备从SrcPos到手上,手上的装备到DesPos
  1234. switch(SrcPos->nPlace)
  1235. {
  1236. case pos_hand:
  1237. g_DebugLog("%s exchange item error", Npc[Player[m_PlayerIdx].m_nIndex].Name);
  1238. return;
  1239. break;
  1240. case pos_equip:
  1241. if (Player[this->m_PlayerIdx].CheckTrading()) // 如果正在交易
  1242. return;
  1243. if (SrcPos->nX < 0 || SrcPos->nX >= itempart_num || DesPos->nX < 0 || DesPos->nX >= itempart_num)
  1244. return;
  1245. nEquipIdx1 = m_EquipItem[SrcPos->nX];
  1246. if (nEquipIdx1)
  1247. {
  1248. UnEquip(nEquipIdx1, SrcPos->nX);
  1249. }
  1250. if (m_Hand)
  1251. {
  1252. if (CanEquip(m_Hand, DesPos->nX))
  1253. {
  1254. Equip(m_Hand, DesPos->nX);
  1255. m_Hand = nEquipIdx1;
  1256. m_Items[FindSame(nEquipIdx1)].nPlace = pos_hand;
  1257. #ifdef _SERVER
  1258. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1259. #endif
  1260. }
  1261. else if (nEquipIdx1)
  1262. {
  1263. Equip(nEquipIdx1, SrcPos->nX);
  1264. }
  1265. }
  1266. else
  1267. {
  1268. m_Hand = nEquipIdx1;
  1269. m_Items[FindSame(nEquipIdx1)].nPlace = pos_hand;
  1270. #ifdef _SERVER
  1271. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1272. #endif
  1273. }
  1274. break;
  1275. case pos_immediacy:
  1276. if (Player[m_PlayerIdx].CheckTrading()) // 如果正在交易
  1277. return;
  1278. // 判断是否有同类型的物品,有的话不让放下去
  1279. if (m_Hand)
  1280. {
  1281. if (m_Room[room_immediacy].CheckSameDetailType(Item[m_Hand].GetGenre(), Item[m_Hand].GetDetailType()))
  1282. {
  1283. #ifdef _SERVER
  1284. BYTE byFinished = s2c_itemexchangefinish;
  1285. if (g_pServer)
  1286. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, &byFinished, sizeof(BYTE));
  1287. #endif
  1288. #ifndef _SERVER
  1289. KSystemMessage sMsg;
  1290. sMsg.eType = SMT_NORMAL;
  1291. sMsg.byConfirmType = SMCT_NONE;
  1292. sMsg.byPriority = 0;
  1293. sMsg.byParamSize = 0;
  1294. sprintf(sMsg.szMessage, MSG_ITEM_SAME_DETAIL_IN_IMMEDIATE);
  1295. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1296. #endif
  1297. return;
  1298. }
  1299. }
  1300. nEquipIdx1 = m_Room[room_immediacy].FindItem(SrcPos->nX, SrcPos->nY);
  1301. if (nEquipIdx1 < 0)
  1302. return;
  1303. // 先把东西拣起来
  1304. if (nEquipIdx1)
  1305. {
  1306. if (!m_Room[room_immediacy].PickUpItem(nEquipIdx1, SrcPos->nX, SrcPos->nY, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight()))
  1307. return;
  1308. }
  1309. // 如果鼠标上有东西,先试试能不能把他放下去,如果不行的话,还得把原来的东西放回去
  1310. if (m_Hand)
  1311. {
  1312. if (m_Room[room_immediacy].PlaceItem(DesPos->nX, DesPos->nY, m_Hand, Item[m_Hand].GetWidth(), Item[m_Hand].GetHeight())
  1313. && (Item[m_Hand].GetGenre() == item_medicine || Item[m_Hand].GetGenre() == item_townportal))
  1314. {
  1315. int nListIdx = FindSame(m_Hand);
  1316. m_Items[nListIdx].nPlace = pos_immediacy;
  1317. m_Items[nListIdx].nX = DesPos->nX;
  1318. m_Items[nListIdx].nY = DesPos->nY;
  1319. m_Hand = nEquipIdx1;
  1320. m_Items[FindSame(nEquipIdx1)].nPlace = pos_hand;
  1321. #ifdef _SERVER
  1322. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1323. #endif
  1324. }
  1325. // 把原来的东西放回去
  1326. else
  1327. {
  1328. m_Room[room_immediacy].PlaceItem(SrcPos->nX, SrcPos->nY, nEquipIdx1, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight());
  1329. }
  1330. }
  1331. // 如果鼠标上没有东西,只需要把拣起来的东西放到鼠标上
  1332. else
  1333. {
  1334. int nListIdx = FindSame(nEquipIdx1);
  1335. if (nEquipIdx1 && nListIdx)
  1336. {
  1337. m_Items[nListIdx].nPlace = pos_hand;
  1338. m_Hand = nEquipIdx1;
  1339. }
  1340. #ifdef _SERVER
  1341. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1342. #endif
  1343. }
  1344. break;
  1345. case pos_repositoryroom:
  1346. if (Player[m_PlayerIdx].CheckTrading()) // 如果正在交易
  1347. return;
  1348. nEquipIdx1 = m_Room[room_repository].FindItem(SrcPos->nX, SrcPos->nY);
  1349. if (nEquipIdx1 < 0)
  1350. return;
  1351. // 先把东西拣起来
  1352. if (nEquipIdx1)
  1353. {
  1354. if (!m_Room[room_repository].PickUpItem(nEquipIdx1, SrcPos->nX, SrcPos->nY, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight()))
  1355. return;
  1356. }
  1357. // 如果鼠标上有东西,先试试能不能把他放下去,如果不行的话,还得把原来的东西放回去
  1358. if (m_Hand)
  1359. {
  1360. if (m_Room[room_repository].PlaceItem(DesPos->nX, DesPos->nY, m_Hand, Item[m_Hand].GetWidth(), Item[m_Hand].GetHeight()))
  1361. {
  1362. int nListIdx = FindSame(m_Hand);
  1363. m_Items[nListIdx].nPlace = pos_repositoryroom;
  1364. m_Items[nListIdx].nX = DesPos->nX;
  1365. m_Items[nListIdx].nY = DesPos->nY;
  1366. m_Hand = nEquipIdx1;
  1367. m_Items[FindSame(nEquipIdx1)].nPlace = pos_hand;
  1368. #ifdef _SERVER
  1369. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1370. #endif
  1371. }
  1372. // 把原来的东西放回去
  1373. else
  1374. {
  1375. m_Room[room_repository].PlaceItem(SrcPos->nX, SrcPos->nY, nEquipIdx1, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight());
  1376. }
  1377. }
  1378. // 如果鼠标上没有东西,只需要把拣起来的东西放到鼠标上
  1379. else
  1380. {
  1381. int nListIdx = FindSame(nEquipIdx1);
  1382. if (nEquipIdx1 && nListIdx)
  1383. {
  1384. m_Items[nListIdx].nPlace = pos_hand;
  1385. m_Hand = nEquipIdx1;
  1386. }
  1387. #ifdef _SERVER
  1388. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1389. #endif
  1390. }
  1391. break;
  1392. case pos_equiproom:
  1393. nEquipIdx1 = m_Room[room_equipment].FindItem(SrcPos->nX, SrcPos->nY);
  1394. if (nEquipIdx1 < 0)
  1395. return;
  1396. // 先把东西拣起来
  1397. if (nEquipIdx1)
  1398. {
  1399. if (!m_Room[room_equipment].PickUpItem(nEquipIdx1, SrcPos->nX, SrcPos->nY, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight()))
  1400. return;
  1401. }
  1402. // 如果鼠标上有东西,先试试能不能把他放下去,如果不行的话,还得把原来的东西放回去
  1403. if (m_Hand)
  1404. {
  1405. if (m_Room[room_equipment].PlaceItem(DesPos->nX, DesPos->nY, m_Hand, Item[m_Hand].GetWidth(), Item[m_Hand].GetHeight()))
  1406. {
  1407. int nListIdx = FindSame(m_Hand);
  1408. m_Items[nListIdx].nPlace = pos_equiproom;
  1409. m_Items[nListIdx].nX = DesPos->nX;
  1410. m_Items[nListIdx].nY = DesPos->nY;
  1411. m_Hand = nEquipIdx1;
  1412. m_Items[FindSame(nEquipIdx1)].nPlace = pos_hand;
  1413. #ifdef _SERVER
  1414. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1415. #endif
  1416. }
  1417. // 把原来的东西放回去
  1418. else
  1419. {
  1420. m_Room[room_equipment].PlaceItem(SrcPos->nX, SrcPos->nY, nEquipIdx1, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight());
  1421. }
  1422. }
  1423. // 如果鼠标上没有东西,只需要把拣起来的东西放到鼠标上
  1424. else
  1425. {
  1426. int nListIdx = FindSame(nEquipIdx1);
  1427. if (nEquipIdx1 && nListIdx)
  1428. {
  1429. m_Items[nListIdx].nPlace = pos_hand;
  1430. m_Hand = nEquipIdx1;
  1431. }
  1432. #ifdef _SERVER
  1433. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1434. #endif
  1435. }
  1436. break;
  1437. case pos_traderoom:
  1438. if ( !Player[m_PlayerIdx].CheckTrading() ) // 不在交易
  1439. return;
  1440. #ifdef _SERVER
  1441. if (m_Hand && Item[m_Hand].GetGenre() == item_task)
  1442. {
  1443. // 通知界面,任务道具,不能交易
  1444. SHOW_MSG_SYNC sMsg;
  1445. sMsg.ProtocolType = s2c_msgshow;
  1446. sMsg.m_wMsgID = enumMSG_ID_TRADE_TASK_ITEM;
  1447. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  1448. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1449. return;
  1450. }
  1451. #endif
  1452. nEquipIdx1 = m_Room[room_trade].FindItem(SrcPos->nX, SrcPos->nY);
  1453. if (nEquipIdx1 < 0)
  1454. return;
  1455. // 先把东西拣起来
  1456. if (nEquipIdx1)
  1457. {
  1458. if (!m_Room[room_trade].PickUpItem(nEquipIdx1, SrcPos->nX, SrcPos->nY, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight()))
  1459. return;
  1460. }
  1461. // 如果鼠标上有东西,先试试能不能把他放下去,如果不行的话,还得把原来的东西放回去
  1462. if (m_Hand)
  1463. {
  1464. if (m_Room[room_trade].PlaceItem(DesPos->nX, DesPos->nY, m_Hand, Item[m_Hand].GetWidth(), Item[m_Hand].GetHeight()))
  1465. {
  1466. int nListIdx = FindSame(m_Hand);
  1467. m_Items[nListIdx].nPlace = pos_traderoom;
  1468. m_Items[nListIdx].nX = DesPos->nX;
  1469. m_Items[nListIdx].nY = DesPos->nY;
  1470. #ifdef _SERVER
  1471. // 发消息给交易对方
  1472. if (nEquipIdx1) // 交易栏有东西被捡起
  1473. {
  1474. ITEM_REMOVE_SYNC sRemove;
  1475. sRemove.ProtocolType = s2c_removeitem;
  1476. sRemove.m_ID = Item[nEquipIdx1].m_dwID;
  1477. g_pServer->PackDataToClient(Player[Player[m_PlayerIdx].m_cTrade.m_nTradeDest].m_nNetConnectIdx, (BYTE*)&sRemove, sizeof(ITEM_REMOVE_SYNC));
  1478. }
  1479. // 手上的东西放在了交易栏
  1480. ITEM_SYNC sItem;
  1481. sItem.ProtocolType = s2c_syncitem;
  1482. sItem.m_ID = Item[m_Hand].GetID();
  1483. sItem.m_Genre = Item[m_Hand].GetGenre();
  1484. sItem.m_Detail = Item[m_Hand].GetDetailType();
  1485. sItem.m_Particur = Item[m_Hand].GetParticular();
  1486. sItem.m_Series = Item[m_Hand].GetSeries();
  1487. sItem.m_Level = Item[m_Hand].GetLevel();
  1488. sItem.m_Luck = Item[m_Hand].m_GeneratorParam.nLuck;
  1489. sItem.m_btPlace = pos_trade1;
  1490. sItem.m_btX = DesPos->nX;
  1491. sItem.m_btY = DesPos->nY;
  1492. for (int j = 0; j < 6; j++)
  1493. sItem.m_MagicLevel[j] = (BYTE)Item[m_Hand].m_GeneratorParam.nGeneratorLevel[j];
  1494. sItem.m_RandomSeed = Item[m_Hand].m_GeneratorParam.uRandomSeed;
  1495. sItem.m_Version = Item[m_Hand].m_GeneratorParam.nVersion;
  1496. sItem.m_Durability = Item[m_Hand].GetDurability();
  1497. g_pServer->PackDataToClient(Player[Player[m_PlayerIdx].m_cTrade.m_nTradeDest].m_nNetConnectIdx, (BYTE*)&sItem, sizeof(ITEM_SYNC));
  1498. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1499. #endif
  1500. m_Hand = nEquipIdx1;
  1501. if (FindSame(nEquipIdx1))
  1502. m_Items[FindSame(nEquipIdx1)].nPlace = pos_hand;
  1503. }
  1504. // 把原来的东西放回去
  1505. else
  1506. {
  1507. m_Room[room_trade].PlaceItem(SrcPos->nX, SrcPos->nY, nEquipIdx1, Item[nEquipIdx1].GetWidth(), Item[nEquipIdx1].GetHeight());
  1508. }
  1509. }
  1510. // 如果鼠标上没有东西,只需要把拣起来的东西放到鼠标上
  1511. else
  1512. {
  1513. #ifdef _SERVER
  1514. // 发消息给交易对方
  1515. if (nEquipIdx1) // 交易栏有东西被捡起
  1516. {
  1517. ITEM_REMOVE_SYNC sRemove;
  1518. sRemove.ProtocolType = s2c_removeitem;
  1519. sRemove.m_ID = Item[nEquipIdx1].m_dwID;
  1520. g_pServer->PackDataToClient(Player[Player[m_PlayerIdx].m_cTrade.m_nTradeDest].m_nNetConnectIdx, (BYTE*)&sRemove, sizeof(ITEM_REMOVE_SYNC));
  1521. }
  1522. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(PLAYER_MOVE_ITEM_SYNC));
  1523. #endif
  1524. int nListIdx = FindSame(nEquipIdx1);
  1525. if (nEquipIdx1 && nListIdx)
  1526. {
  1527. m_Items[nListIdx].nPlace = pos_hand;
  1528. m_Hand = nEquipIdx1;
  1529. }
  1530. }
  1531. break;
  1532. }
  1533. #ifndef _SERVER
  1534. // Notify to Menu
  1535. if (m_Hand != nTempHand) // 交换成功了
  1536. {
  1537. //uParam = (KUiObjAtRegion*)pInfo -> 物品数据及其放置区域位置信息
  1538. //nParam = bAdd -> 0值表示减少这个物品,非0值表示增加这个物品
  1539. KUiObjAtContRegion pInfo1, pInfo2;
  1540. if (nTempHand == 0)
  1541. {
  1542. pInfo2.Obj.uGenre = CGOG_NOTHING;
  1543. pInfo2.Obj.uId = 0;
  1544. pInfo2.Region.Width = 0;
  1545. pInfo2.Region.Height = 0;
  1546. }
  1547. else
  1548. {
  1549. pInfo2.Obj.uGenre = CGOG_ITEM; //源装备
  1550. pInfo2.Obj.uId = nTempHand;
  1551. pInfo2.Region.Width = Item[nTempHand].GetWidth();
  1552. pInfo2.Region.Height = Item[nTempHand].GetHeight();
  1553. }
  1554. if (m_Hand == 0)
  1555. {
  1556. pInfo1.Obj.uGenre = CGOG_NOTHING;
  1557. pInfo1.Obj.uId = 0;
  1558. pInfo1.Region.Width = 0;
  1559. pInfo1.Region.Height = 0;
  1560. }
  1561. else
  1562. {
  1563. pInfo1.Obj.uGenre = CGOG_ITEM;
  1564. pInfo1.Obj.uId = m_Hand;
  1565. pInfo1.Region.Width = Item[m_Hand].GetWidth();
  1566. pInfo1.Region.Height = Item[m_Hand].GetHeight();
  1567. }
  1568. int PartConvert[itempart_num] = 
  1569. {
  1570. UIEP_HEAD,
  1571. UIEP_BODY,
  1572. UIEP_WAIST,
  1573. UIEP_HAND,
  1574. UIEP_FOOT,
  1575. UIEP_FINESSE,
  1576. UIEP_NECK,
  1577. UIEP_FINGER1,
  1578. UIEP_FINGER2,
  1579. UIEP_WAIST_DECOR,
  1580. UIEP_HORSE
  1581. };
  1582. switch(SrcPos->nPlace)
  1583. {
  1584. case pos_immediacy:
  1585. pInfo1.Region.h = SrcPos->nX;
  1586. pInfo1.Region.v = SrcPos->nY;
  1587. pInfo2.Region.h = DesPos->nX;
  1588. pInfo2.Region.v = DesPos->nY;
  1589. pInfo1.eContainer = UOC_IMMEDIA_ITEM;
  1590. pInfo2.eContainer = UOC_IMMEDIA_ITEM;
  1591. break;
  1592. case pos_equiproom:
  1593. pInfo1.Region.h = SrcPos->nX;
  1594. pInfo1.Region.v = SrcPos->nY;
  1595. pInfo2.Region.h = DesPos->nX;
  1596. pInfo2.Region.v = DesPos->nY;
  1597. pInfo1.eContainer = UOC_ITEM_TAKE_WITH;
  1598. pInfo2.eContainer = UOC_ITEM_TAKE_WITH;
  1599. break;
  1600. case pos_equip:
  1601. pInfo1.Region.h = 0;
  1602. pInfo1.Region.v = PartConvert[SrcPos->nX];
  1603. pInfo2.Region.h = 0;
  1604. pInfo2.Region.v = PartConvert[DesPos->nX];
  1605. pInfo1.eContainer = UOC_EQUIPTMENT;
  1606. pInfo2.eContainer = UOC_EQUIPTMENT;
  1607. break;
  1608. case pos_repositoryroom:
  1609. pInfo1.Region.h = SrcPos->nX;
  1610. pInfo1.Region.v = SrcPos->nY;
  1611. pInfo2.Region.h = DesPos->nX;
  1612. pInfo2.Region.v = DesPos->nY;
  1613. pInfo1.eContainer = UOC_STORE_BOX;
  1614. pInfo2.eContainer = UOC_STORE_BOX;
  1615. break;
  1616. case pos_traderoom:
  1617. pInfo1.Region.h = SrcPos->nX;
  1618. pInfo1.Region.v = SrcPos->nY;
  1619. pInfo2.Region.h = DesPos->nX;
  1620. pInfo2.Region.v = DesPos->nY;
  1621. pInfo1.eContainer = UOC_TO_BE_TRADE;
  1622. pInfo2.eContainer = UOC_TO_BE_TRADE;
  1623. break;
  1624. }
  1625. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&pInfo1, 0);
  1626. CoreDataChanged(GDCNI_HOLD_OBJECT, (DWORD)&pInfo2, 0);
  1627. CoreDataChanged(GDCNI_HOLD_OBJECT, (DWORD)&pInfo1, 1);
  1628. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&pInfo2, 1);
  1629. }
  1630. #endif
  1631. if (Npc[Player[m_PlayerIdx].m_nIndex].m_Doing == do_sit)
  1632. {
  1633. Npc[Player[m_PlayerIdx].m_nIndex].SendCommand(do_stand);
  1634. }
  1635. }
  1636. #ifndef _SERVER
  1637. //---------------------------------------------------------------------
  1638. // 功能:物品从一个地方直接移动到另一个地方,不经过鼠标这个中间过程
  1639. //---------------------------------------------------------------------
  1640. BOOL KItemList::AutoMoveItem(ItemPos SrcPos,ItemPos DesPos)
  1641. {
  1642. if (Player[this->m_PlayerIdx].CheckTrading()) // 如果正在交易
  1643. return FALSE;
  1644. BOOL bMove = FALSE;
  1645. int nIdx, nListIdx;
  1646. // 目前只支持从room_equipment到room_immediacy
  1647. switch (SrcPos.nPlace)
  1648. {
  1649. case pos_equiproom:
  1650. {
  1651. switch (DesPos.nPlace)
  1652. {
  1653. case pos_immediacy:
  1654. {
  1655. nIdx = m_Room[room_equipment].FindItem(SrcPos.nX, SrcPos.nY);
  1656. if (nIdx <= 0)
  1657. return FALSE;
  1658. if (Item[nIdx].GetGenre() != item_medicine)
  1659. {
  1660. _ASSERT(0);
  1661. return FALSE;
  1662. }
  1663. if (!m_Room[room_equipment].PickUpItem(nIdx, SrcPos.nX, SrcPos.nY, Item[nIdx].GetWidth(), Item[nIdx].GetHeight()))
  1664. return FALSE;
  1665. m_Room[room_immediacy].PlaceItem(DesPos.nX, DesPos.nY, nIdx, Item[nIdx].GetWidth(), Item[nIdx].GetHeight());
  1666. nListIdx = FindSame(nIdx);
  1667. if (nListIdx <= 0)
  1668. return FALSE;
  1669. m_Items[nListIdx].nPlace = pos_immediacy;
  1670. m_Items[nListIdx].nX = DesPos.nX;
  1671. m_Items[nListIdx].nY = DesPos.nY;
  1672. bMove = TRUE;
  1673. }
  1674. break;
  1675. }
  1676. }
  1677. break;
  1678. }
  1679. if (!bMove)
  1680. return bMove;
  1681. // 通知界面
  1682. KUiObjAtContRegion sSrcInfo, sDestInfo;
  1683. sSrcInfo.Obj.uGenre = CGOG_ITEM;
  1684. sSrcInfo.Obj.uId = nIdx;
  1685. sSrcInfo.Region.Width = Item[nIdx].GetWidth();
  1686. sSrcInfo.Region.Height = Item[nIdx].GetHeight();
  1687. sSrcInfo.Region.h = SrcPos.nX;
  1688. sSrcInfo.Region.v = SrcPos.nY;
  1689. sSrcInfo.eContainer = UOC_ITEM_TAKE_WITH;
  1690. sDestInfo.Obj.uGenre = CGOG_ITEM;
  1691. sDestInfo.Obj.uId = nIdx;
  1692. sDestInfo.Region.Width = Item[nIdx].GetWidth();
  1693. sDestInfo.Region.Height = Item[nIdx].GetHeight();
  1694. sDestInfo.Region.h = DesPos.nX;
  1695. sDestInfo.Region.v = DesPos.nY;
  1696. sDestInfo.eContainer = UOC_IMMEDIA_ITEM;
  1697. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&sSrcInfo, 0);
  1698. CoreDataChanged(GDCNI_OBJECT_CHANGED, (DWORD)&sDestInfo, 1);
  1699. return bMove;
  1700. }
  1701. #endif
  1702. #ifndef _SERVER
  1703. //---------------------------------------------------------------------
  1704. // 功能:物品从一个地方直接移动到另一个地方,不经过鼠标这个中间过程
  1705. //---------------------------------------------------------------------
  1706. void KItemList::MenuSetMouseItem()
  1707. {
  1708. KUiObjAtContRegion sInfo;
  1709. if (!m_Hand)
  1710. {
  1711. CoreDataChanged(GDCNI_HOLD_OBJECT, 0, 0);
  1712. }
  1713. else
  1714. {
  1715. sInfo.Obj.uGenre = CGOG_ITEM;
  1716. sInfo.Obj.uId = m_Hand;
  1717. sInfo.Region.Width = Item[m_Hand].GetWidth();
  1718. sInfo.Region.Height = Item[m_Hand].GetHeight();
  1719. sInfo.Region.h = 0;
  1720. sInfo.Region.v = 0;
  1721. sInfo.eContainer = UOC_IN_HAND;
  1722. CoreDataChanged(GDCNI_HOLD_OBJECT, (DWORD)&sInfo, 0);
  1723. }
  1724. }
  1725. #endif
  1726. #ifdef _SERVER
  1727. BOOL KItemList::EatMecidine(int nPlace, int nX, int nY)
  1728. {
  1729. int nItemIdx = 0;
  1730. switch(nPlace)
  1731. {
  1732. case pos_equiproom:
  1733. nItemIdx = m_Room[room_equipment].FindItem(nX, nY);
  1734. if (nItemIdx > 0)
  1735. return EatMecidine(nItemIdx);
  1736. break;
  1737. case pos_immediacy:
  1738. nItemIdx = m_Room[room_immediacy].FindItem(nX, nY);
  1739. if (nItemIdx > 0)
  1740. {
  1741. if (Item[nItemIdx].GetGenre() != item_medicine)
  1742. return EatMecidine(nItemIdx);
  1743. int nGenre, nDetailType, nIdx, nXpos, nYpos;
  1744. BOOL bEat;
  1745. nGenre = item_medicine;
  1746. nDetailType = Item[nItemIdx].GetDetailType();
  1747. bEat = EatMecidine(nItemIdx);
  1748. if (bEat == FALSE)
  1749. return bEat;
  1750. if (FALSE == FindSameDetailTypeInEquipment(nGenre, nDetailType, &nIdx, &nXpos, &nYpos))
  1751. return bEat;
  1752. this->AutoMoveMedicine(nIdx, nXpos, nYpos, nX, nY);
  1753. return bEat;
  1754. }
  1755. break;
  1756. default:
  1757. break;
  1758. }
  1759. return FALSE;
  1760. }
  1761. #endif
  1762. PlayerItem* KItemList::GetFirstItem()
  1763. {
  1764. m_nListCurIdx = m_UseIdx.GetNext(0);
  1765. return &m_Items[m_nListCurIdx];
  1766. }
  1767. PlayerItem* KItemList::GetNextItem()
  1768. {
  1769. if ( !m_nListCurIdx )
  1770. return NULL;
  1771. m_nListCurIdx = m_UseIdx.GetNext(m_nListCurIdx);
  1772. return &m_Items[m_nListCurIdx];
  1773. }
  1774. void KItemList::ClearRoom(int nRoom)
  1775. {
  1776. if (nRoom >= 0 && nRoom < room_num)
  1777. this->m_Room[nRoom].Clear();
  1778. }
  1779. void KItemList::BackupTrade()
  1780. {
  1781. if ( !m_Room[room_tradeback].m_pArray )
  1782. m_Room[room_tradeback].Init(m_Room[room_equipment].m_nWidth, m_Room[room_equipment].m_nHeight);
  1783. memcpy(m_Room[room_tradeback].m_pArray, m_Room[room_equipment].m_pArray, sizeof(int) * m_Room[room_tradeback].m_nWidth * m_Room[room_tradeback].m_nHeight);
  1784. memcpy(this->m_sBackItems, this->m_Items, sizeof(PlayerItem) * MAX_PLAYER_ITEM);
  1785. m_nBackHand = m_Hand;
  1786. }
  1787. void KItemList::RecoverTrade()
  1788. {
  1789. memcpy(m_Room[room_equipment].m_pArray, m_Room[room_tradeback].m_pArray, sizeof(int) * m_Room[room_tradeback].m_nWidth * m_Room[room_tradeback].m_nHeight);
  1790. #ifndef _SERVER
  1791. int nIdx = 0;
  1792. while((nIdx = m_UseIdx.GetNext(nIdx)))
  1793. {
  1794. if (m_Items[nIdx].nPlace == pos_trade1)
  1795. Remove(m_Items[nIdx].nIdx);
  1796. }
  1797. /* for (int i = 0; i < MAX_PLAYER_ITEM; i++)
  1798. {
  1799. if (m_Items[i].nIdx && m_Items[i].nPlace == pos_trade1)
  1800. Remove(m_Items[i].nIdx);
  1801. }*/
  1802. #endif
  1803. memcpy(m_Items, m_sBackItems, sizeof(PlayerItem) * MAX_PLAYER_ITEM);
  1804. m_Hand = m_nBackHand;
  1805. }
  1806. void KItemList::StartTrade()
  1807. {
  1808. BackupTrade();
  1809. ClearRoom(room_trade);
  1810. ClearRoom(room_trade1);
  1811. }
  1812. /*!*****************************************************************************
  1813. // Function : KItemList::RemoveAll
  1814. // Purpose : 退出时清除所有的装备
  1815. // Return : void
  1816. // Comments : 会实际地从游戏世界中的道具数组中去掉
  1817. // Author : Spe
  1818. *****************************************************************************/
  1819. void KItemList::RemoveAll()
  1820. {
  1821. int nIdx = m_UseIdx.GetNext(0);
  1822. int nIdx1 = 0;
  1823. while(nIdx)
  1824. {
  1825. nIdx1 = m_UseIdx.GetNext(nIdx);
  1826. int nGameIdx = m_Items[nIdx].nIdx;
  1827. Remove(m_Items[nIdx].nIdx);
  1828. #ifdef _SERVER
  1829. // 客户端在上面KItemList::Remove()已经做了ItemSet.Remove()
  1830. ItemSet.Remove(nGameIdx);
  1831. #endif
  1832. nIdx = nIdx1;
  1833. }
  1834. }
  1835. int KItemList::GetWeaponParticular()
  1836. {
  1837. if (m_EquipItem[itempart_weapon])
  1838. return Item[m_EquipItem[itempart_weapon]].GetParticular();
  1839. return -1;
  1840. }
  1841. #ifdef _SERVER
  1842. BOOL KItemList::IsTaskItemExist(int nDetailType)
  1843. {
  1844. int nIdx = 0;
  1845. while ((nIdx = m_UseIdx.GetNext(nIdx)))
  1846. {
  1847. int nGameIdx = m_Items[nIdx].nIdx;
  1848. if (item_task != Item[nGameIdx].GetGenre())
  1849. continue;
  1850. if (nDetailType == Item[nGameIdx].GetDetailType())
  1851. {
  1852. return TRUE;
  1853. }
  1854. }
  1855. return FALSE;
  1856. }
  1857. #endif
  1858. #ifdef _SERVER
  1859. int KItemList::GetTaskItemNum(int nDetailType)
  1860. {
  1861. int nNo = 0;
  1862. int nIdx = 0;
  1863. while ((nIdx = m_UseIdx.GetNext(nIdx)))
  1864. {
  1865. if (item_task != Item[m_Items[nIdx].nIdx].GetGenre())
  1866. continue;
  1867. if (nDetailType == Item[m_Items[nIdx].nIdx].GetDetailType())
  1868. nNo++;
  1869. }
  1870. return nNo;
  1871. }
  1872. #endif
  1873. #ifdef _SERVER
  1874. BOOL KItemList::RemoveTaskItem(int nDetailType)
  1875. {
  1876. int nIdx = 0;
  1877. while ((nIdx = m_UseIdx.GetNext(nIdx)))
  1878. {
  1879. int nGameIdx = m_Items[nIdx].nIdx;
  1880. if (item_task != Item[nGameIdx].GetGenre())
  1881. continue;
  1882. if (nDetailType == Item[nGameIdx].GetDetailType())
  1883. {
  1884. Remove(nGameIdx);
  1885. return TRUE;
  1886. }
  1887. }
  1888. return FALSE;
  1889. }
  1890. #endif
  1891. #ifdef _SERVER
  1892. //--------------------------------------------------------------------------
  1893. // 功能:交易中把 trade room 中的 item 的 idx width height 信息写入 itemset 中的 m_psItemInfo 中去
  1894. //--------------------------------------------------------------------------
  1895. void KItemList::GetTradeRoomItemInfo()
  1896. {
  1897. _ASSERT(ItemSet.m_psItemInfo);
  1898. // if (!ItemSet.m_psItemInfo)
  1899. // {
  1900. // ItemSet.m_psItemInfo = new TRADE_ITEM_INFO[TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT];
  1901. // }
  1902. memset(ItemSet.m_psItemInfo, 0, sizeof(TRADE_ITEM_INFO) * TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT);
  1903. int nItemIdx, nXpos, nYpos, nPos;
  1904. nItemIdx = 0;
  1905. nXpos = 0;
  1906. nYpos = 0;
  1907. nPos = 0;
  1908. while (1)
  1909. {
  1910. nItemIdx = m_Room[room_trade].GetNextItem(nItemIdx, nXpos, nYpos, &nXpos, &nYpos);
  1911. if (nItemIdx == 0)
  1912. break;
  1913. _ASSERT(nPos < TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT);
  1914. ItemSet.m_psItemInfo[nPos].m_nIdx = nItemIdx;
  1915. ItemSet.m_psItemInfo[nPos].m_nWidth = Item[nItemIdx].GetWidth();
  1916. ItemSet.m_psItemInfo[nPos].m_nHeight = Item[nItemIdx].GetHeight();
  1917. nPos++;
  1918. }
  1919. // 从大到小排序
  1920. TRADE_ITEM_INFO sTemp;
  1921. for (int i = nPos - 1; i >= 0; i--)
  1922. {
  1923. for (int j = 0; j < i; j++)
  1924. {
  1925. if (ItemSet.m_psItemInfo[j].m_nWidth * ItemSet.m_psItemInfo[j].m_nHeight < 
  1926. ItemSet.m_psItemInfo[j + 1].m_nWidth * ItemSet.m_psItemInfo[j + 1].m_nHeight)
  1927. {
  1928. sTemp = ItemSet.m_psItemInfo[j];
  1929. ItemSet.m_psItemInfo[j] = ItemSet.m_psItemInfo[j + 1];
  1930. ItemSet.m_psItemInfo[j + 1] = sTemp;
  1931. }
  1932. }
  1933. }
  1934. }
  1935. #endif
  1936. #ifdef _SERVER
  1937. //--------------------------------------------------------------------------
  1938. // 功能:交易中判断买进的物品能不能完全放进自己的物品栏
  1939. //--------------------------------------------------------------------------
  1940. BOOL KItemList::TradeCheckCanPlace()
  1941. {
  1942. LPINT pnTempRoom;
  1943. pnTempRoom = new int[EQUIPMENT_ROOM_WIDTH * EQUIPMENT_ROOM_HEIGHT];
  1944. memcpy(pnTempRoom, m_Room[room_equipment].m_pArray, sizeof(int) * EQUIPMENT_ROOM_WIDTH * EQUIPMENT_ROOM_HEIGHT);
  1945. int nPos, i, j, a, b, nFind, nNext;
  1946. for (nPos = 0; nPos < TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT; nPos++)
  1947. {
  1948. if (!ItemSet.m_psItemInfo[nPos].m_nIdx)
  1949. break;
  1950. nFind = 0;
  1951. for (i = 0; i < EQUIPMENT_ROOM_HEIGHT - ItemSet.m_psItemInfo[nPos].m_nHeight + 1; i++)
  1952. {
  1953. for (j = 0; j < EQUIPMENT_ROOM_WIDTH - ItemSet.m_psItemInfo[nPos].m_nWidth + 1; j++)
  1954. {
  1955. nNext = 0;
  1956. for (a = 0; a < ItemSet.m_psItemInfo[nPos].m_nHeight; a++)
  1957. {
  1958. for (b = 0; b < ItemSet.m_psItemInfo[nPos].m_nWidth; b++)
  1959. {
  1960. if (pnTempRoom[(i + a) * EQUIPMENT_ROOM_WIDTH + j + b])
  1961. {
  1962. nNext = 1;
  1963. break;
  1964. }
  1965. }
  1966. if (nNext)
  1967. break;
  1968. }
  1969. // 找到一个位置
  1970. if (!nNext)
  1971. {
  1972. // 数据处理
  1973. ItemSet.m_psItemInfo[nPos].m_nX = j;
  1974. ItemSet.m_psItemInfo[nPos].m_nY = i;
  1975. for (a = 0; a < ItemSet.m_psItemInfo[nPos].m_nHeight; a++)
  1976. {
  1977. for (b = 0; b < ItemSet.m_psItemInfo[nPos].m_nWidth; b++)
  1978. pnTempRoom[(i + a) * EQUIPMENT_ROOM_WIDTH + j + b] = ItemSet.m_psItemInfo[nPos].m_nIdx;
  1979. }
  1980. nFind = 1;
  1981. break;
  1982. }
  1983. }
  1984. if (nFind)
  1985. break;
  1986. }
  1987. if (!nFind)
  1988. {
  1989. delete []pnTempRoom;
  1990. return FALSE;
  1991. }
  1992. }
  1993. delete []pnTempRoom;
  1994. return TRUE;
  1995. }
  1996. #endif
  1997. #ifdef _SERVER
  1998. //--------------------------------------------------------------------------
  1999. // 功能:判断一定长宽的物品能否放进物品栏 (为了服务器效率,本函数里面没有调用其他函数)
  2000. //--------------------------------------------------------------------------
  2001. BOOL KItemList::CheckCanPlaceInEquipment(int nWidth, int nHeight, int *pnX, int *pnY)
  2002. {
  2003. if (nWidth <= 0 || nHeight <= 0 || !pnX || !pnY)
  2004. return FALSE;
  2005. _ASSERT(m_Room[room_equipment].m_pArray);
  2006. LPINT pnTempRoom;
  2007. int i, j, a, b, nNext;
  2008. pnTempRoom = m_Room[room_equipment].m_pArray;
  2009. for (i = 0; i < EQUIPMENT_ROOM_HEIGHT - nHeight + 1; i++)
  2010. {
  2011. for (j = 0; j < EQUIPMENT_ROOM_WIDTH - nWidth + 1; j++)
  2012. {
  2013. nNext = 0;
  2014. for (a = 0; a < nHeight; a++)
  2015. {
  2016. for (b = 0; b < nWidth; b++)
  2017. {
  2018. if (pnTempRoom[(i + a) * EQUIPMENT_ROOM_WIDTH + j + b])
  2019. {
  2020. nNext = 1;
  2021. break;
  2022. }
  2023. }
  2024. if (nNext)
  2025. break;
  2026. }
  2027. if (!nNext)
  2028. {
  2029. *pnX = j;
  2030. *pnY = i;
  2031. return TRUE;
  2032. }
  2033. }
  2034. }
  2035. return FALSE;
  2036. }
  2037. #endif
  2038. //------------------------------------------------------------------------------
  2039. // 功能:在room_equipment中查找指定Genre和DetailType的物品,得到ItemIdx和位置
  2040. //------------------------------------------------------------------------------
  2041. BOOL KItemList::FindSameDetailTypeInEquipment(int nGenre, int nDetail, int *pnIdx, int *pnX, int *pnY)
  2042. {
  2043. return m_Room[room_equipment].FindSameDetailType(nGenre, nDetail, pnIdx, pnX, pnY);
  2044. }
  2045. #ifdef _SERVER
  2046. //------------------------------------------------------------------------------
  2047. // 功能:自动把一个药品从room_equipment移动到room_immediacy
  2048. //------------------------------------------------------------------------------
  2049. BOOL KItemList::AutoMoveMedicine(int nItemIdx, int nSrcX, int nSrcY, int nDestX, int nDestY)
  2050. {
  2051. if (!m_Room[room_equipment].m_pArray || !m_Room[room_immediacy].m_pArray)
  2052. return FALSE;
  2053. if (nSrcX < 0 || nSrcX >= m_Room[room_equipment].m_nWidth || nSrcY < 0 || nSrcY >= m_Room[room_equipment].m_nHeight)
  2054. return FALSE;
  2055. if (nDestX < 0 || nDestX >= m_Room[room_immediacy].m_nWidth || nDestY < 0 || nDestY >= m_Room[room_immediacy].m_nHeight)
  2056. return FALSE;
  2057. if (nItemIdx != m_Room[room_equipment].m_pArray[nSrcY * m_Room[room_equipment].m_nWidth + nSrcX] ||
  2058. 0 != m_Room[room_immediacy].m_pArray[nDestY * m_Room[room_immediacy].m_nWidth + nDestX])
  2059. return FALSE;
  2060. _ASSERT(Item[nItemIdx].GetWidth() == 1 && Item[nItemIdx].GetHeight() == 1);
  2061. if (!m_Room[room_equipment].PickUpItem(nItemIdx, nSrcX, nSrcY, Item[nItemIdx].GetWidth(), Item[nItemIdx].GetHeight()))
  2062. return FALSE;
  2063. if (!m_Room[room_immediacy].PlaceItem(nDestX, nDestY, nItemIdx, Item[nItemIdx].GetWidth(), Item[nItemIdx].GetHeight()))
  2064. {
  2065. m_Room[room_equipment].PlaceItem(nSrcX, nSrcY, nItemIdx, Item[nItemIdx].GetWidth(), Item[nItemIdx].GetHeight());
  2066. return FALSE;
  2067. }
  2068. int nListIdx = FindSame(nItemIdx);
  2069. _ASSERT(nListIdx > 0);
  2070. m_Items[nListIdx].nPlace = pos_immediacy;
  2071. m_Items[nListIdx].nX = nDestX;
  2072. m_Items[nListIdx].nY = nDestY;
  2073. ITEM_AUTO_MOVE_SYNC sMove;
  2074. sMove.ProtocolType = s2c_ItemAutoMove;
  2075. sMove.m_btSrcPos = pos_equiproom;
  2076. sMove.m_btSrcX = nSrcX;
  2077. sMove.m_btSrcY = nSrcY;
  2078. sMove.m_btDestPos = pos_immediacy;
  2079. sMove.m_btDestX = nDestX;
  2080. sMove.m_btDestY = nDestY;
  2081. if (g_pServer)
  2082. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, (BYTE*)&sMove, sizeof(ITEM_AUTO_MOVE_SYNC));
  2083. return TRUE;
  2084. }
  2085. #endif
  2086. #ifndef _SERVER
  2087. void KItemList::RemoveAllInOneRoom(int nRoom)
  2088. {
  2089. if (nRoom < 0 || nRoom >= room_num)
  2090. return;
  2091. int nItemIdx, nXpos, nYpos, nPos;
  2092. nItemIdx = 0;
  2093. nXpos = 0;
  2094. nYpos = 0;
  2095. nPos = 0;
  2096. while (1)
  2097. {
  2098. nItemIdx = m_Room[nRoom].GetNextItem(nItemIdx, nXpos, nYpos, &nXpos, &nYpos);
  2099. if (nItemIdx == 0)
  2100. break;
  2101. _ASSERT(nPos < m_Room[nRoom].m_nWidth * m_Room[nRoom].m_nHeight);
  2102. Remove(nItemIdx);
  2103. nPos++;
  2104. }
  2105. }
  2106. #endif
  2107. #ifndef _SERVER
  2108. void KItemList::LockOperation()
  2109. {
  2110. if (IsLockOperation())
  2111. {
  2112. _ASSERT(0);
  2113. return;
  2114. }
  2115. m_bLockOperation = TRUE;
  2116. }
  2117. #endif
  2118. #ifndef _SERVER
  2119. void KItemList::UnlockOperation()
  2120. {
  2121. if (!IsLockOperation())
  2122. {
  2123. return;
  2124. }
  2125. m_bLockOperation = FALSE;
  2126. }
  2127. #endif
  2128. int KItemList::GetActiveAttribNum(int nIdx)
  2129. {
  2130. for (int i = 0; i < itempart_num; i++)
  2131. {
  2132. if (nIdx == m_EquipItem[i])
  2133. {
  2134. return GetEquipEnhance(i);
  2135. }
  2136. }
  2137. return 0;
  2138. }
  2139. #ifdef _SERVER
  2140. //-------------------------------------------------------------------------------
  2141. // 功能:丢失随身物品
  2142. //-------------------------------------------------------------------------------
  2143. void KItemList::AutoLoseItemFromEquipmentRoom(int nRate)
  2144. {
  2145. if (Player[m_PlayerIdx].CheckTrading())
  2146. return;
  2147. if (nRate <= 0 || nRate > 100)
  2148. return;
  2149. int nItemIdx, nXpos, nYpos, nPos;
  2150. nItemIdx = 0;
  2151. nXpos = 0;
  2152. nYpos = 0;
  2153. nPos = 0;
  2154. // 先统计所有物品,排除任务物品
  2155. while (1)
  2156. {
  2157. nItemIdx = m_Room[room_equipment].GetNextItem(nItemIdx, nXpos, nYpos, &nXpos, &nYpos);
  2158. if (nItemIdx == 0)
  2159. break;
  2160. if (item_task == Item[nItemIdx].GetGenre())
  2161. continue;
  2162. ItemSet.m_sLoseItemFromEquipmentRoom[nPos].nIdx = nItemIdx;
  2163. ItemSet.m_sLoseItemFromEquipmentRoom[nPos].nPlace = pos_equiproom;
  2164. ItemSet.m_sLoseItemFromEquipmentRoom[nPos].nX = nXpos;
  2165. ItemSet.m_sLoseItemFromEquipmentRoom[nPos].nY = nYpos;
  2166. nPos++;
  2167. }
  2168. if (nPos == 0)
  2169. return;
  2170. KMapPos sMapPos;
  2171. int nSelect;
  2172. int nObj;
  2173. KObjItemInfo sInfo;
  2174. for (int i = 0; i < nPos; i++)
  2175. {
  2176. if (g_Random(100) >= nRate)
  2177. continue;
  2178. nItemIdx = ItemSet.m_sLoseItemFromEquipmentRoom[i].nIdx;
  2179. Player[m_PlayerIdx].GetAboutPos(&sMapPos);
  2180. // 丢弃
  2181. if (Remove(nItemIdx))
  2182. {
  2183. sInfo.m_nItemID = nItemIdx;
  2184. sInfo.m_nItemWidth = Item[nItemIdx].GetWidth();
  2185. sInfo.m_nItemHeight = Item[nItemIdx].GetHeight();
  2186. sInfo.m_nMoneyNum = 0;
  2187. strcpy(sInfo.m_szName, Item[nItemIdx].m_CommonAttrib.szItemName);
  2188. sInfo.m_nColorID = 0;
  2189. sInfo.m_nMovieFlag = 1;
  2190. sInfo.m_nSoundFlag = 1;
  2191. nObj = ObjSet.Add(Item[nItemIdx].GetObjIdx(), sMapPos, sInfo);
  2192. if (nObj >= 0)
  2193. {
  2194. Object[nObj].SetItemBelong(-1);
  2195. }
  2196. SHOW_MSG_SYNC sMsg;
  2197. sMsg.ProtocolType = s2c_msgshow;
  2198. sMsg.m_wMsgID = enumMSG_ID_DEATH_LOSE_ITEM;
  2199. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID) + sizeof(sInfo.m_szName);
  2200. sMsg.m_lpBuf = new BYTE[sMsg.m_wLength + 1];
  2201. memcpy(sMsg.m_lpBuf, &sMsg, sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID));
  2202. memcpy((char*)sMsg.m_lpBuf + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), sInfo.m_szName, sizeof(sInfo.m_szName));
  2203. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
  2204. }
  2205. }
  2206. }
  2207. #endif
  2208. #ifdef _SERVER
  2209. //-------------------------------------------------------------------------------
  2210. // 功能:丢失一个穿在身上的装备(马不会掉)
  2211. //-------------------------------------------------------------------------------
  2212. void KItemList::AutoLoseEquip()
  2213. {
  2214. #ifndef defEQUIP_POWER
  2215. int i, nPos = 0;
  2216. for (i = 0; i < itempart_num; i++)
  2217. {
  2218. if (m_EquipItem[i] <= 0)
  2219. continue;
  2220. if (i == itempart_horse)
  2221. continue;
  2222. ItemSet.m_sLoseEquipItem[nPos].nIdx = m_EquipItem[i];
  2223. ItemSet.m_sLoseEquipItem[nPos].nPlace = nPos;
  2224. nPos++;
  2225. }
  2226. if (nPos == 0)
  2227. return;
  2228. int nSelect = g_Random(nPos);
  2229. #endif
  2230. #ifdef defEQUIP_POWER
  2231. int i, nPos = 0, nTotalPower = 0;
  2232. for (i = 0; i < itempart_num; i++)
  2233. {
  2234. if (m_EquipItem[i] <= 0)
  2235. continue;
  2236. nTotalPower += g_nEquipPower[i];
  2237. ItemSet.m_sLoseEquipItem[nPos].nIdx = m_EquipItem[i];
  2238. ItemSet.m_sLoseEquipItem[nPos].nPlace = nPos;
  2239. ItemSet.m_sLoseEquipItem[nPos].nX = nTotalPower; // nX 借用一下
  2240. nPos++;
  2241. }
  2242. if (nTotalPower == 0)
  2243. return;
  2244. int nSelect = g_Random(nTotalPower);
  2245. for (i = 0; i < nPos; i++)
  2246. {
  2247. if (ItemSet.m_sLoseEquipItem[i].nX > nSelect)
  2248. {
  2249. nSelect = i;
  2250. break;
  2251. }
  2252. }
  2253. if (i >= nPos)
  2254. return;
  2255. #endif
  2256. int  nItemIdx;
  2257. KMapPos sMapPos;
  2258. nItemIdx = ItemSet.m_sLoseEquipItem[nSelect].nIdx;
  2259. Player[m_PlayerIdx].GetAboutPos(&sMapPos);
  2260. if (Remove(nItemIdx))
  2261. {
  2262. int nObj;
  2263. KObjItemInfo sInfo;
  2264. sInfo.m_nItemID = nItemIdx;
  2265. sInfo.m_nItemWidth = Item[nItemIdx].GetWidth();
  2266. sInfo.m_nItemHeight = Item[nItemIdx].GetHeight();
  2267. sInfo.m_nMoneyNum = 0;
  2268. strcpy(sInfo.m_szName, Item[nItemIdx].m_CommonAttrib.szItemName);
  2269. sInfo.m_nColorID = 0;
  2270. sInfo.m_nMovieFlag = 1;
  2271. sInfo.m_nSoundFlag = 1;
  2272. nObj = ObjSet.Add(Item[nItemIdx].GetObjIdx(), sMapPos, sInfo);
  2273. if (nObj >= 0)
  2274. {
  2275. Object[nObj].SetItemBelong(-1);
  2276. }
  2277. SHOW_MSG_SYNC sMsg;
  2278. sMsg.ProtocolType = s2c_msgshow;
  2279. sMsg.m_wMsgID = enumMSG_ID_DEATH_LOSE_ITEM;
  2280. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID) + sizeof(sInfo.m_szName);
  2281. sMsg.m_lpBuf = new BYTE[sMsg.m_wLength + 1];
  2282. memcpy(sMsg.m_lpBuf, &sMsg, sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID));
  2283. memcpy((char*)sMsg.m_lpBuf + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), sInfo.m_szName, sizeof(sInfo.m_szName));
  2284. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
  2285. }
  2286. }
  2287. #endif
  2288. #ifndef _SERVER
  2289. //-------------------------------------------------------------------------------
  2290. // 功能:
  2291. //-------------------------------------------------------------------------------
  2292. int KItemList::GetSameDetailItemNum(int nImmediatePos)
  2293. {
  2294. if (nImmediatePos < 0 || nImmediatePos >= IMMEDIACY_ROOM_WIDTH * IMMEDIACY_ROOM_HEIGHT)
  2295. return 0;
  2296. int nIdx = m_Room[room_immediacy].FindItem(nImmediatePos, 0);
  2297. if (nIdx <= 0)
  2298. return 0;
  2299. return m_Room[room_equipment].CalcSameDetailType(Item[nIdx].GetGenre(), Item[nIdx].GetDetailType()) + 1;
  2300. }
  2301. #endif
  2302. #ifdef _SERVER
  2303. void KItemList::Abrade(int nType)
  2304. {
  2305. int nItemIdx = 0;
  2306. for (int i = 0; i < itempart_num; i++)
  2307. {
  2308. nItemIdx = m_EquipItem[i];
  2309. if (nItemIdx)
  2310. {
  2311. int nOldDur = Item[nItemIdx].GetDurability();
  2312. int nDur = Item[nItemIdx].Abrade(ItemSet.GetAbradeRange(nType, i));
  2313. if (nDur == 0)
  2314. {
  2315. // 给客户端发消息
  2316. SHOW_MSG_SYNC sMsg;
  2317. sMsg.ProtocolType = s2c_msgshow;
  2318. sMsg.m_wMsgID = enumMSG_ID_ITEM_DAMAGED;
  2319. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  2320. sMsg.m_lpBuf = (void *)Item[nItemIdx].m_dwID;
  2321. if (g_pServer)
  2322. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  2323. sMsg.m_lpBuf = 0;
  2324. Remove(nItemIdx);
  2325. ItemSet.Remove(nItemIdx);
  2326. }
  2327. else if (nOldDur != nDur && nDur != -1)
  2328. {
  2329. ITEM_DURABILITY_CHANGE sIDC;
  2330. sIDC.ProtocolType = s2c_itemdurabilitychange;
  2331. sIDC.dwItemID = Item[nItemIdx].GetID();
  2332. sIDC.nChange = nDur - nOldDur;
  2333. if (g_pServer)
  2334. g_pServer->PackDataToClient(Player[m_PlayerIdx].m_nNetConnectIdx, &sIDC, sizeof(ITEM_DURABILITY_CHANGE));
  2335. }
  2336. }
  2337. }
  2338. }
  2339. #endif