Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. bool CExchange::CheckSpace()
  2. {
  3. static CGrid s_grid1(5, INVENTORY_MAX_NUM / 5 / 2); // inven page 1
  4. static CGrid s_grid2(5, INVENTORY_MAX_NUM / 5 / 2); // inven page 2
  5. static CGrid s_grid3(5, INVENTORY_MAX_NUM / 5 / 2); // inven page 3
  6. static CGrid s_grid4(5, INVENTORY_MAX_NUM / 5 / 2); // inven page 4
  7.  
  8. s_grid1.Clear();
  9. s_grid2.Clear();
  10. s_grid3.Clear();
  11. s_grid4.Clear();
  12.  
  13.  
  14. LPCHARACTER victim = GetCompany()->GetOwner();
  15. LPITEM item;
  16.  
  17. int i;
  18. int INVENTORY_PAGE_SLOT_COUNT = INVENTORY_MAX_NUM/4;
  19. for (i = 0; i < INVENTORY_PAGE_SLOT_COUNT; ++i)
  20. {
  21. if (!(item = victim->GetInventoryItem(i)))
  22. continue;
  23. s_grid1.Put(i, 1, item->GetSize());
  24. }
  25. for (i = INVENTORY_PAGE_SLOT_COUNT; i < INVENTORY_PAGE_SLOT_COUNT*2; ++i)
  26. {
  27. if (!(item = victim->GetInventoryItem(i)))
  28. continue;
  29. s_grid2.Put(i - INVENTORY_PAGE_SLOT_COUNT, 1, item->GetSize());
  30. }
  31. for (i = INVENTORY_MAX_NUM*2; i < INVENTORY_MAX_NUM*3; ++i)
  32. {
  33. if (!(item = victim->GetInventoryItem(i)))
  34. continue;
  35. s_grid3.Put(i - INVENTORY_MAX_NUM*2, 1, item->GetSize());
  36. }
  37. for (i = INVENTORY_MAX_NUM*3; i < INVENTORY_MAX_NUM*4; ++i)
  38. {
  39. if (!(item = victim->GetInventoryItem(i)))
  40. continue;
  41. s_grid4.Put(i - INVENTORY_MAX_NUM*3, 1, item->GetSize());
  42. }
  43.  
  44. // ¾Æ... ¹º°¡ °³º´½A °°Ao¸¸... ¿eE¥¼® AIº¥A≫ ³e¸O AIº¥ º¸°i μu¶o ¸¸μc ³≫ A߸øAI´U ¤?¤?
  45. static std::vector <WORD> s_vDSGrid(DRAGON_SOUL_INVENTORY_MAX_NUM);
  46.  
  47. // AI´U ¿eE¥¼®A≫ ±³E?CIAo ¾EA≫ °¡´E¼ºAI Aⓒ¹C·I, ¿eE¥¼® AIº¥ º¹≫c´A ¿eE¥¼®AI AOA≫ ¶§ CIμμ·I CN´U.
  48. bool bDSInitialized = false;
  49.  
  50. for (i = 0; i < EXCHANGE_ITEM_MAX_NUM; ++i)
  51. {
  52. if (!(item = m_apItems))
  53. continue;
  54. #ifdef NEW_ADD_INVENTORY
  55. int empty_pos;
  56. if (item->IsDragonSoul())
  57. empty_pos = victim->GetEmptyDragonSoulInventory(item);
  58. else
  59. empty_pos = victim->GetEmptyInventory(item->GetSize());
  60.  
  61. if (empty_pos < 0)
  62. {
  63. return false;
  64. }
  65. #endif
  66. if (item->IsDragonSoul())
  67. {
  68. if (!victim->DragonSoul_IsQualified())
  69. {
  70. return false;
  71. }
  72.  
  73. if (!bDSInitialized)
  74. {
  75. bDSInitialized = true;
  76. victim->CopyDragonSoulItemGrid(s_vDSGrid);
  77. }
  78.  
  79. bool bExistEmptySpace = false;
  80. WORD wBasePos = DSManager::instance().GetBasePosition(item);
  81. if (wBasePos >= DRAGON_SOUL_INVENTORY_MAX_NUM)
  82. return false;
  83.  
  84. for (int i = 0; i < DRAGON_SOUL_BOX_SIZE; i++)
  85. {
  86. WORD wPos = wBasePos + i;
  87. if (0 == s_vDSGrid[wBasePos])
  88. {
  89. bool bEmpty = true;
  90. for (int j = 1; j < item->GetSize(); j++)
  91. {
  92. if (s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM])
  93. {
  94. bEmpty = false;
  95. break;
  96. }
  97. }
  98. if (bEmpty)
  99. {
  100. for (int j = 0; j < item->GetSize(); j++)
  101. {
  102. s_vDSGrid[wPos + j * DRAGON_SOUL_BOX_COLUMN_NUM] = wPos + 1;
  103. }
  104. bExistEmptySpace = true;
  105. break;
  106. }
  107. }
  108. if (bExistEmptySpace)
  109. break;
  110. }
  111. if (!bExistEmptySpace)
  112. return false;
  113. }
  114. else
  115. {
  116. int iPos = s_grid1.FindBlank(1, item->GetSize());
  117.  
  118. if (iPos >= 0)
  119. {
  120. s_grid1.Put(iPos, 1, item->GetSize());
  121. }
  122. else
  123. {
  124. iPos = s_grid2.FindBlank(1, item->GetSize());
  125.  
  126. if (iPos >= 0)
  127. {
  128. s_grid2.Put(iPos, 1, item->GetSize());
  129. }
  130. else
  131. {
  132. iPos = s_grid3.FindBlank(1, item->GetSize());
  133.  
  134. if (iPos >= 0)
  135. {
  136. s_grid3.Put(iPos, 1, item->GetSize());
  137. }
  138. else
  139. {
  140. iPos = s_grid4.FindBlank(1, item->GetSize());
  141.  
  142. if (iPos >= 0)
  143. {
  144. s_grid4.Put(iPos, 1, item->GetSize());
  145. }
  146. else
  147. {
  148. return false;
  149. }
  150. }
  151. }
  152. }
  153. }
  154. }
  155. return true;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement