Guest User

item_attr

a guest
Nov 28th, 2025
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.60 KB | None | 0 0
  1. unsigned int prob = number(1, total);
  2. int attr_idx = APPLY_NONE;
  3.  
  4. for (DWORD i = 0; i < avail.size(); ++i)
  5. {
  6. const TItemAttrTable & r = g_map_itemAttr[avail[i]];
  7.  
  8. if (prob <= r.dwProb)
  9. {
  10. attr_idx = avail[i];
  11. break;
  12. }
  13.  
  14. prob -= r.dwProb;
  15. }
  16.  
  17. if (!attr_idx)
  18. {
  19. sys_err("Cannot put item attribute %d %d", iAttributeSet, bLevel);
  20. return;
  21. }
  22.  
  23. const TItemAttrTable & r = g_map_itemAttr[attr_idx];
  24.  
  25. // 종류별 속성 레벨 최대값 제한
  26. if (bLevel > r.bMaxLevelBySet[iAttributeSet])
  27. bLevel = r.bMaxLevelBySet[iAttributeSet];
  28.  
  29. AddAttr(attr_idx, bLevel);
  30. }
  31.  
  32. void CItem::PutAttribute(const int * aiAttrPercentTable)
  33. {
  34. int iAttrLevelPercent = number(1, 100);
  35. int i;
  36.  
  37. for (i = 0; i < ITEM_ATTRIBUTE_MAX_LEVEL; ++i)
  38. {
  39. if (iAttrLevelPercent <= aiAttrPercentTable[i])
  40. break;
  41.  
  42. iAttrLevelPercent -= aiAttrPercentTable[i];
  43. }
  44.  
  45. PutAttributeWithLevel(i + 1);
  46. }
  47.  
  48. void CItem::ChangeAttribute(const int* aiChangeProb)
  49. {
  50. int iAttributeCount = GetAttributeCount();
  51.  
  52. ClearAttribute();
  53.  
  54. if (iAttributeCount == 0)
  55. return;
  56.  
  57. TItemTable const * pProto = GetProto();
  58.  
  59. if (pProto && pProto->sAddonType)
  60. {
  61. ApplyAddon(pProto->sAddonType);
  62. }
  63.  
  64. static const int tmpChangeProb[ITEM_ATTRIBUTE_MAX_LEVEL] =
  65. {
  66. 0, 10, 40, 35, 15,
  67. };
  68.  
  69. for (int i = GetAttributeCount(); i < iAttributeCount; ++i)
  70. {
  71. if (aiChangeProb == NULL)
  72. {
  73. PutAttribute(tmpChangeProb);
  74. }
  75. else
  76. {
  77. PutAttribute(aiChangeProb);
  78. }
  79. }
  80. }
  81.  
  82. void CItem::AddAttribute()
  83. {
  84. static const int aiItemAddAttributePercent[ITEM_ATTRIBUTE_MAX_LEVEL] =
  85. {
  86. 40, 50, 10, 0, 0
  87. };
  88.  
  89. if (GetAttributeCount() < MAX_NORM_ATTR_NUM)
  90. PutAttribute(aiItemAddAttributePercent);
  91. }
  92.  
  93. void CItem::ClearAttribute()
  94. {
  95. for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
  96. {
  97. m_aAttr[i].bType = 0;
  98. m_aAttr[i].sValue = 0;
  99. }
  100. }
  101.  
  102. int CItem::GetAttributeCount()
  103. {
  104. int i;
  105.  
  106. for (i = 0; i < MAX_NORM_ATTR_NUM; ++i)
  107. {
  108. if (GetAttributeType(i) == 0)
  109. break;
  110. }
  111.  
  112. return i;
  113. }
  114.  
  115. int CItem::FindAttribute(BYTE bType)
  116. {
  117. for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
  118. {
  119. if (GetAttributeType(i) == bType)
  120. return i;
  121. }
  122.  
  123. return -1;
  124. }
  125.  
  126. bool CItem::RemoveAttributeAt(int index)
  127. {
  128. if (GetAttributeCount() <= index)
  129. return false;
  130.  
  131. for (int i = index; i < MAX_NORM_ATTR_NUM - 1; ++i)
  132. {
  133. SetAttribute(i, GetAttributeType(i + 1), GetAttributeValue(i + 1));
  134. }
  135.  
  136. SetAttribute(MAX_NORM_ATTR_NUM - 1, APPLY_NONE, 0);
  137. return true;
  138. }
  139.  
  140. bool CItem::RemoveAttributeType(BYTE bType)
  141. {
  142. int index = FindAttribute(bType);
  143. return index != -1 && RemoveAttributeType(index);
  144. }
  145.  
  146. void CItem::SetAttributes(const TPlayerItemAttribute* c_pAttribute)
  147. {
  148. thecore_memcpy(m_aAttr, c_pAttribute, sizeof(m_aAttr));
  149. Save();
  150. }
  151.  
  152. void CItem::SetAttribute(int i, BYTE bType, short sValue)
  153. {
  154. assert(i < MAX_NORM_ATTR_NUM);
  155.  
  156. m_aAttr[i].bType = bType;
  157. m_aAttr[i].sValue = sValue;
  158. UpdatePacket();
  159. Save();
  160.  
  161. if (bType)
  162. {
  163. const char * pszIP = NULL;
  164.  
  165. if (GetOwner() && GetOwner()->GetDesc())
  166. pszIP = GetOwner()->GetDesc()->GetHostName();
  167.  
  168. LOG_LEVEL_CHECK(LOG_LEVEL_MAX, LogManager::instance().ItemLog(i, bType, sValue, GetID(), "SET_ATTR", "", pszIP ? pszIP : "", GetOriginalVnum()));
  169. }
  170. }
  171.  
  172. void CItem::SetForceAttribute(int i, BYTE bType, short sValue)
  173. {
  174. assert(i < ITEM_ATTRIBUTE_MAX_NUM);
  175.  
  176. m_aAttr[i].bType = bType;
  177. m_aAttr[i].sValue = sValue;
  178. UpdatePacket();
  179. Save();
  180.  
  181. if (bType)
  182. {
  183. const char * pszIP = NULL;
  184.  
  185. if (GetOwner() && GetOwner()->GetDesc())
  186. pszIP = GetOwner()->GetDesc()->GetHostName();
  187.  
  188. LOG_LEVEL_CHECK(LOG_LEVEL_MAX, LogManager::instance().ItemLog(i, bType, sValue, GetID(), "SET_FORCE_ATTR", "", pszIP ? pszIP : "", GetOriginalVnum()));
  189. }
  190. }
  191.  
  192.  
  193. void CItem::CopyAttributeTo(LPITEM pItem)
  194. {
  195. pItem->SetAttributes(m_aAttr);
  196. }
  197.  
  198. int CItem::GetRareAttrCount()
  199. {
  200. int ret = 0;
  201.  
  202. for (DWORD dwIdx = ITEM_ATTRIBUTE_RARE_START; dwIdx < ITEM_ATTRIBUTE_RARE_END; dwIdx++)
  203. {
  204. if (m_aAttr[dwIdx].bType != 0)
  205. ret++;
  206. }
  207.  
  208. return ret;
  209. }
  210.  
  211. bool CItem::ChangeRareAttribute()
  212. {
  213. if (GetRareAttrCount() == 0)
  214. return false;
  215.  
  216. int cnt = GetRareAttrCount();
  217.  
  218. for (int i = 0; i < cnt; ++i)
  219. {
  220. m_aAttr[i + ITEM_ATTRIBUTE_RARE_START].bType = 0;
  221. m_aAttr[i + ITEM_ATTRIBUTE_RARE_START].sValue = 0;
  222. }
  223.  
  224. if (GetOwner() && GetOwner()->GetDesc())
  225. LOG_LEVEL_CHECK(LOG_LEVEL_MAX, LogManager::instance().ItemLog(GetOwner(), this, "SET_RARE_CHANGE", ""))
  226. else
  227. LOG_LEVEL_CHECK(LOG_LEVEL_MAX, LogManager::instance().ItemLog(0, 0, 0, GetID(), "SET_RARE_CHANGE", "", "", GetOriginalVnum()))
  228.  
  229. for (int i = 0; i < cnt; ++i)
  230. {
  231. AddRareAttribute();
  232. }
  233.  
  234. return true;
  235. }
  236.  
  237. bool CItem::AddRareAttribute()
  238. {
  239. int count = GetRareAttrCount();
  240.  
  241. if (count >= ITEM_ATTRIBUTE_RARE_NUM)
  242. return false;
  243.  
  244. int pos = count + ITEM_ATTRIBUTE_RARE_START;
  245. TPlayerItemAttribute & attr = m_aAttr[pos];
  246.  
  247. int nAttrSet = GetAttributeSetIndex();
  248. std::vector<int> avail;
  249.  
  250. for (int i = 0; i < MAX_APPLY_NUM; ++i)
  251. {
  252. const TItemAttrTable & r = g_map_itemRare[i];
  253.  
  254. if (r.dwApplyIndex != 0 && r.bMaxLevelBySet[nAttrSet] > 0 && HasRareAttr(i) != true)
  255. {
  256. avail.push_back(i);
  257. }
  258. }
  259.  
  260. const TItemAttrTable& r = g_map_itemRare[avail[number(0, avail.size() - 1)]];
  261. int nAttrLevel = number(1, 5);
  262.  
  263. if (nAttrLevel > r.bMaxLevelBySet[nAttrSet])
  264. nAttrLevel = r.bMaxLevelBySet[nAttrSet];
  265.  
  266. attr.bType = r.dwApplyIndex;
  267. attr.sValue = r.lValues[nAttrLevel - 1];
  268.  
  269. UpdatePacket();
  270.  
  271. Save();
  272.  
  273. const char * pszIP = NULL;
  274.  
  275. if (GetOwner() && GetOwner()->GetDesc())
  276. pszIP = GetOwner()->GetDesc()->GetHostName();
  277.  
  278. LOG_LEVEL_CHECK(LOG_LEVEL_MAX, LogManager::instance().ItemLog(pos, attr.bType, attr.sValue, GetID(), "SET_RARE", "", pszIP ? pszIP : "", GetOriginalVnum()));
  279. return true;
  280. }
  281.  
  282. void CItem::AddRareAttribute2(const int * aiAttrPercentTable)
  283. {
  284. static const int aiItemAddAttributePercent[ITEM_ATTRIBUTE_MAX_LEVEL] =
  285. {
  286. 40, 50, 10, 0, 0
  287. };
  288. if (aiAttrPercentTable == NULL)
  289. aiAttrPercentTable = aiItemAddAttributePercent;
  290.  
  291. if (GetRareAttrCount() < MAX_RARE_ATTR_NUM)
  292. PutRareAttribute(aiAttrPercentTable);
  293. }
  294.  
  295. void CItem::PutRareAttribute(const int * aiAttrPercentTable)
  296. {
  297. int iAttrLevelPercent = number(1, 100);
  298. int i;
  299.  
  300. for (i = 0; i < ITEM_ATTRIBUTE_MAX_LEVEL; ++i)
  301. {
  302. if (iAttrLevelPercent <= aiAttrPercentTable[i])
  303. break;
  304.  
  305. iAttrLevelPercent -= aiAttrPercentTable[i];
  306. }
  307.  
  308. PutRareAttributeWithLevel(i + 1);
  309. }
  310.  
  311. void CItem::PutRareAttributeWithLevel(BYTE bLevel)
  312. {
  313. int iAttributeSet = GetAttributeSetIndex();
  314. if (iAttributeSet < 0)
  315. return;
  316.  
  317. if (bLevel > ITEM_ATTRIBUTE_MAX_LEVEL)
  318. return;
  319.  
  320. std::vector<int> avail;
  321.  
  322. int total = 0;
  323.  
  324. // 붙일 수 있는 속성 배열을 구축
  325. for (int i = 0; i < MAX_APPLY_NUM; ++i)
  326. {
  327. const TItemAttrTable & r = g_map_itemRare[i];
  328.  
  329. if (r.bMaxLevelBySet[iAttributeSet] && !HasRareAttr(i))
  330. {
  331. avail.push_back(i);
  332. total += r.dwProb;
  333. }
  334. }
  335.  
  336. // 구축된 배열로 확률 계산을 통해 붙일 속성 선정
  337. unsigned int prob = number(1, total);
  338. int attr_idx = APPLY_NONE;
  339.  
  340. for (DWORD i = 0; i < avail.size(); ++i)
  341. {
  342. const TItemAttrTable & r = g_map_itemRare[avail[i]];
  343.  
  344. if (prob <= r.dwProb)
  345. {
  346. attr_idx = avail[i];
  347. break;
  348. }
  349.  
  350. prob -= r.dwProb;
  351. }
  352.  
  353. if (!attr_idx)
  354. {
  355. sys_err("Cannot put item rare attribute %d %d", iAttributeSet, bLevel);
  356. return;
  357. }
  358.  
  359. const TItemAttrTable & r = g_map_itemRare[attr_idx];
  360.  
  361. // 종류별 속성 레벨 최대값 제한
  362. if (bLevel > r.bMaxLevelBySet[iAttributeSet])
  363. bLevel = r.bMaxLevelBySet[iAttributeSet];
  364.  
  365. AddRareAttr(attr_idx, bLevel);
  366. }
  367.  
  368. void CItem::AddRareAttr(BYTE bApply, BYTE bLevel)
  369. {
  370. if (HasRareAttr(bApply))
  371. return;
  372.  
  373. if (bLevel <= 0)
  374. return;
  375.  
  376. int i = ITEM_ATTRIBUTE_RARE_START + GetRareAttrCount();
  377.  
  378. if (i == ITEM_ATTRIBUTE_RARE_END)
  379. sys_err("item rare attribute overflow!");
  380. else
  381. {
  382. const TItemAttrTable & r = g_map_itemRare[bApply];
  383. long lVal = r.lValues[MIN(4, bLevel - 1)];
  384.  
  385. if (lVal)
  386. SetForceAttribute(i, bApply, lVal);
  387. }
  388. }
  389. #ifdef ENABLE_SWITCHBOT_WORLDARD
  390.  
  391. int CItem::ChangeAttributeSwtichBot(int count,const TPlayerItemAttribute* aAttr, bool* check_add)
  392. {
  393. static const int tmpChangeProb[ITEM_ATTRIBUTE_MAX_LEVEL] =
  394. {
  395. 0, 10, 40, 35, 15,
  396. };
  397.  
  398. int max_count = 0;
  399.  
  400. for (int a = 0; a < count; ++a)
  401. {
  402. int iAttributeCount = GetAttributeCount();
  403. ClearAttribute();
  404. if (iAttributeCount == 0)
  405. return 0;
  406.  
  407. TItemTable const * pProto = GetProto();
  408.  
  409. if (pProto && pProto->sAddonType)
  410. {
  411. ApplyAddon(pProto->sAddonType,true);
  412. }
  413.  
  414.  
  415. for (int b = GetAttributeCount(); b < iAttributeCount; ++b)
  416. {
  417. int iAttrLevelPercent = number(1, 100);
  418. int c;
  419.  
  420. for (c = 0; c < ITEM_ATTRIBUTE_MAX_LEVEL; ++c)
  421. {
  422. if (iAttrLevelPercent <= tmpChangeProb[c])
  423. break;
  424.  
  425. iAttrLevelPercent -= tmpChangeProb[c];
  426. }
  427.  
  428. int iAttributeSet = GetAttributeSetIndex();
  429.  
  430. if (iAttributeSet < 0)
  431. return 0;
  432.  
  433. BYTE bLevel = c + 1;
  434. if (bLevel > ITEM_ATTRIBUTE_MAX_LEVEL)
  435. return 0;
  436.  
  437. std::vector<int> avail;
  438.  
  439. int total = 0;
  440.  
  441. for (int d = 0; d < MAX_APPLY_NUM; ++d)
  442. {
  443. const TItemAttrTable & r = g_map_itemAttr[d];
  444.  
  445. if (r.bMaxLevelBySet[iAttributeSet] && !HasAttr(d))
  446. {
  447. avail.push_back(d);
  448. total += r.dwProb;
  449. }
  450. }
  451.  
  452. unsigned int prob = number(1, total);
  453. int attr_idx = APPLY_NONE;
  454.  
  455. for (DWORD e = 0; e < avail.size(); ++e)
  456. {
  457. const TItemAttrTable & r = g_map_itemAttr[avail[e]];
  458.  
  459. if (prob <= r.dwProb)
  460. {
  461. attr_idx = avail[e];
  462. break;
  463. }
  464.  
  465. prob -= r.dwProb;
  466. }
  467.  
  468. if (!attr_idx)
  469. {
  470. sys_err("Cannot put item attribute %d %d", iAttributeSet, bLevel);
  471. return 0;
  472. }
  473.  
  474. const TItemAttrTable & r = g_map_itemAttr[attr_idx];
  475.  
  476. if (bLevel > r.bMaxLevelBySet[iAttributeSet])
  477. bLevel = r.bMaxLevelBySet[iAttributeSet];
  478.  
  479. if (HasAttr(attr_idx))
  480. return 0;
  481.  
  482. if (bLevel <= 0)
  483. return 0;
  484.  
  485. int i = GetAttributeCount();
  486.  
  487. if (i == MAX_NORM_ATTR_NUM)
  488. sys_err("item attribute overflow!");
  489. else
  490. {
  491. const TItemAttrTable & r = g_map_itemAttr[attr_idx];
  492. long lVal = r.lValues[MIN(4, bLevel - 1)];
  493.  
  494. if (lVal)
  495. SetAttributeSwtichBot(i, attr_idx, lVal);
  496. }
  497. }
  498.  
  499. max_count++;
  500.  
  501. if (CheckBonusSwitchBot(aAttr))
  502. {
  503. *check_add = true;
  504. return max_count;
  505. }
  506. }
  507. *check_add = false;
  508. return max_count;
  509. }
  510.  
  511. int CItem::GetCountSelect(const TPlayerItemAttribute* aAttr)
  512. {
  513. int count = 0;
  514. for (int i = 0; i < MAX_NORM_ATTR_NUM; ++i)
  515. {
  516. if(aAttr[i].bType != 0)
  517. {
  518. count ++;
  519. }
  520. }
  521.  
  522. return count;
  523. }
  524.  
  525. bool CItem::CheckBonusSwitchBot(const TPlayerItemAttribute* aAttr)
  526. {
  527.  
  528. int iAttributeCount = GetAttributeCount();
  529.  
  530. int max_count_select = GetCountSelect(aAttr);
  531.  
  532. int count_total = 0;
  533.  
  534. for (int i = 0; i < iAttributeCount; ++i)
  535. {
  536. for (int a = 0; a < MAX_NORM_ATTR_NUM; ++a)
  537. {
  538. if(aAttr[a].bType != 0)
  539. {
  540. if(aAttr[a].bType == GetAttributeType(i) && GetAttributeValue(i) >= aAttr[a].sValue)
  541. {
  542. count_total ++;
  543. }
  544. }
  545. }
  546.  
  547. }
  548.  
  549. if (count_total == max_count_select){
  550. return true;
  551. }
  552.  
  553. return false;
  554.  
  555. }
  556.  
  557. void CItem::SetAttributeSwtichBot(int i, BYTE bType, short sValue)
  558. {
  559. assert(i < MAX_NORM_ATTR_NUM);
  560.  
  561. m_aAttr[i].bType = bType;
  562. m_aAttr[i].sValue = sValue;
  563. }
  564.  
  565.  
  566. void CItem::AddAttributeSwitchBot(BYTE bApply, short sValue)
  567. {
  568.  
  569. if (HasAttr(bApply))
  570. return;
  571.  
  572. int i = GetAttributeCount();
  573.  
  574. if (i >= MAX_NORM_ATTR_NUM)
  575. sys_err("item attribute overflow!");
  576. else
  577. {
  578. if (sValue)
  579. SetAttributeSwtichBot(i, bApply, sValue);
  580. }
  581. }
  582.  
  583. #endif
  584.  
  585.  
Tags: item_atttr
Advertisement
Add Comment
Please, Sign In to add comment