PlayerCreator.cpp
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 7k
Development Platform:

C/C++

  1. #include "stdafx.h"
  2. #include "PlayerCreator.h"
  3. #include "inifile.h"
  4. #include "utils.h"
  5. #include "tstring.h"
  6. #include "../../Core/src/GameDatadef.h"
  7. using OnlineGameLib::Win32::CIniFile;
  8. using OnlineGameLib::Win32::GetAppFullPath;
  9. using OnlineGameLib::Win32::_tstring;
  10. CPlayerCreator::CPlayerCreator()
  11. {
  12. for (int i = 0; i < MAX_PLAYERTYPE_VALUE; i++)
  13. {
  14. m_pRoleData[i] = NULL;
  15. }
  16. }
  17. CPlayerCreator::~CPlayerCreator()
  18. {
  19. for (int i = 0; i < MAX_PLAYERTYPE_VALUE; i++)
  20. {
  21. if (!m_pRoleData[i])
  22. {
  23. delete [] m_pRoleData[i];
  24. m_pRoleData[i] = NULL;
  25. }
  26. }
  27. }
  28. bool CPlayerCreator::Init()
  29. {
  30. CIniFile theIniFile;
  31. _tstring sIniFilePathName;
  32. sIniFilePathName = GetAppFullPath( NULL );
  33. char szFileName[32];
  34. for (int i = 0; i < MAX_PLAYERTYPE_VALUE; i++)
  35. {
  36. sprintf(szFileName, PLAYERCREATOR_FILE, i);
  37. _tstring sIniFileName = sIniFilePathName + szFileName;
  38. if (!m_pRoleData[i])
  39. m_pRoleData[i] = new BYTE[MAX_NEWPLAYER_BUFFER];
  40. ZeroMemory(m_pRoleData[i], MAX_NEWPLAYER_BUFFER * sizeof(BYTE));
  41. GetRoleDataFromIni(m_pRoleData[i], sIniFileName.c_str());
  42. }
  43. return false;
  44. }
  45. const TRoleData* CPlayerCreator::GetRoleData(unsigned int &uDataLength, LPROLEPARAM lpParam)
  46. {
  47. int nIndex = lpParam->nSeries * ROLE_NO + lpParam->nSex;
  48. if (nIndex < 0 || nIndex >= MAX_PLAYERTYPE_VALUE)
  49. {
  50. uDataLength = 0;
  51. return NULL;
  52. }
  53. if (m_pRoleData[nIndex])
  54. {
  55. const TRoleData* pData = (const TRoleData*)m_pRoleData[nIndex];
  56. uDataLength = pData->dwDataLen;
  57. return pData;
  58. }
  59. uDataLength = 0;
  60. return NULL;
  61. }
  62. bool CPlayerCreator::GetRoleDataFromIni(BYTE* pData, const char* szFileName)
  63. {
  64. CIniFile cFile;
  65. cFile.SetFile( szFileName );
  66. TRoleData* pRoleData = (TRoleData *)pData;
  67. pRoleData->bBaseNeedUpdate = 1;
  68. //玩家信息
  69. pRoleData->BaseInfo.ileftprop = cFile.ReadInteger("ROLE", "ileftprop", 0);
  70. pRoleData->BaseInfo.ileftfight = cFile.ReadInteger("ROLE", "ileftfight", 0);
  71. pRoleData->BaseInfo.ipower = cFile.ReadInteger("ROLE", "ipower", 0);
  72. pRoleData->BaseInfo.iagility = cFile.ReadInteger("ROLE", "iagility", 0);
  73. pRoleData->BaseInfo.iouter = cFile.ReadInteger("ROLE", "iouter", 0);
  74. pRoleData->BaseInfo.iinside = cFile.ReadInteger("ROLE", "iinside", 0);
  75. pRoleData->BaseInfo.iluck = cFile.ReadInteger("ROLE", "iluck", 0);
  76. //玩家的显示信息
  77. pRoleData->BaseInfo.ihelmres = cFile.ReadInteger("ROLE", "ihelmres", 0);
  78. pRoleData->BaseInfo.iarmorres = cFile.ReadInteger("ROLE", "iarmorres", 0);
  79. pRoleData->BaseInfo.iweaponres = cFile.ReadInteger("ROLE", "iweaponres", 0);
  80. //玩家等级信息
  81. pRoleData->BaseInfo.fightexp = cFile.ReadInteger("ROLE", "ifightexp", 0);
  82. pRoleData->BaseInfo.ifightlevel = cFile.ReadInteger("ROLE", "ifightlevel", 0);
  83. pRoleData->BaseInfo.ileadlevel = cFile.ReadInteger("ROLE", "ileadlevel", 0);
  84. pRoleData->BaseInfo.ileadexp = cFile.ReadInteger("ROLE", "ileadexp", 0);
  85. //门派信息
  86. pRoleData->BaseInfo.nSect = cFile.ReadInteger("ROLE", "isect", 0);
  87. pRoleData->BaseInfo.nFirstSect = cFile.ReadInteger("ROLE", "ifirstsect", 0);
  88. pRoleData->BaseInfo.ijoincount = cFile.ReadInteger("ROLE", "ijoincount", 0);
  89. //现金和贮物箱中的钱
  90. pRoleData->BaseInfo.imoney = cFile.ReadInteger("ROLE", "imoney", 0);
  91. pRoleData->BaseInfo.isavemoney = cFile.ReadInteger("ROLE", "isavemoney", 0);
  92. //
  93. pRoleData->BaseInfo.ifiveprop = cFile.ReadInteger("ROLE", "ifiveprop", 0);
  94. pRoleData->BaseInfo.iteam = cFile.ReadInteger("ROLE", "iteam", 0);
  95. pRoleData->BaseInfo.bSex = ( 0 != cFile.ReadInteger("ROLE", "bsex", 0) );
  96. pRoleData->BaseInfo.imaxlife = cFile.ReadInteger("ROLE", "imaxlife", 0);
  97. pRoleData->BaseInfo.imaxstamina = cFile.ReadInteger("ROLE", "imaxstamina", 0);
  98. pRoleData->BaseInfo.imaxinner = cFile.ReadInteger("ROLE", "imaxinner", 0);
  99. //登入点
  100. pRoleData->BaseInfo.irevivalid = cFile.ReadInteger("ROLE", "irevivalid", 0);
  101. pRoleData->BaseInfo.irevivalx = cFile.ReadInteger("ROLE", "irevivalx", 0);
  102. pRoleData->BaseInfo.irevivaly = cFile.ReadInteger("ROLE", "irevivaly", 0);
  103. pRoleData->dwFSkillOffset = (BYTE * )pRoleData->pBuffer - pData;
  104. //  Skill
  105. int nSkillCount = 0;
  106. char szSkillId[100];
  107. char szSkillLevel[100];
  108. nSkillCount = cFile.ReadInteger(SECTION_FIGHTSKILLLIST, KEY_COUNT, 0);
  109. TDBSkillData *pSkillData = (TDBSkillData *)(pData + pRoleData->dwFSkillOffset);
  110. for (int i = 0 ; i < nSkillCount; i ++, pSkillData ++)
  111. {
  112. int nSkillId = 0;
  113. int nSkillLevel = 0;
  114. sprintf(szSkillId, "%s%d", KEY_FIGHTSKILL, i+1);
  115. sprintf(szSkillLevel, "%s%d", KEY_FIGHTSKILLLEVEL, i+1);
  116. pSkillData->m_nSkillId = cFile.ReadInteger(SECTION_FIGHTSKILLLIST, szSkillId, 0);
  117. pSkillData->m_nSkillLevel = cFile.ReadInteger(SECTION_FIGHTSKILLLIST, szSkillLevel, 0);
  118. }
  119. pRoleData->nFightSkillCount = nSkillCount;
  120. pRoleData->dwLSkillOffset = (BYTE *)pSkillData - pData;
  121. nSkillCount = cFile.ReadInteger(SECTION_LIFESKILLLIST, KEY_COUNT, 0);
  122. pSkillData = (TDBSkillData *)(pData + pRoleData->dwLSkillOffset);
  123. for (i = 0 ; i < nSkillCount; i ++, pSkillData ++)
  124. {
  125. int nSkillId = 0;
  126. int nSkillLevel = 0;
  127. sprintf(szSkillId, "%s%d", KEY_FIGHTSKILL, i+1);
  128. sprintf(szSkillLevel, "%s%d", KEY_FIGHTSKILLLEVEL, i+1);
  129. pSkillData->m_nSkillId = cFile.ReadInteger(SECTION_FIGHTSKILLLIST, szSkillId, 0);
  130. pSkillData->m_nSkillLevel = cFile.ReadInteger(SECTION_FIGHTSKILLLIST, szSkillLevel, 0);
  131. }
  132. pRoleData->nLiveSkillCount = nSkillCount;
  133. pRoleData->dwTaskOffset = (BYTE*)pSkillData - pData;
  134. pRoleData->nTaskCount = 0;
  135. //Item
  136. TDBItemData * pItemData = (TDBItemData *)pSkillData;
  137. int nItemCount = 0;
  138. nItemCount = cFile.ReadInteger(SECTION_ITEMLIST, KEY_COUNT, 0);
  139. char szSection[100];
  140. for ( i = 0 ; i < nItemCount; i ++)
  141. {
  142. sprintf(szSection, "%s%d", SECTION_ITEM, i + 1 );
  143. pItemData->cusercode[0] = 0;
  144. //物件基本信息**************************************************************
  145. pItemData->iequipclasscode = cFile.ReadInteger(szSection, "iequipclasscode", 0);
  146. pItemData->idetailtype = cFile.ReadInteger(szSection, "idetailtype", 0);
  147. pItemData->iparticulartype = cFile.ReadInteger(szSection, "iparticulartype", 0);
  148. pItemData->ilevel = cFile.ReadInteger(szSection, "ilevel", 0);
  149. pItemData->iseries = cFile.ReadInteger(szSection, "iseries", 0);
  150. pItemData->ix = cFile.ReadInteger(szSection, "ix", 0);
  151. pItemData->iy = cFile.ReadInteger(szSection, "iy", 0);
  152. pItemData->ilocal = cFile.ReadInteger(szSection, "ilocal", 0);
  153. pItemData->iparam1 = cFile.ReadInteger(szSection, "iparam1", 0);
  154. pItemData->iparam2 = cFile.ReadInteger(szSection, "iparam2", 0);
  155. pItemData->iparam3 = cFile.ReadInteger(szSection, "iparam3", 0);
  156. pItemData->iparam4 = cFile.ReadInteger(szSection, "iparam4", 0);
  157. pItemData->iparam5 = cFile.ReadInteger(szSection, "iparam5", 0);
  158. pItemData->iparam6 = cFile.ReadInteger(szSection, "iparam6", 0);
  159. pItemData->iequipversion = cFile.ReadInteger(szSection, "iequipversion", 0);
  160. pItemData->irandseed = cFile.ReadInteger(szSection, "irandseed", 0);
  161. pItemData->ilucky = cFile.ReadInteger(szSection, "ilucky", 0);
  162. pItemData ++;
  163. }
  164. pRoleData->dwFriendOffset = (BYTE *)pItemData - pData;
  165. pRoleData->nItemCount = nItemCount;
  166. pRoleData->nFriendCount = 0;
  167. pRoleData->dwDataLen = (BYTE *)pItemData - pData;
  168. return true;
  169. }