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

模拟服务器

开发平台:

C/C++

  1. #include "KCore.h"
  2. #include "KItem.h"
  3. #include "KItemGenerator.h"
  4. #include "KItemSet.h"
  5. //#include "MyAssert.h"
  6. KItemSet ItemSet;
  7. /*!*****************************************************************************
  8. // Function : KItemSet::KItemSet
  9. // Purpose : 
  10. // Return : 
  11. // Comments :
  12. // Author : Spe
  13. *****************************************************************************/
  14. KItemSet::KItemSet()
  15. {
  16. m_dwIDCreator = 100;
  17. ZeroMemory(&m_sRepairParam, sizeof(REPAIR_ITEM_PARAM));
  18. #ifdef _SERVER
  19. m_psItemInfo = NULL;
  20. m_psBackItemInfo = NULL;
  21. #endif
  22. }
  23. KItemSet::~KItemSet()
  24. {
  25. #ifdef _SERVER
  26. if (m_psItemInfo)
  27. delete [] m_psItemInfo;
  28. m_psItemInfo = NULL;
  29. if (m_psBackItemInfo)
  30. delete [] m_psBackItemInfo;
  31. m_psBackItemInfo = NULL;
  32. #endif
  33. }
  34. /*!*****************************************************************************
  35. // Function : KItemSet::Init
  36. // Purpose : 
  37. // Return : void 
  38. // Comments :
  39. // Author : Spe
  40. *****************************************************************************/
  41. void KItemSet::Init()
  42. {
  43. m_FreeIdx.Init(MAX_ITEM);
  44. m_UseIdx.Init(MAX_ITEM);
  45. for (int i = MAX_ITEM - 1; i > 0; i--)
  46. {
  47. m_FreeIdx.Insert(i);
  48. }
  49. #ifdef _SERVER
  50. if (m_psItemInfo)
  51. delete [] m_psItemInfo;
  52. m_psItemInfo = NULL;
  53. m_psItemInfo = new TRADE_ITEM_INFO[TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT];
  54. memset(this->m_psItemInfo, 0, sizeof(TRADE_ITEM_INFO) * TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT);
  55. if (m_psBackItemInfo)
  56. delete [] m_psBackItemInfo;
  57. m_psBackItemInfo = NULL;
  58. m_psBackItemInfo = new TRADE_ITEM_INFO[TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT];
  59. memset(this->m_psBackItemInfo, 0, sizeof(TRADE_ITEM_INFO) * TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT);
  60. #endif
  61. KIniFile IniFile;
  62. IniFile.Load(ITEM_ABRADE_FILE);
  63. // 维修价格
  64. IniFile.GetInteger("Repair", "ItemPriceScale", 100, &m_sRepairParam.nPriceScale);
  65. IniFile.GetInteger("Repair", "MagicPriceScale", 10, &m_sRepairParam.nMagicScale);
  66. // 攻击磨损
  67. IniFile.GetInteger("Attack", "Weapon", 256, &m_nItemAbradeRate[enumAbradeAttack][itempart_weapon]);
  68. IniFile.GetInteger("Attack", "Head", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_head]);
  69. IniFile.GetInteger("Attack", "Body", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_body]);
  70. IniFile.GetInteger("Attack", "Belt", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_belt]);
  71. IniFile.GetInteger("Attack", "Foot", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_foot]);
  72. IniFile.GetInteger("Attack", "Cuff", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_cuff]);
  73. IniFile.GetInteger("Attack", "Amulet", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_amulet]);
  74. IniFile.GetInteger("Attack", "Ring1", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_ring1]);
  75. IniFile.GetInteger("Attack", "Ring2", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_ring2]);
  76. IniFile.GetInteger("Attack", "Pendant", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_pendant]);
  77. IniFile.GetInteger("Attack", "Horse", 0, &m_nItemAbradeRate[enumAbradeAttack][itempart_horse]);
  78. // 防御磨损
  79. IniFile.GetInteger("Defend", "Weapon", 0, &m_nItemAbradeRate[enumAbradeDefend][itempart_weapon]);
  80. IniFile.GetInteger("Defend", "Head", 64, &m_nItemAbradeRate[enumAbradeDefend][itempart_head]);
  81. IniFile.GetInteger("Defend", "Body", 64, &m_nItemAbradeRate[enumAbradeDefend][itempart_body]);
  82. IniFile.GetInteger("Defend", "Belt", 64, &m_nItemAbradeRate[enumAbradeDefend][itempart_belt]);
  83. IniFile.GetInteger("Defend", "Foot", 64, &m_nItemAbradeRate[enumAbradeDefend][itempart_foot]);
  84. IniFile.GetInteger("Defend", "Cuff", 64, &m_nItemAbradeRate[enumAbradeDefend][itempart_cuff]);
  85. IniFile.GetInteger("Defend", "Amulet", 0, &m_nItemAbradeRate[enumAbradeDefend][itempart_amulet]);
  86. IniFile.GetInteger("Defend", "Ring1", 0, &m_nItemAbradeRate[enumAbradeDefend][itempart_ring1]);
  87. IniFile.GetInteger("Defend", "Ring2", 0, &m_nItemAbradeRate[enumAbradeDefend][itempart_ring2]);
  88. IniFile.GetInteger("Defend", "Pendant", 0, &m_nItemAbradeRate[enumAbradeDefend][itempart_pendant]);
  89. IniFile.GetInteger("Defend", "Horse", 0, &m_nItemAbradeRate[enumAbradeDefend][itempart_horse]);
  90. // 移动磨损
  91. IniFile.GetInteger("Move", "Weapon", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_weapon]);
  92. IniFile.GetInteger("Move", "Head", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_head]);
  93. IniFile.GetInteger("Move", "Body", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_body]);
  94. IniFile.GetInteger("Move", "Belt", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_belt]);
  95. IniFile.GetInteger("Move", "Foot", 64, &m_nItemAbradeRate[enumAbradeMove][itempart_foot]);
  96. IniFile.GetInteger("Move", "Cuff", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_cuff]);
  97. IniFile.GetInteger("Move", "Amulet", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_amulet]);
  98. IniFile.GetInteger("Move", "Ring1", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_ring1]);
  99. IniFile.GetInteger("Move", "Ring2", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_ring2]);
  100. IniFile.GetInteger("Move", "Pendant", 0, &m_nItemAbradeRate[enumAbradeMove][itempart_pendant]);
  101. IniFile.GetInteger("Move", "Horse", 64, &m_nItemAbradeRate[enumAbradeMove][itempart_horse]);
  102. }
  103. /*!*****************************************************************************
  104. // Function : KItemSet::SearchID
  105. // Purpose : 
  106. // Return : int 
  107. // Argumant : DWORD dwID
  108. // Comments :
  109. // Author : Spe
  110. *****************************************************************************/
  111. int KItemSet::SearchID(DWORD dwID)
  112. {
  113. int nIdx = 0;
  114. while(1)
  115. {
  116. nIdx = m_UseIdx.GetNext(nIdx);
  117. if (!nIdx)
  118. break;
  119. if (Item[nIdx].GetID() == dwID)
  120. break;
  121. }
  122. return nIdx;
  123. }
  124. int KItemSet::Add(KItem* pItem)
  125. {
  126. KASSERT(NULL != pItem);
  127. int i = FindFree();
  128. if (!i)
  129. return 0;
  130. Item[i] = *pItem;
  131. #ifdef _SERVER
  132. SetID(i);
  133. #endif
  134. m_FreeIdx.Remove(i);
  135. m_UseIdx.Insert(i);
  136. return i;
  137. }
  138. /*!*****************************************************************************
  139. // Function : KItemSet::Add
  140. // Purpose : 
  141. // Return : int 数组编号
  142. // Argumant : int 道具类型(装备?药品?矿石?……)
  143. // Argumant : int 魔法等级(如对应于装备,就是一般装备,蓝色装备,亮金等……)
  144. // Argumant : int 五行属性
  145. // Argumant : int 等级
  146. // Argumant : int 幸运值
  147. // Comments :
  148. // Author : Spe
  149. *****************************************************************************/
  150. int KItemSet::Add(int nItemGenre, int nSeries, 
  151.   int nLevel, int nLuck, int nDetailType/*=-1*/, 
  152.   int nParticularType/*=-1*/, int* pnMagicLevel, int nVersion/*=0*/, UINT nRandomSeed)
  153. {
  154. int i = FindFree();
  155. if (i == 0)
  156. return 0;
  157. KItem* pItem = &Item[i];
  158. pItem->m_GeneratorParam.nVersion = nVersion;
  159. pItem->m_GeneratorParam.uRandomSeed = nRandomSeed;
  160. switch(nItemGenre)
  161. {
  162. case item_equip: // 装备类
  163. ItemGen.Gen_Equipment(nDetailType, nParticularType, nSeries, nLevel, pnMagicLevel, nLuck, nVersion, pItem);
  164. break;
  165. case item_medicine: // 药品类
  166. ItemGen.Gen_Medicine(nDetailType, nLevel, nVersion, pItem);
  167. break;
  168. case item_mine: // 矿石类
  169. break;
  170. case item_materials: // 药材类
  171. break;
  172. case item_task: // 默认是任务类
  173. ItemGen.Gen_Quest(nDetailType, pItem);
  174. break;
  175. case item_townportal:
  176. ItemGen.Gen_TownPortal(pItem);
  177. break;
  178. default:
  179. break;
  180. }
  181. #ifdef _SERVER
  182. SetID(i);
  183. #endif
  184. m_FreeIdx.Remove(i);
  185. m_UseIdx.Insert(i);
  186. return i;
  187. }
  188. /*!*****************************************************************************
  189. // Function : KItemSet::FindFree
  190. // Purpose : 
  191. // Return : int 
  192. // Comments :
  193. // Author : Spe
  194. *****************************************************************************/
  195. int KItemSet::FindFree()
  196. {
  197. return m_FreeIdx.GetNext(0);
  198. }
  199. void KItemSet::Remove(IN int nIdx)
  200. {
  201. Item[nIdx].Remove();
  202. m_UseIdx.Remove(nIdx);
  203. m_FreeIdx.Insert(nIdx);
  204. }
  205. void KItemSet::SetID(IN int nIdx)
  206. {
  207. Item[nIdx].SetID(m_dwIDCreator);
  208. m_dwIDCreator++;
  209. }
  210. #ifdef _SERVER
  211. //---------------------------------------------------------------------------
  212. // 功能:copy m_psItemInfo to m_psBackItemInfo
  213. //---------------------------------------------------------------------------
  214. void KItemSet::BackItemInfo()
  215. {
  216. _ASSERT(this->m_psItemInfo);
  217. _ASSERT(this->m_psBackItemInfo);
  218. if (!m_psItemInfo)
  219. return;
  220. if (!m_psBackItemInfo)
  221. m_psBackItemInfo = new TRADE_ITEM_INFO[TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT];
  222. memcpy(m_psBackItemInfo, this->m_psItemInfo, sizeof(TRADE_ITEM_INFO) * TRADE_ROOM_WIDTH * TRADE_ROOM_HEIGHT);
  223. }
  224. #endif
  225. int KItemSet::GetAbradeRange(IN int nType, IN int nPart)
  226. {
  227. if (nType < 0 || nType >= enumAbradeNum)
  228. return 0;
  229. if (nPart < 0 || nPart >= itempart_num)
  230. return 0;
  231. return m_nItemAbradeRate[nType][nPart];
  232. }