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

模拟服务器

开发平台:

C/C++

  1. #include "KCore.h"
  2. #ifdef _SERVER
  3. #include "KEngine.h"
  4. #include "KSubWorldSet.h"
  5. #include "KSubWorld.h"
  6. #include "KPlayer.h"
  7. #ifndef _STANDALONE
  8. #include "../../../lib/S3DBInterface.h"
  9. #else
  10. #include "S3DBInterface.h"
  11. #endif
  12. #include "KNpc.h"
  13. #include "KItem.h"
  14. #include "KItemList.h"
  15. #include "KItemGenerator.h"
  16. #include "KItemSet.h"
  17. #include "KNpcSet.h"
  18. #include "KPlayerSet.h"
  19. #include "KItemChangeRes.h"
  20. #include <time.h>
  21. //#include "MyAssert.H"
  22. #include "KTaskFuns.h"
  23. // 是否将数据库存取档的数据保存下来以供调试
  24. //#define DEBUGOPT_DB_ROLEDATA_OUT 
  25. KList g_DBMsgList;
  26. int KPlayer::AddDBPlayer(char * szPlayerName, int sex, DWORD * pdwID)
  27. {
  28. return FALSE;
  29. }
  30. int KPlayer::LoadDBPlayerInfo(BYTE *pPlayerInfo, int &nStep, unsigned int &nParam)
  31. {
  32. _ASSERT(pPlayerInfo);
  33. int nRet = 0;
  34. int nRetValue = 0;
  35. switch(nStep)
  36. {
  37. case STEP_BASE_INFO:
  38. //数据库中玩家基本信息表
  39. m_pCurStatusOffset = pPlayerInfo;
  40. if ((nRet = LoadPlayerBaseInfo(pPlayerInfo, m_pCurStatusOffset, nParam)) == 1)
  41. {
  42. nRetValue = SendSyncData(nStep, nParam);
  43. nStep++; 
  44. nParam = 0;
  45. }
  46. else 
  47. {
  48. if (nRet == -1)
  49. {
  50. nStep++;
  51. nParam = 0;
  52. return 0;
  53. }
  54. else
  55. {
  56. nRetValue = SendSyncData(nStep, nParam);
  57. }
  58. }
  59. break;
  60. case STEP_FIGHT_SKILL_LIST:
  61. //************************************************
  62. // 玩家的战斗技能列表
  63. if ((nRet = LoadPlayerFightSkillList(pPlayerInfo, m_pCurStatusOffset, nParam)) == 1)
  64. {
  65. nRetValue = SendSyncData(nStep, nParam);
  66. nStep++;
  67. nParam = 0;
  68. }
  69. else
  70. {
  71. if (nRet == -1)
  72. {
  73. nStep++;
  74. nParam = 0;
  75. return 0;
  76. }
  77. // else
  78. // {
  79. // nRetValue = SendSyncData(nStep, nParam);
  80. // }
  81. }
  82. break;
  83. case STEP_LIFE_SKILL_LIST:
  84. //*************************************************
  85. // 玩家的生活技能列表
  86. if ((nRet = LoadPlayerLifeSkilllList(pPlayerInfo, m_pCurStatusOffset, nParam)) == 1)
  87. {
  88. nRetValue = SendSyncData(nStep, nParam);
  89. nStep++;
  90. nParam = 0;
  91. }
  92. else
  93. {
  94. if (nRet == -1)
  95. {
  96. nStep ++;
  97. nParam = 0;
  98. return 0;
  99. }
  100. else
  101. {
  102. nRetValue = SendSyncData(nStep, nParam);
  103. }
  104. }
  105. break;
  106. case STEP_TASK_LIST:
  107. //*************************************************
  108. // 玩家的任务列表
  109. if ((nRet = LoadPlayerTaskList(pPlayerInfo, m_pCurStatusOffset, nParam)) == 1)
  110. {
  111. int i = 0;
  112. for (i  = 0; i < TASKVALUE_MAXWAYPOINT_COUNT; i ++)
  113. {
  114. int nWayPoint = m_cTask.nSave[TASKVALUE_SAVEWAYPOINT_BEGIN + i];
  115. if (nWayPoint)
  116. {
  117. KIndexNode * pNewNode = new KIndexNode;
  118. pNewNode->m_nIndex = nWayPoint;
  119. m_PlayerWayPointList.AddTail(pNewNode);
  120. }
  121. }
  122. for (i  = 0; i < TASKVALUE_MAXSTATION_COUNT / 2; i ++)
  123. {
  124. DWORD Stations = 0;
  125. if (Stations = (DWORD) m_cTask.GetSaveVal(TASKVALUE_SAVESTATION_BEGIN + i))
  126. {
  127. int nStation1 = (int) HIWORD(Stations);
  128. int nStation2 = (int) LOWORD(Stations);
  129. if (nStation1)
  130. {
  131. KIndexNode * pNewNode = new KIndexNode;
  132. pNewNode->m_nIndex = nStation1;
  133. m_PlayerStationList.AddTail(pNewNode);
  134. }
  135. if (nStation2)
  136. {
  137. KIndexNode * pNewNode = new KIndexNode;
  138. pNewNode->m_nIndex = nStation2;
  139. m_PlayerStationList.AddTail(pNewNode);
  140. }
  141. }
  142. }
  143. g_TimerTask.LoadTask(this);
  144. nRetValue = SendSyncData(nStep, nParam);
  145. nStep++;
  146. nParam = 0;
  147. }
  148. else
  149. {
  150. if (nRet == -1)
  151. {
  152. nStep ++;
  153. nParam = 0;
  154. return 0;
  155. }
  156. else
  157. {
  158. nRetValue = SendSyncData(nStep, nParam);
  159. }
  160. }
  161. break;
  162. case STEP_ITEM_LIST:
  163. //*************************************************
  164. // 玩家的装备列表
  165. if ((nRet = LoadPlayerItemList(pPlayerInfo, m_pCurStatusOffset, nParam)) == 1)
  166. {
  167. nRetValue = SendSyncData(nStep, nParam);
  168. nStep++;
  169. nParam = 0;
  170. }
  171. else
  172. {
  173. if (nRet == -1)
  174. {
  175. nStep ++;
  176. nParam = 0;
  177. return 0;
  178. }
  179. else
  180. {
  181. nRetValue = SendSyncData(nStep, nParam);
  182. }
  183. }
  184. break;
  185. default:
  186. nStep = STEP_SYNC_END;
  187. break;
  188. }
  189. return nRetValue;
  190. }
  191. int KPlayer::UpdateDBPlayerInfo(BYTE* pPlayerInfo)
  192. {
  193. //注意,存档取档都必须按照P顺序
  194. if (!pPlayerInfo)
  195. return -1;
  196. //数据库中玩家基本信息表
  197. SavePlayerBaseInfo(pPlayerInfo);
  198. // 玩家的战斗技能列表
  199. SavePlayerFightSkillList(pPlayerInfo);
  200. // 玩家的生活技能列表
  201. SavePlayerLifeSkilllList(pPlayerInfo);
  202. // 玩家的任务列表
  203. SavePlayerTaskList(pPlayerInfo);
  204. // 玩家的物品列表
  205. SavePlayerItemList(pPlayerInfo);
  206. //玩家的好友列表//
  207. // SavePlayerFriendList(pPlayerInfo);
  208. return 1;
  209. }
  210. int KPlayer::LoadPlayerBaseInfo(BYTE  * pRoleBuffer, BYTE * &pCurData, unsigned int &nParam)
  211. {
  212. if (!pRoleBuffer)
  213. {
  214. KASSERT(pRoleBuffer);
  215. return -1;
  216. }
  217. TRoleData * pRoleData = (TRoleData*)pRoleBuffer;
  218. if (nParam != 0) return -1;
  219. int nSex;
  220. int nLevel;
  221. #define PLAYER_MALE_NPCTEMPLATEID -1
  222. #define PLAYER_FEMALE_NPCTEMPLATEID -2
  223. nLevel = pRoleData->BaseInfo.ifightlevel;
  224. nSex = pRoleData->BaseInfo.bSex;
  225. if (nSex)
  226. nSex = MAKELONG(nLevel, PLAYER_FEMALE_NPCTEMPLATEID);
  227. else
  228. nSex = MAKELONG(nLevel, PLAYER_MALE_NPCTEMPLATEID);
  229. //登入点
  230. m_sLoginRevivalPos.m_nSubWorldID = pRoleData->BaseInfo.irevivalid;
  231. m_sLoginRevivalPos.m_ReviveID = pRoleData->BaseInfo.irevivalx;
  232. //---------------------------------------------------------------------------------------------
  233. label_retry:
  234. POINT Pos;
  235. g_SubWorldSet.GetRevivalPosFromId(m_sLoginRevivalPos.m_nSubWorldID,
  236. m_sLoginRevivalPos.m_ReviveID,
  237. &Pos);
  238. m_sLoginRevivalPos.m_nMpsX = Pos.x;
  239. m_sLoginRevivalPos.m_nMpsY = Pos.y;
  240. //---------------------------------------------------------------------------------------------
  241. PLAYER_REVIVAL_POS tempPos;
  242. if (pRoleData->BaseInfo.cUseRevive)
  243. {
  244. tempPos.m_nSubWorldID = m_sLoginRevivalPos.m_nSubWorldID;
  245. tempPos.m_ReviveID = m_sLoginRevivalPos.m_ReviveID;
  246. tempPos.m_nMpsX = m_sLoginRevivalPos.m_nMpsX;
  247. tempPos.m_nMpsY = m_sLoginRevivalPos.m_nMpsY;
  248. }
  249. else
  250. {
  251. tempPos.m_nSubWorldID = pRoleData->BaseInfo.ientergameid;
  252. tempPos.m_nMpsX = pRoleData->BaseInfo.ientergamex;
  253. tempPos.m_nMpsY = pRoleData->BaseInfo.ientergamey;
  254. }
  255. m_nIndex = NpcSet.Add(nSex, 
  256. g_SubWorldSet.SearchWorld(tempPos.m_nSubWorldID),
  257. tempPos.m_nMpsX,
  258. tempPos.m_nMpsY);
  259. if(m_nIndex <= 0) 
  260. {
  261. g_DebugLog("[Error!]AddNpc Error DBFuns.cpp");
  262. if (pRoleData->BaseInfo.cUseRevive)
  263. {
  264. return -1;
  265. }
  266. else
  267. {
  268. pRoleData->BaseInfo.cUseRevive = 1;
  269. goto label_retry;
  270. }
  271. }
  272. m_sDeathRevivalPos = m_sLoginRevivalPos;
  273. KNpc* pNpc = &Npc[m_nIndex];
  274. pNpc->m_Kind = kind_player;
  275. pNpc->SetPlayerIdx(m_nPlayerIndex);
  276. pNpc->m_Level = nLevel;
  277. //玩家信息
  278. strcpy(pNpc->Name, pRoleData->BaseInfo.szName);
  279. m_nForbiddenFlag = pRoleData->BaseInfo.nForbiddenFlag;
  280. m_nAttributePoint = pRoleData->BaseInfo.ileftprop;
  281. m_nSkillPoint = pRoleData->BaseInfo.ileftfight;
  282. m_nStrength = pRoleData->BaseInfo.ipower;
  283. m_nDexterity = pRoleData->BaseInfo.iagility;
  284. m_nVitality = pRoleData->BaseInfo.iouter;
  285. m_nEngergy = pRoleData->BaseInfo.iinside;
  286. m_nLucky = pRoleData->BaseInfo.iluck;
  287. m_cTong.Clear();
  288. m_cTong.DBSetTongNameID(pRoleData->BaseInfo.dwTongID);
  289. m_nCurStrength = m_nStrength;
  290. m_nCurDexterity = m_nDexterity;
  291. m_nCurVitality = m_nVitality;
  292. m_nCurEngergy = m_nEngergy;
  293. m_nCurLucky = m_nLucky;
  294. this->SetFirstDamage();
  295. this->SetBaseAttackRating();
  296. this->SetBaseDefence();
  297. //玩家等级信息
  298. m_nExp = pRoleData->BaseInfo.fightexp;
  299. m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(pNpc->m_Level);
  300. m_dwLeadLevel = pRoleData->BaseInfo.ileadlevel;
  301. m_dwLeadExp = pRoleData->BaseInfo.ileadexp;
  302. //门派信息
  303. m_cFaction.m_nCurFaction = (char)pRoleData->BaseInfo.nSect;
  304. m_cFaction.m_nFirstAddFaction = (char)pRoleData->BaseInfo.nFirstSect;
  305. m_cFaction.m_nAddTimes = pRoleData->BaseInfo.ijoincount;
  306. pNpc->m_btRankId = pRoleData->BaseInfo.isectrole;
  307. m_nWorldStat = pRoleData->BaseInfo.nWorldStat;
  308. m_nSectStat = pRoleData->BaseInfo.nSectStat;
  309. //现金和贮物箱中的钱
  310. int nCashMoney = 0;
  311. int nSaveMoney = 0;
  312. // this->m_ItemList.Init(GetPlayerIndex());
  313. nCashMoney = pRoleData->BaseInfo.imoney;
  314. nSaveMoney = pRoleData->BaseInfo.isavemoney;
  315. m_ItemList.SetMoney(nCashMoney, nSaveMoney,0);
  316. pNpc->m_Series = pRoleData->BaseInfo.ifiveprop;
  317. pNpc->m_Camp = pRoleData->BaseInfo.iteam;
  318. pNpc->m_nSex = pRoleData->BaseInfo.bSex;
  319. pNpc->m_LifeMax = pRoleData->BaseInfo.imaxlife;
  320. pNpc->m_StaminaMax = pRoleData->BaseInfo.imaxstamina;
  321. pNpc->m_ManaMax = pRoleData->BaseInfo.imaxinner;
  322. pNpc->m_LifeReplenish = PLAYER_LIFE_REPLENISH;
  323. pNpc->m_ManaReplenish = PLAYER_MANA_REPLENISH;
  324. pNpc->m_StaminaGain = PLAYER_STAMINA_GAIN;
  325. pNpc->m_StaminaLoss = PLAYER_STAMINA_LOSS;
  326. this->SetBaseResistData();
  327. SetBaseSpeedAndRadius();
  328. pNpc->RestoreNpcBaseInfo();
  329. pNpc->m_CurrentLife = pRoleData->BaseInfo.icurlife;
  330. pNpc->m_CurrentMana = pRoleData->BaseInfo.icurinner;
  331. pNpc->m_CurrentStamina = pRoleData->BaseInfo.icurstamina;
  332. // PK信息
  333. m_cPK.SetNormalPKState(pRoleData->BaseInfo.cPkStatus);
  334. m_cPK.SetPKValue(pRoleData->BaseInfo.ipkvalue);
  335. // 初始化部分数据(这些数据数据库不存储)
  336. m_BuyInfo.Clear();
  337. m_cMenuState.Release();
  338. m_cChat.Release();
  339. m_cTeam.Release();
  340. m_cTeam.SetCanTeamFlag(m_nPlayerIndex, TRUE);
  341. m_nPeapleIdx = 0;
  342. m_nObjectIdx = 0;
  343. memset(m_szTaskAnswerFun, 0, sizeof(m_szTaskAnswerFun));
  344. m_nAvailableAnswerNum = 0;
  345. Npc[m_nIndex].m_ActionScriptID = 0;
  346. Npc[m_nIndex].m_TrapScriptID = 0;
  347. m_nViewEquipTime = 0;
  348. pNpc->m_Experience = 0;
  349. // memset(pNpc->m_szChatBuffer, 0, sizeof(pNpc->m_szChatBuffer));
  350. // pNpc->m_nCurChatTime = 0;
  351. pNpc->m_WeaponType = g_ItemChangeRes.GetWeaponRes(0, 0, 0);
  352. pNpc->m_ArmorType = g_ItemChangeRes.GetArmorRes(0, 0);
  353. pNpc->m_HelmType = g_ItemChangeRes.GetHelmRes(0, 0);
  354. pNpc->m_HorseType = g_ItemChangeRes.GetHorseRes(0, 0);
  355. pNpc->m_bRideHorse = FALSE;
  356. nParam = 1;
  357. pCurData = (BYTE *)&pRoleData->pBuffer;
  358. // 登入游戏时战斗模式
  359. pNpc->m_FightMode = pRoleData->BaseInfo.cFightMode;
  360. // 是否是处于跨服务器状态
  361. if (pRoleData->BaseInfo.cIsExchange)
  362. {
  363. }
  364. return 1;
  365. }
  366. int KPlayer::LoadPlayerItemList(BYTE * pRoleBuffer , BYTE* &pItemBuffer, unsigned int &nParam)
  367. {
  368. KASSERT(pRoleBuffer);
  369. int nItemCount = ((TRoleData *)pRoleBuffer)->nItemCount;
  370. TDBItemData * pItemData = (TDBItemData *)pItemBuffer;
  371. if (nItemCount == 0) return 1;
  372. if (nParam != 0)
  373. // m_ItemList.Init(m_nPlayerIndex);
  374. // else 
  375. {
  376. //如果要求获得的物品号大于实际的物品数量,则退出
  377. if (nParam >= nItemCount )
  378. return -1;
  379. }
  380. char szSection[100];
  381. char szSubSection[100];
  382. char szKey[100];
  383. int nItemClass;
  384. int nItemBaseInfoCount ;
  385. int nItemEfficInfoCount;
  386. int nItemRequireInfoCount;
  387. int dwItemID = 0; 
  388. int nDetailType = 0;
  389. int nParticularType = 0;
  390. int nSeries = 0;
  391. int nLevel = 0;
  392. int nLocal = 0;
  393. int nItemX = 0;
  394. int nItemY = 0;
  395. int nLucky = 0;
  396. int nBegin = nParam;
  397. int nEnd = nParam + DBLOADPERTIME_ITEM;
  398. if ( nEnd > nItemCount)
  399. nEnd = nItemCount;
  400. nParam = nEnd;
  401. for (int i = nBegin ; i < nEnd; i ++)
  402. {
  403. KItem NewItem;
  404. ZeroMemory(&NewItem, sizeof(KItem));
  405. //物件基本信息**************************************************************
  406. nItemClass = pItemData->iequipclasscode;
  407. NewItem.m_CommonAttrib.nDetailType = pItemData->idetailtype;
  408. NewItem.m_CommonAttrib.nParticularType = pItemData->iparticulartype;
  409. NewItem.m_CommonAttrib.nLevel = pItemData->ilevel;
  410. NewItem.m_CommonAttrib.nSeries = pItemData->iseries;
  411. nItemX = pItemData->ix;
  412. nItemY = pItemData->iy;
  413. nLocal = pItemData->ilocal;
  414. //增加物件至世界的ItemSet中,以及增加到玩家物品列表中**************************************************************
  415. //NewItem.SetID(dwItemID);
  416. NewItem.m_GeneratorParam.nGeneratorLevel[0] = pItemData->iparam1;
  417. NewItem.m_GeneratorParam.nGeneratorLevel[1] = pItemData->iparam2;
  418. NewItem.m_GeneratorParam.nGeneratorLevel[2] = pItemData->iparam3;
  419. NewItem.m_GeneratorParam.nGeneratorLevel[3] = pItemData->iparam4;
  420. NewItem.m_GeneratorParam.nGeneratorLevel[4] = pItemData->iparam5;
  421. NewItem.m_GeneratorParam.nGeneratorLevel[5] = pItemData->iparam6;
  422. NewItem.m_GeneratorParam.nVersion = pItemData->iequipversion;
  423. NewItem.m_GeneratorParam.uRandomSeed = pItemData->irandseed;
  424. NewItem.m_GeneratorParam.nLuck = pItemData->ilucky;
  425. BOOL bGetEquiptResult = 0;
  426. //根据不同的物件类型加载
  427. //不同的相关资源信息
  428. switch(nItemClass)
  429. {
  430. case item_equip : // 装备
  431. bGetEquiptResult = ItemGen.Gen_ExistEquipment(
  432. NewItem.m_CommonAttrib.nDetailType, 
  433. NewItem.m_CommonAttrib.nParticularType,
  434. NewItem.m_CommonAttrib.nSeries,
  435. NewItem.m_CommonAttrib.nLevel, 
  436. NewItem.m_GeneratorParam.nGeneratorLevel, 
  437. NewItem.m_GeneratorParam.nLuck,
  438. NewItem.m_GeneratorParam.nVersion,
  439. &NewItem);
  440. break;
  441. case item_medicine: // 药品
  442. bGetEquiptResult = ItemGen.Gen_Medicine(
  443. NewItem.m_CommonAttrib.nDetailType,
  444. NewItem.m_CommonAttrib.nLevel,
  445. NewItem.m_GeneratorParam.nVersion, 
  446. &NewItem);
  447. break;
  448. case item_mine: // 矿石
  449. {
  450. }
  451. break;
  452. case item_materials: // 药材
  453. {
  454. }
  455. break;
  456. case item_task: // 任务
  457. {
  458. bGetEquiptResult = ItemGen.Gen_Quest(NewItem.m_CommonAttrib.nDetailType, &NewItem);
  459. }
  460. break;
  461. case item_townportal:
  462. {
  463. bGetEquiptResult = ItemGen.Gen_TownPortal(&NewItem);
  464. }
  465. break;
  466. }
  467. // 把生成的装备的耐久度调整为数据库中存储的。
  468. if (pItemData->idurability != 0)
  469. NewItem.SetDurability(pItemData->idurability);
  470. pItemData ++;
  471. int nIndex = ItemSet.Add(&NewItem);
  472. if (nIndex <= 0) 
  473. {
  474. KASSERT(0);
  475. continue ;
  476. }
  477. m_ItemList.Add(nIndex, nLocal, nItemX, nItemY);
  478. }
  479. pItemBuffer = (BYTE *)pItemData;
  480. if (nParam >= nItemCount)
  481. return 1;
  482. else 
  483. return 0;
  484. }
  485. int KPlayer::LoadPlayerFightSkillList(BYTE * pRoleBuffer, BYTE * &pFightBuffer, unsigned int& nParam)
  486. {
  487. KASSERT(pRoleBuffer);
  488. int nSkillCount = 0;
  489. char szSkillId[100];
  490. char szSkillLevel[100];
  491. nSkillCount = ((TRoleData*)(pRoleBuffer))->nFightSkillCount;
  492. if (nSkillCount == 0)
  493. return 1;
  494. if (nParam >= nSkillCount )
  495. return -1;
  496. int nBegin = nParam;
  497. int nEnd = nBegin + DBLOADPERTIME_SKILL;
  498. if (nEnd > nSkillCount)  nEnd = nSkillCount;
  499. nParam = nEnd;
  500. TDBSkillData * pSkillData = NULL;
  501. if (nBegin == 0)
  502. pSkillData = (TDBSkillData *)((BYTE*)pRoleBuffer + ((TRoleData*)pRoleBuffer)->dwFSkillOffset);
  503. else
  504. pSkillData = (TDBSkillData*)pFightBuffer;
  505. for (int i = nBegin ; i < nEnd; i ++, pSkillData ++ )
  506. {
  507. int nSkillId = 0;
  508. int nSkillLevel = 0;
  509. nSkillId = pSkillData->m_nSkillId;
  510. nSkillLevel = pSkillData->m_nSkillLevel;
  511. Npc[m_nIndex].m_SkillList.Add(nSkillId, nSkillLevel);
  512. }
  513. pFightBuffer = (BYTE*) pSkillData;
  514. if (nParam >= nSkillCount) return 1;
  515. else 
  516. return 0;
  517. }
  518. int KPlayer::LoadPlayerLifeSkilllList(BYTE * pRoleBuffer, BYTE * &pFriendBuffer, unsigned int& nParam)
  519. {
  520. KASSERT(pRoleBuffer);
  521. int nSkillCount = 0;
  522. char szSkillId[100];
  523. char szSkillLevel[100];
  524. nSkillCount = ((TRoleData*)(pRoleBuffer))->nLiveSkillCount;
  525. if (nSkillCount == 0)
  526. return 1;
  527. if (nParam >= nSkillCount ) return -1;
  528. int nBegin = nParam;
  529. int nEnd = nBegin + DBLOADPERTIME_SKILL;
  530. if (nEnd > nSkillCount)  nEnd = nSkillCount;
  531. nParam = nEnd;
  532. TDBSkillData * pSkillData = (TDBSkillData*)pFriendBuffer;
  533. for (int i = nBegin ; i < nEnd; i ++, pSkillData ++ )
  534. {
  535. int nSkillId = 0;
  536. int nSkillLevel = 0;
  537. nSkillId = pSkillData->m_nSkillId;
  538. nSkillLevel = pSkillData->m_nSkillLevel;
  539. Npc[m_nIndex].m_SkillList.Add(nSkillId, nSkillLevel);
  540. }
  541. pFriendBuffer = (BYTE*) pSkillData;
  542. if (nParam >= nSkillCount) return 1;
  543. else 
  544. return 0;
  545. }
  546. int KPlayer::LoadPlayerFriendList(BYTE * pRoleBuffer, BYTE * &pFriendBuffer, unsigned int &nParam)
  547. {
  548. KASSERT(pRoleBuffer);
  549. if (nParam == 1)
  550. return 0;
  551. if (nParam == 2)
  552. return 1;
  553. int nFriendCount;
  554. DWORD dwID;
  555. char szBuffer[32], szName[32];
  556. nFriendCount = ((TRoleData*)pRoleBuffer)->nFriendCount;
  557. if (nFriendCount == 0)
  558. {
  559. nParam = 2;
  560. return 1;
  561. }
  562. char * pCurFriend = (char *)pFriendBuffer;
  563. for (int i = 0; i < nFriendCount; i++)
  564. {
  565. strcpy(szName, (char *)pFriendBuffer);
  566. if (!szName[0])
  567. continue;
  568. dwID = g_FileName2Id(szName);
  569. m_cChat.DataBaseAddOne(this->m_nPlayerIndex, dwID, szName);
  570. pFriendBuffer += (strlen(szName) + 1);
  571. }
  572. this->m_cChat.StartSendFriendData();
  573. nParam = 1;
  574. return 0;
  575. }
  576. int KPlayer::LoadPlayerTaskList(BYTE * pRoleBuffer, BYTE * &pTaskBuffer, unsigned int& nParam)
  577. {
  578. KASSERT(pRoleBuffer);
  579. while(m_PlayerStationList.GetHead())
  580. {
  581. KIndexNode * pNode = (KIndexNode * ) m_PlayerStationList.GetHead();
  582. m_PlayerStationList.RemoveHead();
  583. delete pNode;
  584. }
  585. while(m_PlayerWayPointList.GetHead())
  586. {
  587. KIndexNode * pNode = (KIndexNode * ) m_PlayerWayPointList.GetHead();
  588. m_PlayerWayPointList.RemoveHead();
  589. delete pNode;
  590. }
  591. if(nParam == 0) m_cTask.Release();
  592. int nTaskCount = 0;
  593. int nTaskId = 0;
  594. int nTaskDegee = 0;
  595. char szTaskIDKey[100];
  596. char szTaskValueKey[100];
  597. nTaskCount = ((TRoleData* )pRoleBuffer)->nTaskCount;
  598. if (nTaskCount == 0) return 1;
  599. if (nParam >= nTaskCount ) return -1;
  600. int nBegin = nParam;
  601. int nEnd = nBegin + DBLOADPERTIME_TASK;
  602. if (nEnd > nTaskCount) nEnd = nTaskCount;
  603. nParam = nEnd;
  604. TDBTaskData * pTaskData = (TDBTaskData*) pTaskBuffer;
  605. for (int i = nBegin; i < nEnd; i ++ , pTaskData ++)
  606. {
  607. nTaskId = pTaskData->m_nTaskId;
  608. nTaskDegee = pTaskData->m_nTaskValue;
  609. if (nTaskId >= MAX_TASK) 
  610. {
  611. KASSERT(0);
  612. continue;//任务ID超过上限了!
  613. }
  614. m_cTask.SetSaveVal(nTaskId, nTaskDegee);
  615. }
  616. pTaskBuffer = (BYTE*) pTaskData;
  617. if (nParam >= nTaskCount) return 1;
  618. else 
  619. return 0;
  620. }
  621. int KPlayer::SavePlayerBaseInfo(BYTE * pRoleBuffer)
  622. {
  623. _ASSERT(pRoleBuffer);
  624. if (m_nIndex <= 0) return -1;
  625. KNpc * pNpc = &Npc[m_nIndex];
  626. TRoleData * pRoleData = (TRoleData*)pRoleBuffer;
  627. //玩家信息
  628. memset(pRoleData, 0, sizeof(TRoleData));
  629. pRoleData->bBaseNeedUpdate = 1;
  630. strcpy(pRoleData->BaseInfo.szName, m_PlayerName);
  631. if (m_AccoutName[0])
  632. strcpy(pRoleData->BaseInfo.caccname, m_AccoutName);
  633. pRoleData->BaseInfo.nForbiddenFlag = m_nForbiddenFlag;
  634. pRoleData->BaseInfo.ileftprop = m_nAttributePoint;
  635. pRoleData->BaseInfo.ileftfight = m_nSkillPoint;
  636. pRoleData->BaseInfo.ipower = m_nStrength;
  637. pRoleData->BaseInfo.iagility = m_nDexterity;
  638. pRoleData->BaseInfo.iouter = m_nVitality;
  639. pRoleData->BaseInfo.iinside =  m_nEngergy;
  640. pRoleData->BaseInfo.iluck = m_nLucky;
  641. pRoleData->BaseInfo.dwTongID = m_cTong.GetTongNameID();
  642. //玩家的显示信息 -- remark by spe because client ui display changed 2003/07/21
  643. // pRoleData->BaseInfo.ihelmres = pNpc->m_HelmType;
  644. // pRoleData->BaseInfo.iarmorres = pNpc->m_ArmorType;
  645. // pRoleData->BaseInfo.iweaponres = pNpc->m_WeaponType;
  646. //玩家等级信息
  647. pRoleData->BaseInfo.fightexp = m_nExp;
  648. pRoleData->BaseInfo.ifightlevel = pNpc->m_Level;
  649. pRoleData->BaseInfo.ileadlevel = m_dwLeadLevel;
  650. pRoleData->BaseInfo.ileadexp = m_dwLeadExp;
  651. //门派信息
  652. pRoleData->BaseInfo.nSect = m_cFaction.m_nCurFaction;
  653. pRoleData->BaseInfo.nFirstSect =  m_cFaction.m_nFirstAddFaction;
  654. pRoleData->BaseInfo.ijoincount = m_cFaction.m_nAddTimes;
  655. pRoleData->BaseInfo.isectrole = pNpc->m_btRankId;
  656. pRoleData->BaseInfo.nWorldStat = m_nWorldStat;
  657. pRoleData->BaseInfo.nSectStat = m_nSectStat;
  658. //现金和贮物箱中的钱
  659. int nCashMoney = 0;
  660. int nSaveMoney = 0;
  661. nCashMoney  = m_ItemList.GetMoney(room_equipment);
  662. nSaveMoney = m_ItemList.GetMoney(room_repository);
  663. pRoleData->BaseInfo.imoney = nCashMoney;
  664. pRoleData->BaseInfo.isavemoney = nSaveMoney;
  665. pRoleData->BaseInfo.ifiveprop = pNpc->m_Series;
  666. pRoleData->BaseInfo.iteam = pNpc->m_Camp;
  667. pRoleData->BaseInfo.bSex = pNpc->m_nSex;
  668. pRoleData->BaseInfo.imaxlife = pNpc->m_LifeMax;
  669. pRoleData->BaseInfo.imaxstamina = pNpc->m_StaminaMax;
  670. pRoleData->BaseInfo.imaxinner = pNpc->m_ManaMax;
  671. pRoleData->BaseInfo.icurlife = pNpc->m_CurrentLife;
  672. pRoleData->BaseInfo.icurinner = pNpc->m_CurrentMana;
  673. pRoleData->BaseInfo.icurstamina = pNpc->m_CurrentStamina;
  674. //登入点
  675. pRoleData->BaseInfo.irevivalid =  m_sLoginRevivalPos.m_nSubWorldID;
  676. pRoleData->BaseInfo.irevivalx =  m_sLoginRevivalPos.m_ReviveID;
  677. pRoleData->BaseInfo.irevivaly =  0;
  678. if (m_bExchangeServer) // 准备跨服务器:把存盘点设为目标点
  679. {
  680. pRoleData->BaseInfo.cUseRevive = 0;
  681. pRoleData->BaseInfo.ientergameid = m_sExchangePos.m_dwMapID;
  682. pRoleData->BaseInfo.ientergamex = m_sExchangePos.m_nX;
  683. pRoleData->BaseInfo.ientergamey = m_sExchangePos.m_nY;
  684. pRoleData->BaseInfo.cFightMode = (BYTE)pNpc->m_FightMode;
  685. }
  686. else if (pNpc->m_SubWorldIndex >= 0 && pNpc->m_RegionIndex >= 0 && pNpc->m_Doing != do_death && pNpc->m_Doing != do_revive)
  687. {
  688. pRoleData->BaseInfo.cUseRevive = m_bUseReviveIdWhenLogin;
  689. pRoleData->BaseInfo.ientergameid = SubWorld[pNpc->m_SubWorldIndex].m_SubWorldID;
  690. pNpc->GetMpsPos(&pRoleData->BaseInfo.ientergamex, &pRoleData->BaseInfo.ientergamey);
  691. pRoleData->BaseInfo.cFightMode = (BYTE)pNpc->m_FightMode;
  692. }
  693. else
  694. {
  695. pRoleData->BaseInfo.cUseRevive = 1;
  696. pRoleData->BaseInfo.cFightMode = 0;
  697. if (pNpc->m_Doing == do_death || pNpc->m_Doing == do_revive)
  698. {
  699. pRoleData->BaseInfo.icurlife = pNpc->m_LifeMax;
  700. pRoleData->BaseInfo.icurinner = pNpc->m_ManaMax;
  701. pRoleData->BaseInfo.icurstamina = pNpc->m_StaminaMax;
  702. }
  703. }
  704. //PK相关
  705. pRoleData->BaseInfo.cPkStatus = (BYTE)m_cPK.GetNormalPKState();
  706. pRoleData->BaseInfo.ipkvalue = m_cPK.GetPKValue();
  707. pRoleData->dwFSkillOffset = (BYTE * )pRoleData->pBuffer - (BYTE *)pRoleBuffer;
  708. return 1;
  709. }
  710. int KPlayer::SavePlayerItemList(BYTE * pRoleBuffer)
  711. {
  712. _ASSERT(pRoleBuffer);
  713. TRoleData * pRoleData = (TRoleData*) pRoleBuffer;
  714. TDBItemData * pItemData = (TDBItemData*) ((BYTE*)pRoleData +  pRoleData->dwItemOffset);
  715. int nItemCount = 0;
  716. char szSection[100];
  717. char szKey[100];
  718. int nIdx = 0;
  719. while(1)
  720. {
  721. nIdx = m_ItemList.m_UseIdx.GetNext(nIdx);
  722. if (nIdx == 0 )
  723. break;
  724. int nItemIndex = m_ItemList.m_Items[nIdx].nIdx;
  725. sprintf(szSection, "%s%d", SECTION_ITEM, nItemCount + 1);
  726. //玩家基本信息*****************************************************************8
  727. pItemData->iequipclasscode =  Item[nItemIndex].m_CommonAttrib.nItemGenre;
  728. pItemData->iequipcode =  Item[nItemIndex].GetID();
  729. pItemData->idetailtype =  Item[nItemIndex].m_CommonAttrib.nDetailType;
  730. pItemData->iparticulartype =  Item[nItemIndex].m_CommonAttrib.nParticularType;
  731. pItemData->ilevel =  Item[nItemIndex].m_CommonAttrib.nLevel;
  732. pItemData->iseries =  Item[nItemIndex].m_CommonAttrib.nSeries;
  733. pItemData->ilocal =  m_ItemList.m_Items[nIdx].nPlace;
  734. pItemData->ix =  m_ItemList.m_Items[nIdx].nX;
  735. pItemData->iy =  m_ItemList.m_Items[nIdx].nY;
  736. pItemData->iequipversion = Item[nItemIndex].GetItemParam()->nVersion;
  737. pItemData->irandseed = Item[nItemIndex].GetItemParam()->uRandomSeed;
  738. pItemData->iparam1 =  Item[nItemIndex].GetItemParam()->nGeneratorLevel[0];
  739. pItemData->iparam2 =  Item[nItemIndex].GetItemParam()->nGeneratorLevel[1];
  740. pItemData->iparam3 =  Item[nItemIndex].GetItemParam()->nGeneratorLevel[2];
  741. pItemData->iparam4 =  Item[nItemIndex].GetItemParam()->nGeneratorLevel[3];
  742. pItemData->iparam5 =  Item[nItemIndex].GetItemParam()->nGeneratorLevel[4];
  743. pItemData->iparam6 =  Item[nItemIndex].GetItemParam()->nGeneratorLevel[5];
  744. pItemData->ilucky =   Item[nItemIndex].GetItemParam()->nLuck;
  745. pItemData->idurability = Item[nItemIndex].GetDurability();
  746. pItemData->iidentify = 0;
  747. //*****************************************************************************8
  748. pItemData++;
  749. nItemCount ++;
  750. }
  751. pRoleData->nItemCount = nItemCount;
  752. pRoleData->dwFriendOffset = (BYTE *)pItemData - (BYTE * )pRoleData;
  753. pRoleData->dwDataLen = (BYTE*)pItemData - (BYTE*)pRoleBuffer;
  754. return 1;
  755. }
  756. int KPlayer::SavePlayerFightSkillList(BYTE * pRoleBuffer)
  757. {
  758. _ASSERT(pRoleBuffer);
  759. if (m_nIndex <= 0) 
  760. return FALSE;
  761. TRoleData * pRoleData = (TRoleData *)pRoleBuffer;
  762. TDBSkillData * pSkillData = (TDBSkillData *) (pRoleBuffer + pRoleData->dwFSkillOffset);
  763. int nCount = Npc[m_nIndex].m_SkillList.UpdateDBSkillList((BYTE *)pSkillData);
  764. if (nCount > 0)
  765. {
  766. pRoleData->nFightSkillCount = nCount;
  767. pRoleData->dwLSkillOffset = (BYTE*)pSkillData - pRoleBuffer + sizeof(TDBSkillData) * nCount;
  768. }
  769. else
  770. {
  771. pRoleData->nFightSkillCount  = 0;
  772. pRoleData->dwLSkillOffset = (BYTE*)pSkillData - pRoleBuffer;
  773. }
  774. return 1;
  775. }
  776. int KPlayer::SavePlayerLifeSkilllList(BYTE * pRoleBuffer)
  777. {
  778. _ASSERT(pRoleBuffer);
  779. TRoleData * pRoleData = (TRoleData *)pRoleBuffer;
  780. TDBSkillData * pSkillData = (TDBSkillData *) (pRoleBuffer + pRoleData->dwLSkillOffset);
  781. pRoleData->dwTaskOffset = (BYTE*)pSkillData - pRoleBuffer;
  782. return 1;
  783. }
  784. int KPlayer::SavePlayerFriendList(BYTE * pRoleBuffer)
  785. {
  786. _ASSERT(pRoleBuffer);
  787. int nFriendNo;
  788. char szBuffer[32];
  789. CChatFriend *pFriend;
  790. TRoleData * pRoleData = (TRoleData *)pRoleBuffer;
  791. nFriendNo = m_cChat.m_cFriendTeam[0].m_nFriendNo;
  792. char * pCurFriend = (char *)((BYTE *)pRoleData + pRoleData->dwFriendOffset);
  793. int nTotalFriendNo  = 0;
  794. pFriend = (CChatFriend*)m_cChat.m_cFriendTeam[0].m_cEveryOne.GetHead();
  795. while (pFriend)
  796. {
  797. nTotalFriendNo++;
  798. strcpy(pCurFriend, pFriend->m_szName);
  799. pCurFriend += strlen(pFriend->m_szName) + 1;
  800. pFriend = (CChatFriend*)pFriend->GetNext();
  801. }
  802. pRoleData->nFriendCount = nTotalFriendNo;
  803. _ASSERT(nTotalFriendNo == nFriendNo);
  804. pRoleData->dwDataLen = (BYTE*)pCurFriend - (BYTE*)pRoleBuffer;
  805. return 1;
  806. }
  807. int KPlayer::SavePlayerTaskList(BYTE * pRoleBuffer)
  808. {
  809. _ASSERT(pRoleBuffer);
  810. TRoleData * pRoleData = (TRoleData *) pRoleBuffer;
  811. int nTaskCount = 0;
  812. int nTaskId = 0;
  813. int nTaskDegee = 0;
  814. char szTaskIDKey[100];
  815. char szTaskValueKey[100];
  816. KIndexNode * pNode = (KIndexNode*)m_PlayerStationList.GetHead();
  817. int n = 0;
  818. memset(&m_cTask.nSave[TASKVALUE_SAVESTATION_BEGIN], 0, (TASKVALUE_MAXSTATION_COUNT / 2) * sizeof(int));
  819. memset(&m_cTask.nSave[TASKVALUE_SAVEWAYPOINT_BEGIN], 0, TASKVALUE_MAXWAYPOINT_COUNT * sizeof(int));
  820. while(pNode)
  821. {
  822. if (n >= TASKVALUE_MAXSTATION_COUNT) break;
  823. DWORD dwValue = m_cTask.nSave[TASKVALUE_SAVESTATION_BEGIN + n / 2];
  824. DWORD OrValue = pNode->m_nIndex ;
  825. OrValue = OrValue << ((n % 2) * 16);
  826. dwValue = dwValue | OrValue;
  827. m_cTask.nSave[TASKVALUE_SAVESTATION_BEGIN + n / 2] = dwValue;
  828. n++;
  829. pNode = (KIndexNode*)pNode->GetNext();
  830. }
  831. n = 0;
  832. pNode = (KIndexNode*) m_PlayerWayPointList.GetHead();
  833. while(pNode)
  834. {
  835. if (n >= TASKVALUE_MAXWAYPOINT_COUNT) break;
  836. if (pNode->m_nIndex == 0) continue;
  837. m_cTask.nSave[TASKVALUE_SAVEWAYPOINT_BEGIN + n] = pNode->m_nIndex;
  838. n++;
  839. pNode = (KIndexNode*)pNode->GetNext();
  840. }
  841. g_TimerTask.SaveTask(this);
  842. TDBTaskData * pTaskData = (TDBTaskData *)(pRoleBuffer + pRoleData->dwTaskOffset);
  843. for (int i = 0; i < MAX_TASK; i ++)
  844. {
  845. if (!m_cTask.nSave[i]) continue;
  846. pTaskData->m_nTaskId = i;
  847. pTaskData->m_nTaskValue = m_cTask.GetSaveVal(i);
  848. nTaskCount ++;
  849. pTaskData ++;
  850. }
  851. pRoleData->nTaskCount = nTaskCount;
  852. pRoleData->dwItemOffset = (BYTE *)pTaskData - pRoleBuffer;
  853. return 1;
  854. }
  855. #endif