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

模拟服务器

开发平台:

C/C++

  1. #include "KCore.h"
  2. #ifndef WM_MOUSEHOVER
  3. #define WM_MOUSEHOVER 0x02A1
  4. #endif
  5. #include "KEngine.h"
  6. #ifdef _SERVER
  7. //#include "KNetServer.h"
  8. //#include "../MultiServer/Heaven/Interface/iServer.h"
  9. #else
  10. //#include "KNetClient.h"
  11. #include "../../Headers/IClient.h"
  12. #include "Scene/KScenePlaceC.h"
  13. #include "KIme.h"
  14. #endif
  15. #include "KNpc.h"
  16. #include "KObj.h"
  17. #include "KNpcSet.h"
  18. #include "KSubWorld.h"
  19. #include "KPlayer.h"
  20. #include "LuaFuns.h"
  21. #include "KSortScript.h"
  22. #include "KScriptValueSet.h"
  23. #include "KObjSet.h"
  24. #include "KSkills.h"
  25. #include "KPlayerSet.h"
  26. #include "KSubWorldSet.h"
  27. #include "KFile.h"
  28. #include "GameDataDef.h"
  29. #include "KBuySell.h"
  30. //#include "MyAssert.h"
  31. #include "MsgGenreDef.h"
  32. #include "KItemSet.h"
  33. #include "KTaskFuns.h"
  34. #include "Text.h"
  35. #ifdef _SERVER
  36. #ifndef _STANDALONE
  37. #include "../../../lib/S3DBInterface.h"
  38. #else
  39. #include "S3DBInterface.h"
  40. #endif
  41. #else
  42. #include "CoreShell.h"
  43. #endif
  44. extern int LuaGetNpcTalk(Lua_State *L);
  45. #define defPLAYER_LOGIN_TIMEOUT 10 * 20// 10 sec
  46. #define defPLAYER_SAVE_TIMEOUT 30 * 20
  47. #define PLAYER_LEVEL_1_EXP 48
  48. #define PLAYER_LEVEL_ADD_ATTRIBUTE 5
  49. #define PLAYER_LEVEL_ADD_SKILL 1
  50. #define PLAYER_SHARE_EXP_DISTANCE 768
  51. #define PLAYER_TEAM_EXP_ADD 50
  52. #define MAX_APPLY_TEAM_TIME 500
  53. #define BASE_WALK_SPEED 5
  54. #define BASE_RUN_SPEED 10
  55. #define BASE_FIRE_RESIST_MAX 75
  56. #define BASE_COLD_RESIST_MAX 75
  57. #define BASE_POISON_RESIST_MAX 75
  58. #define BASE_LIGHT_RESIST_MAX 75
  59. #define BASE_PHYSICS_RESIST_MAX 75
  60. #define BASE_ATTACK_SPEED 20
  61. #define BASE_CAST_SPEED 20
  62. #define BASE_VISION_RADIUS 120
  63. #define BASE_HIT_RECOVER 6
  64. #define TOWN_PORTAL_TIME 1800
  65. KPlayer Player[MAX_PLAYER];
  66. int g_nLastNetMsgLoop;
  67. //-------------------------------------------------------------------------
  68. // 功能:构造函数
  69. //-------------------------------------------------------------------------
  70. KPlayer::KPlayer()
  71. {
  72. Release();
  73. }
  74. //-------------------------------------------------------------------------
  75. // 功能:析构函数
  76. //-------------------------------------------------------------------------
  77. KPlayer::~KPlayer()
  78. {
  79. Release();
  80. }
  81. //-------------------------------------------------------------------------
  82. // 功能:清空
  83. //-------------------------------------------------------------------------
  84. void KPlayer::Release()
  85. {
  86. #ifndef _SERVER
  87. m_RunStatus = 0;
  88. m_dwNextLevelLeadExp = 0;
  89. m_nLeftSkillID = 0;
  90. m_nLeftSkillLevel = 0;
  91. m_nRightSkillID = 0;
  92. m_nRightSkillLevel = 0;
  93. m_nSendMoveFrames = defMAX_PLAYER_SEND_MOVE_FRAME;
  94. m_MouseDown[0] = FALSE;
  95. m_MouseDown[1] = FALSE;
  96. #endif
  97. m_dwID = 0;
  98. m_nIndex = 0;
  99. m_nNetConnectIdx = -1;
  100. m_cMenuState.Release();
  101. m_cTrade.Release();
  102. m_nAttributePoint = 0;
  103. m_nSkillPoint = 0;
  104. m_nStrength = 0;
  105. m_nDexterity = 0;
  106. m_nVitality = 0;
  107. m_nEngergy = 0;
  108. m_nLucky = 0;
  109. m_nCurStrength = 0;
  110. m_nCurDexterity = 0;
  111. m_nCurVitality = 0;
  112. m_nCurEngergy = 0;
  113. m_nCurLucky = 0;
  114. m_btChatSpecialChannel = 0;
  115. m_nExp = 0;
  116. m_nNextLevelExp = PLAYER_LEVEL_1_EXP;
  117. m_bExchangeServer = FALSE;
  118. m_dwLeadExp = 0;
  119. m_dwLeadLevel = 1;
  120. m_nPeapleIdx = 0;
  121. m_nObjectIdx = 0;
  122. m_bWaitingPlayerFeedBack = false;
  123. m_btTryExecuteScriptTimes = 0; //
  124. #ifdef _SERVER
  125. m_bUseReviveIdWhenLogin = 0;
  126. m_dwDeathScriptId = 0;
  127. m_sLoginRevivalPos.m_nSubWorldID = 0;
  128. m_sLoginRevivalPos.m_nMpsX = 0;
  129. m_sLoginRevivalPos.m_nMpsY = 0;
  130. m_sDeathRevivalPos.m_nSubWorldID = 0;
  131. m_sDeathRevivalPos.m_nMpsX = 0;
  132. m_sDeathRevivalPos.m_nMpsY = 0;
  133. m_sPortalPos.m_nSubWorldId = 0;
  134. m_sPortalPos.m_nTime = 0;
  135. m_sPortalPos.m_nMpsX = 0;
  136. m_sPortalPos.m_nMpsY = 0;
  137. m_pLastScriptCacheNode = NULL;
  138. m_dwLoginTime = -1;
  139. // m_uLastPingTime = -1;
  140. m_bFinishLoading = FALSE;
  141. m_uMustSave = SAVE_IDLE;
  142. m_bIsQuiting = FALSE;
  143. m_TimerTask.SetOwner(this);
  144. m_bSleepMode = FALSE;
  145. m_nLastNetOperationTime = 0;
  146. m_nPrePayMoney = 0;
  147. m_nForbiddenFlag = 0;
  148. m_nExtPoint = 0;
  149. m_nChangeExtPoint = 0;
  150. // ZeroMemory(m_SaveBuffer, sizeof(m_SaveBuffer));
  151. #endif
  152. }
  153. //-------------------------------------------------------------------------
  154. // 功能:设定 m_nPlayerIndex (本函数只允许在PlayerSet的Init中调用)
  155. //-------------------------------------------------------------------------
  156. void KPlayer::SetPlayerIndex(int nNo)
  157. {
  158. if (nNo < 0)
  159. m_nPlayerIndex = 0;
  160. else
  161. m_nPlayerIndex = nNo;
  162. }
  163. //-------------------------------------------------------------------------
  164. // 功能:获得本实例在 Player 数组中的位置
  165. //-------------------------------------------------------------------------
  166. int KPlayer::GetPlayerIndex()
  167. {
  168. return m_nPlayerIndex;
  169. }
  170. //-------------------------------------------------------------------------
  171. // 功能:玩家每次游戏循环都需要处理的东西
  172. //-------------------------------------------------------------------------
  173. void KPlayer::Active()
  174. {
  175. #ifdef _SERVER
  176. if (m_nNetConnectIdx == -1 || m_bExchangeServer)
  177. return;
  178. //时间任务的处理
  179. m_TimerTask.Activate(g_PlayerTimerCallBackFun);
  180. this->SendCurNormalSyncData();
  181. this->m_cChat.TimerAdd();
  182. // 仇杀倒计时
  183. this->m_cPK.Active();
  184. #define defMAX_SLEEP_TIME 3600
  185. if (Npc[m_nIndex].m_FightMode == 0 && m_bSleepMode == FALSE && g_SubWorldSet.GetGameTime() - m_nLastNetOperationTime > defMAX_SLEEP_TIME)
  186. {
  187. NPC_SLEEP_SYNC SleepSync;
  188. SleepSync.ProtocolType = s2c_npcsleepmode;
  189. SleepSync.bSleep = 1;
  190. SleepSync.NpcID = Npc[m_nIndex].m_dwID;
  191. Npc[m_nIndex].SendDataToNearRegion(&SleepSync, sizeof(NPC_SLEEP_SYNC));
  192. m_bSleepMode = TRUE;
  193. }
  194. #else
  195. // 队伍申请人的处理
  196. if ( !m_cTeam.m_nFlag )
  197. {
  198. if (m_cTeam.m_nApplyCaptainID > 0)
  199. {
  200. if ( m_cTeam.m_dwApplyTimer == 0 )
  201. {
  202. m_cTeam.m_nApplyCaptainID = 0;
  203. }
  204. else
  205. {
  206. m_cTeam.m_dwApplyTimer--;
  207. if ( !NpcSet.SearchID(m_cTeam.m_nApplyCaptainID) )
  208. {
  209. m_cTeam.m_nApplyCaptainID = 0;
  210. m_cTeam.m_dwApplyTimer = 0;
  211. }
  212. }
  213. }
  214. }
  215. // 队长的处理
  216. else if (m_cTeam.m_nFigure == TEAM_CAPTAIN)
  217. {
  218. for (int i = 0; i < MAX_TEAM_APPLY_LIST; i++)
  219. {
  220. if (m_cTeam.m_sApplyList[i].m_dwNpcID > 0)
  221. {
  222. if (m_cTeam.m_sApplyList[i].m_dwTimer == 0)
  223. {
  224. m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
  225. m_cTeam.UpdateInterface();
  226. }
  227. else
  228. {
  229. m_cTeam.m_sApplyList[i].m_dwTimer--;
  230. if ( !Npc[this->m_nIndex].SearchAroundID(m_cTeam.m_sApplyList[i].m_dwNpcID) )
  231. {
  232. m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
  233. m_cTeam.m_sApplyList[i].m_dwTimer = 0;
  234. m_cTeam.UpdateInterface();
  235. }
  236. }
  237. }
  238. }
  239. }
  240. m_nSendMoveFrames++;
  241. // 仇杀倒计时
  242. this->m_cPK.Active();
  243. #endif
  244. }
  245. void KPlayer::ProcessMsg(KWorldMsgNode *lpMsg)
  246. {
  247. switch (lpMsg->m_dwMsgType)
  248. {
  249. case GWM_PLAYER_SKILL:
  250. break;
  251. case GWM_PLAYER_RUNTO:
  252. break;
  253. case GWM_PLAYER_WALKTO:
  254. break;
  255. case GWM_PLAYER_JUMPTO:
  256. break;
  257. default:
  258. break;
  259. }
  260. }
  261. #ifndef _SERVER
  262. void KPlayer::ProcessInputMsg(UINT uMsg, WPARAM wParam, LPARAM lParam)
  263. {
  264. switch(uMsg)
  265. {
  266. case WM_MOUSEMOVE:
  267. case WM_MOUSEHOVER:
  268. if (wParam & MK_LBUTTON)
  269. OnButtonMove(LOWORD(lParam), HIWORD(lParam),
  270. (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_left);
  271. else if (wParam & MK_RBUTTON)
  272. OnButtonMove(LOWORD(lParam), HIWORD(lParam),
  273. (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_right);
  274. else
  275. OnMouseMove(LOWORD(lParam), HIWORD(lParam));
  276. break;
  277. case WM_LBUTTONUP:
  278. OnButtonUp(LOWORD(lParam), HIWORD(lParam), button_left);
  279. break;
  280. case WM_LBUTTONDOWN:
  281. OnButtonDown(LOWORD(lParam), HIWORD(lParam), 
  282. (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_left);
  283. break;
  284. case WM_RBUTTONUP:
  285. OnButtonUp(LOWORD(lParam), HIWORD(lParam), button_right);
  286. break;
  287. case WM_RBUTTONDOWN:
  288. OnButtonDown(LOWORD(lParam), HIWORD(lParam),
  289. (wParam & ~(MK_LBUTTON | MK_MBUTTON | MK_RBUTTON)), button_right);
  290. break;
  291. }
  292. }
  293. void KPlayer::OnButtonDown(int x,int y, int Key, MOUSE_BUTTON nButton)
  294. {
  295. m_MouseDown[(int)nButton] = TRUE;
  296. FindSelectNpc(x, y, relation_all);
  297. FindSelectObject(x, y);
  298. // Npc[m_nIndex].m_nPeopleIdx = m_nPeapleIdx;
  299. ProcessMouse(x, y, Key, nButton);
  300. }
  301. void KPlayer::OnButtonMove(int x,int y,int Key, MOUSE_BUTTON nButton)
  302. {
  303. if (m_MouseDown[(int)nButton])
  304. {
  305. ProcessMouse(x, y, Key, nButton);
  306. }
  307. }
  308. void KPlayer::OnButtonUp(int x,int y,MOUSE_BUTTON nButton)
  309. {
  310. m_MouseDown[(int)nButton] = 0;
  311. }
  312. void KPlayer::OnMouseMove(int x,int y)
  313. {
  314. m_nPeapleIdx = 0;
  315. m_nObjectIdx = 0;
  316. FindSelectNpc(x, y, relation_all);
  317. FindSelectObject(x, y);
  318. if (m_nPeapleIdx)
  319. {
  320. if (Npc[m_nPeapleIdx].m_Kind == kind_dialoger)
  321. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_DIALOG);
  322. else if (NpcSet.GetRelation(m_nIndex, m_nPeapleIdx) == relation_enemy)
  323. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_FIGHT);
  324. else
  325. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_NORMAL);
  326. }
  327. else if (m_nObjectIdx)
  328. {
  329. if (Object[m_nObjectIdx].m_nKind == Obj_Kind_MapObj)
  330. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_DIALOG);
  331. else if (Object[m_nObjectIdx].m_nKind == Obj_Kind_Item || Object[m_nObjectIdx].m_nKind == Obj_Kind_Money)
  332. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_PICK);
  333. else if (Object[m_nObjectIdx].m_nKind == Obj_Kind_Prop)
  334. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_USE);
  335. }
  336. else
  337. CoreDataChanged(GDCNI_SWITCH_CURSOR, NULL, MOUSE_CURSOR_NORMAL);
  338. }
  339. void KPlayer::ProcessMouse(int x, int y, int Key, MOUSE_BUTTON nButton)
  340. {
  341. if (CheckTrading())
  342. return;
  343. if (m_ItemList.m_Hand > 0)
  344. {
  345. if (nButton == button_left)
  346. {
  347. ThrowAwayItem();
  348. return;
  349. }
  350. }
  351. int nX = x;
  352. int nY = y;
  353. int nZ = 0;
  354. g_ScenePlace.ViewPortCoordToSpaceCoord(nX, nY, nZ);
  355. /* if (Key & MK_SHIFT)
  356. {
  357. Npc[m_nIndex].SendCommand(do_jump, nX, nY);
  358. SendClientCmdJump(nX, nY);
  359. return;
  360. }*/
  361. if (Npc[m_nIndex].IsCanInput())
  362. {
  363. int nIdx = 0;
  364. if (nButton == button_right)
  365. {
  366. nIdx = Npc[m_nIndex].m_SkillList.FindSame(m_nRightSkillID);
  367. g_DebugLog("[skill]right");
  368. }
  369. else
  370. {
  371. nIdx = Npc[m_nIndex].m_SkillList.FindSame(m_nLeftSkillID);
  372. g_DebugLog("[skill]left");
  373. }
  374. Npc[m_nIndex].SetActiveSkill(nIdx);
  375. }
  376. else
  377. {
  378. g_DebugLog("[skill]return");
  379. Npc[m_nIndex].m_nPeopleIdx = 0;
  380. return;
  381. }
  382. if ((Key & MK_SHIFT) || (nButton == button_right))
  383. {
  384. if (Npc[m_nIndex].m_ActiveSkillID > 0)
  385. {
  386. ISkill * pISkill = (KSkill *) g_SkillManager.GetSkill(Npc[m_nIndex].m_ActiveSkillID, 1);
  387. if (!pISkill) 
  388.                 return;
  389. if (pISkill->IsAura())
  390. return;
  391. int nAttackRange = pISkill->GetAttackRadius();
  392. int nTargetIdx = 0;
  393. // m_nPeapleIdx = 0;
  394. //按照Object / Enemy / Ally 的优先级找到需要打的对象id
  395. if (pISkill->IsTargetAlly())
  396. {
  397. FindSelectNpc(x, y, relation_ally);
  398. if (m_nPeapleIdx)
  399. {
  400. nTargetIdx = m_nPeapleIdx;
  401. }
  402. }
  403. if (pISkill->IsTargetEnemy())
  404. {
  405. FindSelectNpc(x, y, relation_enemy);
  406. if (m_nPeapleIdx)
  407. {
  408. nTargetIdx = m_nPeapleIdx;
  409. }
  410. }
  411. if (pISkill->IsTargetObj())
  412. {
  413. FindSelectObject(x, y);
  414. if (m_nObjectIdx)
  415. {
  416. nTargetIdx = m_nObjectIdx;
  417. }
  418. }
  419. //如果技能必须指定对象,而当前位置无对象的话,直接退出
  420. if (pISkill->IsTargetOnly() && !nTargetIdx)
  421.             {
  422. Npc[m_nIndex].m_nPeopleIdx = 0;
  423. m_nPeapleIdx = 0;
  424. return;
  425. }
  426. if (m_nIndex == nTargetIdx)
  427. {
  428. Npc[m_nIndex].m_nPeopleIdx = 0;
  429. m_nPeapleIdx = 0;
  430. return;
  431. }
  432. if ((!Npc[m_nIndex].m_SkillList.CanCast(Npc[m_nIndex].m_ActiveSkillID, SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_dwCurrentTime))
  433. ||
  434. (!Npc[m_nIndex].Cost(pISkill->GetSkillCostType() , pISkill->GetSkillCost(&Npc[m_nIndex]), TRUE))
  435. )
  436. {
  437. Npc[m_nIndex].m_nPeopleIdx = 0;
  438. m_nPeapleIdx = 0;
  439. return ;
  440. }
  441. //无对象,直接发坐标
  442. if (!nTargetIdx)
  443. {
  444. Npc[m_nIndex].SendCommand(do_skill, Npc[m_nIndex].m_ActiveSkillID, nX, nY);
  445. // Send to Server
  446. SendClientCmdSkill(Npc[m_nIndex].m_ActiveSkillID, nX, nY);
  447. }
  448. else
  449. {
  450. if (pISkill->IsTargetOnly())
  451. {
  452. int distance = NpcSet.GetDistance(m_nIndex , nTargetIdx);
  453. if (distance > pISkill->GetAttackRadius())
  454. {
  455. m_nPeapleIdx = nTargetIdx;
  456. return ;
  457. }
  458. }
  459. // 
  460. if (m_nIndex == nTargetIdx && pISkill->GetSkillStyle() == SKILL_SS_Missles) 
  461. return ;
  462. Npc[m_nIndex].SendCommand(do_skill, Npc[m_nIndex].m_ActiveSkillID, -1, nTargetIdx);
  463. // Send to Server
  464. SendClientCmdSkill(Npc[m_nIndex].m_ActiveSkillID, -1, Npc[nTargetIdx].m_dwID);
  465. }
  466. }
  467. Npc[m_nIndex].m_nPeopleIdx = 0;
  468. return;
  469. }
  470. if (Key == 0 )
  471. {
  472. int nRelation = NpcSet.GetRelation(m_nIndex, m_nPeapleIdx);
  473. if(nRelation == relation_enemy || nRelation == relation_dialog)
  474. {
  475. Npc[m_nIndex].m_nPeopleIdx = m_nPeapleIdx;
  476. }
  477. if (m_nSendMoveFrames >= defMAX_PLAYER_SEND_MOVE_FRAME)
  478. {
  479. m_nPickObjectIdx = m_nObjectIdx;
  480. Npc[m_nIndex].m_nObjectIdx = m_nPickObjectIdx;
  481. if (!m_RunStatus)
  482. {
  483. Npc[m_nIndex].SendCommand(do_walk, nX, nY);
  484. // Send to Server
  485. SendClientCmdWalk(nX, nY);
  486. }
  487. else
  488. {
  489. Npc[m_nIndex].SendCommand(do_run, nX, nY);
  490. // Send to Server
  491. SendClientCmdRun(nX, nY);
  492. }
  493. m_nSendMoveFrames = 0;
  494. }
  495. return;
  496. }
  497. /* if (Key & MK_ALT)
  498. {
  499. Npc[m_nIndex].SendCommand(do_jump, nX, nY);
  500. SendClientCmdJump(nX, nY);
  501. }*/
  502. }
  503. void KPlayer::Walk(int nDir, int nSpeed)
  504. {
  505. int nMapX = Npc[m_nIndex].m_MapX;
  506. int nMapY = Npc[m_nIndex].m_MapY;
  507. int nOffX = Npc[m_nIndex].m_OffX;
  508. int nOffY = Npc[m_nIndex].m_OffY;
  509. int nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
  510. int nRegion = Npc[m_nIndex].m_RegionIndex;
  511. int nX, nY;
  512. SubWorld[nSubWorld].Map2Mps(nRegion, nMapX, nMapY, nOffX, nOffY, &nX, &nY);
  513. SubWorld[nSubWorld].GetMps(&nX, &nY, nSpeed * 2, nDir);
  514. if (m_RunStatus)
  515. {
  516. Npc[m_nIndex].SendCommand(do_run, nX, nY);
  517. // Send to Server
  518. if ( !CheckTrading() )
  519. SendClientCmdRun(nX, nY);
  520. }
  521. else
  522. {
  523. Npc[m_nIndex].SendCommand(do_walk, nX, nY);
  524. // Send to Server
  525. if (!CheckTrading())
  526. SendClientCmdWalk(nX, nY);
  527. }
  528. }
  529. void KPlayer::TurnLeft()
  530. {
  531. if (Npc[m_nIndex].m_Doing != do_stand &&
  532. Npc[m_nIndex].m_Doing != do_sit)
  533. return;
  534. if (Npc[m_nIndex].m_Dir > 8)
  535. Npc[m_nIndex].m_Dir -= 8;
  536. else
  537. Npc[m_nIndex].m_Dir = MAX_NPC_DIR - 1;
  538. }
  539. void KPlayer::TurnRight()
  540. {
  541. if (Npc[m_nIndex].m_Doing != do_stand &&
  542. Npc[m_nIndex].m_Doing != do_sit)
  543. return;
  544. if (Npc[m_nIndex].m_Dir < MAX_NPC_DIR - 9)
  545. Npc[m_nIndex].m_Dir += 8;
  546. else
  547. Npc[m_nIndex].m_Dir = 0;
  548. }
  549. void KPlayer::TurnBack()
  550. {
  551. if (Npc[m_nIndex].m_Doing != do_stand &&
  552. Npc[m_nIndex].m_Doing != do_sit)
  553. return;
  554. if (Npc[m_nIndex].m_Dir < MAX_NPC_DIR / 2)
  555. Npc[m_nIndex].m_Dir += MAX_NPC_DIR / 2;
  556. else
  557. Npc[m_nIndex].m_Dir -= MAX_NPC_DIR / 2;
  558. }
  559. void KPlayer::FindSelectNpc(int x, int y, int nRelation)
  560. {
  561. int nNpcIdx = 0;
  562. nNpcIdx = NpcSet.SearchNpcAt(x, y, nRelation, 40);
  563. if (nNpcIdx)
  564. m_nPeapleIdx = nNpcIdx;
  565. else
  566. m_nPeapleIdx = 0;
  567. }
  568. void KPlayer::FindSelectObject(int x, int y)
  569. {
  570. int nObjIdx = 0;
  571. nObjIdx = ObjSet.SearchObjAt(x, y, 40);
  572. if (nObjIdx)
  573. m_nObjectIdx = nObjIdx;
  574. else
  575. m_nObjectIdx = 0;
  576. }
  577. // need change
  578. int KPlayer::NetCommandPlayerTalk(BYTE * pProtocol)
  579. {
  580. /* DWORD dwNpcID;
  581. int nSize;
  582. dwNpcID = *(DWORD *) &pProtocol[1];
  583. nSize = pProtocol[5];
  584. int nIdx = NpcSet.SearchID(dwNpcID);
  585.   if (ConformIdx(nIdx))
  586.   {
  587. strcpy(Npc[nIdx].m_szChatBuffer, (char *)(pProtocol+6));
  588. Npc[nIdx].m_nCurChatTime = NPC_SHOW_CHAT_TIME_LENGTH;
  589. }
  590.   return (7 + nSize); // need test
  591. */
  592. return 0;
  593. }
  594. BOOL KPlayer::ConformIdx(int nIdx)
  595. {
  596. if (nIdx == m_nIndex || nIdx == 0)
  597. return FALSE;
  598. return TRUE;
  599. }
  600. #endif
  601. #ifdef _SERVER
  602. BOOL KPlayer::IsWaitingRemove()
  603. {
  604. if (!m_dwID)
  605. return FALSE;
  606. return m_bIsQuiting;
  607. }
  608. void KPlayer::WaitForRemove()
  609. {
  610. m_bIsQuiting = TRUE;
  611. }
  612. BOOL KPlayer::IsLoginTimeOut()
  613. {
  614. if (m_nNetConnectIdx != -1)
  615. return FALSE;
  616. if (!m_dwID)
  617. return FALSE;
  618. if (-1 != m_dwLoginTime &&
  619. g_SubWorldSet.GetGameTime() - m_dwLoginTime > defPLAYER_LOGIN_TIMEOUT)
  620. {
  621. // m_dwLoginTime = -1;
  622. return TRUE;
  623. }
  624. return FALSE;
  625. }
  626. void KPlayer::LoginTimeOut()
  627. {
  628. // 通知聊天好友自己下线了
  629. m_cChat.OffLine(m_dwID);
  630. m_pStatusLoadPlayerInfo = NULL;
  631. Release();
  632. }
  633. BOOL KPlayer::Save()
  634. {
  635. if (m_nIndex <= 0 && m_dwID == 0)
  636. return FALSE;
  637. /* if (m_uMustSave != SAVE_IDLE)
  638. return FALSE;
  639. */
  640. TRoleData* pData = (TRoleData *)m_SaveBuffer;
  641. if (UpdateDBPlayerInfo((BYTE *)pData) == -1)
  642. return FALSE;
  643. /*
  644. #ifdef _DEBUG
  645. KFile File;
  646. char szFileName[32];
  647. sprintf(szFileName, "d:\%sSave.Buf", m_PlayerName);
  648. File.Create(szFileName);
  649. File.Write(pData, pData->dwDataLen);
  650. File.Close();
  651. #endif
  652. */
  653. _ASSERT(pData->dwDataLen < sizeof(m_SaveBuffer));
  654. if (pData->dwDataLen <= 0)
  655. return FALSE;
  656. // m_uMustSave = SAVE_REQUEST;
  657. m_ulLastSaveTime = g_SubWorldSet.GetGameTime();
  658. return TRUE;
  659. }
  660. BOOL KPlayer::CanSave()
  661. {
  662. if (m_nNetConnectIdx == -1)
  663. return FALSE;
  664. if (m_nIndex <= 0)
  665. return FALSE;
  666. if (m_bExchangeServer)
  667. return FALSE;
  668. if (m_bIsQuiting)
  669. return FALSE;
  670. if (CheckTrading())
  671. {
  672. return FALSE;
  673. }
  674. if (m_uMustSave == SAVE_DOING && g_SubWorldSet.GetGameTime() - m_ulLastSaveTime > defPLAYER_SAVE_TIMEOUT)
  675. return TRUE;
  676. if (m_uMustSave != SAVE_IDLE)
  677. return FALSE;
  678. return TRUE;
  679. }
  680. BOOL KPlayer::SendSyncData(int &nStep, unsigned int &nParam)
  681. {
  682. BOOL bRet = FALSE;
  683. switch(nStep)
  684. {
  685. case STEP_BASE_INFO:
  686. {
  687. bRet = SubWorld[Npc[m_nIndex].m_SubWorldIndex].SendSyncData(m_nIndex, m_nNetConnectIdx);
  688. if (!bRet)
  689. {
  690. printf("SubWorld Fail.n");
  691. break;
  692. }
  693. bRet = Npc[m_nIndex].SendSyncData(m_nNetConnectIdx);
  694. if (!bRet)
  695. {
  696. printf("NPC Fail.n");
  697. break;
  698. }
  699. // 这个消息必须在同步世界NPC数据后做,使客户端能找到当前玩家在客户端的Npc索引
  700. CURPLAYER_SYNC sSync; // 同步当前玩家的自身独特信息给客户端(装备等)
  701. sSync.ProtocolType = (BYTE)s2c_synccurplayer;
  702. sSync.m_dwID = Npc[m_nIndex].m_dwID;
  703. sSync.m_btLevel = (DWORD)Npc[m_nIndex].m_Level;
  704. sSync.m_btSex = Npc[m_nIndex].m_nSex;
  705. sSync.m_btKind = Npc[m_nIndex].m_Kind;
  706. sSync.m_btSeries = Npc[m_nIndex].m_Series;
  707. sSync.m_wLifeMax = Npc[m_nIndex].m_LifeMax;
  708. sSync.m_wStaminaMax = Npc[m_nIndex].m_StaminaMax;
  709. sSync.m_wManaMax = Npc[m_nIndex].m_ManaMax;
  710. sSync.m_HeadImage = Npc[m_nIndex].m_HeadImage;
  711. sSync.m_wAttributePoint = this->m_nAttributePoint;
  712. sSync.m_wSkillPoint = this->m_nSkillPoint;
  713. sSync.m_wStrength = this->m_nStrength;
  714. sSync.m_wDexterity = this->m_nDexterity;
  715. sSync.m_wVitality = this->m_nVitality;
  716. sSync.m_wEngergy = this->m_nEngergy;
  717. sSync.m_wLucky = this->m_nLucky;
  718. sSync.m_nExp = this->m_nExp;
  719. sSync.m_dwLeadExp = this->m_dwLeadExp;
  720. sSync.m_btCurFaction = this->m_cFaction.m_nCurFaction;
  721. sSync.m_btFirstFaction = this->m_cFaction.m_nFirstAddFaction;
  722. sSync.m_nFactionAddTimes = this->m_cFaction.m_nAddTimes;
  723. sSync.m_wWorldStat = (WORD)m_nWorldStat;
  724. sSync.m_wSectStat = (WORD)m_nSectStat;
  725. sSync.m_nMoney1 = this->m_ItemList.GetMoney(room_equipment);
  726. sSync.m_nMoney2 = this->m_ItemList.GetMoney(room_repository);
  727. if (SUCCEEDED(g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(CURPLAYER_SYNC))))
  728. {
  729. bRet = TRUE;
  730. }
  731. else
  732. {
  733. printf("player Packing sync data failed...n");
  734. bRet = FALSE;
  735. break;
  736. }
  737. }
  738. break;
  739. case STEP_FIGHT_SKILL_LIST:
  740. {
  741. bRet = SendSyncData_Skill();
  742. }
  743. break;
  744. case STEP_LIFE_SKILL_LIST:
  745. bRet = TRUE;
  746. break;
  747. case STEP_ITEM_LIST:
  748. bRet = TRUE;
  749. break;
  750. case STEP_TASK_LIST:
  751. bRet = TRUE;
  752. break;
  753. case STEP_SYNC_END:
  754. bRet = TRUE;
  755. break;
  756. }
  757. if (!bRet)
  758. {
  759. printf("Load PlayerInfo Step %d Failed...n", nStep);
  760. }
  761. return bRet;
  762. }
  763. BOOL KPlayer::SendSyncData_Skill()
  764. {
  765. SKILL_SEND_ALL_SYNC sSkill;
  766. sSkill.ProtocolType = s2c_synccurplayerskill;
  767. sSkill.m_wProtocolLong = 2;
  768. int i;
  769. int j;
  770. for (i = 0,j = 0; i < MAX_NPCSKILL; i++)
  771. {
  772. sSkill.m_sAllSkill[i].SkillId = 0;
  773. sSkill.m_sAllSkill[i].SkillLevel = 0;
  774. if( Npc[m_nIndex].m_SkillList.m_Skills[i].SkillId <= 0)
  775. continue;
  776. sSkill.m_sAllSkill[j].SkillId = Npc[m_nIndex].m_SkillList.m_Skills[i].SkillId;
  777. sSkill.m_sAllSkill[j].SkillLevel = Npc[m_nIndex].m_SkillList.m_Skills[i].SkillLevel;
  778. j++;
  779. }
  780. sSkill.m_wProtocolLong += sizeof(SKILL_SEND_ALL_SYNC_DATA) * j;
  781. if (SUCCEEDED(g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSkill, sSkill.m_wProtocolLong + 1)))
  782. {
  783. return TRUE;
  784. }
  785. else
  786. {
  787. printf("player Packing skill sync data failed...n");
  788. return FALSE;
  789. }
  790. }
  791. void KPlayer::SendCurNormalSyncData()
  792. {
  793. CURPLAYER_NORMAL_SYNC sSync;
  794. sSync.ProtocolType = s2c_synccurplayernormal;
  795. sSync.m_shLife = Npc[m_nIndex].m_CurrentLife;
  796. sSync.m_shStamina = Npc[m_nIndex].m_CurrentStamina;
  797. sSync.m_shMana = Npc[m_nIndex].m_CurrentMana;
  798. sSync.m_shAngry = 0;
  799. if ( !m_cTeam.m_nFlag )
  800. sSync.m_btTeamData = 0;
  801. else
  802. {
  803. if (m_cTeam.m_nFigure == TEAM_CAPTAIN)
  804. sSync.m_btTeamData = 0x03;
  805. else
  806. sSync.m_btTeamData = 0x01;
  807. }
  808. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(CURPLAYER_NORMAL_SYNC));
  809. }
  810. void KPlayer::QuitGame(int nType)
  811. {
  812. Save();
  813. }
  814. void KPlayer::BuyItem(BYTE* pProtocol)
  815. {
  816. PLAYER_BUY_ITEM_COMMAND* pCommand = (PLAYER_BUY_ITEM_COMMAND *)pProtocol;
  817. BuySell.Buy(m_nPlayerIndex, m_BuyInfo.m_nBuyIdx, pCommand->m_BuyIdx, pCommand->m_Place, pCommand->m_X, pCommand->m_Y);
  818. }
  819. void KPlayer::SellItem(BYTE* pProtocol)
  820. {
  821. PLAYER_SELL_ITEM_COMMAND* pCommand = (PLAYER_SELL_ITEM_COMMAND *)pProtocol;
  822. BuySell.Sell(m_nPlayerIndex, m_BuyInfo.m_nBuyIdx, m_ItemList.SearchID(pCommand->m_ID));
  823. }
  824. #endif
  825. #ifdef _SERVER
  826. //-------------------------------------------------------------------------
  827. // 功能:获取玩家重生点位置
  828. //-------------------------------------------------------------------------
  829. void KPlayer::GetLoginRevivalPos(int *lpnSubWorld, int *lpnMpsX, int *lpnMpsY)
  830. {
  831. *lpnSubWorld = m_sLoginRevivalPos.m_nSubWorldID;
  832. *lpnMpsX = m_sLoginRevivalPos.m_nMpsX;
  833. *lpnMpsY = m_sLoginRevivalPos.m_nMpsY;
  834. }
  835. void KPlayer::GetDeathRevivalPos(int *lpnSubWorld, int *lpnMpsX, int *lpnMpsY)
  836. {
  837. *lpnSubWorld = m_sDeathRevivalPos.m_nSubWorldID;
  838. *lpnMpsX = m_sDeathRevivalPos.m_nMpsX;
  839. *lpnMpsY = m_sDeathRevivalPos.m_nMpsY;
  840. }
  841. #endif
  842. #ifdef _SERVER
  843. void KPlayer::SetTimer(DWORD nTime, int nTimerTaskId) //时间任务脚本,开启计时器
  844. {
  845. if (!nTime || !nTimerTaskId) return ;
  846. m_TimerTask.SetTimer(nTime, nTimerTaskId);
  847. }
  848. void KPlayer::CloseTimer() //关闭时间计时器
  849. {
  850. m_TimerTask.CloseTimer();
  851. }
  852. #endif
  853. #ifdef _SERVER
  854. //------------------------------------------------------------------------------
  855. // 功能:设定玩家重生点位置
  856. //------------------------------------------------------------------------------
  857. void KPlayer::SetRevivalPos(int nSubWorld, int nReviveId)
  858. {
  859. if (nSubWorld >= 0)  //如果小于0,表示沿用当前的
  860. {
  861. m_sLoginRevivalPos.m_nSubWorldID = nSubWorld;
  862. }
  863. else
  864. {
  865. m_sLoginRevivalPos.m_nSubWorldID = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_SubWorldID;
  866. }
  867. POINT Pos;
  868. g_SubWorldSet.GetRevivalPosFromId(m_sLoginRevivalPos.m_nSubWorldID, nReviveId, &Pos);
  869. m_sLoginRevivalPos.m_ReviveID = nReviveId;
  870. m_sLoginRevivalPos.m_nMpsX = Pos.x;
  871. m_sLoginRevivalPos.m_nMpsY = Pos.y;
  872. m_sDeathRevivalPos = m_sLoginRevivalPos;
  873. }
  874. #endif
  875. #ifdef _SERVER
  876. //------------------------------------------------------------------------------
  877. // 功能:收到客户端查询某个npc组队信息的申请后,向这个客户端发送队伍信息
  878. //------------------------------------------------------------------------------
  879. void KPlayer::S2CSendTeamInfo(BYTE* pProtocol)
  880. {
  881. PLAYER_APPLY_TEAM_INFO *pApplyTeamInfo = (PLAYER_APPLY_TEAM_INFO*)pProtocol;
  882. //------------------------------ 查询自身组队信息 -----------------------------
  883. if (pApplyTeamInfo->m_dwTarNpcID == Npc[m_nIndex].m_dwID)
  884. {
  885. SendSelfTeamInfo();
  886. return;
  887. }
  888. //--------------------------- 查询其他 npc 组队信息 -----------------------------
  889. PLAYER_SEND_TEAM_INFO sTeamInfo;
  890. PLAYER_APPLY_TEAM_INFO_FALSE sTeamInfoFalse;
  891. // 寻找相应 npc id 的 player 编号
  892. int nPlayer, nRegionNo, i;
  893. nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].FindPlayer(pApplyTeamInfo->m_dwTarNpcID);
  894. if ( nPlayer >= 0)
  895. goto SendMsg;
  896. for (i = 0; i < 8; i++)
  897. {
  898. nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
  899. if ( nRegionNo < 0)
  900. continue;
  901. nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].FindPlayer(pApplyTeamInfo->m_dwTarNpcID);
  902. if (nPlayer >= 0)
  903. break;
  904. }
  905. if (i >= 8)
  906. goto SendFalse;
  907. SendMsg:
  908. // 寻找队伍
  909. KTeam *pTeam;
  910. if ( !Player[nPlayer].m_cTeam.m_nFlag )
  911. goto SendFalse;
  912. pTeam = &g_Team[Player[nPlayer].m_cTeam.m_nID];
  913. if (pTeam->m_nCaptain < 0 || !pTeam->IsOpen())
  914. goto SendFalse;
  915. // 发送队伍消息
  916. sTeamInfo.ProtocolType = (BYTE)s2c_teaminfo;
  917. sTeamInfo.m_nCaptain = Npc[Player[pTeam->m_nCaptain].m_nIndex].m_dwID;
  918. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  919. {
  920. if (pTeam->m_nMember[i] < 0)
  921. sTeamInfo.m_nMember[i] = 0;
  922. else
  923. sTeamInfo.m_nMember[i] = Npc[Player[pTeam->m_nMember[i]].m_nIndex].m_dwID;
  924. }
  925. // strcpy(sTeamInfo.m_szTeamName, pTeam->m_szName);
  926. // 发送
  927. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sTeamInfo, sizeof(PLAYER_SEND_TEAM_INFO));
  928. return;
  929. // 发送失败通知
  930. SendFalse:
  931. sTeamInfoFalse.ProtocolType = s2c_teamapplyinfofalse;
  932. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sTeamInfoFalse, sizeof(PLAYER_APPLY_TEAM_INFO_FALSE));
  933. return;
  934. }
  935. #endif
  936. #ifdef _SERVER
  937. //-------------------------------------------------------------------------
  938. // 功能:服务器向客户端发送队伍信息
  939. //-------------------------------------------------------------------------
  940. void KPlayer::SendSelfTeamInfo()
  941. {
  942. if (m_cTeam.m_nFlag && m_cTeam.m_nID >= 0) // 发送队伍信息
  943. {
  944. int nNpcIndex;
  945. PLAYER_SEND_SELF_TEAM_INFO sSelfInfo;
  946. sSelfInfo.ProtocolType = s2c_teamselfinfo;
  947. sSelfInfo.nTeamServerID = m_cTeam.m_nID;
  948. sSelfInfo.m_dwLeadExp = m_dwLeadExp;
  949. sSelfInfo.m_btState = g_Team[m_cTeam.m_nID].m_nState;
  950. // 队长
  951. nNpcIndex = Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex;
  952. sSelfInfo.m_dwNpcID[0] = Npc[nNpcIndex].m_dwID;
  953. sSelfInfo.m_btLevel[0] = (DWORD)Npc[nNpcIndex].m_Level;
  954. strcpy(sSelfInfo.m_szNpcName[0], Npc[nNpcIndex].Name);
  955. // 队员
  956. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  957. {
  958. if (g_Team[m_cTeam.m_nID].m_nMember[i] >= 0)
  959. {
  960. nNpcIndex = Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex;
  961. sSelfInfo.m_dwNpcID[i + 1] = Npc[nNpcIndex].m_dwID;
  962. sSelfInfo.m_btLevel[i + 1] = (DWORD)Npc[nNpcIndex].m_Level;
  963. strcpy(sSelfInfo.m_szNpcName[i + 1], Npc[nNpcIndex].Name);
  964. }
  965. else
  966. {
  967. sSelfInfo.m_dwNpcID[i + 1] = 0;
  968. sSelfInfo.m_btLevel[i + 1] = 0;
  969. }
  970. }
  971. // 发送消息
  972. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSelfInfo, sizeof(PLAYER_SEND_SELF_TEAM_INFO));
  973. }
  974. else // 发送离队信息
  975. {
  976. PLAYER_LEAVE_TEAM sLeaveTeam;
  977. sLeaveTeam.ProtocolType = s2c_teamleave;
  978. sLeaveTeam.m_dwNpcID = Npc[m_nIndex].m_dwID;
  979. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeaveTeam, sizeof(PLAYER_LEAVE_TEAM));
  980. }
  981. }
  982. #endif
  983. #ifdef _SERVER
  984. //-------------------------------------------------------------------------
  985. // 功能:收到客户端请求创建一支队伍
  986. //-------------------------------------------------------------------------
  987. BOOL KPlayer::CreateTeam(BYTE* pProtocol)
  988. {
  989. return m_cTeam.CreateTeam(this->m_nPlayerIndex, (PLAYER_APPLY_CREATE_TEAM*)pProtocol);
  990. }
  991. #endif
  992. #ifdef _SERVER
  993. //-------------------------------------------------------------------------
  994. // 功能:收到客户端请求开放、关闭本player队伍是否允许队员加入状态
  995. //-------------------------------------------------------------------------
  996. BOOL KPlayer::SetTeamState(BYTE* pProtocol)
  997. {
  998. if (this->CheckTrading())
  999. return FALSE;
  1000. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN || m_cTeam.m_nID < 0)
  1001. {
  1002. SendSelfTeamInfo();
  1003. return FALSE;
  1004. }
  1005. PLAYER_TEAM_OPEN_CLOSE *pTeamState = (PLAYER_TEAM_OPEN_CLOSE*)pProtocol;
  1006. if (pTeamState->m_btOpenClose == 0)
  1007. {
  1008. g_Team[m_cTeam.m_nID].SetTeamClose();
  1009. }
  1010. else
  1011. {
  1012. if (m_cMenuState.m_nState == PLAYER_MENU_STATE_TRADEOPEN)
  1013. m_cMenuState.SetState(m_nPlayerIndex, PLAYER_MENU_STATE_NORMAL);
  1014. g_Team[m_cTeam.m_nID].SetTeamOpen();
  1015. }
  1016. return TRUE;
  1017. }
  1018. #endif
  1019. #ifdef _SERVER
  1020. //-------------------------------------------------------------------------
  1021. // 功能:收到客户端请求加入一支队伍
  1022. //-------------------------------------------------------------------------
  1023. BOOL KPlayer::S2CSendAddTeamInfo(BYTE* pProtocol)
  1024. {
  1025. if (!m_cTeam.m_bCanTeamFlag)
  1026. {
  1027. SHOW_MSG_SYNC sMsg;
  1028. sMsg.ProtocolType = s2c_msgshow;
  1029. sMsg.m_wMsgID = enumMSG_ID_CANNOT_ADD_TEAM;
  1030. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  1031. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1032. return FALSE;
  1033. }
  1034. PLAYER_APPLY_ADD_TEAM *pAddTeam = (PLAYER_APPLY_ADD_TEAM*)pProtocol;
  1035. // 寻找队长 npc id 的 player 编号
  1036. int nPlayer, nRegionNo, i;
  1037. nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].FindPlayer(pAddTeam->m_dwTarNpcID);
  1038. if ( nPlayer >= 0)
  1039. goto SendMsg;
  1040. for (i = 0; i < 8; i++)
  1041. {
  1042. nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
  1043. if ( nRegionNo < 0)
  1044. continue;
  1045. nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].FindPlayer(pAddTeam->m_dwTarNpcID);
  1046. if (nPlayer >= 0)
  1047. break;
  1048. }
  1049. if (i >= 8)
  1050. return FALSE;
  1051. SendMsg:
  1052. if (Npc[Player[nPlayer].m_nIndex].m_Camp == camp_begin && Npc[m_nIndex].m_Camp != camp_begin)
  1053. return FALSE;
  1054. m_cTeam.m_nApplyCaptainID = pAddTeam->m_dwTarNpcID;
  1055. PLAYER_APPLY_ADD_TEAM sAddTeam;
  1056. sAddTeam.ProtocolType = s2c_teamgetapply;
  1057. sAddTeam.m_dwTarNpcID = Npc[m_nIndex].m_dwID;
  1058. g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, (BYTE*)&sAddTeam, sizeof(PLAYER_APPLY_ADD_TEAM));
  1059. return TRUE;
  1060. }
  1061. #endif
  1062. #ifdef _SERVER
  1063. //-------------------------------------------------------------------------
  1064. // 功能:队长通知服务器接受某个npc为队伍成员
  1065. //-------------------------------------------------------------------------
  1066. BOOL KPlayer::AddTeamMember(BYTE* pProtocol)
  1067. {
  1068. // 错误检测(是否组队、是否队长、队伍开放状态、队员数、统率力)
  1069. if ( !m_cTeam.m_nFlag ||
  1070. m_cTeam.m_nFigure != TEAM_CAPTAIN ||
  1071. !g_Team[m_cTeam.m_nID].IsOpen() ||
  1072. g_Team[m_cTeam.m_nID].m_nMemNum >= MAX_TEAM_MEMBER ||
  1073. g_Team[m_cTeam.m_nID].m_nMemNum >= g_Team[m_cTeam.m_nID].CalcCaptainPower())
  1074. {
  1075. SendSelfTeamInfo();
  1076. return FALSE;
  1077. }
  1078. // 从npc id查找player
  1079. int nPlayer, i;
  1080. PLAYER_ACCEPT_TEAM_MEMBER *pAccept = (PLAYER_ACCEPT_TEAM_MEMBER*)pProtocol;
  1081. nPlayer = FindAroundPlayer(pAccept->m_dwNpcID);
  1082. if (nPlayer < 0)
  1083. return FALSE;
  1084. // 对方正处于不能组队状态
  1085. if (!Player[nPlayer].m_cTeam.m_bCanTeamFlag)
  1086. {
  1087. SHOW_MSG_SYNC sMsg;
  1088. sMsg.ProtocolType = s2c_msgshow;
  1089. sMsg.m_wMsgID = enumMSG_ID_TARGET_CANNOT_ADD_TEAM;
  1090. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  1091. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1092. return FALSE;
  1093. }
  1094. // 已经在队伍中
  1095. if (Player[nPlayer].m_cTeam.m_nFlag)
  1096. return FALSE;
  1097. if (Player[nPlayer].m_cTeam.m_nApplyCaptainID != Npc[this->m_nIndex].m_dwID)
  1098. return FALSE;
  1099. // 队伍添加成员
  1100. if ( !g_Team[m_cTeam.m_nID].AddMember(nPlayer) )
  1101. return FALSE;
  1102. // 改变队伍状态
  1103. if (g_Team[m_cTeam.m_nID].m_nMemNum >= MAX_TEAM_MEMBER || g_Team[m_cTeam.m_nID].CheckFull())
  1104. {
  1105. g_Team[m_cTeam.m_nID].SetTeamClose();
  1106. }
  1107. // 被接受队员队伍数据处理
  1108. Player[nPlayer].m_cTeam.Release();
  1109. Player[nPlayer].m_cTeam.m_nFlag = 1;
  1110. Player[nPlayer].m_cTeam.m_nFigure = TEAM_MEMBER;
  1111. Player[nPlayer].m_cTeam.m_nID = m_cTeam.m_nID;
  1112. Npc[Player[nPlayer].m_nIndex].SetCurrentCamp(Npc[m_nIndex].m_Camp);
  1113. // 给各个队员发消息
  1114. PLAYER_TEAM_ADD_MEMBER sAddMem;
  1115. sAddMem.ProtocolType = s2c_teamaddmember;
  1116. sAddMem.m_dwNpcID = Npc[Player[nPlayer].m_nIndex].m_dwID;
  1117. sAddMem.m_btLevel = (DWORD)Npc[Player[nPlayer].m_nIndex].m_Level;
  1118. strcpy(sAddMem.m_szName, Npc[Player[nPlayer].m_nIndex].Name);
  1119. // 给队长发消息
  1120. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sAddMem, sizeof(PLAYER_TEAM_ADD_MEMBER));
  1121. // 给老队员发消息
  1122. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1123. {
  1124. if (g_Team[m_cTeam.m_nID].m_nMember[i] < 0 || g_Team[m_cTeam.m_nID].m_nMember[i] == nPlayer)
  1125. continue;
  1126. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, (BYTE*)&sAddMem, sizeof(PLAYER_TEAM_ADD_MEMBER));
  1127. }
  1128. // ------------------------------------- 给新队员发消息 --------------------------
  1129. int nNpcIndex;
  1130. PLAYER_SEND_SELF_TEAM_INFO sSelfInfo;
  1131. sSelfInfo.ProtocolType = s2c_teamselfinfo;
  1132. sSelfInfo.nTeamServerID = m_cTeam.m_nID;
  1133. sSelfInfo.m_dwLeadExp = Player[nPlayer].m_dwLeadExp;
  1134. sSelfInfo.m_btState = g_Team[m_cTeam.m_nID].m_nState;
  1135. // 队长数据
  1136. nNpcIndex = m_nIndex;
  1137. sSelfInfo.m_dwNpcID[0] = Npc[nNpcIndex].m_dwID;
  1138. sSelfInfo.m_btLevel[0] = (DWORD)Npc[nNpcIndex].m_Level;
  1139. strcpy(sSelfInfo.m_szNpcName[0], Npc[nNpcIndex].Name);
  1140. // 队员数据
  1141. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1142. {
  1143. if (g_Team[m_cTeam.m_nID].m_nMember[i] >= 0)
  1144. {
  1145. nNpcIndex = Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex;
  1146. sSelfInfo.m_dwNpcID[i + 1] = Npc[nNpcIndex].m_dwID;
  1147. sSelfInfo.m_btLevel[i + 1] = (DWORD)Npc[nNpcIndex].m_Level;
  1148. strcpy(sSelfInfo.m_szNpcName[i + 1], Npc[nNpcIndex].Name);
  1149. }
  1150. else
  1151. {
  1152. sSelfInfo.m_dwNpcID[i + 1] = 0;
  1153. sSelfInfo.m_btLevel[i + 1] = 0;
  1154. }
  1155. }
  1156. // 发送消息
  1157. g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, (BYTE*)&sSelfInfo, sizeof(PLAYER_SEND_SELF_TEAM_INFO));
  1158. SHOW_MSG_SYNC sMsg;
  1159. sMsg.ProtocolType = s2c_msgshow;
  1160. sMsg.m_wMsgID = enumMSG_ID_TEAM_SELF_ADD;
  1161. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  1162. sMsg.m_lpBuf = 0;
  1163. g_pServer->PackDataToClient(Player[nPlayer].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1164. // --------------------------------- 给新队员发消息 end --------------------------
  1165. return TRUE;
  1166. }
  1167. #endif
  1168. #ifdef _SERVER
  1169. //-------------------------------------------------------------------------
  1170. // 功能:收到客户端队员通知离开队伍
  1171. //-------------------------------------------------------------------------
  1172. void KPlayer::LeaveTeam(BYTE* pProtocol)
  1173. {
  1174. if (!m_cTeam.m_nFlag)
  1175. return;
  1176. if (this->m_cTeam.m_nFigure == TEAM_CAPTAIN && g_Team[m_cTeam.m_nID].IsOpen())
  1177. {
  1178. g_Team[m_cTeam.m_nID].SetTeamClose();
  1179. }
  1180. // 非队长离开队伍,发系统消息,队长离开队伍的系统消息处理在DeleteMember里面
  1181. if (m_cTeam.m_nFigure != TEAM_CAPTAIN)
  1182. {
  1183. SHOW_MSG_SYNC sMsg;
  1184. sMsg.ProtocolType = s2c_msgshow;
  1185. sMsg.m_wMsgID = enumMSG_ID_TEAM_LEAVE;
  1186. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  1187. sMsg.m_lpBuf = (void*)Npc[this->m_nIndex].m_dwID;
  1188. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1189. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  1190. {
  1191. if (g_Team[m_cTeam.m_nID].m_nMember[i] > 0)
  1192. {
  1193. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1194. }
  1195. }
  1196. sMsg.m_lpBuf = 0;
  1197. }
  1198. // 服务器端队员离开的处理
  1199. g_Team[m_cTeam.m_nID].DeleteMember(GetPlayerIndex());
  1200. }
  1201. #endif
  1202. #ifdef _SERVER
  1203. //-------------------------------------------------------------------------
  1204. // 功能:收到客户端队长通知踢出某个队员
  1205. //-------------------------------------------------------------------------
  1206. void KPlayer::TeamKickOne(BYTE* pProtocol)
  1207. {
  1208. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  1209. return;
  1210. int nMemNo;
  1211. PLAYER_TEAM_KICK_MEMBER *pKickOne = (PLAYER_TEAM_KICK_MEMBER*)pProtocol;
  1212. nMemNo = g_Team[m_cTeam.m_nID].FindMemberID(pKickOne->m_dwNpcID);
  1213. if (nMemNo < 0)
  1214. return;
  1215. int nPlayerNo;
  1216. // 服务器端队员离开的处理
  1217. nPlayerNo = g_Team[m_cTeam.m_nID].m_nMember[nMemNo];
  1218. g_Team[m_cTeam.m_nID].DeleteMember(nPlayerNo);
  1219. // 发消息给客户端
  1220. int nLength;
  1221. SHOW_MSG_SYNC sMsg;
  1222. nLength = strlen(Npc[Player[nPlayerNo].m_nIndex].Name);
  1223. sMsg.ProtocolType = s2c_msgshow;
  1224. sMsg.m_wMsgID = enumMSG_ID_TEAM_KICK_One;
  1225. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID) + nLength;
  1226. sMsg.m_lpBuf = new BYTE[sMsg.m_wLength + 1];
  1227. memcpy(sMsg.m_lpBuf, &sMsg, sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID));
  1228. memcpy((char*)sMsg.m_lpBuf + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), Npc[Player[nPlayerNo].m_nIndex].Name, nLength);
  1229. g_pServer->PackDataToClient(Player[nPlayerNo].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
  1230. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
  1231. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  1232. {
  1233. if (g_Team[m_cTeam.m_nID].m_nMember[i] > 0)
  1234. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
  1235. }
  1236. sMsg.Release();
  1237. }
  1238. #endif
  1239. #ifdef _SERVER
  1240. //-------------------------------------------------------------------------
  1241. // 功能:收到客户端队长通知把队长身份交给某个队员
  1242. //-------------------------------------------------------------------------
  1243. void KPlayer::TeamChangeCaptain(BYTE* pProtocol)
  1244. {
  1245. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  1246. return;
  1247. int i, nMember, nPlayerNo, nIsOpen = 0;
  1248. PLAYER_APPLY_TEAM_CHANGE_CAPTAIN *pChange = (PLAYER_APPLY_TEAM_CHANGE_CAPTAIN*)pProtocol;
  1249. nMember = g_Team[m_cTeam.m_nID].FindMemberID(pChange->m_dwNpcID);
  1250. if (nMember < 0)
  1251. return;
  1252. if (Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[nMember]].m_nIndex].m_Camp == camp_begin && Npc[this->m_nIndex].m_Camp != camp_begin)
  1253. {
  1254. // 队长移交失败:对方统帅力不够
  1255. SHOW_MSG_SYNC sMsg;
  1256. sMsg.ProtocolType = s2c_msgshow;
  1257. sMsg.m_wMsgID = enumMSG_ID_TEAM_CHANGE_CAPTAIN_FAIL2;
  1258. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  1259. sMsg.m_lpBuf = (LPVOID)pChange->m_dwNpcID;
  1260. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1261. sMsg.m_lpBuf = 0;
  1262. return;
  1263. }
  1264. if (g_Team[m_cTeam.m_nID].m_nMemNum > PlayerSet.m_cLeadExp.GetMemNumFromLevel(Player[g_Team[m_cTeam.m_nID].m_nMember[nMember]].m_dwLeadLevel))
  1265. {
  1266. // 队长移交失败:对方统帅力不够
  1267. SHOW_MSG_SYNC sMsg;
  1268. sMsg.ProtocolType = s2c_msgshow;
  1269. sMsg.m_wMsgID = enumMSG_ID_TEAM_CHANGE_CAPTAIN_FAIL;
  1270. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1;
  1271. sMsg.m_lpBuf = (LPVOID)pChange->m_dwNpcID;
  1272. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1273. sMsg.m_lpBuf = 0;
  1274. return;
  1275. }
  1276. if (g_Team[m_cTeam.m_nID].IsOpen())
  1277. {
  1278. g_Team[m_cTeam.m_nID].SetTeamClose();
  1279. nIsOpen = 1;
  1280. }
  1281. nPlayerNo = g_Team[m_cTeam.m_nID].m_nCaptain;
  1282. g_Team[m_cTeam.m_nID].m_nCaptain = g_Team[m_cTeam.m_nID].m_nMember[nMember];
  1283. g_Team[m_cTeam.m_nID].m_nMember[nMember] = nPlayerNo;
  1284. m_cTeam.m_nFigure = TEAM_MEMBER;
  1285. Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_cTeam.m_nFigure = TEAM_CAPTAIN;
  1286. // 改变阵营
  1287. Npc[Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex].RestoreCurrentCamp();
  1288. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1289. {
  1290. nPlayerNo = g_Team[m_cTeam.m_nID].m_nMember[i];
  1291. if (nPlayerNo < 0)
  1292. continue;
  1293. Npc[Player[nPlayerNo].m_nIndex].SetCurrentCamp(Npc[Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex].m_Camp);
  1294. }
  1295. // 给各个队员发消息
  1296. PLAYER_TEAM_CHANGE_CAPTAIN sChangeCaptain;
  1297. sChangeCaptain.ProtocolType = s2c_teamchangecaptain;
  1298. sChangeCaptain.m_dwCaptainID = pChange->m_dwNpcID;
  1299. sChangeCaptain.m_dwMemberID = Npc[m_nIndex].m_dwID;
  1300. // 给队长发消息
  1301. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, (BYTE*)&sChangeCaptain, sizeof(PLAYER_TEAM_CHANGE_CAPTAIN));
  1302. // 给队员发消息
  1303. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1304. {
  1305. nPlayerNo = g_Team[m_cTeam.m_nID].m_nMember[i];
  1306. if (nPlayerNo < 0)
  1307. continue;
  1308. g_pServer->PackDataToClient(Player[nPlayerNo].m_nNetConnectIdx, (BYTE*)&sChangeCaptain, sizeof(PLAYER_TEAM_CHANGE_CAPTAIN));
  1309. }
  1310. if (nIsOpen)
  1311. {
  1312. g_Team[m_cTeam.m_nID].SetTeamOpen();
  1313. }
  1314. }
  1315. #endif
  1316. #ifdef _SERVER
  1317. //-------------------------------------------------------------------------
  1318. // 功能:收到客户端队长请求解散队伍
  1319. //-------------------------------------------------------------------------
  1320. void KPlayer::TeamDismiss(BYTE* pProtocol)
  1321. {
  1322. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  1323. return;
  1324. PLAYER_LEAVE_TEAM sLeaveTeam;
  1325. int i;
  1326. SHOW_MSG_SYNC sMsg;
  1327. // 队伍解散消息
  1328. sMsg.ProtocolType = s2c_msgshow;
  1329. sMsg.m_wMsgID = enumMSG_ID_TEAM_DISMISS;
  1330. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  1331. g_pServer->PackDataToClient(m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1332. // 给队长发消息
  1333. sLeaveTeam.ProtocolType = s2c_teamleave;
  1334. sLeaveTeam.m_dwNpcID = Npc[m_nIndex].m_dwID;
  1335. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeaveTeam, sizeof(PLAYER_LEAVE_TEAM));
  1336. // 给队员发消息
  1337. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1338. {
  1339. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1340. sLeaveTeam.m_dwNpcID = Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex].m_dwID;
  1341. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, (BYTE*)&sLeaveTeam, sizeof(PLAYER_LEAVE_TEAM));
  1342. // 队员身份改变
  1343. Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_cTeam.m_nFlag = 0;
  1344. Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex].RestoreCurrentCamp();;
  1345. }
  1346. // 队伍清空
  1347. g_Team[m_cTeam.m_nID].Release();
  1348. // 队长身份改变
  1349. m_cTeam.m_nFlag = 0;
  1350. Npc[m_nIndex].RestoreCurrentCamp();
  1351. }
  1352. #endif
  1353. #ifdef _SERVER
  1354. //-------------------------------------------------------------------------
  1355. // 功能:收到客户端请求设定PK状态
  1356. //-------------------------------------------------------------------------
  1357. void KPlayer::SetPK(BYTE* pProtocol)
  1358. {
  1359. PLAYER_SET_PK *pPK = (PLAYER_SET_PK*)pProtocol;
  1360. if (pPK->m_btPKFlag)
  1361. Npc[m_nIndex].SetCurrentCamp(camp_free);
  1362. else
  1363. Npc[m_nIndex].RestoreCurrentCamp();
  1364. }
  1365. #endif
  1366. #ifdef _SERVER
  1367. //-------------------------------------------------------------------------
  1368. // 功能:收到客户端请求获得门派数据
  1369. //-------------------------------------------------------------------------
  1370. void KPlayer::SendFactionData(BYTE* pProtocol)
  1371. {
  1372. SendFactionData();
  1373. }
  1374. #endif
  1375. #ifdef _SERVER
  1376. //-------------------------------------------------------------------------
  1377. // 功能:向客户端发送门派数据
  1378. //-------------------------------------------------------------------------
  1379. void KPlayer::SendFactionData()
  1380. {
  1381. // 给客户端发消息
  1382. PLAYER_FACTION_DATA sData;
  1383. sData.ProtocolType = s2c_playerfactiondata;
  1384. sData.m_btCamp = Npc[m_nIndex].m_Camp;
  1385. sData.m_btCurFaction = m_cFaction.m_nCurFaction;
  1386. sData.m_btFirstFaction = m_cFaction.m_nFirstAddFaction;
  1387. sData.m_nAddTimes = m_cFaction.m_nAddTimes;
  1388. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sData, sizeof(PLAYER_FACTION_DATA));
  1389. }
  1390. #endif
  1391. #ifdef _SERVER
  1392. // not end
  1393. void KPlayer::GetAboutPos(KMapPos *pMapPos)
  1394. {
  1395. if (m_nIndex <= 0)
  1396. return;
  1397. if (Npc[m_nIndex].m_SubWorldIndex < 0)
  1398. return;
  1399. POINT Pos;
  1400. int nX, nY;
  1401. Npc[m_nIndex].GetMpsPos(&nX, &nY);
  1402. Pos.x = nX;
  1403. Pos.y = nY;
  1404. SubWorld[Npc[m_nIndex].m_SubWorldIndex].GetFreeObjPos(Pos);
  1405. pMapPos->nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
  1406. SubWorld[Npc[m_nIndex].m_SubWorldIndex].Mps2Map(
  1407. Pos.x, 
  1408. Pos.y, 
  1409. &pMapPos->nRegion, 
  1410. &pMapPos->nMapX, 
  1411. &pMapPos->nMapY, 
  1412. &pMapPos->nOffX, 
  1413. &pMapPos->nOffY);
  1414. }
  1415. /*
  1416. void KPlayer::GetAboutPos(KMapPos *pMapPos)
  1417. {
  1418. POINT Pos[8] = 
  1419. {
  1420. {0, 32}, {-32, 32}, {-32, 0}, {-32, -32},
  1421. {0, -32}, {32, -32}, {32, 0}, {32, 32},
  1422. };
  1423.   int nMpsX, nMpsY, nTmpX, nTmpY;
  1424.   int nR, nMapX, nMapY, nOffX, nOffY;
  1425.   Npc[m_nIndex].GetMpsPos(&nMpsX, &nMpsY);
  1426.   
  1427. for (int i = 0; i < 8; i++)
  1428. {
  1429. nTmpX = nMpsX + Pos[i].x;
  1430. nTmpY = nMpsY + Pos[i].y;
  1431. if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].GetBarrier(nTmpX, nTmpY))
  1432. continue;
  1433. SubWorld[Npc[m_nIndex].m_SubWorldIndex].Mps2Map(nTmpX, nTmpY, &nR, &nMapX, &nMapY, &nOffX, &nOffY);
  1434. if (nR == -1)
  1435. continue;
  1436. if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nR].GetRef(nMapX, nMapY, obj_object))
  1437. continue;
  1438. else
  1439. break;
  1440. }
  1441.   if (i == 8)
  1442.   {
  1443.   pMapPos->nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
  1444.   pMapPos->nRegion = Npc[m_nIndex].m_RegionIndex;
  1445.   pMapPos->nMapX = Npc[m_nIndex].m_MapX;
  1446.   pMapPos->nMapY = Npc[m_nIndex].m_MapY;
  1447.   pMapPos->nOffX = Npc[m_nIndex].m_OffX;
  1448.   pMapPos->nOffY = Npc[m_nIndex].m_OffY;
  1449.   }
  1450.   else
  1451.   {
  1452.   pMapPos->nSubWorld = Npc[m_nIndex].m_SubWorldIndex;
  1453.   pMapPos->nRegion = nR;
  1454.   pMapPos->nMapX = nMapX;
  1455.   pMapPos->nMapY = nMapY;
  1456.   pMapPos->nOffX = nOffX;
  1457.   pMapPos->nOffY = nOffY;
  1458.   }
  1459. }*/
  1460. #endif
  1461. #ifdef _SERVER
  1462. //-------------------------------------------------------------------------
  1463. // 功能:寻找玩家周围的某个指定npc id的player index
  1464. //-------------------------------------------------------------------------
  1465. int KPlayer::FindAroundPlayer(DWORD dwNpcID)
  1466. {
  1467. if (dwNpcID == 0)
  1468. return -1;
  1469. int nPlayer, nRegionNo, i;
  1470. nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].FindPlayer(dwNpcID);
  1471. if ( nPlayer >= 0)
  1472. return nPlayer;
  1473. for (i = 0; i < 8; i++)
  1474. {
  1475. nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
  1476. if ( nRegionNo < 0)
  1477. continue;
  1478. nPlayer = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].FindPlayer(dwNpcID);
  1479. if (nPlayer >= 0)
  1480. return nPlayer;
  1481. }
  1482. return -1;
  1483. }
  1484. //-------------------------------------------------------------------------
  1485. // 功能:判断某玩家是否在周围
  1486. //-------------------------------------------------------------------------
  1487. BOOL KPlayer::CheckPlayerAround(int nPlayerIdx)
  1488. {
  1489. if (nPlayerIdx <= 0)
  1490. return FALSE;
  1491. if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].CheckPlayerIn(nPlayerIdx))
  1492. return TRUE;
  1493. int nRegionNo;
  1494. for (int i = 0; i < 8; i++)
  1495. {
  1496. nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
  1497. if ( nRegionNo < 0)
  1498. continue;
  1499. if (SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].CheckPlayerIn(nPlayerIdx))
  1500. return TRUE;
  1501. }
  1502. return FALSE;
  1503. }
  1504. //-------------------------------------------------------------------------
  1505. // 功能:寻找玩家周围的某个指定npc id的npc index
  1506. //-------------------------------------------------------------------------
  1507. int KPlayer::FindAroundNpc(DWORD dwNpcID)
  1508. {
  1509. if (dwNpcID == 0)
  1510. return 0;
  1511. int nNpc, nRegionNo, i;
  1512. nNpc = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].SearchNpc(dwNpcID);
  1513. if ( nNpc > 0)
  1514. return nNpc;
  1515. for (i = 0; i < 8; i++)
  1516. {
  1517. nRegionNo = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[Npc[m_nIndex].m_RegionIndex].m_nConnectRegion[i];
  1518. if ( nRegionNo < 0)
  1519. continue;
  1520. nNpc = SubWorld[Npc[m_nIndex].m_SubWorldIndex].m_Region[nRegionNo].SearchNpc(dwNpcID);
  1521. if (nNpc > 0)
  1522. return nNpc;
  1523. }
  1524. return 0;
  1525. }
  1526. #endif
  1527. //-------------------------------------------------------------------------
  1528. // 功能:新玩家登陆时根据五行属性产生 力量 敏捷 活力 精力 四项数值
  1529. //-------------------------------------------------------------------------
  1530. BOOL KPlayer::NewPlayerGetBaseAttribute(int Series)
  1531. {
  1532. if (Series < series_metal || Series > series_earth)
  1533. return FALSE;
  1534. Npc[m_nIndex].SetSeries(Series);
  1535. m_nStrength = PlayerSet.m_cNewPlayerAttribute.m_nStrength[Series];
  1536. m_nDexterity = PlayerSet.m_cNewPlayerAttribute.m_nDexterity[Series];
  1537. m_nVitality = PlayerSet.m_cNewPlayerAttribute.m_nVitality[Series];
  1538. m_nEngergy = PlayerSet.m_cNewPlayerAttribute.m_nEngergy[Series];
  1539. m_nLucky = PlayerSet.m_cNewPlayerAttribute.m_nLucky[Series];
  1540. m_nCurStrength = m_nStrength;
  1541. m_nCurDexterity = m_nDexterity;
  1542. m_nCurVitality = m_nVitality;
  1543. m_nCurEngergy = m_nEngergy;
  1544. CalcCurLucky();
  1545. m_cFaction.SetSeries(Series);
  1546. return TRUE;
  1547. }
  1548. //-------------------------------------------------------------------------
  1549. // 功能:计算当前力量
  1550. //-------------------------------------------------------------------------
  1551. //void KPlayer::CalcCurStrength()
  1552. //{ // 还需要考虑 装备、技能、状态 的影响
  1553. // m_nCurStrength = m_nStrength;
  1554. //}
  1555. //-------------------------------------------------------------------------
  1556. // 功能:计算当前敏捷
  1557. //-------------------------------------------------------------------------
  1558. //void KPlayer::CalcCurDexterity()
  1559. //{ // 还需要考虑 装备、技能、状态 的影响
  1560. // m_nCurDexterity = m_nDexterity;
  1561. //}
  1562. //-------------------------------------------------------------------------
  1563. // 功能:计算当前活力
  1564. //-------------------------------------------------------------------------
  1565. //void KPlayer::CalcCurVitality()
  1566. //{ // 还需要考虑 装备、技能、状态 的影响
  1567. // m_nCurVitality = m_nVitality;
  1568. //}
  1569. //-------------------------------------------------------------------------
  1570. // 功能:计算当前精力
  1571. //-------------------------------------------------------------------------
  1572. //void KPlayer::CalcCurEngergy()
  1573. //{ // 还需要考虑 装备、技能、状态 的影响
  1574. // m_nCurEngergy = m_nEngergy;
  1575. //}
  1576. //-------------------------------------------------------------------------
  1577. // 功能:计算当前运气
  1578. //-------------------------------------------------------------------------
  1579. void KPlayer::CalcCurLucky()
  1580. { // 还需要考虑 装备、技能、状态 的影响
  1581. m_nCurLucky = m_nLucky;
  1582. }
  1583. #ifdef _SERVER
  1584. //-------------------------------------------------------------------------
  1585. // 功能:增加基本力量
  1586. //-------------------------------------------------------------------------
  1587. void KPlayer::AddBaseStrength(int nData)
  1588. {
  1589. if (nData > 0 && nData <= m_nAttributePoint)
  1590. {
  1591. m_nStrength += nData;
  1592. m_nAttributePoint -= nData;
  1593. m_nCurStrength += nData;
  1594. UpdataCurData();
  1595. SetNpcPhysicsDamage();
  1596. // 把当前力量传给客户端
  1597. PLAYER_ATTRIBUTE_SYNC sSync;
  1598. sSync.ProtocolType = s2c_playersyncattribute;
  1599. sSync.m_btAttribute = 0;
  1600. sSync.m_nBasePoint = m_nStrength;
  1601. sSync.m_nCurPoint = m_nCurStrength;
  1602. sSync.m_nLeavePoint = m_nAttributePoint;
  1603. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
  1604. }
  1605. }
  1606. #endif
  1607. #ifdef _SERVER
  1608. //-------------------------------------------------------------------------
  1609. // 功能:增加基本敏捷
  1610. //-------------------------------------------------------------------------
  1611. void KPlayer::AddBaseDexterity(int nData)
  1612. {
  1613. if (nData > 0 && nData <= m_nAttributePoint)
  1614. {
  1615. m_nDexterity += nData;
  1616. m_nAttributePoint -= nData;
  1617. m_nCurDexterity += nData;
  1618. SetNpcAttackRating();
  1619. SetNpcDefence();
  1620. UpdataCurData();
  1621. SetNpcPhysicsDamage();
  1622. // 把当前力量传给客户端
  1623. PLAYER_ATTRIBUTE_SYNC sSync;
  1624. sSync.ProtocolType = s2c_playersyncattribute;
  1625. sSync.m_btAttribute = 1;
  1626. sSync.m_nBasePoint = m_nDexterity;
  1627. sSync.m_nCurPoint = m_nCurDexterity;
  1628. sSync.m_nLeavePoint = m_nAttributePoint;
  1629. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
  1630. }
  1631. }
  1632. #endif
  1633. #ifdef _SERVER
  1634. //-------------------------------------------------------------------------
  1635. // 功能:增加基本活力
  1636. //-------------------------------------------------------------------------
  1637. void KPlayer::AddBaseVitality(int nData)
  1638. {
  1639. if (nData > 0 && nData <= m_nAttributePoint)
  1640. {
  1641. m_nVitality += nData;
  1642. m_nAttributePoint -= nData;
  1643. m_nCurVitality += nData;
  1644. Npc[m_nIndex].AddBaseLifeMax(PlayerSet.m_cLevelAdd.GetLifePerVitality(Npc[m_nIndex].m_Series) * nData);
  1645. Npc[m_nIndex].AddBaseStaminaMax(PlayerSet.m_cLevelAdd.GetStaminaPerVitality(Npc[m_nIndex].m_Series) * nData);
  1646. UpdataCurData();
  1647. // 把当前力量传给客户端
  1648. PLAYER_ATTRIBUTE_SYNC sSync;
  1649. sSync.ProtocolType = s2c_playersyncattribute;
  1650. sSync.m_btAttribute = 2;
  1651. sSync.m_nBasePoint = m_nVitality;
  1652. sSync.m_nCurPoint = m_nCurVitality;
  1653. sSync.m_nLeavePoint = m_nAttributePoint;
  1654. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
  1655. }
  1656. }
  1657. #endif
  1658. #ifdef _SERVER
  1659. //-------------------------------------------------------------------------
  1660. // 功能:增加基本精力
  1661. //-------------------------------------------------------------------------
  1662. void KPlayer::AddBaseEngergy(int nData)
  1663. {
  1664. if (nData > 0 && nData <= m_nAttributePoint)
  1665. {
  1666. m_nEngergy += nData;
  1667. m_nAttributePoint -= nData;
  1668. m_nCurEngergy += nData;
  1669. Npc[m_nIndex].AddBaseManaMax(PlayerSet.m_cLevelAdd.GetManaPerEnergy(Npc[m_nIndex].m_Series) * nData);
  1670. UpdataCurData();
  1671. // 把当前力量传给客户端
  1672. PLAYER_ATTRIBUTE_SYNC sSync;
  1673. sSync.ProtocolType = s2c_playersyncattribute;
  1674. sSync.m_btAttribute = 3;
  1675. sSync.m_nBasePoint = m_nEngergy;
  1676. sSync.m_nCurPoint = m_nCurEngergy;
  1677. sSync.m_nLeavePoint = m_nAttributePoint;
  1678. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSync, sizeof(PLAYER_ATTRIBUTE_SYNC));
  1679. }
  1680. }
  1681. #endif
  1682. //-------------------------------------------------------------------------
  1683. // 功能:改变当前力量(当 nData 小于 0 时,减少)
  1684. //-------------------------------------------------------------------------
  1685. void KPlayer::ChangeCurStrength(int nData)
  1686. {
  1687. /* if (m_nCurStrength + nData < m_nStrength)
  1688. return;
  1689. */
  1690. m_nCurStrength += nData;
  1691. SetNpcPhysicsDamage();
  1692. // 把当前力量传给客户端
  1693. }
  1694. //-------------------------------------------------------------------------
  1695. // 功能:改变当前敏捷(当 nData 小于 0 时,减少)
  1696. //-------------------------------------------------------------------------
  1697. void KPlayer::ChangeCurDexterity(int nData)
  1698. {
  1699. /* if (m_nCurDexterity + nData < 0)
  1700. return;
  1701. */
  1702. m_nCurDexterity += nData;
  1703. int nRating = nData * 4;
  1704. Npc[m_nIndex].m_CurrentAttackRating += nRating;
  1705. int nDefence = nData / 4;
  1706. Npc[m_nIndex].m_CurrentDefend += nDefence;
  1707. SetNpcPhysicsDamage();
  1708. }
  1709. //-------------------------------------------------------------------------
  1710. // 功能:改变当前活力(当 nData 小于 0 时,减少)
  1711. //-------------------------------------------------------------------------
  1712. void KPlayer::ChangeCurVitality(int nData)
  1713. {
  1714. /* if (nData + m_nAttributePoint < 0)
  1715. return;
  1716. */
  1717. m_nCurVitality += nData;
  1718. Npc[m_nIndex].AddCurLifeMax(PlayerSet.m_cLevelAdd.GetLifePerVitality(Npc[m_nIndex].m_Series) * nData);
  1719. Npc[m_nIndex].AddCurStaminaMax(PlayerSet.m_cLevelAdd.GetStaminaPerVitality(Npc[m_nIndex].m_Series) * nData);
  1720. }
  1721. //-------------------------------------------------------------------------
  1722. // 功能:改变当前精力(当 nData 小于 0 时,减少)
  1723. //-------------------------------------------------------------------------
  1724. void KPlayer::ChangeCurEngergy(int nData)
  1725. {
  1726. /* if (m_nAttributePoint + nData < 0)
  1727. return;
  1728. */
  1729. m_nCurEngergy += nData;
  1730. Npc[m_nIndex].AddCurManaMax(PlayerSet.m_cLevelAdd.GetManaPerEnergy(Npc[m_nIndex].m_Series) * nData);
  1731. }
  1732. //-------------------------------------------------------------------------
  1733. // 功能:增加基本运气
  1734. //-------------------------------------------------------------------------
  1735. void KPlayer::AddBaseLucky(int nData)
  1736. {
  1737. m_nLucky += nData;
  1738. CalcCurLucky();
  1739. }
  1740. //-------------------------------------------------------------------------
  1741. // 功能:由当前力量计算对应npc的物理伤害(PhysicsDamage)
  1742. //-------------------------------------------------------------------------
  1743. void KPlayer::SetNpcPhysicsDamage()
  1744. {
  1745. int nMinDamage, nMaxDamage;
  1746. m_ItemList.GetWeaponDamage(&nMinDamage, &nMaxDamage);
  1747. if (m_ItemList.GetWeaponType() == equip_meleeweapon) // (当前装备是近身武器)
  1748. {
  1749. /* nMinDamage = nMinDamage * (m_nCurStrength + STRENGTH_SET_DAMAGE_VALUE) / STRENGTH_SET_DAMAGE_VALUE;
  1750. nMaxDamage = nMaxDamage * (m_nCurStrength + STRENGTH_SET_DAMAGE_VALUE) / STRENGTH_SET_DAMAGE_VALUE;
  1751. */
  1752. // 数值计算方法修改(孙英要求) by Spe 03/06/11
  1753. nMinDamage += m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE;
  1754. nMaxDamage += m_nCurStrength / STRENGTH_SET_DAMAGE_VALUE;
  1755. Npc[m_nIndex].SetPhysicsDamage(nMinDamage, nMaxDamage);
  1756. }
  1757. else if (m_ItemList.GetWeaponType() == equip_rangeweapon) // (当前装备是远程武器)
  1758. {
  1759. /* nMinDamage = nMinDamage * (m_nCurDexterity + DEXTERITY_SET_DAMAGE_VALUE) / DEXTERITY_SET_DAMAGE_VALUE;
  1760. nMaxDamage = nMaxDamage * (m_nCurDexterity + DEXTERITY_SET_DAMAGE_VALUE) / DEXTERITY_SET_DAMAGE_VALUE;
  1761. */
  1762. // 数值计算方法修改(孙英要求) by Spe 03/06/11
  1763. nMinDamage += m_nCurDexterity / DEXTERITY_SET_DAMAGE_VALUE;
  1764. nMaxDamage += m_nCurDexterity / DEXTERITY_SET_DAMAGE_VALUE;
  1765. Npc[m_nIndex].SetPhysicsDamage(nMinDamage, nMaxDamage);
  1766. }
  1767. else
  1768. {
  1769. Npc[m_nIndex].SetPhysicsDamage(nMinDamage, nMaxDamage);
  1770. }
  1771. }
  1772. //-------------------------------------------------------------------------
  1773. // 功能:由当前敏捷计算对应npc的攻击命中率(AttackRating)
  1774. //-------------------------------------------------------------------------
  1775. void KPlayer::SetNpcAttackRating()
  1776. {
  1777. int nRating;
  1778. nRating = m_nDexterity * 4 - 28;
  1779. Npc[m_nIndex].SetBaseAttackRating(nRating);
  1780. }
  1781. //-------------------------------------------------------------------------
  1782. // 功能:由当前敏捷计算对应npc的防御力
  1783. //-------------------------------------------------------------------------
  1784. void KPlayer::SetNpcDefence()
  1785. {
  1786. int nDefence;
  1787. nDefence = m_nDexterity / 4;
  1788. Npc[m_nIndex].SetBaseDefence(nDefence);
  1789. }
  1790. /*
  1791. #ifdef _SERVER
  1792. //-------------------------------------------------------------------------
  1793. // 功能:由当前敏捷计算对应npc的行走速度
  1794. //-------------------------------------------------------------------------
  1795. void KPlayer::SetNpcWalkSpeed()
  1796. {
  1797. int nSpeed;
  1798. nSpeed = BASE_WALK_SPEED * (m_nCurDexterity + 320) / 320;
  1799. Npc[m_nIndex].SetBaseWalkSpeed(nSpeed);
  1800. }
  1801. #endif
  1802. */
  1803. /*
  1804. #ifdef _SERVER
  1805. //-------------------------------------------------------------------------
  1806. // 功能:由当前敏捷计算对应npc的跑步速度
  1807. //-------------------------------------------------------------------------
  1808. void KPlayer::SetNpcRunSpeed()
  1809. {
  1810. int nSpeed;
  1811. nSpeed = BASE_RUN_SPEED * (m_nCurDexterity + 320) / 320;
  1812. Npc[m_nIndex].SetBaseRunSpeed(nSpeed);
  1813. }
  1814. #endif
  1815. */
  1816. //-------------------------------------------------------------------------
  1817. // 功能:增加经验(原始数据,还未经过处理,需要处理组队的影响)
  1818. //-------------------------------------------------------------------------
  1819. void KPlayer::AddExp(int nExp, int nTarLevel)
  1820. {
  1821. #ifndef _SERVER
  1822. AddSelfExp(nExp, nTarLevel);
  1823. #endif
  1824. #ifdef _SERVER
  1825. // 没有组队
  1826. if ( !m_cTeam.m_nFlag )
  1827. {
  1828. AddSelfExp(nExp, nTarLevel);
  1829. return;
  1830. }
  1831. // 已经组队
  1832. int i, j, nShareFlag[MAX_TEAM_MEMBER + 1], nRegion, nTotalLevel = 0, nTotalPlayer = 0;
  1833. memset(nShareFlag, 0, sizeof(nShareFlag));
  1834. int nMpsX, nMpsY, nNpcIdx, nSelfSubIdx, nSelfMpsX, nSelfMpsY;
  1835. nSelfSubIdx = Npc[m_nIndex].m_SubWorldIndex;
  1836. SubWorld[nSelfSubIdx].Map2Mps(
  1837. Npc[m_nIndex].m_RegionIndex,
  1838. Npc[m_nIndex].m_MapX,
  1839. Npc[m_nIndex].m_MapY,
  1840. Npc[m_nIndex].m_OffX,
  1841. Npc[m_nIndex].m_OffY,
  1842. &nSelfMpsX,
  1843. &nSelfMpsY);
  1844. // 队长
  1845. nNpcIdx = Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex;
  1846. if (nSelfSubIdx == Npc[nNpcIdx].m_SubWorldIndex)
  1847. {
  1848. SubWorld[Npc[nNpcIdx].m_SubWorldIndex].Map2Mps(
  1849. Npc[nNpcIdx].m_RegionIndex,
  1850. Npc[nNpcIdx].m_MapX,
  1851. Npc[nNpcIdx].m_MapY,
  1852. Npc[nNpcIdx].m_OffX,
  1853. Npc[nNpcIdx].m_OffY,
  1854. &nMpsX,
  1855. &nMpsY);
  1856. if ( (nMpsX - nSelfMpsX) * (nMpsX - nSelfMpsX) + 
  1857. (nMpsY - nSelfMpsY) * (nMpsY - nSelfMpsY) <= 
  1858. PLAYER_SHARE_EXP_DISTANCE * PLAYER_SHARE_EXP_DISTANCE)
  1859. {
  1860. nTotalLevel += Npc[nNpcIdx].m_Level;
  1861. nShareFlag[0] = 1;
  1862. nTotalPlayer++;
  1863. if (nTotalPlayer >= g_Team[m_cTeam.m_nID].m_nMemNum + 1)
  1864. goto SharePlace;
  1865. }
  1866. }
  1867. // 队员
  1868. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1869. {
  1870. if (g_Team[m_cTeam.m_nID].m_nMember[i] < 0)
  1871. continue;
  1872. nNpcIdx = Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex;
  1873. if (nSelfSubIdx != Npc[nNpcIdx].m_SubWorldIndex)
  1874. continue;
  1875. SubWorld[Npc[nNpcIdx].m_SubWorldIndex].Map2Mps(
  1876. Npc[nNpcIdx].m_RegionIndex,
  1877. Npc[nNpcIdx].m_MapX,
  1878. Npc[nNpcIdx].m_MapY,
  1879. Npc[nNpcIdx].m_OffX,
  1880. Npc[nNpcIdx].m_OffY,
  1881. &nMpsX,
  1882. &nMpsY);
  1883. if ( (nMpsX - nSelfMpsX) * (nMpsX - nSelfMpsX) + 
  1884. (nMpsY - nSelfMpsY) * (nMpsY - nSelfMpsY) > 
  1885. PLAYER_SHARE_EXP_DISTANCE * PLAYER_SHARE_EXP_DISTANCE)
  1886. continue;
  1887. nTotalLevel += Npc[nNpcIdx].m_Level;
  1888. nShareFlag[i + 1] = 1;
  1889. nTotalPlayer++;
  1890. if (nTotalPlayer >= g_Team[m_cTeam.m_nID].m_nMemNum + 1)
  1891. goto SharePlace;
  1892. }
  1893. SharePlace:
  1894. _ASSERT(nTotalPlayer >= 1);
  1895. _ASSERT(nTotalLevel >= 1);
  1896. if (nTotalPlayer < 1 || nTotalLevel < 1)
  1897. return;
  1898. if (nTotalPlayer == 1)
  1899. {
  1900. AddSelfExp(nExp, nTarLevel);
  1901. return;
  1902. }
  1903. int k, nGetExp;
  1904. k = 100 + nTotalPlayer * 15;
  1905. // 给队长分配经验
  1906. if (nShareFlag[0])
  1907. {
  1908. nGetExp = k * Npc[Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nIndex].m_Level / nTotalLevel;
  1909. if (nGetExp < 5)
  1910. nGetExp = 5;
  1911. Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
  1912. // LeadExp = 怪物提供的经验值 * β * 分享者等级 / 分享者等级和;
  1913. int nLeadExp = nExp * k * PlayerSet.m_cLevelAdd.GetLeadExpShare(Npc[m_nIndex].m_Series) * (nTotalLevel - Npc[m_nIndex].m_Level) / (nTotalLevel * 10000);
  1914. Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddLeadExp(nLeadExp);
  1915. // if (g_Team[m_cTeam.m_nID].m_nCaptain == m_nPlayerIndex)
  1916. // {
  1917. // if (nGetExp < 50)
  1918. // nGetExp = 50;
  1919. // Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
  1920. // }
  1921. // else
  1922. // {
  1923. // if (nGetExp < 5)
  1924. // nGetExp = 5;
  1925. // Player[g_Team[m_cTeam.m_nID].m_nCaptain].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
  1926. // }
  1927. }
  1928. // 给队员分配经验
  1929. for (i = 0; i < MAX_TEAM_MEMBER; i++)
  1930. {
  1931. if ( !nShareFlag[i + 1] )
  1932. continue;
  1933. nGetExp = k * Npc[Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nIndex].m_Level / nTotalLevel;
  1934. if (nGetExp < 5)
  1935. nGetExp = 5;
  1936. Player[g_Team[m_cTeam.m_nID].m_nMember[i]].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
  1937. // if (g_Team[m_cTeam.m_nID].m_nMember[i] == m_nPlayerIndex)
  1938. // {
  1939. // if (nGetExp < 50)
  1940. // nGetExp = 50;
  1941. // Player[g_Team[m_cTeam.m_nID].m_nMember[i]].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
  1942. // }
  1943. // else
  1944. // {
  1945. // if (nGetExp < 5)
  1946. // nGetExp = 5;
  1947. // Player[g_Team[m_cTeam.m_nID].m_nMember[i]].AddSelfExp(nExp * nGetExp / 100, nTarLevel);
  1948. // }
  1949. }
  1950. #endif
  1951. }
  1952. //-------------------------------------------------------------------------
  1953. // 功能:增加经验(不需要再经过队伍分配的处理)
  1954. //  nExp 增加的经验  nTarLevel 被打死的npc的等级
  1955. // 详情参阅 sourcesafe策划库documentSystem战斗经验设定.doc
  1956. //-------------------------------------------------------------------------
  1957. void KPlayer::AddSelfExp(int nExp, int nTarLevel)
  1958. {
  1959. if (nExp <= 0)
  1960. return;
  1961. if (Npc[m_nIndex].m_Level >= MAX_LEVEL)
  1962. return;
  1963. if (Npc[m_nIndex].m_Doing == do_death || Npc[m_nIndex].m_Doing == do_revive)
  1964. return;
  1965. int nSubLevel, nGetExp;
  1966. // int nAbsLevel;
  1967. nSubLevel = Npc[m_nIndex].m_Level - nTarLevel;
  1968. if (nSubLevel <= 5)
  1969. {
  1970. nGetExp = nExp;
  1971. }
  1972. else if (nSubLevel <= 15)
  1973. {
  1974. // nGetExp = nExp * (100 - (95 / 10) * (nSubLevel - 5)) / 100;
  1975. nGetExp = nExp * (295 - 19 * nSubLevel) / 200;
  1976. }
  1977. else
  1978. {
  1979. nGetExp = nExp / 20;
  1980. }
  1981. /*
  1982. nAbsLevel = abs(nTarLevel - Npc[m_nIndex].m_Level);
  1983.   if (nAbsLevel <= 10)
  1984.   {
  1985.   nGetExp = nExp;
  1986.   }
  1987.   else if (nAbsLevel <= 20)
  1988.   {
  1989.   nGetExp = nExp * (30 - nAbsLevel) / 20; // EXP=X*(150-|LM-LP|*5)/100
  1990.   }
  1991.   else
  1992.   {
  1993.   nGetExp = nExp / 2;
  1994.   }
  1995. */
  1996. if (nGetExp <= 0)
  1997. nGetExp = 1;
  1998. m_nExp += nGetExp;
  1999. g_DebugLog("[数值]%s实际增加经验%d点", Npc[m_nIndex].Name, nGetExp);
  2000. #ifdef _SERVER
  2001. if (m_nExp >= m_nNextLevelExp) // 升级
  2002. {
  2003. LevelUp();
  2004. }
  2005. else // 同步经验
  2006. {
  2007. PLAYER_EXP_SYNC sSyncExp;
  2008. sSyncExp.ProtocolType = (BYTE)s2c_playerexp;
  2009. sSyncExp.m_nExp = m_nExp;
  2010. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSyncExp, sizeof(PLAYER_EXP_SYNC));
  2011. }
  2012. #endif
  2013. }
  2014. //-------------------------------------------------------------------------
  2015. // 功能:直接增加经验值,不考虑其他因素
  2016. //-------------------------------------------------------------------------
  2017. void KPlayer::DirectAddExp(int nExp)
  2018. {
  2019. if (nExp > 0 && Npc[m_nIndex].m_Level >= MAX_LEVEL)
  2020. return;
  2021. m_nExp += nExp;
  2022. if (m_nExp < 0)
  2023. {
  2024. if (-m_nExp > m_nNextLevelExp)
  2025. m_nExp = -m_nNextLevelExp;
  2026. }
  2027. #ifdef _SERVER
  2028. if (m_nExp >= m_nNextLevelExp) // 升级
  2029. {
  2030. LevelUp();
  2031. }
  2032. else // 同步经验
  2033. {
  2034. PLAYER_EXP_SYNC sSyncExp;
  2035. sSyncExp.ProtocolType = (BYTE)s2c_playerexp;
  2036. sSyncExp.m_nExp = m_nExp;
  2037. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sSyncExp, sizeof(PLAYER_EXP_SYNC));
  2038. }
  2039. #endif
  2040. }
  2041. //-------------------------------------------------------------------------
  2042. // 功能:玩家升一级
  2043. //-------------------------------------------------------------------------
  2044. void KPlayer::LevelUp()
  2045. {
  2046. m_nExp = 0;
  2047. if (Npc[m_nIndex].m_Level >= MAX_LEVEL)
  2048. return;
  2049. Npc[m_nIndex].m_Level++;
  2050. m_nNextLevelExp = PlayerSet.m_cLevelAdd.GetLevelExp(Npc[m_nIndex].m_Level);
  2051. // -------------------------- 等级增加时各项属性增加 ----------------------
  2052. // 增加未分配属性点
  2053. m_nAttributePoint += PLAYER_LEVEL_ADD_ATTRIBUTE;
  2054. // 增加未分配技能点
  2055. m_nSkillPoint += PLAYER_LEVEL_ADD_SKILL;
  2056. // 处理生命、体力、内力值(影响基本生命、体力、内力最大值的因素:等级、属性点,影响当前生命最大值的因素:装备、技能、药物(临时))
  2057. LevelAddBaseLifeMax();
  2058. LevelAddBaseStaminaMax();
  2059. LevelAddBaseManaMax();
  2060. // Npc[m_nIndex].ResetLifeReplenish();
  2061. // 处理各种抗性的变化 火、冰、毒、电、物理
  2062. Npc[m_nIndex].m_FireResist = PlayerSet.m_cLevelAdd.GetFireResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2063. Npc[m_nIndex].m_CurrentFireResist = Npc[m_nIndex].m_FireResist;
  2064. Npc[m_nIndex].m_ColdResist = PlayerSet.m_cLevelAdd.GetColdResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2065. Npc[m_nIndex].m_CurrentColdResist = Npc[m_nIndex].m_ColdResist;
  2066. Npc[m_nIndex].m_PoisonResist = PlayerSet.m_cLevelAdd.GetPoisonResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2067. Npc[m_nIndex].m_CurrentPoisonResist = Npc[m_nIndex].m_PoisonResist;
  2068. Npc[m_nIndex].m_LightResist = PlayerSet.m_cLevelAdd.GetLightResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2069. Npc[m_nIndex].m_CurrentLightResist = Npc[m_nIndex].m_LightResist;
  2070. Npc[m_nIndex].m_PhysicsResist = PlayerSet.m_cLevelAdd.GetPhysicsResist(Npc[m_nIndex].m_Series, Npc[m_nIndex].m_Level);
  2071. Npc[m_nIndex].m_CurrentPhysicsResist = Npc[m_nIndex].m_PhysicsResist;
  2072. Npc[m_nIndex].m_FireResistMax = BASE_FIRE_RESIST_MAX;
  2073. Npc[m_nIndex].m_ColdResistMax = BASE_COLD_RESIST_MAX;
  2074. Npc[m_nIndex].m_PoisonResistMax = BASE_POISON_RESIST_MAX;
  2075. Npc[m_nIndex].m_LightResistMax = BASE_LIGHT_RESIST_MAX;
  2076. Npc[m_nIndex].m_PhysicsResistMax = BASE_PHYSICS_RESIST_MAX;
  2077. Npc[m_nIndex].m_CurrentFireResistMax = Npc[m_nIndex].m_FireResistMax;
  2078. Npc[m_nIndex].m_CurrentColdResistMax = Npc[m_nIndex].m_ColdResistMax;
  2079. Npc[m_nIndex].m_CurrentPoisonResistMax = Npc[m_nIndex].m_PoisonResistMax;
  2080. Npc[m_nIndex].m_CurrentLightResistMax = Npc[m_nIndex].m_LightResistMax;
  2081. Npc[m_nIndex].m_CurrentPhysicsResistMax = Npc[m_nIndex].m_PhysicsResistMax;
  2082. int nOldCurCamp = Npc[m_nIndex].m_CurrentCamp;
  2083. // 根据装备、技能信息更新当前数据
  2084. this->UpdataCurData();
  2085. SetNpcPhysicsDamage();
  2086. Npc[m_nIndex].m_CurrentCamp = nOldCurCamp;
  2087. // 生命、体力、内力值加满
  2088. Npc[m_nIndex].m_CurrentLife = Npc[m_nIndex].m_CurrentLifeMax;
  2089. Npc[m_nIndex].m_CurrentStamina = Npc[m_nIndex].m_CurrentStaminaMax;
  2090. Npc[m_nIndex].m_CurrentMana = Npc[m_nIndex].m_CurrentManaMax;
  2091. #ifdef _SERVER
  2092. // 给客户端发送数据
  2093. // 自己的数据
  2094. PLAYER_LEVEL_UP_SYNC sLevelUp;
  2095. sLevelUp.ProtocolType = s2c_playerlevelup;
  2096. sLevelUp.m_btLevel = (DWORD)Npc[m_nIndex].m_Level;
  2097. sLevelUp.m_nExp = m_nExp;
  2098. sLevelUp.m_nAttributePoint = m_nAttributePoint;
  2099. sLevelUp.m_nSkillPoint = m_nSkillPoint;
  2100. sLevelUp.m_nBaseLifeMax = Npc[m_nIndex].m_LifeMax;
  2101. sLevelUp.m_nBaseStaminaMax = Npc[m_nIndex].m_StaminaMax;
  2102. sLevelUp.m_nBaseManaMax = Npc[m_nIndex].m_ManaMax;
  2103. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLevelUp, sizeof(PLAYER_LEVEL_UP_SYNC));
  2104. // 给队友发送等级数据
  2105. if ( m_cTeam.m_nFlag )
  2106. {
  2107. PLAYER_TEAMMATE_LEVEL_SYNC sLevel;
  2108. sLevel.ProtocolType = s2c_teammatelevel;
  2109. sLevel.m_btLevel = (DWORD)Npc[m_nIndex].m_Level;
  2110. sLevel.m_dwTeammateID = Npc[m_nIndex].m_dwID;
  2111. // 给队长发
  2112. if (m_cTeam.m_nFigure != TEAM_CAPTAIN)
  2113. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nCaptain].m_nNetConnectIdx, (BYTE*)&sLevel, sizeof(PLAYER_TEAMMATE_LEVEL_SYNC));
  2114. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  2115. {
  2116. if (g_Team[m_cTeam.m_nID].m_nMember[i] >= 0 && g_Team[m_cTeam.m_nID].m_nMember[i] != GetPlayerIndex())
  2117. g_pServer->PackDataToClient(Player[g_Team[m_cTeam.m_nID].m_nMember[i]].m_nNetConnectIdx, (BYTE*)&sLevel, sizeof(PLAYER_TEAMMATE_LEVEL_SYNC));
  2118. }
  2119. }
  2120. #endif
  2121. }
  2122. // need spe edit not end
  2123. void KPlayer::UpdataCurData()
  2124. {
  2125. if (m_nIndex <= 0 || m_nIndex >= MAX_NPC)
  2126. return;
  2127. Npc[m_nIndex].m_CurrentLifeMax = Npc[m_nIndex].m_LifeMax;
  2128. Npc[m_nIndex].m_CurrentManaMax = Npc[m_nIndex].m_ManaMax;
  2129. Npc[m_nIndex].m_CurrentStaminaMax = Npc[m_nIndex].m_StaminaMax;
  2130. Npc[m_nIndex].m_CurrentAttackRating = Npc[m_nIndex].m_AttackRating;
  2131. Npc[m_nIndex].m_CurrentAttackSpeed = Npc[m_nIndex].m_AttackSpeed;
  2132. // Npc[m_nIndex].m_CurrentCamp = Npc[m_nIndex].m_Camp;
  2133. Npc[m_nIndex].m_CurrentCastSpeed = Npc[m_nIndex].m_CastSpeed;
  2134. ZeroMemory(&Npc[m_nIndex].m_CurrentColdDamage, sizeof(KMagicAttrib));
  2135. Npc[m_nIndex].m_CurrentColdEnhance = 0;
  2136. Npc[m_nIndex].m_CurrentColdResist = Npc[m_nIndex].m_ColdResist;
  2137. Npc[m_nIndex].m_CurrentColdResistMax = Npc[m_nIndex].m_ColdResistMax;
  2138. Npc[m_nIndex].m_CurrentDamage2Mana = 0;
  2139. Npc[m_nIndex].m_CurrentDamageReduce = 0;
  2140. Npc[m_nIndex].m_CurrentDeadlyStrike = 0;
  2141. Npc[m_nIndex].m_CurrentDefend = Npc[m_nIndex].m_Defend;
  2142. Npc[m_nIndex].m_CurrentElementDamageReduce = 0;
  2143. ZeroMemory(&Npc[m_nIndex].m_CurrentFireDamage, sizeof(KMagicAttrib));
  2144. Npc[m_nIndex].m_CurrentFireEnhance = 0;
  2145. Npc[m_nIndex].m_CurrentFireResist = Npc[m_nIndex].m_FireResist;
  2146. Npc[m_nIndex].m_CurrentFireResistMax = Npc[m_nIndex].m_FireResistMax;
  2147. Npc[m_nIndex].m_CurrentHandEnhance = 0;
  2148. Npc[m_nIndex].m_CurrentHitRecover = Npc[m_nIndex].m_HitRecover;
  2149. Npc[m_nIndex].m_CurrentJumpSpeed = Npc[m_nIndex].m_JumpSpeed;
  2150. Npc[m_nIndex].m_CurrentKnockBack = 0;
  2151. Npc[m_nIndex].m_CurrentLifeReplenish = Npc[m_nIndex].m_LifeReplenish;
  2152. Npc[m_nIndex].m_CurrentLifeStolen = 0;
  2153. ZeroMemory(&Npc[m_nIndex].m_CurrentLightDamage, sizeof(KMagicAttrib));
  2154. Npc[m_nIndex].m_CurrentLightEnhance = 0;
  2155. Npc[m_nIndex].m_CurrentLightResist = Npc[m_nIndex].m_LightResist;
  2156. Npc[m_nIndex].m_CurrentLightResistMax = Npc[m_nIndex].m_LightResistMax;
  2157. Npc[m_nIndex].m_CurrentManaPerEnemy = 0;
  2158. Npc[m_nIndex].m_CurrentManaReplenish = Npc[m_nIndex].m_ManaReplenish;
  2159. Npc[m_nIndex].m_CurrentManaStolen = 0;
  2160. Npc[m_nIndex].m_CurrentMeleeDmgRet = 0;
  2161. Npc[m_nIndex].m_CurrentMeleeDmgRetPercent = 0;
  2162. ZeroMemory(&Npc[m_nIndex].m_CurrentMeleeEnhance, sizeof(Npc[m_nIndex].m_CurrentMeleeEnhance));
  2163. Npc[m_nIndex].m_CurrentPhysicsResist = Npc[m_nIndex].m_PhysicsResist;
  2164. Npc[m_nIndex].m_CurrentPhysicsResistMax = Npc[m_nIndex].m_PhysicsResistMax;
  2165. Npc[m_nIndex].m_CurrentPiercePercent = 0;
  2166. ZeroMemory(&Npc[m_nIndex].m_CurrentPoisonDamage, sizeof(KMagicAttrib));
  2167. Npc[m_nIndex].m_CurrentPoisonEnhance = 0;
  2168. Npc[m_nIndex].m_CurrentPoisonResist = Npc[m_nIndex].m_PoisonResist;
  2169. Npc[m_nIndex].m_CurrentPoisonResistMax = Npc[m_nIndex].m_PoisonResistMax;
  2170. Npc[m_nIndex].m_CurrentRangeDmgRet = 0;
  2171. Npc[m_nIndex].m_CurrentRangeDmgRetPercent = 0;
  2172. Npc[m_nIndex].m_CurrentRangeEnhance = 0;
  2173. Npc[m_nIndex].m_CurrentRunSpeed = Npc[m_nIndex].m_RunSpeed;
  2174. Npc[m_nIndex].m_CurrentSlowMissle = 0;
  2175. Npc[m_nIndex].m_CurrentStaminaGain = Npc[m_nIndex].m_StaminaGain;
  2176. Npc[m_nIndex].m_CurrentStaminaLoss = Npc[m_nIndex].m_StaminaLoss;
  2177. Npc[m_nIndex].m_CurrentStaminaStolen = 0;
  2178. Npc[m_nIndex].m_CurrentVisionRadius = Npc[m_nIndex].m_VisionRadius;
  2179. Npc[m_nIndex].m_CurrentWalkSpeed = Npc[m_nIndex].m_WalkSpeed;
  2180. Npc[m_nIndex].m_CurrentAddPhysicsDamage = 0;
  2181. m_nCurStrength = m_nStrength;
  2182. m_nCurDexterity = m_nDexterity;
  2183. m_nCurVitality = m_nVitality;
  2184. m_nCurEngergy = m_nEngergy;
  2185. m_nCurLucky = m_nLucky;
  2186. ReCalcEquip();
  2187. ReCalcState();
  2188. }
  2189. void KPlayer::ReCalcEquip()
  2190. {
  2191. _ASSERT(m_nIndex > 0 && m_nIndex < MAX_NPC);
  2192. for (int i = 0; i < itempart_num; i++)
  2193. {
  2194. int nIdx = m_ItemList.m_EquipItem[i];
  2195. if (!nIdx)
  2196. continue;
  2197. int nActive = m_ItemList.GetEquipEnhance(i);
  2198. Item[nIdx].ApplyMagicAttribToNPC(&Npc[m_nIndex], nActive);
  2199. }
  2200. }
  2201. void KPlayer::ReCalcState()
  2202. {
  2203. _ASSERT(m_nIndex > 0 && m_nIndex < MAX_NPC);
  2204. Npc[m_nIndex].ReCalcStateEffect();
  2205. }
  2206. //-------------------------------------------------------------------------
  2207. // 功能:增加统率力经验
  2208. //-------------------------------------------------------------------------
  2209. void KPlayer::AddLeadExp(int nExp)
  2210. {
  2211. if (m_dwLeadLevel >= MAX_LEAD_LEVEL)
  2212. return;
  2213. if (Npc[m_nIndex].m_Doing == do_death || Npc[m_nIndex].m_Doing == do_revive)
  2214. return;
  2215. m_dwLeadExp += nExp;
  2216. if (m_dwLeadExp >= (DWORD)PlayerSet.m_cLeadExp.GetLevelExp(m_dwLeadLevel))
  2217. {
  2218. // 升级
  2219. m_dwLeadLevel = PlayerSet.m_cLeadExp.GetLevel(m_dwLeadExp, m_dwLeadLevel);
  2220. #ifndef _SERVER
  2221. m_dwNextLevelLeadExp = PlayerSet.m_cLeadExp.GetLevelExp(m_dwLeadLevel);
  2222. #endif
  2223. }
  2224. #ifdef _SERVER
  2225. PLAYER_LEAD_EXP_SYNC sLeadExp;
  2226. sLeadExp.ProtocolType = s2c_playersyncleadexp;
  2227. sLeadExp.m_dwLeadExp = m_dwLeadExp;
  2228. g_pServer->PackDataToClient(m_nNetConnectIdx, (BYTE*)&sLeadExp, sizeof(PLAYER_LEAD_EXP_SYNC));
  2229. #endif
  2230. }
  2231. //-------------------------------------------------------------------------
  2232. // 功能:玩家升一级加生命
  2233. //-------------------------------------------------------------------------
  2234. void KPlayer::LevelAddBaseLifeMax()
  2235. {
  2236. Npc[m_nIndex].m_LifeMax += PlayerSet.m_cLevelAdd.GetLifePerLevel(Npc[m_nIndex].m_Series);
  2237. Npc[m_nIndex].m_CurrentLifeMax = Npc[m_nIndex].m_LifeMax;
  2238. }
  2239. //-------------------------------------------------------------------------
  2240. // 功能:玩家升一级加体力
  2241. //-------------------------------------------------------------------------
  2242. void KPlayer::LevelAddBaseStaminaMax()
  2243. {
  2244. Npc[m_nIndex].m_StaminaMax += PlayerSet.m_cLevelAdd.GetStaminaPerLevel(Npc[m_nIndex].m_Series);
  2245. Npc[m_nIndex].m_CurrentStaminaMax = Npc[m_nIndex].m_StaminaMax;
  2246. }
  2247. //-------------------------------------------------------------------------
  2248. // 功能:玩家升一级加内力
  2249. //-------------------------------------------------------------------------
  2250. void KPlayer::LevelAddBaseManaMax()
  2251. {
  2252. Npc[m_nIndex].m_ManaMax += PlayerSet.m_cLevelAdd.GetManaPerLevel(Npc[m_nIndex].m_Series);
  2253. Npc[m_nIndex].m_CurrentManaMax = Npc[m_nIndex].m_ManaMax;
  2254. }
  2255. //-------------------------------------------------------------------------
  2256. // 功能:改变玩家阵营
  2257. //-------------------------------------------------------------------------
  2258. void KPlayer::ChangePlayerCamp(int nCamp)
  2259. {
  2260. if (nCamp < camp_begin || nCamp >= camp_num)
  2261. return;
  2262. Npc[m_nIndex].m_Camp = (NPCCAMP)nCamp;
  2263. }
  2264. #ifndef _SERVER
  2265. //-------------------------------------------------------------------------
  2266. // 功能:向服务器申请查询某个npc所在队伍的信息
  2267. //-------------------------------------------------------------------------
  2268. void KPlayer::ApplyTeamInfo(DWORD dwNpcID)
  2269. {
  2270. if (dwNpcID <= 0)
  2271. return;
  2272. PLAYER_APPLY_TEAM_INFO sApplyInfo;
  2273. sApplyInfo.ProtocolType = (BYTE)c2s_teamapplyinfo;
  2274. sApplyInfo.m_dwTarNpcID = dwNpcID;
  2275. if (g_pClient)
  2276. g_pClient->SendPackToServer(&sApplyInfo, sizeof(PLAYER_APPLY_TEAM_INFO));
  2277. }
  2278. #endif
  2279. #ifndef _SERVER
  2280. //-------------------------------------------------------------------------
  2281. // 功能:向服务器申请查询玩家自身的队伍情况
  2282. //-------------------------------------------------------------------------
  2283. void KPlayer::ApplySelfTeamInfo()
  2284. {
  2285. ApplyTeamInfo(Npc[m_nIndex].m_dwID);
  2286. }
  2287. #endif
  2288. #ifndef _SERVER
  2289. //-------------------------------------------------------------------------
  2290. // 功能:玩家向服务器申请创建队伍
  2291. //-------------------------------------------------------------------------
  2292. BOOL KPlayer::ApplyCreateTeam()//char *lpszTeamName)
  2293. {
  2294. return m_cTeam.ApplyCreate();//lpszTeamName);
  2295. }
  2296. #endif
  2297. #ifndef _SERVER
  2298. //-------------------------------------------------------------------------
  2299. // 功能:队长向服务器申请开放、关闭队伍是否允许加入成员状态
  2300. //-------------------------------------------------------------------------
  2301. BOOL KPlayer::ApplyTeamOpenClose(BOOL bFlag)
  2302. {
  2303. if ( !m_cTeam.m_nFlag ) // 未组队
  2304. return FALSE;
  2305. if (m_cTeam.m_nFigure != TEAM_CAPTAIN) // 不是队长
  2306. return FALSE;
  2307. if (this->CheckTrading()) // 处在交易状态
  2308. return FALSE;
  2309. if (bFlag)
  2310. {
  2311. if (PlayerSet.m_cLeadExp.GetMemNumFromLevel(m_dwLeadLevel) <= g_Team[0].m_nMemNum) // 统帅力不够
  2312. return FALSE;
  2313. }
  2314. PLAYER_TEAM_OPEN_CLOSE sTeamState;
  2315. sTeamState.ProtocolType = c2s_teamapplyopenclose;
  2316. sTeamState.m_btOpenClose = bFlag;
  2317. if (g_pClient)
  2318. g_pClient->SendPackToServer(&sTeamState, sizeof(PLAYER_TEAM_OPEN_CLOSE));
  2319. return TRUE;
  2320. }
  2321. #endif
  2322. #ifndef _SERVER
  2323. //-------------------------------------------------------------------------
  2324. // 功能:玩家向服务器申请加入某个队伍
  2325. // 参数:int nNpcIndex 目标队伍队长在客户端Npc数组中的位置
  2326. //-------------------------------------------------------------------------
  2327. void KPlayer::ApplyAddTeam(int nNpcIndex)
  2328. {
  2329. if (this->CheckTrading())
  2330. return;
  2331. if (m_cTeam.m_nFlag) // 已经组队,不能申请加入别的队伍
  2332. return;
  2333. // 不同阵营现在可以组队,老手不能加入新人队伍,新人可以加入老手队伍
  2334. if (Npc[nNpcIndex].m_Camp == camp_begin && Npc[m_nIndex].m_Camp != camp_begin)
  2335. return;
  2336. // if (Npc[nNpcIndex].m_Camp != Npc[m_nIndex].m_Camp) // 阵营不同
  2337. // return;
  2338. // 判断目标队伍队长是不是处在队伍开放状态
  2339. if (Npc[nNpcIndex].GetMenuState() != PLAYER_MENU_STATE_TEAMOPEN)
  2340. return;
  2341. m_cTeam.m_nApplyCaptainID = Npc[nNpcIndex].m_dwID;
  2342. m_cTeam.m_dwApplyTimer = MAX_APPLY_TEAM_TIME;
  2343. PLAYER_APPLY_ADD_TEAM sAddTeam;
  2344. sAddTeam.ProtocolType = c2s_teamapplyadd;
  2345. sAddTeam.m_dwTarNpcID = Npc[nNpcIndex].m_dwID;
  2346. if (g_pClient)
  2347. g_pClient->SendPackToServer(&sAddTeam, sizeof(PLAYER_APPLY_ADD_TEAM));
  2348. KSystemMessage sMsg;
  2349. sprintf(sMsg.szMessage, MSG_TEAM_APPLY_ADD_SELF_MSG, Npc[nNpcIndex].Name);
  2350. sMsg.eType = SMT_NORMAL;
  2351. sMsg.byConfirmType = SMCT_NONE;
  2352. sMsg.byPriority = 0;
  2353. sMsg.byParamSize = 0;
  2354. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2355. }
  2356. #endif
  2357. #ifndef _SERVER
  2358. //-------------------------------------------------------------------------
  2359. // 功能:玩家通知服务器接受某个npc为队伍成员
  2360. //-------------------------------------------------------------------------
  2361. void KPlayer::AcceptTeamMember(DWORD dwNpcID)
  2362. {
  2363. // 判断状态 (缺少对npc队伍开放状态的检测 not end)
  2364. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  2365. {
  2366. ApplySelfTeamInfo();
  2367. return;
  2368. }
  2369. if (dwNpcID == 0)
  2370. return;
  2371. // 查找申请列表
  2372. int i;
  2373. for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
  2374. {
  2375. if (m_cTeam.m_sApplyList[i].m_dwNpcID == dwNpcID)
  2376. {
  2377. m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
  2378. m_cTeam.UpdateInterface();
  2379. break;
  2380. }
  2381. }
  2382. // 如果没找到
  2383. // if (i >= MAX_TEAM_APPLY_LIST)
  2384. // return;
  2385. // 向服务器发申请
  2386. PLAYER_ACCEPT_TEAM_MEMBER sAcceptTeam;
  2387. sAcceptTeam.ProtocolType = c2s_teamacceptmember;
  2388. sAcceptTeam.m_dwNpcID = dwNpcID;
  2389. if (g_pClient)
  2390. g_pClient->SendPackToServer(&sAcceptTeam, sizeof(PLAYER_ACCEPT_TEAM_MEMBER));
  2391. }
  2392. #endif
  2393. #ifndef _SERVER
  2394. //-------------------------------------------------------------------------
  2395. // 功能:队长删除加入队伍申请列表中的某个npc
  2396. //-------------------------------------------------------------------------
  2397. void KPlayer::TeamDropApplyOne(DWORD dwNpcID)
  2398. {
  2399. if (dwNpcID == 0)
  2400. return;
  2401. // 查找申请列表
  2402. int i;
  2403. for (i = 0; i < MAX_TEAM_APPLY_LIST; i++)
  2404. {
  2405. if (m_cTeam.m_sApplyList[i].m_dwNpcID == dwNpcID)
  2406. {
  2407. m_cTeam.m_sApplyList[i].m_dwNpcID = 0;
  2408. m_cTeam.m_sApplyList[i].m_dwTimer = 0;
  2409. m_cTeam.m_sApplyList[i].m_nLevel = 0;
  2410. m_cTeam.m_sApplyList[i].m_szName[0] = 0;
  2411. break;
  2412. }
  2413. }
  2414. }
  2415. #endif
  2416. #ifndef _SERVER
  2417. //-------------------------------------------------------------------------
  2418. // 功能:通知服务器本玩家离开队伍
  2419. //-------------------------------------------------------------------------
  2420. void KPlayer::LeaveTeam()
  2421. {
  2422. PLAYER_APPLY_LEAVE_TEAM sLeaveTeam;
  2423. sLeaveTeam.ProtocolType = c2s_teamapplyleave;
  2424. if (g_pClient)
  2425. g_pClient->SendPackToServer(&sLeaveTeam, sizeof(PLAYER_APPLY_LEAVE_TEAM));
  2426. }
  2427. #endif
  2428. #ifndef _SERVER
  2429. //-------------------------------------------------------------------------
  2430. // 功能:队长通知服务器踢除某个队员
  2431. //-------------------------------------------------------------------------
  2432. void KPlayer::TeamKickMember(DWORD dwNpcID)
  2433. {
  2434. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  2435. return;
  2436. PLAYER_TEAM_KICK_MEMBER sKickOne;
  2437. sKickOne.ProtocolType = c2s_teamapplykickmember;
  2438. sKickOne.m_dwNpcID = dwNpcID;
  2439. if (g_pClient)
  2440. g_pClient->SendPackToServer(&sKickOne, sizeof(PLAYER_TEAM_KICK_MEMBER));
  2441. }
  2442. #endif
  2443. #ifndef _SERVER
  2444. //-------------------------------------------------------------------------
  2445. // 功能:队长向服务器申请把自己的队长身份交给别的队员
  2446. //-------------------------------------------------------------------------
  2447. void KPlayer::ApplyTeamChangeCaptain(DWORD dwNpcID)
  2448. {
  2449. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  2450. return;
  2451. PLAYER_APPLY_TEAM_CHANGE_CAPTAIN sTeamChange;
  2452. sTeamChange.ProtocolType = c2s_teamapplychangecaptain;
  2453. sTeamChange.m_dwNpcID = dwNpcID;
  2454. if (g_pClient)
  2455. g_pClient->SendPackToServer(&sTeamChange, sizeof(PLAYER_APPLY_TEAM_CHANGE_CAPTAIN));
  2456. }
  2457. #endif
  2458. #ifndef _SERVER
  2459. //-------------------------------------------------------------------------
  2460. // 功能:队长向服务器申请解散队伍
  2461. //-------------------------------------------------------------------------
  2462. void KPlayer::ApplyTeamDismiss()
  2463. {
  2464. if ( !m_cTeam.m_nFlag || m_cTeam.m_nFigure != TEAM_CAPTAIN)
  2465. return;
  2466. PLAYER_APPLY_TEAM_DISMISS sTeamDismiss;
  2467. sTeamDismiss.ProtocolType = c2s_teamapplydismiss;
  2468. if (g_pClient)
  2469. g_pClient->SendPackToServer(&sTeamDismiss, sizeof(PLAYER_APPLY_TEAM_DISMISS));
  2470. }
  2471. #endif
  2472. #ifndef _SERVER
  2473. //-------------------------------------------------------------------------
  2474. // 功能:玩家向服务器申请打开、关闭pk开关
  2475. //-------------------------------------------------------------------------
  2476. void KPlayer::ApplySetPK(BOOL bPK)
  2477. {
  2478. PLAYER_SET_PK sPK;
  2479. sPK.ProtocolType = c2s_playerapplysetpk;
  2480. sPK.m_btPKFlag = bPK;
  2481. if (g_pClient)
  2482. g_pClient->SendPackToServer(&sPK, sizeof(PLAYER_SET_PK));
  2483. }
  2484. #endif
  2485. #ifndef _SERVER
  2486. //-------------------------------------------------------------------------
  2487. // 功能:玩家向服务器申请门派数据
  2488. //-------------------------------------------------------------------------
  2489. void KPlayer::ApplyFactionData()
  2490. {
  2491. PLAYER_APPLY_FACTION_DATA sFaction;
  2492. sFaction.ProtocolType = c2s_playerapplyfactiondata;
  2493. if (g_pClient)
  2494. g_pClient->SendPackToServer(&sFaction, sizeof(PLAYER_APPLY_FACTION_DATA));
  2495. }
  2496. #endif
  2497. #ifndef _SERVER
  2498. //-------------------------------------------------------------------------
  2499. // 功能:客户端发送聊天语句给服务器
  2500. //-------------------------------------------------------------------------
  2501. void KPlayer::SendChat(KUiMsgParam *pMsg, char *lpszSentence)
  2502. {
  2503. if (!lpszSentence || !pMsg || pMsg->nMsgLength <= 0)
  2504. return;
  2505. int nLength = pMsg->nMsgLength;
  2506. if (nLength >= MAX_SENTENCE_LENGTH)
  2507. nLength = MAX_SENTENCE_LENGTH - 1;
  2508. if (pMsg->eGenre == MSG_G_CHAT)
  2509. {
  2510. Npc[m_nIndex].SetChatInfo(pMsg->szName, lpszSentence, nLength);
  2511. m_cChat.SendSentence(pMsg, Npc[m_nIndex].m_szChatBuffer);
  2512. }
  2513. else if (pMsg->eGenre == MSG_G_CMD) // not end
  2514. {
  2515. }
  2516. }
  2517. #endif
  2518. #ifndef _SERVER
  2519. //-------------------------------------------------------------------------
  2520. // 功能:队长向服务器申请增加四项属性中某一项的点数(0=Strength 1=Dexterity 2=Vitality 3=Engergy)
  2521. //-------------------------------------------------------------------------
  2522. void KPlayer::ApplyAddBaseAttribute(int nAttribute, int nNo)
  2523. {
  2524. if (nAttribute < 0 || nAttribute > 3)
  2525. return;
  2526. if (nNo <= 0 || nNo >= 255)
  2527. return;
  2528. PLAYER_ADD_BASE_ATTRIBUTE_COMMAND sAdd;
  2529. sAdd.ProtocolType = c2s_playeraddbaseattribute;
  2530. sAdd.m_btAttribute = nAttribute;
  2531. sAdd.m_nAddNo = nNo;
  2532. if (g_pClient)
  2533. g_pClient->SendPackToServer(&sAdd, sizeof(PLAYER_ADD_BASE_ATTRIBUTE_COMMAND));
  2534. }
  2535. #endif
  2536. #ifndef _SERVER
  2537. //-------------------------------------------------------------------------
  2538. // 功能:向服务器申请某个技能升级
  2539. //-------------------------------------------------------------------------
  2540. BOOL KPlayer::ApplyAddSkillLevel(int nSkillID, int nAddPoint)
  2541. {
  2542. if ( !Npc[m_nIndex].m_SkillList.FindSame(nSkillID) )
  2543. return FALSE;
  2544. if (m_nSkillPoint < nAddPoint || nAddPoint + Npc[m_nIndex].m_SkillList.GetLevel(nSkillID) > MAX_SKILLLEVEL)
  2545. return FALSE;
  2546. PLAYER_ADD_SKILL_POINT_COMMAND sSkill;
  2547. sSkill.ProtocolType = c2s_playerapplyaddskillpoint;
  2548. sSkill.m_nSkillID = nSkillID;
  2549. sSkill.m_nAddPoint = nAddPoint;
  2550. if (g_pClient)
  2551. g_pClient->SendPackToServer(&sSkill, sizeof(PLAYER_ADD_SKILL_POINT_COMMAND));
  2552. return TRUE;
  2553. }
  2554. #endif
  2555. #ifndef _SERVER
  2556. //-------------------------------------------------------------------------
  2557. // 功能:向服务器申请使用某个物品(鼠标右键点击该物品,只能用于吃药)
  2558. //-------------------------------------------------------------------------
  2559. BOOL KPlayer::ApplyUseItem(int nItemID, ItemPos SrcPos)
  2560. {
  2561. if (this->CheckTrading())
  2562. return FALSE;
  2563. int nRet = m_ItemList.UseItem(nItemID);
  2564. if (nRet == 0)
  2565. return FALSE;
  2566. if (nRet == REQUEST_EQUIP_ITEM)
  2567. {
  2568. }
  2569. else if (nRet == REQUEST_EAT_MEDICINE)
  2570. {
  2571. PLAYER_EAT_ITEM_COMMAND sEat;
  2572. sEat.ProtocolType = c2s_playereatitem;
  2573. sEat.m_nItemID = nItemID;
  2574. sEat.m_btPlace = SrcPos.nPlace;
  2575. sEat.m_btX = SrcPos.nX;
  2576. sEat.m_btY = SrcPos.nY;
  2577. if (g_pClient)
  2578. g_pClient->SendPackToServer(&sEat, sizeof(PLAYER_EAT_ITEM_COMMAND));
  2579. }
  2580. return TRUE;
  2581. }
  2582. #endif
  2583. #ifndef _SERVER
  2584. //-------------------------------------------------------------------------
  2585. // 功能:客户端鼠标点击obj检起某个物品,向服务器发消息
  2586. //-------------------------------------------------------------------------
  2587. void KPlayer::PickUpObj(int nObjIndex)
  2588. {
  2589. if (this->CheckTrading())
  2590. return;
  2591. if (nObjIndex <= 0)
  2592. return;
  2593. if (Object[nObjIndex].m_nKind != Obj_Kind_Item && Object[nObjIndex].m_nKind != Obj_Kind_Money)
  2594. return;
  2595. PLAYER_PICKUP_ITEM_COMMAND sPickUp;
  2596. if (Object[nObjIndex].m_nKind == Obj_Kind_Money)
  2597. {
  2598. sPickUp.ProtocolType = c2s_playerpickupitem;
  2599. sPickUp.m_nObjID = Object[nObjIndex].m_nID;
  2600. sPickUp.m_btPosType = 0;
  2601. sPickUp.m_btPosX = 0;
  2602. sPickUp.m_btPosY = 0;
  2603. }
  2604. else
  2605. {
  2606. ItemPos sItemPos;
  2607. if ( FALSE == m_ItemList.SearchPosition(Object[nObjIndex].m_nItemWidth, Object[nObjIndex].m_nItemHeight, &sItemPos) )
  2608. {
  2609. KSystemMessage sMsg;
  2610. sMsg.byConfirmType = SMCT_NONE;
  2611. sMsg.eType = SMT_NORMAL;
  2612. sMsg.byParamSize = 0;
  2613. sMsg.byPriority = 0;
  2614. strcpy(sMsg.szMessage, MSG_SHOP_NO_ROOM);
  2615. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2616. return;
  2617. }
  2618. sPickUp.ProtocolType = c2s_playerpickupitem;
  2619. sPickUp.m_nObjID = Object[nObjIndex].m_nID;
  2620. sPickUp.m_btPosType = sItemPos.nPlace;
  2621. sPickUp.m_btPosX = sItemPos.nX;
  2622. sPickUp.m_btPosY = sItemPos.nY;
  2623. }
  2624. if (g_pClient)
  2625. g_pClient->SendPackToServer(&sPickUp, sizeof(PLAYER_PICKUP_ITEM_COMMAND));
  2626. }
  2627. #endif
  2628. #ifndef _SERVER
  2629. //-------------------------------------------------------------------------
  2630. // 功能:客户端鼠标点击obj,向服务器发消息
  2631. //-------------------------------------------------------------------------
  2632. void KPlayer::ObjMouseClick(int nObjIndex)
  2633. {
  2634. if (this->CheckTrading())
  2635. return;
  2636. if (nObjIndex <= 0)
  2637. return;
  2638. if (Object[nObjIndex].m_nKind != Obj_Kind_Box && Object[nObjIndex].m_nKind != Obj_Kind_Prop)
  2639. return;
  2640. SendObjMouseClick(Object[nObjIndex].m_nID, SubWorld[0].m_Region[Object[nObjIndex].m_nRegionIdx].m_RegionID);
  2641. }
  2642. #endif
  2643. #ifndef _SERVER
  2644. // DownPos 是面板上的物品的当前坐标,UpPos 必须是手上物品放到面板上的坐标
  2645. void KPlayer::MoveItem(ItemPos DownPos, ItemPos UpPos)
  2646. {
  2647. if (this->CheckTrading() && DownPos.nPlace == pos_traderoom)
  2648. {
  2649. if (this->m_cTrade.m_nTradeLock)
  2650. return;
  2651. // 任务物品的限制
  2652. int nHandIdx = m_ItemList.Hand();
  2653. if (nHandIdx && Item[nHandIdx].GetGenre() == item_task)
  2654. {
  2655. KSystemMessage sMsg;
  2656. sprintf(sMsg.szMessage, MSG_TRADE_TASK_ITEM);
  2657. sMsg.eType = SMT_NORMAL;
  2658. sMsg.byConfirmType = SMCT_NONE;
  2659. sMsg.byPriority = 0;
  2660. sMsg.byParamSize = 0;
  2661. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2662. return;
  2663. }
  2664. }
  2665. if (!CheckTrading() && DownPos.nPlace == pos_immediacy)
  2666. {
  2667. int nHandIdx = m_ItemList.Hand();
  2668. if (nHandIdx)
  2669. {
  2670. if (m_ItemList.m_Room[room_immediacy].CheckSameDetailType(Item[nHandIdx].GetGenre(), Item[nHandIdx].GetDetailType()))
  2671. {
  2672. KSystemMessage sMsg;
  2673. sMsg.eType = SMT_NORMAL;
  2674. sMsg.byConfirmType = SMCT_NONE;
  2675. sMsg.byPriority = 0;
  2676. sMsg.byParamSize = 0;
  2677. sprintf(sMsg.szMessage, MSG_ITEM_SAME_DETAIL_IN_IMMEDIATE);
  2678. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2679. return;
  2680. }
  2681. }
  2682. }
  2683. SendClientCmdMoveItem(&DownPos, &UpPos);
  2684. }
  2685. #endif
  2686. #ifndef _SERVER
  2687. int KPlayer::ThrowAwayItem()
  2688. {
  2689. if (this->CheckTrading())
  2690. return 0;
  2691. if ( !m_ItemList.Hand() )
  2692. return 0;
  2693. PLAYER_THROW_AWAY_ITEM_COMMAND sThrow;
  2694. sThrow.ProtocolType = c2s_playerthrowawayitem;
  2695. if (g_pClient)
  2696. g_pClient->SendPackToServer(&sThrow, sizeof(PLAYER_THROW_AWAY_ITEM_COMMAND));
  2697. return 1;
  2698. }
  2699. #endif
  2700. #ifndef _SERVER
  2701. void KPlayer::ChatAddFriend(int nPlayerIdx)
  2702. {
  2703. CHAT_ADD_FRIEND_COMMAND sAdd;
  2704. sAdd.ProtocolType = c2s_chataddfriend;
  2705. sAdd.m_nTargetPlayerIdx = nPlayerIdx;
  2706. if (g_pClient)
  2707. g_pClient->SendPackToServer(&sAdd, sizeof(CHAT_ADD_FRIEND_COMMAND));
  2708. }
  2709. #endif
  2710. #ifndef _SERVER
  2711. void KPlayer::ChatRefuseFriend(int nPlayerIdx)
  2712. {
  2713. CHAT_REFUSE_FRIEND_COMMAND sRefuse;
  2714. sRefuse.ProtocolType = c2s_chatrefusefriend;
  2715. sRefuse.m_nTargetPlayerIdx = nPlayerIdx;
  2716. if (g_pClient)
  2717. g_pClient->SendPackToServer(&sRefuse, sizeof(CHAT_REFUSE_FRIEND_COMMAND));
  2718. }
  2719. #endif
  2720. #ifndef _SERVER
  2721. void KPlayer::TradeApplyOpen(char *lpszSentence, int nLength)
  2722. {
  2723. if (this->CheckTrading())
  2724. return;
  2725. if (!lpszSentence)
  2726. nLength = 0;
  2727. TRADE_APPLY_OPEN_COMMAND sOpen;
  2728. sOpen.ProtocolType = c2s_tradeapplystateopen;
  2729. if (nLength >= MAX_SENTENCE_LENGTH)
  2730. nLength = MAX_SENTENCE_LENGTH - 1;
  2731. sOpen.m_wLength = sizeof(TRADE_APPLY_OPEN_COMMAND) - 1 - sizeof(sOpen.m_szSentence) + nLength;
  2732. memset(m_cMenuState.m_szSentence, 0, sizeof(m_cMenuState.m_szSentence));
  2733. if (lpszSentence)
  2734. memcpy(m_cMenuState.m_szSentence, lpszSentence, nLength);
  2735. memset(sOpen.m_szSentence, 0, sizeof(sOpen.m_szSentence));
  2736. memcpy(sOpen.m_szSentence, m_cMenuState.m_szSentence, nLength);
  2737. if (g_pClient)
  2738. g_pClient->SendPackToServer(&sOpen, sOpen.m_wLength + 1);
  2739. }
  2740. #endif
  2741. #ifndef _SERVER
  2742. void KPlayer::TradeApplyClose()
  2743. {
  2744. TRADE_APPLY_CLOSE_COMMAND sApply;
  2745. sApply.ProtocolType = c2s_tradeapplystateclose;
  2746. if (g_pClient)
  2747. g_pClient->SendPackToServer(&sApply, sizeof(TRADE_APPLY_CLOSE_COMMAND));
  2748. }
  2749. #endif
  2750. #ifndef _SERVER
  2751. void KPlayer::TradeApplyStart(int nNpcIdx)
  2752. {
  2753. if (nNpcIdx < 0 || nNpcIdx >= MAX_NPC)
  2754. return;
  2755. TRADE_APPLY_START_COMMAND sStart;
  2756. sStart.ProtocolType = c2s_tradeapplystart;
  2757. sStart.m_dwID = Npc[nNpcIdx].m_dwID;
  2758. if (g_pClient)
  2759. g_pClient->SendPackToServer(&sStart, sizeof(TRADE_APPLY_START_COMMAND));
  2760. KSystemMessage sMsg;
  2761. sprintf(sMsg.szMessage, MSG_TRADE_SEND_APPLY, Npc[nNpcIdx].Name);
  2762. sMsg.eType = SMT_NORMAL;
  2763. sMsg.byConfirmType = SMCT_NONE;
  2764. sMsg.byPriority = 0;
  2765. sMsg.byParamSize = 0;
  2766. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  2767. }
  2768. #endif
  2769. #ifndef _SERVER
  2770. BOOL KPlayer::TradeMoveMoney(int nMoney)
  2771. {
  2772. if (!CheckTrading())
  2773. return FALSE;
  2774. if (this->m_cTrade.m_nTradeLock)
  2775. return FALSE;
  2776. // 钱数量错误
  2777. if (nMoney < 0 || nMoney > m_ItemList.GetEquipmentMoney())
  2778. return FALSE;
  2779. TRADE_MOVE_MONEY_COMMAND sMoney;
  2780. sMoney.ProtocolType = c2s_trademovemoney;
  2781. sMoney.m_nMoney = nMoney;
  2782. if (g_pClient)
  2783. g_pClient->SendPackToServer(&sMoney, sizeof(TRADE_MOVE_MONEY_COMMAND));
  2784. return TRUE;
  2785. }
  2786. #endif
  2787. #ifndef _SERVER
  2788. //-------------------------------------------------------------------------
  2789. // 功能:交易确定或取消
  2790. // if nDecision == 0 推出交易  if nDecision == 1 确定交易  if nDecision == 2 取消交易确定
  2791. //-------------------------------------------------------------------------
  2792. void KPlayer::TradeDecision(int nDecision)
  2793. {
  2794. if ( !CheckTrading() )
  2795. return;
  2796. TRADE_DECISION_COMMAND sDecision;
  2797. sDecision.ProtocolType = c2s_tradedecision;
  2798. if (nDecision == 1)
  2799. {
  2800. sDecision.m_btDecision = 1;
  2801. }
  2802. else if (nDecision == 0)
  2803. {
  2804. sDecision.m_btDecision = 0;
  2805. }
  2806. else if (nDecision == 2)
  2807. {
  2808. sDecision.m_btDecision = 4;
  2809. }
  2810. if (g_pClient)
  2811. g_pClient->SendPackToServer(&sDecision, sizeof(TRADE_DECISION_COMMAND));
  2812. }
  2813. #endif
  2814. #ifndef _SERVER
  2815. //-------------------------------------------------------------------------
  2816. // 功能:交易锁定或取消锁定
  2817. //-------------------------------------------------------------------------
  2818. void KPlayer::TradeApplyLock(int nLockOrNot)
  2819. {
  2820. if ( !CheckTrading() )
  2821. return;
  2822. TRADE_DECISION_COMMAND sDecision;
  2823. sDecision.ProtocolType = c2s_tradedecision;
  2824. if (nLockOrNot)
  2825. {
  2826. sDecision.m_btDecision = 2;