ProcessMonster.cpp
上传用户:szopptop
上传日期:2013-04-23
资源大小:1047k
文件大小:6k
源码类别:

模拟服务器

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. CMirMap* GetMap(char *pszMapName);
  3. CMonsterObject* AddCreature(CMirMap* pMap, int nX, int nY, int nMonRace, BOOL fSearch)
  4. {
  5. CMonsterObject* pMonsterObject = NULL;
  6. switch(g_pMonRaceInfo[nMonRace].wRaceIndex)
  7. {
  8. case _ANIMAL_DEER:
  9. pMonsterObject = (CMonsterObject*)new CAnimalObject; break;
  10. case _MONSTER_STICK: // 侥牢檬
  11. pMonsterObject = (CMonsterObject*)new CStickObject; break;
  12. case _MONSTER_SANDMOB: // 籍厘牢
  13. pMonsterObject = (CMonsterObject*)new CSandMobObject; break;
  14. case _MONSTER_RON: // 沸
  15. pMonsterObject = (CMonsterObject*)new CRonObject; break;
  16. case _MONSTER_SCULTURE1: // 林付脚厘, 林付龋过
  17. case _MONSTER_SCULTURE2:
  18. pMonsterObject = (CMonsterObject*)new CScultureObject; break;
  19. case _MONSTER_BEEQUEEN: // 厚阜盔面
  20. pMonsterObject = (CMonsterObject*)new CBeeQueen; break;
  21. case _MONSTER_SCULTUREKING: // 林付空
  22. pMonsterObject = (CMonsterObject*)new CScultureKingObject; break;
  23. case _MONSTER_DUALAXE: // 街档尝秦榜
  24. pMonsterObject = (CMonsterObject*)new CDualAxeObject; break;
  25. case _MONSTER_MAGUNGSA: // 付泵荤
  26. pMonsterObject = (CMonsterObject*)new CDualAxeObject(6); break;
  27. case _MONSTER_THONEDARK: // 促农
  28. pMonsterObject = (CMonsterObject*)new CDualAxeObject(3); break;
  29. case _MONSTER_LIGHTZOMBI:
  30. pMonsterObject = (CMonsterObject*)new CLightingZombiObject; break;
  31. case _MONSTER_ROCKMAN: // 荤鲍
  32. pMonsterObject = (CMonsterObject*)new CRockManObject; break;
  33. case _MONSTER_MINORNUMA:
  34. pMonsterObject = (CMonsterObject*)new CMinorNumaObject; break;
  35. case _MONSTER_WHITESKELETON: // 归榜
  36. pMonsterObject = (CMonsterObject*)new CWhiteSkeleton; break;
  37. case _MONSTER_ELFMONSTER: // 脚荐 函脚 傈 
  38. pMonsterObject = (CMonsterObject*)new CElfMonster; break;
  39. case _MONSTER_ELFWARRIOR: // 脚荐 函脚 饶 
  40. pMonsterObject = (CMonsterObject*)new CElfWarriorMonster; break;
  41. case _MONSTER_SPITSPIDER: // 魔芭固
  42. pMonsterObject = (CMonsterObject*)new CSpitSpiderMonster; break;
  43. case _MONSTER_OMA:
  44. case _MONSTER_OMAKNIGHT:
  45. case _MONSTER_OMAWARRIOR:
  46. pMonsterObject = (CMonsterObject*)new COmaObject; break;
  47. default:
  48. pMonsterObject = (CMonsterObject*)new CGenneralMonObject;
  49. // pMonsterObject = (CMonsterObject*)new CChickenObject;
  50. break;
  51. }
  52. if (pMonsterObject)
  53. {
  54. if (fSearch)
  55. pMonsterObject->GetAvailablePosition(pMap, nX, nY, 10);
  56. pMonsterObject->m_nCurrX = nX;
  57. pMonsterObject->m_nCurrY = nY;
  58. pMonsterObject->m_nDirection = rand() % 8;
  59. pMonsterObject->m_pMap = pMap;
  60. pMonsterObject->m_nRace = nMonRace;
  61. pMonsterObject->Initialize();
  62. pMap->AddNewObject(nX, nY, OS_MOVINGOBJECT, pMonsterObject);
  63. if (!pMonsterObject->m_fHideMode)
  64. pMonsterObject->AddRefMsg(RM_TURN, pMonsterObject->m_nDirection, nX, nY, 0, pMonsterObject->m_szName);
  65. return pMonsterObject;
  66. }
  67. return NULL;
  68. }
  69. BOOL RegenMonster(CMonsterGenInfo* pMonGenInfo, int nCount)
  70. {
  71. DWORD dwStart = GetTickCount();
  72. for (int i = 0; i < nCount; i++)
  73. {
  74. int nX = pMonGenInfo->nX - pMonGenInfo->nAreaX + (rand() % (pMonGenInfo->nAreaX * 2 + 1));
  75. int nY = pMonGenInfo->nY - pMonGenInfo->nAreaY + (rand() % (pMonGenInfo->nAreaY * 2 + 1));
  76. if (CMonsterObject* pMonsterObject = AddCreature(GetMap(pMonGenInfo->szMapName), nX, nY, pMonGenInfo->nMonIndex, TRUE))
  77. pMonGenInfo->xMonsterObjList.AddNewNode(pMonsterObject);
  78. if (GetTickCount() - dwStart > 3000/*ZenLimitTime*/)
  79. break;
  80. }
  81. return TRUE;
  82. }
  83. DWORD GetZenTime(DWORD dwZenTime)
  84. {
  85. if (dwZenTime < 30 * 60 * 1000)
  86. {
  87. return dwZenTime;
  88. /*      if ztime < 30 * 60 * 1000 then begin
  89.          r := (GetUserCount - UserFullCount) / ZenFastStep;  //概 200疙捞 疵锭付促 10%究 各阑 歹 哩 矫糯
  90.          if r > 0 then begin
  91.             if r > 6 then r := 6;
  92.             Result := ztime - Round ((ztime/10) * r);
  93.          end else
  94.             Result := ztime;
  95.       end else
  96.          Result := ztime; */
  97. }
  98. return dwZenTime;
  99. }
  100. UINT WINAPI ProcessMonster(LPVOID lpParameter)
  101. {
  102. int nCurrMonGen = 0;
  103. DWORD dwCurrentTick = GetTickCount();
  104. while (TRUE)
  105. {
  106. if (g_fTerminated) 
  107. {
  108. return 0L;
  109. }
  110. /* Generate Monster
  111. if (GetTickCount() - dwLastGenTick > 200)
  112. {
  113. dwLastGenTick = GetTickCount();
  114. if (nCurrMonGen < g_nNumOfMonGenInfo - 1) 
  115. nCurrMonGen++;
  116. else
  117. nCurrMonGen = 0;
  118. CMonsterGenInfo* pMonGenInfo = &g_pMonGenInfo[nCurrMonGen];
  119. if (pMonGenInfo)
  120. {
  121. if ((pMonGenInfo->dwStartTime == 0) || ((dwLastGenTick - pMonGenInfo->dwStartTime) > GetZenTime(pMonGenInfo->dwZenTime)))
  122. {
  123. if (pMonGenInfo->nCount > (int)pMonGenInfo->xMonsterObjList.GetCount())
  124. {
  125. if (RegenMonster(pMonGenInfo, pMonGenInfo->nCount - pMonGenInfo->xMonsterObjList.GetCount()))
  126. pMonGenInfo->dwStartTime = GetTickCount();
  127. }
  128. }
  129. }
  130. }
  131. */
  132. // Execute Monster A.I
  133. for (int i = 0; i < g_nNumOfMonGenInfo + 1; i++)
  134. {
  135. CMonsterGenInfo* pMonGenInfo = &g_pMonGenInfo[i];
  136. if (pMonGenInfo)
  137. {
  138. if (pMonGenInfo->xMonsterObjList.GetCount())
  139. {
  140. PLISTNODE pListNode = pMonGenInfo->xMonsterObjList.GetHead();
  141. while (pListNode)
  142. {
  143. CMonsterObject* pMonsterObject = pMonGenInfo->xMonsterObjList.GetData(pListNode);
  144. if (pMonsterObject)
  145. {
  146. dwCurrentTick = GetTickCount();
  147. if (!pMonsterObject->m_fIsGhost)
  148. {
  149. if (dwCurrentTick - pMonsterObject->m_dwRunTime >= pMonsterObject->m_dwRunNextTick)
  150. {
  151. pMonsterObject->m_dwRunTime = dwCurrentTick;
  152. if (dwCurrentTick - pMonsterObject->m_dwSearchTime >= pMonsterObject->m_dwSearchTick)
  153. {
  154. pMonsterObject->m_dwSearchTime = dwCurrentTick;
  155. pMonsterObject->SearchViewRange();
  156. }
  157. pMonsterObject->Operate();
  158. }
  159. }
  160. else
  161. {
  162. if (GetTickCount() - pMonsterObject->m_dwGhostTime > 3 * 60 * 1000)
  163. {
  164. delete pMonsterObject;
  165. pMonsterObject = NULL;
  166. pListNode = pMonGenInfo->xMonsterObjList.RemoveNode(pListNode);
  167. continue;
  168. }
  169. }
  170. }
  171. pListNode = pMonGenInfo->xMonsterObjList.GetNext(pListNode);
  172. } // while (pListNode)
  173. }
  174. } // if (pMonGenInfo)
  175. }
  176. SleepEx(1, TRUE);
  177. }
  178. return 0L;
  179. }