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

模拟服务器

开发平台:

C/C++

  1. #ifndef KPlayerSetH
  2. #define KPlayerSetH
  3. #include "KLinkArray.h"
  4. #define MAX_LEVEL 150 // 玩家最大等级
  5. #define MAX_SERIES 5
  6. #define MAX_LEAD_LEVEL 100 // 最大统率力等级
  7. typedef struct
  8. {
  9. int m_nExp;
  10. int m_nMoney;
  11. int m_nItem;
  12. int m_nEquip;
  13. } KPK_DEATH_PUNISH_PARAM;
  14. typedef struct
  15. {
  16. int m_nLevel;
  17. int m_nLeadLevel;
  18. int m_nMoney;
  19. } STONG_CREATE_PARAM;
  20. class KLevelAdd
  21. {
  22. private:
  23. int m_nLevelExp[MAX_LEVEL]; // 升级经验
  24. int m_nLifePerLevel[MAX_SERIES]; // 每个系升级加生命点
  25. int m_nStaminaPerLevel[MAX_SERIES]; // 每个系升级加体力点
  26. int m_nManaPerLevel[MAX_SERIES]; // 每个系升级加内力点
  27. int m_nLifePerVitality[MAX_SERIES]; // 每个系活力点增加一点后生命点增长
  28. int m_nStaminaPerVitality[MAX_SERIES]; // 每个系活力点增加一点后体力点增长
  29. int m_nManaPerEnergy[MAX_SERIES]; // 每个系精力点增加一点后内力点增长
  30. int m_nLeadExpShare[MAX_SERIES]; // 每个系获得战斗经验时分配统率力经验的参数
  31. int m_nFireResistPerLevel[MAX_SERIES]; // 每个系升级加火抗性
  32. int m_nColdResistPerLevel[MAX_SERIES]; // 每个系升级加冰抗性
  33. int m_nPoisonResistPerLevel[MAX_SERIES]; // 每个系升级加毒抗性
  34. int m_nLightResistPerLevel[MAX_SERIES]; // 每个系升级加电抗性
  35. int m_nPhysicsResistPerLevel[MAX_SERIES]; // 每个系升级加物理抗性
  36. public:
  37. KLevelAdd();
  38. BOOL Init();
  39. int GetLevelExp(int nLevel);
  40. int GetLifePerLevel(int nSeries);
  41. int GetStaminaPerLevel(int nSeries);
  42. int GetManaPerLevel(int nSeries);
  43. int GetLifePerVitality(int nSeries);
  44. int GetStaminaPerVitality(int nSeries);
  45. int GetManaPerEnergy(int nSeries);
  46. int GetLeadExpShare(int nSeries);
  47. int GetFireResist(int nSeries, int nLevel);
  48. int GetColdResist(int nSeries, int nLevel);
  49. int GetPoisonResist(int nSeries, int nLevel);
  50. int GetLightResist(int nSeries, int nLevel);
  51. int GetPhysicsResist(int nSeries, int nLevel);
  52. };
  53. class KTeamLeadExp
  54. {
  55. public:
  56. struct LEADLEVEL
  57. {
  58. DWORD m_dwExp; // 统率力升级经验
  59. DWORD m_dwMemNum; // 统率等级决定能统率的队员人数
  60. } m_sPerLevel[MAX_LEAD_LEVEL];
  61. public:
  62. KTeamLeadExp();
  63. BOOL Init(); // 初始化
  64. int GetLevel(DWORD dwExp, int nCurLeadLevel = 0);// 传入经验获得等级数 (如果传入当前等级,可以加快搜索速度)
  65. int GetMemNumFromExp(DWORD dwExp); // 传入经验获得可带队员数
  66. int GetMemNumFromLevel(int nLevel); // 传入等级获得可带队员数
  67. int GetLevelExp(int nLevel); // 传入等级获得升级所需经验值
  68. };
  69. class KNewPlayerAttribute
  70. {
  71. public:
  72. int m_nStrength[series_num];
  73. int m_nDexterity[series_num];
  74. int m_nVitality[series_num];
  75. int m_nEngergy[series_num];
  76. int m_nLucky[series_num];
  77. public:
  78. KNewPlayerAttribute();
  79. BOOL Init();
  80. };
  81. class KPlayerSet
  82. {
  83. private: // 用于优化查找速度
  84. KLinkArray m_FreeIdx; // 可用表
  85. KLinkArray m_UseIdx; // 已用表
  86. int m_nListCurIdx; // 用于 GetFirstPlayer 和 GetNextPlayer
  87. #ifdef _SERVER
  88. unsigned long m_ulNextSaveTime;
  89. unsigned long m_ulDelayTimePerSave; //1mins
  90. unsigned long m_ulMaxSaveTimePerPlayer; //30mins
  91. #endif
  92. public:
  93. KLevelAdd m_cLevelAdd;
  94. KTeamLeadExp m_cLeadExp;
  95. KNewPlayerAttribute m_cNewPlayerAttribute;
  96. STONG_CREATE_PARAM m_sTongParam;
  97. #ifdef _SERVER
  98. KPK_DEATH_PUNISH_PARAM m_sPKPunishParam[MAX_DEATH_PUNISH_PK_VALUE + 1]; // PK惩罚参数
  99. #endif
  100. public:
  101. KPlayerSet();
  102. BOOL Init();
  103. int FindSame(DWORD dwID);
  104. int GetFirstPlayer(); // 遍历所有玩家第一步
  105. int GetNextPlayer(); // 遍历所有玩家下一步(这支函数必须在上一支调用之后才能调用)
  106. int GetOnlinePlayerCount() { return m_UseIdx.GetCount(); }
  107. // int FindClient(int nClient);
  108. #ifdef _SERVER
  109. void Activate();
  110. int Add(LPSTR szPlayerID, void* pGuid);
  111. void PrepareRemove(int nClientIdx);
  112. void PrepareExchange(int nIndex);
  113. void PrepareLoginFailed(int nIndex);
  114. void RemoveQuiting(int nIndex);
  115. void RemoveLoginTimeOut(int nIndex);
  116. void RemoveExchanging(int nIndex);
  117. void AutoSave();
  118. void ProcessClientMessage(int nClient, const char* pChar, int nSize);
  119. int GetPlayerNumber() { return m_nNumPlayer; }
  120. BOOL GetPlayerName(int nClient, char* szName);
  121. BOOL GetPlayerAccount(int nClient, char* szName);
  122. int Broadcasting(char* pMessage, int nLen);
  123. void SetSaveBufferPtr(void* pData);
  124. int AttachPlayer(const unsigned long lnID, GUID* pGuid);
  125. int GetPlayerIndexByGuid(GUID* pGuid);
  126. #endif
  127. private:
  128. int FindFree();
  129. #ifdef _SERVER
  130. //welcome message deliver
  131. public:
  132. void ReloadWelcomeMsg();
  133. private:
  134. void SendWelcomeMsg(int nPlayerIndex);
  135. void* m_pWelcomeMsg;
  136. private:
  137. int m_nNumPlayer;
  138. #endif
  139. };
  140. extern KPlayerSet PlayerSet;
  141. #endif //KPlayerSetH